]>
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 | 32 | #include "cube.h" |
3a992940 | 33 | #include "../../sample.xpm" |
8b089c5e | 34 | |
be517567 | 35 | #ifndef __WXMSW__ // for StopWatch, see remark below |
e195c8c9 GD |
36 | #if defined(__WXMAC__) && !defined(__DARWIN__) |
37 | #include <utime.h> | |
38 | #include <unistd.h> | |
39 | #else | |
40 | #include <sys/time.h> | |
41 | #include <sys/unistd.h> | |
42 | #endif | |
8b089c5e JS |
43 | #else |
44 | #include <sys/timeb.h> | |
45 | #endif | |
46 | ||
47 | #define ID_NEW_WINDOW 10000 | |
48 | #define ID_DEF_ROTATE_LEFT_KEY 10001 | |
49 | #define ID_DEF_ROTATE_RIGHT_KEY 10002 | |
50 | ||
51 | /*---------------------------------------------------------- | |
52 | Control to get a keycode | |
53 | ----------------------------------------------------------*/ | |
54 | class ScanCodeCtrl : public wxTextCtrl | |
55 | { | |
56 | public: | |
5cf036d0 DS |
57 | ScanCodeCtrl( wxWindow* parent, wxWindowID id, int code, |
58 | const wxPoint& pos, const wxSize& size ); | |
59 | ||
60 | void OnChar( wxKeyEvent& WXUNUSED(event) ) | |
61 | { | |
62 | // Do nothing | |
63 | } | |
64 | ||
65 | void OnKeyDown(wxKeyEvent& event); | |
66 | ||
8b089c5e | 67 | private: |
5cf036d0 | 68 | |
be5a51fb | 69 | // Any class wishing to process wxWidgets events must use this macro |
5cf036d0 | 70 | DECLARE_EVENT_TABLE() |
8b089c5e | 71 | }; |
5cf036d0 | 72 | |
8b089c5e | 73 | BEGIN_EVENT_TABLE( ScanCodeCtrl, wxTextCtrl ) |
5cf036d0 DS |
74 | EVT_CHAR( ScanCodeCtrl::OnChar ) |
75 | EVT_KEY_DOWN( ScanCodeCtrl::OnKeyDown ) | |
8b089c5e JS |
76 | END_EVENT_TABLE() |
77 | ||
78 | ScanCodeCtrl::ScanCodeCtrl( wxWindow* parent, wxWindowID id, int code, | |
5cf036d0 DS |
79 | const wxPoint& pos, const wxSize& size ) |
80 | : wxTextCtrl( parent, id, wxEmptyString, pos, size ) | |
81 | { | |
82 | SetValue( wxString::Format(wxT("0x%04x"), code) ); | |
8b089c5e JS |
83 | } |
84 | ||
85 | void ScanCodeCtrl::OnKeyDown( wxKeyEvent& event ) | |
2db98bf5 | 86 | { |
5cf036d0 | 87 | SetValue( wxString::Format(wxT("0x%04x"), event.GetKeyCode()) ); |
8b089c5e JS |
88 | } |
89 | ||
90 | /*------------------------------------------------------------------ | |
91 | Dialog for defining a keypress | |
92 | -------------------------------------------------------------------*/ | |
93 | ||
94 | class ScanCodeDialog : public wxDialog | |
95 | { | |
96 | public: | |
5cf036d0 DS |
97 | ScanCodeDialog( wxWindow* parent, wxWindowID id, const int code, |
98 | const wxString &descr, const wxString& title ); | |
99 | int GetValue(); | |
100 | ||
8b089c5e | 101 | private: |
5cf036d0 DS |
102 | |
103 | ScanCodeCtrl *m_ScanCode; | |
104 | wxTextCtrl *m_Description; | |
8b089c5e JS |
105 | }; |
106 | ||
f4a7108f | 107 | ScanCodeDialog::ScanCodeDialog( wxWindow* parent, wxWindowID id, |
5cf036d0 DS |
108 | const int code, const wxString &descr, const wxString& title ) |
109 | : wxDialog( parent, id, title, wxDefaultPosition, wxSize(96*2,76*2) ) | |
8b089c5e | 110 | { |
5cf036d0 DS |
111 | new wxStaticText( this, wxID_ANY, _T("Scancode"), wxPoint(4*2,3*2), |
112 | wxSize(31*2,12*2) ); | |
113 | m_ScanCode = new ScanCodeCtrl( this, wxID_ANY, code, wxPoint(37*2,6*2), | |
114 | wxSize(53*2,14*2) ); | |
115 | ||
116 | new wxStaticText( this, wxID_ANY, _T("Description"), wxPoint(4*2,24*2), | |
117 | wxSize(32*2,12*2) ); | |
118 | m_Description = new wxTextCtrl( this, wxID_ANY, descr, wxPoint(37*2,27*2), | |
119 | wxSize(53*2,14*2) ); | |
120 | ||
121 | new wxButton( this, wxID_OK, _T("Ok"), wxPoint(20*2,50*2), wxSize(20*2,13*2) ); | |
122 | new wxButton( this, wxID_CANCEL, _T("Cancel"), wxPoint(44*2,50*2), | |
123 | wxSize(25*2,13*2) ); | |
8b089c5e JS |
124 | } |
125 | ||
126 | int ScanCodeDialog::GetValue() | |
127 | { | |
5cf036d0 DS |
128 | int code; |
129 | wxString buf = m_ScanCode->GetValue(); | |
130 | wxSscanf( buf.c_str(), _T("%i"), &code ); | |
131 | return code; | |
8b089c5e JS |
132 | } |
133 | ||
134 | /*---------------------------------------------------------------------- | |
135 | Utility function to get the elapsed time (in msec) since a given point | |
f4a7108f VZ |
136 | Content-type: text/html ]>