Mercurial > hg > orthanc-stone
annotate Applications/Samples/Sdl/SdlHelpers.h @ 1807:634ff8993f6a
Stone Web viewer: Patient birth date is now displayed in the overlays
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 20 May 2021 17:17:56 +0200 |
parents | 9ac2a65d4172 |
children | 3889ae96d2e9 |
rev | line source |
---|---|
1457 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
1739
9ac2a65d4172
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
1457 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
1596
4fb8fdf03314
removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1591
diff
changeset
|
16 * |
1457 | 17 * You should have received a copy of the GNU Affero General Public License |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
1382
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
22 #pragma once |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
23 |
1386
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1382
diff
changeset
|
24 #if ORTHANC_ENABLE_SDL != 1 |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1382
diff
changeset
|
25 # error This file cannot be used if ORTHANC_ENABLE_SDL != 1 |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1382
diff
changeset
|
26 #endif |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1382
diff
changeset
|
27 |
1591
5887a4f8594b
moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1542
diff
changeset
|
28 #include "../../Platforms/Sdl/SdlViewport.h" |
1392
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1388
diff
changeset
|
29 |
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1388
diff
changeset
|
30 #include <boost/shared_ptr.hpp> |
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1388
diff
changeset
|
31 |
1386
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1382
diff
changeset
|
32 #include <SDL.h> |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1382
diff
changeset
|
33 |
1382
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
34 #include <map> |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
35 #include <string> |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
36 |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
37 namespace OrthancStoneHelpers |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
38 { |
1392
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1388
diff
changeset
|
39 |
1382
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
40 inline OrthancStone::KeyboardModifiers GetKeyboardModifiers(const uint8_t* keyboardState, |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
41 const int scancodeCount) |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
42 { |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
43 using namespace OrthancStone; |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
44 int result = KeyboardModifiers_None; |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
45 |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
46 if (keyboardState != NULL) |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
47 { |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
48 if (SDL_SCANCODE_LSHIFT < scancodeCount && |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
49 keyboardState[SDL_SCANCODE_LSHIFT]) |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
50 { |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
51 result |= KeyboardModifiers_Shift; |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
52 } |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
53 |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
54 if (SDL_SCANCODE_RSHIFT < scancodeCount && |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
55 keyboardState[SDL_SCANCODE_RSHIFT]) |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
56 { |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
57 result |= KeyboardModifiers_Shift; |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
58 } |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
59 |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
60 if (SDL_SCANCODE_LCTRL < scancodeCount && |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
61 keyboardState[SDL_SCANCODE_LCTRL]) |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
62 { |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
63 result |= KeyboardModifiers_Control; |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
64 } |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
65 |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
66 if (SDL_SCANCODE_RCTRL < scancodeCount && |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
67 keyboardState[SDL_SCANCODE_RCTRL]) |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
68 { |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
69 result |= KeyboardModifiers_Control; |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
70 } |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
71 |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
72 if (SDL_SCANCODE_LALT < scancodeCount && |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
73 keyboardState[SDL_SCANCODE_LALT]) |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
74 { |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
75 result |= KeyboardModifiers_Alt; |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
76 } |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
77 |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
78 if (SDL_SCANCODE_RALT < scancodeCount && |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
79 keyboardState[SDL_SCANCODE_RALT]) |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
80 { |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
81 result |= KeyboardModifiers_Alt; |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
82 } |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
83 } |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
84 |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
85 return static_cast<KeyboardModifiers>(result); |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
86 } |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
87 |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
88 |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
89 inline void GetPointerEvent(OrthancStone::PointerEvent& p, |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
90 const OrthancStone::ICompositor& compositor, |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
91 SDL_Event event, |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
92 const uint8_t* keyboardState, |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
93 const int scancodeCount) |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
94 { |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
95 using namespace OrthancStone; |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
96 KeyboardModifiers modifiers = GetKeyboardModifiers(keyboardState, scancodeCount); |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
97 |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
98 switch (event.button.button) |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
99 { |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
100 case SDL_BUTTON_LEFT: |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
101 p.SetMouseButton(OrthancStone::MouseButton_Left); |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
102 break; |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
103 |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
104 case SDL_BUTTON_RIGHT: |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
105 p.SetMouseButton(OrthancStone::MouseButton_Right); |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
106 break; |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
107 |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
108 case SDL_BUTTON_MIDDLE: |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
109 p.SetMouseButton(OrthancStone::MouseButton_Middle); |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
110 break; |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
111 |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
112 default: |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
113 p.SetMouseButton(OrthancStone::MouseButton_None); |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
114 break; |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
115 } |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
116 |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
117 p.AddPosition(compositor.GetPixelCenterCoordinates(event.button.x, event.button.y)); |
1449 | 118 p.SetAltModifier( (modifiers & KeyboardModifiers_Alt) != 0); |
119 p.SetControlModifier( (modifiers & KeyboardModifiers_Control) != 0); | |
120 p.SetShiftModifier( (modifiers & KeyboardModifiers_Shift) != 0); | |
1382
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
121 } |
1392
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1388
diff
changeset
|
122 |
1501 | 123 |
124 inline boost::shared_ptr<OrthancStone::SdlViewport> GetSdlViewportFromWindowId( | |
1404
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
125 const std::vector<boost::shared_ptr<OrthancStone::SdlViewport> >& viewports, |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
126 Uint32 windowID) |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
127 { |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
128 using namespace OrthancStone; |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
129 for (size_t i = 0; i < viewports.size(); ++i) |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
130 { |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
131 boost::shared_ptr<IViewport> viewport = viewports[i]; |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
132 boost::shared_ptr<SdlViewport> sdlViewport = boost::dynamic_pointer_cast<SdlViewport>(viewport); |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
133 Uint32 curWindowID = sdlViewport->GetSdlWindowId(); |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
134 if (windowID == curWindowID) |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
135 return sdlViewport; |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
136 } |
1424
b424028392cf
fixing some build errors
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1406
diff
changeset
|
137 |
b424028392cf
fixing some build errors
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1406
diff
changeset
|
138 return boost::shared_ptr<OrthancStone::SdlViewport>(); |
1404
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
139 } |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
140 } |
1392
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1388
diff
changeset
|
141 |
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1388
diff
changeset
|
142 |