Logo ROOT  
Reference Guide
guilabels.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_gui
3 /// This macro gives an example of how to create different kind of labels and the possibility to enable/disable them.
4 /// To run it do either:
5 /// ~~~
6 /// .x guilabels.C
7 /// .x guilabels.C++
8 /// ~~~
9 ///
10 /// \macro_code
11 ///
12 /// \author Ilka Antcheva 1/12/2006
13 
14 
15 #include <TApplication.h>
16 #include <TGClient.h>
17 #include <TGButton.h>
18 #include <TGLabel.h>
19 #include <TGResourcePool.h>
20 
21 class MyMainFrame : public TGMainFrame {
22 
23 private:
24  TGLabel *fLbl1, *fLbl2, *fLbl3, *fLbl4;
25  TGTextButton *fToggle;
26 public:
27  MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
28  virtual ~MyMainFrame();
29  void DoExit();
30  void DoSwitch();
31 
32  ClassDef(MyMainFrame, 0)
33 };
34 
35 void MyMainFrame::DoSwitch()
36 {
37  if (fLbl1->IsDisabled()) {
38  printf("Enabled labels\n");
39  fLbl1->Enable();
40  fLbl2->Enable();
41  fLbl3->Enable();
42  fLbl4->Enable();
43  } else {
44  printf("Disabled labels\n");
45  fLbl1->Disable();
46  fLbl2->Disable();
47  fLbl3->Disable();
48  fLbl4->Disable();
49  }
50 }
51 
52 void MyMainFrame::DoExit()
53 {
54  Printf("Slot DoExit()");
56 }
57 
58 MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h) :
59  TGMainFrame(p, w, h)
60 {
61 
62  // label + horizontal line
63  TGGC *fTextGC;
64  const TGFont *font = gClient->GetFont("-*-times-bold-r-*-*-18-*-*-*-*-*-*-*");
65  if (!font)
66  font = gClient->GetResourcePool()->GetDefaultFont();
67  FontStruct_t labelfont = font->GetFontStruct();
68  GCValues_t gval;
70  gval.fFont = font->GetFontHandle();
71  gClient->GetColorByName("yellow", gval.fBackground);
72  fTextGC = gClient->GetGC(&gval, kTRUE);
73 
74 
75  ULong_t bcolor, ycolor;
76  gClient->GetColorByName("yellow", ycolor);
77  gClient->GetColorByName("blue", bcolor);
78 
79  // Create a main frame
80  fLbl1 = new TGLabel(this, "OwnFont & Bck/ForgrColor", fTextGC->GetGC(),
81  labelfont, kChildFrame, bcolor);
82  AddFrame(fLbl1, new TGLayoutHints(kLHintsNormal, 5, 5, 3, 4));
83  fLbl1->SetTextColor(ycolor);
84 
85  fLbl2 = new TGLabel(this, "Own Font & ForegroundColor", fTextGC->GetGC(),
86  labelfont);
87  AddFrame(fLbl2, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
88  fLbl2->SetTextColor(ycolor);
89 
90  fLbl3 = new TGLabel(this, "Normal Label");
91  AddFrame(fLbl3, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
92 
93  fLbl4 = new TGLabel(this, "Multi-line label, resized\nto 300x80 pixels",
94  fTextGC->GetGC(), labelfont, kChildFrame, bcolor);
95  AddFrame(fLbl4, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
96  fLbl4->SetTextColor(ycolor);
97  fLbl4->ChangeOptions(fLbl4->GetOptions() | kFixedSize);
98  fLbl4->Resize(350, 80);
99 
100  // Create a horizontal frame containing two buttons
101  TGTextButton *toggle = new TGTextButton(this, "&Toggle Labels");
102  toggle->Connect("Clicked()", "MyMainFrame", this, "DoSwitch()");
103  toggle->SetToolTipText("Click on the button to toggle label's state (enable/disable)");
104  AddFrame(toggle, new TGLayoutHints(kLHintsExpandX, 5, 5, 3, 4));
105  TGTextButton *exit = new TGTextButton(this, "&Exit ");
106  exit->Connect("Pressed()", "MyMainFrame", this, "DoExit()");
107  AddFrame(exit, new TGLayoutHints(kLHintsExpandX, 5, 5, 3, 4));
108 
109  // Set a name to the main frame
110  SetWindowName("Labels");
111  MapSubwindows();
112 
113  // Initialize the layout algorithm via Resize()
114  Resize(GetDefaultSize());
115 
116  // Map main frame
117  MapWindow();
118 }
119 
120 MyMainFrame::~MyMainFrame()
121 {
122  // Clean up main frame...
123  Cleanup();
124 }
125 
126 void guilabels()
127 {
128  // Popup the GUI...
129  new MyMainFrame(gClient->GetRoot(), 200, 200);
130 }
TGButton::SetToolTipText
virtual void SetToolTipText(const char *text, Long_t delayms=400)
Set tool tip text associated with this button.
Definition: TGButton.cxx:398
TGWindow
Definition: TGWindow.h:31
kLHintsCenterX
@ kLHintsCenterX
Definition: TGLayout.h:32
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TGMainFrame
Definition: TGFrame.h:444
TGGC::GetGC
GContext_t GetGC() const
Definition: TGGC.h:50
FontStruct_t
Handle_t FontStruct_t
Definition: GuiTypes.h:38
TGLabel
Definition: TGLabel.h:32
GCValues_t
Definition: GuiTypes.h:223
TGTextButton
Definition: TGButton.h:142
gClient
#define gClient
Definition: TGClient.h:166
TApplication.h
kLHintsNormal
@ kLHintsNormal
Definition: TGLayout.h:39
h
#define h(i)
Definition: RSha256.hxx:106
TGGC
Definition: TGGC.h:31
kGCForeground
const Mask_t kGCForeground
Definition: GuiTypes.h:287
GCValues_t::fFont
FontH_t fFont
Definition: GuiTypes.h:241
TGFont::GetFontHandle
FontH_t GetFontHandle() const
Definition: TGFont.h:192
TGLayoutHints
Definition: TGLayout.h:57
gApplication
R__EXTERN TApplication * gApplication
Definition: TApplication.h:166
kGCFont
const Mask_t kGCFont
Definition: GuiTypes.h:299
GCValues_t::fBackground
ULong_t fBackground
Definition: GuiTypes.h:227
UInt_t
unsigned int UInt_t
Definition: RtypesCore.h:46
kFixedSize
@ kFixedSize
Definition: GuiTypes.h:390
TApplication::Terminate
virtual void Terminate(Int_t status=0)
ULong_t
unsigned long ULong_t
Definition: RtypesCore.h:55
TGClient.h
kGCBackground
const Mask_t kGCBackground
Definition: GuiTypes.h:288
Printf
void Printf(const char *fmt,...)
TGLabel.h
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:864
GCValues_t::fMask
Mask_t fMask
Definition: GuiTypes.h:250
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TGButton.h
kLHintsExpandX
@ kLHintsExpandX
Definition: TGLayout.h:37
TGResourcePool.h
TGFont::GetFontStruct
FontStruct_t GetFontStruct() const
Definition: TGFont.h:193
TGFont
Definition: TGFont.h:149
kChildFrame
@ kChildFrame
Definition: GuiTypes.h:379