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