2012-03-27 00:24:01 +02:00
|
|
|
UIMiniWindow = extends(UIWindow)
|
|
|
|
|
|
|
|
function UIMiniWindow.create()
|
|
|
|
local miniwindow = UIMiniWindow.internalCreate()
|
|
|
|
return miniwindow
|
|
|
|
end
|
|
|
|
|
2012-03-28 16:10:21 +02:00
|
|
|
function UIMiniWindow:onSetup()
|
2012-06-08 18:58:08 +02:00
|
|
|
self:getChildById('closeButton').onClick = function() signalcall(self.onClose, self) end
|
|
|
|
self:getChildById('minimizeButton').onClick = function() signalcall(self.onMinimize, self) end
|
2012-03-28 16:10:21 +02:00
|
|
|
end
|
|
|
|
|
2012-03-27 00:24:01 +02:00
|
|
|
function UIMiniWindow:onDragEnter(mousePos)
|
|
|
|
local parent = self:getParent()
|
|
|
|
if not parent then return false end
|
|
|
|
|
|
|
|
if parent:getClassName() == 'UIMiniWindowContainer' then
|
|
|
|
local containerParent = parent:getParent()
|
|
|
|
parent:removeChild(self)
|
|
|
|
containerParent:addChild(self)
|
|
|
|
end
|
|
|
|
|
|
|
|
local oldPos = self:getPosition()
|
|
|
|
self.movingReference = { x = mousePos.x - oldPos.x, y = mousePos.y - oldPos.y }
|
|
|
|
self:setPosition(oldPos)
|
2012-03-28 16:10:21 +02:00
|
|
|
self.free = true
|
2012-03-27 00:24:01 +02:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2012-06-11 07:38:08 +02:00
|
|
|
function UIMiniWindow:onDragMove(mousePos, mouseMoved)
|
|
|
|
local oldMousePosY = mousePos.y - mouseMoved.y
|
2012-06-11 16:10:03 +02:00
|
|
|
local children = rootWidget:recursiveGetChildrenByMarginPos(mousePos)
|
2012-06-11 07:38:08 +02:00
|
|
|
local overAnyWidget = false
|
|
|
|
for i=1,#children do
|
|
|
|
local child = children[i]
|
|
|
|
if child:getParent():getClassName() == 'UIMiniWindowContainer' then
|
|
|
|
overAnyWidget = true
|
|
|
|
|
|
|
|
local childCenterY = child:getY() + child:getHeight() / 2
|
|
|
|
if child == self.movedWidget and mousePos.y < childCenterY and oldMousePosY < childCenterY then
|
|
|
|
break
|
|
|
|
end
|
|
|
|
|
|
|
|
if self.movedWidget then
|
2012-06-11 16:10:03 +02:00
|
|
|
self.setMovedChildMargin(0)
|
|
|
|
self.setMovedChildMargin = nil
|
2012-06-11 07:38:08 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if mousePos.y < childCenterY then
|
2012-06-11 16:10:03 +02:00
|
|
|
self.setMovedChildMargin = function(v) child:setMarginTop(v) end
|
2012-06-11 07:38:08 +02:00
|
|
|
self.movedIndex = 0
|
|
|
|
else
|
2012-06-11 16:10:03 +02:00
|
|
|
self.setMovedChildMargin = function(v) child:setMarginBottom(v) end
|
2012-06-11 07:38:08 +02:00
|
|
|
self.movedIndex = 1
|
|
|
|
end
|
|
|
|
|
|
|
|
self.movedWidget = child
|
2012-06-11 16:10:03 +02:00
|
|
|
self.setMovedChildMargin(self:getHeight())
|
2012-06-11 07:38:08 +02:00
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if not overAnyWidget and self.movedWidget then
|
2012-06-11 16:10:03 +02:00
|
|
|
self.setMovedChildMargin(0)
|
2012-06-11 07:38:08 +02:00
|
|
|
self.movedWidget = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
return UIWindow.onDragMove(self, mousePos, mouseMoved)
|
|
|
|
end
|
|
|
|
|
2012-03-28 16:10:21 +02:00
|
|
|
function UIMiniWindow:onMousePress()
|
|
|
|
local parent = self:getParent()
|
|
|
|
if not parent then return false end
|
|
|
|
if parent:getClassName() ~= 'UIMiniWindowContainer' then
|
|
|
|
self:raise()
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-03-27 00:24:01 +02:00
|
|
|
function UIMiniWindow:onDragLeave(droppedWidget, mousePos)
|
2012-06-11 07:38:08 +02:00
|
|
|
if self.movedWidget then
|
2012-06-11 16:10:03 +02:00
|
|
|
self.setMovedChildMargin(0)
|
2012-06-11 07:38:08 +02:00
|
|
|
self.movedWidget = nil
|
2012-06-11 16:10:03 +02:00
|
|
|
self.setMovedChildMargin = nil
|
2012-06-11 07:38:08 +02:00
|
|
|
self.movedIndex = nil
|
|
|
|
end
|
2012-03-27 00:24:01 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function UIMiniWindow:onFocusChange(focused)
|
|
|
|
-- miniwindows only raises when its outside MiniWindowContainers
|
|
|
|
if not focused then return end
|
|
|
|
local parent = self:getParent()
|
|
|
|
if parent and parent:getClassName() ~= 'UIMiniWindowContainer' then
|
|
|
|
self:raise()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-03-28 16:10:21 +02:00
|
|
|
function UIMiniWindow:onClose()
|
|
|
|
end
|
|
|
|
|
|
|
|
function UIMiniWindow:onMinimize()
|
|
|
|
if self:isOn() then
|
|
|
|
self:setOn(false)
|
|
|
|
self:getChildById('contentsPanel'):show()
|
|
|
|
self:getChildById('miniwindowScrollBar'):show()
|
|
|
|
self:getChildById('bottomResizeBorder'):show()
|
|
|
|
self:getChildById('minimizeButton'):setOn(false)
|
|
|
|
self:setHeight(self.savedHeight)
|
|
|
|
else
|
|
|
|
self.savedHeight = self:getHeight()
|
|
|
|
self:setHeight(self.minimizedHeight)
|
|
|
|
self:setOn(true)
|
|
|
|
self:getChildById('contentsPanel'):hide()
|
|
|
|
self:getChildById('miniwindowScrollBar'):hide()
|
|
|
|
self:getChildById('bottomResizeBorder'):hide()
|
|
|
|
self:getChildById('minimizeButton'):setOn(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-03-28 21:09:45 +02:00
|
|
|
function UIMiniWindow:getClassName()
|
|
|
|
return 'UIMiniWindow'
|
|
|
|
end
|