]>
Commit | Line | Data |
---|---|---|
8b089c5e JS |
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 | |
f4a7108f | 9 | // Licence: wxWindows licence |
8b089c5e JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
788233da | 12 | #if defined(__GNUG__) && !defined(__APPLE__) |
8b089c5e JS |
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 | ||
806e2f15 VZ |
28 | #if !wxUSE_GLCANVAS |
29 | #error "OpenGL required: set wxUSE_GLCANVAS to 1 and rebuild the library" | |
30 | #endif | |
31 | ||
8b089c5e JS |
32 | #include "cube.h" |
33 | ||
f4a7108f | 34 | #ifndef __WXMSW__ // for wxStopWatch, see remark below |
e195c8c9 GD |
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 | |
8b089c5e JS |
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: | |
5cf036d0 DS |
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 | ||
8b089c5e | 66 | private: |
5cf036d0 | 67 | |
be5a51fb | 68 | // Any class wishing to process wxWidgets events must use this macro |
5cf036d0 | 69 | DECLARE_EVENT_TABLE() |
8b089c5e | 70 | }; |
5cf036d0 | 71 | |
8b089c5e | 72 | BEGIN_EVENT_TABLE( ScanCodeCtrl, wxTextCtrl ) |
5cf036d0 DS |
73 | EVT_CHAR( ScanCodeCtrl::OnChar ) |
74 | EVT_KEY_DOWN( ScanCodeCtrl::OnKeyDown ) | |
8b089c5e JS |
75 | END_EVENT_TABLE() |
76 | ||
77 | ScanCodeCtrl::ScanCodeCtrl( wxWindow* parent, wxWindowID id, int code, | |
5cf036d0 DS |
78 | const wxPoint& pos, const wxSize& size ) |
79 | : wxTextCtrl( parent, id, wxEmptyString, pos, size ) | |
80 | { | |
81 | SetValue( wxString::Format(wxT("0x%04x"), code) ); | |
8b089c5e JS |
82 | } |
83 | ||
84 | void ScanCodeCtrl::OnKeyDown( wxKeyEvent& event ) | |
2db98bf5 | 85 | { |
5cf036d0 | 86 | SetValue( wxString::Format(wxT("0x%04x"), event.GetKeyCode()) ); |
8b089c5e JS |
87 | } |
88 | ||
89 | /*------------------------------------------------------------------ | |
90 | Dialog for defining a keypress | |
91 | -------------------------------------------------------------------*/ | |
92 | ||
93 | class ScanCodeDialog : public wxDialog | |
94 | { | |
95 | public: | |
5cf036d0 DS |
96 | ScanCodeDialog( wxWindow* parent, wxWindowID id, const int code, |
97 | const wxString &descr, const wxString& title ); | |
98 | int GetValue(); | |
99 | ||
8b089c5e | 100 | private: |
5cf036d0 DS |
101 | |
102 | ScanCodeCtrl *m_ScanCode; | |
103 | wxTextCtrl *m_Description; | |
8b089c5e JS |
104 | }; |
105 | ||
f4a7108f | 106 | ScanCodeDialog::ScanCodeDialog( wxWindow* parent, wxWindowID id, |
5cf036d0 DS |
107 | const int code, const wxString &descr, const wxString& title ) |
108 | : wxDialog( parent, id, title, wxDefaultPosition, wxSize(96*2,76*2) ) | |
8b089c5e | 109 | { |
5cf036d0 DS |
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) ); | |
8b089c5e JS |
123 | } |
124 | ||
125 | int ScanCodeDialog::GetValue() | |
126 | { | |
5cf036d0 DS |
127 | int code; |
128 | wxString buf = m_ScanCode->GetValue(); | |
129 | wxSscanf( buf.c_str(), _T("%i"), &code ); | |
130 | return code; | |
8b089c5e JS |
131 | } |
132 | ||
133 | /*---------------------------------------------------------------------- | |
134 | Utility function to get the elapsed time (in msec) since a given point | |
f4a7108f VZ |
135 | Content-type: text/html ]>