Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
WorldMap.C File Reference

Detailed Description

This macro shows how to use a TGImageMap class.

A TGImageMap provides the functionality like a clickable image in with sensitive regions (similar to MAP HTML tag).

#include <TGPicture.h>
#include <TGMenu.h>
#include <TGImageMap.h>
#include <TGMsgBox.h>
#include <TGClient.h>
////////////////////////////////////////////////////////////////////////////////
namespace ROOT {
namespace GUITutorials {
class WorldMap
{
protected:
TGMainFrame* fMain; // main frame
TGImageMap* fImageMap; // image map
virtual void InitMap();
virtual void InitRU();
virtual void InitUS();
// virtual void InitCN();
virtual void InitAU();
virtual void InitFR();
virtual void InitUK();
public:
// the name corresponds to TLD code
// (http://www.iana.org/cctld/cctld-whois.htm)
// the value to "country phone code"
// (http://www.att.com/traveler/tools/codes.html)
enum ECountryCode {
kRU = 7, kUS = 1, kFR = 33, kDE = 49, kCH = 41, kCN = 86, kAU = 61,
kUK = 44, kUA = 380, kBR = 55
};
WorldMap(const char *picName = "worldmap.jpg");
virtual ~WorldMap() {}
virtual void Show() { fMain->MapRaised(); }
TGImageMap* GetImageMap() const { return fImageMap; }
virtual TString GetTitle() const;
// slots
void PrintCode(Int_t code);
};
//__________________________________________________________________________
WorldMap::WorldMap(const char* picName)
{
//
fMain = new TGMainFrame(gClient->GetRoot(), 750, 420);
fImageMap = new TGImageMap(fMain, picName);
fMain->AddFrame(fImageMap);
fMain->SetWindowName(GetTitle().Data());
fMain->SetIconName("World Map");
fMain->Resize(size);
fMain->MapSubwindows();
InitMap();
fImageMap->Connect("RegionClicked(Int_t)", "ROOT::GUITutorials::WorldMap",
this, "PrintCode(Int_t)");
}
//__________________________________________________________________________
TString WorldMap::GetTitle() const
{
// title
return "Country Code (left button). City/Area Codes (right button)";
}
//__________________________________________________________________________
void WorldMap::InitRU()
{
//
int x[12] = { 403, 406, 427, 444, 438, 470, 508, 568, 599, 632, 645, 493 };
int y[12] = { 68, 90, 120, 125, 109, 94, 109, 101, 122, 107, 74, 46 };
TGRegion reg(12, x, y);
fImageMap->AddRegion(reg, kRU);
fImageMap->SetToolTipText(kRU, "Russia");
TGPopupMenu* pm = fImageMap->CreatePopup(kRU);
pm->AddLabel("City Codes");
pm->AddSeparator();
pm->AddEntry("Moscow = 095", 95);
pm->AddEntry("Protvino = 0967", 967);
pm->AddEntry("St.Petersburg = 812", 812);
}
//__________________________________________________________________________
void WorldMap::InitUS()
{
//
int x[5] = { 136, 122, 165, 194, 232 };
int y[5] = { 110, 141, 158, 160, 118 };
TGRegion reg(5, x, y);
fImageMap->AddRegion(reg, kUS);
int alaskaX[4] = { 86, 131, 154, 117 };
int alaskaY[4] = { 90, 82, 64, 63 };
TGRegion alaska(4, alaskaX, alaskaY);
fImageMap->AddRegion(alaska, kUS);
fImageMap->SetToolTipText(kUS, "USA");
TGPopupMenu* pm = fImageMap->CreatePopup(kUS);
pm->AddLabel("Area Codes");
pm->AddSeparator();
pm->AddEntry("Illinois = 217", 217);
pm->AddEntry("New York = 212", 212);
}
//__________________________________________________________________________
void WorldMap::InitFR()
{
//
int x[5] = { 349, 353, 368, 368, 358 };
int y[5] = { 112, 123, 119, 108, 107 };
TGRegion reg(5, x, y);
fImageMap->AddRegion(reg, kFR);
fImageMap->SetToolTipText(kFR, "France");
}
//__________________________________________________________________________
void WorldMap::InitUK()
{
//
int x[4] = { 346, 348, 359, 352 };
int y[4] = { 93, 104, 103, 87 };
TGRegion reg(4, x, y);
fImageMap->AddRegion(reg, kUK);
fImageMap->SetToolTipText(kUK, "United Kingdom");
}
//__________________________________________________________________________
void WorldMap::InitAU()
{
//
int x[6] = { 582, 576, 634, 658, 641, 607 };
int y[6] = { 271, 300, 310, 283, 251, 253 };
TGRegion reg(6, x, y);
fImageMap->AddRegion(reg, kAU);
fImageMap->SetToolTipText(kAU, "Australia");
}
//__________________________________________________________________________
void WorldMap::InitMap()
{
//
InitRU();
InitUS();
InitFR();
InitAU();
InitUK();
fImageMap->SetToolTipText(GetTitle().Data(), 300);
}
//__________________________________________________________________________
void WorldMap::PrintCode(Int_t code)
{
//
Int_t buttons = 0;
Int_t retval;
new TGMsgBox(gClient->GetRoot(), fMain,
"Country Code", Form("Country Code=%d",code),
icontype, buttons, &retval);
}
}//namespace GUITutorials.
}//namespace ROOT.
void WorldMap()
{
namespace GUI = ROOT::GUITutorials;
GUI::WorldMap *map = new GUI::WorldMap;
map->Show();
}
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
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:1117
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;
Definition TGFrame.h:316
virtual void MapSubwindows()
Map all sub windows that are part of the composite frame.
Definition TGFrame.cxx:1164
virtual void MapRaised()
map raised
Definition TGFrame.h:205
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition TGFrame.cxx:605
(with TGRegion and TGRegionWithId help classes)
Definition TGImageMap.h:107
void SetToolTipText(const char *text, Long_t delayms=300)
Set tooltip text for main region.
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.
Defines top level windows that interact with the system Window Manager.
Definition TGFrame.h:398
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=0)
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:136
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...
Author
Valeriy Onuchin

Definition in file WorldMap.C.