2016-10-17 08:50:25 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2014-05-13 17:10:00 +02:00
|
|
|
Import('env')
|
|
|
|
|
2016-11-02 22:29:36 +01:00
|
|
|
|
2014-05-14 04:47:17 +02:00
|
|
|
def make_editor_icons_action(target, source, env):
|
2014-05-13 17:10:00 +02:00
|
|
|
|
2016-11-02 22:26:55 +01:00
|
|
|
import os
|
|
|
|
import cStringIO
|
2014-05-14 04:47:17 +02:00
|
|
|
|
2016-11-02 22:26:55 +01:00
|
|
|
dst = target[0].srcnode().abspath
|
|
|
|
pixmaps = source
|
2014-05-22 10:24:46 +02:00
|
|
|
|
2016-11-02 22:26:55 +01:00
|
|
|
s = cStringIO.StringIO()
|
2015-11-01 20:53:26 +01:00
|
|
|
|
2016-11-02 22:26:55 +01:00
|
|
|
s.write("#include \"editor_icons.h\"\n\n")
|
|
|
|
s.write("#include \"editor_scale.h\"\n\n")
|
|
|
|
s.write("#include \"scene/resources/theme.h\"\n\n")
|
2014-05-13 17:10:00 +02:00
|
|
|
|
2016-11-02 22:28:28 +01:00
|
|
|
hidpi_list = []
|
2016-06-08 22:48:31 +02:00
|
|
|
|
2016-11-02 22:26:55 +01:00
|
|
|
for x in pixmaps:
|
2015-11-01 20:53:26 +01:00
|
|
|
|
2016-11-02 22:28:28 +01:00
|
|
|
x = str(x)
|
|
|
|
var_str = os.path.basename(x)[:-4] + "_png";
|
|
|
|
# print(var_str)
|
2015-11-01 20:53:26 +01:00
|
|
|
|
2016-11-02 22:28:28 +01:00
|
|
|
s.write("static const unsigned char " + var_str + "[]={\n");
|
2015-11-01 20:53:26 +01:00
|
|
|
|
2016-11-02 22:28:28 +01:00
|
|
|
pngf = open(x, "rb");
|
2015-11-01 20:53:26 +01:00
|
|
|
|
2016-11-02 22:28:28 +01:00
|
|
|
b = pngf.read(1);
|
|
|
|
while(len(b) == 1):
|
2016-11-02 22:26:55 +01:00
|
|
|
s.write(hex(ord(b)))
|
2016-11-02 22:28:28 +01:00
|
|
|
b = pngf.read(1);
|
|
|
|
if (len(b) == 1):
|
2016-11-02 22:26:55 +01:00
|
|
|
s.write(",")
|
2015-11-01 20:53:26 +01:00
|
|
|
|
2016-11-02 22:26:55 +01:00
|
|
|
s.write("\n};\n\n");
|
2016-06-08 22:48:31 +02:00
|
|
|
|
2016-11-02 22:26:55 +01:00
|
|
|
pngf.close();
|
2016-11-02 22:28:28 +01:00
|
|
|
var_str = os.path.basename(x)[:-4] + "_hidpi_png";
|
2016-11-02 22:26:55 +01:00
|
|
|
try:
|
2016-06-08 22:48:31 +02:00
|
|
|
|
2016-11-02 22:28:28 +01:00
|
|
|
pngf = open(os.path.dirname(x) + "/2x/" + os.path.basename(x), "rb")
|
2016-06-08 22:48:31 +02:00
|
|
|
|
2016-11-02 22:28:28 +01:00
|
|
|
s.write("static const unsigned char " + var_str + "[]={\n");
|
2016-06-08 22:48:31 +02:00
|
|
|
|
2016-11-02 22:28:28 +01:00
|
|
|
b = pngf.read(1);
|
|
|
|
while(len(b) == 1):
|
2016-11-02 22:26:55 +01:00
|
|
|
s.write(hex(ord(b)))
|
2016-11-02 22:28:28 +01:00
|
|
|
b = pngf.read(1);
|
|
|
|
if (len(b) == 1):
|
2016-11-02 22:26:55 +01:00
|
|
|
s.write(",")
|
2016-06-08 22:48:31 +02:00
|
|
|
|
2016-11-02 22:26:55 +01:00
|
|
|
s.write("\n};\n\n\n");
|
|
|
|
hidpi_list.append(x)
|
2016-06-08 22:48:31 +02:00
|
|
|
|
2016-11-02 22:26:55 +01:00
|
|
|
except:
|
2016-11-02 22:28:28 +01:00
|
|
|
s.write("static const unsigned char* " + var_str + "=NULL;\n\n\n");
|
2016-06-08 22:48:31 +02:00
|
|
|
|
2016-11-02 22:26:55 +01:00
|
|
|
s.write("static Ref<ImageTexture> make_icon(const uint8_t* p_png,const uint8_t* p_hidpi_png) {\n")
|
|
|
|
s.write("\tRef<ImageTexture> texture( memnew( ImageTexture ) );\n")
|
|
|
|
s.write("\tImage img((editor_is_hidpi()&&p_hidpi_png)?p_hidpi_png:p_png);\n")
|
|
|
|
s.write("\tif (editor_is_hidpi() && !p_hidpi_png) { img.convert(Image::FORMAT_RGBA); img.expand_x2_hq2x(); }\n")
|
|
|
|
s.write("\ttexture->create_from_image( img,ImageTexture::FLAG_FILTER );\n")
|
|
|
|
s.write("\treturn texture;\n")
|
|
|
|
s.write("}\n\n")
|
2014-05-13 17:10:00 +02:00
|
|
|
|
2016-11-02 22:26:55 +01:00
|
|
|
s.write("void editor_register_icons(Ref<Theme> p_theme) {\n\n")
|
2014-05-13 17:10:00 +02:00
|
|
|
|
2016-11-02 22:26:55 +01:00
|
|
|
for x in pixmaps:
|
2015-11-01 20:53:26 +01:00
|
|
|
|
2016-11-02 22:28:28 +01:00
|
|
|
x = os.path.basename(str(x))
|
|
|
|
type = x[5:-4].title().replace("_", "");
|
|
|
|
var_str = x[:-4] + "_png";
|
|
|
|
var_str_hidpi = x[:-4] + "_hidpi_png";
|
|
|
|
s.write("\tp_theme->set_icon(\"" + type + "\",\"EditorIcons\",make_icon(" + var_str + "," + var_str_hidpi + "));\n");
|
2014-05-13 17:10:00 +02:00
|
|
|
|
2016-11-02 22:26:55 +01:00
|
|
|
s.write("\n\n}\n\n");
|
2015-11-01 20:53:26 +01:00
|
|
|
|
2016-11-02 22:28:28 +01:00
|
|
|
f = open(dst, "wb")
|
2016-11-02 22:26:55 +01:00
|
|
|
f.write(s.getvalue())
|
|
|
|
f.close()
|
|
|
|
s.close()
|
2014-05-13 17:10:00 +02:00
|
|
|
|
2014-05-14 04:47:17 +02:00
|
|
|
make_editor_icons_builder = Builder(action=make_editor_icons_action,
|
2016-11-02 22:28:28 +01:00
|
|
|
suffix='.cpp',
|
|
|
|
src_suffix='.png')
|
|
|
|
env['BUILDERS']['MakeEditorIconsBuilder'] = make_editor_icons_builder
|
|
|
|
env.Alias('editor_icons', [env.MakeEditorIconsBuilder('#tools/editor/editor_icons.cpp', Glob("*.png"))])
|
2014-05-14 04:47:17 +02:00
|
|
|
|
|
|
|
env.tool_sources.append("#tools/editor/editor_icons.cpp")
|
|
|
|
Export('env')
|