ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 ////////////////////////////////////////////////////////////////////////////////
17 namespace ROOT {
18 namespace GUITutorials {
19 
20 class WorldMap
21 {
22 protected:
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 
34 public:
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 //__________________________________________________________________________
57 WorldMap::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)", "WorldMap", this,
74  "PrintCode(Int_t)");
75 }
76 
77 //__________________________________________________________________________
78 TString WorldMap::GetTitle() const
79 {
80  // title
81 
82  return "Country Code (left button). City/Area Codes (right button)";
83 }
84 
85 //__________________________________________________________________________
86 void 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 //__________________________________________________________________________
104 void 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 //__________________________________________________________________________
127 void 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 //__________________________________________________________________________
139 void 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 //__________________________________________________________________________
151 void 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 //__________________________________________________________________________
163 void WorldMap::InitMap()
164 {
165  //
166 
167  InitRU();
168  InitUS();
169  InitFR();
170  InitAU();
171  InitUK();
172  fImageMap->SetToolTipText(GetTitle().Data(), 300);
173 }
174 
175 //__________________________________________________________________________
176 void 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 
192 void WorldMap()
193 {
194  namespace GUI = ROOT::GUITutorials;
195  GUI::WorldMap *map = new GUI::WorldMap;
196  map->Show();
197 }
Basic string class.
Definition: TString.h:137
#define gClient
Definition: TGClient.h:174
int Int_t
Definition: RtypesCore.h:41
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:985
virtual void AddSeparator(TGMenuEntry *before=0)
Add a menu separator to the menu.
Definition: TGMenu.cxx:1055
TBonjourRegistrar * reg
Definition: hserv2bonj.C:28
virtual void AddLabel(TGHotString *s, const TGPicture *p=0, TGMenuEntry *before=0)
Add a menu label to the menu.
Definition: TGMenu.cxx:1090
EMsgBoxIcon
Definition: TGMsgBox.h:40
std::vector< std::vector< double > > Data
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:1135
char * Form(const char *fmt,...)
bar Show()