//------------------------------------------------------------------------------ // Application main gui form -- // (C) Piero Giubilato 2008-2010, Berkeley Lab -- //------------------------------------------------------------------------------ //______________________________________________________________________________ // {Trace} // [File name] "gui_Main.cpp" // [Author] "Piero Giubilato" // [Version] "1.2" // [Modified by] "Piero Giubilato" // [Last revision] "13 Jul 2009" // [Language] "C++" // [Compiler] "Visual C++ 9.x" // [Member of] "Cool SEAL" // [Project] "SEAL" // [Description] "Application main gui form." // [Key documentation] // "Root user's guide, writing a graphical interface" // "Visual C++ Reference Help" // {Trace} //______________________________________________________________________________ // Standard libraries // Root components #include #include #include // Application components #include "global.h" #include "gui_Const.h" #include "gso_Shaper.h" #include "gui_Main.h" // Graphics components #include "ico_seal_32.xpm" // The application icon (ico_seal_32) #include "about.xpm" // The about test icon // CINT Preprocessor class import definition ClassImp(gui_Main) //______________________________________________________________________________ // Static members instantiation // Singleton gui_Main* gui_Main::inst_Handle = 0; // No instances int gui_Main::inst_Count = 0; // No instances // Interface elements TGMainFrame* gui_Main::frm_Main = NULL; // The frame window itself TGCanvas* gui_Main::tgc_Draw = NULL; // The whiteboard TG canvas TGCompositeFrame* gui_Main::tgf_Draw; // The whiteboard container // Menus TGMenuBar* gui_Main::mnu_Main; // The main menu bar //______________________________________________________________________________ // Provides a safe self-destruction mechanism in case of missed destruction class GuiCleaner { public: ~GuiCleaner() {gui_Main::instance_Destroy();} } GuiCleanerInst; //______________________________________________________________________________ gui_Main* gui_Main::instance_Load(const TGWindow* p, UInt_t w, UInt_t h) { // Loads one instance of the class dbg_Print("gui_Main::instance_Load:(default)", DBG_LVL_ZERO); // Just loads one class instance if (inst_Count == 0) { inst_Handle = new gui_Main(p, w, h); inst_Count ++; } // Returns the instance handle return inst_Handle; } //______________________________________________________________________________ void gui_Main::instance_Destroy() { // Kills the active instance dbg_Print("gui_Main::instance_Destroy:(default)", DBG_LVL_ZERO); // Deletes the current class instance if (inst_Handle) { inst_Handle = 0; inst_Count = 0; } } //______________________________________________________________________________ gui_Main::gui_Main(const TGWindow *p, UInt_t w, UInt_t h): gui_Object(0) { // Starts the application main graphic user interface (GUI) dbg_Print("gui_Main::gui_Main:(default)", DBG_LVL_ZERO); // Sets up OpenGL support gStyle->SetCanvasPreferGL(true); // Creates the main frame. A TGMainFrame is a top level window. frm_Main = new TGMainFrame(p, w, h, kVerticalFrame); // Title the main windows frm_Main->SetWindowName("Cool SEAL 1.0 beta"); // Icon frm_Main->SetIconPixmap(ico_seal_32); // Connects the close request to the close handler frm_Main->Connect(frm_Main, "CloseWindow()", "gui_Main", this, "do_frm_Close()"); // Tells the frame to do not automatically close frm_Main->DontCallClose(); // Set up all the subwindows frm_main_Menu(); frm_main_Frame(); // Show up! frm_Main->MapSubwindows(); // Makes all sub-frames effective frm_Main->Resize(frm_Main->GetDefaultSize()); frm_Main->MapWindow(); frm_Main->Resize(640, 480); } //______________________________________________________________________________ gui_Main::~gui_Main() { // Standard destructor dbg_Print("gui_Main::~gui_Main:()", DBG_LVL_ZERO); // Deleting the main windows triggers the deletion of all subwindows frm_Main->DeleteWindow(); // deletes fMain } //______________________________________________________________________________ void gui_Main::do_frm_Close() { // Closes the graphical interface dbg_Print("gui_Main::do_frm_Close()", DBG_LVL_FLOW); // Closes the application interpreter gApplication->Terminate(0); } //______________________________________________________________________________ void gui_Main::frm_main_Menu() { // Sets all all the menus dbg_Print("gui_Main::frm_main_Menu()", DBG_LVL_MAKE); // Creates the main menu bar mnu_Main = new TGMenuBar(frm_Main, 100, 20, kHorizontalFrame); frm_Main->AddFrame(mnu_Main, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX, 0, 0, 0, 0)); } //______________________________________________________________________________ void gui_Main::frm_main_Frame() { // Creates the main window sub-frame (TGCompositeFrame inside a TGCanvas). dbg_Print("gui_Main::frm_main_Frame()", DBG_LVL_MAKE); // Creates the frame where to place the drawing canvas (whiteboard). This // allows to exploit a wider-than-screen working space where to place // graphics output tgc_Draw = new TGCanvas(frm_Main, 256, 256); tgf_Draw = new TGCompositeFrame(tgc_Draw->GetViewPort(), 1600, 800, kHorizontalFrame | kFixedSize); tgf_Draw->SetLayoutManager(new TGTileLayout(tgf_Draw, 0)); tgf_Draw->SetBackgroundColor(Pixel_t(0x777777)); tgf_Draw->SetLayoutBroken(kTRUE); // Sets the container operative tgc_Draw->GetViewPort()->AddFrame(tgf_Draw, new TGLayoutHints(kFixedSize)); tgf_Draw->MapSubwindows(); tgc_Draw->SetContainer(tgf_Draw); tgc_Draw->MapSubwindows(); // Adds the frame container to the main window frm_Main->AddFrame(tgc_Draw, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, gui_Const::frm_Border, gui_Const::frm_Border, gui_Const::frm_Border, gui_Const::frm_Border)); // Test tgc_Draw->MapSubwindows(); tgc_Draw->MapWindow(); } //______________________________________________________________________________ TGCompositeFrame* gui_Main::Window() const { // Overload the original gui_Object one as gui_Main // provides container capabilities return tgf_Draw; } //______________________________________________________________________________ TGMenuBar* gui_Main::menu_Window() const { // Overload the original gui_Object one as gui_Main // provides menu handling capabilities return mnu_Main; } //______________________________________________________________________________ void gui_Main::Update(bool force) const { // In that case (obj 0), force is ignored tgc_Draw->MapSubwindows(); tgc_Draw->MapWindow(); } //______________________________________________________________________________ void gui_Main::title_Set(const char* title) { // Sets the drawing board dimensions dbg_Print("gui_Main::title_Set:(const char*)", DBG_LVL_MAKE); // Set title frm_Main->SetWindowName(title); } //______________________________________________________________________________ void gui_Main::size_Set(UInt_t width, UInt_t height) { // Sets the drawing board dimensions dbg_Print("gui_Main::size_Set:(UInt, UInt)", DBG_LVL_MAKE); // Saves th enew dimensions gui_Object::obj_Width = width; gui_Object::obj_Height = height; // Resizes tgf_Draw->Resize(width, height); } //______________________________________________________________________________ void gui_Main::color_Set(UInt_t foreColor, UInt_t backColor) { // Sets foreground and background default colors dbg_Print("gui_Main::color_Set:(UInt, UInt)", DBG_LVL_MAKE); // Saves the color gui_Object::obj_backColor = backColor; gui_Object::obj_foreColor = foreColor; // Computes the resulting surface color UInt_t backRendered; gso_Shaper::map_Pixel(&backRendered, backColor); // Eventually sets the color! tgf_Draw->SetBackgroundColor(backRendered); // Makes color effective, even considering sub object transparencies // This basically means a redraw of every transparent/render object gui_Object::redraw_All(); // Still R&D tgf_Draw->Resize(tgf_Draw->GetDefaultSize()); //frm_Main->Resize(frm_Main->GetDefaultSize()); frm_Main->MapWindow(); frm_Main->MapSubwindows(); //tgf_Draw->MapWindow(); tgf_Draw->MapSubwindows(); ////tgf_Draw->MapSubwindows(); ////gSystem->ProcessEvents(); } //______________________________________________________________________________ void gui_Main::delete_All() { // Kills all the gui objects except the main itself dbg_Print("gui_Main::delete_All:()", DBG_LVL_MAKE); // Destroys all the objects gui_Object::delete_All(); //tgf_Draw->MapSubwindows(); gSystem->ProcessEvents(); } //______________________________________________________________________________ void gui_Main::Quit() { // Kills all the gui objects except the main itself dbg_Print("gui_Main::quit:()", DBG_LVL_MAKE); // Kill whatever gui delete_All(); // Kill itself (bye bye!) do_frm_Close(); }