+void TestGLCanvas::OnKeyDown( wxKeyEvent& event )
+{
+ long evkey = event.KeyCode();
+ if (evkey == 0) return;
+
+ if (!m_TimeInitialized)
+ {
+ m_TimeInitialized = 1;
+ m_xsynct = event.m_timeStamp;
+ m_gsynct = wxStopWatch(&m_secbase);
+
+ m_Key = evkey;
+ m_StartTime = 0;
+ m_LastTime = 0;
+ m_LastRedraw = 0;
+ }
+
+ unsigned long currTime = event.m_timeStamp - m_xsynct;
+
+ if (evkey != m_Key)
+ {
+ m_Key = evkey;
+ m_LastRedraw = m_StartTime = m_LastTime = currTime;
+ }
+
+ if (currTime >= m_LastRedraw) // Redraw:
+ {
+ Action( m_Key, m_LastTime-m_StartTime, currTime-m_StartTime );
+
+ m_LastRedraw = wxStopWatch(&m_secbase) - m_gsynct;
+ m_LastTime = currTime;
+ }
+
+ event.Skip();
+}
+
+void TestGLCanvas::OnKeyUp( wxKeyEvent& event )
+{
+ m_Key = 0;
+ m_StartTime = 0;
+ m_LastTime = 0;
+ m_LastRedraw = 0;
+
+ event.Skip();
+}
+
+void TestGLCanvas::Rotate( GLfloat deg )
+{
+ SetCurrent();
+
+ glMatrixMode(GL_MODELVIEW);
+ glRotatef((GLfloat)deg, 0.0F, 0.0F, 1.0F);
+ Refresh(FALSE);
+}
+
+
+/* -----------------------------------------------------------------------
+ Main Window
+-------------------------------------------------------------------------*/
+
+BEGIN_EVENT_TABLE(MyFrame, wxFrame)
+ EVT_MENU(wxID_EXIT, MyFrame::OnExit)
+ EVT_MENU( ID_NEW_WINDOW, MyFrame::OnNewWindow)
+ EVT_MENU( ID_DEF_ROTATE_LEFT_KEY, MyFrame::OnDefRotateLeftKey)
+ EVT_MENU( ID_DEF_ROTATE_RIGHT_KEY, MyFrame::OnDefRotateRightKey)
+END_EVENT_TABLE()
+
+// My frame constructor
+MyFrame::MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos,
+ const wxSize& size, long style)
+ : wxFrame(frame, -1, title, pos, size, style)
+{
+ m_canvas = NULL;
+}
+
+// Intercept menu commands
+void MyFrame::OnExit(wxCommandEvent& event)
+{
+ Destroy();
+}
+
+void MyFrame::OnNewWindow()
+{
+ MyFrame *frame = new MyFrame(NULL, "Cube OpenGL Demo Clone",
+ wxPoint(50, 50), wxSize(400, 300));
+ // Give it an icon
+#ifdef wx_msw
+ frame->SetIcon(wxIcon("mondrian"));
+#endif
+
+ // Make a menubar
+ wxMenu *winMenu = new wxMenu;
+
+ winMenu->Append(wxID_EXIT, "&Close");
+ winMenu->Append(ID_NEW_WINDOW, "&New" );
+ wxMenuBar *menuBar = new wxMenuBar;
+ menuBar->Append(winMenu, "&Window");
+
+ winMenu = new wxMenu;
+ winMenu->Append(ID_DEF_ROTATE_LEFT_KEY, "Rotate &left");
+ winMenu->Append(ID_DEF_ROTATE_RIGHT_KEY, "Rotate &right");
+ menuBar->Append(winMenu, "&Key");
+
+ frame->SetMenuBar(menuBar);
+
+ frame->m_canvas = new TestGLCanvas( frame, *m_canvas, -1,
+ wxPoint(0, 0), wxSize(200, 200) );
+
+ // Show the frame
+ frame->Show(TRUE);
+}
+
+void MyFrame::OnDefRotateLeftKey()
+{
+ ScanCodeDialog dial( this, -1, m_canvas->m_rleft,
+ wxString("Left"), "Define key" );
+ int result = dial.ShowModal();
+ if( result == wxID_OK )
+ m_canvas->m_rleft = dial.GetValue();
+}
+void MyFrame::OnDefRotateRightKey()
+{
+ ScanCodeDialog dial( this, -1, m_canvas->m_rright,
+ wxString("Right"), "Define key" );
+ int result = dial.ShowModal();
+ if( result == wxID_OK )
+ m_canvas->m_rright = dial.GetValue();
+}
+
+/*------------------------------------------------------------------
+ Application object ( equivalent to main() )
+------------------------------------------------------------------ */
+
+IMPLEMENT_APP(MyApp)
+
+bool MyApp::OnInit(void)
+{
+ wxLog::SetTraceMask(wxTraceMessages);
+
+ // Create the main frame window
+ MyFrame *frame = new MyFrame(NULL, "Cube OpenGL Demo", wxPoint(50, 50),
+ wxSize(400, 300));
+ // Give it an icon
+#ifdef wx_msw
+ frame->SetIcon(wxIcon("mondrian"));
+#endif
+
+ // Make a menubar
+ wxMenu *winMenu = new wxMenu;
+
+ winMenu->Append(wxID_EXIT, "&Close");
+ winMenu->Append(ID_NEW_WINDOW, "&New" );
+ wxMenuBar *menuBar = new wxMenuBar;
+ menuBar->Append(winMenu, "&Window");
+
+ winMenu = new wxMenu;
+ winMenu->Append(ID_DEF_ROTATE_LEFT_KEY, "Rotate &left");
+ winMenu->Append(ID_DEF_ROTATE_RIGHT_KEY, "Rotate &right");
+ menuBar->Append(winMenu, "&Key");
+
+ frame->SetMenuBar(menuBar);
+
+ frame->m_canvas = new TestGLCanvas(frame, -1, wxPoint(0, 0), wxSize(200, 200));
+
+ // Show the frame
+ frame->Show(TRUE);
+
+ return TRUE;
+}