mirror of
https://github.com/godotengine/godot.git
synced 2026-05-12 22:35:35 +00:00
Merge pull request #99515 from KoBeWi/shapez.godot
Refactor ColorPicker shapes
This commit is contained in:
@@ -146,6 +146,4 @@ public:
|
||||
|
||||
ColorModeOKHSL(ColorPicker *p_color_picker) :
|
||||
ColorMode(p_color_picker) {}
|
||||
|
||||
~ColorModeOKHSL() {}
|
||||
};
|
||||
|
||||
+92
-786
File diff suppressed because it is too large
Load Diff
+14
-28
@@ -79,6 +79,13 @@ class ColorPicker : public VBoxContainer {
|
||||
GDCLASS(ColorPicker, VBoxContainer);
|
||||
|
||||
// These classes poke into theme items for their internal logic.
|
||||
friend class ColorPickerShape;
|
||||
friend class ColorPickerShapeRectangle;
|
||||
friend class ColorPickerShapeWheel;
|
||||
friend class ColorPickerShapeCircle;
|
||||
friend class ColorPickerShapeVHSCircle;
|
||||
friend class ColorPickerShapeOKHSLCircle;
|
||||
|
||||
friend class ColorModeRGB;
|
||||
friend class ColorModeHSV;
|
||||
friend class ColorModeRAW;
|
||||
@@ -127,21 +134,17 @@ private:
|
||||
|
||||
int current_slider_count = SLIDER_COUNT;
|
||||
Vector2i circle_keyboard_joypad_picker_cursor_position;
|
||||
float echo_multiplier = 1;
|
||||
float echo_multiplier_step = 1.1;
|
||||
bool rotate_next_echo_event = false;
|
||||
|
||||
const float DEFAULT_GAMEPAD_EVENT_DELAY_MS = 1.0 / 2;
|
||||
const float GAMEPAD_EVENT_REPEAT_RATE_MS = 1.0 / 30;
|
||||
float gamepad_event_delay_ms = DEFAULT_GAMEPAD_EVENT_DELAY_MS;
|
||||
bool cursor_editing = false;
|
||||
int wheel_focus_mode = 0;
|
||||
static const int MODE_BUTTON_COUNT = 3;
|
||||
const float WHEEL_RADIUS = 0.42;
|
||||
|
||||
static constexpr int MODE_BUTTON_COUNT = 3;
|
||||
|
||||
bool slider_theme_modified = true;
|
||||
|
||||
Vector<ColorMode *> modes;
|
||||
LocalVector<ColorMode *> modes;
|
||||
LocalVector<ColorPickerShape *> shapes;
|
||||
|
||||
Popup *picker_window = nullptr;
|
||||
TextureRect *picker_texture_zoom = nullptr;
|
||||
@@ -158,14 +161,7 @@ private:
|
||||
PopupMenu *options_menu = nullptr;
|
||||
|
||||
MarginContainer *internal_margin = nullptr;
|
||||
Control *uv_edit = nullptr;
|
||||
Control *w_edit = nullptr;
|
||||
AspectRatioContainer *wheel_edit = nullptr;
|
||||
MarginContainer *wheel_margin = nullptr;
|
||||
Ref<ShaderMaterial> wheel_mat;
|
||||
Ref<ShaderMaterial> circle_mat;
|
||||
Control *wheel = nullptr;
|
||||
Control *wheel_uv = nullptr;
|
||||
HBoxContainer *shape_container = nullptr;
|
||||
TextureRect *sample = nullptr;
|
||||
VBoxContainer *swatches_vbc = nullptr;
|
||||
GridContainer *preset_container = nullptr;
|
||||
@@ -189,6 +185,7 @@ private:
|
||||
ColorPresetButton *selected_recent_preset = nullptr;
|
||||
Ref<ButtonGroup> preset_group;
|
||||
Ref<ButtonGroup> recent_preset_group;
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
Callable quick_open_callback;
|
||||
Callable palette_saved_callback;
|
||||
@@ -304,18 +301,8 @@ private:
|
||||
void _text_type_toggled();
|
||||
void _sample_input(const Ref<InputEvent> &p_event);
|
||||
void _sample_draw();
|
||||
void _draw_focus_stylebox(Control *p_c, Rect2 p_focus_rect, Ref<StyleBox> &p_focus_stylebox);
|
||||
void _hsv_draw(int p_which, Control *c);
|
||||
void _slider_draw(int p_which);
|
||||
int _get_edge_h_change(const Vector2 &p_color_change_vector);
|
||||
float _get_h_on_circle_edge(const Vector2 &p_color_change_vector);
|
||||
float _get_h_on_wheel(const Vector2 &p_color_change_vector);
|
||||
void _update_uv_cursor(Vector2 &p_color_change_vector, bool p_is_echo);
|
||||
void _update_cursor_editing(const Ref<InputEvent> &p_event, Control *p_c);
|
||||
|
||||
void _uv_input(const Ref<InputEvent> &p_event, Control *c);
|
||||
void _update_w_cursor(float p_color_change, bool p_is_echo);
|
||||
void _w_input(const Ref<InputEvent> &p_event);
|
||||
void _slider_or_spin_input(const Ref<InputEvent> &p_event);
|
||||
void _line_edit_input(const Ref<InputEvent> &p_event);
|
||||
void _preset_input(const Ref<InputEvent> &p_event, const Color &p_color);
|
||||
@@ -373,6 +360,7 @@ public:
|
||||
static void finish_shaders();
|
||||
|
||||
void add_mode(ColorMode *p_mode);
|
||||
void add_shape(ColorPickerShape *p_shape);
|
||||
|
||||
void set_edit_alpha(bool p_show);
|
||||
bool is_editing_alpha() const;
|
||||
@@ -433,8 +421,6 @@ public:
|
||||
void set_focus_on_line_edit();
|
||||
void set_focus_on_picker_shape();
|
||||
|
||||
void _picker_shape_focus_entered();
|
||||
void _picker_shape_focus_exited();
|
||||
ColorPicker();
|
||||
~ColorPicker();
|
||||
};
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,215 @@
|
||||
/**************************************************************************/
|
||||
/* color_picker_shape.h */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "scene/gui/color_picker.h"
|
||||
|
||||
class ColorPickerShape : public Object {
|
||||
GDCLASS(ColorPickerShape, Object);
|
||||
|
||||
void _emit_color_changed();
|
||||
|
||||
protected:
|
||||
ColorPicker *color_picker = nullptr;
|
||||
bool is_dragging = false;
|
||||
|
||||
virtual void _initialize_controls() = 0;
|
||||
virtual void _update_cursor(const Vector2 &p_color_change_vector, bool p_is_echo) = 0;
|
||||
|
||||
bool can_handle(const Ref<InputEvent> &p_event, Vector2 &r_position, bool *r_is_click = nullptr);
|
||||
void apply_color();
|
||||
void cancel_event();
|
||||
|
||||
void draw_focus_rect(Control *p_control, const Rect2 &p_rect = Rect2());
|
||||
void draw_focus_circle(Control *p_control);
|
||||
void draw_sv_square(Control *p_control, const Rect2 &p_square, bool p_draw_focus = true);
|
||||
void draw_cursor(Control *p_control, const Vector2 &p_center, bool p_draw_bg = true);
|
||||
void draw_circle_cursor(Control *p_control, float p_hue);
|
||||
|
||||
void connect_shape_focus(Control *p_shape);
|
||||
void shape_focus_entered();
|
||||
void shape_focus_exited();
|
||||
|
||||
void handle_cursor_editing(const Ref<InputEvent> &p_event, Control *p_control);
|
||||
int get_edge_h_change(const Vector2 &p_color_change_vector);
|
||||
float get_h_on_circle_edge(const Vector2 &p_color_change_vector);
|
||||
|
||||
public:
|
||||
Vector<Control *> controls;
|
||||
bool is_initialized = false;
|
||||
bool cursor_editing = false;
|
||||
float echo_multiplier = 1;
|
||||
|
||||
virtual String get_name() const = 0;
|
||||
virtual Ref<Texture2D> get_icon() const = 0;
|
||||
virtual bool is_ok_hsl() const { return false; }
|
||||
|
||||
void initialize_controls();
|
||||
virtual void update_theme() = 0;
|
||||
void update_cursor(const Vector2 &p_color_change_vector, bool p_is_echo);
|
||||
virtual void grab_focus() = 0;
|
||||
|
||||
ColorPickerShape(ColorPicker *p_color_picker);
|
||||
};
|
||||
|
||||
class ColorPickerShapeRectangle : public ColorPickerShape {
|
||||
Control *sv_square = nullptr;
|
||||
Control *hue_slider = nullptr;
|
||||
|
||||
void _sv_square_input(const Ref<InputEvent> &p_event);
|
||||
void _hue_slider_input(const Ref<InputEvent> &p_event);
|
||||
|
||||
void _sv_square_draw();
|
||||
void _hue_slider_draw();
|
||||
|
||||
protected:
|
||||
virtual void _initialize_controls() override;
|
||||
virtual void _update_cursor(const Vector2 &p_color_change_vector, bool p_is_echo) override;
|
||||
|
||||
public:
|
||||
virtual String get_name() const override { return ETR("HSV Rectangle"); }
|
||||
virtual Ref<Texture2D> get_icon() const override { return color_picker->theme_cache.shape_rect; }
|
||||
virtual void update_theme() override;
|
||||
virtual void grab_focus() override;
|
||||
|
||||
ColorPickerShapeRectangle(ColorPicker *p_color_picker) :
|
||||
ColorPickerShape(p_color_picker) {}
|
||||
};
|
||||
|
||||
class ColorPickerShapeWheel : public ColorPickerShape {
|
||||
GDCLASS(ColorPickerShapeWheel, ColorPickerShape);
|
||||
|
||||
inline static constexpr float WHEEL_RADIUS = 0.42;
|
||||
|
||||
MarginContainer *wheel_margin = nullptr;
|
||||
Control *wheel = nullptr;
|
||||
Control *wheel_uv = nullptr;
|
||||
|
||||
bool wheel_focused = true;
|
||||
bool spinning = false;
|
||||
bool rotate_next_echo_event = false;
|
||||
|
||||
float _get_h_on_wheel(const Vector2 &p_color_change_vector);
|
||||
void _reset_wheel_focus();
|
||||
|
||||
void _wheel_input(const Ref<InputEvent> &p_event);
|
||||
|
||||
void _wheel_draw();
|
||||
void _wheel_uv_draw();
|
||||
|
||||
protected:
|
||||
virtual void _initialize_controls() override;
|
||||
virtual void _update_cursor(const Vector2 &p_color_change_vector, bool p_is_echo) override;
|
||||
|
||||
public:
|
||||
virtual String get_name() const override { return ETR("HSV Wheel"); }
|
||||
virtual Ref<Texture2D> get_icon() const override { return color_picker->theme_cache.shape_rect_wheel; }
|
||||
virtual void update_theme() override;
|
||||
virtual void grab_focus() override;
|
||||
|
||||
ColorPickerShapeWheel(ColorPicker *p_color_picker) :
|
||||
ColorPickerShape(p_color_picker) {}
|
||||
};
|
||||
|
||||
class ColorPickerShapeCircle : public ColorPickerShape {
|
||||
GDCLASS(ColorPickerShapeCircle, ColorPickerShape);
|
||||
|
||||
protected:
|
||||
MarginContainer *circle_margin = nullptr;
|
||||
Control *circle = nullptr;
|
||||
Control *circle_overlay = nullptr;
|
||||
Control *value_slider = nullptr;
|
||||
|
||||
Vector2i circle_keyboard_joypad_picker_cursor_position;
|
||||
|
||||
virtual void _circle_input(const Ref<InputEvent> &p_event) = 0;
|
||||
virtual void _value_slider_input(const Ref<InputEvent> &p_event) = 0;
|
||||
|
||||
virtual void _circle_draw() = 0;
|
||||
virtual void _circle_overlay_draw() = 0;
|
||||
virtual void _value_slider_draw() = 0;
|
||||
|
||||
void update_circle_cursor(const Vector2 &p_color_change_vector, const Vector2 &p_center, const Vector2 &p_hue_offset);
|
||||
|
||||
public:
|
||||
virtual Ref<Shader> _get_shader() const = 0;
|
||||
virtual void _initialize_controls() override;
|
||||
|
||||
virtual Ref<Texture2D> get_icon() const override { return color_picker->theme_cache.shape_circle; }
|
||||
virtual void update_theme() override;
|
||||
virtual void grab_focus() override;
|
||||
|
||||
ColorPickerShapeCircle(ColorPicker *p_color_picker) :
|
||||
ColorPickerShape(p_color_picker) {}
|
||||
};
|
||||
|
||||
class ColorPickerShapeVHSCircle : public ColorPickerShapeCircle {
|
||||
GDCLASS(ColorPickerShapeVHSCircle, ColorPickerShapeCircle);
|
||||
|
||||
protected:
|
||||
virtual void _update_cursor(const Vector2 &p_color_change_vector, bool p_is_echo) override;
|
||||
virtual Ref<Shader> _get_shader() const override { return ColorPicker::circle_shader; }
|
||||
|
||||
virtual void _circle_input(const Ref<InputEvent> &p_event) override;
|
||||
virtual void _value_slider_input(const Ref<InputEvent> &p_event) override;
|
||||
|
||||
virtual void _circle_draw() override;
|
||||
virtual void _circle_overlay_draw() override;
|
||||
virtual void _value_slider_draw() override;
|
||||
|
||||
public:
|
||||
virtual String get_name() const override { return ETR("VHS Circle"); }
|
||||
|
||||
ColorPickerShapeVHSCircle(ColorPicker *p_color_picker) :
|
||||
ColorPickerShapeCircle(p_color_picker) {}
|
||||
};
|
||||
|
||||
class ColorPickerShapeOKHSLCircle : public ColorPickerShapeCircle {
|
||||
GDCLASS(ColorPickerShapeOKHSLCircle, ColorPickerShapeCircle);
|
||||
|
||||
protected:
|
||||
virtual void _update_cursor(const Vector2 &p_color_change_vector, bool p_is_echo) override;
|
||||
virtual Ref<Shader> _get_shader() const override { return ColorPicker::circle_ok_color_shader; }
|
||||
|
||||
virtual void _circle_input(const Ref<InputEvent> &p_event) override;
|
||||
virtual void _value_slider_input(const Ref<InputEvent> &p_event) override;
|
||||
|
||||
virtual void _circle_draw() override;
|
||||
virtual void _circle_overlay_draw() override;
|
||||
virtual void _value_slider_draw() override;
|
||||
|
||||
public:
|
||||
virtual String get_name() const override { return ETR("OKHSL Circle"); }
|
||||
virtual bool is_ok_hsl() const override { return true; }
|
||||
|
||||
ColorPickerShapeOKHSLCircle(ColorPicker *p_color_picker) :
|
||||
ColorPickerShapeCircle(p_color_picker) {}
|
||||
};
|
||||
Reference in New Issue
Block a user