//------------------------------------------------------------------------------ // gui_CoolButton class -- // (C) Piero Giubilato 2008-2010, Berkeley Lab -- //------------------------------------------------------------------------------ //______________________________________________________________________________ // {Trace} // [File name] "gui_CoolButton.cpp" // [Author] "Piero Giubilato" // [Version] "1.0" // [Modified by] "Piero Giubilato" // [Last revision] "17 Feb 2009" // [Language] "C++" // [Compiler] "Visual C++ 8.x 9.x" // [Member of] "Cool SEAL" // [Project] "SEAL" // [Description] "Source for the gui_CoolButton class" // [Key documentation] // "Visual C++ Reference Help" // "Root reference guide" // {Trace} //______________________________________________________________________________ // Standard component // Root Component #include "TSystem.h" // Application component #include "global.h" #include "gui_CoolButton.h" // CINT Preprocessor class import definition ClassImp(gui_CoolButton) //______________________________________________________________________________ gui_CoolButton::gui_CoolButton(const char* label, UInt_t left, UInt_t top, UInt_t width, UInt_t height, UInt_t foreColor, UInt_t backColor) { // Default constructor. gui_CoolButtons provides an interface layer that // integrates the gso_Button together with all the code necesary to // manage the signal system implemented to handle the gso_Button events. // 'label' is the text appearing into the button // 'left', 'top', 'width', 'height' set the position and size of the button // 'behaviour' sets the button behaviour ('km_Button', 'km_Latch'), see // btn_Mode for further info. // Debug dbg_Print("gui_CoolButton::gui_CoolButton:(color)", DBG_LVL_ZERO); // Sets up the button Init(label, left, top, width, height, foreColor, backColor); // Sets up the behaviour //btn_Mode(behaviour); } /* //______________________________________________________________________________ gui_Button(const gui_Button&) { // Copy Constructor dbg_Print("gui_Button::gui_Button: copy constructor", DBG_LVL_ZERO); } //______________________________________________________________________________ const gui_Button& operator=(const gui_Button&) { // Operator= dbg_Print("gui_Button::operator=: copy operator", DBG_LVL_ZERO); } */ //______________________________________________________________________________ gui_CoolButton::~gui_CoolButton() { // Default destructor. dbg_Print("gui_CoolButton::~gui_CoolButton:()", DBG_LVL_ZERO); // Removes the root object from the root graphical server Container()->RemoveFrame(button); button->DestroyWindow(); // Deletes the root object delete button; } //______________________________________________________________________________ void gui_CoolButton::Init(const char* label, UInt_t left, UInt_t top, UInt_t width, UInt_t height, UInt_t foreColor, UInt_t backColor) { // Creates a layer over a root button dbg_Print("gui_CoolButton::btn_Place:(default)", DBG_LVL_MAKE); // Initializes the root button button = new gso_Button(Container(), label, width, height, km_Button, foreColor, backColor, container_Color()); // Connects it to the button handler function button->Connect(button, "Clicked()", "gui_CoolButton", this, "btn_Do()"); // Renders the button into the frame and adds it to the window Container()->AddFrame(button, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0)); button->SetWrapLength(-1); MoveResize(left, top, width, height); // This also update the object // Sets object properties obj_backColor = backColor; obj_foreColor = foreColor; // Sets the mechanical dafault status button_Default = false; // Set the object redrawing properties obj_Transparent = true; obj_Render = true; } //______________________________________________________________________________ UInt_t gui_CoolButton::btn_Mode() const { // Returns current button mode return button->Mode(); } //______________________________________________________________________________ void gui_CoolButton::btn_Mode(UInt_t value) { // Sets the mechanical behaviour of the button through the 'value' param. // 'value' = km_Button means that after the call of the 'btn_Status()' method // the status of the button will be reset to the default value, while // 'value' = km_Latch means that the status of the button will not change // until another user press. // 'value' = km_Led will provide a display only mode showing a led illuminated // when the status value is set to true. dbg_Print("gui_CoolButton::btn_Mode:()", DBG_LVL_FLOW); // Assigns the value button->Mode(value); // Updates the appearance Update(); } //______________________________________________________________________________ bool gui_CoolButton::btn_Default() const { // Returns the current button status return button_Default; } //______________________________________________________________________________ bool gui_CoolButton::btn_Default(bool value) { // Sets the default status of the button. dbg_Print("gui_CoolButton::btn_Default:(bool)", DBG_LVL_FLOW); // Sets the value button_Default = value; // Returns current value return button_Default; } //______________________________________________________________________________ const bool gui_CoolButton::btn_Status() { // Returns the current status of the button. See the 'btn_Mode' method for // more information on how the call to this method influence the button // status itself. // Assigns the value (resets it in case of button mode) //bool answer = button->Mode(); //if (button->Mode() == km_Button) button_Status = button_Default; // Returns the value return button->Status(); } //______________________________________________________________________________ void gui_CoolButton::btn_Status(bool value) { // Sets the status of the button (true, false) dbg_Print("gui_CoolButton::btn_Status:(bool)", DBG_LVL_FLOW); // Sets the current status of the button. button->Status(value); // Update the appearance Update(); } //______________________________________________________________________________ void gui_CoolButton::btn_Do() { // This function is called whenever the button is pressed, as it has been // linked to the associated root TGTextButton when it was instantiated. dbg_Print("gui_CoolButton::btn_Do:()", DBG_LVL_FLOW) // Frees the gui system //gSystem->ProcessEvents(); // Updates the status of the button for LabView like style //button_Status = !button_Status; // Calls the associated handler, if anyone, passing the ID as argument gui_Object::task_Call(gui_Object::obj_Id()); } //______________________________________________________________________________ const gso_Button* gui_CoolButton::Root() const { // Returns the pointer to the embedded root object return button; } //______________________________________________________________________________ void gui_CoolButton::ReDraw() { // Redraw the object to keep it in pair with the general GUI parameters dbg_Print("gui_CoolButton::ReDraw:()", DBG_LVL_FLOW); // What we need here is to change the desk background color, this will in // turn trigger the re-rendering of the whole button button->SetBackgroundColor(container_Color()); } //______________________________________________________________________________ void gui_CoolButton::MoveResize(UInt_t left, UInt_t top, UInt_t width, UInt_t height) { // Update button size and position dbg_Print("gui_CoolButton::moveResize:(default)", DBG_LVL_FLOW); // Moves and resizes the button button->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_CoolButton::color_Set(UInt_t foreColor, UInt_t backColor) { // Sets (foreColor == textColor) and button face color dbg_Print("gui_CoolButton::color_Set:(default)", DBG_LVL_FLOW); // Updates button colors button->SetTextColor(foreColor); button->SetColor(backColor, container_Color()); // Stores the new datas obj_foreColor = foreColor; obj_backColor = backColor; // Refresh the graphical container Update(); } //______________________________________________________________________________ void gui_CoolButton::Text(const char* text) { // Sets (foreColor == textColor) and button face color dbg_Print("gui_CoolButton::text:(default)", DBG_LVL_FLOW); // Sets the button caption button->SetText(text); // Stores the new data obj_Text.Form(text); } //______________________________________________________________________________ const TString gui_CoolButton::Text() const { // Returns the button text return obj_Text; } //______________________________________________________________________________ void gui_CoolButton::fontSize(UInt_t size) { // Sets the size of the text dbg_Print("gui_CoolButton::fontSize:(default)", 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(obj_fontName, -obj_fontSize, kFontWeight, kFontSlantRoman); FontStruct_t ft = font->GetFontStruct(); // Set the font button->SetFont(ft, kFALSE); // Refresh the graphical container Update(); } //______________________________________________________________________________ UInt_t gui_CoolButton::fontSize() const { // Returns the font size return obj_fontSize; } //______________________________________________________________________________ void gui_CoolButton::fontBold(bool bold) { // Sets the boldness of the button text (true = bold) dbg_Print("gui_CoolButton::fontBold:(bool)", DBG_LVL_FLOW); // Stores the new data obj_fontBold = bold; // Uses the fontsize func fontSize(obj_fontSize); } //______________________________________________________________________________ bool gui_CoolButton::fontBold() const { // Returns the font size return obj_fontBold; } //______________________________________________________________________________ void gui_CoolButton::fontName(const char* name) { // Sets the boldness of the button text (true = bold) dbg_Print("gui_CoolButton::fontName:(text)", DBG_LVL_FLOW); // Stores the new data obj_fontName = name; // Uses the fontsize func fontSize(obj_fontSize); } //______________________________________________________________________________ const char* gui_CoolButton::fontName() const { // Returns the font size return obj_fontName.Data(); }