1 /** 2 * Copyright (c) 2006-2016 LOVE Development Team 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 #ifndef LOVE_WINDOW_SDL_WINDOW_H 22 #define LOVE_WINDOW_SDL_WINDOW_H 23 24 // LOVE 25 #include "window/Window.h" 26 27 // SDL 28 #include <SDL.h> 29 30 namespace love 31 { 32 namespace window 33 { 34 namespace sdl 35 { 36 37 class Window : public love::window::Window 38 { 39 public: 40 41 Window(); 42 ~Window(); 43 44 bool setWindow(int width = 800, int height = 600, WindowSettings *settings = nullptr); 45 void getWindow(int &width, int &height, WindowSettings &settings); 46 47 void close(); 48 49 bool setFullscreen(bool fullscreen, FullscreenType fstype); 50 bool setFullscreen(bool fullscreen); 51 52 bool onSizeChanged(int width, int height); 53 54 int getDisplayCount() const; 55 56 const char *getDisplayName(int displayindex) const; 57 58 std::vector<WindowSize> getFullscreenSizes(int displayindex) const; 59 60 void getDesktopDimensions(int displayindex, int &width, int &height) const; 61 62 void setPosition(int x, int y, int displayindex); 63 void getPosition(int &x, int &y, int &displayindex); 64 65 bool isOpen() const; 66 67 void setWindowTitle(const std::string &title); 68 const std::string &getWindowTitle() const; 69 70 bool setIcon(love::image::ImageData *imgd); 71 love::image::ImageData *getIcon(); 72 73 void setDisplaySleepEnabled(bool enable); 74 bool isDisplaySleepEnabled() const; 75 76 void minimize(); 77 void maximize(); 78 79 bool isMaximized() const; 80 81 void swapBuffers(); 82 83 bool hasFocus() const; 84 bool hasMouseFocus() const; 85 86 bool isVisible() const; 87 88 void setMouseGrab(bool grab); 89 bool isMouseGrabbed() const; 90 91 void getPixelDimensions(int &w, int &h) const; 92 void windowToPixelCoords(double *x, double *y) const; 93 void pixelToWindowCoords(double *x, double *y) const; 94 95 double getPixelScale() const; 96 97 double toPixels(double x) const; 98 void toPixels(double wx, double wy, double &px, double &py) const; 99 double fromPixels(double x) const; 100 void fromPixels(double px, double py, double &wx, double &wy) const; 101 102 const void *getHandle() const; 103 104 bool showMessageBox(const std::string &title, const std::string &message, MessageBoxType type, bool attachtowindow); 105 int showMessageBox(const MessageBoxData &data); 106 107 void requestAttention(bool continuous); 108 109 const char *getName() const; 110 111 private: 112 113 struct ContextAttribs 114 { 115 int versionMajor; 116 int versionMinor; 117 bool gles; 118 bool debug; 119 }; 120 121 void setGLFramebufferAttributes(int msaa, bool sRGB); 122 void setGLContextAttributes(const ContextAttribs &attribs); 123 bool checkGLVersion(const ContextAttribs &attribs, std::string &outversion); 124 bool createWindowAndContext(int x, int y, int w, int h, Uint32 windowflags, int msaa); 125 126 // Update the saved window settings based on the window's actual state. 127 void updateSettings(const WindowSettings &newsettings, bool updateGraphicsViewport); 128 129 SDL_MessageBoxFlags convertMessageBoxType(MessageBoxType type) const; 130 131 std::string title; 132 133 int windowWidth = 800; 134 int windowHeight = 600; 135 int pixelWidth = 800; 136 int pixelHeight = 600; 137 WindowSettings settings; 138 StrongRef<love::image::ImageData> icon; 139 140 bool open; 141 142 bool mouseGrabbed; 143 144 SDL_Window *window; 145 SDL_GLContext context; 146 147 bool displayedWindowError; 148 bool hasSDL203orEarlier; 149 150 }; // Window 151 152 } // sdl 153 } // window 154 } // love 155 156 #endif // LOVE_WINDOW_WINDOW_H 157