godot/editor/icons/SCsub
Matthias Hoelzl fb236045de Make build scripts Scons 3.0/Python3 compatible
- Cherry picked #10662 and fixed merge conflicts.
- Manualy merged the change from #11904.
- Did not merge #12236 since I'm not sure whether the issue
  affects Godot 2.1 and I don't have VS2013 to test.
- Did not merge #11843 since it doesn't seem relevant (the
  code is only needed for creating DONORS.md, etc.).
- Did not merge #10727 and #11752 since they seem to be
  already included in #11742.
- The Windows and Linux builds have been tested with Scons 3.0
  using Python 3.
- OSX and iOS should hopefully work but are not tested since
  I don't have a Mac.
- Builds using SCons 2.5 and Python 2 should not be impacted.
2017-10-24 06:41:32 +02:00

94 lines
2.8 KiB
Python

#!/usr/bin/env python
Import('env')
from compat import StringIO
def make_editor_icons_action(target, source, env):
import os
dst = target[0].srcnode().abspath
pixmaps = source
s = StringIO()
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")
hidpi_list = []
for x in pixmaps:
x = str(x)
var_str = os.path.basename(x)[:-4] + "_png"
# print(var_str)
s.write("static const unsigned char " + var_str + "[]={\n")
pngf = open(x, "rb")
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")
pngf.close()
var_str = os.path.basename(x)[:-4] + "_hidpi_png"
try:
pngf = open(os.path.dirname(x) + "/2x/" + os.path.basename(x), "rb")
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")
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")
s.write("void editor_register_icons(Ref<Theme> p_theme) {\n\n")
for x in pixmaps:
x = os.path.basename(str(x))
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")
s.write("\n\n}\n\n")
f = open(dst, "w")
f.write(s.getvalue())
f.close()
s.close()
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('#editor/editor_icons.gen.cpp', Glob("*.png"))])
env.editor_sources.append("#editor/editor_icons.gen.cpp")
Export('env')