testing color picker

This commit is contained in:
2019-03-03 23:09:43 +01:00
parent 91ce555c0a
commit 312cfe1ee2
10 changed files with 78 additions and 10 deletions

View File

@@ -87,6 +87,9 @@
<!--brush-presets-item icon-->
<layout id="tpl-brush-preset">
<button-custom width="300" height="70" margin="1" pad="5" align="center" justify="center" dir="row">
<node width="30" align="center">
<checkbox icon="data/ui/check-lock-transparency.png" width="20" height="20" pad="0"/>
</node>
<border color="1" width="40" height="60" align="center" justify="center" dir="col">
<image id="thumb" width="40" height="40"/>
<text id="caption-size" text="000" color="0" margin="3 0 0 0"/>
@@ -746,15 +749,14 @@
<!-- Color Picker Dialog -->
<layout id="color-picker">
<border positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center">
<border thickness="1" border-color=".2" pad="3">
<border width="300" height="30" color=".2 .2 .2 .9" dir="row" align="center">
<border positioning="absolute" position="0 0">
<!--<border width="300" height="30" color=".2 .2 .2 .9" dir="row" align="center">
<node grow="1" width="10" align="center">
<text id="title" text="Color Picker"/>
</node>
<!--<combobox justify="flex-end" pad="5" margin="0 5 0 0" text="Triangle" combo-list="Triangle,Square" default="0"/>-->
</border>
<border width="300" color=".5 .5 .5 .9" pad="10" dir="col">
--><!--<combobox justify="flex-end" pad="5" margin="0 5 0 0" text="Triangle" combo-list="Triangle,Square" default="0"/>--><!--
</border>-->
<border width="300" color=".4" pad="10" dir="col">
<colorwheel id="wheel" width="100%" aspect-ratio="1"/>
<border color="1" pad="5" dir="row" margin="10 0 0 0">
<border border-color="0 0 0 1" thickness="1" id="color-cur" height="30" grow="1" color="1"/>
@@ -789,7 +791,6 @@
<button id="btn-select" text="Select color" width="100" height="30"/>
</node>
</border>
</border>
</layout>
<!-- Dialog Rename Layer -->
@@ -1643,6 +1644,5 @@ Here's a list of what's available in this release.
<image-texture id="tex-debug" width="100%" height="100%"></image-texture>
</border>
-->
<!-- <color-picker/> -->
</layout>
</root>

View File

Before

Width:  |  Height:  |  Size: 162 KiB

After

Width:  |  Height:  |  Size: 162 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -86,6 +86,9 @@ void NodeCheckBox::parse_attributes(kAttribute ka, const tinyxml2::XMLAttribute*
{
switch (ka)
{
case kAttribute::Padding:
m_outer->parse_attributes(ka, attr);
break;
case kAttribute::Icon:
m_icon_path = attr->Value();
break;

View File

@@ -41,6 +41,25 @@ void NodeColorPicker::handle_value_changed()
}
kEventResult NodeColorPicker::handle_event(Event* e)
{
switch (e->m_type)
{
case kEventType::MouseUpL:
if (!m_mouse_inside)
{
mouse_release();
parent->remove_child(this);
if (on_popup_close)
on_popup_close(this);
}
break;
default:
return kEventResult::Available;
break;
}
}
void NodeColorPicker::init_controls()
{
m_slider_h = find<NodeSliderH>("hsv-h");

View File

@@ -1,3 +1,4 @@
#pragma once
#include "node.h"
#include "node_border.h"
#include "node_slider.h"
@@ -7,6 +8,8 @@
class NodeColorPicker : public NodeBorder
{
public:
std::function<void(Node* target)> on_popup_close;
NodeSliderH* m_slider_h;
NodeSliderH* m_slider_s;
NodeSliderH* m_slider_v;
@@ -27,6 +30,7 @@ public:
virtual void clone_finalize(Node* dest) const override;
virtual void init() override;
virtual void draw() override;
virtual kEventResult handle_event(Event* e) override;
void init_controls();
glm::vec3 get_hsv() const;
void handle_value_changed();

View File

@@ -1,6 +1,7 @@
#include "pch.h"
#include "node_panel_quick.h"
#include "node_stroke_preview.h"
#include "node_image.h"
Node* NodePanelQuick::clone_instantiate() const
{
@@ -25,7 +26,45 @@ void NodePanelQuick::init_controls()
{
auto s = find<NodeStrokePreview>("quick-brush1");
s->m_brush = std::make_shared<Brush>();
s->m_brush->m_tip_size = 10;
s->m_max_size = 10;
s->m_brush->load_tip("data/brushes/Round-Hard.png", "data/brushes/thumbs/Round-Hard.png");
s->draw_stroke();
m_picker = std::make_shared<NodeColorPicker>();
m_picker->m_manager = m_manager;
m_picker->init();
m_picker->create();
m_picker->loaded();
m_picker->m_mouse_ignore = false;
m_picker->m_flood_events = true;
m_picker->m_capture_children = false;
if (auto b = find<NodeButtonCustom>("quick-color1"))
{
b->on_click = [this,b](Node*) {
auto screen = root()->m_size;
glm::vec2 pos = b->m_pos + glm::vec2(b->m_size.x, 0);
root()->add_child(m_picker);
auto tick = root()->add_child<NodeImage>();
tick->SetPositioning(YGPositionTypeAbsolute);
tick->SetSize(16, 32);
tick->SetPosition(pos.x, pos.y + (b->m_size.y - 32) * 0.5f);
tick->set_image("data/ui/popup-tick.png");
//float hh = m_picker->m_container->m_children.size() > 10 ? App::I.height / App::I.zoom * .75f : 400.f;
//m_picker->SetHeight(4);
root()->update();
pos.y -= 130;
if ((pos.y + m_picker->m_size.y) > screen.y)
pos.y = screen.y - m_picker->m_size.y;
if (pos.y < 0)
pos.y = 0;
m_picker->SetPosition(pos.x + 16, pos.y);
m_picker->mouse_capture();
root()->update();
m_picker->on_popup_close = [this, tick](Node*) {
tick->destroy();
};
};
}
}

View File

@@ -2,6 +2,7 @@
#include "node.h"
#include "node_button_custom.h"
#include "node_border.h"
#include "node_dialog_picker.h"
class NodePanelQuick : public NodeBorder
{
@@ -13,6 +14,7 @@ public:
NodeButtonCustom* m_button_color1;
NodeButtonCustom* m_button_color2;
NodeButtonCustom* m_button_color3;
std::shared_ptr<NodeColorPicker> m_picker;
virtual Node* clone_instantiate() const override;
virtual void clone_finalize(Node* dest) const override;
virtual void init() override;

View File

@@ -262,7 +262,7 @@ void NodeStrokePreview::draw_stroke_immediate()
const auto& b = m_brush;
m_stroke.m_filter_points = false;
m_stroke.m_max_size = m_size.y * .75f;
m_stroke.m_max_size = m_max_size > 0 ? m_max_size : m_size.y * .75f;
m_stroke.m_camera.fov = Canvas::I->m_cam_fov;
m_stroke.m_camera.rot = Canvas::I->m_cam_rot;
m_stroke.reset(true);

View File

@@ -37,6 +37,7 @@ public:
Stroke m_dual_stroke;
std::vector<glm::vec2> m_bez_points;
float m_min_flow = 0.f;
float m_max_size = 0.f;
virtual Node* clone_instantiate() const override;
virtual void clone_copy(Node* dest) const override;
virtual void clone_children(Node* dest) const override;