source: trunk/src/input/input.cpp @ 2918

Last change on this file since 2918 was 2918, checked in by benlitz, 6 years ago

input: added a GetAvailableDevices function to retrieve device names.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
File size: 1.8 KB
Line 
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2013 Benjamin Litzelmann
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
7//   Public License, Version 2, as published by Sam Hocevar. See
8//   http://www.wtfpl.net/ for more details.
9//
10
11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#include "core.h"
16
17#include "input/input_internal.h"
18
19namespace lol
20{
21
22Array<InputDevice*> InputDevice::devices;
23bool InputDevice::m_capturemouse;
24
25Array<String> InputDevice::GetAvailableDevices()
26{
27    Array<String> result;
28    for (int i = 0; i < devices.Count(); ++i)
29    {
30        result.Push(devices[i]->m_name);
31    }
32    return result;
33}
34
35void InputDeviceInternal::AddKey(const char* name)
36{
37    m_keynames.Push(name);
38    m_keys.Push(false);
39}
40
41void InputDeviceInternal::AddAxis(const char* name, float sensitivity)
42{
43    m_axisnames.Push(name);
44    m_axis.Push(0.0f, sensitivity);
45}
46
47void InputDeviceInternal::AddCursor(const char* name)
48{
49    m_cursornames.Push(name);
50    m_cursors.Push(vec2(0.0), ivec2(0));
51}
52
53InputDeviceInternal* InputDeviceInternal::CreateStandardKeyboard()
54{
55    InputDeviceInternal* keyboard = new InputDeviceInternal("Keyboard");
56    /* "value" is unused, what matters is the index. */
57#   define KEY_FUNC(key, value) \
58        keyboard->AddKey(#key);
59#   include "input/keys.h"
60#   undef KEY_FUNC
61    return keyboard;
62}
63
64InputDeviceInternal* InputDeviceInternal::CreateStandardMouse()
65{
66    InputDeviceInternal* mouse = new InputDeviceInternal("Mouse");
67    mouse->AddKey("ButtonLeft");
68    mouse->AddKey("ButtonMiddle");
69    mouse->AddKey("ButtonRight");
70
71    mouse->AddAxis("X");
72    mouse->AddAxis("Y");
73
74    mouse->AddCursor("Cursor");
75
76    // TODO: extended button, and wheel (as axis or as buttons? or both?)
77    return mouse;
78}
79
80} /* namespace lol */
Note: See TracBrowser for help on using the repository browser.