Debian Codegraph @

src/gengine/InputHandler.cpp

raw
1 /*
2 * Copyright (C) 2004 Ivo Danihelka ([email protected])
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 */
9 #include "InputHandler.h"
10
11 #include "ExInfo.h"
12
13 //-----------------------------------------------------------------
14 InputHandler::InputHandler()
15 : m_mouseLoc(-1, -1)
16 {
17 m_pressed = NULL;
18 m_buttons = 0;
19 }
20 //-----------------------------------------------------------------
21 void
22 InputHandler::mouseState(const V2 &loc, Uint8 buttons)
23 {
24 m_mouseLoc = loc;
25 m_buttons = buttons;
26 }
27 //-----------------------------------------------------------------
28 bool
29 InputHandler::isPressed(SDLKey key) const
30 {
31 return m_pressed && m_pressed[key];
32 }
33 //-----------------------------------------------------------------
34 bool
35 InputHandler::isLeftPressed() const
36 {
37 return m_buttons & SDL_BUTTON(1);
38 }
39 //-----------------------------------------------------------------
40 bool
41 InputHandler::isMiddlePressed() const
42 {
43 return m_buttons & SDL_BUTTON(2);
44 }
45 //-----------------------------------------------------------------
46 bool
47 InputHandler::isRightPressed() const
48 {
49 return m_buttons & SDL_BUTTON(3);
50 }
51 //-----------------------------------------------------------------
52 std::string
53 InputHandler::toString() const
54 {
55 return ExInfo("input")
56 .addInfo("mouse", m_mouseLoc.toString())
57 .addInfo("buttons", m_buttons).info();
58 }
59