Raygui update.
This commit is contained in:
@@ -42,6 +42,8 @@ local function addButton( bounds, text, callback )
|
||||
{ RL.LABEL, RL.TEXT_COLOR_NORMAL, RL.ColorToInt( { 84, 59, 22 } ) },
|
||||
{ RL.LABEL, RL.TEXT_COLOR_PRESSED, RL.ColorToInt( { 84/2, 59/2, 22/2 } ) },
|
||||
{ RL.LABEL, RL.TEXT_COLOR_FOCUSED, RL.ColorToInt( RL.GREEN ) },
|
||||
{ RL.BUTTON, RL.BASE_COLOR_PRESSED, RL.ColorToInt( RL.WHITE ) },
|
||||
{ RL.BUTTON, RL.BASE_COLOR_NORMAL, RL.ColorToInt( RL.WHITE ) },
|
||||
},
|
||||
},
|
||||
text
|
||||
@@ -324,7 +326,7 @@ function RL.init()
|
||||
end
|
||||
|
||||
function RL.update( delta )
|
||||
Gui:update()
|
||||
Gui:update( delta )
|
||||
end
|
||||
|
||||
function RL.draw()
|
||||
|
||||
@@ -2,18 +2,18 @@ local PropertyList = {}
|
||||
PropertyList.__index = PropertyList
|
||||
|
||||
function PropertyList:new( bounds, text, callbacks, styles, tooltip )
|
||||
local object = setmetatable( {}, self )
|
||||
local object = setmetatable( {}, self )
|
||||
object._gui = nil
|
||||
|
||||
object.padding = 4 -- Content edges.
|
||||
object.spacing = 4 -- Between controls.
|
||||
object.contentPadding = Vector2:new( 0, 0 ) -- Extra padding for content rect.
|
||||
|
||||
object.bounds = bounds:clone()
|
||||
object.text = text
|
||||
object.scroll = Vector2:new( 0, 0 )
|
||||
object.bounds = bounds:clone()
|
||||
object.text = text
|
||||
object.scroll = Vector2:new( 0, 0 )
|
||||
object.view = Rectangle:new( 0, 0, 0, 0 )
|
||||
object.callbacks = callbacks -- scroll, grab, drag.
|
||||
object.callbacks = callbacks -- scroll, grab, drag.
|
||||
object.styles = styles
|
||||
object.tooltip = tooltip
|
||||
|
||||
@@ -31,7 +31,6 @@ function PropertyList:new( bounds, text, callbacks, styles, tooltip )
|
||||
|
||||
object:setSize( Vector2:new( object.bounds.width, object.bounds.height ) )
|
||||
|
||||
object._forceCheckScroll = false
|
||||
object._posY = 0 -- In control list update.
|
||||
|
||||
object:updateMouseOffset()
|
||||
@@ -103,7 +102,7 @@ function PropertyList:updateContent()
|
||||
self.content.width + self.padding + self.contentPadding.y,
|
||||
self.content.height + self.padding + self.contentPadding.x
|
||||
)
|
||||
self._forceCheckScroll = true
|
||||
self:updateMouseOffset()
|
||||
end
|
||||
|
||||
-- Leave control bounds size to 0 to use default. Optional group for parameter 2.
|
||||
@@ -162,29 +161,25 @@ function PropertyList:addGroup( name, active, group )
|
||||
return control
|
||||
end
|
||||
|
||||
function PropertyList:update()
|
||||
function PropertyList:update( delta )
|
||||
if not self.view:checkCollisionPoint( RL.GetMousePosition() ) then
|
||||
self.gui.locked = true
|
||||
else
|
||||
self.gui.locked = false
|
||||
end
|
||||
|
||||
self.gui:update()
|
||||
self.gui:update( delta )
|
||||
|
||||
return self._gui:drag( self )
|
||||
return self._gui:drag( self )
|
||||
end
|
||||
|
||||
function PropertyList:draw()
|
||||
local result, scroll, view = RL.GuiScrollPanel( self.bounds, self.text, self.content, self.scroll, self.view )
|
||||
local oldScroll = Vector2:tempV( self.scroll )
|
||||
local _, scroll, view = RL.GuiScrollPanel( self.bounds, self.text, self.content, self.scroll, self.view )
|
||||
self.view:setT( view )
|
||||
self.scroll:setT( scroll )
|
||||
|
||||
if 0 < result or self._forceCheckScroll then
|
||||
if not self._forceCheckScroll then
|
||||
self._gui:checkScrolling()
|
||||
end
|
||||
self._forceCheckScroll = false
|
||||
|
||||
if self.scroll ~= oldScroll then
|
||||
self:updateMouseOffset()
|
||||
self.gui.view:set( -self.scroll.x, -self.scroll.y, self.view.width, self.view.height )
|
||||
|
||||
@@ -238,8 +233,8 @@ function PropertyList:setSize( size )
|
||||
self.defaultControlSize = Vector2:new( self.content.width, self.defaultControlHeight )
|
||||
|
||||
local _, _, view = RL.GuiScrollPanel( self.bounds, self.text, self.content, self.scroll, self.view )
|
||||
|
||||
self.view = Rectangle:newT( view )
|
||||
|
||||
self.gui.view = Rectangle:new( 0, 0, self.view.width, self.view.height )
|
||||
|
||||
self:updateContent()
|
||||
|
||||
@@ -2,15 +2,15 @@ local SpriteButton = {}
|
||||
SpriteButton.__index = SpriteButton
|
||||
|
||||
function SpriteButton:new( bounds, text, texture, nPatchNormal, nPatchPressed, callbacks, styles, tooltip )
|
||||
local object = setmetatable( {}, self )
|
||||
local object = setmetatable( {}, self )
|
||||
object._gui = nil
|
||||
|
||||
object.bounds = bounds:clone()
|
||||
object.text = text
|
||||
object.bounds = bounds:clone()
|
||||
object.text = text
|
||||
object.buttonTexture = texture
|
||||
object.nPatchNormal = nPatchNormal
|
||||
object.nPatchPressed = nPatchPressed
|
||||
object.callbacks = callbacks -- pressed.
|
||||
object.callbacks = callbacks -- pressed.
|
||||
object.styles = styles
|
||||
object.tooltip = tooltip
|
||||
|
||||
@@ -21,21 +21,28 @@ function SpriteButton:new( bounds, text, texture, nPatchNormal, nPatchPressed, c
|
||||
end
|
||||
|
||||
function SpriteButton:update()
|
||||
return RL.CheckCollisionPointRec( RL.GetMousePosition(), self.bounds )
|
||||
return RL.CheckCollisionPointRec( RL.GetMousePosition(), self.bounds )
|
||||
end
|
||||
|
||||
function SpriteButton:draw()
|
||||
if RL.IsMouseButtonDown( RL.MOUSE_BUTTON_LEFT ) and self:update() and not RL.GuiIsLocked() and not self._gui.scrolling then
|
||||
RL.DrawTextureNPatchRepeat( self.buttonTexture, self.nPatchPressed, self.bounds, { 0, 0 }, 0.0, RL.WHITE )
|
||||
if RL.IsMouseButtonDown( RL.MOUSE_BUTTON_LEFT ) and self:update() and not RL.GuiIsLocked()
|
||||
and not RL.GuiGetSliderDragging() then
|
||||
RL.DrawTextureNPatchRepeat(
|
||||
self.buttonTexture, self.nPatchPressed, self.bounds,
|
||||
{ 0, 0 }, 0.0, RL.GetColor( RL.GuiGetStyle( RL.BUTTON, RL.BASE_COLOR_PRESSED ) )
|
||||
)
|
||||
else
|
||||
RL.DrawTextureNPatchRepeat( self.buttonTexture, self.nPatchNormal, self.bounds, { 0, 0 }, 0.0, RL.WHITE )
|
||||
RL.DrawTextureNPatchRepeat(
|
||||
self.buttonTexture, self.nPatchNormal, self.bounds,
|
||||
{ 0, 0 }, 0.0, RL.GetColor( RL.GuiGetStyle( RL.BUTTON, RL.BASE_COLOR_NORMAL ) )
|
||||
)
|
||||
end
|
||||
|
||||
local result = RL.GuiLabelButton( self.bounds, self.text )
|
||||
|
||||
if result == 1 and self.callbacks.pressed ~= nil and self._gui:clickedInBounds( self.bounds ) then
|
||||
if result == 1 and self.callbacks.pressed ~= nil and self._gui:clickedInBounds( self.bounds ) then
|
||||
self.callbacks.pressed( self )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function SpriteButton:setPosition( pos )
|
||||
|
||||
@@ -46,7 +46,6 @@ function TreeView:new( bounds, text, callbacks, styles, tooltip )
|
||||
|
||||
object:setSize( Vector2:new( object.bounds.width, object.bounds.height ) )
|
||||
|
||||
object._forceCheckScroll = false
|
||||
object._posY = 0 -- In control list update.
|
||||
object._curDepth = 0 -- Current indentation.
|
||||
object._curId = 0 -- Running number to give id's for controls.
|
||||
@@ -125,7 +124,7 @@ function TreeView:updateContent()
|
||||
self.content.width + self.padding,
|
||||
self.content.height + self.padding
|
||||
)
|
||||
self._forceCheckScroll = true
|
||||
self:updateMouseOffset()
|
||||
end
|
||||
|
||||
function TreeView:addItem( name, group )
|
||||
@@ -289,12 +288,7 @@ function TreeView:draw()
|
||||
self.view:setT( view )
|
||||
self.scroll:setT( scroll )
|
||||
|
||||
if 0 < result or self._forceCheckScroll then
|
||||
if not self._forceCheckScroll then
|
||||
self._gui:checkScrolling()
|
||||
end
|
||||
self._forceCheckScroll = false
|
||||
|
||||
if 0 < result then
|
||||
self:updateMouseOffset()
|
||||
self.gui.view:set( -self.scroll.x, -self.scroll.y, self.view.width, self.view.height )
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user