2012-06-26 00:13:30 +02:00
|
|
|
-- @docclass
|
2014-06-06 18:10:14 +02:00
|
|
|
UISplitter = extends(UIWidget, "UISplitter")
|
2012-03-23 02:52:31 +01:00
|
|
|
|
|
|
|
function UISplitter.create()
|
|
|
|
local splitter = UISplitter.internalCreate()
|
|
|
|
splitter:setFocusable(false)
|
2012-03-26 20:33:00 +02:00
|
|
|
splitter.relativeMargin = 'bottom'
|
2012-03-23 02:52:31 +01:00
|
|
|
return splitter
|
|
|
|
end
|
|
|
|
|
|
|
|
function UISplitter:onHoverChange(hovered)
|
2012-10-10 22:20:32 +02:00
|
|
|
-- Check if margin can be changed
|
|
|
|
local margin = (self.vertical and self:getMarginBottom() or self:getMarginRight())
|
|
|
|
if hovered and (self:canUpdateMargin(margin + 1) ~= margin or self:canUpdateMargin(margin - 1) ~= margin) then
|
2012-06-26 00:13:30 +02:00
|
|
|
if g_mouse.isCursorChanged() or g_mouse.isPressed() then return end
|
2012-03-23 02:52:31 +01:00
|
|
|
if self:getWidth() > self:getHeight() then
|
|
|
|
self.vertical = true
|
2013-01-25 14:47:51 +01:00
|
|
|
self.cursortype = 'vertical'
|
2012-03-23 02:52:31 +01:00
|
|
|
else
|
|
|
|
self.vertical = false
|
2013-01-25 14:47:51 +01:00
|
|
|
self.cursortype = 'horizontal'
|
2012-03-23 02:52:31 +01:00
|
|
|
end
|
2012-03-27 20:14:35 +02:00
|
|
|
self.hovering = true
|
2013-01-25 14:47:51 +01:00
|
|
|
g_mouse.pushCursor(self.cursortype)
|
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
|
2012-03-27 20:14:35 +02:00
|
|
|
if not self:isPressed() and self.hovering then
|
2013-01-25 14:47:51 +01:00
|
|
|
g_mouse.popCursor(self.cursortype)
|
2012-06-26 00:13:30 +02:00
|
|
|
g_effects.fadeOut(self)
|
2012-03-27 20:14:35 +02:00
|
|
|
self.hovering = false
|
2012-03-26 20:33:00 +02:00
|
|
|
end
|
2012-03-23 02:52:31 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function UISplitter:onMouseMove(mousePos, mouseMoved)
|
|
|
|
if self:isPressed() then
|
2012-03-26 20:33:00 +02:00
|
|
|
--local currentmargin, newmargin, delta
|
2012-03-23 02:52:31 +01:00
|
|
|
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)
|
2012-03-27 00:24:01 +02:00
|
|
|
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
|
2012-03-23 02:52:31 +01:00
|
|
|
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)
|
2012-03-27 00:24:01 +02:00
|
|
|
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
|
2012-03-23 02:52:31 +01:00
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function UISplitter:onMouseRelease(mousePos, mouseButton)
|
|
|
|
if not self:isHovered() then
|
2013-01-25 14:47:51 +01:00
|
|
|
g_mouse.popCursor(self.cursortype)
|
2012-06-26 00:13:30 +02:00
|
|
|
g_effects.fadeOut(self)
|
2012-03-27 20:14:35 +02:00
|
|
|
self.hovering = false
|
2012-03-23 02:52:31 +01:00
|
|
|
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
|
2012-03-23 02:52:31 +01:00
|
|
|
end
|
|
|
|
|
2012-03-23 04:06:00 +01:00
|
|
|
function UISplitter:canUpdateMargin(newMargin)
|
|
|
|
return newMargin
|
2012-03-23 02:52:31 +01:00
|
|
|
end
|