added slider, mouse capture in Node, desaturated icons
This commit is contained in:
@@ -51,6 +51,7 @@ enum class kWidget : uint16_t
|
||||
Icon = const_hash("icon"),
|
||||
Button = const_hash("button"),
|
||||
ButtonCustom = const_hash("button-custom"),
|
||||
SliderCursor = const_hash("slider-cursor"),
|
||||
PopupMenu = const_hash("popup-menu"),
|
||||
Viewport = const_hash("viewport"),
|
||||
Ref = const_hash("ref"),
|
||||
@@ -126,6 +127,8 @@ public:
|
||||
uint16_t m_nodeID;
|
||||
std::string m_nodeID_s;
|
||||
std::vector<std::unique_ptr<Node>> m_children;
|
||||
Node* current_mouse_capture = nullptr;
|
||||
bool m_mouse_captured = false;
|
||||
|
||||
glm::mat4 m_proj;
|
||||
glm::mat4 m_mvp;
|
||||
@@ -204,6 +207,11 @@ public:
|
||||
void SetPositioning(YGPositionType value) { YGNodeStyleSetPositionType(y_node, value); }
|
||||
void SetAspectRatio(float ar) { YGNodeStyleSetAspectRatio(y_node, ar); }
|
||||
|
||||
glm::vec2 GetPosition() { return{ YGNodeLayoutGetLeft(y_node), YGNodeLayoutGetTop(y_node) }; }
|
||||
float GetWidth() { return YGNodeLayoutGetWidth(y_node); }
|
||||
float GetHeight() { return YGNodeLayoutGetHeight(y_node); }
|
||||
glm::vec2 GetSize() { return { GetWidth(), GetHeight() }; }
|
||||
|
||||
glm::vec4 rect_intersection(glm::vec4 a, glm::vec4 b)
|
||||
{
|
||||
// convert from [x,y,w,h] to [x1,y1,x2,y1]
|
||||
@@ -257,6 +265,8 @@ public:
|
||||
virtual void loaded() { }
|
||||
void add_child(Node* n);
|
||||
void remove_child(Node* n);
|
||||
void mouse_capture() { root()->current_mouse_capture = this; m_mouse_captured = true; }
|
||||
void mouse_release() { root()->current_mouse_capture = nullptr; m_mouse_captured = false; }
|
||||
|
||||
// class iterator
|
||||
// {
|
||||
@@ -876,3 +886,47 @@ public:
|
||||
return kEventResult::Consumed;
|
||||
}
|
||||
};
|
||||
|
||||
class NodeSliderCursor : public NodeButtonCustom
|
||||
{
|
||||
public:
|
||||
glm::vec2 drag_start;
|
||||
glm::vec2 drag_diff;
|
||||
bool dragging = false;
|
||||
glm::vec2 old_pos;
|
||||
virtual Node* clone_instantiate() const override { return new NodeSliderCursor(); }
|
||||
virtual void clone_copy(Node* dest) const override
|
||||
{
|
||||
NodeButtonCustom::clone_copy(dest);
|
||||
NodeSliderCursor* n = static_cast<NodeSliderCursor*>(dest);
|
||||
}
|
||||
virtual kEventResult handle_event(Event* e) override
|
||||
{
|
||||
NodeBorder::handle_event(e);
|
||||
switch (e->m_type)
|
||||
{
|
||||
case kEventType::MouseDownL:
|
||||
drag_start = ((MouseEvent*)e)->m_pos;
|
||||
dragging = true;
|
||||
mouse_capture();
|
||||
break;
|
||||
case kEventType::MouseUpL:
|
||||
mouse_release();
|
||||
dragging = false;
|
||||
break;
|
||||
case kEventType::MouseMove:
|
||||
if (dragging)
|
||||
{
|
||||
float pw = parent->GetWidth();
|
||||
float w = GetWidth();
|
||||
drag_diff = ((MouseEvent*)e)->m_pos - drag_start;
|
||||
float x = glm::clamp<float>(drag_diff.x, 0, pw - w);
|
||||
SetPosition(x, 0);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return kEventResult::Consumed;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user