item menu example
This commit is contained in:
parent
48c22756f5
commit
ca702109d6
|
@ -130,4 +130,9 @@ KeyF12 = 140
|
|||
KeyboardNoModifier = 0
|
||||
KeyboardCtrlModifier = 1
|
||||
KeyboardAltModifier = 2
|
||||
KeyboardShiftModifier = 4
|
||||
KeyboardShiftModifier = 4
|
||||
|
||||
MouseNoButton = 0
|
||||
MouseLeftButton = 1
|
||||
MouseRightButton = 2
|
||||
MouseMidButton = 3
|
|
@ -48,4 +48,19 @@ TopButton < UIButton
|
|||
border: 3
|
||||
|
||||
state.disabled:
|
||||
background-color: #ffffff66
|
||||
background-color: #ffffff66
|
||||
|
||||
MenuButton < UIButton
|
||||
color: white
|
||||
size: 40 18
|
||||
align: center
|
||||
border-image:
|
||||
source: /core_styles/images/menu.png
|
||||
size: 64 24
|
||||
|
||||
state.hover:
|
||||
border-image:
|
||||
source: /core_styles/images/menu.png
|
||||
offset: 0 24
|
||||
size: 64 24
|
||||
color: black
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
Item < UIItem
|
||||
size: 34 34
|
||||
item margin: 1
|
||||
item margin: 1
|
||||
border-image:
|
||||
source: /core_styles/images/panel_flat.png
|
||||
border: 4
|
||||
|
|
|
@ -4,67 +4,68 @@ UIWindow
|
|||
margin.left: 6
|
||||
margin.right: 6
|
||||
move policy: free updated
|
||||
|
||||
|
||||
Item
|
||||
id: head
|
||||
anchors.top: parent.top
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
|
||||
popup menu: /inventory/itempopupmenu.otui
|
||||
|
||||
Item
|
||||
id: armor
|
||||
anchors.top: prev.bottom
|
||||
anchors.horizontalCenter: prev.horizontalCenter
|
||||
margin.top: 10
|
||||
|
||||
|
||||
Item
|
||||
id: legs
|
||||
anchors.top: prev.bottom
|
||||
anchors.horizontalCenter: prev.horizontalCenter
|
||||
margin.top: 10
|
||||
|
||||
|
||||
Item
|
||||
id: feet
|
||||
anchors.top: prev.bottom
|
||||
anchors.horizontalCenter: prev.horizontalCenter
|
||||
margin.top: 10
|
||||
|
||||
|
||||
Item
|
||||
id: necklace
|
||||
anchors.top: parent.top
|
||||
anchors.right: head.left
|
||||
margin.top: 15
|
||||
margin.right: 10
|
||||
|
||||
|
||||
Item
|
||||
id: left
|
||||
anchors.top: prev.bottom
|
||||
anchors.horizontalCenter: prev.horizontalCenter
|
||||
margin.top: 10
|
||||
|
||||
|
||||
Item
|
||||
id: ring
|
||||
anchors.top: prev.bottom
|
||||
anchors.horizontalCenter: prev.horizontalCenter
|
||||
margin.top: 10
|
||||
|
||||
|
||||
Item
|
||||
id: backpack
|
||||
anchors.top: parent.top
|
||||
anchors.left: head.right
|
||||
margin.top: 15
|
||||
margin.left: 10
|
||||
|
||||
|
||||
Item
|
||||
id: right
|
||||
anchors.top: prev.bottom
|
||||
anchors.horizontalCenter: prev.horizontalCenter
|
||||
margin.top: 10
|
||||
|
||||
|
||||
Item
|
||||
id: ammo
|
||||
anchors.top: prev.bottom
|
||||
anchors.horizontalCenter: prev.horizontalCenter
|
||||
margin.top: 10
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ Panel
|
|||
size: 64 48
|
||||
|
||||
MenuButton
|
||||
text: New
|
||||
text: Foo
|
||||
|
||||
MenuButton
|
||||
text: Quit
|
|
@ -1,29 +0,0 @@
|
|||
MenuButton < UIButton
|
||||
color: white
|
||||
size: 40 18
|
||||
align: center
|
||||
border-image:
|
||||
source: /core_styles/images/menu.png
|
||||
size: 64 24
|
||||
|
||||
state.hover:
|
||||
border-image:
|
||||
source: /core_styles/images/menu.png
|
||||
offset: 0 24
|
||||
size: 64 24
|
||||
color: black
|
||||
|
||||
TopMenuButton < MenuButton
|
||||
onMousePress: |
|
||||
function(self, mousePos, mouseButton)
|
||||
local popupMenu = UI.loadAndDisplay(self:getStyle()['popup menu'])
|
||||
if popupMenu then
|
||||
popupMenu:moveTo({ x = self:getX(), y = self:getY() + self:getHeight()})
|
||||
popupMenu.onMouseRelease = function(self) self:destroy() end
|
||||
end
|
||||
end
|
||||
|
||||
TopMenuButton
|
||||
text: File
|
||||
position: 80 0
|
||||
popup menu: /playground/filemenu.otui
|
|
@ -1,10 +1,24 @@
|
|||
-- place any code for testing purposes here
|
||||
|
||||
function displayMenuPopup(file, parent)
|
||||
function UIItem.onMouseRelease(self, mousePos, mouseButton)
|
||||
if mouseButton ~= MouseRightButton then return end
|
||||
local top = self:getY()
|
||||
local bottom = self:getY() + self:getHeight()
|
||||
local left = self:getX()
|
||||
local right = self:getX() + self:getWidth()
|
||||
if not (mousePos.y >= top and mousePos.y <= bottom and mousePos.x >= left and mousePos.x <= right) then return end
|
||||
|
||||
local menuFile = self:getStyle()['popup menu']
|
||||
if not menuFile then return end
|
||||
|
||||
local popupMenu = UI.loadAndDisplay(menuFile)
|
||||
if not popupMenu then return end
|
||||
|
||||
popupMenu:moveTo(mousePos)
|
||||
popupMenu.onMouseRelease = function(self) self:destroy() end
|
||||
end
|
||||
|
||||
local function init()
|
||||
UI.loadAndDisplay('/playground/menubar.otui')
|
||||
end
|
||||
|
||||
addEvent(init)
|
|
@ -57,12 +57,10 @@ void UIButton::onStyleApply(const OTMLNodePtr& styleNode)
|
|||
}
|
||||
}
|
||||
|
||||
bool UIButton::onMouseRelease(const Point& mousePos, Fw::MouseButton button)
|
||||
void UIButton::onMouseRelease(const Point& mousePos, Fw::MouseButton button)
|
||||
{
|
||||
if(isPressed()) {
|
||||
if(m_onClick && getRect().contains(mousePos))
|
||||
m_onClick();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ public:
|
|||
|
||||
protected:
|
||||
virtual void onStyleApply(const OTMLNodePtr& styleNode);
|
||||
virtual bool onMouseRelease(const Point& mousePos, Fw::MouseButton button);
|
||||
virtual void onMouseRelease(const Point& mousePos, Fw::MouseButton button);
|
||||
|
||||
SimpleCallback m_onClick;
|
||||
Point m_textTranslate;
|
||||
|
|
|
@ -44,10 +44,15 @@ public:
|
|||
UIWidgetPtr loadUI(const std::string& file, const UIWidgetPtr& parent = nullptr);
|
||||
UIWidgetPtr loadWidgetFromOTML(const OTMLNodePtr& widgetNode, const UIWidgetPtr& parent);
|
||||
|
||||
//void setMouseGrabWidget();
|
||||
//void setKeyboardGrabWidget();
|
||||
|
||||
UIWidgetPtr getRootWidget() { return m_rootWidget; }
|
||||
|
||||
private:
|
||||
UIWidgetPtr m_rootWidget;
|
||||
//UIWidgetPtr m_mouseGrabWidget;
|
||||
//UIWidgetPtr m_keyboardGrabWidget;
|
||||
std::map<std::string, OTMLNodePtr> m_styles;
|
||||
};
|
||||
|
||||
|
|
|
@ -909,7 +909,7 @@ void UIWidget::onHoverChange(bool hovered)
|
|||
callLuaField("onHoverChange", hovered);
|
||||
|
||||
// check for new hovered elements when the current widget is removed
|
||||
if(!hovered && !getParent())
|
||||
if(!hovered && !getParent() && g_ui.getRootWidget())
|
||||
g_ui.getRootWidget()->updateState(Fw::HoverState);
|
||||
}
|
||||
|
||||
|
@ -1000,10 +1000,9 @@ bool UIWidget::onMousePress(const Point& mousePos, Fw::MouseButton button)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool UIWidget::onMouseRelease(const Point& mousePos, Fw::MouseButton button)
|
||||
void UIWidget::onMouseRelease(const Point& mousePos, Fw::MouseButton button)
|
||||
{
|
||||
if(callLuaField<bool>("onMouseRelease", mousePos, button))
|
||||
return true;
|
||||
callLuaField("onMouseRelease", mousePos, button);
|
||||
|
||||
// do a backup of children list, because it may change while looping it
|
||||
UIWidgetList children;
|
||||
|
@ -1017,16 +1016,11 @@ bool UIWidget::onMouseRelease(const Point& mousePos, Fw::MouseButton button)
|
|||
}
|
||||
|
||||
for(const UIWidgetPtr& child : children) {
|
||||
bool mustEnd = child->onMouseRelease(mousePos, button);
|
||||
child->onMouseRelease(mousePos, button);
|
||||
|
||||
if(child->isPressed())
|
||||
child->setPressed(false);
|
||||
|
||||
if(mustEnd)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UIWidget::onMouseMove(const Point& mousePos, const Point& mouseMoved)
|
||||
|
|
|
@ -173,7 +173,7 @@ protected:
|
|||
/// Triggered when a mouse button is pressed down while mouse pointer is inside widget area
|
||||
virtual bool onMousePress(const Point& mousePos, Fw::MouseButton button);
|
||||
/// Triggered when a mouse button is released
|
||||
virtual bool onMouseRelease(const Point& mousePos, Fw::MouseButton button);
|
||||
virtual void onMouseRelease(const Point& mousePos, Fw::MouseButton button);
|
||||
/// Triggered when mouse moves (even when the mouse is outside widget area)
|
||||
virtual bool onMouseMove(const Point& mousePos, const Point& mouseMoved);
|
||||
/// Triggered when mouse middle button wheels inside widget area
|
||||
|
|
|
@ -120,7 +120,7 @@ bool UIWindow::onMousePress(const Point& mousePos, Fw::MouseButton button)
|
|||
return UIWidget::onMousePress(mousePos, button);
|
||||
}
|
||||
|
||||
bool UIWindow::onMouseRelease(const Point& mousePos, Fw::MouseButton button)
|
||||
void UIWindow::onMouseRelease(const Point& mousePos, Fw::MouseButton button)
|
||||
{
|
||||
if(m_moving) {
|
||||
if(m_movePolicy == FREE_UPDATED_MOVE) {
|
||||
|
@ -143,9 +143,8 @@ bool UIWindow::onMouseRelease(const Point& mousePos, Fw::MouseButton button)
|
|||
updateParentLayout();
|
||||
}
|
||||
m_moving = false;
|
||||
return true;
|
||||
}
|
||||
return UIWidget::onMouseRelease(mousePos, button);
|
||||
UIWidget::onMouseRelease(mousePos, button);
|
||||
}
|
||||
|
||||
bool UIWindow::onMouseMove(const Point& mousePos, const Point& mouseMoved)
|
||||
|
|
|
@ -44,7 +44,7 @@ protected:
|
|||
virtual void onStyleApply(const OTMLNodePtr& styleNode);
|
||||
virtual void onGeometryUpdate(const Rect& oldRect, const Rect& newRect);
|
||||
virtual bool onMousePress(const Point& mousePos, Fw::MouseButton button);
|
||||
virtual bool onMouseRelease(const Point& mousePos, Fw::MouseButton button);
|
||||
virtual void onMouseRelease(const Point& mousePos, Fw::MouseButton button);
|
||||
virtual bool onMouseMove(const Point& mousePos, const Point& mouseMoved);
|
||||
virtual bool onKeyPress(uchar keyCode, char keyChar, int keyboardModifiers);
|
||||
|
||||
|
|
Loading…
Reference in New Issue