* 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
master
Giel van Schijndel 2007-07-26 10:50:15 +00:00
parent 6634aa66fa
commit 20d790a4fa
7 changed files with 41 additions and 36 deletions

View File

@ -350,7 +350,7 @@ SOURCE=.\initiallimitsdlg.h
# End Source File # End Source File
# Begin Source File # Begin Source File
SOURCE=.\keyhandler.h SOURCE=.\keyhandler.hpp
# End Source File # End Source File
# Begin Source File # Begin Source File

View File

@ -35,6 +35,7 @@
//#include "statsview.h" //#include "statsview.h"
#include "tiletypes.h" #include "tiletypes.h"
#include "objectproperties.h" #include "objectproperties.h"
#include "keyhandler.hpp"
#ifdef _DEBUG #ifdef _DEBUG
#define new DEBUG_NEW #define new DEBUG_NEW
@ -121,7 +122,7 @@ CBTEditView::CBTEditView()
m_Selected = -1; m_Selected = -1;
m_DragMode = DM3D_NODRAG; m_DragMode = DM3D_NODRAG;
// m_DirectMaths = NULL; // m_DirectMaths = NULL;
m_KeyHandler = new CKeyHandler(); m_KeyHandler = new KeyHandler();
m_HeightsChanged = FALSE; m_HeightsChanged = FALSE;
// m_InfoDialog = new CInfoDialog(this); // m_InfoDialog = new CInfoDialog(this);

View File

@ -34,7 +34,6 @@
#include "ddimage.h" #include "ddimage.h"
#include "heightmap.h" #include "heightmap.h"
#include "pcxhandler.h" #include "pcxhandler.h"
#include "keyhandler.h"
//#include "InfoDialog.h" //#include "InfoDialog.h"
@ -47,8 +46,9 @@ enum {
DM3D_DRAGOBJECT, DM3D_DRAGOBJECT,
}; };
// Forward declaration for pointer // Forward declarations for pointers
class CBTEditDoc; class CBTEditDoc;
class KeyHandler;
class CBTEditView : public CScrollView class CBTEditView : public CScrollView
{ {
@ -126,7 +126,7 @@ protected:
DWORD m_MouseX; DWORD m_MouseX;
DWORD m_MouseY; DWORD m_MouseY;
DWORD m_DragMode; DWORD m_DragMode;
CKeyHandler *m_KeyHandler; KeyHandler *m_KeyHandler;
// Generated message map functions // Generated message map functions
protected: protected:
//{{AFX_MSG(CBTEditView) //{{AFX_MSG(CBTEditView)

View File

@ -28,32 +28,26 @@
#include "typedefs.h" #include "typedefs.h"
#include "debugprint.hpp" #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<KEYTABSIZE; i++) { if(VKey < _KeyTable.size())
m_KeyTable[i] = 0; {
}
}
void CKeyHandler::HandleKeyDown(UINT VKey)
{
if(VKey < KEYTABSIZE) {
// DebugPrint("KeyDown %d\n",VKey); // DebugPrint("KeyDown %d\n",VKey);
m_KeyTable[VKey] = 1; _KeyTable.set(VKey);
} }
} }
void CKeyHandler::HandleKeyUp(UINT VKey) void KeyHandler::HandleKeyUp(unsigned int VKey)
{ {
if(VKey < KEYTABSIZE) { if(VKey < _KeyTable.size())
m_KeyTable[VKey] = 0; {
_KeyTable.reset(VKey);
// DebugPrint("KeyUp %d\n",VKey); // DebugPrint("KeyUp %d\n",VKey);
} }
} }

View File

@ -22,20 +22,27 @@
$HeadURL$ $HeadURL$
*/ */
#ifndef __INCLUDED_KEYHANDLER__ #ifndef __INCLUDE_KEYHANDLER_HPP__
#define __INCLUDED_KEYHANDLER__ #define __INCLUDE_KEYHANDLER_HPP__
#define KEYTABSIZE 256 #define KEYTABSIZE 256
#include <bitset>
class CKeyHandler { class KeyHandler
public: {
CKeyHandler(void); public:
void InitKeyTable(void); KeyHandler();
void HandleKeyDown(UINT VKey);
void HandleKeyUp(UINT VKey); void HandleKeyDown(unsigned int VKey);
BOOL GetKeyState(UINT VKey) { return m_KeyTable[VKey]; } void HandleKeyUp(unsigned int VKey);
protected:
BOOL m_KeyTable[KEYTABSIZE]; inline bool GetKeyState(unsigned int VKey)
{
return _KeyTable.test(VKey);
}
private:
std::bitset<256> _KeyTable;
}; };
#endif #endif // __INCLUDE_KEYHANDLER_HPP__

View File

@ -34,6 +34,7 @@
#include "debugprint.hpp" #include "debugprint.hpp"
//#include "DebugWin.h" //#include "DebugWin.h"
#include "objectproperties.h" #include "objectproperties.h"
#include "keyhandler.hpp"
#ifdef _DEBUG #ifdef _DEBUG
#define new DEBUG_NEW #define new DEBUG_NEW
@ -76,7 +77,7 @@ CWFView::CWFView()
WFView = this; WFView = this;
m_ViewIsInitialised=FALSE; m_ViewIsInitialised=FALSE;
m_DragMode=DM_NODRAG; m_DragMode=DM_NODRAG;
m_KeyHandler = new CKeyHandler(); m_KeyHandler = new KeyHandler();
m_HeightsChanged = FALSE; m_HeightsChanged = FALSE;
// m_BrushDialog = new CBrushProp(this); // m_BrushDialog = new CBrushProp(this);
} }

View File

@ -34,7 +34,6 @@
#include "ddimage.h" #include "ddimage.h"
#include "heightmap.h" #include "heightmap.h"
#include "pcxhandler.h" #include "pcxhandler.h"
#include "keyhandler.h"
//#include "brushprop.h" //#include "brushprop.h"
#define SCREEN_XRES 640 #define SCREEN_XRES 640
@ -46,6 +45,9 @@ enum {
DM_DRAGOBJECT, DM_DRAGOBJECT,
}; };
// Forward declarations for pointers
class KeyHandler;
class CWFView : public CScrollView class CWFView : public CScrollView
{ {
protected: protected:
@ -121,7 +123,7 @@ protected:
DWORD m_DragMode; DWORD m_DragMode;
// CBrushProp *m_BrushDialog; // CBrushProp *m_BrushDialog;
CKeyHandler *m_KeyHandler; KeyHandler *m_KeyHandler;
// Generated message map functions // Generated message map functions
//{{AFX_MSG(CWFView) //{{AFX_MSG(CWFView)