--[[ A helper allowing to create additional OS windows. Could be used for something like creating a Lua app drawing some widgets or maybe a spectator view on a secondary monitor, or maybe some developer tool. If a function you need is missing, please contact me at . ]] ---@diagnostic disable local oswindow = {} ---Collect information about available monitors. ---Set `rawDimensions = true` in `params` table to get size in physical pixels (usually, it should be in physical pixels regardless, unless AC ---fails to set per-monitor DPI-aware flag). ---@param params nil|{rawDimensions: boolean?} ---@return {position: vec2, size: vec2, name: string, primary: boolean, deviceName: string?, formName: string?}[] function oswindow.monitors(params) return __util.native() end ---Class representing an opened window. Call `:update()` to update its content via a callback, or `:copyFrom()` ---to quickly copy a texture into the window buffer. --- ---After the window is closed, calling all functions but `:close()` and `:closed()` will raise an error. While your ---script is executing, window state won’t change, so make sure to call `:closed()` at the beginning of your function ---to make sure window is still alive. Or, simply set `onClose` callback when creating a window. ---@class oswindow.Window local windowMethods = {} ---Close window. Calling more than once won’t have an effect. function windowMethods:close() self.__release() end ---Check if window is closed. ---@return boolean function windowMethods:closed() return __util.native() end ---Return window size. ---@return vec2 function windowMethods:size() return __util.native() end ---Return window position. ---@return vec2 function windowMethods:position() return __util.native() end ---Return `true` if window is minimized. ---@return boolean function windowMethods:minimized() return __util.native() end ---Return `true` if window is in foreground. ---@return boolean function windowMethods:foreground() return __util.native() end ---Return `true` if window is in borderless fullscreen state. ---@return boolean function windowMethods:fullscreen() return __util.native() end ---Return `true` if window has topmost flag. ---@return boolean function windowMethods:topmost() return __util.native() end ---Return window title. ---@return string function windowMethods:title() return __util.native() end ---Show the window. Window is shown by default when created unless flag `show` is set to `false`. ---@return self function windowMethods:show() __util.native() return self end ---Hide the window. ---@return self function windowMethods:hide() __util.native() return self end ---Change window title. Calling this function too often will cause OS Windows to freeze. ---@return self function windowMethods:setTitle(value) __util.native() return self end ---Set topmost flag. Windows with topmost flag are drawn on top of others. ---@return self function windowMethods:setTopmost(value) __util.native() return self end ---Set window position on the screen. ---@return self function windowMethods:setPosition(value) __util.native() return self end ---Set window size on the screen. Client area size (where you’ll draw things) will be smaller by border thickness. ---@return self function windowMethods:setSize(value) __util.native() return self end ---Set window client area size. Actual window size will be larger by border thickness. ---@return self function windowMethods:setClientSize(value) __util.native() return self end ---Enter or leave bordeless fullscreen mode. When activated, window will expand to cover all the monitors window was present ---on before this function is called, so you might want to call `:setPosition()` and `:setSize()` first to move window to ---the target monitor (or monitors). ---@return self function windowMethods:setFullscreen(value) __util.native() return self end ---Try really hard to get window to show up on top, including some shady tricks. Modern Windows OS ignores regular ---call to activate a window, so we have to be creative. ---@return self function windowMethods:activate() __util.native() return self end ---Update window contents. Callback will be called with a custom IMGUI context for this window, allowing to draw anything ---you need. Window won’t be cleared, so, unless you start by drawing an opaque image (keep in mind that you can use ---`ui.setShadingOffset()` to draw a semi-transparent image as opaque), you might want to first do ---`ui.drawRectFilled(0, ui.windowSize(), rgbm.colors.black)` to clear out the window. --- ---From callback, mouse position and click status corresponds to mouse position within the window. Other mouse buttons, or ---keyboard state, aren’t available at the moment. ---@return self function windowMethods:update(callback) __util.native() return self end ---Clear out window contents. ---@return self function windowMethods:clear(color) __util.native() return self end ---Fill out the window using a texture, an icon or something like that. ---@return self function windowMethods:copyFrom(source) __util.native() return self end local windowMt = {__index = windowMethods} ---Create a new OS window. By default, created in windowed state and shown automatically. Call `:update()` or `:copyFrom()` ---on created window to draw things into it. Window stays open until scripts unloads, or until `:close()` is called. --- ---Available parameters: ---- `title: string?`: window title. Default value: `'Assetto Corsa'`; ---- `position: vec2?`: window position. Default value: `vec2(200, 200)`; ---- `size: vec2?`: window size. Default value: `vec2(640, 480)`; ---- `show: boolean?`: set to `false` to stop window from being shown by default. Default value: `true`; ---- `fullscreen: boolean?`: set to `true` to switch to borderless fullscreen by default. Default value: `false`; ---- `onResize`: callback to be called when window size changes; ---- `onClosing`: callback to be called while window is closing. From within, window methods are available. Return `true` to prevent window from closing; ---- `onClose`: callback to be called when window has closed. From within, no window method is available anymore. ---@param params {title: string?, position: vec2?, size: vec2?, show: boolean?, fullscreen: boolean?, onResize: (fun(newSize: vec2)?), onClosing: (fun(): boolean?), onClose: fun()} ---@return oswindow.Window function oswindow.Window(params) local release, key = __util.native() return setmetatable({__release = release, __key = key}, windowMt) end return oswindow