tibia-client/modules/corelib/ui/uisplitter.lua

83 lines
2.3 KiB
Lua
Raw Normal View History

2012-06-26 00:13:30 +02:00
-- @docclass
UISplitter = extends(UIWidget)
function UISplitter.create()
local splitter = UISplitter.internalCreate()
splitter:setFocusable(false)
2012-03-26 20:33:00 +02:00
splitter.relativeMargin = 'bottom'
return splitter
end
function UISplitter:onHoverChange(hovered)
if hovered then
2012-06-26 00:13:30 +02:00
if g_mouse.isCursorChanged() or g_mouse.isPressed() then return end
if self:getWidth() > self:getHeight() then
2012-06-26 00:13:30 +02:00
g_mouse.setVerticalCursor()
self.vertical = true
else
2012-06-26 00:13:30 +02:00
g_mouse.setHorizontalCursor()
self.vertical = false
end
self.hovering = true
2012-03-26 20:33:00 +02:00
if not self:isPressed() then
2012-06-26 00:13:30 +02:00
g_effects.fadeIn(self)
2012-03-26 20:33:00 +02:00
end
else
if not self:isPressed() and self.hovering then
2012-06-26 00:13:30 +02:00
g_mouse.restoreCursor()
g_effects.fadeOut(self)
self.hovering = false
2012-03-26 20:33:00 +02:00
end
end
end
function UISplitter:onMouseMove(mousePos, mouseMoved)
if self:isPressed() then
2012-03-26 20:33:00 +02:00
--local currentmargin, newmargin, delta
if self.vertical then
2012-03-26 20:33:00 +02:00
local delta = mousePos.y - self:getY() - self:getHeight()/2
2012-03-23 04:06:00 +01:00
local newMargin = self:canUpdateMargin(self:getMarginBottom() - delta)
local currentMargin = self:getMarginBottom()
2012-03-23 04:06:00 +01:00
if newMargin ~= currentMargin then
self.newMargin = newMargin
if not self.event or self.event:isExecuted() then
self.event = addEvent(function()
self:setMarginBottom(self.newMargin)
end)
end
end
else
2012-03-26 20:33:00 +02:00
local delta = mousePos.x - self:getX() - self:getWidth()/2
local newMargin = self:canUpdateMargin(self:getMarginRight() - delta)
local currentMargin = self:getMarginRight()
2012-03-26 20:33:00 +02:00
if newMargin ~= currentMargin then
self.newMargin = newMargin
if not self.event or self.event:isExecuted() then
self.event = addEvent(function()
self:setMarginRight(self.newMargin)
end)
end
end
end
return true
end
end
function UISplitter:onMouseRelease(mousePos, mouseButton)
if not self:isHovered() then
2012-06-26 00:13:30 +02:00
g_mouse.restoreCursor()
g_effects.fadeOut(self)
self.hovering = false
end
end
function UISplitter:onStyleApply(styleName, styleNode)
2012-03-26 20:33:00 +02:00
if styleNode['relative-margin'] then
self.relativeMargin = styleNode['relative-margin']
end
end
2012-03-23 04:06:00 +01:00
function UISplitter:canUpdateMargin(newMargin)
return newMargin
end