summaryrefslogtreecommitdiff
path: root/scene/resources
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources')
-rw-r--r--scene/resources/color_ramp.cpp117
-rw-r--r--scene/resources/color_ramp.h98
-rw-r--r--scene/resources/default_theme/checker_bg.pngbin0 -> 180 bytes
-rw-r--r--scene/resources/default_theme/theme_data.h5
4 files changed, 220 insertions, 0 deletions
diff --git a/scene/resources/color_ramp.cpp b/scene/resources/color_ramp.cpp
new file mode 100644
index 0000000000..97d3fafd58
--- /dev/null
+++ b/scene/resources/color_ramp.cpp
@@ -0,0 +1,117 @@
+/*
+ * color_ramp.h
+ */
+
+#include "color_ramp.h"
+
+//setter and getter names for property serialization
+#define COLOR_RAMP_GET_OFFSETS "get_offsets"
+#define COLOR_RAMP_GET_COLORS "get_colors"
+#define COLOR_RAMP_SET_OFFSETS "set_offsets"
+#define COLOR_RAMP_SET_COLORS "set_colors"
+
+ColorRamp::ColorRamp() {
+ //Set initial color ramp transition from black to white
+ points.resize(2);
+ points[0].color = Color(0,0,0,1);
+ points[0].offset = 0;
+ points[1].color = Color(1,1,1,1);
+ points[1].offset = 1;
+ is_sorted = true;
+}
+
+ColorRamp::~ColorRamp() {
+
+}
+
+void ColorRamp::_bind_methods() {
+
+ ObjectTypeDB::bind_method(_MD(COLOR_RAMP_SET_OFFSETS,"offsets"),&ColorRamp::set_offsets);
+ ObjectTypeDB::bind_method(_MD(COLOR_RAMP_GET_OFFSETS),&ColorRamp::get_offsets);
+
+ ObjectTypeDB::bind_method(_MD(COLOR_RAMP_SET_COLORS,"colors"),&ColorRamp::set_colors);
+ ObjectTypeDB::bind_method(_MD(COLOR_RAMP_GET_COLORS),&ColorRamp::get_colors);
+
+ ADD_PROPERTY( PropertyInfo(Variant::REAL,"offsets"),_SCS(COLOR_RAMP_SET_OFFSETS),_SCS(COLOR_RAMP_GET_OFFSETS) );
+ ADD_PROPERTY( PropertyInfo(Variant::REAL,"colors"),_SCS(COLOR_RAMP_SET_COLORS),_SCS(COLOR_RAMP_GET_COLORS) );
+}
+
+Vector<float> ColorRamp::get_offsets() const {
+ Vector<float> offsets;
+ offsets.resize(points.size());
+ for(int i = 0; i < points.size(); i++)
+ {
+ offsets[i] = points[i].offset;
+ }
+ return offsets;
+}
+
+Vector<Color> ColorRamp::get_colors() const {
+ Vector<Color> colors;
+ colors.resize(points.size());
+ for(int i = 0; i < points.size(); i++)
+ {
+ colors[i] = points[i].color;
+ }
+ return colors;
+}
+
+void ColorRamp::set_offsets(const Vector<float>& p_offsets) {
+ points.resize(p_offsets.size());
+ for(int i = 0; i < points.size(); i++)
+ {
+ points[i].offset = p_offsets[i];
+ }
+ is_sorted = false;
+}
+
+void ColorRamp::set_colors(const Vector<Color>& p_colors) {
+ if(points.size()<p_colors.size())
+ is_sorted = false;
+ points.resize(p_colors.size());
+ for(int i = 0; i < points.size(); i++)
+ {
+ points[i].color = p_colors[i];
+ }
+}
+
+Vector<ColorRamp::Point>& ColorRamp::get_points() {
+ return points;
+}
+
+void ColorRamp::set_points(Vector<ColorRamp::Point>& p_points) {
+ points = p_points;
+ is_sorted = false;
+}
+
+void ColorRamp::set_offset(int pos, const float offset) {
+ if(points.size() <= pos)
+ points.resize(pos + 1);
+ points[pos].offset = offset;
+ is_sorted = false;
+}
+
+float ColorRamp::get_offset(int pos) const {
+ if(points.size() > pos)
+ return points[pos].offset;
+ return 0; //TODO: Maybe throw some error instead?
+}
+
+void ColorRamp::set_color(int pos, const Color& color) {
+ if(points.size() <= pos)
+ {
+ points.resize(pos + 1);
+ is_sorted = false;
+ }
+ points[pos].color = color;
+}
+
+Color ColorRamp::get_color(int pos) const {
+ if(points.size() > pos)
+ return points[pos].color;
+ return Color(0,0,0,1); //TODO: Maybe throw some error instead?
+}
+
+int ColorRamp::get_points_count() const {
+ return points.size();
+}
diff --git a/scene/resources/color_ramp.h b/scene/resources/color_ramp.h
new file mode 100644
index 0000000000..8f6ba2c3e5
--- /dev/null
+++ b/scene/resources/color_ramp.h
@@ -0,0 +1,98 @@
+/*
+ * color_ramp.h
+ */
+
+#ifndef SCENE_RESOURCES_COLOR_RAMP_H_
+#define SCENE_RESOURCES_COLOR_RAMP_H_
+
+#include "resource.h"
+
+class ColorRamp: public Resource {
+ OBJ_TYPE( ColorRamp, Resource );
+ OBJ_SAVE_TYPE( ColorRamp );
+
+public:
+ struct Point {
+
+ float offset;
+ Color color;
+ bool operator<(const Point& p_ponit) const {
+ return offset<p_ponit.offset;
+ }
+ };
+
+private:
+ Vector<Point> points;
+ bool is_sorted;
+
+protected:
+ static void _bind_methods();
+
+public:
+ ColorRamp();
+ virtual ~ColorRamp();
+
+ void set_points(Vector<Point>& points);
+ Vector<Point>& get_points();
+
+ void set_offset(int pos, const float offset);
+ float get_offset(int pos) const;
+
+ void set_color(int pos, const Color& color);
+ Color get_color(int pos) const;
+
+ void set_offsets(const Vector<float>& offsets);
+ Vector<float> get_offsets() const;
+
+ void set_colors(const Vector<Color>& colors);
+ Vector<Color> get_colors() const;
+
+ _FORCE_INLINE_ Color get_color_at_offset(float p_offset) {
+
+ if (points.empty())
+ return Color(0,0,0,1);
+
+ if(!is_sorted)
+ {
+ points.sort();
+ is_sorted = true;
+ }
+
+ //binary search
+ int low = 0;
+ int high = points.size() -1;
+ int middle;
+
+ while( low <= high )
+ {
+ middle = ( low + high ) / 2;
+ Point& point = points[middle];
+ if( point.offset > p_offset ) {
+ high = middle - 1; //search low end of array
+ } else if ( point.offset < p_offset) {
+ low = middle + 1; //search high end of array
+ } else {
+ return point.color;
+ }
+ }
+
+ //return interpolated value
+ if (points[middle].offset>p_offset)
+ {
+ middle--;
+ }
+ int first=middle;
+ int second=middle+1;
+ if(second>=points.size())
+ return points[points.size()-1].color;
+ if(first<0)
+ return points[0].color;
+ Point& pointFirst = points[first];
+ Point& pointSecond = points[second];
+ return pointFirst.color.linear_interpolate(pointSecond.color, (p_offset-pointFirst.offset)/(pointSecond.offset - pointFirst.offset));
+ }
+
+ int get_points_count() const;
+};
+
+#endif /* SCENE_RESOURCES_COLOR_RAMP_H_ */
diff --git a/scene/resources/default_theme/checker_bg.png b/scene/resources/default_theme/checker_bg.png
new file mode 100644
index 0000000000..0674f9da26
--- /dev/null
+++ b/scene/resources/default_theme/checker_bg.png
Binary files differ
diff --git a/scene/resources/default_theme/theme_data.h b/scene/resources/default_theme/theme_data.h
index 78e210239d..8bd0a66271 100644
--- a/scene/resources/default_theme/theme_data.h
+++ b/scene/resources/default_theme/theme_data.h
@@ -49,6 +49,11 @@ static const unsigned char checked_png[]={
};
+static const unsigned char checker_bg_png[]={
+0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x8,0x0,0x0,0x0,0x8,0x8,0x6,0x0,0x0,0x0,0xc4,0xf,0xbe,0x8b,0x0,0x0,0x0,0x1,0x73,0x52,0x47,0x42,0x0,0xae,0xce,0x1c,0xe9,0x0,0x0,0x0,0x4,0x67,0x41,0x4d,0x41,0x0,0x0,0xb1,0x8f,0xb,0xfc,0x61,0x5,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xe,0xc4,0x0,0x0,0xe,0xc4,0x1,0x95,0x2b,0xe,0x1b,0x0,0x0,0x0,0x6,0x62,0x4b,0x47,0x44,0x0,0xff,0x0,0xff,0x0,0xff,0xa0,0xbd,0xa7,0x93,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xde,0x9,0x14,0xd,0x1c,0x1b,0x52,0x41,0x72,0xa4,0x0,0x0,0x0,0x24,0x49,0x44,0x41,0x54,0x28,0x53,0x63,0xfc,0xf,0x4,0xc,0x48,0xa0,0xa1,0xa1,0x1,0xca,0x82,0x0,0x26,0x28,0x8d,0x13,0x50,0xae,0x80,0xb1,0xbe,0xbe,0x7e,0x60,0xdd,0xc0,0xc0,0x0,0x0,0x78,0x11,0x9,0x87,0x2b,0xa,0xe1,0x69,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
+};
+
+
static const unsigned char close_png[]={
0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x10,0x8,0x6,0x0,0x0,0x0,0x1f,0xf3,0xff,0x61,0x0,0x0,0x0,0x6,0x62,0x4b,0x47,0x44,0x0,0x73,0x0,0x29,0x0,0x7c,0x29,0x1e,0x61,0x18,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x13,0x0,0x0,0xb,0x13,0x1,0x0,0x9a,0x9c,0x18,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xdd,0x9,0x19,0x1,0x14,0x3,0xf4,0x10,0x33,0xed,0x0,0x0,0x1,0x53,0x49,0x44,0x41,0x54,0x38,0xcb,0xcd,0x92,0xbd,0x4e,0x5b,0x41,0x10,0x85,0xbf,0xd9,0x9d,0xfd,0xb9,0xd7,0xb2,0xb9,0x81,0x8e,0x26,0xf4,0x69,0x53,0x50,0x44,0xa2,0x74,0x3,0xd,0xd,0x48,0x48,0xf4,0x3c,0x16,0x8f,0xc1,0x23,0xf0,0x0,0xf4,0x8e,0x90,0x11,0x96,0x25,0xa2,0x10,0x45,0x4a,0x9c,0x6b,0x4f,0xa,0xf6,0x4a,0xe6,0xc6,0x4e,0xb,0x47,0x5a,0xed,0xee,0x9c,0xd9,0xd1,0x99,0xb3,0x3,0x6f,0xd,0xd9,0x70,0xd7,0x72,0xfe,0xd3,0xe3,0x42,0xd9,0x5b,0xc0,0xba,0xa0,0xef,0x3d,0xfe,0xe0,0x9c,0x3b,0x35,0xb3,0x21,0xf0,0x1d,0xf8,0x5d,0xe2,0xd,0xf0,0xd9,0x39,0xf7,0xc5,0xcc,0xee,0x81,0x5f,0x9b,0xd4,0x4,0xe7,0xdc,0x65,0xd3,0x34,0x3f,0x53,0x4a,0x73,0xe0,0x18,0xd8,0x2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