//------------------------------------------------------------------------------ // gui icon control class -- // (C) Piero Giubilato, Devis Contarato 2008-2010, Berkeley Lab -- //------------------------------------------------------------------------------ //______________________________________________________________________________ // {Trace} // [File name] "gui_Icon.cpp" // [Author] "Devis Contarato, Piero Giubilato" // [Version] "0.5" // [Modified by] "Devis Contarato" // [Last revision] "22 Jan 2009" // [Language] "C++" // [Compiler] "Visual C++ 8.x 9.x" // [Member of] "Cool SEAL" // [Project] "SEAL" // [Description] "Source for the gui_Icon class" // [Key documentation] // "Visual C++ Reference Help" // "Root reference guide" // {Trace} //______________________________________________________________________________ // Standard component // Root Component #include // Application component #include "global.h" #include "gui_Icon.h" // CINT Preprocessor class import definition ClassImp(gui_Icon) //______________________________________________________________________________ gui_Icon::gui_Icon(const char* picName, UInt_t left, UInt_t top): gui_Object(0) { // Default constructor. gui_Icon provides an interface layer that // integrates a root TGLabel // // 'picName' is the icon picture; the constructure will create a TGPicture // which will then be passed to the TGIcon constructor // 'left', 'top', 'width', 'height' set the position and size of the widget // gui_Icon is a static widget, therefore no callback function is provided // Debug dbg_Print("gui_Icon::gui_Icon:()", DBG_LVL_ZERO); // Get the picture first! pic = icn_Get(picName); // Set up the widget! Init(pic, left, top, pic->GetWidth(), pic->GetHeight()); } //______________________________________________________________________________ gui_Icon::gui_Icon(gui_Object* parent, const char* picName, UInt_t left, UInt_t top): gui_Object(parent) { // Parent constructor. embeds the icon into the parent. dbg_Print("gui_Icon::gui_Icon:(gui_Object*)", DBG_LVL_ZERO); // Get the picture first! pic = icn_Get(picName); // Set up the widget! Init(pic, left, top, pic->GetWidth(), pic->GetHeight()); } //______________________________________________________________________________ gui_Icon::~gui_Icon() { // Default destructor. dbg_Print("gui_Icon::gui_Icon:()", DBG_LVL_ZERO); // Removes the root object from the root graphical server Parent()->Window()->RemoveFrame(icon); icon->DestroyWindow(); // Deletes the root object delete icon; } //______________________________________________________________________________ void gui_Icon::Init(TGPicture* pic, UInt_t left, UInt_t top, UInt_t width, UInt_t height) { // Creates a layer over a root icon control dbg_Print("gui_Icon::Init:(default)", DBG_LVL_MAKE); // Initializes the root widget; get picture and pass it to TGIcon constructor icon = new TGIcon(Parent()->Window(), pic, width, height); // Renders the widget into the frame and adds it to the window Parent()->Window()->AddFrame(icon, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0)); MoveResize(left, top, width, height); // Also updates the container } //______________________________________________________________________________ TGIcon* gui_Icon::Root() const { // Returns the pointer to the embedded root object return icon; } //______________________________________________________________________________ void gui_Icon::MoveResize(UInt_t left, UInt_t top, UInt_t width, UInt_t height) { // Moves and resizes the widget icon->MoveResize(left, top, width, height); // Stores the new datas obj_Left = left; obj_Top = top; obj_Width = width; obj_Height = height; // Paint Update(); } //______________________________________________________________________________ void gui_Icon::color_Set(UInt_t foreColor, UInt_t backColor) { // Set color of widget icon->SetForegroundColor(foreColor); icon->SetBackgroundColor(backColor); // Stores the new datas obj_foreColor = foreColor; obj_backColor = backColor; // Refresh the graphical container Update(); } //______________________________________________________________________________ void gui_Icon::Text(const char* text) { // Sets the button caption // At the monent, no text displayed into numeric //text->SetText(text); // Stores the new data obj_Text.Form(text); } //______________________________________________________________________________ const TString gui_Icon::Text() const { // Returns the button text return obj_Text; } //______________________________________________________________________________ void gui_Icon::fontBold(bool bold) { // Sets the boldness of the button text (true = bold) // Retrieves the font structure TGFontPool* pool = gClient->GetFontPool(); Int_t kFontWeight = (bold == true) ? kFontWeightBold : kFontWeightNormal; TGFont* font = pool->GetFont("helvetica", -12, kFontWeight, kFontSlantRoman); FontStruct_t ft = font->GetFontStruct(); // No font bold at the moment for numeric // Sets the font into the button //text->SetFont(ft, false); // Stores the new data obj_fontBold = bold; // Refresh the graphical container Update(); } //______________________________________________________________________________ bool gui_Icon::fontBold() const { // Returns the boldness of the button text return obj_fontBold; } //______________________________________________________________________________ TGPicture* gui_Icon::icn_Get(const char* picName) const { TGPicture *picture = (TGPicture *)gClient->GetPicture(picName); if (!picture) std::cout << "Icon picture not found" << std::endl; // Returns the picture to be used in the icon return picture; }