diff options
Diffstat (limited to 'scene/resources')
-rw-r--r-- | scene/resources/default_theme/default_theme.cpp | 31 | ||||
-rw-r--r-- | scene/resources/default_theme/default_theme.h | 2 |
2 files changed, 25 insertions, 8 deletions
diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index 03f28bef08..dea612735c 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -40,7 +40,7 @@ typedef Map<const void*,Ref<ImageTexture> > TexCacheMap; static TexCacheMap *tex_cache; -static int scale=1; +static float scale=1; template<class T> static Ref<StyleBoxTexture> make_stylebox(T p_src,float p_left, float p_top, float p_right, float p_botton,float p_margin_left=-1, float p_margin_top=-1, float p_margin_right=-1, float p_margin_botton=-1, bool p_draw_center=true) { @@ -54,10 +54,21 @@ static Ref<StyleBoxTexture> make_stylebox(T p_src,float p_left, float p_top, flo texture = Ref<ImageTexture>( memnew( ImageTexture ) ); Image img(p_src); + if (scale>1) { + Size2 orig_size = Size2(img.get_width(),img.get_height()); + img.convert(Image::FORMAT_RGBA); img.expand_x2_hq2x(); + if (scale!=2.0) { + img.resize(orig_size.x*scale,orig_size.y*scale); + } + } else if (scale<1) { + Size2 orig_size = Size2(img.get_width(),img.get_height()); + img.convert(Image::FORMAT_RGBA); + img.resize(orig_size.x*scale,orig_size.y*scale); } + texture->create_from_image( img,ImageTexture::FLAG_FILTER ); (*tex_cache)[p_src]=texture; } @@ -95,8 +106,17 @@ static Ref<Texture> make_icon(T p_src) { Ref<ImageTexture> texture( memnew( ImageTexture ) ); Image img = Image(p_src); if (scale>1) { + Size2 orig_size = Size2(img.get_width(),img.get_height()); + img.convert(Image::FORMAT_RGBA); img.expand_x2_hq2x(); + if (scale!=2.0) { + img.resize(orig_size.x*scale,orig_size.y*scale); + } + } else if (scale<1) { + Size2 orig_size = Size2(img.get_width(),img.get_height()); + img.convert(Image::FORMAT_RGBA); + img.resize(orig_size.x*scale,orig_size.y*scale); } texture->create_from_image( img,ImageTexture::FLAG_FILTER ); @@ -194,12 +214,9 @@ static Ref<StyleBox> make_empty_stylebox(float p_margin_left=-1, float p_margin_ return style; } -void fill_default_theme(Ref<Theme>& t,const Ref<Font> & default_font,const Ref<Font> & large_font,Ref<Texture>& default_icon, Ref<StyleBox>& default_style,bool p_hidpi) { +void fill_default_theme(Ref<Theme>& t, const Ref<Font> & default_font, const Ref<Font> & large_font, Ref<Texture>& default_icon, Ref<StyleBox>& default_style, float p_scale) { - if (p_hidpi) - scale=2; - else - scale=1; + scale=p_scale; tex_cache = memnew( TexCacheMap ); @@ -969,7 +986,7 @@ void make_default_theme(bool p_hidpi,Ref<Font> p_font) { 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); + fill_default_theme(t,default_font,large_font,default_icon,default_style,p_hidpi?2.0:1.0); 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 a2a45ac004..3312b2d812 100644 --- a/scene/resources/default_theme/default_theme.h +++ b/scene/resources/default_theme/default_theme.h @@ -35,7 +35,7 @@ @author Juan Linietsky <reduzio@gmail.com> */ -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 fill_default_theme(Ref<Theme>& theme,const Ref<Font> & default_font,const Ref<Font> & large_font,Ref<Texture>& default_icon, Ref<StyleBox>& default_style,float p_scale); void make_default_theme(bool p_hidpi, Ref<Font> p_font); void clear_default_theme(); |