From a3c28c00016fb2a2bd13b36e7269c69b0529c6a4 Mon Sep 17 00:00:00 2001 From: jussi Date: Thu, 31 Mar 2022 12:58:50 +0300 Subject: More window related functions. --- src/core.c | 214 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/lua_core.c | 14 ++++ 2 files changed, 228 insertions(+) (limited to 'src') diff --git a/src/core.c b/src/core.c index ef8cfed..8f67c34 100644 --- a/src/core.c +++ b/src/core.c @@ -58,6 +58,84 @@ static inline bool validShader( size_t id ) { ## Core - Window */ +/* +> state = RL_IsWindowReady() + +Check if window has been initialized successfully + +- Success return bool +*/ +int lcoreIsWindowReady( lua_State *L ) { + lua_pushboolean( L, IsWindowReady() ); + + return 1; +} + +/* +> state = RL_IsWindowFullscreen() + +Check if window is currently fullscreen + +- Success return bool +*/ +int lcoreIsWindowFullscreen( lua_State *L ) { + lua_pushboolean( L, IsWindowFullscreen() ); + + return 1; +} + +/* +> state = RL_IsWindowHidden() + +Check if window is currently hidden ( only PLATFORM_DESKTOP ) + +- Success return bool +*/ +int lcoreIsWindowHidden( lua_State *L ) { + lua_pushboolean( L, IsWindowHidden() ); + + return 1; +} + +/* +> state = RL_IsWindowMinimized() + +Check if window is currently minimized ( only PLATFORM_DESKTOP ) + +- Success return bool +*/ +int lcoreIsWindowMinimized( lua_State *L ) { + lua_pushboolean( L, IsWindowMinimized() ); + + return 1; +} + +/* +> state = RL_IsWindowMaximized() + +Check if window is currently maximized ( only PLATFORM_DESKTOP ) + +- Success return bool +*/ +int lcoreIsWindowMaximized( lua_State *L ) { + lua_pushboolean( L, IsWindowMaximized() ); + + return 1; +} + +/* +> state = RL_IsWindowFocused() + +Check if window is currently focused ( only PLATFORM_DESKTOP ) + +- Success return bool +*/ +int lcoreIsWindowFocused( lua_State *L ) { + lua_pushboolean( L, IsWindowFocused() ); + + return 1; +} + /* > success = RL_SetWindowMonitor( int monitor ) @@ -119,6 +197,27 @@ int lcoreSetWindowSize( lua_State *L ) { return 1; } +/* +> success = RL_SetWindowMinSize( Vector2 size ) + +Set window minimum dimensions ( for FLAG_WINDOW_RESIZABLE ) + +- Failure return false +- Success return true +*/ +int lcoreSetWindowMinSize( lua_State *L ) { + if ( !lua_istable( L, -1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_SetWindowMinSize( Vector2 size )" ); + lua_pushboolean( L, false ); + return 1; + } + Vector2 size = uluaGetVector2( L ); + + SetWindowMinSize( (int)size.x, (int)size.y ); + lua_pushboolean( L, true ); + return 1; +} + /* > position = RL_GetMonitorPosition( int monitor ) @@ -313,6 +412,90 @@ int lcoreGetMonitorCount( lua_State *L ) { return 1; } +/* +> monitor = RL_GetCurrentMonitor() + +Get current connected monitor + +- Success return int +*/ +int lcoreGetCurrentMonitor( lua_State *L ) { + lua_pushinteger( L, GetCurrentMonitor() ); + return 1; +} + +/* +> size = RL_GetMonitorPhysicalSize( int monitor ) + +Get specified monitor physical size in millimetres + +- Failure return false +- Success return Vector2 +*/ +int lcoreGetMonitorPhysicalSize( lua_State *L ) { + if ( !lua_isnumber( L, -1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GetMonitorPhysicalSize( int monitor )" ); + lua_pushboolean( L, false ); + return 1; + } + int monitor = lua_tointeger( L, -1 ); + Vector2 size = { GetMonitorPhysicalWidth( monitor ), GetMonitorPhysicalHeight( monitor ) }; + uluaPushVector2( L, size ); + + return 1; +} + +/* +> size = RL_GetMonitorRefreshRate( int monitor ) + +Get specified monitor refresh rate + +- Failure return false +- Success return int +*/ +int lcoreGetMonitorRefreshRate( lua_State *L ) { + if ( !lua_isnumber( L, -1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GetMonitorRefreshRate( int monitor )" ); + lua_pushboolean( L, false ); + return 1; + } + lua_pushinteger( L, GetMonitorRefreshRate( lua_tointeger( L, -1 ) ) ); + + return 1; +} + +/* +> scale = RL_GetWindowScaleDPI() + +Get window scale DPI factor + +- Success return Vector2 +*/ +int lcoreGetWindowScaleDPI( lua_State *L ) { + uluaPushVector2( L, GetWindowScaleDPI() ); + + return 1; +} + +/* +> name = RL_GetMonitorName( int monitor ) + +Get the human-readable, UTF-8 encoded name of the monitor + +- Failure return false +- Success return string +*/ +int lcoreGetMonitorName( lua_State *L ) { + if ( !lua_isnumber( L, -1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GetMonitorName( int monitor )" ); + lua_pushboolean( L, false ); + return 1; + } + lua_pushstring( L, GetMonitorName( lua_tointeger( L, -1 ) ) ); + + return 1; +} + /* > RL_CloseWindow() @@ -324,6 +507,37 @@ int lcoreCloseWindow( lua_State *L ) { return 0; } +/* +> success = RL_SetClipboardText( string text ) + +Set clipboard text content + +- Failure return false +- Success return true +*/ +int lcoreSetClipboardText( lua_State *L ) { + if ( !lua_isstring( L, -1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_SetClipboardText( string text )" ); + lua_pushboolean( L, false ); + return 1; + } + SetClipboardText( lua_tostring( L, -1 ) ); + lua_pushboolean( L, true ); + return 1; +} + +/* +> text = RL_GetClipboardText() + +Get clipboard text content + +- Success return string +*/ +int lcoreGetClipboardText( lua_State *L ) { + lua_pushstring( L, GetClipboardText() ); + return 1; +} + /* ## Core - Timing */ diff --git a/src/lua_core.c b/src/lua_core.c index aeeec9c..4cfbafd 100644 --- a/src/lua_core.c +++ b/src/lua_core.c @@ -472,9 +472,16 @@ void luaRegister() { /* Core. */ /* Window. */ + lua_register( L, "RL_IsWindowReady", lcoreIsWindowReady ); + lua_register( L, "RL_IsWindowFullscreen", lcoreIsWindowFullscreen ); + lua_register( L, "RL_IsWindowHidden", lcoreIsWindowHidden ); + lua_register( L, "RL_IsWindowMinimized", lcoreIsWindowMinimized ); + lua_register( L, "RL_IsWindowMaximized", lcoreIsWindowMaximized ); + lua_register( L, "RL_IsWindowFocused", lcoreIsWindowFocused ); lua_register( L, "RL_SetWindowMonitor", lcoreSetWindowMonitor ); lua_register( L, "RL_SetWindowPosition", lcoreSetWindowPosition ); lua_register( L, "RL_SetWindowSize", lcoreSetWindowSize ); + lua_register( L, "RL_SetWindowMinSize", lcoreSetWindowMinSize ); lua_register( L, "RL_GetMonitorPosition", lcoreGetMonitorPosition ); lua_register( L, "RL_GetMonitorSize", lcoreGetMonitorSize ); lua_register( L, "RL_GetWindowPosition", lcoreGetWindowPosition ); @@ -486,7 +493,14 @@ void luaRegister() { lua_register( L, "RL_SetWindowIcon", lcoreSetWindowIcon ); lua_register( L, "RL_SetWindowTitle", lcoreSetWindowTitle ); lua_register( L, "RL_GetMonitorCount", lcoreGetMonitorCount ); + lua_register( L, "RL_GetCurrentMonitor", lcoreGetCurrentMonitor ); + lua_register( L, "RL_GetMonitorPhysicalSize", lcoreGetMonitorPhysicalSize ); + lua_register( L, "RL_GetMonitorRefreshRate", lcoreGetMonitorRefreshRate ); + lua_register( L, "RL_GetWindowScaleDPI", lcoreGetWindowScaleDPI ); + lua_register( L, "RL_GetMonitorName", lcoreGetMonitorName ); lua_register( L, "RL_CloseWindow", lcoreCloseWindow ); + lua_register( L, "RL_SetClipboardText", lcoreSetClipboardText ); + lua_register( L, "RL_GetClipboardText", lcoreGetClipboardText ); /* Timing. */ lua_register( L, "RL_SetTargetFPS", lcoreSetTargetFPS ); lua_register( L, "RL_GetFrameTime", lcoreGetFrameTime ); -- cgit v1.2.3