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 ////////////////////////////////////////////////////////////////////////////////
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)", "ROOT::GUITutorials::WorldMap",
74  this, "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 }
TGCompositeFrame::GetDefaultSize
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;
Definition: TGFrame.h:352
TGImageMap.h
TGMainFrame
Definition: TGFrame.h:443
TGImageMap::AddRegion
void AddRegion(const TGRegion &region, Int_t id)
Add a region to the image map.
Definition: TGImageMap.cxx:476
TGDimension
Definition: TGDimension.h:27
TGMainFrame::SetIconName
void SetIconName(const char *name)
Set window icon name. This is typically done via the window manager.
Definition: TGFrame.cxx:1762
Form
char * Form(const char *fmt,...)
TGPicture.h
TGMsgBox
Definition: TGMsgBox.h:59
TGPopupMenu::AddLabel
virtual void AddLabel(TGHotString *s, const TGPicture *p=nullptr, TGMenuEntry *before=nullptr)
Add a menu label to the menu.
Definition: TGMenu.cxx:1094
TGPopupMenu::AddSeparator
virtual void AddSeparator(TGMenuEntry *before=nullptr)
Add a menu separator to the menu.
Definition: TGMenu.cxx:1059
Int_t
int Int_t
Definition: RtypesCore.h:45
TGRegion
Definition: TGImageMap.h:35
x
Double_t x[n]
Definition: legend1.C:17
TGMainFrame::SetWindowName
void SetWindowName(const char *name=0)
Set window name. This is typically done via the window manager.
Definition: TGFrame.cxx:1749
TString
Basic string class.
Definition: TString.h:136
gClient
#define gClient
Definition: TGClient.h:166
TGCompositeFrame::MapSubwindows
virtual void MapSubwindows()
Map all sub windows that are part of the composite frame.
Definition: TGFrame.cxx:1149
TGFrame::Resize
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:590
TGImageMap::SetToolTipText
void SetToolTipText(const char *text, Long_t delayms=300)
Set tooltip text for main region.
Definition: TGImageMap.cxx:613
TGFrame::MapRaised
virtual void MapRaised()
map raised
Definition: TGFrame.h:229
y
Double_t y[n]
Definition: legend1.C:17
TGClient.h
TGImageMap
Definition: TGImageMap.h:115
TQObject::Connect
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
TGMsgBox.h
TGPopupMenu
Definition: TGMenu.h:123
kMBIconAsterisk
@ kMBIconAsterisk
Definition: TGMsgBox.h:32
EMsgBoxIcon
EMsgBoxIcon
Definition: TGMsgBox.h:28
TGCompositeFrame::AddFrame
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1102
TGMenu.h
ROOT
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Definition: EExecutionPolicy.hxx:4
TGPopupMenu::AddEntry
virtual void AddEntry(TGHotString *s, Int_t id, void *ud=nullptr, const TGPicture *p=nullptr, TGMenuEntry *before=nullptr)
Add a menu entry.
Definition: TGMenu.cxx:989
TGImageMap::CreatePopup
TGPopupMenu * CreatePopup(Int_t id)
Create popoup menu or returns existing for regions with specified id.
Definition: TGImageMap.cxx:484