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