added bucket options tool
This commit is contained in:
@@ -1577,7 +1577,7 @@ void CanvasModeFloodFill::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
|
||||
std::map<int, std::unique_ptr<bool[]>> plane_mask;
|
||||
std::unique_ptr<glm::vec4> color;
|
||||
Canvas::I->flood_fill(Canvas::I->m_current_layer_idx, plane, { (glm::ivec2)pos },
|
||||
plane_mask, 200, Canvas::I->m_current_brush->m_tip_color, color);
|
||||
plane_mask, m_tool->get_threshold(), Canvas::I->m_current_brush->m_tip_color, color);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -1607,3 +1607,15 @@ void CanvasModeFloodFill::on_Draw(const glm::mat4& ortho, const glm::mat4& proj,
|
||||
t.unbind();
|
||||
}
|
||||
}
|
||||
|
||||
void CanvasModeFloodFill::enter(kCanvasMode prev)
|
||||
{
|
||||
auto tools = App::I.layout[App::I.main_id]->find("tools-container");
|
||||
m_tool = tools->add_child<NodeToolBucket>();
|
||||
}
|
||||
|
||||
void CanvasModeFloodFill::leave(kCanvasMode next)
|
||||
{
|
||||
m_tool->destroy();
|
||||
m_tool = nullptr;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "texture.h"
|
||||
#include "action.h"
|
||||
#include <poly2tri.h>
|
||||
#include "node_tool_bucket.h"
|
||||
|
||||
enum class kCanvasMode
|
||||
{
|
||||
@@ -112,12 +113,15 @@ class CanvasModeFloodFill : public CanvasMode
|
||||
{
|
||||
const std::string m_cursor_path = "data/cursor/bucket-fill.png";
|
||||
const uint16_t m_cursor_id = const_hash(m_cursor_path.c_str());
|
||||
glm::vec2 m_cur_pos;
|
||||
NodeToolBucket* m_tool;
|
||||
public:
|
||||
CanvasModeFloodFill() { hide_curor = true; }
|
||||
glm::vec2 m_cur_pos;
|
||||
virtual void init() override;
|
||||
virtual void on_MouseEvent(MouseEvent* me, glm::vec2& loc) override;
|
||||
virtual void on_Draw(const glm::mat4& ortho, const glm::mat4& proj, const glm::mat4& camera) override;
|
||||
virtual void enter(kCanvasMode prev) override;
|
||||
virtual void leave(kCanvasMode next) override;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include "node_changelog.h"
|
||||
#include "node_usermanual.h"
|
||||
#include "node_panel_quick.h"
|
||||
#include "node_tool_bucket.h"
|
||||
|
||||
void Node::app_redraw()
|
||||
{
|
||||
@@ -1248,6 +1249,7 @@ void Node::load_internal(const tinyxml2::XMLElement* x_node)
|
||||
CASE(kWidget::About, NodeAbout);
|
||||
CASE(kWidget::Changelog, NodeChangelog);
|
||||
CASE(kWidget::UserManual, NodeUserManual);
|
||||
CASE(kWidget::ToolBucket, NodeToolBucket);
|
||||
#undef CASE
|
||||
case kWidget::Ref:
|
||||
{
|
||||
|
||||
@@ -90,6 +90,7 @@ enum class kWidget : uint16_t
|
||||
About = const_hash("about"),
|
||||
Changelog = const_hash("changelog"),
|
||||
UserManual = const_hash("usermanual"),
|
||||
ToolBucket = const_hash("tool-bucket"),
|
||||
};
|
||||
|
||||
class Node : public std::enable_shared_from_this<Node>
|
||||
|
||||
31
src/node_tool_bucket.cpp
Normal file
31
src/node_tool_bucket.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "pch.h"
|
||||
#include "node_tool_bucket.h"
|
||||
|
||||
Node* NodeToolBucket::clone_instantiate() const
|
||||
{
|
||||
return new this_class;
|
||||
}
|
||||
|
||||
void NodeToolBucket::clone_finalize(Node* dest) const
|
||||
{
|
||||
parent::clone_finalize(dest);
|
||||
auto n = static_cast<this_class*>(dest);
|
||||
n->init_controls();
|
||||
}
|
||||
|
||||
void NodeToolBucket::init()
|
||||
{
|
||||
parent::init();
|
||||
init_template("tpl-tool-bucket");
|
||||
init_controls();
|
||||
}
|
||||
|
||||
void NodeToolBucket::init_controls()
|
||||
{
|
||||
m_slider_threshold = find<NodeSliderH>("threshold");
|
||||
}
|
||||
|
||||
float NodeToolBucket::get_threshold() const
|
||||
{
|
||||
return glm::max(1.f, m_slider_threshold->get_value() * 255.f);
|
||||
}
|
||||
16
src/node_tool_bucket.h
Normal file
16
src/node_tool_bucket.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
#include "node.h"
|
||||
#include "node_slider.h"
|
||||
|
||||
class NodeToolBucket : public Node
|
||||
{
|
||||
NodeSliderH* m_slider_threshold;
|
||||
public:
|
||||
using this_class = NodeToolBucket;
|
||||
using parent = Node;
|
||||
virtual Node* clone_instantiate() const override;
|
||||
virtual void clone_finalize(Node* dest) const override;
|
||||
virtual void init() override;
|
||||
void init_controls();
|
||||
float get_threshold() const;
|
||||
};
|
||||
Reference in New Issue
Block a user