2016-10-17 06:50:25 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2014-05-13 15:10:00 +00:00
|
|
|
Import('env')
|
|
|
|
|
2016-11-02 21:29:36 +00:00
|
|
|
|
2014-05-14 02:47:17 +00:00
|
|
|
def make_editor_icons_action(target, source, env):
|
2014-05-13 15:10:00 +00:00
|
|
|
|
2016-11-02 21:26:55 +00:00
|
|
|
import os
|
|
|
|
import cStringIO
|
2014-05-14 02:47:17 +00:00
|
|
|
|
2016-11-02 21:26:55 +00:00
|
|
|
dst = target[0].srcnode().abspath
|
|
|
|
pixmaps = source
|
2014-05-22 08:24:46 +00:00
|
|
|
|
2016-11-02 21:26:55 +00:00
|
|
|
s = cStringIO.StringIO()
|
2015-11-01 19:53:26 +00:00
|
|
|
|
2016-11-02 21:26:55 +00: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 15:10:00 +00:00
|
|
|
|
2016-11-02 21:28:28 +00:00
|
|
|
hidpi_list = []
|
2016-06-08 20:48:31 +00:00
|
|
|
|
2016-11-02 21:26:55 +00:00
|
|
|
for x in pixmaps:
|
2015-11-01 19:53:26 +00:00
|
|
|
|
2016-11-02 21:28:28 +00:00
|
|
|
x = str(x)
|
2016-11-02 21:30:34 +00:00
|
|
|
var_str = os.path.basename(x)[:-4] + "_png"
|
2016-11-02 21:28:28 +00:00
|
|
|
# print(var_str)
|
2015-11-01 19:53:26 +00:00
|
|
|
|
2016-11-02 21:30:34 +00:00
|
|
|
s.write("static const unsigned char " + var_str + "[]={\n")
|
2015-11-01 19:53:26 +00:00
|
|
|
|
2016-11-02 21:30:34 +00:00
|
|
|
pngf = open(x, "rb")
|
2015-11-01 19:53:26 +00:00
|
|
|
|
2016-11-02 21:30:34 +00:00
|
|
|
b = pngf.read(1)
|
2016-11-02 21:28:28 +00:00
|
|
|
while(len(b) == 1):
|
2016-11-02 21:26:55 +00:00
|
|
|
s.write(hex(ord(b)))
|
2016-11-02 21:30:34 +00:00
|
|
|
b = pngf.read(1)
|
2016-11-02 21:28:28 +00:00
|
|
|
if (len(b) == 1):
|
2016-11-02 21:26:55 +00:00
|
|
|
s.write(",")
|
2015-11-01 19:53:26 +00:00
|
|
|
|
2016-11-02 21:30:34 +00:00
|
|
|
s.write("\n};\n\n")
|
2016-06-08 20:48:31 +00:00
|
|
|
|
2016-11-02 21:30:34 +00:00
|
|
|
pngf.close()
|
|
|
|
var_str = os.path.basename(x)[:-4] + "_hidpi_png"
|
2016-11-02 21:26:55 +00:00
|
|
|
try:
|
2016-06-08 20:48:31 +00:00
|
|
|
|
2016-11-02 21:28:28 +00:00
|
|
|
pngf = open(os.path.dirname(x) + "/2x/" + os.path.basename(x), "rb")
|
2016-06-08 20:48:31 +00:00
|
|
|
|
2016-11-02 21:30:34 +00:00
|
|
|
s.write("static const unsigned char " + var_str + "[]={\n")
|
2016-06-08 20:48:31 +00:00
|
|
|
|
2016-11-02 21:30:34 +00:00
|
|
|
b = pngf.read(1)
|
2016-11-02 21:28:28 +00:00
|
|
|
while(len(b) == 1):
|
2016-11-02 21:26:55 +00:00
|
|
|
s.write(hex(ord(b)))
|
2016-11-02 21:30:34 +00:00
|
|
|
b = pngf.read(1)
|
2016-11-02 21:28:28 +00:00
|
|
|
if (len(b) == 1):
|
2016-11-02 21:26:55 +00:00
|
|
|
s.write(",")
|
2016-06-08 20:48:31 +00:00
|
|
|
|
2016-11-02 21:30:34 +00:00
|
|
|
s.write("\n};\n\n\n")
|
2016-11-02 21:26:55 +00:00
|
|
|
hidpi_list.append(x)
|
2016-06-08 20:48:31 +00:00
|
|
|
|
2016-11-02 21:26:55 +00:00
|
|
|
except:
|
2016-11-02 21:30:34 +00:00
|
|
|
s.write("static const unsigned char* " + var_str + "=NULL;\n\n\n")
|
2016-06-08 20:48:31 +00:00
|
|
|
|
2016-11-02 21:26:55 +00: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 15:10:00 +00:00
|
|
|
|
2016-11-02 21:26:55 +00:00
|
|
|
s.write("void editor_register_icons(Ref<Theme> p_theme) {\n\n")
|
2014-05-13 15:10:00 +00:00
|
|
|
|
2016-11-02 21:26:55 +00:00
|
|
|
for x in pixmaps:
|
2015-11-01 19:53:26 +00:00
|
|
|
|
2016-11-02 21:28:28 +00:00
|
|
|
x = os.path.basename(str(x))
|
2016-11-02 21:30:34 +00: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 15:10:00 +00:00
|
|
|
|
2016-11-02 21:30:34 +00:00
|
|
|
s.write("\n\n}\n\n")
|
2015-11-01 19:53:26 +00:00
|
|
|
|
2016-11-02 21:28:28 +00:00
|
|
|
f = open(dst, "wb")
|
2016-11-02 21:26:55 +00:00
|
|
|
f.write(s.getvalue())
|
|
|
|
f.close()
|
|
|
|
s.close()
|
2014-05-13 15:10:00 +00:00
|
|
|
|
2014-05-14 02:47:17 +00:00
|
|
|
make_editor_icons_builder = Builder(action=make_editor_icons_action,
|
2016-11-02 21:28:28 +00: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 02:47:17 +00:00
|
|
|
|
|
|
|
env.tool_sources.append("#tools/editor/editor_icons.cpp")
|
|
|
|
Export('env')
|