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#include <TApplication.h>
15#include <TGClient.h>
16#include <TGButton.h>
17#include <TGLabel.h>
18#include <TGResourcePool.h>
19
20class MyMainFrame : public TGMainFrame {
21
22private:
23 TGLabel *fLbl1, *fLbl2, *fLbl3, *fLbl4;
24 TGTextButton *fToggle;
25
26public:
27 MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
28 ~MyMainFrame() override;
29 void DoExit();
30 void DoSwitch();
31
32 ClassDefOverride(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) : TGMainFrame(p, w, h)
59{
60
61 // label + horizontal line
62 TGGC *fTextGC;
63 const TGFont *font = gClient->GetFont("-*-times-bold-r-*-*-18-*-*-*-*-*-*-*");
64 if (!font)
65 font = gClient->GetResourcePool()->GetDefaultFont();
66 FontStruct_t labelfont = font->GetFontStruct();
69 gval.fFont = font->GetFontHandle();
70 gClient->GetColorByName("yellow", gval.fBackground);
71 fTextGC = gClient->GetGC(&gval, kTRUE);
72
73 ULong_t bcolor, ycolor;
74 gClient->GetColorByName("yellow", ycolor);
75 gClient->GetColorByName("blue", bcolor);
76
77 // Create a main frame
78 fLbl1 = new TGLabel(this, "OwnFont & Bck/ForgrColor", fTextGC->GetGC(), labelfont, kChildFrame, bcolor);
79 AddFrame(fLbl1, new TGLayoutHints(kLHintsNormal, 5, 5, 3, 4));
80 fLbl1->SetTextColor(ycolor);
81
82 fLbl2 = new TGLabel(this, "Own Font & ForegroundColor", fTextGC->GetGC(), labelfont);
83 AddFrame(fLbl2, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
84 fLbl2->SetTextColor(ycolor);
85
86 fLbl3 = new TGLabel(this, "Normal Label");
87 AddFrame(fLbl3, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
88
89 fLbl4 = new TGLabel(this, "Multi-line label, resized\nto 300x80 pixels", fTextGC->GetGC(), labelfont, kChildFrame,
90 bcolor);
91 AddFrame(fLbl4, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
92 fLbl4->SetTextColor(ycolor);
93 fLbl4->ChangeOptions(fLbl4->GetOptions() | kFixedSize);
94 fLbl4->Resize(350, 80);
95
96 // Create a horizontal frame containing two buttons
97 TGTextButton *toggle = new TGTextButton(this, "&Toggle Labels");
98 toggle->Connect("Clicked()", "MyMainFrame", this, "DoSwitch()");
99 toggle->SetToolTipText("Click on the button to toggle label's state (enable/disable)");
100 AddFrame(toggle, new TGLayoutHints(kLHintsExpandX, 5, 5, 3, 4));
101 TGTextButton *exit = new TGTextButton(this, "&Exit ");
102 exit->Connect("Pressed()", "MyMainFrame", this, "DoExit()");
103 AddFrame(exit, new TGLayoutHints(kLHintsExpandX, 5, 5, 3, 4));
104
105 // Set a name to the main frame
106 SetWindowName("Labels");
108
109 // Initialize the layout algorithm via Resize()
110 Resize(GetDefaultSize());
111
112 // Map main frame
113 MapWindow();
114}
115
116MyMainFrame::~MyMainFrame()
117{
118 // Clean up main frame...
119 Cleanup();
120}
121
122void guilabels()
123{
124 // Popup the GUI...
125 new MyMainFrame(gClient->GetRoot(), 200, 200);
126}
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 long ULong_t
Definition RtypesCore.h:55
unsigned int UInt_t
Definition RtypesCore.h:46
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
#define ClassDefOverride(name, id)
Definition Rtypes.h:346
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
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize MapSubwindows
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t gval
void Printf(const char *fmt,...)
Formats a string in a circular formatting buffer and prints the string.
Definition TString.cxx:2503
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:397
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