Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
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 {
21protected:
22 TGMainFrame *fMain; // main frame
23 TGImageMap *fImageMap; // image map
24
25 virtual void InitMap();
26 virtual void InitRU();
27 virtual void InitUS();
28 // virtual void InitCN();
29 virtual void InitAU();
30 virtual void InitFR();
31 virtual void InitUK();
32
33public:
34 // the name corresponds to TLD code
35 // (http://www.iana.org/cctld/cctld-whois.htm)
36 // the value to "country phone code"
37 // (http://www.att.com/traveler/tools/codes.html)
38 enum ECountryCode {
39 kRU = 7,
40 kUS = 1,
41 kFR = 33,
42 kDE = 49,
43 kCH = 41,
44 kCN = 86,
45 kAU = 61,
46 kUK = 44,
47 kUA = 380,
48 kBR = 55
49 };
50
51 WorldMap(const char *picName = "worldmap.jpg");
52 virtual ~WorldMap() {}
53
54 virtual void Show() { fMain->MapRaised(); }
55 TGImageMap *GetImageMap() const { return fImageMap; }
56 virtual TString GetTitle() const;
57
58 // slots
59 void PrintCode(Int_t code);
60};
61
62//__________________________________________________________________________
63WorldMap::WorldMap(const char *picName)
64{
65 //
66
67 fMain = new TGMainFrame(gClient->GetRoot(), 750, 420);
68
69 fImageMap = new TGImageMap(fMain, picName);
70 fMain->AddFrame(fImageMap);
71 fMain->SetWindowName(GetTitle().Data());
72 fMain->SetIconName("World Map");
73
75 fMain->Resize(size);
76 fMain->MapSubwindows();
77 InitMap();
78
79 fImageMap->Connect("RegionClicked(Int_t)", "ROOT::GUITutorials::WorldMap", this, "PrintCode(Int_t)");
80}
81
82//__________________________________________________________________________
83TString WorldMap::GetTitle() const
84{
85 // title
86
87 return "Country Code (left button). City/Area Codes (right button)";
88}
89
90//__________________________________________________________________________
91void WorldMap::InitRU()
92{
93 //
94
95 int x[12] = {403, 406, 427, 444, 438, 470, 508, 568, 599, 632, 645, 493};
96 int y[12] = {68, 90, 120, 125, 109, 94, 109, 101, 122, 107, 74, 46};
97 TGRegion reg(12, x, y);
98 fImageMap->AddRegion(reg, kRU);
99 fImageMap->SetToolTipText(kRU, "Russia");
100 TGPopupMenu *pm = fImageMap->CreatePopup(kRU);
101 pm->AddLabel("City Codes");
102 pm->AddSeparator();
103 pm->AddEntry("Moscow = 095", 95);
104 pm->AddEntry("Protvino = 0967", 967);
105 pm->AddEntry("St.Petersburg = 812", 812);
106}
107
108//__________________________________________________________________________
109void WorldMap::InitUS()
110{
111 //
112
113 int x[5] = {136, 122, 165, 194, 232};
114 int y[5] = {110, 141, 158, 160, 118};
115 TGRegion reg(5, x, y);
116 fImageMap->AddRegion(reg, kUS);
117
118 int alaskaX[4] = {86, 131, 154, 117};
119 int alaskaY[4] = {90, 82, 64, 63};
120 TGRegion alaska(4, alaskaX, alaskaY);
121 fImageMap->AddRegion(alaska, kUS);
122 fImageMap->SetToolTipText(kUS, "USA");
123
124 TGPopupMenu *pm = fImageMap->CreatePopup(kUS);
125 pm->AddLabel("Area Codes");
126 pm->AddSeparator();
127 pm->AddEntry("Illinois = 217", 217);
128 pm->AddEntry("New York = 212", 212);
129}
130
131//__________________________________________________________________________
132void WorldMap::InitFR()
133{
134 //
135
136 int x[5] = {349, 353, 368, 368, 358};
137 int y[5] = {112, 123, 119, 108, 107};
138 TGRegion reg(5, x, y);
139 fImageMap->AddRegion(reg, kFR);
140 fImageMap->SetToolTipText(kFR, "France");
141}
142
143//__________________________________________________________________________
144void WorldMap::InitUK()
145{
146 //
147
148 int x[4] = {346, 348, 359, 352};
149 int y[4] = {93, 104, 103, 87};
150 TGRegion reg(4, x, y);
151 fImageMap->AddRegion(reg, kUK);
152 fImageMap->SetToolTipText(kUK, "United Kingdom");
153}
154
155//__________________________________________________________________________
156void WorldMap::InitAU()
157{
158 //
159
160 int x[6] = {582, 576, 634, 658, 641, 607};
161 int y[6] = {271, 300, 310, 283, 251, 253};
162 TGRegion reg(6, x, y);
163 fImageMap->AddRegion(reg, kAU);
164 fImageMap->SetToolTipText(kAU, "Australia");
165}
166
167//__________________________________________________________________________
168void WorldMap::InitMap()
169{
170 //
171
172 InitRU();
173 InitUS();
174 InitFR();
175 InitAU();
176 InitUK();
177 fImageMap->SetToolTipText(GetTitle().Data(), 300);
178}
179
180//__________________________________________________________________________
181void WorldMap::PrintCode(Int_t code)
182{
183 //
184
185 EMsgBoxIcon icontype = kMBIconAsterisk;
186 Int_t buttons = 0;
187 Int_t retval;
188
189 new TGMsgBox(gClient->GetRoot(), fMain, "Country Code", Form("Country Code=%d", code), icontype, buttons, &retval);
190}
191
192} // namespace GUITutorials.
193} // namespace ROOT.
194
195void WorldMap()
196{
197 namespace GUI = ROOT::GUITutorials;
198 GUI::WorldMap *map = new GUI::WorldMap;
199 map->Show();
200}
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Definition RtypesCore.h:45
#define gClient
Definition TGClient.h:157
EMsgBoxIcon
Definition TGMsgBox.h:21
@ kMBIconAsterisk
Definition TGMsgBox.h:25
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void reg
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2489
TGDimension GetDefaultSize() const override
std::cout << fWidth << "x" << fHeight << std::endl;
Definition TGFrame.h:316
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1117
void MapSubwindows() override
Map all sub windows that are part of the composite frame.
Definition TGFrame.cxx:1164
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the frame.
Definition TGFrame.cxx:605
void MapRaised() override
map raised
Definition TGFrame.h:205
(with TGRegion and TGRegionWithId help classes)
Definition TGImageMap.h:107
void AddRegion(const TGRegion &region, Int_t id)
Add a region to the image map.
TGPopupMenu * CreatePopup(Int_t id)
Create popup menu or returns existing for regions with specified id.
void SetToolTipText(const char *text, Long_t delayms=300) override
Set tooltip text for main region.
Defines top level windows that interact with the system Window Manager.
Definition TGFrame.h:397
void SetIconName(const char *name)
Set window icon name. This is typically done via the window manager.
Definition TGFrame.cxx:1801
void SetWindowName(const char *name=nullptr) override
Set window name. This is typically done via the window manager.
Definition TGFrame.cxx:1788
This class creates a popup menu object.
Definition TGMenu.h:110
virtual void AddLabel(TGHotString *s, const TGPicture *p=nullptr, TGMenuEntry *before=nullptr)
Add a menu label to the menu.
Definition TGMenu.cxx:1095
virtual void AddSeparator(TGMenuEntry *before=nullptr)
Add a menu separator to the menu.
Definition TGMenu.cxx:1060
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:990
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:869
Basic string class.
Definition TString.h:139
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...