From 20d790a4fac810148709c514ec3b8ad144cfec7c Mon Sep 17 00:00:00 2001 From: Giel van Schijndel Date: Thu, 26 Jul 2007 10:50:15 +0000 Subject: [PATCH] Cleanup: * Rename class CKeyHandler to KeyHandler (I don't want freaking MFC style classnames being prefixed with 'C') * Modify class KeyHandler to use std::bitset instead of an array of bools * Use forward declarations for pointers instead of including the entire header git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@2200 4a71c877-e1ca-e34f-864e-861f7616d084 --- tools/editworld/src/EditWorld.dsp | 2 +- tools/editworld/src/bteditview.cpp | 3 +- tools/editworld/src/bteditview.h | 6 ++-- tools/editworld/src/keyhandler.cpp | 26 ++++++---------- .../src/{keyhandler.h => keyhandler.hpp} | 31 ++++++++++++------- tools/editworld/src/wfview.cpp | 3 +- tools/editworld/src/wfview.h | 6 ++-- 7 files changed, 41 insertions(+), 36 deletions(-) rename tools/editworld/src/{keyhandler.h => keyhandler.hpp} (70%) diff --git a/tools/editworld/src/EditWorld.dsp b/tools/editworld/src/EditWorld.dsp index 479faf0fa..7662c6b9d 100644 --- a/tools/editworld/src/EditWorld.dsp +++ b/tools/editworld/src/EditWorld.dsp @@ -350,7 +350,7 @@ SOURCE=.\initiallimitsdlg.h # End Source File # Begin Source File -SOURCE=.\keyhandler.h +SOURCE=.\keyhandler.hpp # End Source File # Begin Source File diff --git a/tools/editworld/src/bteditview.cpp b/tools/editworld/src/bteditview.cpp index 973a361b3..09809d454 100644 --- a/tools/editworld/src/bteditview.cpp +++ b/tools/editworld/src/bteditview.cpp @@ -35,6 +35,7 @@ //#include "statsview.h" #include "tiletypes.h" #include "objectproperties.h" +#include "keyhandler.hpp" #ifdef _DEBUG #define new DEBUG_NEW @@ -121,7 +122,7 @@ CBTEditView::CBTEditView() m_Selected = -1; m_DragMode = DM3D_NODRAG; // m_DirectMaths = NULL; - m_KeyHandler = new CKeyHandler(); + m_KeyHandler = new KeyHandler(); m_HeightsChanged = FALSE; // m_InfoDialog = new CInfoDialog(this); diff --git a/tools/editworld/src/bteditview.h b/tools/editworld/src/bteditview.h index 172bf7aad..8bccd0005 100644 --- a/tools/editworld/src/bteditview.h +++ b/tools/editworld/src/bteditview.h @@ -34,7 +34,6 @@ #include "ddimage.h" #include "heightmap.h" #include "pcxhandler.h" -#include "keyhandler.h" //#include "InfoDialog.h" @@ -47,8 +46,9 @@ enum { DM3D_DRAGOBJECT, }; -// Forward declaration for pointer +// Forward declarations for pointers class CBTEditDoc; +class KeyHandler; class CBTEditView : public CScrollView { @@ -126,7 +126,7 @@ protected: DWORD m_MouseX; DWORD m_MouseY; DWORD m_DragMode; - CKeyHandler *m_KeyHandler; + KeyHandler *m_KeyHandler; // Generated message map functions protected: //{{AFX_MSG(CBTEditView) diff --git a/tools/editworld/src/keyhandler.cpp b/tools/editworld/src/keyhandler.cpp index f8bdb4582..3213e68c4 100644 --- a/tools/editworld/src/keyhandler.cpp +++ b/tools/editworld/src/keyhandler.cpp @@ -28,32 +28,26 @@ #include "typedefs.h" #include "debugprint.hpp" -#include "keyhandler.h" +#include "keyhandler.hpp" -CKeyHandler::CKeyHandler(void) +KeyHandler::KeyHandler() { - InitKeyTable(); } -void CKeyHandler::InitKeyTable(void) +void KeyHandler::HandleKeyDown(unsigned int VKey) { - for(int i = 0; i -class CKeyHandler { -public: - CKeyHandler(void); - void InitKeyTable(void); - void HandleKeyDown(UINT VKey); - void HandleKeyUp(UINT VKey); - BOOL GetKeyState(UINT VKey) { return m_KeyTable[VKey]; } -protected: - BOOL m_KeyTable[KEYTABSIZE]; +class KeyHandler +{ + public: + KeyHandler(); + + void HandleKeyDown(unsigned int VKey); + void HandleKeyUp(unsigned int VKey); + + inline bool GetKeyState(unsigned int VKey) + { + return _KeyTable.test(VKey); + } + + private: + std::bitset<256> _KeyTable; }; -#endif +#endif // __INCLUDE_KEYHANDLER_HPP__ diff --git a/tools/editworld/src/wfview.cpp b/tools/editworld/src/wfview.cpp index ad16b3bcd..fd0635d61 100644 --- a/tools/editworld/src/wfview.cpp +++ b/tools/editworld/src/wfview.cpp @@ -34,6 +34,7 @@ #include "debugprint.hpp" //#include "DebugWin.h" #include "objectproperties.h" +#include "keyhandler.hpp" #ifdef _DEBUG #define new DEBUG_NEW @@ -76,7 +77,7 @@ CWFView::CWFView() WFView = this; m_ViewIsInitialised=FALSE; m_DragMode=DM_NODRAG; - m_KeyHandler = new CKeyHandler(); + m_KeyHandler = new KeyHandler(); m_HeightsChanged = FALSE; // m_BrushDialog = new CBrushProp(this); } diff --git a/tools/editworld/src/wfview.h b/tools/editworld/src/wfview.h index 0f97cdd21..f05d8beca 100644 --- a/tools/editworld/src/wfview.h +++ b/tools/editworld/src/wfview.h @@ -34,7 +34,6 @@ #include "ddimage.h" #include "heightmap.h" #include "pcxhandler.h" -#include "keyhandler.h" //#include "brushprop.h" #define SCREEN_XRES 640 @@ -46,6 +45,9 @@ enum { DM_DRAGOBJECT, }; +// Forward declarations for pointers +class KeyHandler; + class CWFView : public CScrollView { protected: @@ -121,7 +123,7 @@ protected: DWORD m_DragMode; // CBrushProp *m_BrushDialog; - CKeyHandler *m_KeyHandler; + KeyHandler *m_KeyHandler; // Generated message map functions //{{AFX_MSG(CWFView)