Mercurial > hg > orthanc-stone
annotate Applications/Sdl/SdlWindow.cpp @ 436:04711a2e12cd am-vsol-upgrade
fix crop + export photometric interpretation correctly
author | am@osimis.io |
---|---|
date | Thu, 06 Dec 2018 11:53:37 +0100 |
parents | 1c5a47dda299 |
children | b70e9be013e4 |
rev | line source |
---|---|
0 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
134
4cff7b1ed31d
upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
84
diff
changeset
|
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium |
0 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
47 | 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. | |
0 | 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 | |
47 | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
0 | 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 **/ | |
20 | |
21 | |
22 #include "SdlWindow.h" | |
23 | |
24 #if ORTHANC_ENABLE_SDL == 1 | |
25 | |
212
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
26 #include <Core/Logging.h> |
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
27 #include <Core/OrthancException.h> |
0 | 28 |
214 | 29 #include <SDL.h> |
30 | |
0 | 31 namespace OrthancStone |
32 { | |
33 SdlWindow::SdlWindow(const char* title, | |
34 unsigned int width, | |
35 unsigned int height, | |
36 bool enableOpenGl) : | |
37 maximized_(false) | |
38 { | |
39 // TODO Understand why, with SDL_WINDOW_OPENGL + MinGW32 + Release | |
40 // build mode, the application crashes whenever the SDL window is | |
41 // resized or maximized | |
42 | |
43 uint32_t windowFlags, rendererFlags; | |
44 if (enableOpenGl) | |
45 { | |
46 windowFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE; | |
47 rendererFlags = SDL_RENDERER_ACCELERATED; | |
48 } | |
49 else | |
50 { | |
51 windowFlags = SDL_WINDOW_RESIZABLE; | |
52 rendererFlags = SDL_RENDERER_SOFTWARE; | |
53 } | |
54 | |
55 window_ = SDL_CreateWindow(title, | |
56 SDL_WINDOWPOS_UNDEFINED, | |
57 SDL_WINDOWPOS_UNDEFINED, | |
58 width, height, windowFlags); | |
59 | |
60 if (window_ == NULL) | |
61 { | |
62 LOG(ERROR) << "Cannot create the SDL window: " << SDL_GetError(); | |
63 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
64 } | |
65 | |
66 renderer_ = SDL_CreateRenderer(window_, -1, rendererFlags); | |
67 if (!renderer_) | |
68 { | |
69 LOG(ERROR) << "Cannot create the SDL renderer: " << SDL_GetError(); | |
70 SDL_DestroyWindow(window_); | |
71 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
72 } | |
73 } | |
74 | |
75 | |
76 SdlWindow::~SdlWindow() | |
77 { | |
78 if (renderer_ != NULL) | |
79 { | |
80 SDL_DestroyRenderer(renderer_); | |
81 } | |
82 | |
83 if (window_ != NULL) | |
84 { | |
85 SDL_DestroyWindow(window_); | |
86 } | |
87 } | |
88 | |
89 | |
90 unsigned int SdlWindow::GetWidth() const | |
91 { | |
92 int w = -1; | |
93 SDL_GetWindowSize(window_, &w, NULL); | |
94 | |
95 if (w < 0) | |
96 { | |
97 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
98 } | |
99 else | |
100 { | |
101 return static_cast<unsigned int>(w); | |
102 } | |
103 } | |
104 | |
105 | |
106 unsigned int SdlWindow::GetHeight() const | |
107 { | |
108 int h = -1; | |
109 SDL_GetWindowSize(window_, NULL, &h); | |
110 | |
111 if (h < 0) | |
112 { | |
113 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
114 } | |
115 else | |
116 { | |
117 return static_cast<unsigned int>(h); | |
118 } | |
119 } | |
120 | |
121 | |
122 void SdlWindow::Render(SDL_Surface* surface) | |
123 { | |
124 //SDL_RenderClear(renderer_); | |
125 | |
126 SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer_, surface); | |
127 if (texture != NULL) | |
128 { | |
129 SDL_RenderCopy(renderer_, texture, NULL, NULL); | |
130 SDL_DestroyTexture(texture); | |
131 } | |
132 | |
133 SDL_RenderPresent(renderer_); | |
134 } | |
135 | |
136 | |
137 void SdlWindow::ToggleMaximize() | |
138 { | |
139 if (maximized_) | |
140 { | |
141 SDL_RestoreWindow(window_); | |
142 maximized_ = false; | |
143 } | |
144 else | |
145 { | |
146 SDL_MaximizeWindow(window_); | |
147 maximized_ = true; | |
148 } | |
149 } | |
214 | 150 |
151 | |
152 void SdlWindow::GlobalInitialize() | |
153 { | |
154 if (SDL_Init(SDL_INIT_VIDEO) != 0) | |
155 { | |
156 LOG(ERROR) << "Cannot initialize SDL"; | |
157 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
158 } | |
159 } | |
160 | |
161 | |
162 void SdlWindow::GlobalFinalize() | |
163 { | |
164 SDL_Quit(); | |
165 } | |
0 | 166 } |
167 | |
168 #endif |