Symphony Of Empires
event.cpp
Go to the documentation of this file.
1
// Eng3D - General purpouse game engine
2
// Copyright (C) 2021, Eng3D contributors
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 3 of the License, or
7
// (at your option) any later version.
8
//
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with this program. If not, see <https://www.gnu.org/licenses/>.
16
//
17
// ----------------------------------------------------------------------------
18
// Name:
19
// event.cpp
20
//
21
// Abstract:
22
// Does important stuff.
23
// ----------------------------------------------------------------------------
24
25
#include <SDL.h>
26
#include <SDL_events.h>
27
#include <SDL_keycode.h>
28
#include <SDL_mouse.h>
29
30
#include "eng3d/event.hpp"
31
32
Eng3D::Event::Key::Type
Eng3D::Event::Key::from_sdl
(
int
sdl) {
33
// Use a simple switch case jumptable
34
switch
(sdl) {
35
// Alphabet
36
case
SDLK_a:
return
Eng3D::Event::Key::Type::A
;
37
case
SDLK_b:
return
Eng3D::Event::Key::Type::B
;
38
case
SDLK_c:
return
Eng3D::Event::Key::Type::C
;
39
case
SDLK_d:
return
Eng3D::Event::Key::Type::D
;
40
case
SDLK_e:
return
Eng3D::Event::Key::Type::E
;
41
case
SDLK_f:
return
Eng3D::Event::Key::Type::F
;
42
case
SDLK_g:
return
Eng3D::Event::Key::Type::G
;
43
case
SDLK_h:
return
Eng3D::Event::Key::Type::H
;
44
case
SDLK_i:
return
Eng3D::Event::Key::Type::I
;
45
case
SDLK_j:
return
Eng3D::Event::Key::Type::J
;
46
case
SDLK_k:
return
Eng3D::Event::Key::Type::K
;
47
case
SDLK_l:
return
Eng3D::Event::Key::Type::L
;
48
case
SDLK_m:
return
Eng3D::Event::Key::Type::M
;
49
case
SDLK_n:
return
Eng3D::Event::Key::Type::N
;
50
case
SDLK_o:
return
Eng3D::Event::Key::Type::O
;
51
case
SDLK_p:
return
Eng3D::Event::Key::Type::P
;
52
case
SDLK_q:
return
Eng3D::Event::Key::Type::Q
;
53
case
SDLK_r:
return
Eng3D::Event::Key::Type::R
;
54
case
SDLK_s:
return
Eng3D::Event::Key::Type::S
;
55
case
SDLK_t:
return
Eng3D::Event::Key::Type::T
;
56
case
SDLK_u:
return
Eng3D::Event::Key::Type::U
;
57
case
SDLK_v:
return
Eng3D::Event::Key::Type::V
;
58
case
SDLK_w:
return
Eng3D::Event::Key::Type::W
;
59
case
SDLK_x:
return
Eng3D::Event::Key::Type::X
;
60
case
SDLK_y:
return
Eng3D::Event::Key::Type::Y
;
61
case
SDLK_z:
return
Eng3D::Event::Key::Type::Z
;
62
// Numericals
63
case
SDLK_0:
return
Eng3D::Event::Key::Type::NUM_0
;
64
case
SDLK_1:
return
Eng3D::Event::Key::Type::NUM_1
;
65
case
SDLK_2:
return
Eng3D::Event::Key::Type::NUM_2
;
66
case
SDLK_3:
return
Eng3D::Event::Key::Type::NUM_3
;
67
case
SDLK_4:
return
Eng3D::Event::Key::Type::NUM_4
;
68
case
SDLK_5:
return
Eng3D::Event::Key::Type::NUM_5
;
69
case
SDLK_6:
return
Eng3D::Event::Key::Type::NUM_6
;
70
case
SDLK_7:
return
Eng3D::Event::Key::Type::NUM_7
;
71
case
SDLK_8:
return
Eng3D::Event::Key::Type::NUM_8
;
72
case
SDLK_9:
return
Eng3D::Event::Key::Type::NUM_9
;
73
// Function
74
case
SDLK_F1:
return
Eng3D::Event::Key::Type::F1
;
75
case
SDLK_F2:
return
Eng3D::Event::Key::Type::F2
;
76
case
SDLK_F3:
return
Eng3D::Event::Key::Type::F3
;
77
case
SDLK_F4:
return
Eng3D::Event::Key::Type::F4
;
78
case
SDLK_F5:
return
Eng3D::Event::Key::Type::F5
;
79
case
SDLK_F6:
return
Eng3D::Event::Key::Type::F6
;
80
case
SDLK_F7:
return
Eng3D::Event::Key::Type::F7
;
81
case
SDLK_F8:
return
Eng3D::Event::Key::Type::F8
;
82
case
SDLK_F9:
return
Eng3D::Event::Key::Type::F9
;
83
case
SDLK_F10:
return
Eng3D::Event::Key::Type::F10
;
84
case
SDLK_F11:
return
Eng3D::Event::Key::Type::F11
;
85
case
SDLK_F12:
return
Eng3D::Event::Key::Type::F12
;
86
// Arrow keys
87
case
SDLK_UP:
return
Eng3D::Event::Key::Type::UP
;
88
case
SDLK_DOWN:
return
Eng3D::Event::Key::Type::DOWN
;
89
case
SDLK_LEFT:
return
Eng3D::Event::Key::Type::LEFT
;
90
case
SDLK_RIGHT:
return
Eng3D::Event::Key::Type::RIGHT
;
91
// Miscellaneous
92
case
SDLK_SPACE:
return
Eng3D::Event::Key::Type::SPACE
;
93
case
SDLK_BACKSPACE:
return
Eng3D::Event::Key::Type::BACKSPACE
;
94
case
SDLK_ESCAPE:
return
Eng3D::Event::Key::Type::ESC
;
95
case
SDLK_BACKSLASH:
// Fallthrough
96
case
SDLK_BACKQUOTE:
return
Eng3D::Event::Key::Type::TILDE
;
97
}
98
return
Eng3D::Event::Key::Type::NONE
;
99
}
100
101
Eng3D::Event::MouseButton::Type
Eng3D::Event::MouseButton::from_sdl
(
int
sdl) {
102
switch
(sdl) {
103
case
SDL_BUTTON_LEFT:
return
Eng3D::Event::MouseButton::Type::LEFT
;
104
case
SDL_BUTTON_RIGHT:
return
Eng3D::Event::MouseButton::Type::RIGHT
;
105
case
SDL_BUTTON_MIDDLE:
return
Eng3D::Event::MouseButton::Type::MIDDLE
;
106
}
107
return
Eng3D::Event::MouseButton::Type::NONE
;
108
}
109
110
glm::ivec2
Eng3D::Event::get_mouse_pos
() {
111
int
sdl_x, sdl_y;
112
SDL_GetMouseState(&sdl_x, &sdl_y);
113
return
glm::ivec2{ sdl_x, sdl_y };
114
}
Eng3D::Event::get_mouse_pos
glm::ivec2 get_mouse_pos()
Definition:
event.cpp:110
Eng3D::Event::Key::from_sdl
Eng3D::Event::Key::Type from_sdl(int sdl)
Definition:
event.cpp:32
Eng3D::Event::Key::Type
Type
Definition:
event.hpp:32
Eng3D::Event::Key::Type::X
@ X
Eng3D::Event::Key::Type::NUM_5
@ NUM_5
Eng3D::Event::Key::Type::NUM_0
@ NUM_0
Eng3D::Event::Key::Type::C
@ C
Eng3D::Event::Key::Type::NUM_1
@ NUM_1
Eng3D::Event::Key::Type::F6
@ F6
Eng3D::Event::Key::Type::RIGHT
@ RIGHT
Eng3D::Event::Key::Type::Z
@ Z
Eng3D::Event::Key::Type::F5
@ F5
Eng3D::Event::Key::Type::E
@ E
Eng3D::Event::Key::Type::NUM_6
@ NUM_6
Eng3D::Event::Key::Type::P
@ P
Eng3D::Event::Key::Type::F7
@ F7
Eng3D::Event::Key::Type::F8
@ F8
Eng3D::Event::Key::Type::F3
@ F3
Eng3D::Event::Key::Type::U
@ U
Eng3D::Event::Key::Type::V
@ V
Eng3D::Event::Key::Type::TILDE
@ TILDE
Eng3D::Event::Key::Type::Y
@ Y
Eng3D::Event::Key::Type::S
@ S
Eng3D::Event::Key::Type::W
@ W
Eng3D::Event::Key::Type::ESC
@ ESC
Eng3D::Event::Key::Type::F11
@ F11
Eng3D::Event::Key::Type::SPACE
@ SPACE
Eng3D::Event::Key::Type::LEFT
@ LEFT
Eng3D::Event::Key::Type::M
@ M
Eng3D::Event::Key::Type::BACKSPACE
@ BACKSPACE
Eng3D::Event::Key::Type::A
@ A
Eng3D::Event::Key::Type::F
@ F
Eng3D::Event::Key::Type::F9
@ F9
Eng3D::Event::Key::Type::N
@ N
Eng3D::Event::Key::Type::NUM_4
@ NUM_4
Eng3D::Event::Key::Type::B
@ B
Eng3D::Event::Key::Type::NUM_3
@ NUM_3
Eng3D::Event::Key::Type::K
@ K
Eng3D::Event::Key::Type::NUM_2
@ NUM_2
Eng3D::Event::Key::Type::NUM_9
@ NUM_9
Eng3D::Event::Key::Type::F10
@ F10
Eng3D::Event::Key::Type::NONE
@ NONE
Eng3D::Event::Key::Type::T
@ T
Eng3D::Event::Key::Type::H
@ H
Eng3D::Event::Key::Type::DOWN
@ DOWN
Eng3D::Event::Key::Type::L
@ L
Eng3D::Event::Key::Type::I
@ I
Eng3D::Event::Key::Type::NUM_8
@ NUM_8
Eng3D::Event::Key::Type::G
@ G
Eng3D::Event::Key::Type::F1
@ F1
Eng3D::Event::Key::Type::R
@ R
Eng3D::Event::Key::Type::F4
@ F4
Eng3D::Event::Key::Type::F12
@ F12
Eng3D::Event::Key::Type::Q
@ Q
Eng3D::Event::Key::Type::O
@ O
Eng3D::Event::Key::Type::NUM_7
@ NUM_7
Eng3D::Event::Key::Type::D
@ D
Eng3D::Event::Key::Type::UP
@ UP
Eng3D::Event::Key::Type::F2
@ F2
Eng3D::Event::Key::Type::J
@ J
Eng3D::Event::MouseButton::from_sdl
Eng3D::Event::MouseButton::Type from_sdl(int sdl)
Definition:
event.cpp:101
Eng3D::Event::MouseButton::Type
Type
Definition:
event.hpp:55
Eng3D::Event::MouseButton::Type::RIGHT
@ RIGHT
Eng3D::Event::MouseButton::Type::MIDDLE
@ MIDDLE
Eng3D::Event::MouseButton::Type::LEFT
@ LEFT
Eng3D::Event::MouseButton::Type::NONE
@ NONE
eng3d
src
event.cpp
Generated by
1.9.1