summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--scene/register_scene_types.cpp23
-rw-r--r--scene/resources/default_theme/default_theme.cpp38
-rw-r--r--scene/resources/default_theme/default_theme.h2
-rw-r--r--tools/editor/io_plugins/editor_font_import_plugin.cpp22
4 files changed, 52 insertions, 33 deletions
diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp
index 54b4ddca9e..b16b4aa56d 100644
--- a/scene/register_scene_types.cpp
+++ b/scene/register_scene_types.cpp
@@ -271,7 +271,28 @@ void register_scene_types() {
resource_loader_shader = memnew( ResourceFormatLoaderShader );
ResourceLoader::add_resource_format_loader( resource_loader_shader );
- make_default_theme();
+ bool default_theme_hidpi=GLOBAL_DEF("display/use_hidpi_theme",false);
+ Globals::get_singleton()->set_custom_property_info("display/use_hidpi_theme",PropertyInfo(Variant::BOOL,"display/use_hidpi_theme",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_DEFAULT|PROPERTY_USAGE_RESTART_IF_CHANGED));
+ String theme_path = GLOBAL_DEF("display/custom_theme","");
+ Globals::get_singleton()->set_custom_property_info("display/custom_theme",PropertyInfo(Variant::STRING,"display/custom_theme",PROPERTY_HINT_FILE,"*.tres,*.res",PROPERTY_USAGE_DEFAULT|PROPERTY_USAGE_RESTART_IF_CHANGED));
+ String font_path = GLOBAL_DEF("display/custom_theme_font","");
+ Globals::get_singleton()->set_custom_property_info("display/custom_theme_font",PropertyInfo(Variant::STRING,"display/custom_theme_font",PROPERTY_HINT_FILE,"*.tres,*.res,*.fnt",PROPERTY_USAGE_DEFAULT|PROPERTY_USAGE_RESTART_IF_CHANGED));
+
+
+ if (theme_path!=String()) {
+ Ref<Theme> theme = ResourceLoader::load(theme_path);
+ if (theme.is_valid()) {
+ Theme::set_default(theme);
+ }
+ } else {
+
+ Ref<Font> font;
+ if (font_path!=String()) {
+ font=ResourceLoader::load(font_path);
+ }
+ make_default_theme(default_theme_hidpi,font);
+ }
+
OS::get_singleton()->yield(); //may take time to init
diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp
index 58b1366e7c..b9c29e583a 100644
--- a/scene/resources/default_theme/default_theme.cpp
+++ b/scene/resources/default_theme/default_theme.cpp
@@ -16,14 +16,8 @@
#include "theme_data.h"
#include "os/os.h"
-
-#include "normal_font.inc"
-#include "bold_font.inc"
-#include "mono_font.inc"
-
-#include "font_normal.inc"
-#include "font_source.inc"
-#include "font_large.inc"
+#include "font_lodpi.inc"
+#include "font_hidpi.inc"
typedef Map<const void*,Ref<ImageTexture> > TexCacheMap;
@@ -124,21 +118,14 @@ static Ref<BitmapFont> make_font(int p_height,int p_ascent, int p_valign, int p_
return font;
}
+
+
static Ref<BitmapFont> make_font2(int p_height,int p_ascent, int p_charcount, const int *p_char_rects,int p_kerning_count,const int *p_kernings,int p_w, int p_h, const unsigned char *p_img) {
Ref<BitmapFont> font( memnew( BitmapFont ) );
- DVector<uint8_t> img;
- img.resize(p_w*p_h*2);
- {
- DVector<uint8_t>::Write w = img.write();
- for(int i=0;i<(p_w*p_h*2);i++) {
- w[i]=p_img[i];
- }
- }
-
- Image image(p_w,p_h,0,Image::FORMAT_GRAYSCALE_ALPHA,img);
+ Image image(p_img);
Ref<ImageTexture> tex = memnew( ImageTexture );
tex->create_from_image(image);
@@ -926,16 +913,23 @@ void fill_default_theme(Ref<Theme>& t,const Ref<Font> & default_font,const Ref<F
}
-void make_default_theme() {
+void make_default_theme(bool p_hidpi,Ref<Font> p_font) {
Ref<Theme> t;
t.instance();
Ref<StyleBox> default_style;
Ref<Texture> default_icon;
- Ref<BitmapFont> default_font=make_font2(_builtin_normal_font_height,_builtin_normal_font_ascent,_builtin_normal_font_charcount,&_builtin_normal_font_charrects[0][0],_builtin_normal_font_kerning_pair_count,&_builtin_normal_font_kerning_pairs[0][0],_builtin_normal_font_img_width,_builtin_normal_font_img_height,_builtin_normal_font_img_data);
- Ref<BitmapFont> large_font=make_font2(_builtin_large_font_height,_builtin_large_font_ascent,_builtin_large_font_charcount,&_builtin_large_font_charrects[0][0],_builtin_large_font_kerning_pair_count,&_builtin_large_font_kerning_pairs[0][0],_builtin_large_font_img_width,_builtin_large_font_img_height,_builtin_large_font_img_data);
- fill_default_theme(t,default_font,large_font,default_icon,default_style,false);
+ Ref<BitmapFont> default_font;
+ if (p_font.is_valid()) {
+ default_font=p_font;
+ } if (p_hidpi) {
+ default_font=make_font2(_hidpi_font_height,_hidpi_font_ascent,_hidpi_font_charcount,&_hidpi_font_charrects[0][0],_hidpi_font_kerning_pair_count,&_hidpi_font_kerning_pairs[0][0],_hidpi_font_img_width,_hidpi_font_img_height,_hidpi_font_img_data);
+ } else {
+ default_font=make_font2(_lodpi_font_height,_lodpi_font_ascent,_lodpi_font_charcount,&_lodpi_font_charrects[0][0],_lodpi_font_kerning_pair_count,&_lodpi_font_kerning_pairs[0][0],_lodpi_font_img_width,_lodpi_font_img_height,_lodpi_font_img_data);
+ }
+ Ref<BitmapFont> large_font=default_font;
+ fill_default_theme(t,default_font,large_font,default_icon,default_style,p_hidpi);
Theme::set_default( t );
Theme::set_default_icon( default_icon );
diff --git a/scene/resources/default_theme/default_theme.h b/scene/resources/default_theme/default_theme.h
index 1e3b4b4081..3d71289162 100644
--- a/scene/resources/default_theme/default_theme.h
+++ b/scene/resources/default_theme/default_theme.h
@@ -18,7 +18,7 @@
*/
void fill_default_theme(Ref<Theme>& theme,const Ref<Font> & default_font,const Ref<Font> & large_font,Ref<Texture>& default_icon, Ref<StyleBox>& default_style,bool p_hidpi);
-void make_default_theme();
+void make_default_theme(bool p_hidpi, Ref<Font> p_font);
void clear_default_theme();
#endif
diff --git a/tools/editor/io_plugins/editor_font_import_plugin.cpp b/tools/editor/io_plugins/editor_font_import_plugin.cpp
index d5e6e3077e..2fbc4af94f 100644
--- a/tools/editor/io_plugins/editor_font_import_plugin.cpp
+++ b/tools/editor/io_plugins/editor_font_import_plugin.cpp
@@ -489,18 +489,22 @@ class EditorFontImportDialog : public ConfirmationDialog {
Image img = tex->get_data();
f->store_line("static const int _builtin_font_img_width="+itos(img.get_width())+";");
- f->store_line("static const int _builtin_font_img_height="+itos(img.get_height())+";");
- f->store_line("static const unsigned char _builtin_font_img_data["+itos(img.get_width()*img.get_height()*2)+"]={");
- for(int i=0;i<img.get_height();i++) {
+ f->store_line("static const int _builtin_font_img_height="+itos(img.get_height())+";");
- for(int j=0;j<img.get_width();j++) {
+ String fname = p_font.basename()+".sv.png";
+ ResourceSaver::save(fname,tex);
+ Vector<uint8_t> data=FileAccess::get_file_as_array(fname);
- Color c = img.get_pixel(j,i);
- int v = CLAMP(((c.r+c.g+c.b)/3.0)*255,0,255);
- int a = CLAMP(c.a*255,0,255);
- f->store_line(itos(v)+","+itos(a)+",");
- }
+ f->store_line("static const int _builtin_font_img_data_size="+itos(data.size())+";");
+ f->store_line("static const unsigned char _builtin_font_img_data["+itos(data.size())+"]={");
+
+
+
+ for(int i=0;i<data.size();i++) {
+
+ f->store_line(itos(data[i])+",");
+
}
f->store_line("};");