//------------------------------------------------------------------------------ // gui object base class -- // (C) Piero Giubilato 2008-2010, Berkeley Lab -- //------------------------------------------------------------------------------ //______________________________________________________________________________ // {Trace} // [File name] "gui_Object.cpp" // [Author] "Piero Giubilato" // [Version] "1.0" // [Modified by] "Piero Giubilato, Devis Contarato" // [Last revision] "01 Feb 2009" // [Language] "C++" // [Compiler] "Visual C++ 8.x 9.x" // [Member of] "Cool SEAL" // [Project] "SEAL" // [Description] "gui_Object class definition" // [Key documentation] // "Visual C++ Reference Help" // "Root reference guide" // {Trace} //______________________________________________________________________________ // Root Component #include // Application component #include "global.h" #include "gui_Const.h" #include "gui_Main.h" #include "gui_Object.h" // CINT Preprocessor class import definition ClassImp(gui_Object) //______________________________________________________________________________ // Static member declaration std::vector gui_Object::gui_obj_Is; std::vector gui_Object::gui_obj_Ref; bool gui_Object::redraw_all_On = false; bool gui_Object::update_auto_On = true; //______________________________________________________________________________ gui_Object::gui_Object() { // Default constructor. gui_Object provides a common interface for all // gui objects, so it is composed mainly by virtual declarations plus // some commons control mechanism. dbg_Print("gui_Object::gui_Object:(default)", DBG_LVL_ZERO); // Checks for present status of objects IDs list gui_obj_Id = 0; while (gui_obj_Id < gui_obj_Is.size()) { if (!gui_obj_Is[gui_obj_Id]) break; gui_obj_Id++; } // Registers current object own Id if (gui_obj_Id == gui_obj_Is.size()) gui_obj_Is.push_back(true); else gui_obj_Is[gui_obj_Id] = true; // Register current object reference if (gui_obj_Id == gui_obj_Ref.size()) gui_obj_Ref.push_back(this); else gui_obj_Ref[gui_obj_Id] = this; // Creates the string version of the object Id gui_obj_id_Text.Form("%i", gui_obj_Id); // Store the reference to the main graphical window frame_Main = gui_Main::frame_Main(); // Retrives and stores the current graphical container (basically, the // TGCompositeFrame provided by the gui_Master interface). frame_Draw = gui_Main::frame_Draw(); mnu_Bar = gui_Main::menu_Bar(); // Initializes the callback functor to null Clbk = 0; // Sets default properties obj_Left = 0; obj_Top = 0; obj_Width = 64; obj_Height = 32; obj_foreColor = gui_Const::obj_foreColor; obj_backColor = gui_Const::obj_backColor; obj_Transparent = false; obj_Render = false; // Text obj_Text.Form("Text"); obj_fontName.Form("Helvetica"); obj_fontBold = false; obj_fontSize = 16; // Sets TGLabel pointer to NULL gui_obj_Label = NULL; } //______________________________________________________________________________ gui_Object::~gui_Object() { // Default destructor. dbg_Print("gui_Object::~gui_Object:()", DBG_LVL_ZERO); // Deletes the callback functor(s) in case if (Clbk) delete Clbk; // Delete the label, if any if(gui_obj_Label) { Container()->RemoveFrame(gui_obj_Label); gui_obj_Label->DestroyWindow(); delete gui_obj_Label; } // Sets the object as killed! gui_obj_Is[gui_obj_Id] = false; gui_obj_Ref[gui_obj_Id] = NULL; } //______________________________________________________________________________ UInt_t gui_Object::obj_Id() const { // Returns the unique object Id return gui_obj_Id; } //______________________________________________________________________________ const TString gui_Object::obj_id_Text() const { // Returns the unique object Id as a TString return gui_obj_id_Text; } //______________________________________________________________________________ TGMainFrame* gui_Object::Window() const { // Returns the pointer to the graphic main frame (main window) return frame_Main; } //______________________________________________________________________________ TGCompositeFrame* gui_Object::Container() const { // Returns the pointer to the object graphics container. return frame_Draw; } //______________________________________________________________________________ TGMenuBar* gui_Object::container_Menu() const { // Returns the pointer to the main menu bar. return mnu_Bar; } //______________________________________________________________________________ UInt_t gui_Object::container_Color() const { // Returns the container "theorethical" background color. i.e. the color // before the rendering procedure! return gui_obj_Ref[0]->backColor(); } //______________________________________________________________________________ void gui_Object::update_Auto(bool state) { // Sets the auto update function on and off. Basically, when auto update // is TRUE (default at startup), every time a property of a gui_Object is // changed the entire windows is refreshed to show the new object appearance. // If auto update is set to FALSE, the update function has to be called in // order to refresh the window. dbg_Print("gui_Object::auto_update_Set:(bool)", DBG_LVL_FLOW); // Set he value! update_auto_On = state; } //______________________________________________________________________________ void gui_Object::Update(bool force) const { // This is called by single-object when one of its appearance setting is // modified and hence the object needs to be redrawn. if ((!redraw_all_On && update_auto_On) || force) { // Debug dbg_Print("gui_Object::update:()", DBG_LVL_FLOW); // Repaints the object (except that for object 0, the container itself) if (gui_obj_Id) Container()->MapSubwindows(); } } //______________________________________________________________________________ void gui_Object::redraw_All() { // Regenerates all the objects who have interaction with the // main gui parameters dbg_Print("gui_Object::redraw_All:()", DBG_LVL_FLOW); // Stop the single object update redraw_all_On = true; // Search trhough all the objects. Note how object #0 is gui_Main itself, // so it is skipped by default (loop starts at 1) for (UInt_t i = 1; i < gui_obj_Is.size(); i++) { if (gui_obj_Is[i]) { gui_obj_Ref[i]->ReDraw(); } } // Refreshes the main window redraw_all_On = false; } //______________________________________________________________________________ void gui_Object::ReDraw() { // Virtual function. This is called whrn the GUI appearance general // parameters (background color, light direction, ...) are changed, and // so GUI objects using them must be redrawn. // Overload it for object which needs it! dbg_Print("gui_Object::ReDraw:()", DBG_LVL_FLOW); } //______________________________________________________________________________ void gui_Object::delete_All() { // Delete all objects exept the #0 dbg_Print("gui_Object::delete_All:()", DBG_LVL_FLOW); // Search trhough all the objects. Note how object #0 is gui_Main itself, // so it is skipped by default (loop starts at 1) for (UInt_t i = 1; i < gui_obj_Is.size(); i++) { gui_obj_Is[i] = false; delete gui_obj_Ref[i]; } } //______________________________________________________________________________ void gui_Object::Move(UInt_t left, UInt_t top) { // Moves the object MoveResize(left, top, obj_Width, obj_Height); } //______________________________________________________________________________ void gui_Object::Resize(UInt_t width, UInt_t height) { // Resizes the object MoveResize(obj_Left, obj_Top, width, height); } //______________________________________________________________________________ UInt_t gui_Object::Left() const { // Returns the object lef position return obj_Left; } //______________________________________________________________________________ UInt_t gui_Object::Top() const { // Returns the object top position return obj_Top; } //______________________________________________________________________________ UInt_t gui_Object::Width() const { // Returns the object width return obj_Width; } //______________________________________________________________________________ UInt_t gui_Object::Height() const { // Returns the object height return obj_Height; } //______________________________________________________________________________ void gui_Object::foreColor(UInt_t color) { // Sets the object foreground color color_Set(color, obj_backColor); } //______________________________________________________________________________ void gui_Object::backColor(UInt_t color) { // Sets the object background color color_Set(obj_foreColor, color); } //______________________________________________________________________________ UInt_t gui_Object::foreColor() const { // Returns the object foreground color return obj_foreColor; } //______________________________________________________________________________ UInt_t gui_Object::backColor() const { // Returns the object background color return obj_backColor; } //______________________________________________________________________________ bool gui_Object::Transparent() const { // Returns the object background color return obj_Transparent; } //______________________________________________________________________________ bool gui_Object::Render() const { // Returns the object background color return obj_Render; } //______________________________________________________________________________ const TString gui_Object::Text() const { // Returns the object text return obj_Text; } //______________________________________________________________________________ bool gui_Object::fontBold() const { // Returns the font-boldness return obj_fontBold; } //______________________________________________________________________________ UInt_t gui_Object::fontSize() const { // Returns the font-boldness return obj_fontSize; } //______________________________________________________________________________ const char* gui_Object::fontName() const { // Returns the font-boldness return obj_fontName.Data(); } //______________________________________________________________________________ void gui_Object::label_Set(const char* labelText, UInt_t align, UInt_t foreColor, UInt_t backColor) { // Sets a label to be put around the widget dbg_Print("gui_Object::label_Set:(default)", DBG_LVL_MAKE); // Allow only one label per object if(!gui_obj_Label ){ gui_obj_Label = new TGLabel(Container(), labelText); Container()->AddFrame(gui_obj_Label, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0)); // The horizontal and vertical reference coordinates UInt_t hanchor, vanchor; // Sets label positioning from object dimensions according to align parameter; // hanchor and vanchor are the horizontal and vertical coordinates of the label anchor point switch(align) { // Left | Top = 4 case (gui_Const::align_Left + gui_Const::align_Top) : hanchor = Left(); vanchor = Top() - Height() + (UInt_t)(0.5 * gui_obj_Label->GetDefaultHeight()); break; // Center | Top = 5 case (gui_Const::align_Center + gui_Const::align_Top) : hanchor = Left() + (UInt_t)(0.5*Width()) - (UInt_t)(0.5*gui_obj_Label->GetDefaultWidth()); vanchor = Top() - Height() + (UInt_t)(0.5 * gui_obj_Label->GetDefaultHeight()); break; // Right | Top = 6 case (gui_Const::align_Right + gui_Const::align_Top) : hanchor = Left() + Width() + gui_Const::lbl_offset_Right; vanchor = Top() - Height() + (UInt_t)(0.5 * gui_obj_Label->GetDefaultHeight()); break; // Left | Middle = 8 case (gui_Const::align_Left + gui_Const::align_Middle) : hanchor = Left() - gui_obj_Label->GetDefaultWidth() - gui_Const::lbl_offset_Left; vanchor = Top() + (UInt_t)(0.5 * Height()) - (UInt_t)(0.5 * gui_obj_Label->GetDefaultHeight()); break; // Right | Middle = 10 case (gui_Const::align_Right + gui_Const::align_Middle) : hanchor = Left() + Width() + gui_Const::lbl_offset_Right; vanchor = Top() + (UInt_t)(0.5 * Height()) - (UInt_t)(0.5 * gui_obj_Label->GetDefaultHeight()); break; // Left | Bottom = 16 case (gui_Const::align_Left + gui_Const::align_Bottom) : hanchor = Left(); vanchor = Top() + Height(); break; // Center | Bottom = 17 case (gui_Const::align_Center + gui_Const::align_Bottom) : hanchor = Left() + (UInt_t)(0.5 * Width()) - (UInt_t)(0.5 * gui_obj_Label->GetDefaultWidth()); vanchor = Top() + Height(); break; // Right | Bottom = 18 case (gui_Const::align_Right + gui_Const::align_Bottom) : hanchor = Left() + Width() + gui_Const::lbl_offset_Right; vanchor = Top() + Height(); break; // Default; set equal to left and top default : hanchor = Left(); vanchor = Top() - Height() + (UInt_t)(0.5 * gui_obj_Label->GetDefaultHeight()); break; } // Move the label in place gui_obj_Label->Move(hanchor, vanchor); // Sets label color, if they are not provided uses the object colors if (foreColor <= 0xFFFFFF) gui_obj_Label->SetForegroundColor(foreColor); else gui_obj_Label->SetForegroundColor(this->foreColor()); if (backColor <= 0xFFFFFF) gui_obj_Label->SetBackgroundColor(backColor); else gui_obj_Label->SetBackgroundColor(Container()->GetBackground()); } else { // Warning dbg_Print("Label already defined", DBG_LVL_WARN); } }