test_client.cpp
来自「ncbi源码」· C++ 代码 · 共 263 行
CPP
263 行
/* * =========================================================================== * PRODUCTION $Log: test_client.cpp,v $ * PRODUCTION Revision 1000.1 2004/06/01 21:14:45 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.6 * PRODUCTION * =========================================================================== *//* $Id: test_client.cpp,v 1000.1 2004/06/01 21:14:45 gouriano Exp $ * =========================================================================== * * PUBLIC DOMAIN NOTICE * National Center for Biotechnology Information * * This software/database is a "United States Government Work" under the * terms of the United States Copyright Act. It was written as part of * the author's official duties as a United States Government employee and * thus cannot be copyrighted. This software/database is freely available * to the public for use. The National Library of Medicine and the U.S. * Government have not placed any restriction on its use or reproduction. * * Although all reasonable efforts have been taken to ensure the accuracy * and reliability of the software and data, the NLM and the U.S. * Government do not and cannot warrant the performance or results that * may be obtained by using this software or data. The NLM and the U.S. * Government disclaim all warranties, express or implied, including * warranties of performance, merchantability or fitness for any particular * purpose. * * Please cite the author in any work or product based on this material. * * =========================================================================== * * Authors: Andrey Yazhuk * * File Description: * */#include <ncbi_pch.hpp>#include <gui/widgets/workspace/test_client.hpp>#include <FL/Fl.H>BEGIN_NCBI_SCOPEstatic int s_iColor = 0;const static int kColors = 4;static Fl_Color GetRandomColor(){ s_iColor = (s_iColor + 1) % kColors; switch(s_iColor) { case 0: return fl_rgb_color(128, 128, 255); case 1: return fl_rgb_color(255, 128, 128); case 2: return fl_rgb_color(128, 255, 128); case 3: return fl_rgb_color(255, 128, 255); } return FL_MAGENTA;}/////////////////////////////////////////////////////////////////////////////////// CFLTestClient CFLTestClient::CFLTestClient(int type, const char* slabel): Fl_Box(0, 0, 0, 0, 0), m_Label(slabel), m_Type(type){ m_StateLabel = m_Label; label(m_StateLabel.c_str()); color(GetRandomColor()); box(FL_FLAT_BOX); m_MenuRoot = new CMenuItem("Root"); CMenuItem* submenu = m_MenuRoot->AddSubMenu("Commands"); submenu->AddSubItem("Test", eCmdTest); string s = "Test " + NStr::IntToString(m_Type); submenu->AddSubItem(s, eCmdTest + m_Type);}CFLTestClient::~CFLTestClient(){ delete m_MenuRoot;}string CFLTestClient::GetLabel(void) const { return m_Label; }BEGIN_CMD_MAP(CFLTestClient, CCommandTarget) ON_COMMAND_RANGE(eCmdTest, eCmdTest3, &CFLTestClient::OnTest) ON_UPDATE_COMMAND_UI_RANGE(eCmdTest, eCmdTest3, &CFLTestClient::OnUpdateTest)END_CMD_MAP()int CFLTestClient::handle(int event){ switch(event) { case FL_FOCUS: { m_StateLabel = m_Label + " FOCUSED"; label(m_StateLabel.c_str()); redraw(); return true; } case FL_UNFOCUS: { m_StateLabel = m_Label; label(m_StateLabel.c_str()); redraw(); return true; } case FL_PUSH: { if(Fl::focus() != static_cast<Fl_Widget*>(this)) { take_focus(); } } }; return Fl_Box::handle(event);} void CFLTestClient::OnTest(TCmdID cmd){ if(cmd == eCmdTest1 || cmd == (eCmdTest + m_Type)) { cout << "\nOnTest() cmd = eCmdTest" << (cmd - eCmdTest); }}// clients handles two commands: eCmdTest and (eCmdTest + m_Type)void CFLTestClient::OnUpdateTest(ICmdUI* pCmdUI){ TCmdID cmd = pCmdUI->GetCommand(); pCmdUI->Enable(cmd == eCmdTest || cmd == (eCmdTest + m_Type));}/////////////////////////////////////////////////////////////////////////////////// CGLTestClient CGLTestClient::CGLTestClient(int type, const char* slabel): CGlCanvas2d(0, 0, 0, 0, 0), m_Label(slabel), m_Type(type), m_Font(CGlBitmapFont::eHelvetica18){ label(m_Label.c_str()); m_Color = GetRandomColor(); m_StateLabel = m_Label; m_MenuRoot = new CMenuItem("Root"); CMenuItem* submenu = m_MenuRoot->AddSubMenu("Commands"); submenu->AddSubItem("Test", eCmdTest); string s = "Test " + NStr::IntToString(m_Type); submenu->AddSubItem(s, eCmdTest + m_Type);}CGLTestClient::~CGLTestClient(){ delete m_MenuRoot;}BEGIN_CMD_MAP(CGLTestClient, CCommandTarget) ON_COMMAND_RANGE(eCmdTest, eCmdTest3, &CGLTestClient::OnTest) ON_UPDATE_COMMAND_UI_RANGE(eCmdTest, eCmdTest3, &CGLTestClient::OnUpdateTest)END_CMD_MAP()int CGLTestClient::handle(int event){ switch(event) { case FL_FOCUS: { m_StateLabel = m_Label + " FOCUSED"; redraw(); return true; } case FL_UNFOCUS: { m_StateLabel = m_Label; redraw(); return true; } case FL_PUSH: { if(Fl::focus() != static_cast<Fl_Widget*>(this)) { take_focus(); } } }; return CGlCanvas2d::handle(event);} void CGLTestClient::OnTest(TCmdID cmd){ if(cmd == eCmdTest1 || cmd == (eCmdTest + m_Type)) { cout << "\nOnTest() cmd = eCmdTest" << (cmd - eCmdTest); }}// clients handles two commands: eCmdTest and (eCmdTest + m_Type)void CGLTestClient::OnUpdateTest(ICmdUI* pCmdUI){ TCmdID cmd = pCmdUI->GetCommand(); pCmdUI->Enable(cmd == eCmdTest || cmd == (eCmdTest + m_Type));}string CGLTestClient::GetLabel(void) const { return m_Label; }void CGLTestClient::draw(void){ glClearColor(1.0, 1.0, 1.0, 1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); CGlPane pane; pane.SetViewport(TVPRect(0, 0, w(), h())); pane.SetModelLimitsRect(TModelRect(0,0,1,1)); pane.ZoomAll(); pane.OpenOrtho(); glColorC(m_Color); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glRectd(0.1, 0.1, 0.9, 0.9); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glRectd(0.2, 0.2, 0.8, 0.8); glColor3i(0, 0, 0); m_Font.TextOut(0.15f, 0.5f, m_Label.c_str()); pane.Close();}END_NCBI_SCOPE/* * =========================================================================== * $Log: test_client.cpp,v $ * Revision 1000.1 2004/06/01 21:14:45 gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.6 * * Revision 1.6 2004/05/21 22:27:56 gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.5 2004/05/13 17:32:22 yazhuk * Extended CGLClient to support command handling * * Revision 1.4 2004/05/07 14:23:04 yazhuk * Extended CLTestClient to implement IWMClient and support command handling * * Revision 1.3 2004/02/18 02:21:34 ucko * Remove the remaining use of PolyMode (no longer declared...) * * Revision 1.2 2004/02/17 15:22:19 yazhuk * Refactoring - removed CGlParam * * Revision 1.1 2004/02/04 19:42:01 yazhuk * Initial revision * * =========================================================================== */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?