diff options
author | marynate <mary.w.nate@gmail.com> | 2014-05-13 23:10:00 +0800 |
---|---|---|
committer | marynate <mary.w.nate@gmail.com> | 2014-05-13 23:13:08 +0800 |
commit | f5421cdaf342ba15840a4041b4a9d9efb44fa4f0 (patch) | |
tree | 0fd037bf0de90dccb13814f31353f21d9939540a /tools/editor/icons | |
parent | 45a509282e912d85c46b40974a2deb926be5be42 (diff) |
Auto generate editor_icons.cpp to make it more easy to update editor icons
Diffstat (limited to 'tools/editor/icons')
-rw-r--r-- | tools/editor/icons/SCsub | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tools/editor/icons/SCsub b/tools/editor/icons/SCsub new file mode 100644 index 0000000000..edc4cc56ff --- /dev/null +++ b/tools/editor/icons/SCsub @@ -0,0 +1,48 @@ +Import('env') + +def make_editor_icons(): + + import glob + + pixmaps = glob.glob("*.png") + + f = open("../editor_icons.cpp","wb") + f.write("#include \"editor_icons.h\"\n\n") + f.write("#include \"scene/resources/theme.h\"\n\n") + + for x in pixmaps: + + var_str=x[:-4]+"_png"; + + f.write("static const unsigned char "+ var_str +"[]={\n"); + + pngf=open(x,"rb"); + + b=pngf.read(1); + while(len(b)==1): + f.write(hex(ord(b))) + b=pngf.read(1); + if (len(b)==1): + f.write(",") + + f.write("\n};\n\n\n"); + pngf.close(); + + f.write("static Ref<ImageTexture> make_icon(const uint8_t* p_png) {\n") + f.write("\tRef<ImageTexture> texture( memnew( ImageTexture ) );\n") + f.write("\ttexture->create_from_image( Image(p_png),ImageTexture::FLAG_FILTER );\n") + f.write("\treturn texture;\n") + f.write("}\n\n") + + f.write("void editor_register_icons(Ref<Theme> p_theme) {\n\n") + + for x in pixmaps: + + type=x[5:-4].title().replace("_",""); + var_str=x[:-4]+"_png"; + f.write("\tp_theme->set_icon(\""+type+"\",\"EditorIcons\",make_icon("+var_str+"));\n"); + + f.write("\n\n}\n\n"); + f.close() + +make_editor_icons() |