annotate Samples/MultiPlatform/BasicScene/mainSdl.cpp @ 1310:9bea7e15b519 broker

- first pass at changes to cope with the refactoring of the loading system - global loader-related data accessible through ILoadersContext::ILock - many changes in legacy loaders (CT, RTSTRUCT, DOSE) + loader cache - NOT FINISHED! there are shared_from_this calls in ctors! this will crash!
author Benjamin Golinvaux <bgo@osimis.io>
date Mon, 09 Mar 2020 14:53:22 +0100
parents 2d8ab34c8c91
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
916
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
1 /**
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
2 * Stone of Orthanc
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
1270
2d8ab34c8c91 upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 938
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
916
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
6 *
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
10 * the License, or (at your option) any later version.
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
11 *
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
15 * Affero General Public License for more details.
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
16 *
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
19 **/
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
20
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
21
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
22 // From Stone
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
23 #include "Framework/Viewport/SdlViewport.h"
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
24 #include "Framework/Scene2D/OpenGLCompositor.h"
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
25 #include "Framework/Scene2DViewport/UndoStack.h"
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
26 #include "Framework/StoneInitialization.h"
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
27 #include "Framework/Messages/MessageBroker.h"
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
28
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
29 // From Orthanc framework
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
30 #include <Core/Logging.h>
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
31 #include <Core/OrthancException.h>
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
32
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
33 #include <boost/make_shared.hpp>
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
34 #include <boost/ref.hpp>
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
35
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
36 #include <SDL.h>
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
37 #include <stdio.h>
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
38
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
39
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
40 #include "BasicScene.h"
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
41
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
42 using namespace OrthancStone;
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
43
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
44 boost::shared_ptr<BasicScene2DInteractor> interactor;
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
45
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
46 void HandleApplicationEvent(boost::shared_ptr<OrthancStone::ViewportController> controller,
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
47 const SDL_Event& event)
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
48 {
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
49 using namespace OrthancStone;
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
50 Scene2D& scene(controller->GetScene());
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
51 if (event.type == SDL_MOUSEBUTTONDOWN || event.type == SDL_MOUSEBUTTONUP || event.type == SDL_MOUSEMOTION)
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
52 {
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
53 // TODO: this code is copy/pasted from GuiAdapter::Run() -> find the right place
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
54 int scancodeCount = 0;
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
55 const uint8_t* keyboardState = SDL_GetKeyboardState(&scancodeCount);
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
56 bool ctrlPressed(false);
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
57 bool shiftPressed(false);
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
58 bool altPressed(false);
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
59
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
60 if (SDL_SCANCODE_LCTRL < scancodeCount && keyboardState[SDL_SCANCODE_LCTRL])
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
61 ctrlPressed = true;
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
62 if (SDL_SCANCODE_RCTRL < scancodeCount && keyboardState[SDL_SCANCODE_RCTRL])
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
63 ctrlPressed = true;
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
64 if (SDL_SCANCODE_LSHIFT < scancodeCount && keyboardState[SDL_SCANCODE_LSHIFT])
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
65 shiftPressed = true;
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
66 if (SDL_SCANCODE_RSHIFT < scancodeCount && keyboardState[SDL_SCANCODE_RSHIFT])
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
67 shiftPressed = true;
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
68 if (SDL_SCANCODE_LALT < scancodeCount && keyboardState[SDL_SCANCODE_LALT])
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
69 altPressed = true;
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
70
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
71 GuiAdapterMouseEvent guiEvent;
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
72 ConvertFromPlatform(guiEvent, ctrlPressed, shiftPressed, altPressed, event);
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
73 PointerEvent pointerEvent;
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
74 pointerEvent.AddPosition(controller->GetViewport().GetPixelCenterCoordinates(event.button.x, event.button.y));
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
75
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
76 interactor->OnMouseEvent(guiEvent, pointerEvent);
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
77 return;
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
78 }
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
79 else if ((event.type == SDL_KEYDOWN || event.type == SDL_KEYUP) && event.key.repeat == 0 /* Ignore key bounce */)
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
80 {
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
81 GuiAdapterKeyboardEvent guiEvent;
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
82 ConvertFromPlatform(guiEvent, event);
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
83
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
84 interactor->OnKeyboardEvent(guiEvent);
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
85 }
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
86
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
87 }
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
88
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
89
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
90 static void GLAPIENTRY
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
91 OpenGLMessageCallback(GLenum source,
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
92 GLenum type,
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
93 GLuint id,
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
94 GLenum severity,
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
95 GLsizei length,
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
96 const GLchar* message,
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
97 const void* userParam )
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
98 {
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
99 if (severity != GL_DEBUG_SEVERITY_NOTIFICATION)
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
100 {
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
101 fprintf(stderr, "GL CALLBACK: %s type = 0x%x, severity = 0x%x, message = %s\n",
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
102 ( type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : "" ),
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
103 type, severity, message );
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
104 }
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
105 }
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
106
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
107
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
108 void Run(boost::shared_ptr<OrthancStone::ViewportController> controller)
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
109 {
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
110 SdlViewport& sdlViewport = dynamic_cast<SdlViewport&>(controller->GetViewport());
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
111
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
112 glEnable(GL_DEBUG_OUTPUT);
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
113 glDebugMessageCallback(OpenGLMessageCallback, 0);
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
114
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
115 controller->GetViewport().GetCompositor().SetFont(0, Orthanc::EmbeddedResources::UBUNTU_FONT,
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
116 BASIC_SCENE_FONT_SIZE, Orthanc::Encoding_Latin1);
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
117
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
118 controller->GetViewport().Refresh();
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
119 controller->FitContent();
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
120
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
121
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
122 bool stop = false;
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
123 while (!stop)
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
124 {
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
125 controller->GetViewport().Refresh();
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
126
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
127 SDL_Event event;
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
128 while (!stop &&
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
129 SDL_PollEvent(&event))
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
130 {
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
131 if (event.type == SDL_QUIT)
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
132 {
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
133 stop = true;
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
134 break;
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
135 }
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
136 else if (event.type == SDL_WINDOWEVENT &&
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
137 event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
138 {
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
139 sdlViewport.UpdateSize(event.window.data1, event.window.data2);
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
140 }
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
141 else if (event.type == SDL_KEYDOWN &&
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
142 event.key.repeat == 0 /* Ignore key bounce */)
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
143 {
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
144 switch (event.key.keysym.sym)
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
145 {
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
146 case SDLK_f:
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
147 sdlViewport.GetWindow().ToggleMaximize();
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
148 break;
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
149
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
150 case SDLK_q:
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
151 stop = true;
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
152 break;
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
153
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
154 default:
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
155 break;
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
156 }
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
157 }
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
158
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
159 HandleApplicationEvent(controller, event);
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
160 }
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
161
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
162 SDL_Delay(1);
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
163 }
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
164 interactor.reset();
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
165 }
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
166
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
167
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
168
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
169
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
170 /**
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
171 * IMPORTANT: The full arguments to "main()" are needed for SDL on
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
172 * Windows. Otherwise, one gets the linking error "undefined reference
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
173 * to `SDL_main'". https://wiki.libsdl.org/FAQWindows
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
174 **/
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
175 int main(int argc, char* argv[])
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
176 {
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
177 using namespace OrthancStone;
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
178 StoneInitialize();
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
179 Orthanc::Logging::EnableInfoLevel(true);
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
180
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
181 try
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
182 {
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
183 SdlOpenGLViewport viewport("Hello", 1024, 768);
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
184 MessageBroker broker;
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
185 boost::shared_ptr<UndoStack> undoStack(new UndoStack);
938
eaaa9b574e05 Fixed the Stone samples wrt the recent API changes (SdlOpenGLViewport, ICompositor...)
Benjamin Golinvaux <bgo@osimis.io>
parents: 916
diff changeset
186 boost::shared_ptr<ViewportController> controller = boost::make_shared<ViewportController>(undoStack, boost::ref(broker), boost::ref(viewport));
916
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
187 interactor.reset(new BasicScene2DInteractor(controller));
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
188 PrepareScene(controller->GetScene());
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
189 Run(controller);
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
190 }
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
191 catch (Orthanc::OrthancException& e)
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
192 {
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
193 LOG(ERROR) << "EXCEPTION: " << e.What();
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
194 }
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
195
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
196 StoneFinalize();
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
197
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
198 return 0;
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
199 }