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