2014-05-13 17:10:00 +02:00
|
|
|
Import('env')
|
|
|
|
|
2014-05-14 04:47:17 +02:00
|
|
|
def make_editor_icons_action(target, source, env):
|
2014-05-13 17:10:00 +02:00
|
|
|
|
2014-05-14 04:47:17 +02:00
|
|
|
import os
|
2014-05-22 10:24:46 +02:00
|
|
|
import cStringIO
|
2014-05-14 04:47:17 +02:00
|
|
|
|
|
|
|
dst = target[0].srcnode().abspath
|
|
|
|
pixmaps = source
|
2014-05-22 10:24:46 +02:00
|
|
|
|
|
|
|
s = cStringIO.StringIO()
|
2014-05-13 17:10:00 +02:00
|
|
|
|
2014-05-22 10:24:46 +02:00
|
|
|
s.write("#include \"editor_icons.h\"\n\n")
|
|
|
|
s.write("#include \"scene/resources/theme.h\"\n\n")
|
2014-05-13 17:10:00 +02:00
|
|
|
|
|
|
|
for x in pixmaps:
|
2014-05-14 04:47:17 +02:00
|
|
|
|
|
|
|
x=str(x)
|
|
|
|
var_str=os.path.basename(x)[:-4]+"_png";
|
|
|
|
#print(var_str)
|
2014-05-13 17:10:00 +02:00
|
|
|
|
2014-05-22 10:24:46 +02:00
|
|
|
s.write("static const unsigned char "+ var_str +"[]={\n");
|
2014-05-13 17:10:00 +02:00
|
|
|
|
|
|
|
pngf=open(x,"rb");
|
|
|
|
|
|
|
|
b=pngf.read(1);
|
|
|
|
while(len(b)==1):
|
2014-05-22 10:24:46 +02:00
|
|
|
s.write(hex(ord(b)))
|
2014-05-13 17:10:00 +02:00
|
|
|
b=pngf.read(1);
|
|
|
|
if (len(b)==1):
|
2014-05-22 10:24:46 +02:00
|
|
|
s.write(",")
|
2014-05-13 17:10:00 +02:00
|
|
|
|
2014-05-22 10:24:46 +02:00
|
|
|
s.write("\n};\n\n\n");
|
2014-05-13 17:10:00 +02:00
|
|
|
pngf.close();
|
|
|
|
|
2014-05-22 10:24:46 +02:00
|
|
|
s.write("static Ref<ImageTexture> make_icon(const uint8_t* p_png) {\n")
|
|
|
|
s.write("\tRef<ImageTexture> texture( memnew( ImageTexture ) );\n")
|
|
|
|
s.write("\ttexture->create_from_image( Image(p_png),ImageTexture::FLAG_FILTER );\n")
|
|
|
|
s.write("\treturn texture;\n")
|
|
|
|
s.write("}\n\n")
|
2014-05-13 17:10:00 +02:00
|
|
|
|
2014-05-22 10:24:46 +02:00
|
|
|
s.write("void editor_register_icons(Ref<Theme> p_theme) {\n\n")
|
2014-05-13 17:10:00 +02:00
|
|
|
|
|
|
|
for x in pixmaps:
|
2014-05-14 04:47:17 +02:00
|
|
|
|
|
|
|
x=os.path.basename(str(x))
|
2014-05-13 17:10:00 +02:00
|
|
|
type=x[5:-4].title().replace("_","");
|
|
|
|
var_str=x[:-4]+"_png";
|
2014-05-22 10:24:46 +02:00
|
|
|
s.write("\tp_theme->set_icon(\""+type+"\",\"EditorIcons\",make_icon("+var_str+"));\n");
|
2014-05-13 17:10:00 +02:00
|
|
|
|
2014-05-22 10:24:46 +02:00
|
|
|
s.write("\n\n}\n\n");
|
|
|
|
|
|
|
|
f = open(dst,"wb")
|
|
|
|
f.write(s.getvalue())
|
2014-05-13 17:10:00 +02:00
|
|
|
f.close()
|
2014-05-22 10:24:46 +02:00
|
|
|
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,
|
|
|
|
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')
|
|
|
|
|