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:
Eduardo Bart 2012-03-22 22:52:31 -03:00
parent 33458a3e39
commit 79a1d66f3f
9 changed files with 99 additions and 2 deletions

View File

@ -38,3 +38,5 @@ Module
dofile 'widgets/uipopupmenu' dofile 'widgets/uipopupmenu'
dofile 'widgets/uiwindow' dofile 'widgets/uiwindow'
dofile 'widgets/uimessagebox' dofile 'widgets/uimessagebox'
dofile 'widgets/uisplitter'

View File

@ -4,7 +4,14 @@ function Mouse.setTargetCursor()
g_window.setMouseCursor('/core_styles/cursors/targetcursor.png', {x=9,y=9}) g_window.setMouseCursor('/core_styles/cursors/targetcursor.png', {x=9,y=9})
end 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() function Mouse.restoreCursor()
g_window.restoreMouseCursor() g_window.restoreMouseCursor()
end end

View File

@ -47,7 +47,8 @@ function ToolTip.init()
addEvent(function() addEvent(function()
toolTipLabel = createWidget('Label', rootWidget) toolTipLabel = createWidget('Label', rootWidget)
toolTipLabel:setId('toolTip') toolTipLabel:setId('toolTip')
toolTipLabel:setBackgroundColor('#111111bb') toolTipLabel:setBackgroundColor('#111111cc')
toolTipLabel:setTextAlign(AlignCenter)
toolTipLabel.onMouseMove = moveToolTip toolTipLabel.onMouseMove = moveToolTip
end) end)
end end

View 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

Binary file not shown.

After

Width:  |  Height:  |  Size: 230 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 B

View File

@ -38,6 +38,7 @@ UIWidget
anchors.left: gameLeftPanel.right anchors.left: gameLeftPanel.right
anchors.right: gameRightPanel.left anchors.right: gameRightPanel.left
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
@onGeometryChange: self:getParent():getChildById('mapSplitter'):setGrow(self:getHeight() > 100)
GameMapPanel GameMapPanel
id: gameMapPanel id: gameMapPanel
@ -46,6 +47,16 @@ UIWidget
anchors.top: parent.top anchors.top: parent.top
anchors.bottom: gameBottomPanel.top anchors.bottom: gameBottomPanel.top
focusable: false 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

View File

@ -94,6 +94,10 @@ function TextMessage.terminate()
disconnect(g_game, { onDeath = TextMessage.displayDeadMessage, disconnect(g_game, { onDeath = TextMessage.displayDeadMessage,
onTextMessage = TextMessage.display, onTextMessage = TextMessage.display,
onGameEnd = TextMessage.clearMessages }) onGameEnd = TextMessage.clearMessages })
removeEvent(GameInterface.getMapPanel():recursiveGetChildById('centerWarning').hideEvent)
removeEvent(GameInterface.getMapPanel():recursiveGetChildById('centerAdvance').hideEvent)
removeEvent(GameInterface.getMapPanel():recursiveGetChildById('centerInfo').hideEvent)
removeEvent(GameInterface.getMapPanel():recursiveGetChildById('bottomStatus').hideEvent)
centerTextMessagePanel:destroy() centerTextMessagePanel:destroy()
centerTextMessagePanel = nil centerTextMessagePanel = nil
bottomStatusLabel:destroy() bottomStatusLabel:destroy()

View File

@ -116,6 +116,8 @@ TilePtr UIMap::getTile(const Point& mousePos)
void UIMap::onGeometryChange(const Rect& oldRect, const Rect& newRect) void UIMap::onGeometryChange(const Rect& oldRect, const Rect& newRect)
{ {
UIWidget::onGeometryChange(oldRect, newRect);
Rect mapRect = getChildrenRect().expanded(-1); Rect mapRect = getChildrenRect().expanded(-1);
Size mapSize = m_mapView->getVisibleSize(); Size mapSize = m_mapView->getVisibleSize();
mapSize.scale(mapRect.size(), Fw::KeepAspectRatio); mapSize.scale(mapRect.size(), Fw::KeepAspectRatio);