diff options
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/button_array.cpp | 546 | ||||
-rw-r--r-- | scene/gui/button_array.h | 131 | ||||
-rw-r--r-- | scene/gui/color_picker.cpp | 19 | ||||
-rw-r--r-- | scene/gui/gradient_edit.cpp (renamed from scene/gui/color_ramp_edit.cpp) | 36 | ||||
-rw-r--r-- | scene/gui/gradient_edit.h (renamed from scene/gui/color_ramp_edit.h) | 8 |
5 files changed, 33 insertions, 707 deletions
diff --git a/scene/gui/button_array.cpp b/scene/gui/button_array.cpp deleted file mode 100644 index 1616272e66..0000000000 --- a/scene/gui/button_array.cpp +++ /dev/null @@ -1,546 +0,0 @@ -/*************************************************************************/ -/* button_array.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ -/* */ -/* 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. */ -/*************************************************************************/ -#include "button_array.h" - -bool ButtonArray::_set(const StringName &p_name, const Variant &p_value) { - - String n = String(p_name); - if (n.begins_with("button/")) { - - String what = n.get_slicec('/', 1); - if (what == "count") { - int new_size = p_value; - if (new_size > 0 && buttons.size() == 0) { - selected = 0; - } - - if (new_size < buttons.size()) { - if (selected >= new_size) - selected = new_size - 1; - } - buttons.resize(new_size); - _change_notify(); - minimum_size_changed(); - } else if (what == "align") { - set_align(Align(p_value.operator int())); - } else if (what == "selected") { - set_selected(p_value); - } else if (what == "min_button_size") { - min_button_size = p_value; - } else { - int idx = what.to_int(); - ERR_FAIL_INDEX_V(idx, buttons.size(), false); - String f = n.get_slicec('/', 2); - if (f == "text") { - buttons[idx].text = p_value; - buttons[idx].xl_text = XL_MESSAGE(p_value); - } else if (f == "tooltip") - buttons[idx].tooltip = p_value; - else if (f == "icon") - buttons[idx].icon = p_value; - else - return false; - } - - update(); - return true; - } - - return false; -} - -bool ButtonArray::_get(const StringName &p_name, Variant &r_ret) const { - - String n = String(p_name); - if (n.begins_with("button/")) { - - String what = n.get_slicec('/', 1); - if (what == "count") { - r_ret = buttons.size(); - } else if (what == "align") { - r_ret = get_align(); - } else if (what == "selected") { - r_ret = get_selected(); - } else if (what == "min_button_size") { - r_ret = min_button_size; - } else { - int idx = what.to_int(); - ERR_FAIL_INDEX_V(idx, buttons.size(), false); - String f = n.get_slicec('/', 2); - if (f == "text") - r_ret = buttons[idx].text; - else if (f == "tooltip") - r_ret = buttons[idx].tooltip; - else if (f == "icon") - r_ret = buttons[idx].icon; - else - return false; - } - - return true; - } - - return false; -} -void ButtonArray::_get_property_list(List<PropertyInfo> *p_list) const { - - p_list->push_back(PropertyInfo(Variant::INT, "button/count", PROPERTY_HINT_RANGE, "0,512,1")); - p_list->push_back(PropertyInfo(Variant::INT, "button/min_button_size", PROPERTY_HINT_RANGE, "0,1024,1")); - p_list->push_back(PropertyInfo(Variant::INT, "button/align", PROPERTY_HINT_ENUM, "Begin,Center,End,Fill,Expand")); - for (int i = 0; i < buttons.size(); i++) { - String base = "button/" + itos(i) + "/"; - p_list->push_back(PropertyInfo(Variant::STRING, base + "text")); - p_list->push_back(PropertyInfo(Variant::STRING, base + "tooltip")); - p_list->push_back(PropertyInfo(Variant::OBJECT, base + "icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture")); - } - if (buttons.size() > 0) { - p_list->push_back(PropertyInfo(Variant::INT, "button/selected", PROPERTY_HINT_RANGE, "0," + itos(buttons.size() - 1) + ",1")); - } -} - -Size2 ButtonArray::get_minimum_size() const { - - Ref<StyleBox> style_normal = get_stylebox("normal"); - Ref<StyleBox> style_selected = get_stylebox("selected"); - Ref<Font> font_normal = get_font("font"); - Ref<Font> font_selected = get_font("font_selected"); - int icon_sep = get_constant("icon_separator"); - int button_sep = get_constant("button_separator"); - - Size2 minsize; - - for (int i = 0; i < buttons.size(); i++) { - - Ref<StyleBox> sb = i == selected ? style_selected : style_normal; - Ref<Font> f = i == selected ? font_selected : font_normal; - - Size2 ms; - ms = f->get_string_size(buttons[i].xl_text); - if (buttons[i].icon.is_valid()) { - - Size2 bs = buttons[i].icon->get_size(); - ms.height = MAX(ms.height, bs.height); - ms.width += bs.width + icon_sep; - } - - ms += sb->get_minimum_size(); - - buttons[i]._ms_cache = ms[orientation]; - - minsize[orientation] += ms[orientation]; - if (i > 0) - minsize[orientation] += button_sep; - minsize[!orientation] = MAX(minsize[!orientation], ms[!orientation]); - } - - return minsize; -} - -void ButtonArray::_notification(int p_what) { - - switch (p_what) { - case NOTIFICATION_MOUSE_EXIT: { - hover = -1; - update(); - } break; - case NOTIFICATION_READY: { - MethodInfo mi; - mi.name = "mouse_sub_enter"; - - add_user_signal(mi); - - } break; - case NOTIFICATION_DRAW: { - - Size2 size = get_size(); - Size2 minsize = get_combined_minimum_size(); - Ref<StyleBox> style_normal = get_stylebox("normal"); - Ref<StyleBox> style_selected = get_stylebox("selected"); - Ref<StyleBox> style_focus = get_stylebox("focus"); - Ref<StyleBox> style_hover = get_stylebox("hover"); - Ref<Font> font_normal = get_font("font"); - Ref<Font> font_selected = get_font("font_selected"); - int icon_sep = get_constant("icon_separator"); - int button_sep = get_constant("button_separator"); - Color color_normal = get_color("font_color"); - Color color_selected = get_color("font_color_selected"); - - int sep = button_sep; - int ofs = 0; - int expand = 0; - - switch (align) { - case ALIGN_BEGIN: { - - ofs = 0; - } break; - case ALIGN_CENTER: { - - ofs = Math::floor((size[orientation] - minsize[orientation]) / 2); - } break; - case ALIGN_END: { - - ofs = Math::floor((size[orientation] - minsize[orientation])); - } break; - case ALIGN_FILL: { - - if (buttons.size() > 1) - sep += Math::floor((size[orientation] - minsize[orientation]) / (buttons.size() - 1.0)); - ofs = 0; - } break; - case ALIGN_EXPAND_FILL: { - - ofs = 0; - expand = size[orientation] - minsize[orientation]; - } break; - } - - int op_size = orientation == VERTICAL ? size.width : size.height; - - for (int i = 0; i < buttons.size(); i++) { - - int ms = buttons[i]._ms_cache; - int s = ms; - if (expand > 0) { - s += expand / buttons.size(); - } - if (min_button_size != -1 && s < min_button_size) { - s = min_button_size; - } - - Rect2 r; - r.position[orientation] = ofs; - r.position[!orientation] = 0; - r.size[orientation] = s; - r.size[!orientation] = op_size; - - Ref<Font> f; - Color c; - Point2 sbsize; - Point2 sbofs; - if (i == selected) { - draw_style_box(style_selected, r); - sbsize = style_selected->get_minimum_size(); - sbofs = style_selected->get_offset(); - f = font_selected; - c = color_selected; - if (has_focus()) - draw_style_box(style_focus, r); - } else { - if (hover == i) - draw_style_box(style_hover, r); - else if (!flat) - draw_style_box(style_normal, r); - sbsize = style_normal->get_minimum_size(); - sbofs = style_normal->get_offset(); - f = font_normal; - c = color_normal; - } - - Size2 ssize = f->get_string_size(buttons[i].xl_text); - if (buttons[i].icon.is_valid()) { - - ssize.x += buttons[i].icon->get_width(); - } - Point2 text_ofs = ((r.size - ssize - sbsize) / 2.0 + Point2(0, f->get_ascent())).floor() + sbofs; - if (buttons[i].icon.is_valid()) { - - draw_texture(buttons[i].icon, r.position + Point2(text_ofs.x, Math::floor((r.size.height - buttons[i].icon->get_height()) / 2.0))); - text_ofs.x += buttons[i].icon->get_width() + icon_sep; - } - draw_string(f, text_ofs + r.position, buttons[i].xl_text, c); - buttons[i]._pos_cache = ofs; - buttons[i]._size_cache = s; - - ofs += s; - ofs += sep; - } - - } break; - } -} - -void ButtonArray::_gui_input(const Ref<InputEvent> &p_event) { - - if ( - ((orientation == HORIZONTAL && p_event->is_action("ui_left")) || - (orientation == VERTICAL && p_event->is_action("ui_up"))) && - p_event->is_pressed() && selected > 0) { - set_selected(selected - 1); - accept_event(); - emit_signal("button_selected", selected); - return; - } - - if ( - ((orientation == HORIZONTAL && p_event->is_action("ui_right")) || - (orientation == VERTICAL && p_event->is_action("ui_down"))) && - p_event->is_pressed() && selected < (buttons.size() - 1)) { - set_selected(selected + 1); - accept_event(); - emit_signal("button_selected", selected); - return; - } - - Ref<InputEventMouseButton> mb = p_event; - - if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { - - int ofs = orientation == HORIZONTAL ? mb->get_position().x : mb->get_position().y; - - for (int i = 0; i < buttons.size(); i++) { - - if (ofs >= buttons[i]._pos_cache && ofs < buttons[i]._pos_cache + buttons[i]._size_cache) { - - set_selected(i); - emit_signal("button_selected", i); - return; - } - } - } - - Ref<InputEventMouseMotion> mm = p_event; - - if (mm.is_valid()) { - - int ofs = orientation == HORIZONTAL ? mm->get_position().x : mm->get_position().y; - int new_hover = -1; - for (int i = 0; i < buttons.size(); i++) { - - if (ofs >= buttons[i]._pos_cache && ofs < buttons[i]._pos_cache + buttons[i]._size_cache) { - - new_hover = i; - break; - } - } - - if (new_hover != hover) { - hover = new_hover; - emit_signal("mouse_sub_enter"); - update(); - } - } -} - -String ButtonArray::get_tooltip(const Point2 &p_pos) const { - - int ofs = orientation == HORIZONTAL ? p_pos.x : p_pos.y; - for (int i = 0; i < buttons.size(); i++) { - - if (ofs >= buttons[i]._pos_cache && ofs < buttons[i]._pos_cache + buttons[i]._size_cache) - return buttons[i].tooltip; - } - return Control::get_tooltip(p_pos); -} - -void ButtonArray::set_align(Align p_align) { - - align = p_align; - update(); -} - -ButtonArray::Align ButtonArray::get_align() const { - - return align; -} - -void ButtonArray::set_flat(bool p_flat) { - - flat = p_flat; - update(); -} - -bool ButtonArray::is_flat() const { - - return flat; -} - -void ButtonArray::add_button(const String &p_text, const String &p_tooltip) { - - Button button; - button.text = p_text; - button.xl_text = XL_MESSAGE(p_text); - button.tooltip = p_tooltip; - buttons.push_back(button); - update(); - - if (selected == -1) - selected = 0; - - minimum_size_changed(); -} - -void ButtonArray::add_icon_button(const Ref<Texture> &p_icon, const String &p_text, const String &p_tooltip) { - - Button button; - button.text = p_text; - button.xl_text = XL_MESSAGE(p_text); - button.icon = p_icon; - button.tooltip = p_tooltip; - buttons.push_back(button); - if (selected == -1) - selected = 0; - - update(); -} - -void ButtonArray::set_button_text(int p_button, const String &p_text) { - - ERR_FAIL_INDEX(p_button, buttons.size()); - buttons[p_button].text = p_text; - buttons[p_button].xl_text = XL_MESSAGE(p_text); - update(); - minimum_size_changed(); -} - -void ButtonArray::set_button_tooltip(int p_button, const String &p_text) { - - ERR_FAIL_INDEX(p_button, buttons.size()); - buttons[p_button].tooltip = p_text; -} - -void ButtonArray::set_button_icon(int p_button, const Ref<Texture> &p_icon) { - - ERR_FAIL_INDEX(p_button, buttons.size()); - buttons[p_button].icon = p_icon; - update(); - minimum_size_changed(); -} - -String ButtonArray::get_button_text(int p_button) const { - - ERR_FAIL_INDEX_V(p_button, buttons.size(), ""); - return buttons[p_button].text; -} - -String ButtonArray::get_button_tooltip(int p_button) const { - - ERR_FAIL_INDEX_V(p_button, buttons.size(), ""); - return buttons[p_button].tooltip; -} - -Ref<Texture> ButtonArray::get_button_icon(int p_button) const { - - ERR_FAIL_INDEX_V(p_button, buttons.size(), Ref<Texture>()); - return buttons[p_button].icon; -} - -int ButtonArray::get_selected() const { - - return selected; -} - -int ButtonArray::get_hovered() const { - - return hover; -} - -void ButtonArray::set_selected(int p_selected) { - - ERR_FAIL_INDEX(p_selected, buttons.size()); - selected = p_selected; - update(); -} - -void ButtonArray::erase_button(int p_button) { - - ERR_FAIL_INDEX(p_button, buttons.size()); - buttons.remove(p_button); - if (p_button >= selected) - selected--; - if (selected < 0) - selected = 0; - if (selected >= buttons.size()) - selected = buttons.size() - 1; - - update(); -} - -void ButtonArray::clear() { - - buttons.clear(); - selected = -1; - update(); -} - -int ButtonArray::get_button_count() const { - - return buttons.size(); -} - -void ButtonArray::get_translatable_strings(List<String> *p_strings) const { - - for (int i = 0; i < buttons.size(); i++) { - p_strings->push_back(buttons[i].text); - p_strings->push_back(buttons[i].tooltip); - } -} - -void ButtonArray::_bind_methods() { - - ClassDB::bind_method(D_METHOD("add_button", "text", "tooltip"), &ButtonArray::add_button, DEFVAL("")); - ClassDB::bind_method(D_METHOD("add_icon_button", "icon:Texture", "text", "tooltip"), &ButtonArray::add_icon_button, DEFVAL(""), DEFVAL("")); - ClassDB::bind_method(D_METHOD("set_button_text", "button_idx", "text"), &ButtonArray::set_button_text); - ClassDB::bind_method(D_METHOD("set_button_tooltip", "button_idx", "text"), &ButtonArray::set_button_tooltip); - ClassDB::bind_method(D_METHOD("set_button_icon", "button_idx", "icon:Texture"), &ButtonArray::set_button_icon); - ClassDB::bind_method(D_METHOD("get_button_text", "button_idx"), &ButtonArray::get_button_text); - ClassDB::bind_method(D_METHOD("get_button_tooltip", "button_idx"), &ButtonArray::get_button_tooltip); - ClassDB::bind_method(D_METHOD("get_button_icon:Texture", "button_idx"), &ButtonArray::get_button_icon); - ClassDB::bind_method(D_METHOD("get_button_count"), &ButtonArray::get_button_count); - ClassDB::bind_method(D_METHOD("set_flat", "enabled"), &ButtonArray::set_flat); - ClassDB::bind_method(D_METHOD("is_flat"), &ButtonArray::is_flat); - ClassDB::bind_method(D_METHOD("get_selected"), &ButtonArray::get_selected); - ClassDB::bind_method(D_METHOD("get_hovered"), &ButtonArray::get_hovered); - ClassDB::bind_method(D_METHOD("set_selected", "button_idx"), &ButtonArray::set_selected); - ClassDB::bind_method(D_METHOD("erase_button", "button_idx"), &ButtonArray::erase_button); - ClassDB::bind_method(D_METHOD("clear"), &ButtonArray::clear); - - ClassDB::bind_method(D_METHOD("_gui_input"), &ButtonArray::_gui_input); - - BIND_CONSTANT(ALIGN_BEGIN); - BIND_CONSTANT(ALIGN_CENTER); - BIND_CONSTANT(ALIGN_END); - BIND_CONSTANT(ALIGN_FILL); - BIND_CONSTANT(ALIGN_EXPAND_FILL); - - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "flat"), "set_flat", "is_flat"); - - ADD_SIGNAL(MethodInfo("button_selected", PropertyInfo(Variant::INT, "button_idx"))); -} - -ButtonArray::ButtonArray(Orientation p_orientation) { - - orientation = p_orientation; - selected = -1; - set_focus_mode(FOCUS_ALL); - hover = -1; - flat = false; - min_button_size = -1; -} diff --git a/scene/gui/button_array.h b/scene/gui/button_array.h deleted file mode 100644 index 0ebf681cb6..0000000000 --- a/scene/gui/button_array.h +++ /dev/null @@ -1,131 +0,0 @@ -/*************************************************************************/ -/* button_array.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ -/* */ -/* 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. */ -/*************************************************************************/ -#ifndef BUTTON_ARRAY_H -#define BUTTON_ARRAY_H - -#include "scene/gui/control.h" - -class ButtonArray : public Control { - - GDCLASS(ButtonArray, Control); - -public: - enum Align { - ALIGN_BEGIN, - ALIGN_CENTER, - ALIGN_END, - ALIGN_FILL, - ALIGN_EXPAND_FILL - }; - -private: - Orientation orientation; - Align align; - - struct Button { - - String text; - String xl_text; - String tooltip; - Ref<Texture> icon; - mutable int _ms_cache; - mutable int _pos_cache; - mutable int _size_cache; - }; - - int selected; - int hover; - bool flat; - double min_button_size; - - Vector<Button> buttons; - -protected: - bool _set(const StringName &p_name, const Variant &p_value); - bool _get(const StringName &p_name, Variant &r_ret) const; - void _get_property_list(List<PropertyInfo> *p_list) const; - - void _notification(int p_what); - static void _bind_methods(); - -public: - void _gui_input(const Ref<InputEvent> &p_event); - - void set_align(Align p_align); - Align get_align() const; - - void set_flat(bool p_flat); - bool is_flat() const; - - void add_button(const String &p_button, const String &p_tooltip = ""); - void add_icon_button(const Ref<Texture> &p_icon, const String &p_button = "", const String &p_tooltip = ""); - - void set_button_text(int p_button, const String &p_text); - void set_button_tooltip(int p_button, const String &p_text); - void set_button_icon(int p_button, const Ref<Texture> &p_icon); - - String get_button_text(int p_button) const; - String get_button_tooltip(int p_button) const; - Ref<Texture> get_button_icon(int p_button) const; - - int get_selected() const; - int get_hovered() const; - void set_selected(int p_selected); - - int get_button_count() const; - - void erase_button(int p_button); - void clear(); - - virtual Size2 get_minimum_size() const; - - virtual void get_translatable_strings(List<String> *p_strings) const; - virtual String get_tooltip(const Point2 &p_pos) const; - - ButtonArray(Orientation p_orientation = HORIZONTAL); -}; - -class HButtonArray : public ButtonArray { - GDCLASS(HButtonArray, ButtonArray); - -public: - HButtonArray() - : ButtonArray(HORIZONTAL){}; -}; - -class VButtonArray : public ButtonArray { - GDCLASS(VButtonArray, ButtonArray); - -public: - VButtonArray() - : ButtonArray(VERTICAL){}; -}; - -#endif // BUTTON_ARRAY_H diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index f0e486aa50..d3bdc401ab 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -156,6 +156,8 @@ void ColorPicker::_update_color() { _update_text_value(); sample->update(); + uv_edit->update(); + w_edit->update(); updating = false; } @@ -263,10 +265,10 @@ void ColorPicker::_hsv_draw(int p_wich, Control *c) { points.push_back(c->get_size()); points.push_back(Vector2(0, c->get_size().y)); Vector<Color> colors; - colors.push_back(Color(1, 1, 1)); - colors.push_back(Color(1, 1, 1)); - colors.push_back(Color()); - colors.push_back(Color()); + colors.push_back(Color(1, 1, 1, 1)); + colors.push_back(Color(1, 1, 1, 1)); + colors.push_back(Color(0, 0, 0, 1)); + colors.push_back(Color(0, 0, 0, 1)); c->draw_polygon(points, colors); Vector<Color> colors2; Color col = color; @@ -279,7 +281,7 @@ void ColorPicker::_hsv_draw(int p_wich, Control *c) { colors2.push_back(col); col.a = 0; colors2.push_back(col); - c->draw_polygon(points, colors); + c->draw_polygon(points, colors2); int x = CLAMP(c->get_size().x * s, 0, c->get_size().x); int y = CLAMP(c->get_size().y - c->get_size().y * v, 0, c->get_size().y); col = color; @@ -290,7 +292,7 @@ void ColorPicker::_hsv_draw(int p_wich, Control *c) { } else if (p_wich == 1) { Ref<Texture> hue = get_icon("color_hue", "ColorPicker"); c->draw_texture_rect(hue, Rect2(Point2(), c->get_size())); - int y = c->get_size().y - c->get_size().y * h; + int y = c->get_size().y - c->get_size().y * (1.0 - h); Color col = Color(); col.set_hsv(h, 1, 1); c->draw_line(Point2(0, y), Point2(c->get_size().x, y), col.inverted()); @@ -343,7 +345,7 @@ void ColorPicker::_w_input(const Ref<InputEvent> &ev) { if (bev->is_pressed() && bev->get_button_index() == BUTTON_LEFT) { changing_color = true; - h = 1 - ((float)bev->get_position().y) / 256.0; + h = 1 - (256.0 - (float)bev->get_position().y) / 256.0; } else { changing_color = false; @@ -362,7 +364,8 @@ void ColorPicker::_w_input(const Ref<InputEvent> &ev) { if (!changing_color) return; float y = CLAMP((float)mev->get_position().y, 0, 256); - h = 1.0 - y / 256.0; + //h = 1.0 - y / 256.0; + h = y / 256.0; color.set_hsv(h, s, v, color.a); last_hsv = color; set_pick_color(color); diff --git a/scene/gui/color_ramp_edit.cpp b/scene/gui/gradient_edit.cpp index 33e4ce0403..58bce57580 100644 --- a/scene/gui/color_ramp_edit.cpp +++ b/scene/gui/gradient_edit.cpp @@ -27,10 +27,10 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "color_ramp_edit.h" +#include "gradient_edit.h" #include "os/keyboard.h" -ColorRampEdit::ColorRampEdit() { +GradientEdit::GradientEdit() { grabbed = -1; grabbing = false; set_focus_mode(FOCUS_ALL); @@ -46,7 +46,7 @@ ColorRampEdit::ColorRampEdit() { checker->create_from_image(img, ImageTexture::FLAG_REPEAT); } -int ColorRampEdit::_get_point_from_pos(int x) { +int GradientEdit::_get_point_from_pos(int x) { int result = -1; int total_w = get_size().width - get_size().height - 3; for (int i = 0; i < points.size(); i++) { @@ -58,7 +58,7 @@ int ColorRampEdit::_get_point_from_pos(int x) { return result; } -void ColorRampEdit::_show_color_picker() { +void GradientEdit::_show_color_picker() { if (grabbed == -1) return; Size2 ms = Size2(350, picker->get_combined_minimum_size().height + 10); @@ -68,10 +68,10 @@ void ColorRampEdit::_show_color_picker() { popup->popup(); } -ColorRampEdit::~ColorRampEdit() { +GradientEdit::~GradientEdit() { } -void ColorRampEdit::_gui_input(const Ref<InputEvent> &p_event) { +void GradientEdit::_gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventKey> k = p_event; @@ -272,7 +272,7 @@ void ColorRampEdit::_gui_input(const Ref<InputEvent> &p_event) { } } -void ColorRampEdit::_notification(int p_what) { +void GradientEdit::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { if (!picker->is_connected("color_changed", this, "_color_changed")) { @@ -370,7 +370,7 @@ void ColorRampEdit::_notification(int p_what) { } } -void ColorRampEdit::_draw_checker(int x, int y, int w, int h) { +void GradientEdit::_draw_checker(int x, int y, int w, int h) { //Draw it with polygon to insert UVs for scale Vector<Vector2> backPoints; backPoints.push_back(Vector2(x, y)); @@ -391,12 +391,12 @@ void ColorRampEdit::_draw_checker(int x, int y, int w, int h) { draw_polygon(backPoints, colorPoints, uvPoints, checker); } -Size2 ColorRampEdit::get_minimum_size() const { +Size2 GradientEdit::get_minimum_size() const { return Vector2(0, 16); } -void ColorRampEdit::_color_changed(const Color &p_color) { +void GradientEdit::_color_changed(const Color &p_color) { if (grabbed == -1) return; @@ -405,7 +405,7 @@ void ColorRampEdit::_color_changed(const Color &p_color) { emit_signal("ramp_changed"); } -void ColorRampEdit::set_ramp(const Vector<float> &p_offsets, const Vector<Color> &p_colors) { +void GradientEdit::set_ramp(const Vector<float> &p_offsets, const Vector<Color> &p_colors) { ERR_FAIL_COND(p_offsets.size() != p_colors.size()); points.clear(); @@ -420,33 +420,33 @@ void ColorRampEdit::set_ramp(const Vector<float> &p_offsets, const Vector<Color> update(); } -Vector<float> ColorRampEdit::get_offsets() const { +Vector<float> GradientEdit::get_offsets() const { Vector<float> ret; for (int i = 0; i < points.size(); i++) ret.push_back(points[i].offset); return ret; } -Vector<Color> ColorRampEdit::get_colors() const { +Vector<Color> GradientEdit::get_colors() const { Vector<Color> ret; for (int i = 0; i < points.size(); i++) ret.push_back(points[i].color); return ret; } -void ColorRampEdit::set_points(Vector<Gradient::Point> &p_points) { +void GradientEdit::set_points(Vector<Gradient::Point> &p_points) { if (points.size() != p_points.size()) grabbed = -1; points.clear(); points = p_points; } -Vector<Gradient::Point> &ColorRampEdit::get_points() { +Vector<Gradient::Point> &GradientEdit::get_points() { return points; } -void ColorRampEdit::_bind_methods() { - ClassDB::bind_method(D_METHOD("_gui_input"), &ColorRampEdit::_gui_input); - ClassDB::bind_method(D_METHOD("_color_changed"), &ColorRampEdit::_color_changed); +void GradientEdit::_bind_methods() { + ClassDB::bind_method(D_METHOD("_gui_input"), &GradientEdit::_gui_input); + ClassDB::bind_method(D_METHOD("_color_changed"), &GradientEdit::_color_changed); ADD_SIGNAL(MethodInfo("ramp_changed")); } diff --git a/scene/gui/color_ramp_edit.h b/scene/gui/gradient_edit.h index 0fe447c43a..6c4ae6fd15 100644 --- a/scene/gui/color_ramp_edit.h +++ b/scene/gui/gradient_edit.h @@ -37,9 +37,9 @@ #define POINT_WIDTH 8 -class ColorRampEdit : public Control { +class GradientEdit : public Control { - GDCLASS(ColorRampEdit, Control); + GDCLASS(GradientEdit, Control); PopupPanel *popup; ColorPicker *picker; @@ -68,8 +68,8 @@ public: Vector<Gradient::Point> &get_points(); virtual Size2 get_minimum_size() const; - ColorRampEdit(); - virtual ~ColorRampEdit(); + GradientEdit(); + virtual ~GradientEdit(); }; /*class ColorRampEditPanel : public Panel |