]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: cube.cpp | |
3 | // Purpose: wxGLCanvas demo program | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #if defined(__GNUG__) && !defined(__APPLE__) | |
13 | #pragma implementation | |
14 | #pragma interface | |
15 | #endif | |
16 | ||
17 | // For compilers that support precompilation, includes "wx.h". | |
18 | #include "wx/wxprec.h" | |
19 | ||
20 | #ifdef __BORLANDC__ | |
21 | #pragma hdrstop | |
22 | #endif | |
23 | ||
24 | #ifndef WX_PRECOMP | |
25 | #include "wx/wx.h" | |
26 | #endif | |
27 | ||
28 | #if !wxUSE_GLCANVAS | |
29 | #error "OpenGL required: set wxUSE_GLCANVAS to 1 and rebuild the library" | |
30 | #endif | |
31 | ||
32 | #include "cube.h" | |
33 | ||
34 | #ifndef __WXMSW__ // for wxStopWatch, see remark below | |
35 | #if defined(__WXMAC__) && !defined(__DARWIN__) | |
36 | #include <utime.h> | |
37 | #include <unistd.h> | |
38 | #else | |
39 | #include <sys/time.h> | |
40 | #include <sys/unistd.h> | |
41 | #endif | |
42 | #else | |
43 | #include <sys/timeb.h> | |
44 | #endif | |
45 | ||
46 | #define ID_NEW_WINDOW 10000 | |
47 | #define ID_DEF_ROTATE_LEFT_KEY 10001 | |
48 | #define ID_DEF_ROTATE_RIGHT_KEY 10002 | |
49 | ||
50 | /*---------------------------------------------------------- | |
51 | Control to get a keycode | |
52 | ----------------------------------------------------------*/ | |
53 | class ScanCodeCtrl : public wxTextCtrl | |
54 | { | |
55 | public: | |
56 | ScanCodeCtrl( wxWindow* parent, wxWindowID id, int code, | |
57 | const wxPoint& pos, const wxSize& size ); | |
58 | ||
59 | void OnChar( wxKeyEvent& WXUNUSED(event) ) | |
60 | { | |
61 | // Do nothing | |
62 | } | |
63 | ||
64 | void OnKeyDown(wxKeyEvent& event); | |
65 | ||
66 | private: | |
67 | ||
68 | // Any class wishing to process wxWidgets events must use this macro | |
69 | DECLARE_EVENT_TABLE() | |
70 | }; | |
71 | ||
72 | BEGIN_EVENT_TABLE( ScanCodeCtrl, wxTextCtrl ) | |
73 | EVT_CHAR( ScanCodeCtrl::OnChar ) | |
74 | EVT_KEY_DOWN( ScanCodeCtrl::OnKeyDown ) | |
75 | END_EVENT_TABLE() | |
76 | ||
77 | ScanCodeCtrl::ScanCodeCtrl( wxWindow* parent, wxWindowID id, int code, | |
78 | const wxPoint& pos, const wxSize& size ) | |
79 | : wxTextCtrl( parent, id, wxEmptyString, pos, size ) | |
80 | { | |
81 | SetValue( wxString::Format(wxT("0x%04x"), code) ); | |
82 | } | |
83 | ||
84 | void ScanCodeCtrl::OnKeyDown( wxKeyEvent& event ) | |
85 | { | |
86 | SetValue( wxString::Format(wxT("0x%04x"), event.GetKeyCode()) ); | |
87 | } | |
88 | ||
89 | /*------------------------------------------------------------------ | |
90 | Dialog for defining a keypress | |
91 | -------------------------------------------------------------------*/ | |
92 | ||
93 | class ScanCodeDialog : public wxDialog | |
94 | { | |
95 | public: | |
96 | ScanCodeDialog( wxWindow* parent, wxWindowID id, const int code, | |
97 | const wxString &descr, const wxString& title ); | |
98 | int GetValue(); | |
99 | ||
100 | private: | |
101 | ||
102 | ScanCodeCtrl *m_ScanCode; | |
103 | wxTextCtrl *m_Description; | |
104 | }; | |
105 | ||
106 | ScanCodeDialog::ScanCodeDialog( wxWindow* parent, wxWindowID id, | |
107 | const int code, const wxString &descr, const wxString& title ) | |
108 | : wxDialog( parent, id, title, wxDefaultPosition, wxSize(96*2,76*2) ) | |
109 | { | |
110 | new wxStaticText( this, wxID_ANY, _T("Scancode"), wxPoint(4*2,3*2), | |
111 | wxSize(31*2,12*2) ); | |
112 | m_ScanCode = new ScanCodeCtrl( this, wxID_ANY, code, wxPoint(37*2,6*2), | |
113 | wxSize(53*2,14*2) ); | |
114 | ||
115 | new wxStaticText( this, wxID_ANY, _T("Description"), wxPoint(4*2,24*2), | |
116 | wxSize(32*2,12*2) ); | |
117 | m_Description = new wxTextCtrl( this, wxID_ANY, descr, wxPoint(37*2,27*2), | |
118 | wxSize(53*2,14*2) ); | |
119 | ||
120 | new wxButton( this, wxID_OK, _T("Ok"), wxPoint(20*2,50*2), wxSize(20*2,13*2) ); | |
121 | new wxButton( this, wxID_CANCEL, _T("Cancel"), wxPoint(44*2,50*2), | |
122 | wxSize(25*2,13*2) ); | |
123 | } | |
124 | ||
125 | int ScanCodeDialog::GetValue() | |
126 | { | |
127 | int code; | |
128 | wxString buf = m_ScanCode->GetValue(); | |
129 | wxSscanf( buf.c_str(), _T("%i"), &code ); | |
130 | return code; | |
131 | } | |
132 | ||
133 | /*---------------------------------------------------------------------- | |
134 | Utility function to get the elapsed time (in msec) since a given point | |
135 | Content-type: text/html ]>