From 10a2a74cd813cbda68e297cb5d43e45f6c6101c3 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Wed, 9 Jul 2014 15:39:02 -0700 Subject: [PATCH] Handle title and window flags --- lime/ui/Window.hx | 52 ++++++++++++++++++------- project/include/ui/Window.h | 20 +++++++++- project/src/ExternalInterface.cpp | 6 +-- project/src/backend/sdl/SDLRenderer.cpp | 23 ++++++++++- project/src/backend/sdl/SDLWindow.cpp | 18 ++++----- project/src/backend/sdl/SDLWindow.h | 7 +--- 6 files changed, 93 insertions(+), 33 deletions(-) diff --git a/lime/ui/Window.hx b/lime/ui/Window.hx index ba97c4724..08c9dc6c4 100644 --- a/lime/ui/Window.hx +++ b/lime/ui/Window.hx @@ -23,10 +23,7 @@ import flash.Lib; class Window { - public inline static var DEPTH_BUFFER = 0x0200; - public inline static var STENCIL_BUFFER = 0x0400; - - public static var onWindowActivate = new EventVoid> (); + public static var onWindowActivate = new EventVoid> (); public static var onWindowDeactivate = new EventVoid> (); private static var eventInfo = new WindowEventInfo (); @@ -172,16 +169,28 @@ class Window { #end #elseif (cpp || neko) - // forward flags - var flags:Int = 0; - - if (config.depthBuffer) - flags |= DEPTH_BUFFER; - if (config.stencilBuffer) - flags |= STENCIL_BUFFER; + var flags = 0; + + if (config.antialiasing >= 4) { + + flags |= cast WindowFlags.WINDOW_FLAG_HW_AA_HIRES; + + } else if (config.antialiasing >= 2) { + + flags |= cast WindowFlags.WINDOW_FLAG_HW_AA; + + } + + if (config.borderless) flags |= cast WindowFlags.WINDOW_FLAG_BORDERLESS; + if (config.depthBuffer) flags |= cast WindowFlags.WINDOW_FLAG_DEPTH_BUFFER; + if (config.fullscreen) flags |= cast WindowFlags.WINDOW_FLAG_FULLSCREEN; + if (config.resizable) flags |= cast WindowFlags.WINDOW_FLAG_RESIZABLE; + if (config.stencilBuffer) flags |= cast WindowFlags.WINDOW_FLAG_STENCIL_BUFFER; + if (config.vsync) flags |= cast WindowFlags.WINDOW_FLAG_VSYNC; + + handle = lime_window_create (application.__handle, width, height, flags, config.title); - handle = lime_window_create (application.__handle, width, height, flags); #end MouseEventManager.registerWindow (this); @@ -242,7 +251,7 @@ class Window { #if (cpp || neko) - private static var lime_window_create = System.load ("lime", "lime_window_create", 4); + private static var lime_window_create = System.load ("lime", "lime_window_create", 5); private static var lime_window_event_manager_register = System.load ("lime", "lime_window_event_manager_register", 2); #end @@ -273,6 +282,23 @@ private class WindowEventInfo { } +@:enum private abstract WindowFlags(Int) { + + var WINDOW_FLAG_FULLSCREEN = 0x00000001; + var WINDOW_FLAG_BORDERLESS = 0x00000002; + var WINDOW_FLAG_RESIZABLE = 0x00000004; + var WINDOW_FLAG_HARDWARE = 0x00000008; + var WINDOW_FLAG_VSYNC = 0x00000010; + var WINDOW_FLAG_HW_AA = 0x00000020; + var WINDOW_FLAG_HW_AA_HIRES = 0x00000060; + var WINDOW_FLAG_ALLOW_SHADERS = 0x00000080; + var WINDOW_FLAG_REQUIRE_SHADERS = 0x00000100; + var WINDOW_FLAG_DEPTH_BUFFER = 0x00000200; + var WINDOW_FLAG_STENCIL_BUFFER = 0x00000400; + +} + + @:enum private abstract WindowEventType(Int) { var WINDOW_ACTIVATE = 0; diff --git a/project/include/ui/Window.h b/project/include/ui/Window.h index fbef7bb05..7a90d8ad4 100644 --- a/project/include/ui/Window.h +++ b/project/include/ui/Window.h @@ -18,14 +18,32 @@ namespace lime { public: Application* currentApplication; + + int flags; }; - Window* CreateWindow (Application* application, int width, int height, int flags); + Window* CreateWindow (Application* application, int width, int height, int flags, const char* title); + enum WindowFlags { + + WINDOW_FLAG_FULLSCREEN = 0x00000001, + WINDOW_FLAG_BORDERLESS = 0x00000002, + WINDOW_FLAG_RESIZABLE = 0x00000004, + WINDOW_FLAG_HARDWARE = 0x00000008, + WINDOW_FLAG_VSYNC = 0x00000010, + WINDOW_FLAG_HW_AA = 0x00000020, + WINDOW_FLAG_HW_AA_HIRES = 0x00000060, + WINDOW_FLAG_ALLOW_SHADERS = 0x00000080, + WINDOW_FLAG_REQUIRE_SHADERS = 0x00000100, + WINDOW_FLAG_DEPTH_BUFFER = 0x00000200, + WINDOW_FLAG_STENCIL_BUFFER = 0x00000400 + + }; + } diff --git a/project/src/ExternalInterface.cpp b/project/src/ExternalInterface.cpp index 6d98442af..d4586c15b 100644 --- a/project/src/ExternalInterface.cpp +++ b/project/src/ExternalInterface.cpp @@ -177,9 +177,9 @@ namespace lime { } - value lime_window_create (value application, value width, value height, value flags) { + value lime_window_create (value application, value width, value height, value flags, value title) { - Window* window = CreateWindow ((Application*)(intptr_t)val_float (application), val_int (width), val_int (height), val_int(flags)); + Window* window = CreateWindow ((Application*)(intptr_t)val_float (application), val_int (width), val_int (height), val_int (flags), val_string (title)); return alloc_float ((intptr_t)window); } @@ -209,7 +209,7 @@ namespace lime { DEFINE_PRIM (lime_system_get_timestamp, 0); DEFINE_PRIM (lime_touch_event_manager_register, 2); DEFINE_PRIM (lime_update_event_manager_register, 2); - DEFINE_PRIM (lime_window_create, 4); + DEFINE_PRIM (lime_window_create, 5); DEFINE_PRIM (lime_window_event_manager_register, 2); diff --git a/project/src/backend/sdl/SDLRenderer.cpp b/project/src/backend/sdl/SDLRenderer.cpp index ff1781f89..f8a3c9409 100644 --- a/project/src/backend/sdl/SDLRenderer.cpp +++ b/project/src/backend/sdl/SDLRenderer.cpp @@ -17,7 +17,28 @@ namespace lime { if (context) { - SDL_GL_SetSwapInterval (0); + if (window->flags & WINDOW_FLAG_VSYNC) { + + SDL_GL_SetSwapInterval (1); + + } else { + + SDL_GL_SetSwapInterval (0); + + } + + if (window->flags & WINDOW_FLAG_DEPTH_BUFFER) { + + SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 32 - (window->flags & WINDOW_FLAG_STENCIL_BUFFER) ? 8 : 0); + + } + + if (window->flags & WINDOW_FLAG_STENCIL_BUFFER) { + + SDL_GL_SetAttribute (SDL_GL_STENCIL_SIZE, 8); + + } + SDL_GL_MakeCurrent (sdlWindow, context); } diff --git a/project/src/backend/sdl/SDLWindow.cpp b/project/src/backend/sdl/SDLWindow.cpp index ab102f0c4..82421ab6d 100644 --- a/project/src/backend/sdl/SDLWindow.cpp +++ b/project/src/backend/sdl/SDLWindow.cpp @@ -4,18 +4,18 @@ namespace lime { - SDLWindow::SDLWindow (Application* application, int width, int height, int flags) { + SDLWindow::SDLWindow (Application* application, int width, int height, int flags, const char* title) { currentApplication = application; + this->flags = flags; - // config the window - if (flags & DEPTH_BUFFER) - SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 32 - (flags & STENCIL_BUFFER) ? 8 : 0); + int sdlFlags = SDL_WINDOW_OPENGL; - if (flags & STENCIL_BUFFER) - SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); + if (flags & WINDOW_FLAG_FULLSCREEN) sdlFlags |= SDL_WINDOW_FULLSCREEN; + if (flags & WINDOW_FLAG_RESIZABLE) sdlFlags |= SDL_WINDOW_RESIZABLE; + if (flags & WINDOW_FLAG_BORDERLESS) sdlFlags |= SDL_WINDOW_BORDERLESS; - sdlWindow = SDL_CreateWindow ("Test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_OPENGL); + sdlWindow = SDL_CreateWindow (title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, sdlFlags); } @@ -27,9 +27,9 @@ namespace lime { } - Window* CreateWindow (Application* application, int width, int height, int flags) { + Window* CreateWindow (Application* application, int width, int height, int flags, const char* title) { - return new SDLWindow (application, width, height, flags); + return new SDLWindow (application, width, height, flags, title); } diff --git a/project/src/backend/sdl/SDLWindow.h b/project/src/backend/sdl/SDLWindow.h index 6c9a66c11..fa18c0a0d 100644 --- a/project/src/backend/sdl/SDLWindow.h +++ b/project/src/backend/sdl/SDLWindow.h @@ -8,17 +8,12 @@ namespace lime { - enum SDLWindowFlags - { - DEPTH_BUFFER = 0x00000200, - STENCIL_BUFFER = 0x00000400, - }; class SDLWindow : public Window { public: - SDLWindow (Application* application, int width, int height, int flags); + SDLWindow (Application* application, int width, int height, int flags, const char* title); ~SDLWindow (); SDL_Window* sdlWindow;