Logo ROOT  
Reference Guide
iconAsXPMData.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_gui
3 /// A simple example of creating icon image from XPM data, included into the code.
4 ///
5 /// \macro_code
6 ///
7 /// \author Ilka Antcheva 27/09/2007
8 
9 #include <TGClient.h>
10 #include <TGButton.h>
11 #include <TGFrame.h>
12 #include <TGIcon.h>
13 #include <TGResourcePool.h>
14 #include <TGPicture.h>
15 #include <TString.h>
16 #include <TApplication.h>
17 
18 const char * const icon1[] =
19 {
20 "16 16 8 1",
21 " c None s None",
22 ". c #808080",
23 "X c #FFFF00",
24 "o c #c0c0c0",
25 "O c black",
26 "+ c #00FFFF",
27 "@ c #00FF00",
28 "# c white",
29 " ..... ",
30 " ..XXoooOO ",
31 " .+XXXoooooO ",
32 " .@++XXoooo#oO ",
33 " .@@+XXooo#ooO ",
34 ".oo@@+Xoo#ooooO ",
35 ".ooo@+.O.oooooO ",
36 ".oooo@O#OoooooO ",
37 ".oooo#.O.+ooooO ",
38 ".ooo#oo#@X+oooO ",
39 " .o#oooo@X++oO ",
40 " .#ooooo@XX++O ",
41 " .ooooo@@XXO ",
42 " ..ooo@@OO ",
43 " ..OOO ",
44 " "
45 };
46 
47 class MyMainFrame : public TGMainFrame {
48 
49 public:
50  MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
51  virtual ~MyMainFrame();
52 
53  void DoExit();
54 
55  ClassDef(MyMainFrame, 0)
56 };
57 
58 void MyMainFrame::DoExit()
59 {
60  Cleanup();
62 }
63 
64 MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h) :
65  TGMainFrame(p, w, h)
66 {
67  // Create a main frame
68 
69  TString name = "myicon";
70  ULong_t yellow;
71  gClient->GetColorByName("yellow", yellow);
72 
73  // Create a picture from the XPM data
74  TGPicturePool *picpool = gClient->GetResourcePool()->GetPicturePool();
75  const TGPicture *iconpic = picpool->GetPicture(name.Data(),(char **)icon1);
76  TGIcon *icon = new TGIcon(this, iconpic, 40, 40, kChildFrame, yellow);
77  AddFrame(icon, new TGLayoutHints(kLHintsLeft, 1,15,1,1));
78 
79  TGTextButton *exit = new TGTextButton(this, "&Exit","gApplication->Terminate(0)");
80  AddFrame(exit, new TGLayoutHints(kLHintsExpandX,2,0,2,2));
81 
82  SetWindowName("Icon test");
83  MapSubwindows();
84  Resize(GetDefaultSize());
85  MapWindow();
86 }
87 
88 MyMainFrame::~MyMainFrame()
89 {
90  // Clean up all widgets, frames and layouthints.
91  Cleanup();
92 }
93 
94 void iconAsXPMData()
95 {
96  // Popup the GUI...
97  new MyMainFrame(gClient->GetRoot(), 350, 80);
98 }
TGWindow
Definition: TGWindow.h:31
TGMainFrame
Definition: TGFrame.h:443
TGPicture
Definition: TGPicture.h:36
TGPicture.h
TGIcon.h
kLHintsLeft
@ kLHintsLeft
Definition: TGLayout.h:31
TGTextButton
Definition: TGButton.h:142
TString
Basic string class.
Definition: TString.h:136
TString.h
TGIcon
Definition: TGIcon.h:30
gClient
#define gClient
Definition: TGClient.h:166
TApplication.h
TGPicturePool::GetPicture
const TGPicture * GetPicture(const char *name)
Get a picture from the picture pool.
Definition: TGPicture.cxx:80
h
#define h(i)
Definition: RSha256.hxx:106
TGFrame.h
TGLayoutHints
Definition: TGLayout.h:57
gApplication
R__EXTERN TApplication * gApplication
Definition: TApplication.h:166
TGPicturePool
Definition: TGPicture.h:100
UInt_t
unsigned int UInt_t
Definition: RtypesCore.h:46
TApplication::Terminate
virtual void Terminate(Int_t status=0)
ULong_t
unsigned long ULong_t
Definition: RtypesCore.h:55
TGClient.h
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TGButton.h
name
char name[80]
Definition: TGX11.cxx:110
kLHintsExpandX
@ kLHintsExpandX
Definition: TGLayout.h:37
TGResourcePool.h
kChildFrame
@ kChildFrame
Definition: GuiTypes.h:379