Implement window.fullscreen and window.minimize, add onWindow minimize, restore, fullscreen events

This commit is contained in:
Joshua Granick
2015-03-19 16:55:38 -07:00
parent 580e8d426d
commit 138e3f6703
15 changed files with 437 additions and 30 deletions

View File

@@ -51,6 +51,13 @@ class FlashWindow {
}
public function setFullscreen (value:Bool):Bool {
return value;
}
public function setIcon (image:Image):Void {
@@ -58,4 +65,11 @@ class FlashWindow {
}
public function setMinimized (value:Bool):Void {
return false;
}
}

View File

@@ -372,6 +372,13 @@ class HTML5Window {
}
public function setFullscreen (value:Bool):Bool {
return false;
}
public function setIcon (image:Image):Void {
@@ -379,4 +386,11 @@ class HTML5Window {
}
public function setMinimized (value:Bool):Bool {
return false;
}
}

View File

@@ -15,6 +15,7 @@ import lime.ui.Window;
@:access(lime.app.Application)
@:access(lime.graphics.Renderer)
@:access(lime.ui.Gamepad)
@:access(lime.ui.Window)
class NativeApplication {
@@ -290,6 +291,11 @@ class NativeApplication {
parent.window.onWindowFocusOut.dispatch ();
case WINDOW_MINIMIZE:
parent.window.__minimized = true;
parent.window.onWindowMinimize.dispatch ();
case WINDOW_MOVE:
parent.window.x = windowEventInfo.x;
@@ -304,6 +310,12 @@ class NativeApplication {
parent.window.onWindowResize.dispatch (windowEventInfo.width, windowEventInfo.height);
case WINDOW_RESTORE:
parent.window.__fullscreen = false;
parent.window.__minimized = false;
parent.window.onWindowRestore.dispatch ();
}
}
@@ -595,7 +607,9 @@ private class WindowEventInfo {
var WINDOW_DEACTIVATE = 2;
var WINDOW_FOCUS_IN = 3;
var WINDOW_FOCUS_OUT = 4;
var WINDOW_MOVE = 5;
var WINDOW_RESIZE = 6;
var WINDOW_MINIMIZE = 5;
var WINDOW_MOVE = 6;
var WINDOW_RESIZE = 7;
var WINDOW_RESTORE = 8;
}

View File

@@ -79,21 +79,65 @@ class NativeWindow {
public function move (x:Int, y:Int):Void {
lime_window_move (handle, x, y);
if (handle != null) {
lime_window_move (handle, x, y);
}
}
public function resize (width:Int, height:Int):Void {
lime_window_resize (handle, width, height);
if (handle != null) {
lime_window_resize (handle, width, height);
}
}
public function setFullscreen (value:Bool):Bool {
if (handle != null) {
value = lime_window_set_fullscreen (handle, value);
if (value) {
parent.onWindowFullscreen.dispatch ();
}
}
return value;
}
public function setIcon (image:Image):Void {
lime_window_set_icon (handle, image.buffer);
if (handle != null) {
lime_window_set_icon (handle, image.buffer);
}
}
public function setMinimized (value:Bool):Bool {
if (handle != null) {
return lime_window_set_minimized (handle, value);
}
return value;
}
@@ -102,7 +146,9 @@ class NativeWindow {
private static var lime_window_create = System.load ("lime", "lime_window_create", 5);
private static var lime_window_move = System.load ("lime", "lime_window_move", 3);
private static var lime_window_resize = System.load ("lime", "lime_window_resize", 3);
private static var lime_window_set_fullscreen = System.load ("lime", "lime_window_set_fullscreen", 2);
private static var lime_window_set_icon = System.load ("lime", "lime_window_set_icon", 2);
private static var lime_window_set_minimized = System.load ("lime", "lime_window_set_minimized", 2);
}

View File

@@ -3,6 +3,9 @@ package lime.app;
import lime.graphics.Renderer;
import lime.graphics.RenderContext;
import lime.ui.Gamepad;
import lime.ui.GamepadAxis;
import lime.ui.GamepadButton;
import lime.ui.KeyCode;
import lime.ui.KeyModifier;
import lime.ui.Window;
@@ -117,8 +120,11 @@ class Application extends Module {
window.onWindowDeactivate.add (onWindowDeactivate);
window.onWindowFocusIn.add (onWindowFocusIn);
window.onWindowFocusOut.add (onWindowFocusOut);
window.onWindowFullscreen.add (onWindowFullscreen);
window.onWindowMinimize.add (onWindowMinimize);
window.onWindowMove.add (onWindowMove);
window.onWindowResize.add (onWindowResize);
window.onWindowRestore.add (onWindowRestore);
window.create (this);
@@ -166,6 +172,61 @@ class Application extends Module {
}
public override function onGamepadAxisMove (gamepad:Gamepad, axis:GamepadAxis, value:Float):Void {
for (module in modules) {
module.onGamepadAxisMove (gamepad, axis, value);
}
}
public override function onGamepadButtonDown (gamepad:Gamepad, button:GamepadButton):Void {
for (module in modules) {
module.onGamepadButtonDown (gamepad, button);
}
}
public override function onGamepadButtonUp (gamepad:Gamepad, button:GamepadButton):Void {
for (module in modules) {
module.onGamepadButtonUp (gamepad, button);
}
}
public override function onGamepadConnect (gamepad:Gamepad):Void {
for (module in modules) {
module.onGamepadConnect (gamepad);
}
}
public override function onGamepadDisconnect (gamepad:Gamepad):Void {
for (module in modules) {
module.onGamepadDisconnect (gamepad);
}
}
public override function onKeyDown (keyCode:KeyCode, modifier:KeyModifier):Void {
for (module in modules) {
@@ -342,6 +403,28 @@ class Application extends Module {
}
public override function onWindowFullscreen ():Void {
for (module in modules) {
module.onWindowFullscreen ();
}
}
public override function onWindowMinimize ():Void {
for (module in modules) {
module.onWindowMinimize ();
}
}
public override function onWindowMove (x:Float, y:Float):Void {
for (module in modules) {
@@ -364,6 +447,17 @@ class Application extends Module {
}
public override function onWindowRestore ():Void {
for (module in modules) {
module.onWindowRestore ();
}
}
/**
* Removes a module from the Application
* @param module A module to remove

View File

@@ -21,10 +21,42 @@ interface IModule {
public function init (context:RenderContext):Void;
/**
* Called when a gamepad axis move event is fired
* @param gamepad The current gamepad
* @param axis The axis that was moved
* @param value The axis value (between 0 and 1)
*/
public function onGamepadAxisMove (gamepad:Gamepad, axis:GamepadAxis, value:Float):Void;
/**
* Called when a gamepad button down event is fired
* @param gamepad The current gamepad
* @param button The button that was pressed
*/
public function onGamepadButtonDown (gamepad:Gamepad, button:GamepadButton):Void;
/**
* Called when a gamepad button up event is fired
* @param gamepad The current gamepad
* @param button The button that was released
*/
public function onGamepadButtonUp (gamepad:Gamepad, button:GamepadButton):Void;
/**
* Called when a gamepad is connected
* @param gamepad The gamepad that was connected
*/
public function onGamepadConnect (gamepad:Gamepad):Void;
/**
* Called when a gamepad is disconnected
* @param gamepad The gamepad that was disconnected
*/
public function onGamepadDisconnect (gamepad:Gamepad):Void;
@@ -149,6 +181,12 @@ interface IModule {
public function onWindowFocusOut ():Void;
/**
* Called when a window enters fullscreen
*/
public function onWindowFullscreen ():Void;
/**
* Called when a window move event is fired
* @param x The x position of the window
@@ -157,6 +195,12 @@ interface IModule {
public function onWindowMove (x:Float, y:Float):Void;
/**
* Called when a window is minimized
*/
public function onWindowMinimize ():Void;
/**
* Called when a window resize event is fired
* @param width The width of the window
@@ -165,6 +209,12 @@ interface IModule {
public function onWindowResize (width:Int, height:Int):Void;
/**
* Called when a window is restored from being minimized or fullscreen
*/
public function onWindowRestore ():Void;
/**
* Called when a render event is fired
* @param context The current render context

View File

@@ -156,6 +156,10 @@ class Module implements IModule {
public function onWindowFocusOut ():Void { }
public function onWindowFullscreen ():Void { }
public function onWindowMinimize ():Void { }
/**
* Called when a window move event is fired
* @param x The x position of the window
@@ -172,6 +176,9 @@ class Module implements IModule {
public function onWindowResize (width:Int, height:Int):Void { }
public function onWindowRestore ():Void { }
/**
* Called when a render event is fired
* @param context The current render context

View File

@@ -13,8 +13,9 @@ class Window {
public var currentRenderer:Renderer;
public var config:Config;
public var fullscreen:Bool;
public var height:Int;
public var fullscreen (get, set):Bool;
public var height (get, set):Int;
public var minimized (get, set):Bool;
public var onGamepadAxisMove = new Event<Gamepad->GamepadAxis->Float->Void> ();
public var onGamepadButtonDown = new Event<Gamepad->GamepadButton->Void> ();
public var onGamepadButtonUp = new Event<Gamepad->GamepadButton->Void> ();
@@ -34,32 +35,41 @@ class Window {
public var onWindowDeactivate = new Event<Void->Void> ();
public var onWindowFocusIn = new Event<Void->Void> ();
public var onWindowFocusOut = new Event<Void->Void> ();
public var onWindowFullscreen = new Event<Void->Void> ();
public var onWindowMinimize = new Event<Void->Void> ();
public var onWindowMove = new Event<Float->Float->Void> ();
public var onWindowResize = new Event<Int->Int->Void> ();
public var width:Int;
public var x:Int;
public var y:Int;
public var onWindowRestore = new Event<Void->Void> ();
public var width (get, set):Int;
public var x (get, set):Int;
public var y (get, set):Int;
@:noCompletion private var backend:WindowBackend;
@:noCompletion private var __fullscreen:Bool;
@:noCompletion private var __height:Int;
@:noCompletion private var __minimized:Bool;
@:noCompletion private var __width:Int;
@:noCompletion private var __x:Int;
@:noCompletion private var __y:Int;
public function new (config:Config = null) {
this.config = config;
width = 0;
height = 0;
fullscreen = false;
x = 0;
y = 0;
__width = 0;
__height = 0;
__fullscreen = false;
__x = 0;
__y = 0;
if (config != null) {
// TODO: Switch to the tool's Config type?
if (Reflect.hasField (config, "width")) width = config.width;
if (Reflect.hasField (config, "height")) height = config.height;
if (Reflect.hasField (config, "fullscreen")) fullscreen = config.fullscreen;
if (Reflect.hasField (config, "width")) __width = config.width;
if (Reflect.hasField (config, "height")) __height = config.height;
if (Reflect.hasField (config, "fullscreen")) __fullscreen = config.fullscreen;
}
@@ -92,8 +102,8 @@ class Window {
backend.move (x, y);
this.x = x;
this.y = y;
__x = x;
__y = y;
}
@@ -102,8 +112,8 @@ class Window {
backend.resize (width, height);
this.width = width;
this.height = height;
__width = width;
__height = height;
}
@@ -121,6 +131,101 @@ class Window {
}
// Get & Set Methods
@:noCompletion private inline function get_fullscreen ():Bool {
return __fullscreen;
}
@:noCompletion private function set_fullscreen (value:Bool):Bool {
return __fullscreen = backend.setFullscreen (value);
}
@:noCompletion private inline function get_height ():Int {
return __height;
}
@:noCompletion private function set_height (value:Int):Int {
resize (__width, value);
return __height;
}
@:noCompletion private inline function get_minimized ():Bool {
return __minimized;
}
@:noCompletion private function set_minimized (value:Bool):Bool {
return __minimized = backend.setMinimized (value);
}
@:noCompletion private inline function get_width ():Int {
return __width;
}
@:noCompletion private function set_width (value:Int):Int {
resize (value, __height);
return __width;
}
@:noCompletion private inline function get_x ():Int {
return __x;
}
@:noCompletion private function set_x (value:Int):Int {
move (value, __y);
return __x;
}
@:noCompletion private inline function get_y ():Int {
return __y;
}
@:noCompletion private function set_y (value:Int):Int {
move (__x, value);
return __y;
}
}

View File

@@ -21,7 +21,9 @@ namespace lime {
virtual void Close () = 0;
virtual void Move (int x, int y) = 0;
virtual void Resize (int width, int height) = 0;
virtual bool SetFullscreen (bool fullscreen) = 0;
virtual void SetIcon (ImageBuffer *imageBuffer) = 0;
virtual bool SetMinimized (bool minimized) = 0;
Application* currentApplication;
int flags;

View File

@@ -15,8 +15,10 @@ namespace lime {
WINDOW_DEACTIVATE,
WINDOW_FOCUS_IN,
WINDOW_FOCUS_OUT,
WINDOW_MINIMIZE,
WINDOW_MOVE,
WINDOW_RESIZE
WINDOW_RESIZE,
WINDOW_RESTORE
};

View File

@@ -720,6 +720,14 @@ namespace lime {
}
value lime_window_set_fullscreen (value window, value fullscreen) {
Window* targetWindow = (Window*)(intptr_t)val_float (window);
return alloc_bool (targetWindow->SetFullscreen (val_bool (fullscreen)));
}
value lime_window_set_icon (value window, value buffer) {
Window* targetWindow = (Window*)(intptr_t)val_float (window);
@@ -730,6 +738,14 @@ namespace lime {
}
value lime_window_set_minimized (value window, value fullscreen) {
Window* targetWindow = (Window*)(intptr_t)val_float (window);
return alloc_bool (targetWindow->SetMinimized (val_bool (fullscreen)));
}
DEFINE_PRIM (lime_application_create, 1);
DEFINE_PRIM (lime_application_exec, 1);
DEFINE_PRIM (lime_application_init, 1);
@@ -784,7 +800,9 @@ namespace lime {
DEFINE_PRIM (lime_window_event_manager_register, 2);
DEFINE_PRIM (lime_window_move, 3);
DEFINE_PRIM (lime_window_resize, 3);
DEFINE_PRIM (lime_window_set_fullscreen, 2);
DEFINE_PRIM (lime_window_set_icon, 2);
DEFINE_PRIM (lime_window_set_minimized, 2);
}

View File

@@ -155,7 +155,9 @@ namespace lime {
case SDL_WINDOWEVENT_HIDDEN:
case SDL_WINDOWEVENT_FOCUS_GAINED:
case SDL_WINDOWEVENT_FOCUS_LOST:
case SDL_WINDOWEVENT_MINIMIZED:
case SDL_WINDOWEVENT_MOVED:
case SDL_WINDOWEVENT_RESTORED:
ProcessWindowEvent (event);
break;
@@ -339,6 +341,7 @@ namespace lime {
case SDL_WINDOWEVENT_HIDDEN: windowEvent.type = WINDOW_DEACTIVATE; break;
case SDL_WINDOWEVENT_FOCUS_GAINED: windowEvent.type = WINDOW_FOCUS_IN; break;
case SDL_WINDOWEVENT_FOCUS_LOST: windowEvent.type = WINDOW_FOCUS_OUT; break;
case SDL_WINDOWEVENT_MINIMIZED: windowEvent.type = WINDOW_MINIMIZE; break;
case SDL_WINDOWEVENT_MOVED:
@@ -354,6 +357,8 @@ namespace lime {
windowEvent.height = event->window.data2;
break;
case SDL_WINDOWEVENT_RESTORED: windowEvent.type = WINDOW_RESTORE; break;
}
WindowEvent::Dispatch (&windowEvent);

View File

@@ -95,6 +95,23 @@ namespace lime {
}
bool SDLWindow::SetFullscreen (bool fullscreen) {
if (fullscreen) {
SDL_SetWindowFullscreen (sdlWindow, SDL_WINDOW_FULLSCREEN_DESKTOP);
} else {
SDL_SetWindowFullscreen (sdlWindow, 0);
}
return fullscreen;
}
void SDLWindow::SetIcon (ImageBuffer *imageBuffer) {
SDL_Surface *surface = SDL_CreateRGBSurfaceFrom (imageBuffer->data->Bytes (), imageBuffer->width, imageBuffer->height, imageBuffer->bpp * 8, imageBuffer->width * imageBuffer->bpp, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000);
@@ -109,6 +126,23 @@ namespace lime {
}
bool SDLWindow::SetMinimized (bool minimized) {
if (minimized) {
SDL_MinimizeWindow (sdlWindow);
} else {
SDL_RestoreWindow (sdlWindow);
}
return minimized;
}
Window* CreateWindow (Application* application, int width, int height, int flags, const char* title) {
return new SDLWindow (application, width, height, flags, title);

View File

@@ -20,7 +20,9 @@ namespace lime {
virtual void Close ();
virtual void Move (int x, int y);
virtual void Resize (int width, int height);
virtual bool SetFullscreen (bool fullscreen);
virtual void SetIcon (ImageBuffer *imageBuffer);
virtual bool SetMinimized (bool minimized);
SDL_Window* sdlWindow;

View File

@@ -688,24 +688,24 @@ class DefaultAssetLibrary extends AssetLibrary {
#else
::if (assets != null)::::foreach assets::::if (!embed)::::if (type == "font")::@:keep class __ASSET__::flatName:: extends lime.text.Font { public function new () { __fontPath = "::targetPath::"; name = "::fontName::"; super (); }}
::if (assets != null)::::foreach assets::::if (!embed)::::if (type == "font")::@:keep #if display private #end class __ASSET__::flatName:: extends lime.text.Font { public function new () { __fontPath = "::targetPath::"; name = "::fontName::"; super (); }}
::end::::end::::end::::end::
#if (windows || mac || linux)
::if (assets != null)::
::foreach assets::::if (embed)::::if (type == "image")::@:image("::sourcePath::") class __ASSET__::flatName:: extends lime.graphics.Image {}
::elseif (type == "sound")::@:file("::sourcePath::") class __ASSET__::flatName:: extends lime.utils.ByteArray {}
::elseif (type == "music")::@:file("::sourcePath::") class __ASSET__::flatName:: extends lime.utils.ByteArray {}
::elseif (type == "font")::@:font("::sourcePath::") class __ASSET__::flatName:: extends lime.graphics.Font {}
::else::@:file("::sourcePath::") class __ASSET__::flatName:: extends lime.utils.ByteArray {}
::foreach assets::::if (embed)::::if (type == "image")::@:image("::sourcePath::") #if display private #end class __ASSET__::flatName:: extends lime.graphics.Image {}
::elseif (type == "sound")::@:file("::sourcePath::") #if display private #end class __ASSET__::flatName:: extends lime.utils.ByteArray {}
::elseif (type == "music")::@:file("::sourcePath::") #if display private #end class __ASSET__::flatName:: extends lime.utils.ByteArray {}
::elseif (type == "font")::@:font("::sourcePath::") #if display private #end class __ASSET__::flatName:: extends lime.graphics.Font {}
::else::@:file("::sourcePath::") #if display private #end class __ASSET__::flatName:: extends lime.utils.ByteArray {}
::end::::end::::end::
::end::
#end
#if openfl
::if (assets != null)::::foreach assets::::if (type == "font")::@:keep class __ASSET__OPENFL__::flatName:: extends openfl.text.Font { public function new () { __fontPath = "::targetPath::"; name = "::fontName::"; super (); }}
::if (assets != null)::::foreach assets::::if (type == "font")::@:keep #if display private #end class __ASSET__OPENFL__::flatName:: extends openfl.text.Font { public function new () { __fontPath = "::targetPath::"; name = "::fontName::"; super (); }}
::end::::end::::end::
#end