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 
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  }
99 }
100 
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  }
108 }
109 
111  int sdl_x, sdl_y;
112  SDL_GetMouseState(&sdl_x, &sdl_y);
113  return glm::ivec2{ sdl_x, sdl_y };
114 }
glm::ivec2 get_mouse_pos()
Definition: event.cpp:110
Eng3D::Event::Key::Type from_sdl(int sdl)
Definition: event.cpp:32
Eng3D::Event::MouseButton::Type from_sdl(int sdl)
Definition: event.cpp:101