X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/be5a51fb592f3fa2ba38ac6cd1e488d6d806058c..6ba5438dda164146bf36ca729f8328332fae36b7:/samples/opengl/cube/cube.cpp diff --git a/samples/opengl/cube/cube.cpp b/samples/opengl/cube/cube.cpp index 19a3bfa236..66bac043e0 100644 --- a/samples/opengl/cube/cube.cpp +++ b/samples/opengl/cube/cube.cpp @@ -25,9 +25,14 @@ #include "wx/wx.h" #endif +#if !wxUSE_GLCANVAS + #error "OpenGL required: set wxUSE_GLCANVAS to 1 and rebuild the library" +#endif + #include "cube.h" +#include "../../sample.xpm" -#ifndef __WXMSW__ // for wxStopWatch, see remark below +#ifndef __WXMSW__ // for StopWatch, see remark below #if defined(__WXMAC__) && !defined(__DARWIN__) #include #include @@ -131,7 +136,7 @@ int ScanCodeDialog::GetValue() in time (in sec) (because current version of wxGetElapsedTime doesn´t works right with glibc-2.1 and linux, at least for me) -----------------------------------------------------------------------*/ -unsigned long wxStopWatch( unsigned long *sec_base ) +unsigned long StopWatch( unsigned long *sec_base ) { unsigned long secs,msec; @@ -162,8 +167,6 @@ unsigned long wxStopWatch( unsigned long *sec_base ) Implementation of Test-GLCanvas -----------------------------------------------------------------*/ -#if wxUSE_GLCANVAS - BEGIN_EVENT_TABLE(TestGLCanvas, wxGLCanvas) EVT_SIZE(TestGLCanvas::OnSize) EVT_PAINT(TestGLCanvas::OnPaint) @@ -180,7 +183,7 @@ unsigned long TestGLCanvas::m_gsynct; TestGLCanvas::TestGLCanvas(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name) - : wxGLCanvas(parent, (wxGLCanvas*) NULL, id, pos, size, style, name ) + : wxGLCanvas(parent, (wxGLCanvas*) NULL, id, pos, size, style|wxFULL_REPAINT_ON_RESIZE , name ) { m_init = false; m_gllist = 0; @@ -188,13 +191,13 @@ TestGLCanvas::TestGLCanvas(wxWindow *parent, wxWindowID id, m_rright = WXK_RIGHT; } -TestGLCanvas::TestGLCanvas(wxWindow *parent, const TestGLCanvas &other, +TestGLCanvas::TestGLCanvas(wxWindow *parent, const TestGLCanvas *other, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name ) - : wxGLCanvas(parent, other.GetContext(), id, pos, size, style, name) + : wxGLCanvas(parent, other->GetContext(), id, pos, size, style|wxFULL_REPAINT_ON_RESIZE , name) { m_init = false; - m_gllist = other.m_gllist; // share display list + m_gllist = other->m_gllist; // share display list m_rleft = WXK_LEFT; m_rright = WXK_RIGHT; } @@ -369,8 +372,8 @@ void TestGLCanvas::OnKeyDown( wxKeyEvent& event ) if (!m_TimeInitialized) { m_TimeInitialized = 1; - m_xsynct = event.m_timeStamp; - m_gsynct = wxStopWatch(&m_secbase); + m_xsynct = event.GetTimestamp(); + m_gsynct = StopWatch(&m_secbase); m_Key = evkey; m_StartTime = 0; @@ -378,7 +381,7 @@ void TestGLCanvas::OnKeyDown( wxKeyEvent& event ) m_LastRedraw = 0; } - unsigned long currTime = event.m_timeStamp - m_xsynct; + unsigned long currTime = event.GetTimestamp() - m_xsynct; if (evkey != m_Key) { @@ -391,9 +394,9 @@ void TestGLCanvas::OnKeyDown( wxKeyEvent& event ) Action( m_Key, m_LastTime-m_StartTime, currTime-m_StartTime ); #if defined(__WXMAC__) && !defined(__DARWIN__) - m_LastRedraw = currTime; // wxStopWatch() doesn't work on Mac... + m_LastRedraw = currTime; // StopWatch() doesn't work on Mac... #else - m_LastRedraw = wxStopWatch(&m_secbase) - m_gsynct; + m_LastRedraw = StopWatch(&m_secbase) - m_gsynct; #endif m_LastTime = currTime; } @@ -421,8 +424,6 @@ void TestGLCanvas::Rotate( GLfloat deg ) } -#endif // wxUSE_GLCANVAS - /* ----------------------------------------------------------------------- Main Window -------------------------------------------------------------------------*/ @@ -440,6 +441,7 @@ MyFrame::MyFrame(wxWindow *parent, const wxString& title, const wxPoint& pos, : wxFrame(parent, wxID_ANY, title, pos, size, style) { m_canvas = NULL; + SetIcon(wxIcon(sample_xpm)); } // Intercept menu commands @@ -457,11 +459,6 @@ void MyFrame::OnExit( wxCommandEvent& WXUNUSED(event) ) MyFrame *frame = new MyFrame(NULL, str, wxDefaultPosition, wxSize(400, 300)); - // Give it an icon -#ifdef __WXMSW__ - frame->SetIcon(wxIcon(_T("mondrian"))); -#endif - // Make a menubar wxMenu *winMenu = new wxMenu; @@ -477,7 +474,6 @@ void MyFrame::OnExit( wxCommandEvent& WXUNUSED(event) ) frame->SetMenuBar(menuBar); -#if wxUSE_GLCANVAS if (parentFrame) { frame->m_canvas = new TestGLCanvas( frame, parentFrame->m_canvas, @@ -488,7 +484,6 @@ void MyFrame::OnExit( wxCommandEvent& WXUNUSED(event) ) frame->m_canvas = new TestGLCanvas(frame, wxID_ANY, wxDefaultPosition, wxDefaultSize); } -#endif // Show the frame frame->Show(true); @@ -503,7 +498,6 @@ void MyFrame::OnNewWindow( wxCommandEvent& WXUNUSED(event) ) void MyFrame::OnDefRotateLeftKey( wxCommandEvent& WXUNUSED(event) ) { -#if wxUSE_GLCANVAS ScanCodeDialog dial( this, wxID_ANY, m_canvas->m_rleft, wxString(_T("Left")), _T("Define key") ); @@ -511,12 +505,10 @@ void MyFrame::OnDefRotateLeftKey( wxCommandEvent& WXUNUSED(event) ) if( result == wxID_OK ) m_canvas->m_rleft = dial.GetValue(); -#endif } void MyFrame::OnDefRotateRightKey( wxCommandEvent& WXUNUSED(event) ) { -#if wxUSE_GLCANVAS ScanCodeDialog dial( this, wxID_ANY, m_canvas->m_rright, wxString(_T("Right")), _T("Define key") ); @@ -524,7 +516,6 @@ void MyFrame::OnDefRotateRightKey( wxCommandEvent& WXUNUSED(event) ) if( result == wxID_OK ) m_canvas->m_rright = dial.GetValue(); -#endif } /*------------------------------------------------------------------ @@ -535,24 +526,8 @@ IMPLEMENT_APP(MyApp) bool MyApp::OnInit() { -#if wxUSE_LOG - wxLog::SetTraceMask(wxTraceMessages); -#endif - // Create the main frame window (void) MyFrame::Create(NULL); -#if wxUSE_GLCANVAS - return true; - -#else - - wxMessageBox( _T("This sample has to be compiled with wxUSE_GLCANVAS"), - _T("Building error"), wxOK); - - return false; - -#endif - }