lua: create type defs for Window and start on Vec2
This commit is contained in:
parent
a2c52a0bb8
commit
de14b6211b
|
@ -1,4 +1,6 @@
|
||||||
HAS_SETUP_WINDOW = false
|
--local win = require "scripts.window"
|
||||||
|
|
||||||
|
local is_window_setup = false
|
||||||
|
|
||||||
---Return the userdata's name from its metatable.
|
---Return the userdata's name from its metatable.
|
||||||
---
|
---
|
||||||
|
@ -31,14 +33,16 @@ function on_init()
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_first()
|
function on_first()
|
||||||
if not HAS_SETUP_WINDOW then
|
if not is_window_setup then
|
||||||
world:view(function (w)
|
world:view(
|
||||||
|
---@param w Window
|
||||||
|
function (w)
|
||||||
if w.cursor_grab == CursorGrabMode.NONE then
|
if w.cursor_grab == CursorGrabMode.NONE then
|
||||||
w.cursor_grab = CursorGrabMode.LOCKED
|
w.cursor_grab = CursorGrabMode.LOCKED
|
||||||
w.cursor_visible = false
|
w.cursor_visible = false
|
||||||
return w
|
return w
|
||||||
else
|
else
|
||||||
HAS_SETUP_WINDOW = true
|
is_window_setup = true
|
||||||
print("Window setup")
|
print("Window setup")
|
||||||
end
|
end
|
||||||
end, Window)
|
end, Window)
|
||||||
|
|
|
@ -0,0 +1,126 @@
|
||||||
|
---@class Window
|
||||||
|
Window = {
|
||||||
|
---Gets or sets the window's focus.
|
||||||
|
---@type boolean
|
||||||
|
focused = nil,
|
||||||
|
---Gets or sets the window mode.
|
||||||
|
---@type WindowMode
|
||||||
|
window_mode = nil,
|
||||||
|
---Gets or sets the position of the top-left corner of the window.
|
||||||
|
---
|
||||||
|
---The top-left hand corner of the desktop is not necessarily the same
|
||||||
|
---as the screen. If the user uses a desktop with multiple monitors, the top-left
|
||||||
|
---hand corner of the desktop is the top-left hand corner of the monitor at the
|
||||||
|
---top-left of the desktop.
|
||||||
|
---
|
||||||
|
---If this is `nil`, the position will be chosen by the windowing manager at creation,
|
||||||
|
---then set when the window is created.
|
||||||
|
---
|
||||||
|
---@type Vec2?
|
||||||
|
position = nil,
|
||||||
|
---@type Vec2
|
||||||
|
physical_size = nil,
|
||||||
|
---@type Vec2
|
||||||
|
size = nil,
|
||||||
|
---Gets/sets if the window has decorations.
|
||||||
|
---@type boolean
|
||||||
|
decorated = nil,
|
||||||
|
---Gets/sets the window's current maximized state.
|
||||||
|
---@type boolean
|
||||||
|
maximized = nil,
|
||||||
|
---Gets/sets the window's current minimized state.
|
||||||
|
---
|
||||||
|
---Is `nil` if the minimized state could not be determined.
|
||||||
|
---
|
||||||
|
---@type boolean?
|
||||||
|
minimized = nil,
|
||||||
|
---Gets/sets the window's current resizable state
|
||||||
|
---@type boolean
|
||||||
|
resizable = nil,
|
||||||
|
---Gets/sets the window's current visibility state.
|
||||||
|
---
|
||||||
|
---Is `nil` when it could not be determined.
|
||||||
|
---
|
||||||
|
---@type boolean?
|
||||||
|
visible = nil,
|
||||||
|
|
||||||
|
--TODO: resize_increments
|
||||||
|
|
||||||
|
---Gets the scale factor.
|
||||||
|
---
|
||||||
|
---You cannot set this field.
|
||||||
|
---
|
||||||
|
---@type number
|
||||||
|
scale_factor = nil,
|
||||||
|
---Gets/sets the window's blur state.
|
||||||
|
---@type boolean
|
||||||
|
blur = nil,
|
||||||
|
|
||||||
|
--TODO: cursor appearance
|
||||||
|
|
||||||
|
---Gets/sets the window's cursor grab mode.
|
||||||
|
---@type CursorGrabMode
|
||||||
|
cursor_grab = nil,
|
||||||
|
---Gets/sets whether the window catches cursor events.
|
||||||
|
---@type boolean
|
||||||
|
cursor_hittest = nil,
|
||||||
|
---Gets/sets the cursor's visibility.
|
||||||
|
---@type boolean
|
||||||
|
cursor_visible = nil,
|
||||||
|
---Sets whether the window should get IME events.
|
||||||
|
---
|
||||||
|
---When IME is allowed, the window will receive Ime events, and during the preedit phase
|
||||||
|
---the window will NOT get KeyboardInput events. The window should allow IME while
|
||||||
|
---it is expecting text input.
|
||||||
|
---
|
||||||
|
---When IME is not allowed, the window won’t receive window ime events, and will receive
|
||||||
|
---KeyboardInput events for every keypress instead. Not allowing IME is useful for games
|
||||||
|
---for example. IME is not allowed by default.
|
||||||
|
---
|
||||||
|
---@type boolean
|
||||||
|
ime_allowed = nil,
|
||||||
|
---Gets/sets the minimum size of the window.
|
||||||
|
---@type Vec2?
|
||||||
|
min_size = nil,
|
||||||
|
---Gets/sets the maximum size of the window.
|
||||||
|
---@type Vec2?
|
||||||
|
max_size = nil,
|
||||||
|
---Gets/sets the current window theme.
|
||||||
|
---
|
||||||
|
---Specify `nil` to reset the theme to the system default. May also be `nil` on
|
||||||
|
---unsupported platforms.
|
||||||
|
---
|
||||||
|
---@type WindowTheme?
|
||||||
|
theme = nil,
|
||||||
|
---Gets/sets the title of the window.
|
||||||
|
---@type string
|
||||||
|
title = nil,
|
||||||
|
---Gets/sets the window's transparency state.
|
||||||
|
---@type boolean
|
||||||
|
transparent = nil,
|
||||||
|
|
||||||
|
--TODO: window_icon
|
||||||
|
|
||||||
|
---Change the window level.
|
||||||
|
---@type WindowLevel
|
||||||
|
window_level = nil,
|
||||||
|
---Gets the window's occluded state (completely hidden from view).
|
||||||
|
---@type boolean
|
||||||
|
occluded = nil,
|
||||||
|
---Gets/sets the cursor position in the window in logical coordinates.
|
||||||
|
---
|
||||||
|
---The value is `nil` when the cursor is not in the window.
|
||||||
|
---
|
||||||
|
---@type Vec2?
|
||||||
|
cursor_position = nil,
|
||||||
|
---Gets/sets the cursor position in the window in physical coordinates.
|
||||||
|
---
|
||||||
|
---The value is `nil` when the cursor is not in the window.
|
||||||
|
---
|
||||||
|
---@type Vec2?
|
||||||
|
physical_cursor_position = nil,
|
||||||
|
---Checks if the mouse is inside the window
|
||||||
|
---@param self Window
|
||||||
|
---@return boolean
|
||||||
|
is_mouse_inside = function (self) return false end,
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
require "math.vec2"
|
||||||
|
|
||||||
|
require "ecs.window"
|
|
@ -0,0 +1,14 @@
|
||||||
|
---@class Vec2
|
||||||
|
Vec2 = {
|
||||||
|
---The x coordinate
|
||||||
|
---@type number
|
||||||
|
x = nil,
|
||||||
|
---The y coordinate
|
||||||
|
---@type number
|
||||||
|
y = nil,
|
||||||
|
|
||||||
|
---Create a new `Vec2`
|
||||||
|
---@param x number
|
||||||
|
---@param y number
|
||||||
|
new = function (x, y) end
|
||||||
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
|
---@enum WindowMode
|
||||||
WindowMode = {
|
WindowMode = {
|
||||||
WNDOWED = "windowed",
|
WNDOWED = "windowed",
|
||||||
BORDERLESS_FULLSCREEN = "borderless_fullscreen",
|
BORDERLESS_FULLSCREEN = "borderless_fullscreen",
|
||||||
|
@ -5,17 +6,20 @@ WindowMode = {
|
||||||
FULLSCREEN = "fullscreen",
|
FULLSCREEN = "fullscreen",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
---@enum CursorGrabMode
|
||||||
CursorGrabMode = {
|
CursorGrabMode = {
|
||||||
NONE = "none",
|
NONE = "none",
|
||||||
CONFINED = "confined",
|
CONFINED = "confined",
|
||||||
LOCKED = "locked",
|
LOCKED = "locked",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
---@enum WindowTheme
|
||||||
WindowTheme = {
|
WindowTheme = {
|
||||||
LIGHT = "light",
|
LIGHT = "light",
|
||||||
DARK = "dark",
|
DARK = "dark",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
---@enum WindowLevel
|
||||||
WindowLevel = {
|
WindowLevel = {
|
||||||
ALWAYS_ON_BOTTOM = "always_on_bottom",
|
ALWAYS_ON_BOTTOM = "always_on_bottom",
|
||||||
NORMAL = "normal",
|
NORMAL = "normal",
|
||||||
|
|
|
@ -135,10 +135,6 @@ wrap_lua_struct!(
|
||||||
fields.add_field_method_get("scale_factor", |lua, this| {
|
fields.add_field_method_get("scale_factor", |lua, this| {
|
||||||
this.scale_factor.into_lua(lua)
|
this.scale_factor.into_lua(lua)
|
||||||
});
|
});
|
||||||
fields.add_field_method_set("scale_factor", |_, this, val: f64| {
|
|
||||||
this.scale_factor = val;
|
|
||||||
Ok(())
|
|
||||||
});
|
|
||||||
|
|
||||||
fields.add_field_method_get("blur", |lua, this| {
|
fields.add_field_method_get("blur", |lua, this| {
|
||||||
this.blur.into_lua(lua)
|
this.blur.into_lua(lua)
|
||||||
|
|
Loading…
Reference in New Issue