Mercurial > hg > orthanc-stone
comparison Samples/Sdl/BasicScene.cpp @ 617:7efa2543699d
simplification
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 02 May 2019 18:21:59 +0200 |
parents | 412a2d01a189 |
children | 462a5074f914 |
comparison
equal
deleted
inserted
replaced
616:97926984d5d0 | 617:7efa2543699d |
---|---|
155 writer.WriteToFile(target, png); | 155 writer.WriteToFile(target, png); |
156 } | 156 } |
157 | 157 |
158 | 158 |
159 void HandleApplicationEvent(OrthancStone::Scene2D& scene, | 159 void HandleApplicationEvent(OrthancStone::Scene2D& scene, |
160 const OrthancStone::OpenGLCompositor& compositor, | |
160 const SDL_Event& event, | 161 const SDL_Event& event, |
161 std::auto_ptr<OrthancStone::IPointerTracker>& activeTracker, | 162 std::auto_ptr<OrthancStone::IPointerTracker>& activeTracker) |
162 unsigned int windowWidth, | 163 { |
163 unsigned int windowHeight) | |
164 { | |
165 bool hasPositionLayer = false; | |
166 | |
167 if (event.type == SDL_MOUSEMOTION) | 164 if (event.type == SDL_MOUSEMOTION) |
168 { | 165 { |
169 int scancodeCount = 0; | 166 int scancodeCount = 0; |
170 const uint8_t* keyboardState = SDL_GetKeyboardState(&scancodeCount); | 167 const uint8_t* keyboardState = SDL_GetKeyboardState(&scancodeCount); |
171 | 168 |
174 keyboardState[SDL_SCANCODE_LCTRL]) | 171 keyboardState[SDL_SCANCODE_LCTRL]) |
175 { | 172 { |
176 // The "left-ctrl" key is down, while no tracker is present | 173 // The "left-ctrl" key is down, while no tracker is present |
177 | 174 |
178 OrthancStone::PointerEvent e; | 175 OrthancStone::PointerEvent e; |
179 e.AddIntegerPosition(event.button.x - static_cast<int>(windowWidth) / 2, | 176 e.AddPosition(compositor.GetPixelCenterCoordinates(event.button.x, event.button.y)); |
180 event.button.y - static_cast<int>(windowHeight) / 2); | 177 |
181 OrthancStone::ScenePoint2D p = e.GetMainPosition().Apply(scene.GetCanvasToSceneTransform()); | 178 OrthancStone::ScenePoint2D p = e.GetMainPosition().Apply(scene.GetCanvasToSceneTransform()); |
182 | 179 |
183 char buf[64]; | 180 char buf[64]; |
184 sprintf(buf, "(%0.02f,%0.02f)", p.GetX(), p.GetY()); | 181 sprintf(buf, "(%0.02f,%0.02f)", p.GetX(), p.GetY()); |
185 | 182 |
198 layer->SetBorder(20); | 195 layer->SetBorder(20); |
199 layer->SetAnchor(OrthancStone::BitmapAnchor_BottomCenter); | 196 layer->SetAnchor(OrthancStone::BitmapAnchor_BottomCenter); |
200 layer->SetPosition(p.GetX(), p.GetY()); | 197 layer->SetPosition(p.GetX(), p.GetY()); |
201 scene.SetLayer(LAYER_POSITION, layer.release()); | 198 scene.SetLayer(LAYER_POSITION, layer.release()); |
202 } | 199 } |
203 | 200 } |
204 hasPositionLayer = true; | 201 else |
202 { | |
203 scene.DeleteLayer(LAYER_POSITION); | |
205 } | 204 } |
206 } | 205 } |
207 else if (event.type == SDL_MOUSEBUTTONDOWN) | 206 else if (event.type == SDL_MOUSEBUTTONDOWN) |
208 { | 207 { |
209 OrthancStone::PointerEvent e; | 208 OrthancStone::PointerEvent e; |
210 e.AddIntegerPosition(event.button.x, event.button.y); | 209 e.AddPosition(compositor.GetPixelCenterCoordinates(event.button.x, event.button.y)); |
211 | 210 |
212 switch (event.button.button) | 211 switch (event.button.button) |
213 { | 212 { |
214 case SDL_BUTTON_MIDDLE: | 213 case SDL_BUTTON_MIDDLE: |
215 activeTracker.reset(new OrthancStone::PanSceneTracker(scene, e)); | 214 activeTracker.reset(new OrthancStone::PanSceneTracker(scene, e)); |
216 break; | 215 break; |
217 | 216 |
218 case SDL_BUTTON_RIGHT: | 217 case SDL_BUTTON_RIGHT: |
219 activeTracker.reset(new OrthancStone::ZoomSceneTracker | 218 activeTracker.reset(new OrthancStone::ZoomSceneTracker(scene, e, |
220 (scene, e, windowWidth, windowHeight)); | 219 compositor.GetCanvasHeight())); |
221 break; | 220 break; |
222 | 221 |
223 case SDL_BUTTON_LEFT: | 222 case SDL_BUTTON_LEFT: |
224 activeTracker.reset(new OrthancStone::RotateSceneTracker | 223 activeTracker.reset(new OrthancStone::RotateSceneTracker(scene, e)); |
225 (scene, e, windowWidth, windowHeight)); | |
226 break; | 224 break; |
227 | 225 |
228 default: | 226 default: |
229 break; | 227 break; |
230 } | 228 } |
233 event.key.repeat == 0 /* Ignore key bounce */) | 231 event.key.repeat == 0 /* Ignore key bounce */) |
234 { | 232 { |
235 switch (event.key.keysym.sym) | 233 switch (event.key.keysym.sym) |
236 { | 234 { |
237 case SDLK_s: | 235 case SDLK_s: |
238 scene.FitContent(windowWidth, windowHeight); | 236 scene.FitContent(compositor.GetCanvasWidth(), |
237 compositor.GetCanvasHeight()); | |
239 break; | 238 break; |
240 | 239 |
241 case SDLK_c: | 240 case SDLK_c: |
242 TakeScreenshot("screenshot.png", scene, windowWidth, windowHeight); | 241 TakeScreenshot("screenshot.png", scene, |
242 compositor.GetCanvasWidth(), | |
243 compositor.GetCanvasHeight()); | |
243 break; | 244 break; |
244 | 245 |
245 default: | 246 default: |
246 break; | 247 break; |
247 } | 248 } |
248 } | |
249 | |
250 if (!hasPositionLayer) | |
251 { | |
252 scene.DeleteLayer(LAYER_POSITION); | |
253 } | 249 } |
254 } | 250 } |
255 | 251 |
256 | 252 |
257 static void GLAPIENTRY | 253 static void GLAPIENTRY |
304 else if (event.type == SDL_MOUSEMOTION) | 300 else if (event.type == SDL_MOUSEMOTION) |
305 { | 301 { |
306 if (tracker.get() != NULL) | 302 if (tracker.get() != NULL) |
307 { | 303 { |
308 OrthancStone::PointerEvent e; | 304 OrthancStone::PointerEvent e; |
309 e.AddIntegerPosition(event.button.x, event.button.y); | 305 e.AddPosition(compositor.GetPixelCenterCoordinates(event.button.x, event.button.y)); |
310 tracker->Update(e); | 306 tracker->Update(e); |
311 } | 307 } |
312 } | 308 } |
313 else if (event.type == SDL_MOUSEBUTTONUP) | 309 else if (event.type == SDL_MOUSEBUTTONUP) |
314 { | 310 { |
340 default: | 336 default: |
341 break; | 337 break; |
342 } | 338 } |
343 } | 339 } |
344 | 340 |
345 HandleApplicationEvent(scene, event, tracker, window.GetCanvasWidth(), window.GetCanvasHeight()); | 341 HandleApplicationEvent(scene, compositor, event, tracker); |
346 } | 342 } |
347 | 343 |
348 SDL_Delay(1); | 344 SDL_Delay(1); |
349 } | 345 } |
350 } | 346 } |