diff options
| -rw-r--r-- | API.md | 16 | ||||
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | ReiLua_API.lua | 10 | ||||
| -rw-r--r-- | changelog | 1 | ||||
| -rw-r--r-- | examples/resources/lib/boundingBox.lua | 2 | ||||
| -rw-r--r-- | examples/resources/lib/camera3d.lua | 26 | ||||
| -rw-r--r-- | examples/resources/lib/quaternion.lua | 4 | ||||
| -rw-r--r-- | examples/resources/lib/raygui.lua | 74 | ||||
| -rw-r--r-- | examples/resources/lib/rectangle.lua | 2 | ||||
| -rw-r--r-- | examples/resources/lib/vector3.lua | 2 | ||||
| -rw-r--r-- | include/core.h | 2 | ||||
| -rw-r--r-- | include/state.h | 2 | ||||
| -rw-r--r-- | src/core.c | 28 | ||||
| -rw-r--r-- | src/lua_core.c | 2 | ||||
| -rw-r--r-- | src/rgui.c | 2 | ||||
| -rw-r--r-- | src/state.c | 2 |
16 files changed, 121 insertions, 56 deletions
@@ -5066,6 +5066,22 @@ Set mouse scaling --- +> offset = RL.GetMouseOffset() + +Get mouse offset + +- Success return Vector2 + +--- + +> scale = RL.GetMouseScale() + +Get mouse scale + +- Success return Vector2 + +--- + > movement = RL.GetMouseWheelMove() Get mouse wheel movement for X or Y, whichever is larger @@ -31,6 +31,8 @@ List of some MISSING features that are planned to be included. For specific func * v0.8 * Thorough search for any missing raylib functions that should get implemented. +* v0.9 + * Move to raylib 5.5. ## Usage diff --git a/ReiLua_API.lua b/ReiLua_API.lua index 27acb0f..dd7980d 100644 --- a/ReiLua_API.lua +++ b/ReiLua_API.lua @@ -2309,6 +2309,16 @@ function RL.SetMouseOffset( offset ) end ---@return any RL.SetMouseScale function RL.SetMouseScale( scale ) end +---Get mouse offset +---- Success return Vector2 +---@return any offset +function RL.GetMouseOffset() end + +---Get mouse scale +---- Success return Vector2 +---@return any scale +function RL.GetMouseScale() end + ---Get mouse wheel movement for X or Y, whichever is larger ---- Success return float ---@return any movement @@ -60,6 +60,7 @@ DETAILED CHANGES: - CHANGE: Naming of gui functions set2Top and set2Back to setToTop and setToBack. - FIXED: GuiGetIcons was returning just first int. Now returns a Buffer. - ADDED: GuiSetIcons. + - ADDED: GetMouseOffset and GetMouseScale. ------------------------------------------------------------------------ Release: ReiLua version 0.7.0 Using Raylib 5.0 and Forked Raygui 4.0 diff --git a/examples/resources/lib/boundingBox.lua b/examples/resources/lib/boundingBox.lua index da79875..cc29fab 100644 --- a/examples/resources/lib/boundingBox.lua +++ b/examples/resources/lib/boundingBox.lua @@ -3,7 +3,7 @@ if table.unpack == nil then table.unpack = unpack end -local Vector3 = require( "vector3" ) +local Vector3 = Vector3 or require( "vector3" ) local BoundingBox = {} local metatable = { diff --git a/examples/resources/lib/camera3d.lua b/examples/resources/lib/camera3d.lua index 8c15fa7..6acb78b 100644 --- a/examples/resources/lib/camera3d.lua +++ b/examples/resources/lib/camera3d.lua @@ -1,5 +1,5 @@ -local Vec2 = require( "vector2" ) -local Vec3 = require( "vector3" ) +local Vector2 = Vector2 or require( "vector2" ) +local Vector3 = Vector3 or require( "vector3" ) Camera3D = {} Camera3D.meta = { @@ -62,15 +62,15 @@ function Camera3D:setProjection( projection ) end function Camera3D:getPosition() - return Vec3:newT( RL.GetCamera3DPosition( self.camera ) ) + return Vector3:newT( RL.GetCamera3DPosition( self.camera ) ) end function Camera3D:getTarget() - return Vec3:newT( RL.GetCamera3DTarget( self.camera ) ) + return Vector3:newT( RL.GetCamera3DTarget( self.camera ) ) end function Camera3D:getUp() - return Vec3:newT( RL.GetCamera3DUp( self.camera ) ) + return Vector3:newT( RL.GetCamera3DUp( self.camera ) ) end function Camera3D:getFoyv() @@ -83,12 +83,12 @@ end --- Returns the cameras forward vector ( normalized ) function Camera3D:getForward() - return Vec3:newT( RL.GetCamera3DForward( self.camera ) ) + return Vector3:newT( RL.GetCamera3DForward( self.camera ) ) end --- Returns the cameras up vector ( normalized ) Note: The up vector might not be perpendicular to the forward vector function Camera3D:getUpward() - return Vec3:newT( RL.GetCamera3DUpNormalized( self.camera ) ) + return Vector3:newT( RL.GetCamera3DUpNormalized( self.camera ) ) end function Camera3D:update( delta ) @@ -96,7 +96,7 @@ function Camera3D:update( delta ) if self.mode == self.MODES.FREE then if RL.IsMouseButtonDown( RL.MOUSE_BUTTON_MIDDLE ) then - local mouseDelta = Vec2:newT( RL.GetMouseDelta() ) + local mouseDelta = Vector2:newT( RL.GetMouseDelta() ) if RL.IsKeyDown( self.KEYS.PAN ) then mouseDelta = mouseDelta:scale( self.MOUSE_MOVE_SPEED * delta ) @@ -119,13 +119,13 @@ function Camera3D:update( delta ) RL.Camera3DMoveToTarget( self.camera, self.ZOOM_AMOUNT * self:getTargetDistance() * -mouseScroll ) end elseif self.mode == self.MODES.FIRST_PERSON then - local mouseDelta = Vec2:newT( RL.GetMouseDelta() ) + local mouseDelta = Vector2:newT( RL.GetMouseDelta() ) mouseDelta = mouseDelta:scale( self.TURN_SPEED * delta ) RL.Camera3DYaw( self.camera, -mouseDelta.x, false ) RL.Camera3DPitch( self.camera, -mouseDelta.y, false, false, false ) - RL.SetMousePosition( Vec2:newT( RL.GetScreenSize() ):scale( 0.5 ) ) + RL.SetMousePosition( Vector2:newT( RL.GetScreenSize() ):scale( 0.5 ) ) local distance = self.KEYBOARD_MOVE_SPEED * delta local forward = RL.GetCamera3DForward( self.camera )[2] @@ -162,9 +162,9 @@ end function Camera3D:draw() local targetPos = self:getTarget() - RL.DrawLine3D( targetPos + Vec3:new( -0.5, 0, 0 ), targetPos + Vec3:new( 0.5, 0, 0 ), RL.GREEN ) - RL.DrawLine3D( targetPos + Vec3:new( 0, -0.5, 0 ), targetPos + Vec3:new( 0, 0.5, 0 ), RL.BLUE ) - RL.DrawLine3D( targetPos + Vec3:new( 0, 0, -0.5 ), targetPos + Vec3:new( 0, 0, 0.5 ), RL.RED ) + RL.DrawLine3D( targetPos + Vector3:new( -0.5, 0, 0 ), targetPos + Vector3:new( 0.5, 0, 0 ), RL.GREEN ) + RL.DrawLine3D( targetPos + Vector3:new( 0, -0.5, 0 ), targetPos + Vector3:new( 0, 0.5, 0 ), RL.BLUE ) + RL.DrawLine3D( targetPos + Vector3:new( 0, 0, -0.5 ), targetPos + Vector3:new( 0, 0, 0.5 ), RL.RED ) end function Camera3D:getTargetDistance() diff --git a/examples/resources/lib/quaternion.lua b/examples/resources/lib/quaternion.lua index b91f474..92261ff 100644 --- a/examples/resources/lib/quaternion.lua +++ b/examples/resources/lib/quaternion.lua @@ -3,8 +3,8 @@ if table.unpack == nil then table.unpack = unpack end -local Vector3 = require( "vector3" ) -local Matrix = require( "matrix" ) +local Vector3 = Vector3 or require( "vector3" ) +local Matrix = Matrix or require( "matrix" ) local Quaternion = {} local metatable = { diff --git a/examples/resources/lib/raygui.lua b/examples/resources/lib/raygui.lua index 437bc96..d0cf039 100644 --- a/examples/resources/lib/raygui.lua +++ b/examples/resources/lib/raygui.lua @@ -1,9 +1,9 @@ -- Wrapper for raygui. -local Util = require( "utillib" ) -local Rect = require( "rectangle" ) -local Vec2 = require( "vector2" ) -local Color = require( "color" ) +local Util = Util or require( "utillib" ) +local Rectangle = Rectangle or require( "rectangle" ) +local Vector2 = Vector2 or require( "vector2" ) +local Color = Color or require( "color" ) local function getItemCount( text ) local count, rowItemCounts = 1, { 1 } @@ -259,7 +259,7 @@ function ScrollPanel:new( bounds, text, content, scroll, callbacks, styles, tool object.text = text object.content = content:clone() object.scroll = scroll:clone() - object.view = Rect:new( 0, 0, 0, 0 ) + object.view = Rectangle:new( 0, 0, 0, 0 ) object.callbacks = callbacks -- scroll, grab, drag. object.visible = true @@ -507,8 +507,8 @@ function ToggleGroup:updateFocusBounds() for y, rowItemCount in ipairs( rowItemCounts ) do for x = 1, rowItemCount do - local pos = Vec2:new( x - 1, y - 1 ) - local focusBound = Rect:new( + local pos = Vector2:new( x - 1, y - 1 ) + local focusBound = Rectangle:new( self.bounds.x + pos.x * ( self.bounds.width + RL.GuiGetStyle( RL.TOGGLE, RL.GROUP_PADDING ) ), self.bounds.y + pos.y * ( self.bounds.height + RL.GuiGetStyle( RL.TOGGLE, RL.GROUP_PADDING ) ), self.bounds.width, @@ -581,10 +581,10 @@ function CheckBox:new( bounds, text, checked, callbacks, styles, tooltip ) object.visible = true object.disabled = false - object.textBounds = Rect:new( 0, 0, 0, 0 ) + object.textBounds = Rectangle:new( 0, 0, 0, 0 ) object.focusBounds = bounds:clone() - object._focusBoundsOffset = Vec2:new( 0, 0 ) -- Used in set position. + object._focusBoundsOffset = Vector2:new( 0, 0 ) -- Used in set position. object.styles = styles object.tooltip = tooltip @@ -758,10 +758,10 @@ function Spinner:new( bounds, text, value, minValue, maxValue, editMode, callbac object.visible = true object.disabled = false - object.textBounds = Rect:new( 0, 0, 0, 0 ) + object.textBounds = Rectangle:new( 0, 0, 0, 0 ) object.viewBounds = bounds:clone() - object._viewBoundsOffset = Vec2:new( 0, 0 ) + object._viewBoundsOffset = Vector2:new( 0, 0 ) object.styles = styles object.tooltip = tooltip @@ -829,10 +829,10 @@ function ValueBox:new( bounds, text, value, minValue, maxValue, editMode, callba object.visible = true object.disabled = false - object.textBounds = Rect:new( 0, 0, 0, 0 ) + object.textBounds = Rectangle:new( 0, 0, 0, 0 ) object.viewBounds = bounds:clone() - object._viewBoundsOffset = Vec2:new( 0, 0 ) + object._viewBoundsOffset = Vector2:new( 0, 0 ) object.styles = styles object.tooltip = tooltip @@ -949,11 +949,11 @@ function Slider:new( bounds, textLeft, textRight, value, minValue, maxValue, cal object.visible = true object.disabled = false - object.textLeftBounds = Rect:new( 0, 0, 0, 0 ) - object.textRightBounds = Rect:new( 0, 0, 0, 0 ) + object.textLeftBounds = Rectangle:new( 0, 0, 0, 0 ) + object.textRightBounds = Rectangle:new( 0, 0, 0, 0 ) object.viewBounds = bounds:clone() - object._viewBoundsOffset = Vec2:new( 0, 0 ) + object._viewBoundsOffset = Vector2:new( 0, 0 ) object.styles = styles object.tooltip = tooltip @@ -1013,11 +1013,11 @@ function SliderBar:new( bounds, textLeft, textRight, value, minValue, maxValue, object.visible = true object.disabled = false - object.textLeftBounds = Rect:new( 0, 0, 0, 0 ) - object.textRightBounds = Rect:new( 0, 0, 0, 0 ) + object.textLeftBounds = Rectangle:new( 0, 0, 0, 0 ) + object.textRightBounds = Rectangle:new( 0, 0, 0, 0 ) object.viewBounds = bounds:clone() - object._viewBoundsOffset = Vec2:new( 0, 0 ) + object._viewBoundsOffset = Vector2:new( 0, 0 ) object.styles = styles object.tooltip = tooltip @@ -1077,11 +1077,11 @@ function ProgressBar:new( bounds, textLeft, textRight, value, minValue, maxValue object.visible = true object.disabled = false - object.textLeftBounds = Rect:new( 0, 0, 0, 0 ) - object.textRightBounds = Rect:new( 0, 0, 0, 0 ) + object.textLeftBounds = Rectangle:new( 0, 0, 0, 0 ) + object.textRightBounds = Rectangle:new( 0, 0, 0, 0 ) object.viewBounds = bounds:clone() - object._viewBoundsOffset = Vec2:new( 0, 0 ) + object._viewBoundsOffset = Vector2:new( 0, 0 ) object.styles = styles object.tooltip = tooltip @@ -1204,7 +1204,7 @@ function Grid:new( bounds, text, spacing, subdivs, callbacks, styles, tooltip ) object.subdivs = subdivs object.callbacks = callbacks -- cellChange. - object.mouseCell = Vec2:new( 0, 0 ) + object.mouseCell = Vector2:new( 0, 0 ) object.visible = true object.disabled = false object.styles = styles @@ -1455,7 +1455,7 @@ function ColorPicker:new( bounds, text, color, callbacks, styles, tooltip ) object.visible = true object.disabled = false - object.focusBounds = Rect:new( 0, 0, 0, 0 ) + object.focusBounds = Rectangle:new( 0, 0, 0, 0 ) object.styles = styles object.tooltip = tooltip @@ -1470,7 +1470,7 @@ function ColorPicker:update() end function ColorPicker:updateFocusBounds() - local boundsHue = Rect:new( + local boundsHue = Rectangle:new( self.bounds.x + self.bounds.width + RL.GuiGetStyle( RL.COLORPICKER, RL.HUEBAR_PADDING ), self.bounds.y, RL.GuiGetStyle( RL.COLORPICKER, RL.HUEBAR_WIDTH ), @@ -1718,25 +1718,25 @@ function Raygui:new() object.controls = {} object.focused = 0 object.dragging = nil - object.grabPos = Vec2:new( 0, 0 ) + object.grabPos = Vector2:new( 0, 0 ) object.scrolling = false object.textEdit = false object.textEditControl = nil object.defaultTexture = RL.GetTextureDefault() - object.defaultRect = Rect:new( 0, 0, 1, 1 ) -- For texture. + object.defaultRect = Rectangle:new( 0, 0, 1, 1 ) -- For texture. object.defaultFont = RL.GuiGetFont() - object.mouseOffset = Vec2:new( 0, 0 ) - object.view = Rect:new( 0, 0, 0, 0 ) -- Active if larger than 0. Then only controls in view will be updated and drawn. + object.mouseOffset = Vector2:new( 0, 0 ) + object.view = Rectangle:new( 0, 0, 0, 0 ) -- Active if larger than 0. Then only controls in view will be updated and drawn. object.tooltip = { text = nil, - offset = Vec2:new( 12, 24 ), + offset = Vector2:new( 12, 24 ), delay = 0.5, timer = 0.0, focused = 0 } object._lastProperties = {} - object._mousePressPos = Vec2:new( -1, -1 ) -- Use to check if release and check are inside bounds. + object._mousePressPos = Vector2:new( -1, -1 ) -- Use to check if release and check are inside bounds. return object end @@ -1784,7 +1784,7 @@ function Raygui:update() self.tooltip.timer = self.tooltip.timer + RL.GetFrameTime() else self.tooltip.text = control.tooltip - self.tooltip.position = Vec2:newT( RL.GetMousePosition() ) + self.tooltip.offset + self.tooltip.position = Vector2:newT( RL.GetMousePosition() ) + self.tooltip.offset end end @@ -1802,12 +1802,12 @@ function Raygui:update() end function Raygui:drag( control ) - local mousePos = Vec2:tempT( RL.GetMousePosition() ) + local mousePos = Vector2:tempT( RL.GetMousePosition() ) local mouseOver = RL.CheckCollisionPointRec( mousePos, control.bounds ) if not control.disabled and control.draggable and control ~= self.dragging and RL.IsMouseButtonPressed( RL.MOUSE_BUTTON_LEFT ) and mouseOver and mousePos.y - control.bounds.y <= self.RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT then - self.grabPos = mousePos - Vec2:temp( control.bounds.x, control.bounds.y ) + self.grabPos = mousePos - Vector2:temp( control.bounds.x, control.bounds.y ) if control.callbacks.grab ~= nil then control.callbacks.grab( control ) @@ -1843,17 +1843,17 @@ function Raygui:_addLastProperty( property ) end function Raygui:drawTooltip() - local textSize = Vec2:tempT( RL.MeasureTextEx( + local textSize = Vector2:tempT( RL.MeasureTextEx( self.defaultFont, self.tooltip.text, RL.GuiGetStyle( RL.DEFAULT, RL.TEXT_SIZE ), RL.GuiGetStyle( RL.DEFAULT, RL.TEXT_SPACING ) ) ) - local tooltipRect = Rect:new( self.tooltip.position.x, self.tooltip.position.y, textSize.x, textSize.y ) + local tooltipRect = Rectangle:new( self.tooltip.position.x, self.tooltip.position.y, textSize.x, textSize.y ) local view = self.view:clone() -- If no view size, clamp to window size. if view.width == 0 or view.height == 0 then - local screenSize = Vec2:tempT( RL.GetScreenSize() ) + local screenSize = Vector2:tempT( RL.GetScreenSize() ) view.width = screenSize.x view.height = screenSize.y end diff --git a/examples/resources/lib/rectangle.lua b/examples/resources/lib/rectangle.lua index 5fc6c63..3de80e4 100644 --- a/examples/resources/lib/rectangle.lua +++ b/examples/resources/lib/rectangle.lua @@ -3,7 +3,7 @@ if table.unpack == nil then table.unpack = unpack end -local Vector2 = require( "vector2" ) +local Vector2 = Vector2 or require( "vector2" ) local Rectangle = {} local metatable = { diff --git a/examples/resources/lib/vector3.lua b/examples/resources/lib/vector3.lua index 216962e..3706017 100644 --- a/examples/resources/lib/vector3.lua +++ b/examples/resources/lib/vector3.lua @@ -3,7 +3,7 @@ if table.unpack == nil then table.unpack = unpack end -local Vector2 = require( "vector2" ) +local Vector2 = Vector2 or require( "vector2" ) local Vector3 = {} local metatable = { diff --git a/include/core.h b/include/core.h index d72fdb9..14b2630 100644 --- a/include/core.h +++ b/include/core.h @@ -193,6 +193,8 @@ int lcoreGetMouseDelta( lua_State* L ); int lcoreSetMousePosition( lua_State* L ); int lcoreSetMouseOffset( lua_State* L ); int lcoreSetMouseScale( lua_State* L ); +int lcoreGetMouseOffset( lua_State* L ); +int lcoreGetMouseScale( lua_State* L ); int lcoreGetMouseWheelMove( lua_State* L ); int lcoreGetMouseWheelMoveV( lua_State* L ); int lcoreSetMouseCursor( lua_State* L ); diff --git a/include/state.h b/include/state.h index 92ed132..8168535 100644 --- a/include/state.h +++ b/include/state.h @@ -10,6 +10,8 @@ typedef struct { bool run; bool gcUnload; int lineSpacing; /* We need to store copy here since raylib has it in static. */ + Vector2 mouseOffset; + Vector2 mouseScale; lua_State* luaState; Vector2 resolution; int logLevelInvalid; @@ -2585,6 +2585,7 @@ int lcoreSetMouseOffset( lua_State* L ) { Vector2 offset = uluaGetVector2( L, 1 ); SetMouseOffset( offset.x, offset.y ); + state->mouseOffset = offset; return 0; } @@ -2598,11 +2599,38 @@ int lcoreSetMouseScale( lua_State* L ) { Vector2 scale = uluaGetVector2( L, 1 ); SetMouseScale( scale.x, scale.y ); + state->mouseScale = scale; return 0; } /* +> offset = RL.GetMouseOffset() + +Get mouse offset + +- Success return Vector2 +*/ +int lcoreGetMouseOffset( lua_State* L ) { + uluaPushVector2( L, state->mouseOffset ); + + return 1; +} + +/* +> scale = RL.GetMouseScale() + +Get mouse scale + +- Success return Vector2 +*/ +int lcoreGetMouseScale( lua_State* L ) { + uluaPushVector2( L, state->mouseScale ); + + return 1; +} + +/* > movement = RL.GetMouseWheelMove() Get mouse wheel movement for X or Y, whichever is larger diff --git a/src/lua_core.c b/src/lua_core.c index e7356e9..0955f77 100644 --- a/src/lua_core.c +++ b/src/lua_core.c @@ -1455,6 +1455,8 @@ void luaRegister() { assingGlobalFunction( "SetMousePosition", lcoreSetMousePosition ); assingGlobalFunction( "SetMouseOffset", lcoreSetMouseOffset ); assingGlobalFunction( "SetMouseScale", lcoreSetMouseScale ); + assingGlobalFunction( "GetMouseOffset", lcoreGetMouseOffset ); + assingGlobalFunction( "GetMouseScale", lcoreGetMouseScale ); assingGlobalFunction( "GetMouseWheelMove", lcoreGetMouseWheelMove ); assingGlobalFunction( "GetMouseWheelMoveV", lcoreGetMouseWheelMoveV ); assingGlobalFunction( "SetMouseCursor", lcoreSetMouseCursor ); @@ -303,7 +303,7 @@ int lguiGuiGetIcons( lua_State* L ) { }; memcpy( buffer.data, GuiGetIcons(), dataSize ); - uluaPushBuffer( L, buffer ); + uluaPushBuffer( L, buffer ); return 1; } diff --git a/src/state.c b/src/state.c index c17f3f0..0fed44e 100644 --- a/src/state.c +++ b/src/state.c @@ -19,6 +19,8 @@ bool stateInit( int argn, const char** argc, const char* basePath ) { state->logLevelInvalid = LOG_ERROR; state->gcUnload = true; state->lineSpacing = 15; + state->mouseOffset = (Vector2){ 0, 0 }; + state->mouseScale = (Vector2){ 1, 1 }; InitWindow( state->resolution.x, state->resolution.y, "ReiLua" ); |
