2016-10-17 08:50:25 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2014-05-13 17:10:00 +02:00
|
|
|
Import('env')
|
|
|
|
|
2016-10-30 19:05:14 +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-10-30 18:44:57 +01:00
|
|
|
import os
|
|
|
|
import cStringIO
|
2014-05-14 04:47:17 +02:00
|
|
|
|
2016-10-30 18:44:57 +01:00
|
|
|
dst = target[0].srcnode().abspath
|
|
|
|
pixmaps = source
|
2014-05-22 10:24:46 +02:00
|
|
|
|
2016-10-30 18:44:57 +01:00
|
|
|
s = cStringIO.StringIO()
|
2015-11-01 20:53:26 +01:00
|
|
|
|
2016-10-30 18:44:57 +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-10-30 18:57:40 +01:00
|
|
|
hidpi_list = []
|
2016-06-08 22:48:31 +02:00
|
|
|
|
2016-10-30 18:44:57 +01:00
|
|
|
for x in pixmaps:
|
2015-11-01 20:53:26 +01:00
|
|
|
|
2016-10-30 18:57:40 +01:00
|
|
|
x = str(x)
|
2016-11-01 00:24:30 +01:00
|
|
|
var_str = os.path.basename(x)[:-4] + "_png"
|
2016-10-30 18:57:40 +01:00
|
|
|
# print(var_str)
|
2015-11-01 20:53:26 +01:00
|
|
|
|
2016-11-01 00:24:30 +01:00
|
|
|
s.write("static const unsigned char " + var_str + "[]={\n")
|
2015-11-01 20:53:26 +01:00
|
|
|
|
2016-11-01 00:24:30 +01:00
|
|
|
pngf = open(x, "rb")
|
2015-11-01 20:53:26 +01:00
|
|
|
|
2016-11-01 00:24:30 +01:00
|
|
|
b = pngf.read(1)
|
2016-10-30 18:57:40 +01:00
|
|
|
while(len(b) == 1):
|
2016-10-30 18:44:57 +01:00
|
|
|
s.write(hex(ord(b)))
|
2016-11-01 00:24:30 +01:00
|
|
|
b = pngf.read(1)
|
2016-10-30 18:57:40 +01:00
|
|
|
if (len(b) == 1):
|
2016-10-30 18:44:57 +01:00
|
|
|
s.write(",")
|
2015-11-01 20:53:26 +01:00
|
|
|
|
2016-11-01 00:24:30 +01:00
|
|
|
s.write("\n};\n\n")
|
2016-06-08 22:48:31 +02:00
|
|
|
|
2016-11-01 00:24:30 +01:00
|
|
|
pngf.close()
|
|
|
|
var_str = os.path.basename(x)[:-4] + "_hidpi_png"
|
2016-10-30 18:44:57 +01:00
|
|
|
try:
|
2016-06-08 22:48:31 +02:00
|
|
|
|
2016-10-30 18:57:40 +01:00
|
|
|
pngf = open(os.path.dirname(x) + "/2x/" + os.path.basename(x), "rb")
|
2016-06-08 22:48:31 +02:00
|
|
|
|
2016-11-01 00:24:30 +01:00
|
|
|
s.write("static const unsigned char " + var_str + "[]={\n")
|
2016-06-08 22:48:31 +02:00
|
|
|
|
2016-11-01 00:24:30 +01:00
|
|
|
b = pngf.read(1)
|
2016-10-30 18:57:40 +01:00
|
|
|
while(len(b) == 1):
|
2016-10-30 18:44:57 +01:00
|
|
|
s.write(hex(ord(b)))
|
2016-11-01 00:24:30 +01:00
|
|
|
b = pngf.read(1)
|
2016-10-30 18:57:40 +01:00
|
|
|
if (len(b) == 1):
|
2016-10-30 18:44:57 +01:00
|
|
|
s.write(",")
|
2016-06-08 22:48:31 +02:00
|
|
|
|
2016-11-01 00:24:30 +01:00
|
|
|
s.write("\n};\n\n\n")
|
2016-10-30 18:44:57 +01:00
|
|
|
hidpi_list.append(x)
|
2016-06-08 22:48:31 +02:00
|
|
|
|
2016-10-30 18:44:57 +01:00
|
|
|
except:
|
2016-11-01 00:24:30 +01:00
|
|
|
s.write("static const unsigned char* " + var_str + "=NULL;\n\n\n")
|
2016-06-08 22:48:31 +02:00
|
|
|
|
2016-10-30 18:44:57 +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("\tbool use_hidpi_image=(editor_get_scale()>1.0&&p_hidpi_png);\n")
|
|
|
|
s.write("\tImage img(use_hidpi_image?p_hidpi_png:p_png);\n")
|
2017-01-02 21:38:20 +01:00
|
|
|
s.write("\tif (editor_get_scale()>1.0 && !p_hidpi_png) { img.convert(Image::FORMAT_RGBA8); img.expand_x2_hq2x(); use_hidpi_image=true;}\n")
|
2016-10-30 18:44:57 +01:00
|
|
|
s.write("\timg.resize(img.get_width()*EDSCALE/(use_hidpi_image?2:1),img.get_height()*EDSCALE/(use_hidpi_image?2:1));\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-10-30 18:44:57 +01:00
|
|
|
s.write("void editor_register_icons(Ref<Theme> p_theme) {\n\n")
|
2014-05-13 17:10:00 +02:00
|
|
|
|
2016-10-30 18:44:57 +01:00
|
|
|
for x in pixmaps:
|
2015-11-01 20:53:26 +01:00
|
|
|
|
2016-10-30 18:57:40 +01:00
|
|
|
x = os.path.basename(str(x))
|
2016-11-01 00:24:30 +01:00
|
|
|
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-01 00:24:30 +01:00
|
|
|
s.write("\n\n}\n\n")
|
2015-11-01 20:53:26 +01:00
|
|
|
|
2016-10-30 18:57:40 +01:00
|
|
|
f = open(dst, "wb")
|
2016-10-30 18:44:57 +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-10-30 18:57:40 +01:00
|
|
|
suffix='.cpp',
|
|
|
|
src_suffix='.png')
|
|
|
|
env['BUILDERS']['MakeEditorIconsBuilder'] = make_editor_icons_builder
|
2017-03-05 14:21:25 +01:00
|
|
|
env.Alias('editor_icons', [env.MakeEditorIconsBuilder('#editor/editor_icons.cpp', Glob("*.png"))])
|
2014-05-14 04:47:17 +02:00
|
|
|
|
2017-03-05 14:21:25 +01:00
|
|
|
env.editor_sources.append("#editor/editor_icons.cpp")
|
2014-05-14 04:47:17 +02:00
|
|
|
Export('env')
|