Logo ROOT  
Reference Guide
guilabels.C File Reference

Detailed Description

This macro gives an example of how to create different kind of labels and the possibility to enable/disable them. To run it do either:

.x guilabels.C
.x guilabels.C++
#include <TApplication.h>
#include <TGClient.h>
#include <TGButton.h>
#include <TGLabel.h>
#include <TGResourcePool.h>
class MyMainFrame : public TGMainFrame {
private:
TGLabel *fLbl1, *fLbl2, *fLbl3, *fLbl4;
TGTextButton *fToggle;
public:
MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
virtual ~MyMainFrame();
void DoExit();
void DoSwitch();
ClassDef(MyMainFrame, 0)
};
void MyMainFrame::DoSwitch()
{
if (fLbl1->IsDisabled()) {
printf("Enabled labels\n");
fLbl1->Enable();
fLbl2->Enable();
fLbl3->Enable();
fLbl4->Enable();
} else {
printf("Disabled labels\n");
fLbl1->Disable();
fLbl2->Disable();
fLbl3->Disable();
fLbl4->Disable();
}
}
void MyMainFrame::DoExit()
{
Printf("Slot DoExit()");
}
MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h) :
TGMainFrame(p, w, h)
{
// label + horizontal line
TGGC *fTextGC;
const TGFont *font = gClient->GetFont("-*-times-bold-r-*-*-18-*-*-*-*-*-*-*");
if (!font)
font = gClient->GetResourcePool()->GetDefaultFont();
FontStruct_t labelfont = font->GetFontStruct();
GCValues_t gval;
gval.fFont = font->GetFontHandle();
gClient->GetColorByName("yellow", gval.fBackground);
fTextGC = gClient->GetGC(&gval, kTRUE);
ULong_t bcolor, ycolor;
gClient->GetColorByName("yellow", ycolor);
gClient->GetColorByName("blue", bcolor);
// Create a main frame
fLbl1 = new TGLabel(this, "OwnFont & Bck/ForgrColor", fTextGC->GetGC(),
labelfont, kChildFrame, bcolor);
AddFrame(fLbl1, new TGLayoutHints(kLHintsNormal, 5, 5, 3, 4));
fLbl1->SetTextColor(ycolor);
fLbl2 = new TGLabel(this, "Own Font & ForegroundColor", fTextGC->GetGC(),
labelfont);
AddFrame(fLbl2, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
fLbl2->SetTextColor(ycolor);
fLbl3 = new TGLabel(this, "Normal Label");
AddFrame(fLbl3, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
fLbl4 = new TGLabel(this, "Multi-line label, resized\nto 300x80 pixels",
fTextGC->GetGC(), labelfont, kChildFrame, bcolor);
AddFrame(fLbl4, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
fLbl4->SetTextColor(ycolor);
fLbl4->ChangeOptions(fLbl4->GetOptions() | kFixedSize);
fLbl4->Resize(350, 80);
// Create a horizontal frame containing two buttons
TGTextButton *toggle = new TGTextButton(this, "&Toggle Labels");
toggle->Connect("Clicked()", "MyMainFrame", this, "DoSwitch()");
toggle->SetToolTipText("Click on the button to toggle label's state (enable/disable)");
AddFrame(toggle, new TGLayoutHints(kLHintsExpandX, 5, 5, 3, 4));
TGTextButton *exit = new TGTextButton(this, "&Exit ");
exit->Connect("Pressed()", "MyMainFrame", this, "DoExit()");
AddFrame(exit, new TGLayoutHints(kLHintsExpandX, 5, 5, 3, 4));
// Set a name to the main frame
SetWindowName("Labels");
MapSubwindows();
// Initialize the layout algorithm via Resize()
Resize(GetDefaultSize());
// Map main frame
MapWindow();
}
MyMainFrame::~MyMainFrame()
{
// Clean up main frame...
Cleanup();
}
void guilabels()
{
// Popup the GUI...
new MyMainFrame(gClient->GetRoot(), 200, 200);
}
Author
Ilka Antcheva 1/12/2006

Definition in file guilabels.C.

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:38
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:45
h
#define h(i)
Definition: RSha256.hxx:124
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:43
TGResourcePool.h
TGFont::GetFontStruct
FontStruct_t GetFontStruct() const
Definition: TGFont.h:193
TGFont
Definition: TGFont.h:149
kChildFrame
@ kChildFrame
Definition: GuiTypes.h:379