| 
									
										
										
										
											2016-06-18 14:46:12 +02:00
										 |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2018-01-05 00:50:27 +01:00
										 |  |  | /*  gradient_edit.cpp                                                    */ | 
					
						
							| 
									
										
										
										
											2016-06-18 14:46:12 +02:00
										 |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*                       This file is part of:                           */ | 
					
						
							|  |  |  | /*                           GODOT ENGINE                                */ | 
					
						
							| 
									
										
										
										
											2017-08-27 14:16:55 +02:00
										 |  |  | /*                      https://godotengine.org                          */ | 
					
						
							| 
									
										
										
										
											2016-06-18 14:46:12 +02:00
										 |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2021-01-01 20:13:46 +01:00
										 |  |  | /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ | 
					
						
							|  |  |  | /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md).   */ | 
					
						
							| 
									
										
										
										
											2016-06-18 14:46:12 +02:00
										 |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* 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.                */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2018-01-05 00:50:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-13 23:47:34 +02:00
										 |  |  | #include "gradient_edit.h"
 | 
					
						
							| 
									
										
										
										
											2019-06-12 22:35:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-11 18:13:45 +02:00
										 |  |  | #include "core/os/keyboard.h"
 | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-12 22:35:35 +02:00
										 |  |  | #ifdef TOOLS_ENABLED
 | 
					
						
							|  |  |  | #include "editor/editor_scale.h"
 | 
					
						
							| 
									
										
										
										
											2018-09-07 13:49:10 -03:00
										 |  |  | #define SPACING (3 * EDSCALE)
 | 
					
						
							| 
									
										
										
										
											2019-06-12 22:35:35 +02:00
										 |  |  | #define POINT_WIDTH (8 * EDSCALE)
 | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | #define SPACING 3
 | 
					
						
							|  |  |  | #define POINT_WIDTH 8
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2018-09-07 13:49:10 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-13 23:47:34 +02:00
										 |  |  | GradientEdit::GradientEdit() { | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 	set_focus_mode(FOCUS_ALL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	popup = memnew(PopupPanel); | 
					
						
							|  |  |  | 	picker = memnew(ColorPicker); | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 	popup->add_child(picker); | 
					
						
							| 
									
										
										
										
											2017-01-10 01:49:55 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 	add_child(popup); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	checker = Ref<ImageTexture>(memnew(ImageTexture)); | 
					
						
							| 
									
										
										
										
											2017-05-17 07:36:47 -03:00
										 |  |  | 	Ref<Image> img = memnew(Image(checker_bg_png)); | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-13 23:47:34 +02:00
										 |  |  | int GradientEdit::_get_point_from_pos(int x) { | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 	int result = -1; | 
					
						
							| 
									
										
										
										
											2018-09-07 13:49:10 -03:00
										 |  |  | 	int total_w = get_size().width - get_size().height - SPACING; | 
					
						
							|  |  |  | 	float min_distance = 1e20; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i < points.size(); i++) { | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 		//Check if we clicked at point
 | 
					
						
							| 
									
										
										
										
											2018-09-07 13:49:10 -03:00
										 |  |  | 		float distance = ABS(x - points[i].offset * total_w); | 
					
						
							|  |  |  | 		float min = (POINT_WIDTH / 2 * 1.7); //make it easier to grab
 | 
					
						
							|  |  |  | 		if (distance <= min && distance < min_distance) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			result = i; | 
					
						
							| 
									
										
										
										
											2018-09-07 13:49:10 -03:00
										 |  |  | 			min_distance = distance; | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-13 23:47:34 +02:00
										 |  |  | void GradientEdit::_show_color_picker() { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (grabbed == -1) { | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-14 11:07:57 -03:00
										 |  |  | 	picker->set_pick_color(points[grabbed].color); | 
					
						
							| 
									
										
										
										
											2020-03-12 09:37:40 -03:00
										 |  |  | 	Size2 minsize = popup->get_contents_minimum_size(); | 
					
						
							| 
									
										
										
										
											2018-09-07 13:49:10 -03:00
										 |  |  | 	bool show_above = false; | 
					
						
							|  |  |  | 	if (get_global_position().y + get_size().y + minsize.y > get_viewport_rect().size.y) { | 
					
						
							|  |  |  | 		show_above = true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (show_above) { | 
					
						
							| 
									
										
										
										
											2020-03-12 09:37:40 -03:00
										 |  |  | 		popup->set_position(get_screen_position() - Vector2(0, minsize.y)); | 
					
						
							| 
									
										
										
										
											2018-09-07 13:49:10 -03:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2020-03-12 09:37:40 -03:00
										 |  |  | 		popup->set_position(get_screen_position() + Vector2(0, get_size().y)); | 
					
						
							| 
									
										
										
										
											2018-09-07 13:49:10 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 	popup->popup(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-13 23:47:34 +02:00
										 |  |  | GradientEdit::~GradientEdit() { | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-13 23:47:34 +02:00
										 |  |  | void GradientEdit::_gui_input(const Ref<InputEvent> &p_event) { | 
					
						
							| 
									
										
										
										
											2021-04-05 08:52:21 +02:00
										 |  |  | 	ERR_FAIL_COND(p_event.is_null()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 	Ref<InputEventKey> k = p_event; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-05 20:59:35 +03:00
										 |  |  | 	if (k.is_valid() && k->is_pressed() && k->get_keycode() == KEY_DELETE && grabbed != -1) { | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 		points.remove(grabbed); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		grabbed = -1; | 
					
						
							|  |  |  | 		grabbing = false; | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 		update(); | 
					
						
							|  |  |  | 		emit_signal("ramp_changed"); | 
					
						
							|  |  |  | 		accept_event(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 	Ref<InputEventMouseButton> mb = p_event; | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 	//Show color picker on double click.
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 	if (mb.is_valid() && mb->get_button_index() == 1 && mb->is_doubleclick() && mb->is_pressed()) { | 
					
						
							| 
									
										
										
										
											2017-06-03 10:54:24 +02:00
										 |  |  | 		grabbed = _get_point_from_pos(mb->get_position().x); | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 		_show_color_picker(); | 
					
						
							|  |  |  | 		accept_event(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//Delete point on right click
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 	if (mb.is_valid() && mb->get_button_index() == 2 && mb->is_pressed()) { | 
					
						
							| 
									
										
										
										
											2017-06-03 10:54:24 +02:00
										 |  |  | 		grabbed = _get_point_from_pos(mb->get_position().x); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (grabbed != -1) { | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 			points.remove(grabbed); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			grabbed = -1; | 
					
						
							|  |  |  | 			grabbing = false; | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 			update(); | 
					
						
							|  |  |  | 			emit_signal("ramp_changed"); | 
					
						
							|  |  |  | 			accept_event(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-11 04:36:11 +02:00
										 |  |  | 	//Hold alt key to duplicate selected color
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 	if (mb.is_valid() && mb->get_button_index() == 1 && mb->is_pressed() && mb->get_alt()) { | 
					
						
							| 
									
										
										
										
											2017-06-03 10:54:24 +02:00
										 |  |  | 		int x = mb->get_position().x; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		grabbed = _get_point_from_pos(x); | 
					
						
							| 
									
										
										
										
											2015-06-11 04:36:11 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (grabbed != -1) { | 
					
						
							| 
									
										
										
										
											2018-09-07 13:49:10 -03:00
										 |  |  | 			int total_w = get_size().width - get_size().height - SPACING; | 
					
						
							| 
									
										
										
										
											2017-05-28 21:46:48 -03:00
										 |  |  | 			Gradient::Point newPoint = points[grabbed]; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			newPoint.offset = CLAMP(x / float(total_w), 0, 1); | 
					
						
							| 
									
										
										
										
											2015-06-11 04:36:11 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			points.push_back(newPoint); | 
					
						
							|  |  |  | 			points.sort(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			for (int i = 0; i < points.size(); ++i) { | 
					
						
							|  |  |  | 				if (points[i].offset == newPoint.offset) { | 
					
						
							|  |  |  | 					grabbed = i; | 
					
						
							| 
									
										
										
										
											2015-06-11 04:36:11 +02:00
										 |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			emit_signal("ramp_changed"); | 
					
						
							|  |  |  | 			update(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-07 13:49:10 -03:00
										 |  |  | 	//select
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 	if (mb.is_valid() && mb->get_button_index() == 1 && mb->is_pressed()) { | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 		update(); | 
					
						
							| 
									
										
										
										
											2017-06-03 10:54:24 +02:00
										 |  |  | 		int x = mb->get_position().x; | 
					
						
							| 
									
										
										
										
											2018-09-07 13:49:10 -03:00
										 |  |  | 		int total_w = get_size().width - get_size().height - SPACING; | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		//Check if color selector was clicked.
 | 
					
						
							| 
									
										
										
										
											2018-09-07 13:49:10 -03:00
										 |  |  | 		if (x > total_w + SPACING) { | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 			_show_color_picker(); | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		grabbing = true; | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		grabbed = _get_point_from_pos(x); | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 		//grab or select
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (grabbed != -1) { | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		//insert
 | 
					
						
							| 
									
										
										
										
											2017-05-28 21:46:48 -03:00
										 |  |  | 		Gradient::Point newPoint; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		newPoint.offset = CLAMP(x / float(total_w), 0, 1); | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-28 21:46:48 -03:00
										 |  |  | 		Gradient::Point prev; | 
					
						
							|  |  |  | 		Gradient::Point next; | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		int pos = -1; | 
					
						
							|  |  |  | 		for (int i = 0; i < points.size(); i++) { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			if (points[i].offset < newPoint.offset) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				pos = i; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (pos == -1) { | 
					
						
							|  |  |  | 			prev.color = Color(0, 0, 0); | 
					
						
							|  |  |  | 			prev.offset = 0; | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 			if (points.size()) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				next = points[0]; | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				next.color = Color(1, 1, 1); | 
					
						
							|  |  |  | 				next.offset = 1.0; | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			if (pos == points.size() - 1) { | 
					
						
							|  |  |  | 				next.color = Color(1, 1, 1); | 
					
						
							|  |  |  | 				next.offset = 1.0; | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				next = points[pos + 1]; | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			prev = points[pos]; | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-16 05:07:33 -04:00
										 |  |  | 		newPoint.color = prev.color.lerp(next.color, (newPoint.offset - prev.offset) / (next.offset - prev.offset)); | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		points.push_back(newPoint); | 
					
						
							|  |  |  | 		points.sort(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		for (int i = 0; i < points.size(); i++) { | 
					
						
							|  |  |  | 			if (points[i].offset == newPoint.offset) { | 
					
						
							|  |  |  | 				grabbed = i; | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		emit_signal("ramp_changed"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 	if (mb.is_valid() && mb->get_button_index() == 1 && !mb->is_pressed()) { | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 		if (grabbing) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			grabbing = false; | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 			emit_signal("ramp_changed"); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		update(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 	Ref<InputEventMouseMotion> mm = p_event; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (mm.is_valid() && grabbing) { | 
					
						
							| 
									
										
										
										
											2018-09-07 13:49:10 -03:00
										 |  |  | 		int total_w = get_size().width - get_size().height - SPACING; | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-03 10:54:24 +02:00
										 |  |  | 		int x = mm->get_position().x; | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		float newofs = CLAMP(x / float(total_w), 0, 1); | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-02 13:35:42 +02:00
										 |  |  | 		// Snap to "round" coordinates if holding Ctrl.
 | 
					
						
							|  |  |  | 		// Be more precise if holding Shift as well
 | 
					
						
							|  |  |  | 		if (mm->get_control()) { | 
					
						
							| 
									
										
										
										
											2020-12-21 18:02:57 +00:00
										 |  |  | 			newofs = Math::snapped(newofs, mm->get_shift() ? 0.025 : 0.1); | 
					
						
							| 
									
										
										
										
											2019-09-02 13:35:42 +02:00
										 |  |  | 		} else if (mm->get_shift()) { | 
					
						
							|  |  |  | 			// Snap to nearest point if holding just Shift
 | 
					
						
							|  |  |  | 			const float snap_threshold = 0.03; | 
					
						
							| 
									
										
										
										
											2018-10-22 09:08:16 +07:00
										 |  |  | 			float smallest_ofs = snap_threshold; | 
					
						
							| 
									
										
										
										
											2018-10-04 18:54:20 +02:00
										 |  |  | 			bool found = false; | 
					
						
							|  |  |  | 			int nearest_point = 0; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			for (int i = 0; i < points.size(); ++i) { | 
					
						
							| 
									
										
										
										
											2015-06-11 04:36:11 +02:00
										 |  |  | 				if (i != grabbed) { | 
					
						
							|  |  |  | 					float temp_ofs = ABS(points[i].offset - newofs); | 
					
						
							|  |  |  | 					if (temp_ofs < smallest_ofs) { | 
					
						
							|  |  |  | 						smallest_ofs = temp_ofs; | 
					
						
							|  |  |  | 						nearest_point = i; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 						if (found) { | 
					
						
							| 
									
										
										
										
											2015-06-11 04:36:11 +02:00
										 |  |  | 							break; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 						} | 
					
						
							| 
									
										
										
										
											2018-10-04 18:54:20 +02:00
										 |  |  | 						found = true; | 
					
						
							| 
									
										
										
										
											2015-06-11 04:36:11 +02:00
										 |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-10-04 18:54:20 +02:00
										 |  |  | 			if (found) { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 				if (points[nearest_point].offset < newofs) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					newofs = points[nearest_point].offset + 0.00001; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 				} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					newofs = points[nearest_point].offset - 0.00001; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				newofs = CLAMP(newofs, 0, 1); | 
					
						
							| 
									
										
										
										
											2015-06-11 04:36:11 +02:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		bool valid = true; | 
					
						
							|  |  |  | 		for (int i = 0; i < points.size(); i++) { | 
					
						
							|  |  |  | 			if (points[i].offset == newofs && i != grabbed) { | 
					
						
							|  |  |  | 				valid = false; | 
					
						
							| 
									
										
										
										
											2019-11-19 22:05:03 +01:00
										 |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-19 22:05:03 +01:00
										 |  |  | 		if (!valid || grabbed == -1) { | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2019-11-19 22:05:03 +01:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-07-25 03:11:03 +02:00
										 |  |  | 		points.write[grabbed].offset = newofs; | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		points.sort(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		for (int i = 0; i < points.size(); i++) { | 
					
						
							|  |  |  | 			if (points[i].offset == newofs) { | 
					
						
							|  |  |  | 				grabbed = i; | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		emit_signal("ramp_changed"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		update(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-13 23:47:34 +02:00
										 |  |  | void GradientEdit::_notification(int p_what) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (p_what == NOTIFICATION_ENTER_TREE) { | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 		if (!picker->is_connected("color_changed", callable_mp(this, &GradientEdit::_color_changed))) { | 
					
						
							|  |  |  | 			picker->connect("color_changed", callable_mp(this, &GradientEdit::_color_changed)); | 
					
						
							| 
									
										
										
										
											2016-06-30 15:12:14 +01:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (p_what == NOTIFICATION_DRAW) { | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 		int w = get_size().x; | 
					
						
							|  |  |  | 		int h = get_size().y; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		if (w == 0 || h == 0) { | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 			return; //Safety check. We have division by 'h'. And in any case there is nothing to draw with such size
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-07 13:49:10 -03:00
										 |  |  | 		int total_w = get_size().width - get_size().height - SPACING; | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		//Draw checker pattern for ramp
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		_draw_checker(0, 0, total_w, h); | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		//Draw color ramp
 | 
					
						
							| 
									
										
										
										
											2017-05-28 21:46:48 -03:00
										 |  |  | 		Gradient::Point prev; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		prev.offset = 0; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		if (points.size() == 0) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			prev.color = Color(0, 0, 0); //Draw black rectangle if we have no points
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			prev.color = points[0].color; //Extend color of first point to the beginning.
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		for (int i = -1; i < points.size(); i++) { | 
					
						
							| 
									
										
										
										
											2017-05-28 21:46:48 -03:00
										 |  |  | 			Gradient::Point next; | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 			//If there is no next point
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			if (i + 1 == points.size()) { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 				if (points.size() == 0) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					next.color = Color(0, 0, 0); //Draw black rectangle if we have no points
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 				} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					next.color = points[i].color; //Extend color of last point to the end.
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				next.offset = 1; | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				next = points[i + 1]; | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			if (prev.offset == next.offset) { | 
					
						
							|  |  |  | 				prev = next; | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 				continue; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			Vector<Vector2> points; | 
					
						
							|  |  |  | 			Vector<Color> colors; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			points.push_back(Vector2(prev.offset * total_w, h)); | 
					
						
							|  |  |  | 			points.push_back(Vector2(prev.offset * total_w, 0)); | 
					
						
							|  |  |  | 			points.push_back(Vector2(next.offset * total_w, 0)); | 
					
						
							|  |  |  | 			points.push_back(Vector2(next.offset * total_w, h)); | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 			colors.push_back(prev.color); | 
					
						
							|  |  |  | 			colors.push_back(prev.color); | 
					
						
							|  |  |  | 			colors.push_back(next.color); | 
					
						
							|  |  |  | 			colors.push_back(next.color); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			draw_primitive(points, colors, Vector<Point2>()); | 
					
						
							|  |  |  | 			prev = next; | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		//Draw point markers
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		for (int i = 0; i < points.size(); i++) { | 
					
						
							| 
									
										
										
										
											2020-11-03 00:21:06 +01:00
										 |  |  | 			Color col = points[i].color.inverted(); | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 			col.a = 0.9; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			draw_line(Vector2(points[i].offset * total_w, 0), Vector2(points[i].offset * total_w, h / 2), col); | 
					
						
							| 
									
										
										
										
											2018-09-07 13:49:10 -03:00
										 |  |  | 			Rect2 rect = Rect2(points[i].offset * total_w - POINT_WIDTH / 2, h / 2, POINT_WIDTH, h / 2); | 
					
						
							|  |  |  | 			draw_rect(rect, points[i].color, true); | 
					
						
							|  |  |  | 			draw_rect(rect, col, false); | 
					
						
							|  |  |  | 			if (grabbed == i) { | 
					
						
							|  |  |  | 				rect = rect.grow(-1); | 
					
						
							|  |  |  | 				if (has_focus()) { | 
					
						
							|  |  |  | 					draw_rect(rect, Color(1, 0, 0, 0.9), false); | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					draw_rect(rect, Color(0.6, 0, 0, 0.9), false); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				rect = rect.grow(-1); | 
					
						
							|  |  |  | 				draw_rect(rect, col, false); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		//Draw "button" for color selector
 | 
					
						
							| 
									
										
										
										
											2018-09-07 13:49:10 -03:00
										 |  |  | 		_draw_checker(total_w + SPACING, 0, h, h); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (grabbed != -1) { | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 			//Draw with selection color
 | 
					
						
							| 
									
										
										
										
											2018-09-07 13:49:10 -03:00
										 |  |  | 			draw_rect(Rect2(total_w + SPACING, 0, h, h), points[grabbed].color); | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			//if no color selected draw grey color with 'X' on top.
 | 
					
						
							| 
									
										
										
										
											2018-09-07 13:49:10 -03:00
										 |  |  | 			draw_rect(Rect2(total_w + SPACING, 0, h, h), Color(0.5, 0.5, 0.5, 1)); | 
					
						
							|  |  |  | 			draw_line(Vector2(total_w + SPACING, 0), Vector2(total_w + SPACING + h, h), Color(1, 1, 1, 0.6)); | 
					
						
							|  |  |  | 			draw_line(Vector2(total_w + SPACING, h), Vector2(total_w + SPACING + h, 0), Color(1, 1, 1, 0.6)); | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		//Draw borders around color ramp if in focus
 | 
					
						
							|  |  |  | 		if (has_focus()) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			draw_line(Vector2(-1, -1), Vector2(total_w + 1, -1), Color(1, 1, 1, 0.6)); | 
					
						
							|  |  |  | 			draw_line(Vector2(total_w + 1, -1), Vector2(total_w + 1, h + 1), Color(1, 1, 1, 0.6)); | 
					
						
							|  |  |  | 			draw_line(Vector2(total_w + 1, h + 1), Vector2(-1, h + 1), Color(1, 1, 1, 0.6)); | 
					
						
							|  |  |  | 			draw_line(Vector2(-1, -1), Vector2(-1, h + 1), Color(1, 1, 1, 0.6)); | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-02-12 22:22:45 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { | 
					
						
							|  |  |  | 		if (!is_visible()) { | 
					
						
							|  |  |  | 			grabbing = false; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-13 23:47:34 +02:00
										 |  |  | void GradientEdit::_draw_checker(int x, int y, int w, int h) { | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 	//Draw it with polygon to insert UVs for scale
 | 
					
						
							|  |  |  | 	Vector<Vector2> backPoints; | 
					
						
							|  |  |  | 	backPoints.push_back(Vector2(x, y)); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	backPoints.push_back(Vector2(x, y + h)); | 
					
						
							|  |  |  | 	backPoints.push_back(Vector2(x + w, y + h)); | 
					
						
							|  |  |  | 	backPoints.push_back(Vector2(x + w, y)); | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 	Vector<Color> colorPoints; | 
					
						
							|  |  |  | 	colorPoints.push_back(Color(1, 1, 1, 1)); | 
					
						
							|  |  |  | 	colorPoints.push_back(Color(1, 1, 1, 1)); | 
					
						
							|  |  |  | 	colorPoints.push_back(Color(1, 1, 1, 1)); | 
					
						
							|  |  |  | 	colorPoints.push_back(Color(1, 1, 1, 1)); | 
					
						
							|  |  |  | 	Vector<Vector2> uvPoints; | 
					
						
							|  |  |  | 	//Draw checker pattern pixel-perfect and scale it by 2.
 | 
					
						
							|  |  |  | 	uvPoints.push_back(Vector2(x, y)); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	uvPoints.push_back(Vector2(x, y + h * .5f / checker->get_height())); | 
					
						
							|  |  |  | 	uvPoints.push_back(Vector2(x + w * .5f / checker->get_width(), y + h * .5f / checker->get_height())); | 
					
						
							|  |  |  | 	uvPoints.push_back(Vector2(x + w * .5f / checker->get_width(), y)); | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 	draw_polygon(backPoints, colorPoints, uvPoints, checker); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-13 23:47:34 +02:00
										 |  |  | Size2 GradientEdit::get_minimum_size() const { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	return Vector2(0, 16); | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-13 23:47:34 +02:00
										 |  |  | void GradientEdit::_color_changed(const Color &p_color) { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (grabbed == -1) { | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-07-25 03:11:03 +02:00
										 |  |  | 	points.write[grabbed].color = p_color; | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 	update(); | 
					
						
							|  |  |  | 	emit_signal("ramp_changed"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-13 23:47:34 +02:00
										 |  |  | void GradientEdit::set_ramp(const Vector<float> &p_offsets, const Vector<Color> &p_colors) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ERR_FAIL_COND(p_offsets.size() != p_colors.size()); | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 	points.clear(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i < p_offsets.size(); i++) { | 
					
						
							| 
									
										
										
										
											2017-05-28 21:46:48 -03:00
										 |  |  | 		Gradient::Point p; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		p.offset = p_offsets[i]; | 
					
						
							|  |  |  | 		p.color = p_colors[i]; | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 		points.push_back(p); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	points.sort(); | 
					
						
							|  |  |  | 	update(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-13 23:47:34 +02:00
										 |  |  | Vector<float> GradientEdit::get_offsets() const { | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 	Vector<float> ret; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	for (int i = 0; i < points.size(); i++) { | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 		ret.push_back(points[i].offset); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-13 23:47:34 +02:00
										 |  |  | Vector<Color> GradientEdit::get_colors() const { | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 	Vector<Color> ret; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	for (int i = 0; i < points.size(); i++) { | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 		ret.push_back(points[i].color); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-13 23:47:34 +02:00
										 |  |  | void GradientEdit::set_points(Vector<Gradient::Point> &p_points) { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (points.size() != p_points.size()) { | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 		grabbed = -1; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 	points.clear(); | 
					
						
							|  |  |  | 	points = p_points; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-13 23:47:34 +02:00
										 |  |  | Vector<Gradient::Point> &GradientEdit::get_points() { | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 	return points; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-13 23:47:34 +02:00
										 |  |  | void GradientEdit::_bind_methods() { | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_gui_input"), &GradientEdit::_gui_input); | 
					
						
							| 
									
										
										
										
											2015-05-24 21:18:52 +03:00
										 |  |  | 	ADD_SIGNAL(MethodInfo("ramp_changed")); | 
					
						
							|  |  |  | } |