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