src/gui/widgets/gl/demo/w_gl_demo.cpp

Go to the documentation of this file.
00001 /*  $Id: w_gl_demo.cpp 15756 2008-01-22 16:53:29Z dicuccio $
00002  * ===========================================================================
00003  *
00004  *                            PUBLIC DOMAIN NOTICE
00005  *               National Center for Biotechnology Information
00006  *
00007  *  This software/database is a "United States Government Work" under the
00008  *  terms of the United States Copyright Act.  It was written as part of
00009  *  the author's official duties as a United States Government employee and
00010  *  thus cannot be copyrighted.  This software/database is freely available
00011  *  to the public for use. The National Library of Medicine and the U.S.
00012  *  Government have not placed any restriction on its use or reproduction.
00013  *
00014  *  Although all reasonable efforts have been taken to ensure the accuracy
00015  *  and reliability of the software and data, the NLM and the U.S.
00016  *  Government do not and cannot warrant the performance or results that
00017  *  may be obtained by using this software or data. The NLM and the U.S.
00018  *  Government disclaim all warranties, express or implied, including
00019  *  warranties of performance, merchantability or fitness for any particular
00020  *  purpose.
00021  *
00022  *  Please cite the author in any work or product based on this material.
00023  *
00024  * ===========================================================================
00025  *
00026  * Authors:  Andrey Yazhuk
00027  *
00028  * File Description:
00029  *    Demo application illustrating various components of w_gl library.
00030  */
00031 
00032 
00033 #include <ncbi_pch.hpp>
00034 
00035 #include <corelib/ncbiapp.hpp>
00036 #include <corelib/ncbiargs.hpp>
00037 #include <corelib/ncbienv.hpp>
00038 #include <corelib/ncbireg.hpp>
00039 
00040 #include "ruler_demo_panel.hpp"
00041 
00042 #include <gui/widgets/fl/tab_control.hpp>
00043 #include <gui/widgets/fl/frame_window.hpp>
00044 
00045 
00046 USING_NCBI_SCOPE;
00047 
00048 /// Commands specific for this application
00049 enum EDemoControlsCommands   {
00050     eCmdExit = 10000
00051 };
00052 
00053 
00054 class CDemoControlsClient : public  CTabControl,
00055                             public  IFrameWindowClient
00056 {
00057 public:
00058     virtual void    SetFrameWindow(CFrameWindow* frame)     {};
00059     virtual CMenuItem*    GetMenu()   {   return NULL;    };
00060     virtual void    UpdateMenu(CMenuItem& root) {};
00061 };
00062 
00063 
00064 class CWGLDemoApp : public CNcbiApplication,
00065                     public CCommandTarget // application should be able to handle commands
00066 {
00067 public:
00068     virtual void Init(void);
00069     virtual int  Run(void);
00070     virtual void Exit(void);
00071 
00072     DECLARE_EVENT_MAP();
00073 
00074     void    OnExit();
00075 
00076 protected:
00077     void    x_Create();
00078     void    x_Destroy();
00079 
00080 protected:
00081     CRef<CResourceManager>  m_ResourceManager;
00082     auto_ptr<CFrameWindow>  m_Frame;
00083     auto_ptr<CDemoControlsClient>   m_Client;
00084 
00085     auto_ptr<CRulerDemoGroup>       m_RulerGroup;
00086 };
00087 
00088 
00089 /// Event Map
00090 BEGIN_EVENT_MAP(CWGLDemoApp, CCommandTarget)
00091     ON_COMMAND(eCmdExit, &CWGLDemoApp::OnExit)
00092 END_EVENT_MAP()
00093 
00094 
00095 
00096 DEFINE_MENU(BaseMenu)
00097     SUBMENU("&File")
00098         MENU_ITEM(eCmdExit, "E&xit")
00099     END_SUBMENU()
00100 END_MENU()
00101 
00102 
00103 void CWGLDemoApp::Init(void)
00104 {
00105     auto_ptr<CArgDescriptions> arg_desc(new CArgDescriptions);
00106     arg_desc->SetUsageContext(GetArguments().GetProgramBasename(),
00107                               "w_gl demo application");
00108     SetupArgDescriptions(arg_desc.release());
00109 }
00110 
00111 
00112 int CWGLDemoApp::Run(void)
00113 {
00114     x_Create();
00115 
00116     m_Frame->show();
00117     m_RulerGroup->CreateCanvas();
00118 
00119     while( m_Frame -> shown() ){ // message loop
00120         Fl::wait();
00121     }
00122 
00123     x_Destroy();
00124     return 0;
00125 }
00126 
00127 
00128 void CWGLDemoApp::Exit(void)
00129 {
00130     SetDiagStream(0);
00131 }
00132 
00133 
00134 void  CWGLDemoApp::x_Create()
00135 {
00136     CResourceManager::CreateInstance("Z:\\Projects\\c++\\src\\gui\\res\\share\\gbench; <home>; <res>; <std>");
00137     m_ResourceManager = CResourceManager::GetInstance();
00138     CMenu::SetResourceManager(*m_ResourceManager);
00139 
00140     m_ResourceManager->RegisterAlias("menu::zoom_in", "zoom_in.png");
00141     m_ResourceManager->RegisterAlias("menu::zoom_out", "zoom_out.png");
00142 
00143     m_Frame.reset(new CFrameWindow(0, 0, 800, 600));
00144     m_Frame->end();
00145 
00146     /// create backbone of top-level menu
00147     CMenuItem* root = CreateMenuItems(BaseMenu);
00148     m_Frame->ResetMenu(*root);
00149     delete root;
00150 
00151     /// add Client and merge client menus
00152     m_Client.reset(new CDemoControlsClient());
00153     m_Client->end();
00154 
00155     m_Frame->SetClient(m_Client.get());
00156 
00157     m_Frame->AddListener(this); // let application process commands
00158 
00159     // create Tabs
00160     m_RulerGroup.reset(new CRulerDemoGroup());
00161     m_Client->AddTab(m_RulerGroup.get(), "CRuler");
00162 
00163     //AddListener(m_RulerPanel.get());
00164 
00165     m_Client->SelectTab(0);
00166 }
00167 
00168 
00169 void CWGLDemoApp::x_Destroy()
00170 {
00171     m_Frame->SetClient(NULL);
00172 }
00173 
00174 
00175 void CWGLDemoApp::OnExit()
00176 {
00177     m_Frame->hide();
00178 }
00179 
00180 
00181 /////////////////////////////////////////////////////////////////////////////
00182 //  MAIN
00183 
00184 int main(int argc, const char* argv[])
00185 {
00186     // Execute main application function
00187     return CWGLDemoApp().AppMain(argc, argv, 0, eDS_Default, 0);
00188 }
00189 
00190 

Generated on Sun Dec 6 22:31:14 2009 for NCBI C++ ToolKit by  doxygen 1.4.6
Modified on Mon Dec 07 16:21:04 2009 by modify_doxy.py rev. 173732