2016-10-17 06:50:25 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2014-05-13 15:10:00 +00:00
|
|
|
Import('env')
|
2017-08-26 16:53:49 +00:00
|
|
|
from compat import StringIO
|
2016-10-30 18:05:14 +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-10-30 17:44:57 +00:00
|
|
|
import os
|
2014-05-14 02:47:17 +00:00
|
|
|
|
2016-10-30 17:44:57 +00:00
|
|
|
dst = target[0].srcnode().abspath
|
2017-08-19 02:34:09 +00:00
|
|
|
svg_icons = source
|
2014-05-22 08:24:46 +00:00
|
|
|
|
2017-08-30 18:29:35 +00:00
|
|
|
icons_string = StringIO()
|
2015-11-01 19:53:26 +00:00
|
|
|
|
2017-08-19 02:34:09 +00:00
|
|
|
for f in svg_icons:
|
2015-11-01 19:53:26 +00:00
|
|
|
|
2017-08-19 02:34:09 +00:00
|
|
|
fname = str(f)
|
2015-11-01 19:53:26 +00:00
|
|
|
|
2017-08-30 18:29:35 +00:00
|
|
|
icons_string.write('\t"')
|
2015-11-01 19:53:26 +00:00
|
|
|
|
2017-08-19 02:34:09 +00:00
|
|
|
with open(fname, 'rb') as svgf:
|
|
|
|
b = svgf.read(1)
|
2016-10-30 17:57:40 +00:00
|
|
|
while(len(b) == 1):
|
2017-08-30 18:29:35 +00:00
|
|
|
icons_string.write("\\" + str(hex(ord(b)))[1:])
|
2017-08-19 02:34:09 +00:00
|
|
|
b = svgf.read(1)
|
|
|
|
|
|
|
|
|
2017-08-30 18:29:35 +00:00
|
|
|
icons_string.write('"')
|
2017-08-19 02:34:09 +00:00
|
|
|
if fname != svg_icons[-1]:
|
2017-08-30 18:29:35 +00:00
|
|
|
icons_string.write(",")
|
|
|
|
icons_string.write('\n')
|
2016-06-08 20:48:31 +00:00
|
|
|
|
2017-08-26 16:53:49 +00:00
|
|
|
s = StringIO()
|
2017-08-19 02:34:09 +00:00
|
|
|
s.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
|
|
|
|
s.write("#ifndef _EDITOR_ICONS_H\n")
|
|
|
|
s.write("#define _EDITOR_ICONS_H\n")
|
2018-02-14 16:29:25 +00:00
|
|
|
s.write("static const int editor_icons_count = {};\n".format(len(svg_icons)))
|
2017-08-19 02:34:09 +00:00
|
|
|
s.write("static const char *editor_icons_sources[] = {\n")
|
2017-08-30 18:29:35 +00:00
|
|
|
s.write(icons_string.getvalue())
|
2017-08-19 02:34:09 +00:00
|
|
|
s.write('};\n\n')
|
|
|
|
s.write("static const char *editor_icons_names[] = {\n")
|
2017-09-08 07:32:43 +00:00
|
|
|
|
|
|
|
# this is used to store the indices of thumbnail icons
|
|
|
|
thumb_medium_indices = [];
|
|
|
|
thumb_big_indices = [];
|
|
|
|
index = 0
|
2017-08-19 02:34:09 +00:00
|
|
|
for f in svg_icons:
|
2016-06-08 20:48:31 +00:00
|
|
|
|
2017-08-19 02:34:09 +00:00
|
|
|
fname = str(f)
|
2014-05-13 15:10:00 +00:00
|
|
|
|
2017-08-19 02:34:09 +00:00
|
|
|
icon_name = os.path.basename(fname)[5:-4].title().replace("_", "")
|
2017-12-17 20:04:59 +00:00
|
|
|
# some special cases
|
|
|
|
if icon_name in ['Int', 'Bool', 'Float']:
|
|
|
|
icon_name = icon_name.lower()
|
2018-01-18 20:37:17 +00:00
|
|
|
if icon_name.endswith("MediumThumb"): # don't know a better way to handle this
|
2017-09-08 07:32:43 +00:00
|
|
|
thumb_medium_indices.append(str(index))
|
2018-01-18 20:37:17 +00:00
|
|
|
if icon_name.endswith("BigThumb"): # don't know a better way to handle this
|
2017-09-08 07:32:43 +00:00
|
|
|
thumb_big_indices.append(str(index))
|
2014-05-13 15:10:00 +00:00
|
|
|
|
2018-02-14 16:29:25 +00:00
|
|
|
s.write('\t"{0}"'.format(icon_name))
|
2015-11-01 19:53:26 +00:00
|
|
|
|
2017-08-19 02:34:09 +00:00
|
|
|
if fname != svg_icons[-1]:
|
|
|
|
s.write(",")
|
|
|
|
s.write('\n')
|
2017-09-08 07:32:43 +00:00
|
|
|
|
|
|
|
index += 1
|
|
|
|
|
2017-08-19 02:34:09 +00:00
|
|
|
s.write('};\n')
|
2017-09-08 07:32:43 +00:00
|
|
|
|
|
|
|
if thumb_medium_indices:
|
|
|
|
s.write("\n\n")
|
2018-02-14 16:29:25 +00:00
|
|
|
s.write("static const int editor_md_thumbs_count = {};\n".format(len(thumb_medium_indices)))
|
2017-09-08 07:32:43 +00:00
|
|
|
s.write("static const int editor_md_thumbs_indices[] = {")
|
|
|
|
s.write(", ".join(thumb_medium_indices))
|
|
|
|
s.write("};\n")
|
|
|
|
if thumb_big_indices:
|
|
|
|
s.write("\n\n")
|
2018-02-14 16:29:25 +00:00
|
|
|
s.write("static const int editor_bg_thumbs_count = {};\n".format(len(thumb_big_indices)))
|
2017-09-08 07:32:43 +00:00
|
|
|
s.write("static const int editor_bg_thumbs_indices[] = {")
|
|
|
|
s.write(", ".join(thumb_big_indices))
|
|
|
|
s.write("};\n")
|
|
|
|
|
2017-08-19 02:34:09 +00:00
|
|
|
s.write("#endif\n")
|
2014-05-13 15:10:00 +00:00
|
|
|
|
2015-11-01 19:53:26 +00:00
|
|
|
|
2017-08-26 16:53:49 +00:00
|
|
|
f = open(dst, "w")
|
2016-10-30 17:44:57 +00:00
|
|
|
f.write(s.getvalue())
|
|
|
|
f.close()
|
|
|
|
s.close()
|
2017-08-30 18:29:35 +00:00
|
|
|
icons_string.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,
|
2017-08-19 02:34:09 +00:00
|
|
|
suffix='.h',
|
|
|
|
src_suffix='.svg')
|
2016-10-30 17:57:40 +00:00
|
|
|
env['BUILDERS']['MakeEditorIconsBuilder'] = make_editor_icons_builder
|
2017-08-19 02:34:09 +00:00
|
|
|
env.Alias('editor_icons', [env.MakeEditorIconsBuilder('#editor/editor_icons.gen.h', Glob("*.svg"))])
|
2014-05-14 02:47:17 +00:00
|
|
|
|
|
|
|
Export('env')
|