From 61c932f2605aac5a8fef4264087e9ea8f86c6760 Mon Sep 17 00:00:00 2001 From: jussi Date: Tue, 2 Jul 2024 20:49:25 +0300 Subject: GetMouseOffset and GetMouseScale. --- examples/resources/lib/boundingBox.lua | 2 +- examples/resources/lib/camera3d.lua | 26 ++++++------ examples/resources/lib/quaternion.lua | 4 +- examples/resources/lib/raygui.lua | 74 +++++++++++++++++----------------- examples/resources/lib/rectangle.lua | 2 +- examples/resources/lib/vector3.lua | 2 +- 6 files changed, 55 insertions(+), 55 deletions(-) (limited to 'examples/resources/lib') 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 = { -- cgit v1.2.3