//------------------------------------------------------------------------------ // gui label control class -- // (C) Piero Giubilato, Devis Contarato 2008, Berkeley Lab -- //------------------------------------------------------------------------------ //______________________________________________________________________________ // {Trace} // [File name] "gui_Label.cpp" // [Author] "Devis Contarato, Piero Giubilato" // [Version] "1.1" // [Modified by] "Devis Contarato" // [Last revision] "13 Jul 2009" // [Language] "C++" // [Compiler] "Visual C++ 8.x 9.x" // [Member of] "Cool SEAL" // [Project] "SEAL" // [Description] "Source for the gui_Label class" // [Key documentation] // "Visual C++ Reference Help" // "Root reference guide" // {Trace} //______________________________________________________________________________ // Standard component // Root Component #include // Application component #include "global.h" #include "gui_Label.h" // CINT Preprocessor class import definition ClassImp(gui_Label) //______________________________________________________________________________ gui_Label::gui_Label(TGString entry, UInt_t left, UInt_t top): gui_Object(0) { // Default constructor. gui_Label provides an interface layer that // integrates a root TGLabel plus all the code necesary to implement // events management. // // 'entry' is the label text // 'left', 'top' set the position of the widget // gui_Label is a static widget, therefore no callback function is // provided // Debug dbg_Print("gui_Label::gui_Label:(default)", DBG_LVL_ZERO); // Sets up the widget Init(entry, left, top); } //______________________________________________________________________________ gui_Label::gui_Label(gui_Object* parent, TGString entry, UInt_t left, UInt_t top): gui_Object(parent) { // Default constructor. gui_Label provides an interface layer that dbg_Print("gui_Label::gui_Label:(gui_Object*)", DBG_LVL_ZERO); // Sets up the widget Init(entry, left, top); } //______________________________________________________________________________ gui_Label::~gui_Label() { // Default destructor. dbg_Print("gui_Label::~gui_Label:()", DBG_LVL_ZERO); // Removes the root object from the root graphical server Parent()->Window()->RemoveFrame(label); label->DestroyWindow(); // Deletes the root object delete label; } //______________________________________________________________________________ void gui_Label::Init(TGString entry, UInt_t left, UInt_t top) { // Creates a layer over a root text control dbg_Print("gui_Label::Init:(default)", DBG_LVL_ZERO); // Initializes the root widget label = new TGLabel(Parent()->Window(), entry); // Renders the widget into the frame and adds it to the window Parent()->Window()->AddFrame(label, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0)); MoveResize(left, top, 0, 0); // Store the text obj_Text.Form(entry); // Set as transparent by default Transparent(true); } //______________________________________________________________________________ const TGLabel* gui_Label::Root() { // Returns the pointer to the embedded root object return label; } //______________________________________________________________________________ void gui_Label::ReDraw() { // Overloaded gui_Object member dbg_Print("gui_Label::ReDraw:()", DBG_LVL_FLOW); // Redraw the label only if it is transparnt if (obj_Transparent) color_Set(obj_foreColor, Parent()->backColor()); } //______________________________________________________________________________ void gui_Label::MoveResize(UInt_t left, UInt_t top, UInt_t width, UInt_t height) { // Overloaded gui_Object member dbg_Print("gui_Label::moveResize:(default)", DBG_LVL_FLOW); // Moves and resizes the widget label->MoveResize(left, top); // Stores the new datas obj_Left = left; obj_Top = top; // Paint Update(); } //______________________________________________________________________________ void gui_Label::color_Set(UInt_t foreColor, UInt_t backColor) { // Sets the label colors (foreColor == textColor) dbg_Print("gui_Label::color_Set", DBG_LVL_FLOW); // Check for transparency if (obj_Transparent) backColor = Parent()->Window()->GetBackground(); // Set the label colors label->SetForegroundColor(foreColor); label->SetBackgroundColor(backColor); // Stores the new datas obj_foreColor = foreColor; obj_backColor = backColor; // Refresh the graphical container Update(); } //______________________________________________________________________________ void gui_Label::Transparent(bool transp) { // Sets the label colors (foreColor == textColor) dbg_Print("gui_Label::transparent:(bool)", DBG_LVL_FLOW); // Stores the new datas obj_Transparent = transp; // Updates colors color_Set(obj_foreColor, obj_backColor); } //______________________________________________________________________________ bool gui_Label::Transparent() const { // Returns the font size return obj_Transparent; } //______________________________________________________________________________ void gui_Label::Text(const char* text) { // Sets the label colors (foreColor == textColor) dbg_Print("gui_Label::text:(char*)", DBG_LVL_FLOW); // Assign the new twxt to the label label->ChangeText(text); label->Layout(); // Stores the new data obj_Text.Form(text); } //______________________________________________________________________________ const TString gui_Label::Text() const { // Returns the button text return obj_Text; } //______________________________________________________________________________ void gui_Label::fontBold(bool bold) { // Sets the boldness of the button text (true = bold) dbg_Print("gui_Label::fontBold:(char*)", DBG_LVL_FLOW); // Stores the new data obj_fontBold = bold; // Uses the fontsize func fontSize(obj_fontSize); } //______________________________________________________________________________ bool gui_Label::fontBold() const { // Returns the font size return obj_fontBold; } //______________________________________________________________________________ void gui_Label::fontSize(UInt_t size) { // Sets the size (and the weight) of the text dbg_Print("gui_Label::fontSize:(UInt)", DBG_LVL_FLOW); // Stores the new data obj_fontSize = (int)size; // Retrieves the font structure TGFontPool* pool = gClient->GetFontPool(); Int_t kFontWeight = (obj_fontBold == true) ? kFontWeightBold : kFontWeightNormal; TGFont* font = pool->GetFont("helvetica", -obj_fontSize, kFontWeight, kFontSlantRoman); FontStruct_t ft = font->GetFontStruct(); // Set the font label->SetTextFont(ft, kFALSE); // Fit the label and update MoveResize(obj_Left, obj_Top, 0, 0); } //______________________________________________________________________________ UInt_t gui_Label::fontSize() const { // Returns the font size return obj_fontSize; } //______________________________________________________________________________ const TGString* gui_Label::lbl_Val() const { // Returns the current text entry return label->GetText(); }