Incremental Engine  1.0.6
A 2D Game Engine to create Idle Games
IncrementalEngine::InputManager Class Reference

#include <InputManager.h>

Inheritance diagram for IncrementalEngine::InputManager:
IncrementalEngine::WindowsInput

Public Member Functions

 InputManager ()
 
virtual ~InputManager ()
 
HRESULT Init (RenderWindow *renderWindow)
 
HRESULT Update ()
 
bool IsKeyDown (DirectInputKey key)
 
bool IsMouseButtonDown (DirectInputMouseButton button)
 
void GetMousePosition (float &mouseX, float &mouseY)
 
bool MouseInsideScreen ()
 
virtual LRESULT MessageHandler (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) override
 
- Public Member Functions inherited from IncrementalEngine::WindowsInput
 WindowsInput ()
 

Private Member Functions

void KeyDown (unsigned int key)
 
void KeyUp (unsigned int key)
 

Private Attributes

RenderWindow_renderWindow
 
unsigned char _keys [KEY_NUM]
 
float _mouseX
 
float _mouseY
 
bool _leftMousePressed
 
bool _rightMousePressed
 

Additional Inherited Members

- Static Public Attributes inherited from IncrementalEngine::WindowsInput
static WindowsInputWINDOWS_INPUT = nullptr
 

Detailed Description

Definition at line 12 of file InputManager.h.

Constructor & Destructor Documentation

◆ InputManager()

IncrementalEngine::InputManager::InputManager ( )

Definition at line 6 of file InputManager.cpp.

7  {
8  for (int i = 0; i < KEY_NUM; i++)
9  {
10  _keys[i] = false;
11  }
12  }

◆ ~InputManager()

IncrementalEngine::InputManager::~InputManager ( )
virtual

Definition at line 14 of file InputManager.cpp.

15  {
16  }

Member Function Documentation

◆ GetMousePosition()

void IncrementalEngine::InputManager::GetMousePosition ( float &  mouseX,
float &  mouseY 
)

Definition at line 38 of file InputManager.cpp.

39  {
40  mouseX = _mouseX;
41  mouseY = _mouseY;
42  }

◆ Init()

HRESULT IncrementalEngine::InputManager::Init ( RenderWindow renderWindow)

Definition at line 18 of file InputManager.cpp.

19  {
20  _renderWindow = renderWindow;
21  _mouseX = _mouseY = 0;
22 
23  return S_OK;
24  }

◆ IsKeyDown()

bool IncrementalEngine::InputManager::IsKeyDown ( DirectInputKey  key)

Definition at line 44 of file InputManager.cpp.

45  {
46  return _keys[(unsigned int)key];
47  }

◆ IsMouseButtonDown()

bool IncrementalEngine::InputManager::IsMouseButtonDown ( DirectInputMouseButton  button)

Definition at line 49 of file InputManager.cpp.

50  {
51  switch (button)
52  {
53  case DirectInputMouseButton::MouseLeft:
54  {
55  return _leftMousePressed;
56  };
57  case DirectInputMouseButton::MouseRight:
58  {
59  return _rightMousePressed;
60  }
61  }
62 
63  return false;
64  }

◆ KeyDown()

void IncrementalEngine::InputManager::KeyDown ( unsigned int  key)
private

Definition at line 66 of file InputManager.cpp.

67  {
68  _keys[key] = true;
69  return;
70  }

◆ KeyUp()

void IncrementalEngine::InputManager::KeyUp ( unsigned int  key)
private

Definition at line 72 of file InputManager.cpp.

73  {
74  _keys[key] = false;
75  return;
76  }

◆ MessageHandler()

LRESULT IncrementalEngine::InputManager::MessageHandler ( HWND  hWnd,
UINT  message,
WPARAM  wParam,
LPARAM  lParam 
)
overridevirtual

Implements IncrementalEngine::WindowsInput.

Definition at line 86 of file InputManager.cpp.

87  {
88  switch (message)
89  {
90  case WM_KEYDOWN:
91  {
92  KeyDown((unsigned int)wParam);
93  return 0;
94  }
95  case WM_KEYUP:
96  {
97  KeyUp((unsigned int)wParam);
98  return 0;
99  }
100  case WM_LBUTTONDOWN:
101  {
102  _leftMousePressed = true;
103  return 0;
104  }
105  case WM_LBUTTONUP:
106  {
107  _leftMousePressed = false;
108  return 0;
109  }
110  case WM_RBUTTONDOWN:
111  {
112  _rightMousePressed = true;
113  return 0;
114  }
115  case WM_RBUTTONUP:
116  {
117  _rightMousePressed = false;
118  return 0;
119  }
120  default:
121  {
122  return DefWindowProc(hWnd, message, wParam, lParam);
123  }
124  }
125  }

◆ MouseInsideScreen()

bool IncrementalEngine::InputManager::MouseInsideScreen ( )

Definition at line 78 of file InputManager.cpp.

79  {
80  return _mouseX > -_renderWindow->GetScreenWidth() * .5f &&
84  }

◆ Update()

HRESULT IncrementalEngine::InputManager::Update ( )

Definition at line 26 of file InputManager.cpp.

27  {
28  POINT pt;
29  GetCursorPos(&pt);
30  ScreenToClient(_renderWindow->GetHWND(), &pt);
31 
32  _mouseX = pt.x - _renderWindow->GetScreenWidth() * .5f;
33  _mouseY = pt.y - _renderWindow->GetScreenHeight() * .5f;
34 
35  return S_OK;
36  }

Member Data Documentation

◆ _keys

unsigned char IncrementalEngine::InputManager::_keys[KEY_NUM]
private

Definition at line 32 of file InputManager.h.

◆ _leftMousePressed

bool IncrementalEngine::InputManager::_leftMousePressed
private

Definition at line 35 of file InputManager.h.

◆ _mouseX

float IncrementalEngine::InputManager::_mouseX
private

Definition at line 34 of file InputManager.h.

◆ _mouseY

float IncrementalEngine::InputManager::_mouseY
private

Definition at line 34 of file InputManager.h.

◆ _renderWindow

RenderWindow* IncrementalEngine::InputManager::_renderWindow
private

Definition at line 30 of file InputManager.h.

◆ _rightMousePressed

bool IncrementalEngine::InputManager::_rightMousePressed
private

Definition at line 35 of file InputManager.h.

IncrementalEngine::InputManager::KeyUp
void KeyUp(unsigned int key)
Definition: InputManager.cpp:72
IncrementalEngine::InputManager::_mouseY
float _mouseY
Definition: InputManager.h:34
IncrementalEngine::InputManager::_rightMousePressed
bool _rightMousePressed
Definition: InputManager.h:35
IncrementalEngine::InputManager::_renderWindow
RenderWindow * _renderWindow
Definition: InputManager.h:30
IncrementalEngine::InputManager::_leftMousePressed
bool _leftMousePressed
Definition: InputManager.h:35
IncrementalEngine::InputManager::_keys
unsigned char _keys[KEY_NUM]
Definition: InputManager.h:32
IncrementalEngine::InputManager::_mouseX
float _mouseX
Definition: InputManager.h:34
IncrementalEngine::InputManager::KeyDown
void KeyDown(unsigned int key)
Definition: InputManager.cpp:66
IncrementalEngine::RenderWindow::GetScreenHeight
int GetScreenHeight()
Definition: RenderWindow.cpp:120
IncrementalEngine::RenderWindow::GetScreenWidth
int GetScreenWidth()
Definition: RenderWindow.cpp:115
IncrementalEngine::RenderWindow::GetHWND
HWND GetHWND()
Definition: RenderWindow.cpp:105