annotate OrthancStone/Sources/Platforms/Sdl/SdlWindow.cpp @ 2077:07964689cb0b

upgrade to year 2023
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 12 Jul 2023 21:20:22 +0200
parents 917500c46fe0
children c23eef785569
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1899
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
1 /**
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
2 * Stone of Orthanc
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
2077
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1899
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1899
diff changeset
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
1899
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
7 *
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public License
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
11 * the License, or (at your option) any later version.
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
12 *
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
16 * Lesser General Public License for more details.
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
17 *
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
19 * License along with this program. If not, see
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
20 * <http://www.gnu.org/licenses/>.
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
21 **/
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
22
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
23
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
24 #include "SdlWindow.h"
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
25
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
26 #if ORTHANC_ENABLE_SDL == 1
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
27
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
28 #include <Logging.h>
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
29 #include <OrthancException.h>
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
30
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
31 #ifdef WIN32
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
32 #include <windows.h> // for SetProcessDpiAware
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
33 #endif
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
34 // WIN32
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
35
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
36 #include <SDL_render.h>
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
37 #include <SDL_video.h>
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
38 #include <SDL.h>
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
39
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
40 namespace OrthancStone
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
41 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
42 SdlWindow::SdlWindow(const std::string& title,
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
43 unsigned int width,
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
44 unsigned int height,
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
45 bool enableOpenGl,
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
46 bool allowDpiScaling) :
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
47 maximized_(false)
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
48 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
49 // TODO Understand why, with SDL_WINDOW_OPENGL + MinGW32 + Release
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
50 // build mode, the application crashes whenever the SDL window is
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
51 // resized or maximized
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
52
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
53 uint32_t windowFlags, rendererFlags;
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
54 if (enableOpenGl)
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
55 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
56 windowFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE;
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
57 rendererFlags = SDL_RENDERER_ACCELERATED;
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
58 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
59 else
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
60 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
61 windowFlags = SDL_WINDOW_RESIZABLE;
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
62 rendererFlags = SDL_RENDERER_SOFTWARE;
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
63 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
64
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
65 // TODO: probably required on MacOS X, too
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
66 #if defined(WIN32) && (_WIN32_WINNT >= 0x0600)
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
67 if (!allowDpiScaling)
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
68 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
69 // if we do NOT allow DPI scaling, it means an SDL pixel will be a real
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
70 // monitor pixel. This is needed for high-DPI applications
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
71
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
72 // Enable high-DPI support on Windows
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
73
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
74 // THE FOLLOWING HAS BEEN COMMENTED OUT BECAUSE IT WILL CRASH UNDER
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
75 // OLD WINDOWS VERSIONS
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
76 // ADD THIS AT THE TOP TO ENABLE IT:
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
77 //
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
78 //#pragma comment(lib, "Shcore.lib") THIS IS ONLY REQUIRED FOR SetProcessDpiAwareness
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
79 //#include <windows.h>
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
80 //#include <ShellScalingAPI.h> THIS IS ONLY REQUIRED FOR SetProcessDpiAwareness
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
81 //#include <comdef.h> THIS IS ONLY REQUIRED FOR SetProcessDpiAwareness
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
82 // SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
83
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
84 // This is supported on Vista+
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
85 SetProcessDPIAware();
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
86
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
87 windowFlags |= SDL_WINDOW_ALLOW_HIGHDPI;
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
88 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
89 #endif
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
90 // WIN32
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
91
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
92 window_ = SDL_CreateWindow(title.c_str(),
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
93 SDL_WINDOWPOS_UNDEFINED,
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
94 SDL_WINDOWPOS_UNDEFINED,
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
95 width, height, windowFlags);
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
96
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
97 if (window_ == NULL)
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
98 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
99 LOG(ERROR) << "Cannot create the SDL window: " << SDL_GetError();
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
100 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
101 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
102
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
103 renderer_ = SDL_CreateRenderer(window_, -1, rendererFlags);
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
104 if (!renderer_)
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
105 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
106 LOG(ERROR) << "Cannot create the SDL renderer: " << SDL_GetError();
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
107 SDL_DestroyWindow(window_);
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
108 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
109 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
110 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
111
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
112
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
113 SdlWindow::~SdlWindow()
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
114 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
115 if (renderer_ != NULL)
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
116 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
117 SDL_DestroyRenderer(renderer_);
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
118 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
119
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
120 if (window_ != NULL)
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
121 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
122 SDL_DestroyWindow(window_);
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
123 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
124 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
125
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
126
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
127 unsigned int SdlWindow::GetWidth() const
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
128 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
129 int w = -1;
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
130 SDL_GetWindowSize(window_, &w, NULL);
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
131
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
132 if (w < 0)
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
133 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
134 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
135 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
136 else
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
137 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
138 return static_cast<unsigned int>(w);
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
139 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
140 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
141
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
142
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
143 unsigned int SdlWindow::GetHeight() const
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
144 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
145 int h = -1;
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
146 SDL_GetWindowSize(window_, NULL, &h);
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
147
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
148 if (h < 0)
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
149 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
150 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
151 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
152 else
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
153 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
154 return static_cast<unsigned int>(h);
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
155 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
156 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
157
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
158
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
159 void SdlWindow::Render(SDL_Surface* surface)
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
160 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
161 /**
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
162 * "You are strongly encouraged to call SDL_RenderClear() to
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
163 * initialize the backbuffer before starting each new frame's
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
164 * drawing, even if you plan to overwrite every pixel."
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
165 * https://wiki.libsdl.org/SDL_RenderPresent
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
166 **/
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
167 SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 255);
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
168 SDL_RenderClear(renderer_); // Clear the entire screen to our selected color
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
169
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
170 SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer_, surface);
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
171 if (texture != NULL)
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
172 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
173 SDL_RenderCopy(renderer_, texture, NULL, NULL);
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
174 SDL_DestroyTexture(texture);
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
175 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
176
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
177 SDL_RenderPresent(renderer_);
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
178 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
179
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
180
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
181 void SdlWindow::ToggleMaximize()
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
182 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
183 if (maximized_)
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
184 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
185 SDL_RestoreWindow(window_);
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
186 maximized_ = false;
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
187 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
188 else
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
189 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
190 SDL_MaximizeWindow(window_);
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
191 maximized_ = true;
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
192 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
193 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
194
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
195
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
196 void SdlWindow::GlobalInitialize()
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
197 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
198 if (SDL_Init(SDL_INIT_VIDEO) != 0)
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
199 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
200 LOG(ERROR) << "Cannot initialize SDL";
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
201 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
202 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
203 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
204
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
205
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
206 void SdlWindow::GlobalFinalize()
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
207 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
208 SDL_Quit();
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
209 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
210 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
211
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
212 #endif