annotate Applications/Sdl/SdlEngine.cpp @ 236:f73d722d98c8 am

renamed folder
author am@osimis.io
date Tue, 19 Jun 2018 16:06:32 +0200
parents 84844649a8fd
children 46c5296d867e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
134
4cff7b1ed31d upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 84
diff changeset
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
47
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
10 * the License, or (at your option) any later version.
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
47
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
15 * Affero General Public License for more details.
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
16 *
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #include "SdlEngine.h"
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #if ORTHANC_ENABLE_SDL == 1
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
212
5412adf19980 resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
26 #include <Core/Logging.h>
201
e9c7a78a3e77 removed absolute paths
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 196
diff changeset
27
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include <SDL.h>
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 namespace OrthancStone
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 {
222
84844649a8fd continued: reusable applications
am@osimis.io
parents: 214
diff changeset
32 void SdlEngine::SetSize(BasicSdlApplicationContext::ViewportLocker& locker,
56
9e3c2e75b870 extremely simplified SDL engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
33 unsigned int width,
9e3c2e75b870 extremely simplified SDL engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
34 unsigned int height)
9e3c2e75b870 extremely simplified SDL engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
35 {
9e3c2e75b870 extremely simplified SDL engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
36 locker.GetViewport().SetSize(width, height);
9e3c2e75b870 extremely simplified SDL engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
37 surface_.SetSize(width, height);
9e3c2e75b870 extremely simplified SDL engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
38 }
9e3c2e75b870 extremely simplified SDL engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
39
9e3c2e75b870 extremely simplified SDL engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
40
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 void SdlEngine::RenderFrame()
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 {
56
9e3c2e75b870 extremely simplified SDL engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
43 if (viewportChanged_)
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 {
222
84844649a8fd continued: reusable applications
am@osimis.io
parents: 214
diff changeset
45 BasicSdlApplicationContext::ViewportLocker locker(context_);
56
9e3c2e75b870 extremely simplified SDL engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
46 surface_.Render(locker.GetViewport());
53
c2dc924f1a63 removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 51
diff changeset
47
56
9e3c2e75b870 extremely simplified SDL engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
48 viewportChanged_ = false;
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 KeyboardModifiers SdlEngine::GetKeyboardModifiers(const uint8_t* keyboardState,
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 const int scancodeCount)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 int result = KeyboardModifiers_None;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 if (keyboardState != NULL)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 if (SDL_SCANCODE_LSHIFT < scancodeCount &&
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 keyboardState[SDL_SCANCODE_LSHIFT])
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 result |= KeyboardModifiers_Shift;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 if (SDL_SCANCODE_RSHIFT < scancodeCount &&
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 keyboardState[SDL_SCANCODE_RSHIFT])
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 result |= KeyboardModifiers_Shift;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 if (SDL_SCANCODE_LCTRL < scancodeCount &&
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 keyboardState[SDL_SCANCODE_LCTRL])
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 result |= KeyboardModifiers_Control;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 if (SDL_SCANCODE_RCTRL < scancodeCount &&
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 keyboardState[SDL_SCANCODE_RCTRL])
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 result |= KeyboardModifiers_Control;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 if (SDL_SCANCODE_LALT < scancodeCount &&
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 keyboardState[SDL_SCANCODE_LALT])
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 result |= KeyboardModifiers_Alt;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 if (SDL_SCANCODE_RALT < scancodeCount &&
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 keyboardState[SDL_SCANCODE_RALT])
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 result |= KeyboardModifiers_Alt;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 return static_cast<KeyboardModifiers>(result);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 SdlEngine::SdlEngine(SdlWindow& window,
222
84844649a8fd continued: reusable applications
am@osimis.io
parents: 214
diff changeset
102 BasicSdlApplicationContext& context) :
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 window_(window),
53
c2dc924f1a63 removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 51
diff changeset
104 context_(context),
56
9e3c2e75b870 extremely simplified SDL engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
105 surface_(window),
9e3c2e75b870 extremely simplified SDL engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
106 viewportChanged_(true)
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 SdlEngine::~SdlEngine()
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 void SdlEngine::Run()
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 int scancodeCount = 0;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 const uint8_t* keyboardState = SDL_GetKeyboardState(&scancodeCount);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120
61
ca644004d2ee MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
121 {
222
84844649a8fd continued: reusable applications
am@osimis.io
parents: 214
diff changeset
122 BasicSdlApplicationContext::ViewportLocker locker(context_);
61
ca644004d2ee MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
123 SetSize(locker, window_.GetWidth(), window_.GetHeight());
ca644004d2ee MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
124 locker.GetViewport().SetDefaultView();
ca644004d2ee MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
125 }
ca644004d2ee MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
126
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 bool stop = false;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 while (!stop)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 {
56
9e3c2e75b870 extremely simplified SDL engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
130 RenderFrame();
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 SDL_Event event;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133
56
9e3c2e75b870 extremely simplified SDL engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
134 while (!stop &&
9e3c2e75b870 extremely simplified SDL engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
135 SDL_PollEvent(&event))
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 {
222
84844649a8fd continued: reusable applications
am@osimis.io
parents: 214
diff changeset
137 BasicSdlApplicationContext::ViewportLocker locker(context_);
53
c2dc924f1a63 removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 51
diff changeset
138
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 if (event.type == SDL_QUIT)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 stop = true;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 break;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 else if (event.type == SDL_MOUSEBUTTONDOWN)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 KeyboardModifiers modifiers = GetKeyboardModifiers(keyboardState, scancodeCount);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 switch (event.button.button)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 case SDL_BUTTON_LEFT:
53
c2dc924f1a63 removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 51
diff changeset
151 locker.GetViewport().MouseDown(MouseButton_Left, event.button.x, event.button.y, modifiers);
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 break;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 case SDL_BUTTON_RIGHT:
53
c2dc924f1a63 removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 51
diff changeset
155 locker.GetViewport().MouseDown(MouseButton_Right, event.button.x, event.button.y, modifiers);
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 break;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 case SDL_BUTTON_MIDDLE:
53
c2dc924f1a63 removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 51
diff changeset
159 locker.GetViewport().MouseDown(MouseButton_Middle, event.button.x, event.button.y, modifiers);
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 break;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 default:
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 break;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 else if (event.type == SDL_MOUSEMOTION)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 {
53
c2dc924f1a63 removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 51
diff changeset
168 locker.GetViewport().MouseMove(event.button.x, event.button.y);
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 else if (event.type == SDL_MOUSEBUTTONUP)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 {
53
c2dc924f1a63 removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 51
diff changeset
172 locker.GetViewport().MouseUp();
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 else if (event.type == SDL_WINDOWEVENT)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 switch (event.window.event)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 case SDL_WINDOWEVENT_LEAVE:
53
c2dc924f1a63 removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 51
diff changeset
179 locker.GetViewport().MouseLeave();
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 break;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 case SDL_WINDOWEVENT_ENTER:
53
c2dc924f1a63 removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 51
diff changeset
183 locker.GetViewport().MouseEnter();
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 break;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 case SDL_WINDOWEVENT_SIZE_CHANGED:
53
c2dc924f1a63 removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 51
diff changeset
187 SetSize(locker, event.window.data1, event.window.data2);
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 break;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 default:
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 break;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 else if (event.type == SDL_MOUSEWHEEL)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 KeyboardModifiers modifiers = GetKeyboardModifiers(keyboardState, scancodeCount);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 int x, y;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 SDL_GetMouseState(&x, &y);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 if (event.wheel.y > 0)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 {
53
c2dc924f1a63 removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 51
diff changeset
203 locker.GetViewport().MouseWheel(MouseWheelDirection_Up, x, y, modifiers);
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 else if (event.wheel.y < 0)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 {
53
c2dc924f1a63 removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 51
diff changeset
207 locker.GetViewport().MouseWheel(MouseWheelDirection_Down, x, y, modifiers);
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 }
56
9e3c2e75b870 extremely simplified SDL engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
210 else if (event.type == SDL_KEYDOWN &&
9e3c2e75b870 extremely simplified SDL engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
211 event.key.repeat == 0 /* Ignore key bounce */)
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 KeyboardModifiers modifiers = GetKeyboardModifiers(keyboardState, scancodeCount);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 switch (event.key.keysym.sym)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 {
167
0ee144f8f75a numeric pad
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
217 case SDLK_a: locker.GetViewport().KeyPressed('a', modifiers); break;
0ee144f8f75a numeric pad
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
218 case SDLK_b: locker.GetViewport().KeyPressed('b', modifiers); break;
0ee144f8f75a numeric pad
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
219 case SDLK_c: locker.GetViewport().KeyPressed('c', modifiers); break;
0ee144f8f75a numeric pad
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
220 case SDLK_d: locker.GetViewport().KeyPressed('d', modifiers); break;
0ee144f8f75a numeric pad
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
221 case SDLK_e: locker.GetViewport().KeyPressed('e', modifiers); break;
0ee144f8f75a numeric pad
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
222 case SDLK_f: window_.ToggleMaximize(); break;
0ee144f8f75a numeric pad
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
223 case SDLK_g: locker.GetViewport().KeyPressed('g', modifiers); break;
0ee144f8f75a numeric pad
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
224 case SDLK_h: locker.GetViewport().KeyPressed('h', modifiers); break;
0ee144f8f75a numeric pad
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
225 case SDLK_i: locker.GetViewport().KeyPressed('i', modifiers); break;
0ee144f8f75a numeric pad
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
226 case SDLK_j: locker.GetViewport().KeyPressed('j', modifiers); break;
0ee144f8f75a numeric pad
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
227 case SDLK_k: locker.GetViewport().KeyPressed('k', modifiers); break;
0ee144f8f75a numeric pad
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
228 case SDLK_l: locker.GetViewport().KeyPressed('l', modifiers); break;
0ee144f8f75a numeric pad
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
229 case SDLK_m: locker.GetViewport().KeyPressed('m', modifiers); break;
0ee144f8f75a numeric pad
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
230 case SDLK_n: locker.GetViewport().KeyPressed('n', modifiers); break;
0ee144f8f75a numeric pad
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
231 case SDLK_o: locker.GetViewport().KeyPressed('o', modifiers); break;
0ee144f8f75a numeric pad
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
232 case SDLK_p: locker.GetViewport().KeyPressed('p', modifiers); break;
0ee144f8f75a numeric pad
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
233 case SDLK_q: stop = true; break;
0ee144f8f75a numeric pad
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
234 case SDLK_r: locker.GetViewport().KeyPressed('r', modifiers); break;
0ee144f8f75a numeric pad
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
235 case SDLK_s: locker.GetViewport().KeyPressed('s', modifiers); break;
0ee144f8f75a numeric pad
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
236 case SDLK_t: locker.GetViewport().KeyPressed('t', modifiers); break;
0ee144f8f75a numeric pad
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
237 case SDLK_u: locker.GetViewport().KeyPressed('u', modifiers); break;
0ee144f8f75a numeric pad
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
238 case SDLK_v: locker.GetViewport().KeyPressed('v', modifiers); break;
0ee144f8f75a numeric pad
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
239 case SDLK_w: locker.GetViewport().KeyPressed('w', modifiers); break;
0ee144f8f75a numeric pad
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
240 case SDLK_x: locker.GetViewport().KeyPressed('x', modifiers); break;
0ee144f8f75a numeric pad
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
241 case SDLK_y: locker.GetViewport().KeyPressed('y', modifiers); break;
0ee144f8f75a numeric pad
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
242 case SDLK_z: locker.GetViewport().KeyPressed('z', modifiers); break;
0ee144f8f75a numeric pad
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
243 case SDLK_KP_0: locker.GetViewport().KeyPressed('0', modifiers); break;
0ee144f8f75a numeric pad
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
244 case SDLK_KP_1: locker.GetViewport().KeyPressed('1', modifiers); break;
0ee144f8f75a numeric pad
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
245 case SDLK_KP_2: locker.GetViewport().KeyPressed('2', modifiers); break;
0ee144f8f75a numeric pad
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
246 case SDLK_KP_3: locker.GetViewport().KeyPressed('3', modifiers); break;
0ee144f8f75a numeric pad
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
247 case SDLK_KP_4: locker.GetViewport().KeyPressed('4', modifiers); break;
0ee144f8f75a numeric pad
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
248 case SDLK_KP_5: locker.GetViewport().KeyPressed('5', modifiers); break;
0ee144f8f75a numeric pad
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
249 case SDLK_KP_6: locker.GetViewport().KeyPressed('6', modifiers); break;
0ee144f8f75a numeric pad
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
250 case SDLK_KP_7: locker.GetViewport().KeyPressed('7', modifiers); break;
0ee144f8f75a numeric pad
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
251 case SDLK_KP_8: locker.GetViewport().KeyPressed('8', modifiers); break;
0ee144f8f75a numeric pad
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
252 case SDLK_KP_9: locker.GetViewport().KeyPressed('9', modifiers); break;
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253
170
0261909fa6f0 add support for plus/minus in SDL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 167
diff changeset
254 case SDLK_PLUS:
0261909fa6f0 add support for plus/minus in SDL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 167
diff changeset
255 case SDLK_KP_PLUS:
0261909fa6f0 add support for plus/minus in SDL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 167
diff changeset
256 locker.GetViewport().KeyPressed('+', modifiers); break;
0261909fa6f0 add support for plus/minus in SDL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 167
diff changeset
257
0261909fa6f0 add support for plus/minus in SDL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 167
diff changeset
258 case SDLK_MINUS:
0261909fa6f0 add support for plus/minus in SDL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 167
diff changeset
259 case SDLK_KP_MINUS:
0261909fa6f0 add support for plus/minus in SDL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 167
diff changeset
260 locker.GetViewport().KeyPressed('-', modifiers); break;
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 default:
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 break;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267
98
a33abae66344 scrolling over series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 63
diff changeset
268 // Small delay to avoid using 100% of CPU
a33abae66344 scrolling over series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 63
diff changeset
269 SDL_Delay(1);
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 #endif