settings menu update + UINode 'enabled' property
This commit is contained in:
@@ -79,7 +79,11 @@ void Button::drawBackground(const DrawContext* pctx, Assets* assets) {
|
||||
glm::vec2 pos = calcPos();
|
||||
auto batch = pctx->getBatch2D();
|
||||
batch->texture(nullptr);
|
||||
batch->setColor(isPressed() ? pressedColor : (hover ? hoverColor : color));
|
||||
if (enabled) {
|
||||
batch->setColor(isPressed() ? pressedColor : (hover ? hoverColor : color));
|
||||
} else {
|
||||
batch->setColor({color.r, color.g, color.b, color.a * 0.5f});
|
||||
}
|
||||
batch->rect(pos.x, pos.y, size.x, size.y);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ Container::Container(glm::vec2 size) : UINode(size) {
|
||||
}
|
||||
|
||||
std::shared_ptr<UINode> Container::getAt(glm::vec2 pos, std::shared_ptr<UINode> self) {
|
||||
if (!interactive) {
|
||||
if (!interactive || !enabled) {
|
||||
return nullptr;
|
||||
}
|
||||
if (!isInside(pos)) return nullptr;
|
||||
|
||||
@@ -20,6 +20,18 @@ void UINode::setVisible(bool flag) {
|
||||
visible = flag;
|
||||
}
|
||||
|
||||
void UINode::setEnabled(bool flag) {
|
||||
enabled = flag;
|
||||
if (!flag) {
|
||||
defocus();
|
||||
hover = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool UINode::isEnabled() const {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
Align UINode::getAlign() const {
|
||||
return align;
|
||||
}
|
||||
@@ -82,7 +94,7 @@ bool UINode::isInside(glm::vec2 point) {
|
||||
}
|
||||
|
||||
std::shared_ptr<UINode> UINode::getAt(glm::vec2 point, std::shared_ptr<UINode> self) {
|
||||
if (!interactive) {
|
||||
if (!interactive || !enabled) {
|
||||
return nullptr;
|
||||
}
|
||||
return isInside(point) ? self : nullptr;
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
#ifndef GRAPHICS_UI_ELEMENTS_UINODE_H_
|
||||
#define GRAPHICS_UI_ELEMENTS_UINODE_H_
|
||||
|
||||
#include "../../../delegates.h"
|
||||
#include "../../../window/input.h"
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <unordered_map>
|
||||
#include "../../../delegates.h"
|
||||
#include "../../../window/input.h"
|
||||
|
||||
class DrawContext;
|
||||
class Assets;
|
||||
@@ -60,6 +61,8 @@ namespace gui {
|
||||
glm::vec4 pressedColor {1.0f};
|
||||
/// @brief element margin (only supported for Panel sub-nodes)
|
||||
glm::vec4 margin {1.0f};
|
||||
/// @brief element enabled state
|
||||
bool enabled = true;
|
||||
/// @brief is element visible
|
||||
bool visible = true;
|
||||
/// @brief is mouse over the element
|
||||
@@ -95,6 +98,9 @@ namespace gui {
|
||||
virtual void setVisible(bool flag);
|
||||
bool isVisible() const;
|
||||
|
||||
virtual void setEnabled(bool flag);
|
||||
bool isEnabled() const;
|
||||
|
||||
virtual void setAlign(Align align);
|
||||
Align getAlign() const;
|
||||
|
||||
|
||||
@@ -87,6 +87,9 @@ static void _readUINode(UiXmlReader& reader, xml::xmlelement element, UINode& no
|
||||
if (element->has("visible")) {
|
||||
node.setVisible(element->attr("visible").asBool());
|
||||
}
|
||||
if (element->has("enabled")) {
|
||||
node.setEnabled(element->attr("enabled").asBool());
|
||||
}
|
||||
if (element->has("position-func")) {
|
||||
node.setPositionFunc(scripting::create_vec2_supplier(
|
||||
reader.getEnvironment(),
|
||||
|
||||
@@ -304,6 +304,9 @@ static int l_gui_getattr(lua_State* L) {
|
||||
} else if (attr == "visible") {
|
||||
lua_pushboolean(L, node->isVisible());
|
||||
return 1;
|
||||
} else if (attr == "enabled") {
|
||||
lua_pushboolean(L, node->isEnabled());
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (getattr(L, dynamic_cast<Container*>(node), attr))
|
||||
@@ -350,6 +353,8 @@ static int l_gui_setattr(lua_State* L) {
|
||||
node->setInteractive(lua_toboolean(L, 4));
|
||||
} else if (attr == "visible") {
|
||||
node->setVisible(lua_toboolean(L, 4));
|
||||
} else if (attr == "enabled") {
|
||||
node->setEnabled(lua_toboolean(L, 4));
|
||||
} else {
|
||||
if (setattr(L, dynamic_cast<Button*>(node), attr))
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user