Jelajahi Sumber

Merge pull request #415 from marynate/PR-auto-editor-icons-cpp

Auto generate editor_icons.cpp to make it easy to update editor icons
reduz 11 tahun lalu
induk
melakukan
fb5223a69d
4 mengubah file dengan 64 tambahan dan 6 penghapusan
  1. 1 0
      .gitignore
  2. 3 1
      tools/editor/SCsub
  3. 0 5
      tools/editor/editor_icons.cpp
  4. 60 0
      tools/editor/icons/SCsub

+ 1 - 0
.gitignore

@@ -15,6 +15,7 @@ core/method_bind.inc
 core/global_defaults.cpp
 core/global_defaults.cpp
 tools/editor/register_exporters.cpp
 tools/editor/register_exporters.cpp
 tools/editor/doc_data_compressed.h
 tools/editor/doc_data_compressed.h
+tools/editor/editor_icons.cpp
 -fpic
 -fpic
 
 
 # Android specific
 # Android specific

+ 3 - 1
tools/editor/SCsub

@@ -48,9 +48,11 @@ if (env["tools"]=="yes"):
 	env.Command("#tools/editor/doc_data_compressed.h","#doc/base/classes.xml",make_doc_header)
 	env.Command("#tools/editor/doc_data_compressed.h","#doc/base/classes.xml",make_doc_header)
 
 
 	#make_doc_header(env.File("#tools/editor/doc_data_raw.h").srcnode().abspath,env.File("#doc/base/classes.xml").srcnode().abspath,env)
 	#make_doc_header(env.File("#tools/editor/doc_data_raw.h").srcnode().abspath,env.File("#doc/base/classes.xml").srcnode().abspath,env)
+	
 	env.add_source_files(env.tool_sources,"*.cpp")
 	env.add_source_files(env.tool_sources,"*.cpp")
-
+	
 	Export('env')
 	Export('env')
+	SConscript('icons/SCsub');	
 	SConscript('plugins/SCsub');
 	SConscript('plugins/SCsub');
 	SConscript('fileserver/SCsub');
 	SConscript('fileserver/SCsub');
 	SConscript('io_plugins/SCsub');
 	SConscript('io_plugins/SCsub');

File diff ditekan karena terlalu besar
+ 0 - 5
tools/editor/editor_icons.cpp


+ 60 - 0
tools/editor/icons/SCsub

@@ -0,0 +1,60 @@
+Import('env')
+
+def make_editor_icons_action(target, source, env):
+
+	import os
+
+	dst = target[0].srcnode().abspath
+	pixmaps = source
+	
+	f = open(dst,"wb")
+	f.write("#include \"editor_icons.h\"\n\n")
+	f.write("#include \"scene/resources/theme.h\"\n\n")
+
+	for x in pixmaps:
+	
+		x=str(x)
+		var_str=os.path.basename(x)[:-4]+"_png";
+		#print(var_str)
+		
+		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:
+	
+		x=os.path.basename(str(x))
+		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_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')
+

Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini