diff options
author | Juan Linietsky <reduzio@gmail.com> | 2016-06-16 20:04:33 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2016-06-16 20:05:22 -0300 |
commit | 816b3fa94de91fb671b58d7cda57f10104a682da (patch) | |
tree | 49482dc65c688694dc05410aa104960e9d875f76 /scene/resources | |
parent | c4c6797fc1d700f59ea8d4927d42c1838bcfb3b9 (diff) |
It is now possible to set a default custom theme, whether you want a hidpi default theme, or just use a custom font for the default theme
Diffstat (limited to 'scene/resources')
-rw-r--r-- | scene/resources/default_theme/default_theme.cpp | 38 | ||||
-rw-r--r-- | scene/resources/default_theme/default_theme.h | 2 |
2 files changed, 17 insertions, 23 deletions
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 |