Screen: Add frame_inset
and display_scale
, and implement them in Android.
This commit is contained in:
parent
bb4f8e1c00
commit
e0b02d2708
3 changed files with 21 additions and 0 deletions
|
@ -60,6 +60,12 @@ template to_rotation(o: GLFMInterfaceOrientation): int8 =
|
||||||
of GLFMInterfaceOrientationLandscapeLeft: 3
|
of GLFMInterfaceOrientationLandscapeLeft: 3
|
||||||
else: 0
|
else: 0
|
||||||
|
|
||||||
|
proc update_inset(window: Window) {.inline.} =
|
||||||
|
let screen = window.screen
|
||||||
|
var top, right, bottom, left = 0.0
|
||||||
|
window.glfmGetDisplayChromeInsets(top.addr, right.addr, bottom.addr, left.addr)
|
||||||
|
screen.frame_inset = FrameInset(top:top, right:right, bottom:bottom, left:left)
|
||||||
|
|
||||||
proc `screen=`*(window: Window, screen: Screen) {.inline.} =
|
proc `screen=`*(window: Window, screen: Screen) {.inline.} =
|
||||||
window.glfmSetUserData cast[pointer](screen)
|
window.glfmSetUserData cast[pointer](screen)
|
||||||
if screen == nil:
|
if screen == nil:
|
||||||
|
@ -69,9 +75,15 @@ proc `screen=`*(window: Window, screen: Screen) {.inline.} =
|
||||||
let orientation = window.glfmGetInterfaceOrientation()
|
let orientation = window.glfmGetInterfaceOrientation()
|
||||||
echo &"resizing {width} {height}"
|
echo &"resizing {width} {height}"
|
||||||
window.screen.resize(width.int32, height.int32)
|
window.screen.resize(width.int32, height.int32)
|
||||||
|
window.update_inset()
|
||||||
|
window.screen.display_scale = scale
|
||||||
window.glfmSetOrientationChangedFunc proc(window: Window, orientation: GLFMInterfaceOrientation) {.cdecl.} =
|
window.glfmSetOrientationChangedFunc proc(window: Window, orientation: GLFMInterfaceOrientation) {.cdecl.} =
|
||||||
echo &"orientation {orientation.to_rotation}"
|
echo &"orientation {orientation.to_rotation}"
|
||||||
window.screen.resize(window.screen.width, window.screen.height, orientation.to_rotation)
|
window.screen.resize(window.screen.width, window.screen.height, orientation.to_rotation)
|
||||||
|
# TODO: Check if this is being called in sensorLandscape mode.
|
||||||
|
# window.glfmSetDisplayChromeInsetsChangedFunc proc (display: Window, top, right, bottom, left: float) {.cdecl.} =
|
||||||
|
# echo "insets:"
|
||||||
|
# dump (top, right, bottom, left)
|
||||||
# TODO: on emscripten there's no way to distinguish between
|
# TODO: on emscripten there's no way to distinguish between
|
||||||
# multi touch and right/middle mouse clicks!!
|
# multi touch and right/middle mouse clicks!!
|
||||||
# TODO: maybe add a couple of listeners with EM_ASM to know
|
# TODO: maybe add a couple of listeners with EM_ASM to know
|
||||||
|
@ -83,8 +95,11 @@ proc `screen=`*(window: Window, screen: Screen) {.inline.} =
|
||||||
var width, height: cint
|
var width, height: cint
|
||||||
glfmGetDisplaySize(window, width.addr, height.addr)
|
glfmGetDisplaySize(window, width.addr, height.addr)
|
||||||
let orientation = window.glfmGetInterfaceOrientation()
|
let orientation = window.glfmGetInterfaceOrientation()
|
||||||
|
let scale = window.glfmGetDisplayScale()
|
||||||
echo &"sizing {width} {height}"
|
echo &"sizing {width} {height}"
|
||||||
screen.resize(width.int32, height.int32, orientation.to_rotation)
|
screen.resize(width.int32, height.int32, orientation.to_rotation)
|
||||||
|
window.update_inset()
|
||||||
|
window.screen.display_scale = scale
|
||||||
|
|
||||||
{.emit:"void* global_glfm_window;".}
|
{.emit:"void* global_glfm_window;".}
|
||||||
var window {.importc:"global_glfm_window".}: Window
|
var window {.importc:"global_glfm_window".}: Window
|
||||||
|
|
|
@ -71,6 +71,7 @@ proc newScreen*(engine: MyouEngine, width, height: int32, title: string): Screen
|
||||||
result.pre_draw = proc(self: Screen) = discard
|
result.pre_draw = proc(self: Screen) = discard
|
||||||
result.post_draw = proc(self: Screen) = discard
|
result.post_draw = proc(self: Screen) = discard
|
||||||
result.frame_interval = 1
|
result.frame_interval = 1
|
||||||
|
result.display_scale = 1.0
|
||||||
|
|
||||||
proc destroy*(self: Screen) =
|
proc destroy*(self: Screen) =
|
||||||
## Destroys the screen/window and all its resources. If you destroy the main
|
## Destroys the screen/window and all its resources. If you destroy the main
|
||||||
|
|
|
@ -841,6 +841,9 @@ type
|
||||||
DebugDraw* = ref object of RootObj
|
DebugDraw* = ref object of RootObj
|
||||||
Body* = ref object
|
Body* = ref object
|
||||||
|
|
||||||
|
FrameInset* = object
|
||||||
|
top*, right*, bottom*, left*: float
|
||||||
|
|
||||||
Screen* = ref object of RootObj
|
Screen* = ref object of RootObj
|
||||||
engine* {.cursor.}: MyouEngine
|
engine* {.cursor.}: MyouEngine
|
||||||
width*, height*: int32
|
width*, height*: int32
|
||||||
|
@ -864,6 +867,8 @@ type
|
||||||
resize_callbacks*: seq[proc(screen: Screen)] ## private
|
resize_callbacks*: seq[proc(screen: Screen)] ## private
|
||||||
platform_event_callbacks*: seq[proc(screen: Screen, e: PlatformEvent)] ## private
|
platform_event_callbacks*: seq[proc(screen: Screen, e: PlatformEvent)] ## private
|
||||||
break_current_callbacks*: bool ## private
|
break_current_callbacks*: bool ## private
|
||||||
|
frame_inset*: FrameInset
|
||||||
|
display_scale*: float
|
||||||
|
|
||||||
PlatformEvent* = enum
|
PlatformEvent* = enum
|
||||||
PlatformPause
|
PlatformPause
|
||||||
|
|
Loading…
Reference in a new issue