side panel splitter

This commit is contained in:
Eduardo Bart 2012-03-26 15:33:00 -03:00
parent 9309d6e7f3
commit ee869bb279
15 changed files with 126 additions and 62 deletions

View File

@ -9,7 +9,7 @@ local LabelHeight = 16
local MaxHistory = 1000 local MaxHistory = 1000
-- private variables -- private variables
local terminalWidget local terminalWindow
local terminalButton local terminalButton
local logLocked = false local logLocked = false
local commandEnv = newenv() local commandEnv = newenv()
@ -107,22 +107,36 @@ end
-- public functions -- public functions
function Terminal.init() function Terminal.init()
terminalWidget = displayUI('terminal.otui') terminalWindow = displayUI('terminal.otui')
terminalWidget:setVisible(false) terminalWindow:setVisible(false)
local poped = false
terminalWindow.onDoubleClick = function(self)
if poped then
self:fill('parent')
poped = false
else
self:breakAnchors()
self:resize(g_window.getWidth()/2, g_window.getHeight()/2)
self:move(g_window.getWidth()/2, g_window.getHeight()/2)
poped = true
end
end
terminalButton = TopMenu.addLeftButton('terminalButton', 'Terminal (Ctrl + T)', 'terminal.png', Terminal.toggle) terminalButton = TopMenu.addLeftButton('terminalButton', 'Terminal (Ctrl + T)', 'terminal.png', Terminal.toggle)
Keyboard.bindKeyDown('Ctrl+T', Terminal.toggle) Keyboard.bindKeyDown('Ctrl+T', Terminal.toggle)
commandHistory = Settings.getList('terminal-history') commandHistory = Settings.getList('terminal-history')
commandLineEdit = terminalWidget:getChildById('commandLineEdit') commandLineEdit = terminalWindow:getChildById('commandLineEdit')
Keyboard.bindKeyPress('Up', function() navigateCommand(1) end, commandLineEdit) Keyboard.bindKeyPress('Up', function() navigateCommand(1) end, commandLineEdit)
Keyboard.bindKeyPress('Down', function() navigateCommand(-1) end, commandLineEdit) Keyboard.bindKeyPress('Down', function() navigateCommand(-1) end, commandLineEdit)
Keyboard.bindKeyDown('Tab', completeCommand, commandLineEdit) Keyboard.bindKeyDown('Tab', completeCommand, commandLineEdit)
Keyboard.bindKeyDown('Enter', doCommand, commandLineEdit) Keyboard.bindKeyDown('Enter', doCommand, commandLineEdit)
Keyboard.bindKeyDown('Escape', Terminal.hide, terminalWidget) Keyboard.bindKeyDown('Escape', Terminal.hide, terminalWindow)
terminalBuffer = terminalWidget:getChildById('terminalBuffer') terminalBuffer = terminalWindow:getChildById('terminalBuffer')
g_logger.setOnLog(onLog) g_logger.setOnLog(onLog)
g_logger.fireOldMessages() g_logger.fireOldMessages()
end end
@ -135,14 +149,14 @@ function Terminal.terminate()
terminalButton = nil terminalButton = nil
commandLineEdit = nil commandLineEdit = nil
terminalBuffer = nil terminalBuffer = nil
terminalWidget:destroy() terminalWindow:destroy()
terminalWidget = nil terminalWindow = nil
commandEnv = nil commandEnv = nil
Terminal = nil Terminal = nil
end end
function Terminal.toggle() function Terminal.toggle()
if terminalWidget:isVisible() then if terminalWindow:isVisible() then
Terminal.hide() Terminal.hide()
else else
Terminal.show() Terminal.show()
@ -150,13 +164,13 @@ function Terminal.toggle()
end end
function Terminal.show() function Terminal.show()
terminalWidget:show() terminalWindow:show()
terminalWidget:raise() terminalWindow:raise()
terminalWidget:focus() terminalWindow:focus()
end end
function Terminal.hide() function Terminal.hide()
terminalWidget:hide() terminalWindow:hide()
end end
function Terminal.addLine(text, color) function Terminal.addLine(text, color)

View File

@ -1,16 +1,21 @@
TerminalLabel < UILabel TerminalLabel < UILabel
font: terminus-14px-bold font: terminus-14px-bold
height: 16 height: 16
text-wrap: true
text-auto-resize: true
UIWidget UIWindow
id: terminalWidget id: terminalWindow
background-color: #000000 background-color: #000000
opacity: 0.85 opacity: 0.85
clipping: true
anchors.fill: parent anchors.fill: parent
Panel Panel
id: terminalBuffer id: terminalBuffer
layout: verticalBox layout:
type: verticalBox
align-bottom: true
focusable: false focusable: false
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
@ -35,3 +40,5 @@ UIWidget
anchors.right: parent.right anchors.right: parent.right
margin-left: 5 margin-left: 5
font: terminus-14px-bold font: terminus-14px-bold

View File

@ -2,8 +2,9 @@ Effects = {}
function Effects.fadeIn(widget, time, elapsed) function Effects.fadeIn(widget, time, elapsed)
if not elapsed then elapsed = 0 end if not elapsed then elapsed = 0 end
if not time then time = 250 end if not time then time = 300 end
widget:setOpacity(math.min(elapsed/time, 1)) widget:setOpacity(math.min(elapsed/time, 1))
removeEvent(widget.fadeEvent)
if elapsed < time then if elapsed < time then
removeEvent(widget.fadeEvent) removeEvent(widget.fadeEvent)
widget.fadeEvent = scheduleEvent(function() widget.fadeEvent = scheduleEvent(function()
@ -16,19 +17,20 @@ end
function Effects.fadeOut(widget, time, elapsed) function Effects.fadeOut(widget, time, elapsed)
if not elapsed then elapsed = 0 end if not elapsed then elapsed = 0 end
if not time then time = 250 end if not time then time = 300 end
elapsed = math.max((1 - widget:getOpacity()) * time, elapsed)
removeEvent(widget.fadeEvent)
widget:setOpacity(math.max((time - elapsed)/time, 0)) widget:setOpacity(math.max((time - elapsed)/time, 0))
if elapsed < time then if elapsed < time then
removeEvent(widget.fadeEvent)
widget.fadeEvent = scheduleEvent(function() widget.fadeEvent = scheduleEvent(function()
Effects.fadeOut(widget, time, elapsed + 30) Effects.fadeOut(widget, time, elapsed + 30)
end, 30) end, 30)
else else
widget.fadeEvent = nil widget.fadeEvent = nil
widget:destroy()
end end
end end
function Effects.cancelFade(widget) function Effects.cancelFade(widget)
removeEvent(widget.fadeEvent) removeEvent(widget.fadeEvent)
widget.fadeEvent = nil
end end

View File

@ -74,12 +74,12 @@ function ToolTip.display(text)
toolTipLabel:show() toolTipLabel:show()
toolTipLabel:raise() toolTipLabel:raise()
toolTipLabel:enable() toolTipLabel:enable()
Effects.fadeIn(toolTipLabel, 100)
moveToolTip(toolTipLabel) moveToolTip(toolTipLabel)
end end
function ToolTip.hide() function ToolTip.hide()
Effects.fadeOut(toolTipLabel, 100)
toolTipLabel:hide()
end end
-- UIWidget extensions -- UIWidget extensions

View File

@ -3,6 +3,7 @@ UISplitter = extends(UIWidget)
function UISplitter.create() function UISplitter.create()
local splitter = UISplitter.internalCreate() local splitter = UISplitter.internalCreate()
splitter:setFocusable(false) splitter:setFocusable(false)
splitter.relativeMargin = 'bottom'
return splitter return splitter
end end
@ -15,17 +16,22 @@ function UISplitter:onHoverChange(hovered)
Mouse.setHorizontalCursor() Mouse.setHorizontalCursor()
self.vertical = false self.vertical = false
end end
elseif not self:isPressed() then if not self:isPressed() then
Mouse.restoreCursor() Effects.fadeIn(self)
end
else
if not self:isPressed() then
Mouse.restoreCursor()
Effects.fadeOut(self)
end
end end
end end
function UISplitter:onMouseMove(mousePos, mouseMoved) function UISplitter:onMouseMove(mousePos, mouseMoved)
if self:isPressed() then if self:isPressed() then
--local currentmargin, newmargin, delta
if self.vertical then if self.vertical then
local delta = mousePos.y - self:getY() local delta = mousePos.y - self:getY() - self:getHeight()/2
local currentMargin = self:getMarginBottom()
local newMargin = self:canUpdateMargin(self:getMarginBottom() - delta) local newMargin = self:canUpdateMargin(self:getMarginBottom() - delta)
if newMargin ~= currentMargin then if newMargin ~= currentMargin then
self.newMargin = newMargin self.newMargin = newMargin
@ -36,7 +42,16 @@ function UISplitter:onMouseMove(mousePos, mouseMoved)
end end
end end
else else
--TODO local delta = mousePos.x - self:getX() - self:getWidth()/2
local newMargin = self:canUpdateMargin(self:getMarginRight() - delta)
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 end
return true return true
end end
@ -45,14 +60,14 @@ end
function UISplitter:onMouseRelease(mousePos, mouseButton) function UISplitter:onMouseRelease(mousePos, mouseButton)
if not self:isHovered() then if not self:isHovered() then
Mouse.restoreCursor() Mouse.restoreCursor()
Effects.fadeOut(self)
end end
end end
function UISplitter:onStyleApply(styleName, styleNode) function UISplitter:onStyleApply(styleName, styleNode)
--TODO: relative margins if styleNode['relative-margin'] then
--if styleNode['relative-margin'] then self.relativeMargin = styleNode['relative-margin']
--- self.relativeMargin = styleNode['relative-margin'] end
--end
end end
function UISplitter:canUpdateMargin(newMargin) function UISplitter:canUpdateMargin(newMargin)

View File

@ -29,3 +29,4 @@ Module
importStyle 'styles/spinboxes.otui' importStyle 'styles/spinboxes.otui'
importStyle 'styles/messageboxes.otui' importStyle 'styles/messageboxes.otui'
importStyle 'styles/scrollbars.otui' importStyle 'styles/scrollbars.otui'
importStyle 'styles/splitters.otui'

View File

@ -17,7 +17,7 @@ Window < UIWindow
$disabled: $disabled:
color: #aaaaaa88 color: #aaaaaa88
$pressed: $dragging:
opacity: 0.8 opacity: 0.8
MainWindow < Window MainWindow < Window

View File

@ -24,34 +24,13 @@ UIWidget
anchors.bottom: gameBottomPanel.top anchors.bottom: gameBottomPanel.top
focusable: false 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
@canUpdateMargin: function(self, newMargin) return math.min(math.max(newMargin, 100), self:getParent():getHeight() - 300) end
@onGeometryChange: function(self) self:setMarginBottom(math.min(self:getParent():getHeight() - 300, self:getMarginBottom())) end
GameBottomPanel GameBottomPanel
id: gameBottomPanel id: gameBottomPanel
anchors.left: gameLeftPanel.right anchors.left: gameLeftPanel.right
anchors.right: gameRightPanel.left anchors.right: gameRightPanel.left
anchors.top: mapSplitter.top anchors.top: bottomSplitter.top
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
GameSidePanel
id: gameRightPanel
width: 190
layout: verticalBox
anchors.right: parent.right
anchors.top: parent.top
anchors.bottom: parent.bottom
focusable: false
GameSidePanel GameSidePanel
id: gameLeftPanel id: gameLeftPanel
width: 0 width: 0
@ -61,6 +40,35 @@ UIWidget
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
focusable: false focusable: false
GameSidePanel
id: gameRightPanel
layout: verticalBox
anchors.left: rightSplitter.left
anchors.right: parent.right
anchors.top: parent.top
anchors.bottom: parent.bottom
focusable: false
Splitter
id: bottomSplitter
anchors.left: gameLeftPanel.right
anchors.right: gameRightPanel.left
anchors.bottom: parent.bottom
relative-margin: bottom
margin-bottom: 172
@canUpdateMargin: function(self, newMargin) return math.min(math.max(newMargin, 100), self:getParent():getHeight() - 300) end
@onGeometryChange: function(self) self:setMarginBottom(math.min(self:getParent():getHeight() - 300, self:getMarginBottom())) end
Splitter
id: rightSplitter
anchors.right: parent.right
anchors.top: parent.top
anchors.bottom: parent.bottom
relative-margin: right
margin-right: 190
@canUpdateMargin: function(self, newMargin) return math.min(math.max(newMargin, 150), self:getParent():getWidth() - 300) end
@onGeometryChange: function(self) self:setMarginRight(math.min(self:getParent():getWidth() - 300, self:getMarginRight())) end
UIWidget UIWidget
id: mouseGrabber id: mouseGrabber
focusable: false focusable: false

View File

@ -59,6 +59,8 @@ local function createTextMessageLabel(id, parent)
label:setTextAlign(AlignCenter) label:setTextAlign(AlignCenter)
label:setId(id) label:setId(id)
label:setMarginBottom(2) label:setMarginBottom(2)
label:setTextWrap(true)
label:setTextAutoResize(true)
label:setVisible(false) label:setVisible(false)
return label return label
end end

View File

@ -2,6 +2,7 @@ CenterLabel < GameLabel
font: verdana-11px-rounded font: verdana-11px-rounded
height: 64 height: 64
text-align: center text-align: center
text-wrap: true
anchors.centerIn: parent anchors.centerIn: parent
size: 360 264 size: 360 264
@ -11,5 +12,4 @@ BottomLabel < GameLabel
text-align: center text-align: center
margin-bottom: 2 margin-bottom: 2
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.left: parent.left anchors.horizontalCenter: parent.horizontalCenter
anchors.right: parent.right

View File

@ -58,8 +58,8 @@ void Application::registerLuaFunctions()
g_lua.bindClassMemberFunction<ScheduledEvent>("ticks", &ScheduledEvent::ticks); g_lua.bindClassMemberFunction<ScheduledEvent>("ticks", &ScheduledEvent::ticks);
// UIWidget // UIWidget
g_lua.registerClass<UIWidget>();
g_lua.bindClassStaticFunction<UIWidget>("create", []{ return UIWidgetPtr(new UIWidget); }); g_lua.registerClass<UIWidget>(); g_lua.bindClassStaticFunction<UIWidget>("create", []{ return UIWidgetPtr(new UIWidget); });
g_lua.bindClassMemberFunction<UIWidget>("addChild", &UIWidget::addChild); g_lua.bindClassMemberFunction<UIWidget>("addChild", &UIWidget::addChild);
g_lua.bindClassMemberFunction<UIWidget>("insertChild", &UIWidget::insertChild); g_lua.bindClassMemberFunction<UIWidget>("insertChild", &UIWidget::insertChild);
g_lua.bindClassMemberFunction<UIWidget>("removeChild", &UIWidget::removeChild); g_lua.bindClassMemberFunction<UIWidget>("removeChild", &UIWidget::removeChild);
@ -169,6 +169,7 @@ void Application::registerLuaFunctions()
g_lua.bindClassMemberFunction<UIWidget>("getAutoRepeatDelay", &UIWidget::getAutoRepeatDelay); g_lua.bindClassMemberFunction<UIWidget>("getAutoRepeatDelay", &UIWidget::getAutoRepeatDelay);
g_lua.bindClassMemberFunction<UIWidget>("getVirtualOffset", &UIWidget::getVirtualOffset); g_lua.bindClassMemberFunction<UIWidget>("getVirtualOffset", &UIWidget::getVirtualOffset);
g_lua.bindClassMemberFunction<UIWidget>("getStyleName", &UIWidget::getStyleName); g_lua.bindClassMemberFunction<UIWidget>("getStyleName", &UIWidget::getStyleName);
g_lua.bindClassMemberFunction<UIWidget>("getLastClickPosition", &UIWidget::getLastClickPosition);
g_lua.bindClassMemberFunction<UIWidget>("setX", &UIWidget::setX); g_lua.bindClassMemberFunction<UIWidget>("setX", &UIWidget::setX);
g_lua.bindClassMemberFunction<UIWidget>("setY", &UIWidget::setY); g_lua.bindClassMemberFunction<UIWidget>("setY", &UIWidget::setY);
g_lua.bindClassMemberFunction<UIWidget>("setWidth", &UIWidget::setWidth); g_lua.bindClassMemberFunction<UIWidget>("setWidth", &UIWidget::setWidth);
@ -298,8 +299,10 @@ void Application::registerLuaFunctions()
g_lua.bindClassMemberFunction<UIWidget>("setTextAlign", &UIWidget::setTextAlign); g_lua.bindClassMemberFunction<UIWidget>("setTextAlign", &UIWidget::setTextAlign);
g_lua.bindClassMemberFunction<UIWidget>("setTextOffset", &UIWidget::setTextOffset); g_lua.bindClassMemberFunction<UIWidget>("setTextOffset", &UIWidget::setTextOffset);
g_lua.bindClassMemberFunction<UIWidget>("setTextWrap", &UIWidget::setTextWrap); g_lua.bindClassMemberFunction<UIWidget>("setTextWrap", &UIWidget::setTextWrap);
g_lua.bindClassMemberFunction<UIWidget>("setTextAutoResize", &UIWidget::setTextAutoResize);
g_lua.bindClassMemberFunction<UIWidget>("setFont", &UIWidget::setFont); g_lua.bindClassMemberFunction<UIWidget>("setFont", &UIWidget::setFont);
g_lua.bindClassMemberFunction<UIWidget>("getText", &UIWidget::getText); g_lua.bindClassMemberFunction<UIWidget>("getText", &UIWidget::getText);
g_lua.bindClassMemberFunction<UIWidget>("getDrawText", &UIWidget::getDrawText);
g_lua.bindClassMemberFunction<UIWidget>("getTextAlign", &UIWidget::getTextAlign); g_lua.bindClassMemberFunction<UIWidget>("getTextAlign", &UIWidget::getTextAlign);
g_lua.bindClassMemberFunction<UIWidget>("getTextOffset", &UIWidget::getTextOffset); g_lua.bindClassMemberFunction<UIWidget>("getTextOffset", &UIWidget::getTextOffset);
g_lua.bindClassMemberFunction<UIWidget>("getTextWrap", &UIWidget::getTextWrap); g_lua.bindClassMemberFunction<UIWidget>("getTextWrap", &UIWidget::getTextWrap);

View File

@ -116,8 +116,11 @@ void UIManager::inputEvent(const InputEvent& event)
} }
case Fw::MouseMoveInputEvent: { case Fw::MouseMoveInputEvent: {
// start dragging when moving a pressed widget // start dragging when moving a pressed widget
if(m_pressedWidget && m_pressedWidget->isDragable() && m_draggingWidget != m_pressedWidget) if(m_pressedWidget && m_pressedWidget->isDragable() && m_draggingWidget != m_pressedWidget) {
updateDraggingWidget(m_pressedWidget, event.mousePos - event.mouseMoved); // only drags when moving more than 4 pixels
if((event.mousePos - m_pressedWidget->getLastClickPosition()).length() >= 4)
updateDraggingWidget(m_pressedWidget, event.mousePos - event.mouseMoved);
}
// mouse move can change hovered widgets // mouse move can change hovered widgets
updateHoveredWidget(); updateHoveredWidget();

View File

@ -1323,6 +1323,7 @@ bool UIWidget::onMousePress(const Point& mousePos, Fw::MouseButton button)
m_clickTimer.stop(); m_clickTimer.stop();
} else } else
m_clickTimer.restart(); m_clickTimer.restart();
m_lastClickPosition = mousePos;
} }
if(hasLuaField("onMousePress")) if(hasLuaField("onMousePress"))

View File

@ -43,6 +43,7 @@ struct EdgeGroup {
// generate lua bindings for this class running: // generate lua bindings for this class running:
// ./tools/lua-binding-generator/generate_lua_bindings.lua src/framework/ui/uiwidget.h // ./tools/lua-binding-generator/generate_lua_bindings.lua src/framework/ui/uiwidget.h
class UIWidget : public LuaObject class UIWidget : public LuaObject
{ {
// widget core // widget core
@ -253,6 +254,7 @@ public:
int getAutoRepeatDelay() { return m_autoRepeatDelay; } int getAutoRepeatDelay() { return m_autoRepeatDelay; }
Point getVirtualOffset() { return m_virtualOffset; } Point getVirtualOffset() { return m_virtualOffset; }
std::string getStyleName() { return m_style->tag(); } std::string getStyleName() { return m_style->tag(); }
Point getLastClickPosition() { return m_lastClickPosition; }
// base style // base style
@ -277,6 +279,7 @@ protected:
EdgeGroup<int> m_padding; EdgeGroup<int> m_padding;
float m_opacity; float m_opacity;
int m_autoRepeatDelay; int m_autoRepeatDelay;
Point m_lastClickPosition;
public: public:
void setX(int x) { move(x, getY()); } void setX(int x) { move(x, getY()); }

View File

@ -50,7 +50,12 @@ void UIWidget::updateText()
newSize.setHeight(textSize.height()); newSize.setHeight(textSize.height());
setSize(newSize); setSize(newSize);
} else if(m_textAutoResize) { } else if(m_textAutoResize) {
setSize(getTextSize()); Size textSize = getTextSize();
Size size = getSize();
if(textSize.width() > size.width())
size.setWidth(textSize.width());
size.setHeight(textSize.height());
setSize(size);
} }
m_textMustRecache = true; m_textMustRecache = true;