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