Add window.scale, let window width/height and mouse events be in logical points
This commit is contained in:
@@ -14,7 +14,6 @@ import lime.graphics.Renderer;
|
||||
@:build(lime.system.CFFI.build())
|
||||
#end
|
||||
|
||||
@:access(lime._backend.native.NativeWindow)
|
||||
@:access(lime.graphics.cairo.Cairo)
|
||||
@:access(lime.ui.Window)
|
||||
|
||||
@@ -46,10 +45,7 @@ class NativeRenderer {
|
||||
#if !macro
|
||||
handle = lime_renderer_create (parent.window.backend.handle);
|
||||
|
||||
#if (mac || ios)
|
||||
parent.window.__width = NativeWindow.lime_window_get_width (parent.window.backend.handle);
|
||||
parent.window.__height = NativeWindow.lime_window_get_height (parent.window.backend.handle);
|
||||
#end
|
||||
parent.window.__scale = lime_renderer_get_scale (handle);
|
||||
|
||||
#if lime_console
|
||||
|
||||
@@ -163,6 +159,7 @@ class NativeRenderer {
|
||||
@:cffi private static function lime_renderer_create (window:Dynamic):Dynamic;
|
||||
@:cffi private static function lime_renderer_flip (handle:Dynamic):Void;
|
||||
@:cffi private static function lime_renderer_get_context (handle:Dynamic):Float;
|
||||
@:cffi private static function lime_renderer_get_scale (handle:Dynamic):Float;
|
||||
@:cffi private static function lime_renderer_get_type (handle:Dynamic):Dynamic;
|
||||
@:cffi private static function lime_renderer_lock (handle:Dynamic):Dynamic;
|
||||
@:cffi private static function lime_renderer_make_current (handle:Dynamic):Void;
|
||||
|
||||
@@ -49,6 +49,7 @@ class Window {
|
||||
public var onTextEdit = new Event<String->Int->Int->Void> ();
|
||||
public var onTextInput = new Event<String->Void> ();
|
||||
public var renderer:Renderer;
|
||||
public var scale (get, null):Float;
|
||||
public var stage:Stage;
|
||||
public var title (get, set):String;
|
||||
public var width (get, set):Int;
|
||||
@@ -59,6 +60,7 @@ class Window {
|
||||
@:noCompletion private var __fullscreen:Bool;
|
||||
@:noCompletion private var __height:Int;
|
||||
@:noCompletion private var __minimized:Bool;
|
||||
@:noCompletion private var __scale:Float;
|
||||
@:noCompletion private var __title:String;
|
||||
@:noCompletion private var __width:Int;
|
||||
@:noCompletion private var __x:Int;
|
||||
@@ -72,6 +74,7 @@ class Window {
|
||||
__width = 0;
|
||||
__height = 0;
|
||||
__fullscreen = false;
|
||||
__scale = 1;
|
||||
__x = 0;
|
||||
__y = 0;
|
||||
__title = "";
|
||||
@@ -367,6 +370,13 @@ class Window {
|
||||
}
|
||||
|
||||
|
||||
@:noCompletion private inline function get_scale ():Float {
|
||||
|
||||
return __scale;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@:noCompletion private inline function get_title ():String {
|
||||
|
||||
return __title;
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace lime {
|
||||
|
||||
virtual void Flip () = 0;
|
||||
virtual void* GetContext () = 0;
|
||||
virtual double GetScale () = 0;
|
||||
virtual value Lock () = 0;
|
||||
virtual void MakeCurrent () = 0;
|
||||
virtual const char* Type () = 0;
|
||||
|
||||
@@ -991,6 +991,14 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
double lime_renderer_get_scale (value renderer) {
|
||||
|
||||
Renderer* targetRenderer = (Renderer*)val_data (renderer);
|
||||
return targetRenderer->GetScale ();
|
||||
|
||||
}
|
||||
|
||||
|
||||
value lime_renderer_get_type (value renderer) {
|
||||
|
||||
Renderer* targetRenderer = (Renderer*)val_data (renderer);
|
||||
@@ -1367,6 +1375,7 @@ namespace lime {
|
||||
DEFINE_PRIME1 (lime_renderer_create);
|
||||
DEFINE_PRIME1v (lime_renderer_flip);
|
||||
DEFINE_PRIME1 (lime_renderer_get_context);
|
||||
DEFINE_PRIME1 (lime_renderer_get_scale);
|
||||
DEFINE_PRIME1 (lime_renderer_get_type);
|
||||
DEFINE_PRIME1 (lime_renderer_lock);
|
||||
DEFINE_PRIME1v (lime_renderer_make_current);
|
||||
|
||||
@@ -536,9 +536,8 @@ namespace lime {
|
||||
case SDL_WINDOWEVENT_SIZE_CHANGED:
|
||||
|
||||
windowEvent.type = WINDOW_RESIZE;
|
||||
SDL_GL_GetDrawableSize (SDL_GetWindowFromID (event->window.windowID), &windowEvent.width, &windowEvent.height);
|
||||
//windowEvent.width = event->window.data1;
|
||||
//windowEvent.height = event->window.data2;
|
||||
windowEvent.width = event->window.data1;
|
||||
windowEvent.height = event->window.data2;
|
||||
break;
|
||||
|
||||
case SDL_WINDOWEVENT_RESTORED: windowEvent.type = WINDOW_RESTORE; break;
|
||||
|
||||
@@ -85,6 +85,24 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
double SDLRenderer::GetScale () {
|
||||
|
||||
int outputWidth;
|
||||
int outputHeight;
|
||||
|
||||
SDL_GetRendererOutputSize (sdlRenderer, &outputWidth, &outputHeight);
|
||||
|
||||
int width;
|
||||
int height;
|
||||
|
||||
SDL_GetWindowSize (sdlWindow, &width, &height);
|
||||
|
||||
double scale = outputWidth / width;
|
||||
return scale;
|
||||
|
||||
}
|
||||
|
||||
|
||||
value SDLRenderer::Lock () {
|
||||
|
||||
int width;
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace lime {
|
||||
|
||||
virtual void Flip ();
|
||||
virtual void* GetContext ();
|
||||
virtual double GetScale ();
|
||||
virtual value Lock ();
|
||||
virtual void MakeCurrent ();
|
||||
virtual const char* Type ();
|
||||
|
||||
@@ -173,19 +173,7 @@ namespace lime {
|
||||
int width;
|
||||
int height;
|
||||
|
||||
SDL_GL_GetDrawableSize (sdlWindow, &width, &height);
|
||||
|
||||
SDL_Renderer* sdlRenderer = SDL_GetRenderer (sdlWindow);
|
||||
|
||||
if (sdlRenderer) {
|
||||
|
||||
SDL_GetRendererOutputSize (sdlRenderer, &width, &height);
|
||||
|
||||
} else {
|
||||
|
||||
SDL_GetWindowSize (sdlWindow, &width, &height);
|
||||
|
||||
}
|
||||
SDL_GetWindowSize (sdlWindow, &width, &height);
|
||||
|
||||
return height;
|
||||
|
||||
@@ -204,17 +192,7 @@ namespace lime {
|
||||
int width;
|
||||
int height;
|
||||
|
||||
SDL_Renderer* sdlRenderer = SDL_GetRenderer (sdlWindow);
|
||||
|
||||
if (sdlRenderer) {
|
||||
|
||||
SDL_GetRendererOutputSize (sdlRenderer, &width, &height);
|
||||
|
||||
} else {
|
||||
|
||||
SDL_GetWindowSize (sdlWindow, &width, &height);
|
||||
|
||||
}
|
||||
SDL_GetWindowSize (sdlWindow, &width, &height);
|
||||
|
||||
return width;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user