Browse Source

Merge pull request #9482 from Noshyaar/pr-ramp

Fix shrunk ColorPickers
Rémi Verschelde 8 years ago
parent
commit
5a42bbaace

+ 0 - 3
editor/plugins/script_text_editor.cpp

@@ -1276,8 +1276,6 @@ void ScriptTextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) {
 						color_picker->set_pick_color(Color(color[0], color[1], color[2], alpha));
 						color_picker->set_pick_color(Color(color[0], color[1], color[2], alpha));
 					}
 					}
 					color_panel->set_position(get_global_transform().xform(get_local_mouse_pos()));
 					color_panel->set_position(get_global_transform().xform(get_local_mouse_pos()));
-					Size2 ms = Size2(300, color_picker->get_combined_minimum_size().height + 10);
-					color_panel->set_size(ms);
 				} else {
 				} else {
 					have_color = false;
 					have_color = false;
 				}
 				}
@@ -1360,7 +1358,6 @@ ScriptTextEditor::ScriptTextEditor() {
 	add_child(color_panel);
 	add_child(color_panel);
 	color_picker = memnew(ColorPicker);
 	color_picker = memnew(ColorPicker);
 	color_panel->add_child(color_picker);
 	color_panel->add_child(color_picker);
-	color_panel->set_child_rect(color_picker); //NOT
 	color_picker->connect("color_changed", this, "_color_changed");
 	color_picker->connect("color_changed", this, "_color_changed");
 
 
 	edit_hb = memnew(HBoxContainer);
 	edit_hb = memnew(HBoxContainer);

+ 0 - 4
editor/property_editor.cpp

@@ -815,16 +815,12 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant::
 				color_picker = memnew(ColorPicker);
 				color_picker = memnew(ColorPicker);
 				add_child(color_picker);
 				add_child(color_picker);
 				color_picker->hide();
 				color_picker->hide();
-				color_picker->set_area_as_parent_rect();
-				for (int i = 0; i < 4; i++)
-					color_picker->set_margin((Margin)i, 5);
 				color_picker->connect("color_changed", this, "_color_changed");
 				color_picker->connect("color_changed", this, "_color_changed");
 			}
 			}
 
 
 			color_picker->show();
 			color_picker->show();
 			color_picker->set_edit_alpha(hint != PROPERTY_HINT_COLOR_NO_ALPHA);
 			color_picker->set_edit_alpha(hint != PROPERTY_HINT_COLOR_NO_ALPHA);
 			color_picker->set_pick_color(v);
 			color_picker->set_pick_color(v);
-			set_size(Size2(307 * EDSCALE, 460 * EDSCALE));
 			color_picker->set_focus_on_line_edit();
 			color_picker->set_focus_on_line_edit();
 			/*
 			/*
 			int ofs=80;
 			int ofs=80;

+ 26 - 18
scene/gui/color_picker.cpp

@@ -50,6 +50,19 @@ void ColorPicker::_notification(int p_what) {
 			_update_color();
 			_update_color();
 		} break;
 		} break;
 
 
+		case NOTIFICATION_PARENTED: {
+			for (int i = 0; i < 4; i++)
+				set_margin((Margin)i, get_constant("margin"));
+		} break;
+
+		case NOTIFICATION_VISIBILITY_CHANGED: {
+			if (get_parent()) {
+				Popup *p = get_parent()->cast_to<Popup>();
+				if (p)
+					p->set_size(Size2(get_combined_minimum_size().width + get_constant("margin") * 2, get_combined_minimum_size().height + get_constant("margin") * 2));
+			}
+		} break;
+
 		case MainLoop::NOTIFICATION_WM_QUIT_REQUEST: {
 		case MainLoop::NOTIFICATION_WM_QUIT_REQUEST: {
 			if (screen != NULL) {
 			if (screen != NULL) {
 				if (screen->is_visible()) {
 				if (screen->is_visible()) {
@@ -254,13 +267,13 @@ void ColorPicker::_update_text_value() {
 }
 }
 
 
 void ColorPicker::_sample_draw() {
 void ColorPicker::_sample_draw() {
-	sample->draw_rect(Rect2(Point2(), Size2(uv_edit->get_size().width, 20)), color);
+	sample->draw_rect(Rect2(Point2(), Size2(uv_edit->get_size().width, sample->get_size().height * 0.95)), color);
 }
 }
 
 
-void ColorPicker::_hsv_draw(int p_wich, Control *c) {
+void ColorPicker::_hsv_draw(int p_which, Control *c) {
 	if (!c)
 	if (!c)
 		return;
 		return;
-	if (p_wich == 0) {
+	if (p_which == 0) {
 		Vector<Point2> points;
 		Vector<Point2> points;
 		points.push_back(Vector2());
 		points.push_back(Vector2());
 		points.push_back(Vector2(c->get_size().x, 0));
 		points.push_back(Vector2(c->get_size().x, 0));
@@ -291,7 +304,7 @@ void ColorPicker::_hsv_draw(int p_wich, Control *c) {
 		c->draw_line(Point2(x, 0), Point2(x, c->get_size().y), col.inverted());
 		c->draw_line(Point2(x, 0), Point2(x, c->get_size().y), col.inverted());
 		c->draw_line(Point2(0, y), Point2(c->get_size().x, y), col.inverted());
 		c->draw_line(Point2(0, y), Point2(c->get_size().x, y), col.inverted());
 		c->draw_line(Point2(x, y), Point2(x, y), Color(1, 1, 1), 2);
 		c->draw_line(Point2(x, y), Point2(x, y), Color(1, 1, 1), 2);
-	} else if (p_wich == 1) {
+	} else if (p_which == 1) {
 		Ref<Texture> hue = get_icon("color_hue", "ColorPicker");
 		Ref<Texture> hue = get_icon("color_hue", "ColorPicker");
 		c->draw_texture_rect(hue, Rect2(Point2(), c->get_size()));
 		c->draw_texture_rect(hue, Rect2(Point2(), c->get_size()));
 		int y = c->get_size().y - c->get_size().y * (1.0 - h);
 		int y = c->get_size().y - c->get_size().y * (1.0 - h);
@@ -512,23 +525,18 @@ ColorPicker::ColorPicker()
 	uv_edit->set_mouse_filter(MOUSE_FILTER_PASS);
 	uv_edit->set_mouse_filter(MOUSE_FILTER_PASS);
 	uv_edit->set_h_size_flags(SIZE_EXPAND_FILL);
 	uv_edit->set_h_size_flags(SIZE_EXPAND_FILL);
 	uv_edit->set_v_size_flags(SIZE_EXPAND_FILL);
 	uv_edit->set_v_size_flags(SIZE_EXPAND_FILL);
-	Vector<Variant> args = Vector<Variant>();
-	args.push_back(0);
-	args.push_back(uv_edit);
-	uv_edit->connect("draw", this, "_hsv_draw", args);
+	uv_edit->set_custom_minimum_size(Size2(get_constant("sv_width"), get_constant("sv_height")));
+	uv_edit->connect("draw", this, "_hsv_draw", make_binds(0, uv_edit));
 
 
 	add_child(hb_edit);
 	add_child(hb_edit);
 
 
 	w_edit = memnew(Control);
 	w_edit = memnew(Control);
 	//w_edit->set_ignore_mouse(false);
 	//w_edit->set_ignore_mouse(false);
-	w_edit->set_custom_minimum_size(Size2(30, 0));
+	w_edit->set_custom_minimum_size(Size2(get_constant("h_width"), 0));
 	w_edit->set_h_size_flags(SIZE_FILL);
 	w_edit->set_h_size_flags(SIZE_FILL);
 	w_edit->set_v_size_flags(SIZE_EXPAND_FILL);
 	w_edit->set_v_size_flags(SIZE_EXPAND_FILL);
 	w_edit->connect("gui_input", this, "_w_input");
 	w_edit->connect("gui_input", this, "_w_input");
-	args.clear();
-	args.push_back(1);
-	args.push_back(w_edit);
-	w_edit->connect("draw", this, "_hsv_draw", args);
+	w_edit->connect("draw", this, "_hsv_draw", make_binds(1, w_edit));
 
 
 	hb_edit->add_child(uv_edit);
 	hb_edit->add_child(uv_edit);
 	hb_edit->add_child(memnew(VSeparator));
 	hb_edit->add_child(memnew(VSeparator));
@@ -549,10 +557,12 @@ ColorPicker::ColorPicker()
 		HBoxContainer *hbc = memnew(HBoxContainer);
 		HBoxContainer *hbc = memnew(HBoxContainer);
 
 
 		labels[i] = memnew(Label(lt[i]));
 		labels[i] = memnew(Label(lt[i]));
-		labels[i]->set_custom_minimum_size(Size2(10, 0));
+		labels[i]->set_custom_minimum_size(Size2(get_constant("label_width"), 0));
+		labels[i]->set_v_size_flags(SIZE_SHRINK_CENTER);
 		hbc->add_child(labels[i]);
 		hbc->add_child(labels[i]);
 
 
 		scroll[i] = memnew(HSlider);
 		scroll[i] = memnew(HSlider);
+		scroll[i]->set_v_size_flags(SIZE_SHRINK_CENTER);
 		hbc->add_child(scroll[i]);
 		hbc->add_child(scroll[i]);
 
 
 		values[i] = memnew(SpinBox);
 		values[i] = memnew(SpinBox);
@@ -571,7 +581,7 @@ ColorPicker::ColorPicker()
 	HBoxContainer *hhb = memnew(HBoxContainer);
 	HBoxContainer *hhb = memnew(HBoxContainer);
 
 
 	btn_mode = memnew(CheckButton);
 	btn_mode = memnew(CheckButton);
-	btn_mode->set_text(TTR("RAW Mode"));
+	btn_mode->set_text(TTR("Raw Mode"));
 	btn_mode->connect("toggled", this, "set_raw_mode");
 	btn_mode->connect("toggled", this, "set_raw_mode");
 	hhb->add_child(btn_mode);
 	hhb->add_child(btn_mode);
 	vbr->add_child(hhb);
 	vbr->add_child(hhb);
@@ -617,9 +627,7 @@ void ColorPickerButton::_color_changed(const Color &p_color) {
 
 
 void ColorPickerButton::pressed() {
 void ColorPickerButton::pressed() {
 
 
-	Size2 ms = Size2(300, picker->get_combined_minimum_size().height + 10);
-	popup->set_position(get_global_position() - Size2(0, ms.height));
-	popup->set_size(ms);
+	popup->set_position(get_global_position() - picker->get_combined_minimum_size());
 	popup->popup();
 	popup->popup();
 	picker->set_focus_on_line_edit();
 	picker->set_focus_on_line_edit();
 }
 }

+ 1 - 1
scene/gui/color_picker.h

@@ -79,7 +79,7 @@ private:
 	void _update_text_value();
 	void _update_text_value();
 	void _text_type_toggled();
 	void _text_type_toggled();
 	void _sample_draw();
 	void _sample_draw();
-	void _hsv_draw(int p_wich, Control *c);
+	void _hsv_draw(int p_which, Control *c);
 
 
 	void _uv_input(const Ref<InputEvent> &p_input);
 	void _uv_input(const Ref<InputEvent> &p_input);
 	void _w_input(const Ref<InputEvent> &p_input);
 	void _w_input(const Ref<InputEvent> &p_input);

+ 1 - 3
scene/gui/gradient_edit.cpp

@@ -61,10 +61,8 @@ int GradientEdit::_get_point_from_pos(int x) {
 void GradientEdit::_show_color_picker() {
 void GradientEdit::_show_color_picker() {
 	if (grabbed == -1)
 	if (grabbed == -1)
 		return;
 		return;
-	Size2 ms = Size2(350, picker->get_combined_minimum_size().height + 10);
 	picker->set_pick_color(points[grabbed].color);
 	picker->set_pick_color(points[grabbed].color);
-	popup->set_position(get_global_position() - Vector2(ms.width - get_size().width, ms.height));
-	popup->set_size(ms);
+	popup->set_position(get_global_position() - popup->get_combined_minimum_size());
 	popup->popup();
 	popup->popup();
 }
 }
 
 

+ 5 - 5
scene/resources/default_theme/default_theme.cpp

@@ -761,11 +761,11 @@ void fill_default_theme(Ref<Theme> &t, const Ref<Font> &default_font, const Ref<
 
 
 	// colorPicker
 	// colorPicker
 
 
-	t->set_constant("value_height", "ColorPicker", 23 * scale);
-	t->set_constant("value_width", "ColorPicker", 50 * scale);
-	t->set_constant("color_width", "ColorPicker", 100 * scale);
-	t->set_constant("label_width", "ColorPicker", 20 * scale);
-	t->set_constant("hseparator", "ColorPicker", 4 * scale);
+	t->set_constant("margin", "ColorPicker", 4 * scale);
+	t->set_constant("sv_width", "ColorPicker", 256 * scale);
+	t->set_constant("sv_height", "ColorPicker", 256 * scale);
+	t->set_constant("h_width", "ColorPicker", 30 * scale);
+	t->set_constant("label_width", "ColorPicker", 10 * scale);
 
 
 	t->set_icon("screen_picker", "ColorPicker", make_icon(icon_color_pick_png));
 	t->set_icon("screen_picker", "ColorPicker", make_icon(icon_color_pick_png));
 	t->set_icon("add_preset", "ColorPicker", make_icon(icon_add_png));
 	t->set_icon("add_preset", "ColorPicker", make_icon(icon_add_png));