Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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->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};
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)
{
//
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
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#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:318
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:207
(with TGRegion and TGRegionWithId help classes)
Definition TGImageMap.h:107
Defines top level windows that interact with the system Window Manager.
Definition TGFrame.h:399
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
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...
Author
Valeriy Onuchin

Definition in file WorldMap.C.