Mercurial > hg > orthanc-stone
comparison Samples/Sdl/BasicScene.cpp @ 818:e42b491f1fb2
Removed typedefs to shared_ptr by making them explicit. Removed using namespace
directives to make usage more explicit, too.
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Wed, 29 May 2019 10:51:28 +0200 |
parents | 61ba4b504e9a |
children | 80829436ce0c e3c56d4f863f |
comparison
equal
deleted
inserted
replaced
817:68f888812af4 | 818:e42b491f1fb2 |
---|---|
47 #include <stdio.h> | 47 #include <stdio.h> |
48 | 48 |
49 static const unsigned int FONT_SIZE = 32; | 49 static const unsigned int FONT_SIZE = 32; |
50 static const int LAYER_POSITION = 150; | 50 static const int LAYER_POSITION = 150; |
51 | 51 |
52 using namespace OrthancStone; | 52 void PrepareScene(boost::shared_ptr<OrthancStone::ViewportController> controller) |
53 | 53 { |
54 void PrepareScene(ViewportControllerPtr controller) | 54 using namespace OrthancStone; |
55 { | |
56 Scene2D& scene(*controller->GetScene()); | 55 Scene2D& scene(*controller->GetScene()); |
57 // Texture of 2x2 size | 56 // Texture of 2x2 size |
58 { | 57 { |
59 Orthanc::Image i(Orthanc::PixelFormat_RGB24, 2, 2, false); | 58 Orthanc::Image i(Orthanc::PixelFormat_RGB24, 2, 2, false); |
60 | 59 |
139 } | 138 } |
140 } | 139 } |
141 | 140 |
142 | 141 |
143 void TakeScreenshot(const std::string& target, | 142 void TakeScreenshot(const std::string& target, |
144 const Scene2D& scene, | 143 const OrthancStone::Scene2D& scene, |
145 unsigned int canvasWidth, | 144 unsigned int canvasWidth, |
146 unsigned int canvasHeight) | 145 unsigned int canvasHeight) |
147 { | 146 { |
147 using namespace OrthancStone; | |
148 // Take a screenshot, then save it as PNG file | 148 // Take a screenshot, then save it as PNG file |
149 CairoCompositor compositor(scene, canvasWidth, canvasHeight); | 149 CairoCompositor compositor(scene, canvasWidth, canvasHeight); |
150 compositor.SetFont(0, Orthanc::EmbeddedResources::UBUNTU_FONT, FONT_SIZE, Orthanc::Encoding_Latin1); | 150 compositor.SetFont(0, Orthanc::EmbeddedResources::UBUNTU_FONT, FONT_SIZE, Orthanc::Encoding_Latin1); |
151 compositor.Refresh(); | 151 compositor.Refresh(); |
152 | 152 |
159 Orthanc::PngWriter writer; | 159 Orthanc::PngWriter writer; |
160 writer.WriteToFile(target, png); | 160 writer.WriteToFile(target, png); |
161 } | 161 } |
162 | 162 |
163 | 163 |
164 void HandleApplicationEvent(ViewportControllerPtr controller, | 164 void HandleApplicationEvent(boost::shared_ptr<OrthancStone::ViewportController> controller, |
165 const OpenGLCompositor& compositor, | 165 const OrthancStone::OpenGLCompositor& compositor, |
166 const SDL_Event& event, | 166 const SDL_Event& event, |
167 FlexiblePointerTrackerPtr& activeTracker) | 167 boost::shared_ptr<OrthancStone::IFlexiblePointerTracker>& activeTracker) |
168 { | 168 { |
169 using namespace OrthancStone; | |
169 Scene2D& scene(*controller->GetScene()); | 170 Scene2D& scene(*controller->GetScene()); |
170 if (event.type == SDL_MOUSEMOTION) | 171 if (event.type == SDL_MOUSEMOTION) |
171 { | 172 { |
172 int scancodeCount = 0; | 173 int scancodeCount = 0; |
173 const uint8_t* keyboardState = SDL_GetKeyboardState(&scancodeCount); | 174 const uint8_t* keyboardState = SDL_GetKeyboardState(&scancodeCount); |
273 type, severity, message ); | 274 type, severity, message ); |
274 } | 275 } |
275 } | 276 } |
276 | 277 |
277 | 278 |
278 void Run(ViewportControllerPtr controller) | 279 void Run(boost::shared_ptr<OrthancStone::ViewportController> controller) |
279 { | 280 { |
281 using namespace OrthancStone; | |
280 SdlOpenGLWindow window("Hello", 1024, 768); | 282 SdlOpenGLWindow window("Hello", 1024, 768); |
281 | 283 |
282 controller->FitContent(window.GetCanvasWidth(), window.GetCanvasHeight()); | 284 controller->FitContent(window.GetCanvasWidth(), window.GetCanvasHeight()); |
283 | 285 |
284 glEnable(GL_DEBUG_OUTPUT); | 286 glEnable(GL_DEBUG_OUTPUT); |
286 | 288 |
287 OpenGLCompositor compositor(window, *controller->GetScene()); | 289 OpenGLCompositor compositor(window, *controller->GetScene()); |
288 compositor.SetFont(0, Orthanc::EmbeddedResources::UBUNTU_FONT, | 290 compositor.SetFont(0, Orthanc::EmbeddedResources::UBUNTU_FONT, |
289 FONT_SIZE, Orthanc::Encoding_Latin1); | 291 FONT_SIZE, Orthanc::Encoding_Latin1); |
290 | 292 |
291 FlexiblePointerTrackerPtr tracker; | 293 boost::shared_ptr<IFlexiblePointerTracker> tracker; |
292 | 294 |
293 bool stop = false; | 295 bool stop = false; |
294 while (!stop) | 296 while (!stop) |
295 { | 297 { |
296 compositor.Refresh(); | 298 compositor.Refresh(); |
365 * Windows. Otherwise, one gets the linking error "undefined reference | 367 * Windows. Otherwise, one gets the linking error "undefined reference |
366 * to `SDL_main'". https://wiki.libsdl.org/FAQWindows | 368 * to `SDL_main'". https://wiki.libsdl.org/FAQWindows |
367 **/ | 369 **/ |
368 int main(int argc, char* argv[]) | 370 int main(int argc, char* argv[]) |
369 { | 371 { |
372 using namespace OrthancStone; | |
370 StoneInitialize(); | 373 StoneInitialize(); |
371 Orthanc::Logging::EnableInfoLevel(true); | 374 Orthanc::Logging::EnableInfoLevel(true); |
372 | 375 |
373 try | 376 try |
374 { | 377 { |
375 MessageBroker broker; | 378 MessageBroker broker; |
376 ViewportControllerPtr controller = boost::make_shared<ViewportController>( | 379 boost::shared_ptr<ViewportController> controller = boost::make_shared<ViewportController>( |
377 boost::ref(broker)); | 380 boost::ref(broker)); |
378 PrepareScene(controller); | 381 PrepareScene(controller); |
379 Run(controller); | 382 Run(controller); |
380 } | 383 } |
381 catch (Orthanc::OrthancException& e) | 384 catch (Orthanc::OrthancException& e) |