mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 11:34:54 +02:00
add splitter widget
* add horizontal/vertical cursor * possibildiade to resize game map with the new splitter widget * fix reload warnings in textmessage
This commit is contained in:
@@ -38,3 +38,5 @@ Module
|
||||
dofile 'widgets/uipopupmenu'
|
||||
dofile 'widgets/uiwindow'
|
||||
dofile 'widgets/uimessagebox'
|
||||
dofile 'widgets/uisplitter'
|
||||
|
||||
|
@@ -4,7 +4,14 @@ function Mouse.setTargetCursor()
|
||||
g_window.setMouseCursor('/core_styles/cursors/targetcursor.png', {x=9,y=9})
|
||||
end
|
||||
|
||||
function Mouse.setHorizontalCursor()
|
||||
g_window.setMouseCursor('/core_styles/cursors/horizontal.png', {x=9,y=4})
|
||||
end
|
||||
|
||||
function Mouse.setVerticalCursor()
|
||||
g_window.setMouseCursor('/core_styles/cursors/vertical.png', {x=4,y=9})
|
||||
end
|
||||
|
||||
function Mouse.restoreCursor()
|
||||
g_window.restoreMouseCursor()
|
||||
end
|
||||
|
||||
|
@@ -47,7 +47,8 @@ function ToolTip.init()
|
||||
addEvent(function()
|
||||
toolTipLabel = createWidget('Label', rootWidget)
|
||||
toolTipLabel:setId('toolTip')
|
||||
toolTipLabel:setBackgroundColor('#111111bb')
|
||||
toolTipLabel:setBackgroundColor('#111111cc')
|
||||
toolTipLabel:setTextAlign(AlignCenter)
|
||||
toolTipLabel.onMouseMove = moveToolTip
|
||||
end)
|
||||
end
|
||||
|
70
modules/core_lib/widgets/uisplitter.lua
Normal file
70
modules/core_lib/widgets/uisplitter.lua
Normal file
@@ -0,0 +1,70 @@
|
||||
UISplitter = extends(UIWidget)
|
||||
|
||||
function UISplitter.create()
|
||||
local splitter = UISplitter.internalCreate()
|
||||
splitter:setFocusable(false)
|
||||
splitter.canGrow = true
|
||||
splitter.canShrink = true
|
||||
return splitter
|
||||
end
|
||||
|
||||
function UISplitter:onHoverChange(hovered)
|
||||
if hovered then
|
||||
if self:getWidth() > self:getHeight() then
|
||||
Mouse.setVerticalCursor()
|
||||
self.vertical = true
|
||||
else
|
||||
Mouse.setHorizontalCursor()
|
||||
self.vertical = false
|
||||
end
|
||||
elseif not self:isPressed() then
|
||||
Mouse.restoreCursor()
|
||||
end
|
||||
end
|
||||
|
||||
function UISplitter:getAttachedTo()
|
||||
local parent = self:getParent()
|
||||
if parent and self.attachedTo then
|
||||
return parent:getChildById(self.attachedTo)
|
||||
end
|
||||
end
|
||||
|
||||
function UISplitter:onMouseMove(mousePos, mouseMoved)
|
||||
if self:isPressed() then
|
||||
local deltay = mousePos.y - (self:getPosition().y + self:getHeight()/2)
|
||||
local deltax = mousePos.x - (self:getPosition().x + self:getWidth()/2)
|
||||
local attachedToWidget = self:getAttachedTo()
|
||||
if not attachedToWidget then return end
|
||||
if self.vertical then
|
||||
if deltay == 0 then return end
|
||||
if not self.canGrow and deltay > 0 then return end
|
||||
if not self.canShrink and deltay < 0 then return end
|
||||
attachedToWidget:setHeight(attachedToWidget:getHeight() - deltay)
|
||||
else
|
||||
if deltax == 0 then return end
|
||||
attachedToWidget:setWidth(attachedToWidget:getWidth() - deltax)
|
||||
end
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
function UISplitter:onMouseRelease(mousePos, mouseButton)
|
||||
if not self:isHovered() then
|
||||
Mouse.restoreCursor()
|
||||
end
|
||||
self:ungrabMouse()
|
||||
end
|
||||
|
||||
function UISplitter:onStyleApply(styleName, styleNode)
|
||||
if styleNode['attached-to'] then
|
||||
self.attachedTo = styleNode['attached-to']
|
||||
end
|
||||
end
|
||||
|
||||
function UISplitter:setGrow(enabled)
|
||||
self.canGrow = enabled
|
||||
end
|
||||
|
||||
function UISplitter:setShrink(enabled)
|
||||
self.canShrink = enabled
|
||||
end
|
Reference in New Issue
Block a user