summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--scene/resources/default_theme/default_theme.cpp31
-rw-r--r--scene/resources/default_theme/default_theme.h2
-rw-r--r--tools/editor/editor_fonts.cpp15
-rw-r--r--tools/editor/editor_node.cpp12
-rw-r--r--tools/editor/editor_scale.cpp11
-rw-r--r--tools/editor/editor_scale.h6
-rw-r--r--tools/editor/editor_settings.cpp2
-rw-r--r--tools/editor/editor_themes.cpp5
-rw-r--r--tools/editor/icons/SCsub6
-rw-r--r--tools/editor/project_manager.cpp12
10 files changed, 61 insertions, 41 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();
diff --git a/tools/editor/editor_fonts.cpp b/tools/editor/editor_fonts.cpp
index 47891eef6c..bcf41cbac8 100644
--- a/tools/editor/editor_fonts.cpp
+++ b/tools/editor/editor_fonts.cpp
@@ -158,17 +158,10 @@ void editor_register_fonts(Ref<Theme> p_theme) {
p_theme->set_font("doc_source","EditorFonts",df_doc_code);
- if (editor_is_hidpi()) {
- //replace default theme
- Ref<Texture> di;
- Ref<StyleBox> ds;
- fill_default_theme(p_theme,df,df_doc,di,ds,true);
+ //replace default theme
+ Ref<Texture> di;
+ Ref<StyleBox> ds;
+ fill_default_theme(p_theme,df,df_doc,di,ds,EDSCALE);
- } else {
- Ref<Texture> di;
- Ref<StyleBox> ds;
- fill_default_theme(p_theme,df,df_doc,di,ds,false);
-
- }
}
diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp
index 6df40ad9e5..65cc383a00 100644
--- a/tools/editor/editor_node.cpp
+++ b/tools/editor/editor_node.cpp
@@ -5369,11 +5369,15 @@ EditorNode::EditorNode() {
{
int dpi_mode = EditorSettings::get_singleton()->get("global/hidpi_mode");
if (dpi_mode==0) {
- editor_set_hidpi( OS::get_singleton()->get_screen_dpi(0) > 150 );
+ editor_set_scale( OS::get_singleton()->get_screen_dpi(0) > 150 ? 2.0 : 1.0 );
+ } else if (dpi_mode==1) {
+ editor_set_scale(0.75);
} else if (dpi_mode==2) {
- editor_set_hidpi(true);
- } else {
- editor_set_hidpi(false);
+ editor_set_scale(1.0);
+ } else if (dpi_mode==3) {
+ editor_set_scale(1.5);
+ } else if (dpi_mode==4) {
+ editor_set_scale(2.0);
}
}
diff --git a/tools/editor/editor_scale.cpp b/tools/editor/editor_scale.cpp
index c332acc0ca..8575e1c30a 100644
--- a/tools/editor/editor_scale.cpp
+++ b/tools/editor/editor_scale.cpp
@@ -1,14 +1,13 @@
#include "editor_scale.h"
#include "os/os.h"
-static bool editor_hidpi=false;
+static float scale = 1.0;
-void editor_set_hidpi(bool p_hidpi) {
+void editor_set_scale(float p_scale) {
- editor_hidpi=p_hidpi;
+ scale=p_scale;
}
+float editor_get_scale() {
-bool editor_is_hidpi() {
-
- return editor_hidpi;
+ return scale;
}
diff --git a/tools/editor/editor_scale.h b/tools/editor/editor_scale.h
index a60cf00f0a..90e575f771 100644
--- a/tools/editor/editor_scale.h
+++ b/tools/editor/editor_scale.h
@@ -1,8 +1,8 @@
#ifndef EDITOR_SCALE_H
#define EDITOR_SCALE_H
-void editor_set_hidpi(bool p_hidpi);
-bool editor_is_hidpi();
+void editor_set_scale(float p_scale);
+float editor_get_scale();
-#define EDSCALE (editor_is_hidpi() ? 2 : 1)
+#define EDSCALE (editor_get_scale())
#endif // EDITOR_SCALE_H
diff --git a/tools/editor/editor_settings.cpp b/tools/editor/editor_settings.cpp
index ad5cd86b4b..4778a7ce90 100644
--- a/tools/editor/editor_settings.cpp
+++ b/tools/editor/editor_settings.cpp
@@ -511,7 +511,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
}
set("global/hidpi_mode",0);
- hints["global/hidpi_mode"]=PropertyInfo(Variant::INT,"global/hidpi_mode",PROPERTY_HINT_ENUM,"Auto,LoDPI,HiDPI",PROPERTY_USAGE_DEFAULT|PROPERTY_USAGE_RESTART_IF_CHANGED);
+ hints["global/hidpi_mode"]=PropertyInfo(Variant::INT,"global/hidpi_mode",PROPERTY_HINT_ENUM,"Auto,VeryLoDPI,LoDPI,MidDPI,HiDPI",PROPERTY_USAGE_DEFAULT|PROPERTY_USAGE_RESTART_IF_CHANGED);
set("global/show_script_in_scene_tabs",false);
set("global/font_size",14);
hints["global/font_size"]=PropertyInfo(Variant::INT,"global/font_size",PROPERTY_HINT_RANGE,"10,40,1",PROPERTY_USAGE_DEFAULT|PROPERTY_USAGE_RESTART_IF_CHANGED);
diff --git a/tools/editor/editor_themes.cpp b/tools/editor/editor_themes.cpp
index 80ba4c46e0..08f14ec167 100644
--- a/tools/editor/editor_themes.cpp
+++ b/tools/editor/editor_themes.cpp
@@ -32,6 +32,7 @@
#include "editor_fonts.h"
#include "editor_settings.h"
#include "core/io/resource_loader.h"
+#include "editor_scale.h"
Ref<Theme> create_editor_theme()
{
@@ -43,8 +44,8 @@ Ref<Theme> create_editor_theme()
Ref<StyleBoxTexture> focus_sbt=memnew( StyleBoxTexture );
focus_sbt->set_texture(theme->get_icon("EditorFocus","EditorIcons"));
for(int i=0;i<4;i++) {
- focus_sbt->set_margin_size(Margin(i),16);
- focus_sbt->set_default_margin(Margin(i),16);
+ focus_sbt->set_margin_size(Margin(i),16*EDSCALE);
+ focus_sbt->set_default_margin(Margin(i),16*EDSCALE);
}
focus_sbt->set_draw_center(false);
theme->set_stylebox("EditorFocus","EditorStyles",focus_sbt);
diff --git a/tools/editor/icons/SCsub b/tools/editor/icons/SCsub
index bc104294cb..44e28f49e6 100644
--- a/tools/editor/icons/SCsub
+++ b/tools/editor/icons/SCsub
@@ -61,8 +61,10 @@ def make_editor_icons_action(target, source, env):
s.write("static Ref<ImageTexture> make_icon(const uint8_t* p_png,const uint8_t* p_hidpi_png) {\n")
s.write("\tRef<ImageTexture> texture( memnew( ImageTexture ) );\n")
- s.write("\tImage img((editor_is_hidpi()&&p_hidpi_png)?p_hidpi_png:p_png);\n")
- s.write("\tif (editor_is_hidpi() && !p_hidpi_png) { img.convert(Image::FORMAT_RGBA); img.expand_x2_hq2x(); }\n")
+ s.write("\tbool use_hidpi_image=(editor_get_scale()>1.0&&p_hidpi_png);\n")
+ s.write("\tImage img(use_hidpi_image?p_hidpi_png:p_png);\n")
+ s.write("\tif (editor_get_scale()>1.0 && !p_hidpi_png) { img.convert(Image::FORMAT_RGBA); img.expand_x2_hq2x(); use_hidpi_image=true;}\n")
+ s.write("\timg.resize(img.get_width()*EDSCALE/(use_hidpi_image?2:1),img.get_height()*EDSCALE/(use_hidpi_image?2:1));\n")
s.write("\ttexture->create_from_image( img,ImageTexture::FLAG_FILTER );\n")
s.write("\treturn texture;\n")
s.write("}\n\n")
diff --git a/tools/editor/project_manager.cpp b/tools/editor/project_manager.cpp
index b884e0d111..b9691ee7c4 100644
--- a/tools/editor/project_manager.cpp
+++ b/tools/editor/project_manager.cpp
@@ -1185,11 +1185,15 @@ ProjectManager::ProjectManager() {
{
int dpi_mode = EditorSettings::get_singleton()->get("global/hidpi_mode");
if (dpi_mode==0) {
- editor_set_hidpi( OS::get_singleton()->get_screen_dpi(0) > 150 );
+ editor_set_scale( OS::get_singleton()->get_screen_dpi(0) > 150 ? 2.0 : 1.0 );
+ } else if (dpi_mode==1) {
+ editor_set_scale(0.75);
} else if (dpi_mode==2) {
- editor_set_hidpi(true);
- } else {
- editor_set_hidpi(false);
+ editor_set_scale(1.0);
+ } else if (dpi_mode==3) {
+ editor_set_scale(1.5);
+ } else if (dpi_mode==4) {
+ editor_set_scale(2.0);
}
}