KeyDialog.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2003
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #include <wxdialogs/KeyDialog.h>
00022 #include <wxdialogs/MainDialog.h>
00023 #include <common/Defines.h>
00024 #include <common/Keyboard.h>
00025 #include <wx/wx.h>
00026 
00027 extern char scorched3dAppName[128];
00028 extern char *displayOptions;
00029 static bool keyDialogShiftDown = false;
00030 static bool keyDialogControlDown = false;
00031 static bool keyDialogAltDown = false;
00032 static unsigned int keyDialogKeyCode = 0;
00033 
00034 class KeyFrame;
00035 class TextWindow : public wxWindow
00036 {
00037 public:
00038     TextWindow(wxDialog *parent)
00039         : wxWindow(parent, -1, wxDefaultPosition, wxDefaultSize,
00040                    wxRAISED_BORDER),
00041                    frame_((KeyFrame *) parent)
00042     {
00043                 wxBoxSizer *topsizer = new wxBoxSizer(wxVERTICAL);
00044 
00045                 wxStaticText *text = 
00046                         new wxStaticText(this, -1, wxT("Press a key to bind to this function"));
00047                 topsizer->Add(text, 0, wxALIGN_CENTER | wxALL, 5);
00048 
00049                 SetSizer(topsizer); // use the sizer for layout
00050                 topsizer->SetSizeHints(this); // set size hints to honour minimum size
00051     }
00052 
00053 protected:
00054         KeyFrame *frame_;
00055 
00056     void OnKeyDown(wxKeyEvent& event);
00057 
00058 private:
00059     DECLARE_EVENT_TABLE()
00060 };
00061 
00062 BEGIN_EVENT_TABLE(TextWindow, wxWindow)
00063     EVT_KEY_DOWN(TextWindow::OnKeyDown)
00064 END_EVENT_TABLE()
00065 
00066 class KeyFrame : public wxDialog
00067 {
00068 public:
00069         KeyFrame(wxDialog *);
00070 
00071 protected:
00072         TextWindow *winText_;
00073 
00074         DECLARE_EVENT_TABLE()
00075 };
00076 
00077 unsigned int getKeyDialogKey()
00078 {
00079         return keyDialogKeyCode;
00080 }
00081 
00082 bool getKeyDialogShift()
00083 {
00084         return keyDialogShiftDown;
00085 }
00086 
00087 bool getKeyDialogControl()
00088 {
00089         return keyDialogControlDown;
00090 }
00091 
00092 bool getKeyDialogAlt()
00093 {
00094         return keyDialogAltDown;
00095 }
00096 
00097 void TextWindow::OnKeyDown(wxKeyEvent& event)
00098 {
00099         switch (event.GetKeyCode())
00100         {
00101         case WXK_SHIFT:
00102         case WXK_CONTROL:
00103         case WXK_ALT:
00104         case WXK_MENU:
00105                 break;
00106         default:
00107                 keyDialogControlDown = event.ControlDown();
00108                 keyDialogShiftDown = event.ShiftDown();
00109                 keyDialogAltDown = event.AltDown();
00110                 keyDialogKeyCode = event.KeyCode();
00111                 frame_->EndModal(0);
00112         }
00113 }
00114 
00115 BEGIN_EVENT_TABLE(KeyFrame, wxDialog)
00116 END_EVENT_TABLE()
00117 
00118 KeyFrame::KeyFrame(wxDialog *dialog) :
00119         wxDialog(dialog, -1, wxString(scorched3dAppName, wxConvUTF8), 
00120                 wxDefaultPosition, wxSize(190, 50), wxSIMPLE_BORDER )
00121 {
00122 #ifdef _WIN32
00123         // Set the frame's icon
00124         wxIcon icon(convertString(S3D::getDataFile("data/windows/tank2.ico")), wxBITMAP_TYPE_ICO);
00125         SetIcon(icon);
00126 #endif
00127 
00128         wxSize size = GetClientSize();
00129         winText_ = new TextWindow(this);
00130         winText_->SetSize(0, 0, size.x, size.y);
00131 
00132         CentreOnScreen();
00133 }
00134 
00135 void showKeyDialog(wxDialog *dialog)
00136 {
00137         KeyFrame frame(dialog);
00138         frame.ShowModal();
00139 }

Generated on Mon Feb 16 15:14:52 2009 for Scorched3D by  doxygen 1.5.3