#pragma once
#include "util.h"
#include "node.h"
#include "shape.h"
#include "node_slider.h"
#include "node_border.h"

class NodeColorWheel : public Node
{
public:
    Circle m_circle;
    Plane m_cur_hue;
    Circle m_cur_quad;
    Plane m_quad;
    NodeBorder* m_color_cur;
    glm::vec3 m_hsv;
    GLuint m_tri_vbo;
    GLuint m_tri_vao;
    GLuint buffers;
    GLuint arrays;
    std::function<void(Node* target, glm::vec3 hsv)> on_value_changed;
    int mode; // 1:hue 2:quad
    bool dragging = false;
    glm::vec3 m_old_value{0.f};
    virtual Node* clone_instantiate() const override;
    virtual void clone_finalize(Node* dest) const override;
    virtual void init() override;
    virtual void loaded() override;
    virtual void draw() override;
    virtual kEventResult handle_event(Event* e) override;
    void init_controls();
    glm::vec4 get_quad_rect() const;
    bool inside_quad(glm::vec2 pos, glm::vec2& out_coord) const;
    void handle_color_change();
};
