reorder tool icons, add popup auto-hide after interaction

This commit is contained in:
2019-03-06 18:43:38 +01:00
parent 99929dac39
commit 5eba9f1227
8 changed files with 74 additions and 13 deletions

View File

@@ -1617,25 +1617,25 @@ Here's a list of what's available in this release.
<image path="data/ui/eraser.png" width="100%" height="100%" align="center" justify="flex-end"/>
</button-custom>
<button id="btn-cam" width="40" height="40" margin="2 0 2 5" text="Cam"/>
<button-custom id="btn-bucket" width="40" height="40" margin="2 0 2 5" thickness="1" border-color="0 0 0 1" pad="2">
<image path="data/ui/bucket.png" width="100%" height="100%" align="center" justify="flex-end"/>
</button-custom>
<button-custom id="btn-line" width="40" height="40" margin="2 0 2 5" thickness="1" border-color="0 0 0 1" pad="2">
<image path="data/ui/line.png" width="100%" height="100%" align="center" justify="flex-end"/>
</button-custom>
<button id="btn-grid" width="40" height="40" margin="2 0 2 5" text="Grid"/>
<button id="btn-copy" width="40" height="40" margin="2 0 2 5" text="Copy"/>
<button id="btn-cut" width="40" height="40" margin="2 0 2 5" text="Cut"/>
<!-- <button id="btn-fill" width="40" height="40" margin="0" text="Fill"/> -->
<button-custom id="btn-mask-free" width="40" height="40" margin="2 0 2 5" thickness="1" border-color="0 0 0 1" pad="2">
<image path="data/ui/sel-free.png" width="100%" height="100%" align="center" justify="flex-end"/>
</button-custom>
<button-custom id="btn-mask-line" width="40" height="40" margin="2 0 2 5" thickness="1" border-color="0 0 0 1" pad="2">
<image path="data/ui/sel-poly.png" width="100%" height="100%" align="center" justify="flex-end"/>
</button-custom>
<button id="btn-copy" width="40" height="40" margin="2 0 2 5" text="Copy"/>
<button id="btn-cut" width="40" height="40" margin="2 0 2 5" text="Cut"/>
<!-- <button id="btn-fill" width="40" height="40" margin="0" text="Fill"/> -->
<button-custom id="btn-bucket" width="40" height="40" margin="2 0 2 5" thickness="1" border-color="0 0 0 1" pad="2">
<image path="data/ui/bucket.png" width="100%" height="100%" align="center" justify="flex-end"/>
</button-custom>
<button id="btn-cam" width="40" height="40" margin="2 0 2 5" text="Cam"/>
<button id="btn-grid" width="40" height="40" margin="2 0 2 5" text="Grid"/>
<button-custom id="btn-touchlock" width="40" height="40" margin="2 0 2 5" thickness="1" border-color="0 0 0 1" pad="2">
<image path="data/ui/notouch.png" width="100%" height="100%" align="center" justify="flex-end"/>
</button-custom>

View File

@@ -114,12 +114,33 @@ kEventResult Node::on_event(Event* e)
}
else
{
return kEventResult::Consumed;
ret = kEventResult::Consumed;
break;
}
}
}
if (ret == kEventResult::Consumed)
return ret;
{
if (e->m_cat == kEventCategory::MouseEvent)
{
MouseEvent* me = static_cast<MouseEvent*>(e);
bool old_inside = m_mouse_inside;
m_mouse_inside = point_in_rect(me->m_pos, m_clip);
if (old_inside == false && m_mouse_inside == true)
{
MouseEvent e2 = *me;
e2.m_type = kEventType::MouseEnter;
handle_event(&e2);
}
if (old_inside == true && m_mouse_inside == false)
{
MouseEvent e2 = *me;
e2.m_type = kEventType::MouseLeave;
handle_event(&e2);
}
}
return kEventResult::Consumed;
}
}
switch (e->m_cat)

View File

@@ -36,15 +36,19 @@ void NodeColorPicker::draw()
// m_wheel->m_hsv = hsv;
}
void NodeColorPicker::handle_value_changed()
void NodeColorPicker::added(Node* parent)
{
m_interacted = false;
}
kEventResult NodeColorPicker::handle_event(Event* e)
{
switch (e->m_type)
{
case kEventType::MouseLeave:
if (!m_interacted)
break;
// else fall through
case kEventType::MouseUpL:
if (!m_mouse_inside)
{
@@ -93,6 +97,7 @@ void NodeColorPicker::init_controls()
m_color_cur->m_color = { rgb, 1 };
if (on_color_change)
on_color_change(this, rgb);
m_interacted = true;
};
auto hsv_setter = [this](Node* target, float v)
{
@@ -105,6 +110,7 @@ void NodeColorPicker::init_controls()
m_slider_b->m_value = rgb.z;
if (on_color_change)
on_color_change(this, rgb);
m_interacted = true;
};
m_slider_h->on_value_changed = hsv_setter;
m_slider_s->on_value_changed = hsv_setter;
@@ -121,6 +127,7 @@ void NodeColorPicker::init_controls()
m_slider_v->set_value(hsv.z);
if (on_color_change)
on_color_change(this, rgb);
m_interacted = true;
};
m_slider_r->on_value_changed = rgb_setter;
m_slider_g->on_value_changed = rgb_setter;

View File

@@ -11,6 +11,7 @@ public:
std::function<void(Node* target)> on_popup_close;
std::function<void(Node* target, glm::vec3 rgb)> on_color_change;
bool m_interacted = false;
NodeSliderH* m_slider_h;
NodeSliderH* m_slider_s;
NodeSliderH* m_slider_v;
@@ -31,9 +32,9 @@ public:
virtual void init() override;
virtual void draw() override;
virtual kEventResult handle_event(Event* e) override;
virtual void added(Node* parent) override;
void init_controls();
void set_color(glm::vec3 rgb);
glm::vec3 get_hsv() const;
glm::vec3 get_rgb() const;
void handle_value_changed();
};

View File

@@ -191,6 +191,10 @@ kEventResult NodePanelBrush::handle_event(Event* e)
{
switch (e->m_type)
{
case kEventType::MouseLeave:
if (!m_interacted)
break;
// else fall through
case kEventType::MouseUpL:
if (!m_mouse_inside)
{
@@ -217,6 +221,7 @@ void NodePanelBrush::handle_click(Node* target)
m_current->m_selected = true;
if (on_brush_changed)
on_brush_changed(this, m_container->get_child_index(target));
m_interacted = true;
}
int NodePanelBrush::find_brush(const std::string & name) const
@@ -330,6 +335,11 @@ bool NodePanelBrush::restore()
return false;
}
void NodePanelBrush::added(Node* parent)
{
m_interacted = false;
}
// -----------------------------------------------------------------------
Node* NodeBrushPresetItem::clone_instantiate() const
@@ -426,6 +436,10 @@ kEventResult NodePanelBrushPreset::handle_event(Event* e)
{
switch (e->m_type)
{
case kEventType::MouseLeave:
if (!m_interacted)
break;
// else fall through
case kEventType::MouseUpL:
if (!m_mouse_inside)
{
@@ -452,6 +466,7 @@ void NodePanelBrushPreset::handle_click(Node* target)
m_current->m_selected = true;
if (on_brush_changed)
on_brush_changed(this, m_current->m_brush);
m_interacted = true;
}
bool NodePanelBrushPreset::save()
@@ -704,3 +719,8 @@ void NodePanelBrushPreset::add_brush(std::shared_ptr<Brush> brush)
b->m_caption_size->set_text_format("%d", (int)brush->m_tip_size);
b->on_click = std::bind(&NodePanelBrushPreset::handle_click, this, std::placeholders::_1);
}
void NodePanelBrushPreset::added(Node* parent)
{
m_interacted = false;
}

View File

@@ -33,6 +33,7 @@ class NodePanelBrush : public Node
NodeButtonCustom* m_btn_up;
NodeButtonCustom* m_btn_down;
NodeButtonCustom* m_btn_remove;
bool m_interacted = false;
struct header_t {
char magic[5]{ 'P', 'P', 'B', 'R', 0 };
uint16_t version = 0;
@@ -55,6 +56,7 @@ public:
virtual Node* clone_instantiate() const override;
virtual void init() override;
virtual kEventResult handle_event(Event* e) override;
virtual void added(Node* parent) override;
void handle_click(Node* target);
int find_brush(const std::string& name) const;
std::string get_texture_path(int index) const;
@@ -82,6 +84,7 @@ public:
class NodePanelBrushPreset : public Node
{
bool m_interacted = false;
NodeBrushPresetItem* m_current = nullptr;
NodeButtonCustom* m_btn_add;
NodeButtonCustom* m_btn_up;
@@ -179,6 +182,7 @@ public:
virtual Node* clone_instantiate() const override;
virtual void init() override;
virtual kEventResult handle_event(Event* e) override;
virtual void added(Node* parent) override;
void handle_click(Node* target);
bool save();
bool restore();

View File

@@ -31,6 +31,7 @@ void NodePanelColor::init_controls()
m_quad->m_color = hue_color;
if (on_color_changed)
on_color_changed(this, m_color);
m_interacted = true;
};
m_quad->on_value_changed = [this](Node*, glm::vec2 pos)
{
@@ -39,6 +40,7 @@ void NodePanelColor::init_controls()
m_color = glm::vec4(convert_hsv2rgb(glm::vec3(hue, m_cursor.x, 1.f-m_cursor.y)), 1.f);
if (on_color_changed)
on_color_changed(this, m_color);
m_interacted = true;
};
m_hue->set_value(0);
}
@@ -57,6 +59,10 @@ kEventResult NodePanelColor::handle_event(Event* e)
{
switch (e->m_type)
{
case kEventType::MouseLeave:
if (!m_interacted)
break;
// else fall through
case kEventType::MouseUpL:
if (!m_mouse_inside)
{
@@ -76,4 +82,5 @@ kEventResult NodePanelColor::handle_event(Event* e)
void NodePanelColor::added(Node* parent)
{
set_color(Canvas::I->m_current_brush->m_tip_color);
m_interacted = false;
}

View File

@@ -6,6 +6,7 @@
class NodePanelColor : public Node
{
public:
bool m_interacted = false;
NodeColorQuad* m_quad;
NodeSliderHue* m_hue;
glm::vec4 m_base_color;