Logo ROOT  
Reference Guide
WorldMap.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_gui
3/// This macro shows how to use a TGImageMap class.
4/// A TGImageMap provides the functionality like a clickable image in with sensitive regions (similar to MAP HTML tag).
5///
6/// \macro_code
7///
8/// \author Valeriy Onuchin
9
10#include <TGPicture.h>
11#include <TGMenu.h>
12#include <TGImageMap.h>
13#include <TGMsgBox.h>
14#include <TGClient.h>
15
16////////////////////////////////////////////////////////////////////////////////
17namespace ROOT {
18namespace GUITutorials {
19
20class WorldMap
21{
22protected:
23 TGMainFrame* fMain; // main frame
24 TGImageMap* fImageMap; // image map
25
26 virtual void InitMap();
27 virtual void InitRU();
28 virtual void InitUS();
29// virtual void InitCN();
30 virtual void InitAU();
31 virtual void InitFR();
32 virtual void InitUK();
33
34public:
35 // the name corresponds to TLD code
36 // (http://www.iana.org/cctld/cctld-whois.htm)
37 // the value to "country phone code"
38 // (http://www.att.com/traveler/tools/codes.html)
39 enum ECountryCode {
40 kRU = 7, kUS = 1, kFR = 33, kDE = 49, kCH = 41, kCN = 86, kAU = 61,
41 kUK = 44, kUA = 380, kBR = 55
42 };
43
44 WorldMap(const char *picName = "worldmap.jpg");
45 virtual ~WorldMap() {}
46
47 virtual void Show() { fMain->MapRaised(); }
48 TGImageMap* GetImageMap() const { return fImageMap; }
49 virtual TString GetTitle() const;
50
51 // slots
52 void PrintCode(Int_t code);
53};
54
55
56//__________________________________________________________________________
57WorldMap::WorldMap(const char* picName)
58{
59 //
60
61 fMain = new TGMainFrame(gClient->GetRoot(), 750, 420);
62
63 fImageMap = new TGImageMap(fMain, picName);
64 fMain->AddFrame(fImageMap);
65 fMain->SetWindowName(GetTitle().Data());
66 fMain->SetIconName("World Map");
67
68 TGDimension size = fMain->GetDefaultSize();
69 fMain->Resize(size);
70 fMain->MapSubwindows();
71 InitMap();
72
73 fImageMap->Connect("RegionClicked(Int_t)", "ROOT::GUITutorials::WorldMap",
74 this, "PrintCode(Int_t)");
75}
76
77//__________________________________________________________________________
78TString WorldMap::GetTitle() const
79{
80 // title
81
82 return "Country Code (left button). City/Area Codes (right button)";
83}
84
85//__________________________________________________________________________
86void WorldMap::InitRU()
87{
88 //
89
90 int x[12] = { 403, 406, 427, 444, 438, 470, 508, 568, 599, 632, 645, 493 };
91 int y[12] = { 68, 90, 120, 125, 109, 94, 109, 101, 122, 107, 74, 46 };
92 TGRegion reg(12, x, y);
93 fImageMap->AddRegion(reg, kRU);
94 fImageMap->SetToolTipText(kRU, "Russia");
95 TGPopupMenu* pm = fImageMap->CreatePopup(kRU);
96 pm->AddLabel("City Codes");
97 pm->AddSeparator();
98 pm->AddEntry("Moscow = 095", 95);
99 pm->AddEntry("Protvino = 0967", 967);
100 pm->AddEntry("St.Petersburg = 812", 812);
101}
102
103//__________________________________________________________________________
104void WorldMap::InitUS()
105{
106 //
107
108 int x[5] = { 136, 122, 165, 194, 232 };
109 int y[5] = { 110, 141, 158, 160, 118 };
110 TGRegion reg(5, x, y);
111 fImageMap->AddRegion(reg, kUS);
112
113 int alaskaX[4] = { 86, 131, 154, 117 };
114 int alaskaY[4] = { 90, 82, 64, 63 };
115 TGRegion alaska(4, alaskaX, alaskaY);
116 fImageMap->AddRegion(alaska, kUS);
117 fImageMap->SetToolTipText(kUS, "USA");
118
119 TGPopupMenu* pm = fImageMap->CreatePopup(kUS);
120 pm->AddLabel("Area Codes");
121 pm->AddSeparator();
122 pm->AddEntry("Illinois = 217", 217);
123 pm->AddEntry("New York = 212", 212);
124}
125
126//__________________________________________________________________________
127void WorldMap::InitFR()
128{
129 //
130
131 int x[5] = { 349, 353, 368, 368, 358 };
132 int y[5] = { 112, 123, 119, 108, 107 };
133 TGRegion reg(5, x, y);
134 fImageMap->AddRegion(reg, kFR);
135 fImageMap->SetToolTipText(kFR, "France");
136}
137
138//__________________________________________________________________________
139void WorldMap::InitUK()
140{
141 //
142
143 int x[4] = { 346, 348, 359, 352 };
144 int y[4] = { 93, 104, 103, 87 };
145 TGRegion reg(4, x, y);
146 fImageMap->AddRegion(reg, kUK);
147 fImageMap->SetToolTipText(kUK, "United Kingdom");
148}
149
150//__________________________________________________________________________
151void WorldMap::InitAU()
152{
153 //
154
155 int x[6] = { 582, 576, 634, 658, 641, 607 };
156 int y[6] = { 271, 300, 310, 283, 251, 253 };
157 TGRegion reg(6, x, y);
158 fImageMap->AddRegion(reg, kAU);
159 fImageMap->SetToolTipText(kAU, "Australia");
160}
161
162//__________________________________________________________________________
163void WorldMap::InitMap()
164{
165 //
166
167 InitRU();
168 InitUS();
169 InitFR();
170 InitAU();
171 InitUK();
172 fImageMap->SetToolTipText(GetTitle().Data(), 300);
173}
174
175//__________________________________________________________________________
176void WorldMap::PrintCode(Int_t code)
177{
178 //
179
180 EMsgBoxIcon icontype = kMBIconAsterisk;
181 Int_t buttons = 0;
182 Int_t retval;
183
184 new TGMsgBox(gClient->GetRoot(), fMain,
185 "Country Code", Form("Country Code=%d",code),
186 icontype, buttons, &retval);
187}
188
189}//namespace GUITutorials.
190}//namespace ROOT.
191
192void WorldMap()
193{
194 namespace GUI = ROOT::GUITutorials;
195 GUI::WorldMap *map = new GUI::WorldMap;
196 map->Show();
197}
int Int_t
Definition: RtypesCore.h:43
#define gClient
Definition: TGClient.h:166
EMsgBoxIcon
Definition: TGMsgBox.h:32
@ kMBIconAsterisk
Definition: TGMsgBox.h:36
char * Form(const char *fmt,...)
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1101
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;
Definition: TGFrame.h:353
virtual void MapSubwindows()
Map all sub windows that are part of the composite frame.
Definition: TGFrame.cxx:1148
virtual void MapRaised()
map raised
Definition: TGFrame.h:230
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:589
void SetToolTipText(const char *text, Long_t delayms=300)
Set tooltip text for main region.
Definition: TGImageMap.cxx:613
void AddRegion(const TGRegion &region, Int_t id)
Add a region to the image map.
Definition: TGImageMap.cxx:476
TGPopupMenu * CreatePopup(Int_t id)
Create popoup menu or returns existing for regions with specified id.
Definition: TGImageMap.cxx:484
void SetIconName(const char *name)
Set window icon name. This is typically done via the window manager.
Definition: TGFrame.cxx:1761
void SetWindowName(const char *name=0)
Set window name. This is typically done via the window manager.
Definition: TGFrame.cxx:1748
virtual void AddLabel(TGHotString *s, const TGPicture *p=0, TGMenuEntry *before=0)
Add a menu label to the menu.
Definition: TGMenu.cxx:1093
virtual void AddEntry(TGHotString *s, Int_t id, void *ud=0, const TGPicture *p=0, TGMenuEntry *before=0)
Add a menu entry.
Definition: TGMenu.cxx:988
virtual void AddSeparator(TGMenuEntry *before=0)
Add a menu separator to the menu.
Definition: TGMenu.cxx:1058
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot.
Definition: TQObject.cxx:866
Basic string class.
Definition: TString.h:131
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Definition: StringConv.hxx:21