Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
21class MyMainFrame : public TGMainFrame {
22
23private:
24 TGLabel *fLbl1, *fLbl2, *fLbl3, *fLbl4;
25 TGTextButton *fToggle;
26public:
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
35void 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
52void MyMainFrame::DoExit()
53{
54 Printf("Slot DoExit()");
56}
57
58MyMainFrame::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
120MyMainFrame::~MyMainFrame()
121{
122 // Clean up main frame...
123 Cleanup();
124}
125
126void guilabels()
127{
128 // Popup the GUI...
129 new MyMainFrame(gClient->GetRoot(), 200, 200);
130}
const Mask_t kGCBackground
Definition GuiTypes.h:289
const Mask_t kGCForeground
Definition GuiTypes.h:288
const Mask_t kGCFont
Definition GuiTypes.h:300
@ kChildFrame
Definition GuiTypes.h:379
@ kFixedSize
Definition GuiTypes.h:390
Handle_t FontStruct_t
Pointer to font structure.
Definition GuiTypes.h:39
#define h(i)
Definition RSha256.hxx:106
unsigned int UInt_t
Definition RtypesCore.h:46
unsigned long ULong_t
Definition RtypesCore.h:55
const Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassDef(name, id)
Definition Rtypes.h:325
R__EXTERN TApplication * gApplication
#define gClient
Definition TGClient.h:157
@ kLHintsNormal
Definition TGLayout.h:32
@ kLHintsCenterX
Definition TGLayout.h:25
@ kLHintsExpandX
Definition TGLayout.h:30
void Printf(const char *fmt,...)
virtual void Terminate(Int_t status=0)
Terminate the application by call TSystem::Exit() unless application has been told to return from Run...
virtual void SetToolTipText(const char *text, Long_t delayms=400)
Set tool tip text associated with this button.
Definition TGButton.cxx:445
Encapsulate fonts used in the GUI system.
Definition TGFont.h:140
FontStruct_t GetFontStruct() const
Definition TGFont.h:184
FontH_t GetFontHandle() const
Definition TGFont.h:183
Encapsulate a graphics context used in the low level graphics.
Definition TGGC.h:22
GContext_t GetGC() const
Definition TGGC.h:41
This class handles GUI labels.
Definition TGLabel.h:24
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
Defines top level windows that interact with the system Window Manager.
Definition TGFrame.h:398
Yield an action as soon as it is clicked.
Definition TGButton.h:142
ROOT GUI Window base class.
Definition TGWindow.h:23
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
Graphics context structure.
Definition GuiTypes.h:224
ULong_t fBackground
background pixel
Definition GuiTypes.h:228
Mask_t fMask
bit mask specifying which fields are valid
Definition GuiTypes.h:251
FontH_t fFont
default text font for text operations
Definition GuiTypes.h:242