rework splitter implementation

This commit is contained in:
Eduardo Bart 2012-03-23 00:06:00 -03:00
parent 79a1d66f3f
commit b301aa1a2b
4 changed files with 51 additions and 56 deletions

View File

@ -3,8 +3,6 @@ UISplitter = extends(UIWidget)
function UISplitter.create() function UISplitter.create()
local splitter = UISplitter.internalCreate() local splitter = UISplitter.internalCreate()
splitter:setFocusable(false) splitter:setFocusable(false)
splitter.canGrow = true
splitter.canShrink = true
return splitter return splitter
end end
@ -22,27 +20,23 @@ function UISplitter:onHoverChange(hovered)
end end
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) function UISplitter:onMouseMove(mousePos, mouseMoved)
if self:isPressed() then 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 self.vertical then
if deltay == 0 then return end local delta = mousePos.y - self:getY()
if not self.canGrow and deltay > 0 then return end local currentMargin = self:getMarginBottom()
if not self.canShrink and deltay < 0 then return end local newMargin = self:canUpdateMargin(self:getMarginBottom() - delta)
attachedToWidget:setHeight(attachedToWidget:getHeight() - deltay) 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 else
if deltax == 0 then return end --TODO
attachedToWidget:setWidth(attachedToWidget:getWidth() - deltax)
end end
return true return true
end end
@ -56,15 +50,11 @@ function UISplitter:onMouseRelease(mousePos, mouseButton)
end end
function UISplitter:onStyleApply(styleName, styleNode) function UISplitter:onStyleApply(styleName, styleNode)
if styleNode['attached-to'] then if styleNode['relative-margin'] then
self.attachedTo = styleNode['attached-to'] self.relativeMargin = styleNode['relative-margin']
end end
end end
function UISplitter:setGrow(enabled) function UISplitter:canUpdateMargin(newMargin)
self.canGrow = enabled return newMargin
end
function UISplitter:setShrink(enabled)
self.canShrink = enabled
end end

View File

@ -16,6 +16,33 @@ UIWidget
anchors.fill: parent anchors.fill: parent
anchors.top: topMenu.bottom anchors.top: topMenu.bottom
GameMapPanel
id: gameMapPanel
anchors.left: gameLeftPanel.right
anchors.right: gameRightPanel.left
anchors.top: parent.top
anchors.bottom: gameBottomPanel.top
focusable: false
UISplitter
id: mapSplitter
anchors.left: gameLeftPanel.right
anchors.right: gameRightPanel.left
anchors.bottom: parent.bottom
relative-margin: bottom
margin-bottom: 172
height: 4
margin-top: -2
background: red
@canUpdateMargin: function(self, newMargin) return math.min(math.max(newMargin, 100), self:getParent():getHeight() - 300) end
GameBottomPanel
id: gameBottomPanel
anchors.left: gameLeftPanel.right
anchors.right: gameRightPanel.left
anchors.top: mapSplitter.top
anchors.bottom: parent.bottom
GameSidePanel GameSidePanel
id: gameRightPanel id: gameRightPanel
width: 190 width: 190
@ -32,32 +59,6 @@ UIWidget
anchors.top: parent.top anchors.top: parent.top
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
GameBottomPanel
id: gameBottomPanel
height: 170
anchors.left: gameLeftPanel.right
anchors.right: gameRightPanel.left
anchors.bottom: parent.bottom
@onGeometryChange: self:getParent():getChildById('mapSplitter'):setGrow(self:getHeight() > 100)
GameMapPanel
id: gameMapPanel
anchors.left: gameLeftPanel.right
anchors.right: gameRightPanel.left
anchors.top: parent.top
anchors.bottom: gameBottomPanel.top
focusable: false
@onGeometryChange: self:getParent():getChildById('mapSplitter'):setShrink(self:getHeight() > 300)
UISplitter
id: mapSplitter
anchors.left: gameBottomPanel.left
anchors.right: gameBottomPanel.right
anchors.top: gameBottomPanel.top
attached-to: gameBottomPanel
height: 4
margin-top: -2
UIWidget UIWidget
id: mouseGrabber id: mouseGrabber
focusable: false focusable: false

View File

@ -714,6 +714,10 @@ void UIWidget::setLayout(const UILayoutPtr& layout)
void UIWidget::setRect(const Rect& rect) void UIWidget::setRect(const Rect& rect)
{ {
if(rect.width() > 8192 || rect.height() > 8192) {
logError("attempt to set huge rect size (", rect,") for ", m_id);
return;
}
// only update if the rect really changed // only update if the rect really changed
Rect oldRect = m_rect; Rect oldRect = m_rect;
if(rect == oldRect) if(rect == oldRect)

View File

@ -49,7 +49,7 @@ namespace Proto {
#if PROTOCOL>=861 #if PROTOCOL>=861
constexpr int NumViolationReasons = 19; constexpr int NumViolationReasons = 19;
#elif PROTOCOL==860 #elif PROTOCOL>=860
constexpr int NumViolationReasons = 20; constexpr int NumViolationReasons = 20;
#endif #endif
@ -246,7 +246,7 @@ namespace Proto {
ServerSpeakRVRAnswer, ServerSpeakRVRAnswer,
ServerSpeakRVRContinue, ServerSpeakRVRContinue,
ServerSpeakChannelRed2 ServerSpeakChannelRed2
#elif PROTOCOL==860 #elif PROTOCOL>=860
ServerSpeakSay = 1, ServerSpeakSay = 1,
ServerSpeakWhisper, ServerSpeakWhisper,
ServerSpeakYell, ServerSpeakYell,
@ -269,7 +269,7 @@ namespace Proto {
}; };
enum MessageTypes { enum MessageTypes {
#if PROTOCOL>=862 #if PROTOCOL>=861
MessageConsoleOrange = 13, MessageConsoleOrange = 13,
MessageConsoleOrange2, MessageConsoleOrange2,
MessageWarning, MessageWarning,
@ -280,7 +280,7 @@ namespace Proto {
MessageStatusSmall, MessageStatusSmall,
MessageConsoleBlue, MessageConsoleBlue,
MessageConsoleRed MessageConsoleRed
#elif PROTOCOL==860 #elif PROTOCOL>=860
MessageConsoleRed = 18, MessageConsoleRed = 18,
MessageConsoleOrange, MessageConsoleOrange,
MessageConsoleOrange2, MessageConsoleOrange2,