summaryrefslogtreecommitdiff
path: root/scene/resources
diff options
context:
space:
mode:
authorMarianoGNU <marianognu.easyrpg@gmail.com>2015-12-20 18:21:53 -0300
committerMarianoGNU <marianognu.easyrpg@gmail.com>2016-01-15 17:23:19 -0300
commit1f3d6824c8db30cd5636aaa3978a953bedff4ed8 (patch)
tree970e602191846d847029fbda46d54e08a02f4da5 /scene/resources
parentdc7755ffcd1e275b065d3acfcc7696697097567b (diff)
Move shaders to default theme and add shader_override related methods to Control class
Diffstat (limited to 'scene/resources')
-rw-r--r--scene/resources/default_theme/default_theme.cpp11
-rw-r--r--scene/resources/default_theme/make_header.py (renamed from scene/resources/default_theme/make_png_header.py)55
-rw-r--r--scene/resources/default_theme/theme_data.h39
-rw-r--r--scene/resources/default_theme/uv_editor.gsl19
-rw-r--r--scene/resources/default_theme/w_editor.gsl11
-rw-r--r--scene/resources/theme.cpp45
-rw-r--r--scene/resources/theme.h10
7 files changed, 176 insertions, 14 deletions
diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp
index 842dbb154b..2d6039ca4d 100644
--- a/scene/resources/default_theme/default_theme.cpp
+++ b/scene/resources/default_theme/default_theme.cpp
@@ -80,6 +80,13 @@ static Ref<Texture> make_icon(T p_src) {
return texture;
}
+static Ref<Shader> make_shader(const char*vertex_code,const char*fragment_code,const char*lighting_code) {
+ Ref<Shader> shader = (memnew( Shader(Shader::MODE_CANVAS_ITEM) ));
+ shader->set_code(vertex_code, fragment_code, lighting_code);
+
+ return shader;
+}
+
static Ref<Font> make_font(int p_height,int p_ascent, int p_valign, int p_charcount, const int *p_chars,const Ref<Texture> &p_texture) {
@@ -768,7 +775,9 @@ void make_default_theme() {
t->set_constant("hseparator","ColorPicker", 4);
t->set_icon("screen_picker","ColorPicker", make_icon( icon_color_pick_png ) );
-
+
+ t->set_shader("uv_editor", "ColorPicker", make_shader("", uv_editor_shader_code, ""));
+ t->set_shader("w_editor", "ColorPicker", make_shader("", w_editor_shader_code, ""));
// TooltipPanel
diff --git a/scene/resources/default_theme/make_png_header.py b/scene/resources/default_theme/make_header.py
index 0f0ce1808f..2d3f989e01 100644
--- a/scene/resources/default_theme/make_png_header.py
+++ b/scene/resources/default_theme/make_header.py
@@ -3,9 +3,6 @@ import os;
import glob;
import string;
-pixmaps = glob.glob("*.png");
-
-pixmaps.sort();
#Generate include files
@@ -15,27 +12,61 @@ f.write("// THIS FILE HAS BEEN AUTOGENERATED, DONT EDIT!!\n");
f.write("\n\n");
+#Generate png image block
+
+pixmaps = glob.glob("*.png");
+
+pixmaps.sort();
+
f.write("\n\n\n");
-
-
for x in pixmaps:
-
+
var_str=x[:-4]+"_png";
-
+
f.write("static const unsigned char "+ var_str +"[]={\n");
-
+
pngf=open(x,"rb");
-
+
b=pngf.read(1);
while(len(b)==1):
f.write(hex(ord(b)))
b=pngf.read(1);
if (len(b)==1):
f.write(",")
-
+
f.write("\n};\n\n\n");
pngf.close();
-
-f.close();
+#Generate shaders block
+
+shaders = glob.glob("*.gsl")
+
+shaders.sort();
+
+f.write("\n\n\n");
+
+for x in shaders:
+
+ var_str=x[:-4]+"_shader_code";
+
+ f.write("static const char *"+ var_str +"=\n");
+
+ sf=open(x,"rb");
+
+
+ b=sf.readline();
+ while(b!=""):
+ if (b.endswith("\r\n")):
+ b=b[:-2]
+ if (b.endswith("\n")):
+ b=b[:-1]
+ f.write(" \""+b)
+ b=sf.readline();
+ if (b!=""):
+ f.write("\"\n")
+
+ f.write("\";\n\n\n");
+ sf.close();
+
+f.close();
diff --git a/scene/resources/default_theme/theme_data.h b/scene/resources/default_theme/theme_data.h
index dc69cf4b0b..004b3e4ce8 100644
--- a/scene/resources/default_theme/theme_data.h
+++ b/scene/resources/default_theme/theme_data.h
@@ -524,3 +524,42 @@ static const unsigned char vsplitter_png[]={
};
+
+
+
+static const char *uv_editor_shader_code=
+ "vec3 nd1sl2=vec3(UV,0);"
+ "uniform float H=0;"
+ "float nd4sl0=H;"
+ "float nd7sl0=nd1sl2.x;"
+ "float nd7sl1=nd1sl2.y;"
+ "float nd7sl2=nd1sl2.z;"
+ "float nd2sl1def=-1;"
+ "float nd2sl0=nd7sl1*nd2sl1def;"
+ "float nd6sl1def=1;"
+ "float nd6sl0=nd2sl0+nd6sl1def;"
+ "vec3 nd3sl0=vec3(nd4sl0,nd7sl0,nd6sl0);"
+ "vec3 nd5sl0;"
+ "{"
+ " vec3 c = nd3sl0;"
+ " vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);"
+ " vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);"
+ " nd5sl0=c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);"
+ "}"
+ "COLOR.rgb=nd5sl0;";
+
+
+static const char *w_editor_shader_code=
+ "vec3 nd1sl2=vec3(UV,0);"
+ "float nd2sl1=1-nd1sl2.y;"
+ "vec3 nd3sl0=vec3(nd2sl1,1,1);"
+ "vec3 nd6sl0;"
+ "{"
+ " vec3 c = nd3sl0;"
+ " vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);"
+ " vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);"
+ " nd6sl0=c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);"
+ "}"
+ "COLOR.rgb=nd6sl0;";
+
+
diff --git a/scene/resources/default_theme/uv_editor.gsl b/scene/resources/default_theme/uv_editor.gsl
new file mode 100644
index 0000000000..8c24e76dd5
--- /dev/null
+++ b/scene/resources/default_theme/uv_editor.gsl
@@ -0,0 +1,19 @@
+vec3 nd1sl2=vec3(UV,0);
+uniform float H=0;
+float nd4sl0=H;
+float nd7sl0=nd1sl2.x;
+float nd7sl1=nd1sl2.y;
+float nd7sl2=nd1sl2.z;
+float nd2sl1def=-1;
+float nd2sl0=nd7sl1*nd2sl1def;
+float nd6sl1def=1;
+float nd6sl0=nd2sl0+nd6sl1def;
+vec3 nd3sl0=vec3(nd4sl0,nd7sl0,nd6sl0);
+vec3 nd5sl0;
+{
+ vec3 c = nd3sl0;
+ vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
+ vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
+ nd5sl0=c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
+}
+COLOR.rgb=nd5sl0; \ No newline at end of file
diff --git a/scene/resources/default_theme/w_editor.gsl b/scene/resources/default_theme/w_editor.gsl
new file mode 100644
index 0000000000..6d2dd9a0bb
--- /dev/null
+++ b/scene/resources/default_theme/w_editor.gsl
@@ -0,0 +1,11 @@
+vec3 nd1sl2=vec3(UV,0);
+float nd2sl1=1-nd1sl2.y;
+vec3 nd3sl0=vec3(nd2sl1,1,1);
+vec3 nd6sl0;
+{
+ vec3 c = nd3sl0;
+ vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
+ vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
+ nd6sl0=c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
+}
+COLOR.rgb=nd6sl0; \ No newline at end of file
diff --git a/scene/resources/theme.cpp b/scene/resources/theme.cpp
index e2413f7d84..685b2e07e1 100644
--- a/scene/resources/theme.cpp
+++ b/scene/resources/theme.cpp
@@ -266,7 +266,52 @@ void Theme::get_icon_list(StringName p_type, List<StringName> *p_list) const {
p_list->push_back(*key);
}
+
+}
+
+void Theme::set_shader(const StringName &p_name,const StringName &p_type,const Ref<Shader>& p_shader) {
+ bool new_value=!shader_map.has(p_type) || !shader_map[p_type].has(p_name);
+
+ shader_map[p_type][p_name]=p_shader;
+ if (new_value) {
+ _change_notify();
+ emit_changed();;
+ }
+}
+
+Ref<Shader> Theme::get_shader(const StringName &p_name, const StringName &p_type) const {
+ if (shader_map.has(p_type) && shader_map[p_type].has(p_name) && shader_map[p_type][p_name].is_valid()) {
+ return shader_map[p_type][p_name];
+ } else {
+ return NULL;
+ }
+}
+
+bool Theme::has_shader(const StringName &p_name, const StringName &p_type) const {
+ return (shader_map.has(p_type) && shader_map[p_type].has(p_name) && shader_map[p_type][p_name].is_valid());
+}
+
+void Theme::clear_shader(const StringName &p_name, const StringName &p_type) {
+ ERR_FAIL_COND(!shader_map.has(p_type));
+ ERR_FAIL_COND(!shader_map[p_type].has(p_name));
+
+ shader_map[p_type].erase(p_name);
+ _change_notify();
+ emit_changed();;
+}
+
+void Theme::get_shader_list(const StringName &p_type, List<StringName> *p_list) const {
+ if (!shader_map.has(p_type))
+ return;
+
+ const StringName *key=NULL;
+
+ while((key=shader_map[p_type].next(key))) {
+
+ p_list->push_back(*key);
+ }
+
}
diff --git a/scene/resources/theme.h b/scene/resources/theme.h
index f0747fb3c4..180f55381d 100644
--- a/scene/resources/theme.h
+++ b/scene/resources/theme.h
@@ -33,6 +33,7 @@
#include "scene/resources/font.h"
#include "scene/resources/style_box.h"
#include "scene/resources/texture.h"
+#include "scene/resources/shader.h"
#include "io/resource_loader.h"
/**
@@ -48,6 +49,7 @@ class Theme : public Resource {
HashMap<StringName,HashMap<StringName,Ref<Texture>,StringNameHasher >, StringNameHasher > icon_map;
HashMap<StringName,HashMap<StringName,Ref<StyleBox>,StringNameHasher >,StringNameHasher > style_map;
HashMap<StringName,HashMap<StringName,Ref<Font>,StringNameHasher >,StringNameHasher > font_map;
+ HashMap<StringName,HashMap<StringName,Ref<Shader>,StringNameHasher >, StringNameHasher > shader_map;
HashMap<StringName,HashMap<StringName,Color,StringNameHasher >,StringNameHasher > color_map;
HashMap<StringName,HashMap<StringName,int,StringNameHasher>,StringNameHasher > constant_map;
protected:
@@ -86,7 +88,13 @@ public:
bool has_icon(const StringName& p_name,const StringName& p_type) const;
void clear_icon(const StringName& p_name,const StringName& p_type);
void get_icon_list(StringName p_type, List<StringName> *p_list) const;
-
+
+ void set_shader(const StringName& p_name,const StringName& p_type,const Ref<Shader>& p_shader);
+ Ref<Shader> get_shader(const StringName& p_name,const StringName& p_type) const;
+ bool has_shader(const StringName& p_name,const StringName& p_type) const;
+ void clear_shader(const StringName& p_name,const StringName& p_type);
+ void get_shader_list(const StringName& p_name, List<StringName> *p_list) const;
+
void set_stylebox(const StringName& p_name,const StringName& p_type,const Ref<StyleBox>& p_style);
Ref<StyleBox> get_stylebox(const StringName& p_name,const StringName& p_type) const;
bool has_stylebox(const StringName& p_name,const StringName& p_type) const;