Sfoglia il codice sorgente

Merge pull request #7711 from williamd1k0/cherrypick-colorframe

Add ColorFrame control (2.1)
Rémi Verschelde 8 anni fa
parent
commit
be0350704f

+ 36 - 0
scene/gui/color_rect.cpp

@@ -0,0 +1,36 @@
+#include "color_rect.h"
+
+
+
+
+void ColorFrame::set_frame_color(const Color& p_color) {
+
+	color=p_color;
+	update();
+}
+
+Color ColorFrame::get_frame_color() const{
+
+	return color;
+}
+
+void ColorFrame::_notification(int p_what) {
+
+	if (p_what==NOTIFICATION_DRAW) {
+		draw_rect(Rect2(Point2(),get_size()),color);
+	}
+}
+
+void ColorFrame::_bind_methods() {
+
+	ObjectTypeDB::bind_method(_MD("set_frame_color","color"),&ColorFrame::set_frame_color);
+	ObjectTypeDB::bind_method(_MD("get_frame_color"),&ColorFrame::get_frame_color);
+
+	ADD_PROPERTY(PropertyInfo(Variant::COLOR,"color"),_SCS("set_frame_color"),_SCS("get_frame_color") );
+}
+
+ColorFrame::ColorFrame() {
+
+	color=Color(1,1,1);
+}
+

+ 22 - 0
scene/gui/color_rect.h

@@ -0,0 +1,22 @@
+#ifndef COLORRECT_H
+#define COLORRECT_H
+
+#include "scene/gui/control.h"
+
+class ColorFrame : public Control  {
+	OBJ_TYPE(ColorFrame,Control)
+
+	Color color;
+protected:
+
+	void _notification(int p_what);
+	static void _bind_methods();
+public:
+
+	void set_frame_color(const Color& p_color);
+	Color get_frame_color() const;
+
+	ColorFrame();
+};
+
+#endif // COLORRECT_H

+ 2 - 0
scene/register_scene_types.cpp

@@ -55,6 +55,7 @@
 #include "scene/gui/option_button.h"
 #include "scene/gui/color_picker.h"
 #include "scene/gui/texture_frame.h"
+#include "scene/gui/color_rect.h"
 #include "scene/gui/patch_9_frame.h"
 #include "scene/gui/menu_button.h"
 #include "scene/gui/check_box.h"
@@ -338,6 +339,7 @@ void register_scene_types() {
 	OS::get_singleton()->yield(); //may take time to init
 
 	ObjectTypeDB::register_type<TextureFrame>();
+	ObjectTypeDB::register_type<ColorFrame>();
 	ObjectTypeDB::register_type<Patch9Frame>();
 	ObjectTypeDB::register_type<TabContainer>();
 	ObjectTypeDB::register_type<Tabs>();

BIN
tools/editor/icons/icon_color_frame.png