Mercurial > love-experiments
annotate src/modules/window/sdl/Window.cpp @ 1418:357697c2e2a8
More internal code cleanup
| author | Alex Szpakowski <slime73@gmail.com> |
|---|---|
| date | Sun, 31 Mar 2013 19:02:27 -0300 |
| parents | 9115e52f5350 |
| children |
| rev | line source |
|---|---|
| 1096 | 1 /** |
|
1282
b7f097053d74
Updated copyright text for the new year
Alex Szpakowski <slime73@gmail.com>
parents:
1250
diff
changeset
|
2 * Copyright (c) 2006-2013 LOVE Development Team |
| 1096 | 3 * |
| 4 * This software is provided 'as-is', without any express or implied | |
| 5 * warranty. In no event will the authors be held liable for any damages | |
| 6 * arising from the use of this software. | |
| 7 * | |
| 8 * Permission is granted to anyone to use this software for any purpose, | |
| 9 * including commercial applications, and to alter it and redistribute it | |
| 10 * freely, subject to the following restrictions: | |
| 11 * | |
| 12 * 1. The origin of this software must not be misrepresented; you must not | |
| 13 * claim that you wrote the original software. If you use this software | |
| 14 * in a product, an acknowledgment in the product documentation would be | |
| 15 * appreciated but is not required. | |
| 16 * 2. Altered source versions must be plainly marked as such, and must not be | |
| 17 * misrepresented as being the original software. | |
| 18 * 3. This notice may not be removed or altered from any source distribution. | |
| 19 **/ | |
| 20 | |
| 21 // STL | |
| 22 #include <iostream> | |
| 23 | |
| 24 // SDL | |
| 25 #include <SDL.h> | |
| 26 | |
| 27 // LOVE | |
| 28 #include "common/config.h" | |
| 29 #include "Window.h" | |
| 30 | |
| 31 namespace love | |
| 32 { | |
| 33 namespace window | |
| 34 { | |
| 35 namespace sdl | |
| 36 { | |
| 37 | |
| 38 Window::Window() | |
| 39 : windowTitle("") | |
| 40 , created(false) | |
| 41 { | |
| 42 if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) | |
|
1250
8c3108ab0e95
Removed direct OpenGL calls in the SDL Window module
Alex Szpakowski <slime73@gmail.com>
parents:
1198
diff
changeset
|
43 throw love::Exception(SDL_GetError()); |
| 1096 | 44 } |
| 45 | |
| 46 Window::~Window() | |
| 47 { | |
| 48 SDL_QuitSubSystem(SDL_INIT_VIDEO); | |
| 49 } | |
| 50 | |
| 51 Window::_currentMode::_currentMode() | |
| 52 : width(800), height(600), fullscreen(false), vsync(true), fsaa(0) | |
| 53 { | |
| 54 } | |
| 55 | |
|
1111
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1096
diff
changeset
|
56 bool Window::setWindow(int width, int height, WindowFlags *flags) |
| 1096 | 57 { |
|
1111
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1096
diff
changeset
|
58 bool fullscreen = false; |
|
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1096
diff
changeset
|
59 bool vsync = true; |
|
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1096
diff
changeset
|
60 int fsaa = 0; |
|
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1096
diff
changeset
|
61 bool resizable = false; |
|
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1096
diff
changeset
|
62 bool borderless = false; |
|
1356
9115e52f5350
Add centered flag to setMode, optionally centers the window (on by default, as before) (issue #463)
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1339
diff
changeset
|
63 bool centered = true; |
|
1111
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1096
diff
changeset
|
64 |
|
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1096
diff
changeset
|
65 if (flags) |
|
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1096
diff
changeset
|
66 { |
|
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1096
diff
changeset
|
67 fullscreen = flags->fullscreen; |
|
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1096
diff
changeset
|
68 vsync = flags->vsync; |
|
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1096
diff
changeset
|
69 fsaa = flags->fsaa; |
|
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1096
diff
changeset
|
70 resizable = flags->resizable; |
|
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1096
diff
changeset
|
71 borderless = flags->borderless; |
|
1356
9115e52f5350
Add centered flag to setMode, optionally centers the window (on by default, as before) (issue #463)
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1339
diff
changeset
|
72 centered = flags->centered; |
|
1111
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1096
diff
changeset
|
73 } |
|
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1096
diff
changeset
|
74 |
| 1096 | 75 bool mouseVisible = getMouseVisible(); |
|
1198
4fede85debc1
Reapply sdl's keyrepeat settings after setWindow
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1096
diff
changeset
|
76 int keyrepeatDelay, keyrepeatInterval; |
|
4fede85debc1
Reapply sdl's keyrepeat settings after setWindow
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1096
diff
changeset
|
77 SDL_GetKeyRepeat(&keyrepeatDelay, &keyrepeatInterval); |
| 1096 | 78 |
| 79 // We need to restart the subsystem for two reasons: | |
| 80 // 1) Special case for fullscreen -> windowed. Windows XP did not | |
| 81 // work well with "normal" display mode change in this case. | |
| 82 // The application window does leave fullscreen, but the desktop | |
| 83 // resolution does not revert to the correct one. Restarting the | |
| 84 // SDL video subsystem does the trick, though. | |
| 85 // 2) Restart the event system (for whatever reason the event system | |
| 86 // started and stopped with SDL_INIT_VIDEO, see: | |
| 87 // http://sdl.beuc.net/sdl.wiki/Introduction_to_Events) | |
| 88 // because the mouse position will not be able to exceed | |
| 89 // the previous' video mode window size (i.e. alway | |
| 90 // love.mouse.getX() < 800 when switching from 800x600 to a | |
| 91 // higher resolution) | |
| 92 SDL_QuitSubSystem(SDL_INIT_VIDEO); | |
|
1356
9115e52f5350
Add centered flag to setMode, optionally centers the window (on by default, as before) (issue #463)
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1339
diff
changeset
|
93 |
|
9115e52f5350
Add centered flag to setMode, optionally centers the window (on by default, as before) (issue #463)
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1339
diff
changeset
|
94 if (centered) // Window should be centered. |
|
9115e52f5350
Add centered flag to setMode, optionally centers the window (on by default, as before) (issue #463)
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1339
diff
changeset
|
95 SDL_putenv(const_cast<char *>("SDL_VIDEO_CENTERED=center")); |
|
9115e52f5350
Add centered flag to setMode, optionally centers the window (on by default, as before) (issue #463)
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1339
diff
changeset
|
96 else |
|
9115e52f5350
Add centered flag to setMode, optionally centers the window (on by default, as before) (issue #463)
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1339
diff
changeset
|
97 SDL_putenv(const_cast<char *>("SDL_VIDEO_CENTERED=")); |
|
9115e52f5350
Add centered flag to setMode, optionally centers the window (on by default, as before) (issue #463)
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1339
diff
changeset
|
98 |
| 1096 | 99 if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) |
| 100 { | |
| 101 std::cout << "Could not init SDL_VIDEO: " << SDL_GetError() << std::endl; | |
| 102 return false; | |
| 103 } | |
| 104 | |
| 105 // Set caption. | |
| 106 setWindowTitle(windowTitle); | |
| 107 setMouseVisible(mouseVisible); | |
|
1198
4fede85debc1
Reapply sdl's keyrepeat settings after setWindow
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1096
diff
changeset
|
108 SDL_EnableKeyRepeat(keyrepeatDelay, keyrepeatInterval); |
| 1096 | 109 |
| 110 // Set GL attributes | |
| 111 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); | |
| 112 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); | |
| 113 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); | |
| 114 SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); | |
| 115 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); | |
| 116 SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, (vsync ? 1 : 0)); | |
| 117 SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 1); | |
| 118 | |
| 119 // FSAA | |
|
1250
8c3108ab0e95
Removed direct OpenGL calls in the SDL Window module
Alex Szpakowski <slime73@gmail.com>
parents:
1198
diff
changeset
|
120 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, (fsaa > 0) ? 1 : 0); |
|
8c3108ab0e95
Removed direct OpenGL calls in the SDL Window module
Alex Szpakowski <slime73@gmail.com>
parents:
1198
diff
changeset
|
121 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, (fsaa > 0) ? fsaa : 0); |
| 1096 | 122 |
|
1111
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1096
diff
changeset
|
123 Uint32 sdlflags = SDL_OPENGL; |
|
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1096
diff
changeset
|
124 // Flags |
|
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1096
diff
changeset
|
125 if (fullscreen) |
|
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1096
diff
changeset
|
126 sdlflags |= SDL_FULLSCREEN; |
|
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1096
diff
changeset
|
127 if (resizable) |
|
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1096
diff
changeset
|
128 sdlflags |= SDL_RESIZABLE; |
|
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1096
diff
changeset
|
129 if (borderless) |
|
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1096
diff
changeset
|
130 sdlflags |= SDL_NOFRAME; |
| 1096 | 131 |
| 132 // Have SDL set the video mode. | |
|
1111
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1096
diff
changeset
|
133 SDL_Surface *surface; |
|
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1096
diff
changeset
|
134 if ((surface = SDL_SetVideoMode(width, height, 32, sdlflags)) == 0) |
| 1096 | 135 { |
| 136 bool failed = true; | |
| 137 if (fsaa > 0) | |
| 138 { | |
|
1250
8c3108ab0e95
Removed direct OpenGL calls in the SDL Window module
Alex Szpakowski <slime73@gmail.com>
parents:
1198
diff
changeset
|
139 // FSAA might have caused the failure, disable it and try again |
| 1096 | 140 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0); |
|
1250
8c3108ab0e95
Removed direct OpenGL calls in the SDL Window module
Alex Szpakowski <slime73@gmail.com>
parents:
1198
diff
changeset
|
141 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0); |
|
1339
9dc7d74bbc58
Fixed some potential instability or crash issues
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
142 failed = (surface = SDL_SetVideoMode(width, height, 32, sdlflags)) == 0; |
| 1096 | 143 } |
| 144 if (failed) | |
| 145 { | |
| 146 std::cerr << "Could not set video mode: " << SDL_GetError() << std::endl; | |
| 147 return false; | |
| 148 } | |
| 149 } | |
| 150 | |
| 151 created = true; | |
| 152 | |
| 153 if (width == 0 || height == 0) | |
| 154 { | |
| 155 const SDL_VideoInfo *videoinfo = SDL_GetVideoInfo(); | |
| 156 width = videoinfo->current_w; | |
| 157 height = videoinfo->current_h; | |
| 158 } | |
| 159 | |
|
1250
8c3108ab0e95
Removed direct OpenGL calls in the SDL Window module
Alex Szpakowski <slime73@gmail.com>
parents:
1198
diff
changeset
|
160 int buffers; |
|
8c3108ab0e95
Removed direct OpenGL calls in the SDL Window module
Alex Szpakowski <slime73@gmail.com>
parents:
1198
diff
changeset
|
161 int samples; |
| 1096 | 162 |
|
1250
8c3108ab0e95
Removed direct OpenGL calls in the SDL Window module
Alex Szpakowski <slime73@gmail.com>
parents:
1198
diff
changeset
|
163 SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &buffers); |
|
8c3108ab0e95
Removed direct OpenGL calls in the SDL Window module
Alex Szpakowski <slime73@gmail.com>
parents:
1198
diff
changeset
|
164 SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &samples); |
| 1096 | 165 |
| 166 // Don't fail because of this, but issue a warning. | |
| 167 if ((!buffers && fsaa) || (samples != fsaa)) | |
| 168 { | |
|
1250
8c3108ab0e95
Removed direct OpenGL calls in the SDL Window module
Alex Szpakowski <slime73@gmail.com>
parents:
1198
diff
changeset
|
169 std::cerr << "Warning, FSAA setting failed! (Result: buffers: " << buffers << ", samples: " << samples << ")" << std::endl; |
|
8c3108ab0e95
Removed direct OpenGL calls in the SDL Window module
Alex Szpakowski <slime73@gmail.com>
parents:
1198
diff
changeset
|
170 fsaa = (buffers > 0) ? samples : 0; |
| 1096 | 171 } |
| 172 | |
| 173 // Get the actual vsync status | |
| 174 int real_vsync; | |
| 175 SDL_GL_GetAttribute(SDL_GL_SWAP_CONTROL, &real_vsync); | |
| 176 | |
| 177 // Set the new display mode as the current display mode. | |
| 178 currentMode.width = width; | |
| 179 currentMode.height = height; | |
| 180 currentMode.fsaa = fsaa; | |
| 181 currentMode.fullscreen = fullscreen; | |
| 182 currentMode.vsync = (real_vsync != 0); | |
|
1111
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1096
diff
changeset
|
183 currentMode.resizable = ((surface->flags & SDL_RESIZABLE) != 0); |
|
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1096
diff
changeset
|
184 currentMode.borderless = ((surface->flags & SDL_NOFRAME) != 0); |
|
1356
9115e52f5350
Add centered flag to setMode, optionally centers the window (on by default, as before) (issue #463)
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1339
diff
changeset
|
185 currentMode.centered = centered; |
| 1096 | 186 |
| 187 return true; | |
| 188 } | |
| 189 | |
|
1333
730ed5f01ab0
Merge in default, update changelog
Bart van Strien <bart.bes+projects@gmail.com>
diff
changeset
|
190 void Window::getWindow(int &width, int &height, WindowFlags &flags) const |
| 1096 | 191 { |
| 192 width = currentMode.width; | |
| 193 height = currentMode.height; | |
|
1111
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1096
diff
changeset
|
194 flags.fullscreen = currentMode.fullscreen; |
|
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1096
diff
changeset
|
195 flags.vsync = currentMode.vsync; |
|
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1096
diff
changeset
|
196 flags.fsaa = currentMode.fsaa; |
|
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1096
diff
changeset
|
197 flags.resizable = currentMode.resizable; |
|
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1096
diff
changeset
|
198 flags.borderless = currentMode.borderless; |
|
1356
9115e52f5350
Add centered flag to setMode, optionally centers the window (on by default, as before) (issue #463)
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1339
diff
changeset
|
199 flags.centered = currentMode.centered; |
| 1096 | 200 } |
| 201 | |
|
1310
2061cc4dc762
Constified many Graphics and Window methods
Alex Szpakowski <slime73@gmail.com>
parents:
1282
diff
changeset
|
202 bool Window::checkWindowSize(int width, int height, bool fullscreen) const |
| 1096 | 203 { |
| 204 Uint32 sdlflags = fullscreen ? (SDL_OPENGL | SDL_FULLSCREEN) : SDL_OPENGL; | |
| 205 | |
| 206 // Check if mode is supported | |
| 207 int bpp = SDL_VideoModeOK(width, height, 32, sdlflags); | |
| 208 | |
| 209 return (bpp >= 16); | |
| 210 } | |
| 211 | |
| 212 typedef Window::WindowSize WindowSize; | |
| 213 | |
|
1418
357697c2e2a8
More internal code cleanup
Alex Szpakowski <slime73@gmail.com>
parents:
1356
diff
changeset
|
214 WindowSize *Window::getFullscreenSizes(int &n) const |
| 1096 | 215 { |
| 216 SDL_Rect **modes = SDL_ListModes(0, SDL_OPENGL | SDL_FULLSCREEN); | |
| 217 | |
| 218 if (modes == (SDL_Rect **)0 || modes == (SDL_Rect **)-1) | |
| 219 { | |
| 220 n = 0; | |
| 221 return NULL; | |
| 222 } | |
| 223 | |
| 224 n = 0; | |
| 225 for (int i = 0; modes[i]; i++) | |
| 226 n++; | |
| 227 | |
|
1418
357697c2e2a8
More internal code cleanup
Alex Szpakowski <slime73@gmail.com>
parents:
1356
diff
changeset
|
228 WindowSize *sizes = new WindowSize[n]; |
| 1096 | 229 |
| 230 for (int i = 0; i < n; i++) | |
| 231 { | |
|
1418
357697c2e2a8
More internal code cleanup
Alex Szpakowski <slime73@gmail.com>
parents:
1356
diff
changeset
|
232 WindowSize w = {modes[i]->w, modes[i]->h}; |
|
357697c2e2a8
More internal code cleanup
Alex Szpakowski <slime73@gmail.com>
parents:
1356
diff
changeset
|
233 sizes[i] = w; |
| 1096 | 234 } |
| 235 return sizes; | |
| 236 } | |
| 237 | |
|
1310
2061cc4dc762
Constified many Graphics and Window methods
Alex Szpakowski <slime73@gmail.com>
parents:
1282
diff
changeset
|
238 int Window::getWidth() const |
| 1096 | 239 { |
| 240 return currentMode.width; | |
| 241 } | |
| 242 | |
|
1310
2061cc4dc762
Constified many Graphics and Window methods
Alex Szpakowski <slime73@gmail.com>
parents:
1282
diff
changeset
|
243 int Window::getHeight() const |
| 1096 | 244 { |
| 245 return currentMode.height; | |
| 246 } | |
| 247 | |
|
1310
2061cc4dc762
Constified many Graphics and Window methods
Alex Szpakowski <slime73@gmail.com>
parents:
1282
diff
changeset
|
248 bool Window::isCreated() const |
| 1096 | 249 { |
| 250 return created; | |
| 251 } | |
| 252 | |
|
1418
357697c2e2a8
More internal code cleanup
Alex Szpakowski <slime73@gmail.com>
parents:
1356
diff
changeset
|
253 void Window::setWindowTitle(const std::string &title) |
| 1096 | 254 { |
| 255 windowTitle = title; | |
| 256 SDL_WM_SetCaption(windowTitle.c_str(), 0); | |
| 257 } | |
| 258 | |
|
1310
2061cc4dc762
Constified many Graphics and Window methods
Alex Szpakowski <slime73@gmail.com>
parents:
1282
diff
changeset
|
259 std::string Window::getWindowTitle() const |
| 1096 | 260 { |
| 261 // not a reference | |
| 262 // because we want this untouched | |
| 263 // const std::string& might be an option | |
| 264 return windowTitle; | |
| 265 } | |
| 266 | |
| 267 bool Window::setIcon(love::image::ImageData *imgd) | |
| 268 { | |
| 269 Uint32 rmask, gmask, bmask, amask; | |
| 270 #ifdef LOVE_BIG_ENDIAN | |
| 271 rmask = 0xFF000000; | |
| 272 gmask = 0x00FF0000; | |
| 273 bmask = 0x0000FF00; | |
| 274 amask = 0x000000FF; | |
| 275 #else | |
| 276 rmask = 0x000000FF; | |
| 277 gmask = 0x0000FF00; | |
| 278 bmask = 0x00FF0000; | |
| 279 amask = 0xFF000000; | |
| 280 #endif | |
| 281 | |
| 282 int w = static_cast<int>(imgd->getWidth()); | |
| 283 int h = static_cast<int>(imgd->getHeight()); | |
| 284 int pitch = static_cast<int>(imgd->getWidth() * 4); | |
| 285 | |
| 286 SDL_Surface *icon = SDL_CreateRGBSurfaceFrom(imgd->getData(), w, h, 32, pitch, rmask, gmask, bmask, amask); | |
| 287 SDL_WM_SetIcon(icon, NULL); | |
| 288 SDL_FreeSurface(icon); | |
| 289 return true; | |
| 290 } | |
| 291 | |
| 292 void Window::swapBuffers() | |
| 293 { | |
| 294 SDL_GL_SwapBuffers(); | |
| 295 } | |
| 296 | |
|
1310
2061cc4dc762
Constified many Graphics and Window methods
Alex Szpakowski <slime73@gmail.com>
parents:
1282
diff
changeset
|
297 bool Window::hasFocus() const |
| 1096 | 298 { |
| 299 return (SDL_GetAppState() & SDL_APPINPUTFOCUS) != 0; | |
| 300 } | |
| 301 | |
| 302 void Window::setMouseVisible(bool visible) | |
| 303 { | |
| 304 SDL_ShowCursor(visible ? SDL_ENABLE : SDL_DISABLE); | |
| 305 } | |
| 306 | |
|
1310
2061cc4dc762
Constified many Graphics and Window methods
Alex Szpakowski <slime73@gmail.com>
parents:
1282
diff
changeset
|
307 bool Window::getMouseVisible() const |
| 1096 | 308 { |
| 309 return (SDL_ShowCursor(SDL_QUERY) == SDL_ENABLE) ? true : false; | |
| 310 } | |
| 311 | |
| 312 love::window::Window *Window::getSingleton() | |
| 313 { | |
| 314 if (!singleton) | |
| 315 singleton = new Window(); | |
| 316 else | |
| 317 singleton->retain(); | |
| 318 | |
| 319 return singleton; | |
| 320 } | |
| 321 | |
| 322 const char *Window::getName() const | |
| 323 { | |
| 324 return "love.window.sdl"; | |
| 325 } | |
| 326 | |
| 327 } // sdl | |
| 328 } // window | |
| 329 } // love |
