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