]>
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 | #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 | ||
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 | ||
39 | #define ID_NEW_WINDOW 10000 | |
40 | #define ID_DEF_ROTATE_LEFT_KEY 10001 | |
41 | #define ID_DEF_ROTATE_RIGHT_KEY 10002 | |
42 | ||
43 | /*---------------------------------------------------------- | |
44 | Control to get a keycode | |
45 | ----------------------------------------------------------*/ | |
46 | class ScanCodeCtrl : public wxTextCtrl | |
47 | { | |
48 | public: | |
49 | ScanCodeCtrl( wxWindow* parent, wxWindowID id, int code, | |
50 | const wxPoint& pos, const wxSize& size ); | |
51 | void OnChar( wxKeyEvent& event ) { } /* do nothing */ | |
52 | void OnKeyDown(wxKeyEvent& event); | |
53 | private: | |
54 | // any class wishing to process wxWindows events must use this macro | |
55 | DECLARE_EVENT_TABLE() | |
56 | }; | |
57 | BEGIN_EVENT_TABLE( ScanCodeCtrl, wxTextCtrl ) | |
58 | EVT_CHAR( ScanCodeCtrl::OnChar ) | |
59 | EVT_KEY_DOWN( ScanCodeCtrl::OnKeyDown ) | |
60 | END_EVENT_TABLE() | |
61 | ||
62 | ScanCodeCtrl::ScanCodeCtrl( wxWindow* parent, wxWindowID id, int code, | |
63 | const wxPoint& pos, const wxSize& size ) | |
64 | : wxTextCtrl( parent, id, "", pos, size ) | |
65 | { wxString buf; | |
66 | buf.Printf( "0x%04x", code ); | |
67 | SetValue( buf ); | |
68 | } | |
69 | ||
70 | void ScanCodeCtrl::OnKeyDown( wxKeyEvent& event ) | |
71 | { wxString buf; | |
72 | buf.Printf( "0x%04x", event.KeyCode() ); | |
73 | SetValue( buf ); | |
74 | } | |
75 | ||
76 | /*------------------------------------------------------------------ | |
77 | Dialog for defining a keypress | |
78 | -------------------------------------------------------------------*/ | |
79 | class ScanCodeDialog : public wxDialog | |
80 | { | |
81 | public: | |
82 | ScanCodeDialog( wxWindow* parent, wxWindowID id, const int code, | |
83 | const wxString &descr, const wxString& title ); | |
84 | int GetValue(); | |
85 | private: | |
86 | ScanCodeCtrl *m_ScanCode; | |
87 | wxTextCtrl *m_Description; | |
88 | // any class wishing to process wxWindows events must use this macro | |
89 | DECLARE_EVENT_TABLE() | |
90 | }; | |
91 | ||
92 | BEGIN_EVENT_TABLE( ScanCodeDialog, wxDialog ) | |
93 | // | |
94 | END_EVENT_TABLE() | |
95 | ||
96 | /* ---------------------------------------------------------------- */ | |
97 | ||
98 | ScanCodeDialog::ScanCodeDialog( wxWindow* parent, wxWindowID id, | |
99 | const int code, const wxString &descr, const wxString& title ) | |
100 | : wxDialog( parent, id, title, wxPoint(-1, -1), wxSize(96*2,76*2) ) | |
101 | { | |
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) ); | |
106 | ||
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) ); | |
111 | ||
112 | new wxButton( this, wxID_OK, "Ok", wxPoint(20*2,50*2), wxSize(20*2,13*2) ); | |
113 | new wxButton( this, wxID_CANCEL, "Cancel", wxPoint(44*2,50*2), | |
114 | wxSize(25*2,13*2) ); | |
115 | } | |
116 | ||
117 | int ScanCodeDialog::GetValue() | |
118 | { | |
119 | int code; | |
120 | wxString buf = m_ScanCode->GetValue(); | |
121 | sscanf( buf.c_str(), "%i", &code ); | |
122 | return( code ); | |
123 | } | |
124 | ||
125 | /*---------------------------------------------------------------------- | |
126 | Utility function to get the elapsed time (in msec) since a given point | |
127 | Content-type: text/html ]>