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