From 9b1f8230ec435d9289b53afa8da02367daf8b5af Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Mon, 30 May 2016 00:28:29 -0300 Subject: [PATCH] -Some fixes to OSX retina scaling for window functions -Implemented HiDPI detection and support for Godot Editor! --- core/os/os.cpp | 1 + core/os/os.h | 2 + main/main.cpp | 12 +- platform/osx/os_osx.h | 19 +- platform/osx/os_osx.mm | 87 ++++-- scene/gui/dialogs.cpp | 79 ++++- scene/gui/dialogs.h | 7 + scene/gui/tab_container.cpp | 5 + .../resources/default_theme/default_theme.cpp | 275 +++++++++--------- scene/resources/default_theme/default_theme.h | 2 + tools/editor/editor_file_dialog.cpp | 9 +- tools/editor/editor_fonts.cpp | 22 +- tools/editor/editor_node.cpp | 19 +- tools/editor/editor_node.h | 1 + tools/editor/editor_resource_preview.cpp | 4 +- tools/editor/editor_scale.cpp | 7 + tools/editor/editor_scale.h | 8 + tools/editor/icons/SCsub | 3 +- .../io_plugins/editor_font_import_plugin.cpp | 10 +- .../io_plugins/editor_mesh_import_plugin.cpp | 2 +- .../editor_sample_import_plugin.cpp | 6 +- .../io_plugins/editor_scene_import_plugin.cpp | 14 +- .../editor_texture_import_plugin.cpp | 14 +- .../editor_translation_import_plugin.cpp | 12 +- .../editor/plugins/editor_preview_plugins.cpp | 9 +- .../editor/plugins/material_editor_plugin.cpp | 2 +- tools/editor/plugins/mesh_editor_plugin.cpp | 2 +- tools/editor/plugins/sample_editor_plugin.cpp | 2 +- tools/editor/plugins/script_editor_plugin.cpp | 4 +- tools/editor/progress_dialog.cpp | 6 +- tools/editor/property_editor.cpp | 12 +- tools/editor/scenes_dock.cpp | 4 +- tools/editor/script_editor_debugger.cpp | 2 +- 33 files changed, 421 insertions(+), 242 deletions(-) create mode 100644 tools/editor/editor_scale.cpp create mode 100644 tools/editor/editor_scale.h diff --git a/core/os/os.cpp b/core/os/os.cpp index 1aee6d9aa2e..6910b368d34 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -548,6 +548,7 @@ OS::OS() { _render_thread_mode=RENDER_THREAD_SAFE; _time_scale=1.0; _pixel_snap=false; + _allow_hidpi=true; Math::seed(1234567); } diff --git a/core/os/os.h b/core/os/os.h index 5fd2bd6c25f..76dd235d24f 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -60,6 +60,7 @@ class OS { int _target_fps; float _time_scale; bool _pixel_snap; + bool _allow_hidpi; char *last_error; @@ -418,6 +419,7 @@ public: virtual void set_context(int p_context); + bool is_hidpi_allowed() const { return _allow_hidpi; } OS(); virtual ~OS(); diff --git a/main/main.cpp b/main/main.cpp index 0a92971bae9..fba7a781bf3 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -101,12 +101,13 @@ static bool init_fullscreen=false; static bool init_use_custom_pos=false; static bool debug_collisions=false; static bool debug_navigation=false; +static bool allow_hidpi=true; static Vector2 init_custom_pos; static int video_driver_idx=-1; static int audio_driver_idx=-1; static String locale; static bool use_debug_profiler=false; - +static bool force_lowdpi=false; static int init_screen=-1; static String unescape_cmdline(const String& p_str) { @@ -157,6 +158,8 @@ void Main::print_help(const char* p_binary) { OS::get_singleton()->print("%s",OS::get_singleton()->get_video_driver_name(i)); } OS::get_singleton()->print(")\n"); + OS::get_singleton()->print("\t-ldpi\t : Force low-dpi mode (OSX Only)"); + OS::get_singleton()->print("\t-ad DRIVER\t : Audio Driver ("); for (int i=0;iget_audio_driver_count();i++) { @@ -386,6 +389,9 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas goto error; } + } else if (I->get()=="-ldpi") { // language + + force_lowdpi=true; } else if (I->get()=="-rfs") { // language if (I->next()) { @@ -691,6 +697,9 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas video_mode.width=globals->get("display/width"); if (!force_res &&use_custom_res && globals->has("display/height")) video_mode.height=globals->get("display/height"); + if (!editor && (!bool(globals->get("display/allow_hidpi")) || force_lowdpi)) { + OS::get_singleton()->_allow_hidpi=false; + } if (use_custom_res && globals->has("display/fullscreen")) video_mode.fullscreen=globals->get("display/fullscreen"); if (use_custom_res && globals->has("display/resizable")) @@ -710,6 +719,7 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas GLOBAL_DEF("display/width",video_mode.width); GLOBAL_DEF("display/height",video_mode.height); + GLOBAL_DEF("display/allow_hidpi",false); GLOBAL_DEF("display/fullscreen",video_mode.fullscreen); GLOBAL_DEF("display/resizable",video_mode.resizable); GLOBAL_DEF("display/borderless_window", video_mode.borderless_window); diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h index d88dd890027..8d646863359 100644 --- a/platform/osx/os_osx.h +++ b/platform/osx/os_osx.h @@ -59,7 +59,7 @@ public: bool force_quit; Rasterizer *rasterizer; VisualServer *visual_server; - VideoMode current_videomode; + List args; MainLoop *main_loop; unsigned int event_id; @@ -104,9 +104,22 @@ public: bool minimized; bool maximized; bool zoomed; + Vector screens; + Vector screen_dpi; + + Size2 window_size; int current_screen; Rect2 restore_rect; + + float _mouse_scale(float p_scale) { + if (display_scale>1.0) + return p_scale; + else + return 1.0; + } + + float display_scale; protected: virtual int get_video_driver_count() const; @@ -173,6 +186,9 @@ public: virtual int get_current_screen() const; virtual void set_current_screen(int p_screen); virtual Point2 get_screen_position(int p_screen=0) const; + virtual Size2 get_screen_size(int p_screen=0) const; + virtual int get_screen_dpi(int p_screen=0) const; + virtual Point2 get_window_position() const; virtual void set_window_position(const Point2& p_position); virtual void set_window_size(const Size2 p_size); @@ -184,7 +200,6 @@ public: virtual bool is_window_minimized() const; virtual void set_window_maximized(bool p_enabled); virtual bool is_window_maximized() const; - Size2 get_screen_size(int p_screen=0) const; void run(); diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index c443fc2d0e8..b614dd57aa8 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -202,10 +202,10 @@ static int button_mask=0; [OS_OSX::singleton->context update]; const NSRect contentRect = [OS_OSX::singleton->window_view frame]; - const NSRect fbRect = convertRectToBacking(contentRect); + const NSRect fbRect = contentRect;//convertRectToBacking(contentRect); - OS_OSX::singleton->current_videomode.width=fbRect.size.width; - OS_OSX::singleton->current_videomode.height=fbRect.size.height; + OS_OSX::singleton->window_size.width=fbRect.size.width*OS_OSX::singleton->display_scale; + OS_OSX::singleton->window_size.height=fbRect.size.height*OS_OSX::singleton->display_scale; // _GodotInputFramebufferSize(window, fbRect.size.width, fbRect.size.height); @@ -324,7 +324,7 @@ static int button_mask=0; - (void)mouseDown:(NSEvent *)event { - print_line("mouse down:"); + //print_line("mouse down:"); button_mask|=BUTTON_MASK_LEFT; InputEvent ev; ev.type=InputEvent::MOUSE_BUTTON; @@ -383,14 +383,14 @@ static int button_mask=0; prev_mouse_y=mouse_y; const NSRect contentRect = [OS_OSX::singleton->window_view frame]; const NSPoint p = [event locationInWindow]; - mouse_x = p.x * [[event window] backingScaleFactor]; - mouse_y = (contentRect.size.height - p.y) * [[event window] backingScaleFactor]; + mouse_x = p.x * OS_OSX::singleton->_mouse_scale([[event window] backingScaleFactor]); + mouse_y = (contentRect.size.height - p.y) * OS_OSX::singleton->_mouse_scale([[event window] backingScaleFactor]); ev.mouse_motion.x=mouse_x; ev.mouse_motion.y=mouse_y; ev.mouse_motion.global_x=mouse_x; ev.mouse_motion.global_y=mouse_y; - ev.mouse_motion.relative_x=[event deltaX] * [[event window] backingScaleFactor]; - ev.mouse_motion.relative_y=[event deltaY] * [[event window] backingScaleFactor]; + ev.mouse_motion.relative_x=[event deltaX] * OS_OSX::singleton->_mouse_scale([[event window] backingScaleFactor]); + ev.mouse_motion.relative_y=[event deltaY] * OS_OSX::singleton->_mouse_scale([[event window] backingScaleFactor]); ev.mouse_motion.mod = translateFlags([event modifierFlags]); OS_OSX::singleton->input->set_mouse_pos(Point2(mouse_x,mouse_y)); @@ -893,6 +893,15 @@ void OS_OSX::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi kTISNotifySelectedKeyboardInputSourceChanged, NULL, CFNotificationSuspensionBehaviorDeliverImmediately); + if (is_hidpi_allowed() && [[NSScreen mainScreen] respondsToSelector:@selector(backingScaleFactor)]) { + for (NSScreen *screen in [NSScreen screens]) { + float s = [screen backingScaleFactor]; + if (s > display_scale) { + display_scale=s; + } + } + } + window_delegate = [[GodotWindowDelegate alloc] init]; // Don't use accumulation buffer support; it's not accelerated @@ -902,7 +911,7 @@ void OS_OSX::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi window_object = [[GodotWindow alloc] - initWithContentRect:NSMakeRect(0, 0, p_desired.width, p_desired.height) + initWithContentRect:NSMakeRect(0, 0, p_desired.width/display_scale, p_desired.height/display_scale) styleMask:styleMask backing:NSBackingStoreBuffered defer:NO]; @@ -911,15 +920,11 @@ void OS_OSX::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi window_view = [[GodotContentView alloc] init]; - current_videomode = p_desired; - - // Adjust for display density - const NSRect fbRect = convertRectToBacking(NSMakeRect(0, 0, p_desired.width, p_desired.height)); - current_videomode.width = fbRect.size.width; - current_videomode.height = fbRect.size.height; + window_size.width = p_desired.width; + window_size.height = p_desired.height; #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 - if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6) { + if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6 && display_scale>1) { [window_view setWantsBestResolutionOpenGLSurface:YES]; //if (current_videomode.resizable) [window_object setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary]; @@ -1062,9 +1067,28 @@ void OS_OSX::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi printf("nscreen count %i\n", (int)[screenArray count]); for (int i=0; i<[screenArray count]; i++) { + float displayScale = 1.0; + + if (display_scale>1.0 && [[screenArray objectAtIndex: i] respondsToSelector:@selector(backingScaleFactor)]) { + displayScale = [[screenArray objectAtIndex: i] backingScaleFactor]; + } + NSRect nsrect = [[screenArray objectAtIndex: i] visibleFrame]; - screens.push_back(Rect2(nsrect.origin.x, nsrect.origin.y, nsrect.size.width, nsrect.size.height)); - printf("added screen %i\n", screens.size()); + Rect2 rect = Rect2(nsrect.origin.x, nsrect.origin.y, nsrect.size.width, nsrect.size.height); + rect.pos*=displayScale; + rect.size*=displayScale; + screens.push_back(rect); + + NSDictionary *description = [[screenArray objectAtIndex: i] deviceDescription]; + NSSize displayPixelSize = [[description objectForKey:NSDeviceSize] sizeValue]; + CGSize displayPhysicalSize = CGDisplayScreenSize( + [[description objectForKey:@"NSScreenNumber"] unsignedIntValue]); + + //printf("width: %i pwidth %i rect width %i\n",int(displayPixelSize.width*displayScale),int(displayPhysicalSize.width*displayScale),int(nsrect.size.width)); + int dpi = (displayPixelSize.width * 25.4f / displayPhysicalSize.width)*displayScale; + + screen_dpi.push_back(dpi); + }; restore_rect = Rect2(get_window_position(), get_window_size()); } @@ -1326,7 +1350,11 @@ void OS_OSX::set_video_mode(const VideoMode& p_video_mode,int p_screen) { OS::VideoMode OS_OSX::get_video_mode(int p_screen) const { - return current_videomode; + VideoMode vm; + vm.width=window_size.width; + vm.height=window_size.height; + + return vm; } void OS_OSX::get_fullscreen_mode_list(List *p_list,int p_screen) const { @@ -1354,6 +1382,12 @@ Point2 OS_OSX::get_screen_position(int p_screen) const { return screens[p_screen].pos; }; +int OS_OSX::get_screen_dpi(int p_screen) const { + + ERR_FAIL_INDEX_V(p_screen, screens.size(), 72); + return screen_dpi[p_screen]; +} + Size2 OS_OSX::get_screen_size(int p_screen) const { ERR_FAIL_INDEX_V(p_screen, screens.size(), Point2()); @@ -1362,24 +1396,29 @@ Size2 OS_OSX::get_screen_size(int p_screen) const { Point2 OS_OSX::get_window_position() const { - return Size2([window_object frame].origin.x, [window_object frame].origin.y); + Size2 wp([window_object frame].origin.x, [window_object frame].origin.y); + wp*=display_scale; }; void OS_OSX::set_window_position(const Point2& p_position) { - [window_object setFrame:NSMakeRect(p_position.x, p_position.y, [window_object frame].size.width, [window_object frame].size.height) display:YES]; + Point2 size=p_position; + size/=display_scale; + [window_object setFrame:NSMakeRect(size.x, size.y, [window_object frame].size.width, [window_object frame].size.height) display:YES]; }; Size2 OS_OSX::get_window_size() const { - return Size2([window_object frame].size.width, [window_object frame].size.height); + return window_size; + }; void OS_OSX::set_window_size(const Size2 p_size) { + Size2 size=p_size; NSRect frame = [window_object frame]; - [window_object setFrame:NSMakeRect(frame.origin.x, frame.origin.y, p_size.x, p_size.y) display:YES]; + [window_object setFrame:NSMakeRect(frame.origin.x, frame.origin.y, size.x, size.y) display:YES]; }; void OS_OSX::set_window_fullscreen(bool p_enabled) { @@ -1690,5 +1729,7 @@ OS_OSX::OS_OSX() { maximized = false; minimized = false; + window_size=Vector2(1024,600); zoomed = false; + display_scale=1.0; } diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp index 51242d89bdc..e7a84d1146c 100644 --- a/scene/gui/dialogs.cpp +++ b/scene/gui/dialogs.cpp @@ -118,6 +118,16 @@ void WindowDialog::set_title(const String& p_title) { update(); } +Size2 WindowDialog::get_minimum_size() const { + + Ref font = get_font("title_font","WindowDialog"); + int msx=close_button->get_combined_minimum_size().x; + msx+=font->get_string_size(title).x; + + return Size2(msx,1); +} + + String WindowDialog::get_title() const { return title; @@ -192,11 +202,9 @@ void AcceptDialog::_notification(int p_what) { if (p_what==NOTIFICATION_MODAL_CLOSE) { cancel_pressed(); - } if (p_what==NOTIFICATION_DRAW) { - - - + } if (p_what==NOTIFICATION_RESIZED) { + _update_child_rect(); } } @@ -244,12 +252,69 @@ void AcceptDialog::register_text_enter(Node *p_line_edit) { p_line_edit->connect("text_entered", this,"_builtin_text_entered"); } +void AcceptDialog::_update_child_rect() { + + int margin = get_constant("margin","Dialogs"); + Size2 size = get_size(); + Size2 hminsize = hbc->get_combined_minimum_size(); + + Vector2 cpos(margin,margin); + Vector2 csize(size.x-margin*2,size.y-margin*3-hminsize.y); + label->set_pos(cpos); + label->set_size(csize); + + if (child) { + + child->set_pos(cpos); + child->set_size(csize); + } + + cpos.y+=csize.y+margin; + csize.y=hminsize.y; + + hbc->set_pos(cpos); + hbc->set_size(csize); + +} + +Size2 AcceptDialog::get_minimum_size() const { + + int margin = get_constant("margin","Dialogs"); + Size2 minsize = label->get_combined_minimum_size(); + if (child) { + + Size2 cminsize = child->get_combined_minimum_size(); + minsize.x=MAX(cminsize.x,minsize.x); + minsize.y=MAX(cminsize.y,minsize.y); + } + + Size2 hminsize = hbc->get_combined_minimum_size(); + minsize.x = MAX(hminsize.x,minsize.x); + minsize.y+=hminsize.y; + minsize.x+=margin*2; + minsize.y+=margin*3; //one as separation between hbc and child + + Size2 wmsize = WindowDialog::get_minimum_size(); + minsize.x=MAX(wmsize.x,minsize.x); + return minsize; +} + + void AcceptDialog::set_child_rect(Control *p_child) { ERR_FAIL_COND(p_child->get_parent()!=this); - p_child->set_area_as_parent_rect(get_constant("margin","Dialogs")); - p_child->set_margin(MARGIN_BOTTOM, get_constant("button_margin","Dialogs")+10); + //p_child->set_area_as_parent_rect(get_constant("margin","Dialogs")); + child=p_child; + minimum_size_changed(); + _update_child_rect(); +} + +void AcceptDialog::remove_child_notify(Node *p_child) { + + if (p_child==child) { + child=NULL; + } } void AcceptDialog::_custom_action(const String& p_action) { @@ -352,6 +417,8 @@ AcceptDialog::AcceptDialog() { hide_on_ok=true; set_title("Alert!"); + + child=NULL; } diff --git a/scene/gui/dialogs.h b/scene/gui/dialogs.h index f256c49aee9..d00bb41ff60 100644 --- a/scene/gui/dialogs.h +++ b/scene/gui/dialogs.h @@ -64,6 +64,8 @@ public: void set_title(const String& p_title); String get_title() const; + Size2 get_minimum_size() const; + WindowDialog(); ~WindowDialog(); @@ -89,6 +91,7 @@ class AcceptDialog : public WindowDialog { OBJ_TYPE(AcceptDialog,WindowDialog); + Control *child; HBoxContainer *hbc; Label *label; Button *ok; @@ -100,10 +103,12 @@ class AcceptDialog : public WindowDialog { void _ok_pressed(); void _close_pressed(); void _builtin_text_entered(const String& p_text); + void _update_child_rect(); static bool swap_ok_cancel; + virtual void remove_child_notify(Node *p_child); protected: @@ -116,6 +121,8 @@ protected: virtual void custom_action(const String&) {} public: + Size2 get_minimum_size() const; + Label *get_label() { return label; } static void set_swap_ok_cancel(bool p_swap); diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp index 1c6a97bab8e..c8bd1cb5a12 100644 --- a/scene/gui/tab_container.cpp +++ b/scene/gui/tab_container.cpp @@ -411,6 +411,11 @@ void TabContainer::_notification(int p_what) { panel->draw(ci, Rect2( 0, top_size.height, size.width, size.height-top_size.height)); } break; + case NOTIFICATION_READY: + case NOTIFICATION_THEME_CHANGED: { + + call_deferred("set_current_tab",get_current_tab()); //wait until all changed theme + } break; } } diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index cd90bf52b66..9ebb7e75615 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -28,6 +28,7 @@ typedef Map > TexCacheMap; static TexCacheMap *tex_cache; +static int scale=1; template static Ref 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) { @@ -40,21 +41,24 @@ static Ref make_stylebox(T p_src,float p_left, float p_top, flo } else { texture = Ref( memnew( ImageTexture ) ); - texture->create_from_image( Image(p_src),ImageTexture::FLAG_FILTER ); + Image img(p_src); + if (scale>1) + img.expand_x2_hq2x(); + texture->create_from_image( img,ImageTexture::FLAG_FILTER ); (*tex_cache)[p_src]=texture; } Ref style( memnew( StyleBoxTexture ) ); style->set_texture(texture); - style->set_margin_size( MARGIN_LEFT, p_left ); - style->set_margin_size( MARGIN_RIGHT, p_right ); - style->set_margin_size( MARGIN_BOTTOM, p_botton ); - style->set_margin_size( MARGIN_TOP, p_top ); - style->set_default_margin( MARGIN_LEFT, p_margin_left ); - style->set_default_margin( MARGIN_RIGHT, p_margin_right ); - style->set_default_margin( MARGIN_BOTTOM, p_margin_botton ); - style->set_default_margin( MARGIN_TOP, p_margin_top ); + style->set_margin_size( MARGIN_LEFT, p_left * scale); + style->set_margin_size( MARGIN_RIGHT, p_right * scale); + style->set_margin_size( MARGIN_BOTTOM, p_botton * scale); + style->set_margin_size( MARGIN_TOP, p_top * scale); + style->set_default_margin( MARGIN_LEFT, p_margin_left * scale); + style->set_default_margin( MARGIN_RIGHT, p_margin_right * scale); + style->set_default_margin( MARGIN_BOTTOM, p_margin_botton * scale); + style->set_default_margin( MARGIN_TOP, p_margin_top * scale); style->set_draw_center(p_draw_center); return style; @@ -63,10 +67,10 @@ static Ref make_stylebox(T p_src,float p_left, float p_top, flo static Ref sb_expand(Ref p_sbox,float p_left, float p_top, float p_right, float p_botton) { - p_sbox->set_expand_margin_size(MARGIN_LEFT,p_left); - p_sbox->set_expand_margin_size(MARGIN_TOP,p_top); - p_sbox->set_expand_margin_size(MARGIN_RIGHT,p_right); - p_sbox->set_expand_margin_size(MARGIN_BOTTOM,p_botton); + p_sbox->set_expand_margin_size(MARGIN_LEFT,p_left * scale); + p_sbox->set_expand_margin_size(MARGIN_TOP,p_top * scale); + p_sbox->set_expand_margin_size(MARGIN_RIGHT,p_right * scale); + p_sbox->set_expand_margin_size(MARGIN_BOTTOM,p_botton * scale); return p_sbox; } @@ -75,7 +79,10 @@ static Ref make_icon(T p_src) { Ref texture( memnew( ImageTexture ) ); - texture->create_from_image( Image(p_src),ImageTexture::FLAG_FILTER ); + Image img = Image(p_src); + if (scale>1) + img.expand_x2_hq2x(); + texture->create_from_image( img,ImageTexture::FLAG_FILTER ); return texture; } @@ -170,27 +177,24 @@ static Ref make_empty_stylebox(float p_margin_left=-1, float p_margin_ Ref style( memnew( StyleBoxEmpty) ); - style->set_default_margin( MARGIN_LEFT, p_margin_left ); - style->set_default_margin( MARGIN_RIGHT, p_margin_right ); - style->set_default_margin( MARGIN_BOTTOM, p_margin_botton ); - style->set_default_margin( MARGIN_TOP, p_margin_top ); + style->set_default_margin( MARGIN_LEFT, p_margin_left * scale); + style->set_default_margin( MARGIN_RIGHT, p_margin_right * scale); + style->set_default_margin( MARGIN_BOTTOM, p_margin_botton * scale); + style->set_default_margin( MARGIN_TOP, p_margin_top * scale); return style; } -#ifndef DEFAULT_THEME_DISABLED - -void make_default_theme() { +void fill_default_theme(Ref& t,const Ref & default_font,const Ref & large_font,Ref& default_icon, Ref& default_style,bool p_hidpi) { + if (p_hidpi) + scale=2; + else + scale=1; tex_cache = memnew( TexCacheMap ); - Ref t( memnew( Theme ) ); - //Ref default_font = make_font(_bi_font_normal_height,_bi_font_normal_ascent,_bi_font_normal_valign,_bi_font_normal_charcount,_bi_font_normal_characters,make_icon(font_normal_png)); - Ref 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 source_font=make_font2(_builtin_source_font_height,_builtin_source_font_ascent,_builtin_source_font_charcount,&_builtin_source_font_charrects[0][0],_builtin_source_font_kerning_pair_count,&_builtin_source_font_kerning_pairs[0][0],_builtin_source_font_img_width,_builtin_source_font_img_height,_builtin_source_font_img_data); - Ref 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); // Font Colors @@ -213,7 +217,7 @@ void make_default_theme() { Ref focus = make_stylebox( focus_png,5,5,5,5); for(int i=0;i<4;i++) { - focus->set_expand_margin_size(Margin(i),1); + focus->set_expand_margin_size(Margin(i),1 *scale); } @@ -239,7 +243,7 @@ void make_default_theme() { t->set_color("font_color_hover","Button", control_font_color_hover ); t->set_color("font_color_disabled","Button", control_font_color_disabled ); - t->set_constant("hseparation","Button", 2); + t->set_constant("hseparation","Button", 2 *scale); // LinkButton @@ -249,7 +253,7 @@ void make_default_theme() { t->set_color("font_color_pressed","LinkButton", control_font_color_pressed ); t->set_color("font_color_hover","LinkButton", control_font_color_hover ); - t->set_constant("underline_spacing","LinkButton", 2 ); + t->set_constant("underline_spacing","LinkButton", 2 *scale); // ColorPickerButton @@ -266,16 +270,16 @@ void make_default_theme() { t->set_color("font_color_hover","ColorPickerButton", Color(1,1,1,1) ); t->set_color("font_color_disabled","ColorPickerButton", Color(0.9,0.9,0.9,0.3) ); - t->set_constant("hseparation","ColorPickerButton", 2 ); + t->set_constant("hseparation","ColorPickerButton", 2 *scale); // ToolButton Ref tb_empty = memnew( StyleBoxEmpty ); - tb_empty->set_default_margin(MARGIN_LEFT,6); - tb_empty->set_default_margin(MARGIN_RIGHT,6); - tb_empty->set_default_margin(MARGIN_TOP,4); - tb_empty->set_default_margin(MARGIN_BOTTOM,4); + tb_empty->set_default_margin(MARGIN_LEFT,6 *scale); + tb_empty->set_default_margin(MARGIN_RIGHT,6 *scale); + tb_empty->set_default_margin(MARGIN_TOP,4 *scale); + tb_empty->set_default_margin(MARGIN_BOTTOM,4 *scale); t->set_stylebox("normal","ToolButton", tb_empty); t->set_stylebox("pressed","ToolButton", make_stylebox( button_pressed_png,4,4,4,4) ); @@ -316,8 +320,8 @@ void make_default_theme() { t->set_color("font_color_hover","OptionButton", control_font_color_hover ); t->set_color("font_color_disabled","OptionButton", control_font_color_disabled ); - t->set_constant("hseparation","OptionButton", 2 ); - t->set_constant("arrow_margin","OptionButton", 2 ); + t->set_constant("hseparation","OptionButton", 2 *scale); + t->set_constant("arrow_margin","OptionButton", 2 *scale); @@ -336,7 +340,7 @@ void make_default_theme() { t->set_color("font_color_hover","MenuButton", control_font_color_hover ); t->set_color("font_color_disabled","MenuButton", Color(1,1,1,0.3) ); - t->set_constant("hseparation","MenuButton", 3 ); + t->set_constant("hseparation","MenuButton", 3 *scale); // ButtonGroup @@ -345,15 +349,15 @@ void make_default_theme() { // CheckBox Ref cbx_empty = memnew( StyleBoxEmpty ); - cbx_empty->set_default_margin(MARGIN_LEFT,22); - cbx_empty->set_default_margin(MARGIN_RIGHT,4); - cbx_empty->set_default_margin(MARGIN_TOP,4); - cbx_empty->set_default_margin(MARGIN_BOTTOM,5); + cbx_empty->set_default_margin(MARGIN_LEFT,22 *scale); + cbx_empty->set_default_margin(MARGIN_RIGHT,4 *scale); + cbx_empty->set_default_margin(MARGIN_TOP,4 *scale); + cbx_empty->set_default_margin(MARGIN_BOTTOM,5 *scale); Ref cbx_focus = focus; - cbx_focus->set_default_margin(MARGIN_LEFT,4); - cbx_focus->set_default_margin(MARGIN_RIGHT,22); - cbx_focus->set_default_margin(MARGIN_TOP,4); - cbx_focus->set_default_margin(MARGIN_BOTTOM,5); + cbx_focus->set_default_margin(MARGIN_LEFT,4 *scale); + cbx_focus->set_default_margin(MARGIN_RIGHT,22 *scale); + cbx_focus->set_default_margin(MARGIN_TOP,4 *scale); + cbx_focus->set_default_margin(MARGIN_BOTTOM,5 *scale); t->set_stylebox("normal","CheckBox", cbx_empty ); t->set_stylebox("pressed","CheckBox", cbx_empty ); @@ -373,18 +377,18 @@ void make_default_theme() { t->set_color("font_color_hover","CheckBox", control_font_color_hover ); t->set_color("font_color_disabled","CheckBox", control_font_color_disabled ); - t->set_constant("hseparation","CheckBox",4); - t->set_constant("check_vadjust","CheckBox",0); + t->set_constant("hseparation","CheckBox",4 *scale); + t->set_constant("check_vadjust","CheckBox",0 *scale); // CheckButton Ref cb_empty = memnew( StyleBoxEmpty ); - cb_empty->set_default_margin(MARGIN_LEFT,6); - cb_empty->set_default_margin(MARGIN_RIGHT,70); - cb_empty->set_default_margin(MARGIN_TOP,4); - cb_empty->set_default_margin(MARGIN_BOTTOM,4); + cb_empty->set_default_margin(MARGIN_LEFT,6 *scale); + cb_empty->set_default_margin(MARGIN_RIGHT,70 *scale); + cb_empty->set_default_margin(MARGIN_TOP,4 *scale); + cb_empty->set_default_margin(MARGIN_BOTTOM,4 *scale); t->set_stylebox("normal","CheckButton", cb_empty ); t->set_stylebox("pressed","CheckButton", cb_empty ); @@ -402,8 +406,8 @@ void make_default_theme() { t->set_color("font_color_hover","CheckButton", control_font_color_hover ); t->set_color("font_color_disabled","CheckButton", control_font_color_disabled ); - t->set_constant("hseparation","CheckButton",4); - t->set_constant("check_vadjust","CheckButton",0); + t->set_constant("hseparation","CheckButton",4 *scale); + t->set_constant("check_vadjust","CheckButton",0 *scale); @@ -414,10 +418,10 @@ void make_default_theme() { t->set_color("font_color","Label", Color(1,1,1) ); t->set_color("font_color_shadow","Label", Color(0,0,0,0) ); - t->set_constant("shadow_offset_x","Label", 1 ); - t->set_constant("shadow_offset_y","Label", 1 ); - t->set_constant("shadow_as_outline","Label", 0 ); - t->set_constant("line_spacing","Label", 3 ); + t->set_constant("shadow_offset_x","Label", 1 *scale); + t->set_constant("shadow_offset_y","Label", 1 *scale); + t->set_constant("shadow_as_outline","Label", 0 *scale); + t->set_constant("line_spacing","Label", 3 *scale); @@ -434,7 +438,7 @@ void make_default_theme() { t->set_color("cursor_color","LineEdit", control_font_color_hover ); t->set_color("selection_color","LineEdit", font_color_selection ); - t->set_constant("minimum_spaces","LineEdit", 12 ); + t->set_constant("minimum_spaces","LineEdit", 12 *scale); @@ -475,7 +479,7 @@ void make_default_theme() { t->set_constant("completion_lines","TextEdit", 7 ); t->set_constant("completion_max_width","TextEdit", 50 ); t->set_constant("completion_scroll_width","TextEdit", 3 ); - t->set_constant("line_spacing","TextEdit",4 ); + t->set_constant("line_spacing","TextEdit",4 *scale); Ref empty_icon = memnew( ImageTexture ); @@ -555,10 +559,10 @@ void make_default_theme() { t->set_color("title_color","WindowDialog", Color(0,0,0) ); - t->set_constant("close_h_ofs","WindowDialog", 22 ); - t->set_constant("close_v_ofs","WindowDialog", 20 ); - t->set_constant("titlebar_height","WindowDialog", 18 ); - t->set_constant("title_height","WindowDialog", 20 ); + t->set_constant("close_h_ofs","WindowDialog", 22 *scale); + t->set_constant("close_v_ofs","WindowDialog", 20 *scale); + t->set_constant("titlebar_height","WindowDialog", 18 *scale); + t->set_constant("title_height","WindowDialog", 20 *scale); // File Dialog @@ -572,7 +576,7 @@ void make_default_theme() { Ref selected = make_stylebox( selection_png,6,6,6,6); for(int i=0;i<4;i++) { - selected->set_expand_margin_size(Margin(i),2); + selected->set_expand_margin_size(Margin(i),2 *scale); } t->set_stylebox("panel","PopupPanel", style_pp ); @@ -598,8 +602,8 @@ void make_default_theme() { t->set_color("font_color_disabled","PopupMenu", Color(0.4,0.4,0.4,0.8) ); t->set_color("font_color_hover","PopupMenu", control_font_color ); - t->set_constant("hseparation","PopupMenu",4); - t->set_constant("vseparation","PopupMenu",4); + t->set_constant("hseparation","PopupMenu",4 *scale); + t->set_constant("vseparation","PopupMenu",4 *scale); // GraphNode @@ -614,14 +618,14 @@ void make_default_theme() { t->set_stylebox("selectedframe","GraphNode", graphsbselected ); t->set_stylebox("defaultframe", "GraphNode", graphsbdefault ); t->set_stylebox("defaultfocus", "GraphNode", graphsbdeffocus ); - t->set_constant("separation","GraphNode", 1 ); + t->set_constant("separation","GraphNode", 1 *scale); t->set_icon("port","GraphNode", make_icon( graph_port_png ) ); t->set_icon("close","GraphNode", make_icon( graph_node_close_png ) ); t->set_font("title_font","GraphNode", default_font ); t->set_color("title_color","GraphNode", Color(0,0,0,1)); - t->set_constant("title_offset","GraphNode", 18); - t->set_constant("close_offset","GraphNode", 18); - t->set_constant("port_offset","GraphNode", 3); + t->set_constant("title_offset","GraphNode", 18 *scale); + t->set_constant("close_offset","GraphNode", 18 *scale); + t->set_constant("port_offset","GraphNode", 3 *scale); // Tree @@ -658,11 +662,11 @@ void make_default_theme() { t->set_color("guide_color","Tree", Color(0,0,0,0.1) ); t->set_color("drop_position_color","Tree", Color(1,0.3,0.2) ); - t->set_constant("hseparation","Tree",4); - t->set_constant("vseparation","Tree",4); - t->set_constant("guide_width","Tree",2); - t->set_constant("item_margin","Tree",12); - t->set_constant("button_margin","Tree",4); + t->set_constant("hseparation","Tree",4 *scale); + t->set_constant("vseparation","Tree",4 *scale); + t->set_constant("guide_width","Tree",2 *scale); + t->set_constant("item_margin","Tree",12 *scale); + t->set_constant("button_margin","Tree",4 *scale); // ItemList @@ -674,7 +678,7 @@ void make_default_theme() { t->set_constant("hseparation","ItemList",4); t->set_constant("vseparation","ItemList",2); t->set_constant("icon_margin","ItemList",4); - t->set_constant("line_separation","ItemList",2); + t->set_constant("line_separation","ItemList",2 *scale); t->set_font("font","ItemList", default_font ); t->set_color("font_color","ItemList", control_font_color_lower ); t->set_color("font_color_selected","ItemList", control_font_color_pressed ); @@ -695,8 +699,8 @@ void make_default_theme() { Ref tc_sb = sb_expand( make_stylebox( tab_container_bg_png,4,4,4,4,4,4,4,4),3,3,3,3); - tc_sb->set_expand_margin_size(MARGIN_TOP,2); - tc_sb->set_default_margin(MARGIN_TOP,8); + tc_sb->set_expand_margin_size(MARGIN_TOP,2 *scale); + tc_sb->set_default_margin(MARGIN_TOP,8 *scale); t->set_stylebox("tab_fg","TabContainer", sb_expand( make_stylebox( tab_current_png,4,4,4,1,16,4,16,4),2,2,2,2) ); t->set_stylebox("tab_bg","TabContainer", sb_expand( make_stylebox( tab_behind_png,5,5,5,1,16,6,16,4),3,0,3,3) ); @@ -714,11 +718,11 @@ void make_default_theme() { t->set_color("font_color_fg","TabContainer", control_font_color_hover ); t->set_color("font_color_bg","TabContainer", control_font_color_low ); - t->set_constant("side_margin","TabContainer", 8 ); - t->set_constant("top_margin","TabContainer", 24); - t->set_constant("label_valign_fg","TabContainer", 0); - t->set_constant("label_valign_bg","TabContainer", 2); - t->set_constant("hseparation","TabContainer", 4); + t->set_constant("side_margin","TabContainer", 8 *scale); + t->set_constant("top_margin","TabContainer", 24 *scale); + t->set_constant("label_valign_fg","TabContainer", 0 *scale); + t->set_constant("label_valign_bg","TabContainer", 2 *scale); + t->set_constant("hseparation","TabContainer", 4 *scale); @@ -741,10 +745,10 @@ void make_default_theme() { t->set_color("font_color_fg","Tabs", control_font_color_hover ); t->set_color("font_color_bg","Tabs", control_font_color_low ); - t->set_constant("top_margin","Tabs", 24); - t->set_constant("label_valign_fg","Tabs", 0); - t->set_constant("label_valign_bg","Tabs", 2); - t->set_constant("hseparation","Tabs", 4); + t->set_constant("top_margin","Tabs", 24 *scale); + t->set_constant("label_valign_fg","Tabs", 0 *scale); + t->set_constant("label_valign_bg","Tabs", 2 *scale); + t->set_constant("hseparation","Tabs", 4 *scale); @@ -754,18 +758,17 @@ void make_default_theme() { t->set_stylebox("separator","VSeparator", make_stylebox( hseparator_png,3,3,3,3) ); t->set_icon("close","Icons", make_icon(icon_close_png)); - t->set_font("source","Fonts", source_font); t->set_font("normal","Fonts", default_font ); t->set_font("large","Fonts", large_font ); - t->set_constant("separation","HSeparator", 4); - t->set_constant("separation","VSeparator", 4); + t->set_constant("separation","HSeparator", 4 *scale); + t->set_constant("separation","VSeparator", 4 *scale); // Dialogs - t->set_constant("margin","Dialogs",8); - t->set_constant("button_margin","Dialogs",32); + t->set_constant("margin","Dialogs",8 *scale); + t->set_constant("button_margin","Dialogs",32 *scale); @@ -778,11 +781,11 @@ void make_default_theme() { // colorPicker - t->set_constant("value_height","ColorPicker", 23 ); - t->set_constant("value_width","ColorPicker", 50); - t->set_constant("color_width","ColorPicker", 100); - t->set_constant("label_width","ColorPicker", 20); - t->set_constant("hseparator","ColorPicker", 4); + t->set_constant("value_height","ColorPicker", 23 *scale); + t->set_constant("value_width","ColorPicker", 50 *scale); + t->set_constant("color_width","ColorPicker", 100 *scale); + t->set_constant("label_width","ColorPicker", 20 *scale); + t->set_constant("hseparator","ColorPicker", 4 *scale); t->set_icon("screen_picker","ColorPicker", make_icon( icon_color_pick_png ) ); t->set_icon("add_preset","ColorPicker", make_icon( icon_add_png ) ); @@ -794,7 +797,7 @@ void make_default_theme() { Ref style_tt = make_stylebox( tooltip_bg_png,4,4,4,4); for(int i=0;i<4;i++) - style_tt->set_expand_margin_size((Margin)i,4); + style_tt->set_expand_margin_size((Margin)i,4 *scale); t->set_stylebox("panel","TooltipPanel", style_tt ); @@ -822,9 +825,9 @@ void make_default_theme() { t->set_color("font_color_selected","RichTextLabel", font_color_selection ); t->set_color("selection_color","RichTextLabel", Color(0.1,0.1,1,0.8) ); - t->set_constant("line_separation","RichTextLabel", 1 ); - t->set_constant("table_hseparation","RichTextLabel", 3 ); - t->set_constant("table_vseparation","RichTextLabel", 3 ); + t->set_constant("line_separation","RichTextLabel", 1 *scale); + t->set_constant("table_hseparation","RichTextLabel", 3 *scale); + t->set_constant("table_vseparation","RichTextLabel", 3 *scale); @@ -836,18 +839,18 @@ void make_default_theme() { t->set_icon("grabber","VSplitContainer",make_icon(vsplitter_png)); t->set_icon("grabber","HSplitContainer",make_icon(hsplitter_png)); - t->set_constant("separation","HBoxContainer",4); - t->set_constant("separation","VBoxContainer",4); - t->set_constant("margin_left","MarginContainer",8); - t->set_constant("margin_top","MarginContainer",0); - t->set_constant("margin_right","MarginContainer",0); - t->set_constant("margin_bottom","MarginContainer",0); - t->set_constant("hseparation","GridContainer",4); - t->set_constant("vseparation","GridContainer",4); - t->set_constant("separation","HSplitContainer",12); - t->set_constant("separation","VSplitContainer",12); - t->set_constant("autohide","HSplitContainer",1); - t->set_constant("autohide","VSplitContainer",1); + t->set_constant("separation","HBoxContainer",4 *scale); + t->set_constant("separation","VBoxContainer",4 *scale); + t->set_constant("margin_left","MarginContainer",8 *scale); + t->set_constant("margin_top","MarginContainer",0 *scale); + t->set_constant("margin_right","MarginContainer",0 *scale); + t->set_constant("margin_bottom","MarginContainer",0 *scale); + t->set_constant("hseparation","GridContainer",4 *scale); + t->set_constant("vseparation","GridContainer",4 *scale); + t->set_constant("separation","HSplitContainer",12 *scale); + t->set_constant("separation","VSplitContainer",12 *scale); + t->set_constant("autohide","HSplitContainer",1 *scale); + t->set_constant("autohide","VSplitContainer",1 *scale); @@ -863,8 +866,8 @@ void make_default_theme() { t->set_color("font_color","HButtonArray", control_font_color_low ); t->set_color("font_color_selected","HButtonArray", control_font_color_hover ); - t->set_constant("icon_separator","HButtonArray", 4 ); - t->set_constant("button_separator","HButtonArray", 8 ); + t->set_constant("icon_separator","HButtonArray", 4 *scale ); + t->set_constant("button_separator","HButtonArray", 8 *scale ); t->set_stylebox("focus","HButtonArray", focus ); @@ -881,8 +884,8 @@ void make_default_theme() { t->set_color("font_color","VButtonArray", control_font_color_low ); t->set_color("font_color_selected","VButtonArray", control_font_color_hover ); - t->set_constant("icon_separator","VButtonArray", 4); - t->set_constant("button_separator","VButtonArray", 8); + t->set_constant("icon_separator","VButtonArray", 4 *scale); + t->set_constant("button_separator","VButtonArray", 8 *scale); t->set_stylebox("focus","VButtonArray", focus ); @@ -914,45 +917,31 @@ void make_default_theme() { // Theme - Theme::set_default( t ); - Theme::set_default_icon( make_icon(error_icon_png) ); - Theme::set_default_style( make_stylebox( error_icon_png,2,2,2,2) ); - Theme::set_default_font( default_font ); + default_icon= make_icon(error_icon_png) ; + default_style = make_stylebox( error_icon_png,2,2,2,2) ; memdelete( tex_cache ); } -#else - -#include "error_icon.xpm" - void make_default_theme() { - Ref t( memnew( Theme ) ); + Ref t; + t.instance(); + Ref default_style; + Ref default_icon; + Ref 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 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); - Image error_img(error_icon_xpm); - Ref texture( memnew( Texture ) ); - texture->create_from_image( error_img ); - - Ref style( memnew( StyleBoxTexture ) ); - style->set_texture(texture); - - for(int i=0;i<4;i++) { - style->set_margin_size( Margin(),8); - style->set_default_margin( Margin(),8); - } - - Ref f = make_default_font(); Theme::set_default( t ); - Theme::set_default_icon( texture ); - Theme::set_default_style( style ); - Theme::set_default_font( f ); + Theme::set_default_icon( default_icon ); + Theme::set_default_style( default_style ); + Theme::set_default_font( default_font ); } -#endif void clear_default_theme() { Theme::set_default( Ref() ); diff --git a/scene/resources/default_theme/default_theme.h b/scene/resources/default_theme/default_theme.h index 44569ba192d..1e3b4b40818 100644 --- a/scene/resources/default_theme/default_theme.h +++ b/scene/resources/default_theme/default_theme.h @@ -12,10 +12,12 @@ #ifndef DEFAULT_THEME_H #define DEFAULT_THEME_H +#include "scene/resources/theme.h" /** @author Juan Linietsky */ +void fill_default_theme(Ref& theme,const Ref & default_font,const Ref & large_font,Ref& default_icon, Ref& default_style,bool p_hidpi); void make_default_theme(); void clear_default_theme(); diff --git a/tools/editor/editor_file_dialog.cpp b/tools/editor/editor_file_dialog.cpp index b9d4949018a..185ec17459e 100644 --- a/tools/editor/editor_file_dialog.cpp +++ b/tools/editor/editor_file_dialog.cpp @@ -7,7 +7,7 @@ #include "editor_settings.h" #include "scene/gui/margin_container.h" #include "os/file_access.h" - +#include "editor_scale.h" EditorFileDialog::GetIconFunc EditorFileDialog::get_icon_func=NULL; EditorFileDialog::GetIconFunc EditorFileDialog::get_large_icon_func=NULL; @@ -347,7 +347,7 @@ void EditorFileDialog::_action_pressed() { if (!valid) { - exterr->popup_centered_minsize(Size2(250,80)); + exterr->popup_centered_minsize(Size2(250,80)*EDSCALE); return; } @@ -431,6 +431,7 @@ void EditorFileDialog::update_file_list() { int thumbnail_size = EditorSettings::get_singleton()->get("file_dialog/thumbnail_size"); + thumbnail_size*=EDSCALE; Ref folder_thumbnail; Ref file_thumbnail; @@ -840,7 +841,7 @@ void EditorFileDialog::_make_dir_confirm() { _push_history(); } else { - mkdirerr->popup_centered_minsize(Size2(250,50)); + mkdirerr->popup_centered_minsize(Size2(250,50)*EDSCALE); } makedirname->set_text(""); // reset label } @@ -848,7 +849,7 @@ void EditorFileDialog::_make_dir_confirm() { void EditorFileDialog::_make_dir() { - makedialog->popup_centered_minsize(Size2(250,80)); + makedialog->popup_centered_minsize(Size2(250,80)*EDSCALE); makedirname->grab_focus(); } diff --git a/tools/editor/editor_fonts.cpp b/tools/editor/editor_fonts.cpp index e04dce294a7..da947748a41 100644 --- a/tools/editor/editor_fonts.cpp +++ b/tools/editor/editor_fonts.cpp @@ -33,6 +33,8 @@ #include "builtin_fonts.h" #include "editor_settings.h" #include "scene/resources/dynamic_font.h" +#include "editor_scale.h" +#include "scene/resources/default_theme/default_theme.h" static Ref make_font(int p_height,int p_ascent, int p_valign, int p_charcount, const int *p_chars,const Ref &p_texture) { @@ -67,6 +69,7 @@ static Ref make_font(int p_height,int p_ascent, int p_valign, int p_ void editor_register_fonts(Ref p_theme) { + Ref dfd; dfd.instance(); dfd->set_font_ptr(_font_droid_sans,_font_droid_sans_size); @@ -79,7 +82,7 @@ void editor_register_fonts(Ref p_theme) { Ref df; df.instance(); - df->set_size(int(EditorSettings::get_singleton()->get("global/font_size"))); + df->set_size(int(EditorSettings::get_singleton()->get("global/font_size"))*EDSCALE); df->set_font_data(dfd); @@ -91,12 +94,12 @@ void editor_register_fonts(Ref p_theme) { Ref df_title; df_title.instance(); - df_title->set_size(int(EDITOR_DEF("help/help_title_font_size",18))); + df_title->set_size(int(EDITOR_DEF("help/help_title_font_size",18))*EDSCALE); df_title->set_font_data(dfd); Ref df_doc; df_doc.instance(); - df_doc->set_size(int(EDITOR_DEF("help/help_font_size",16))); + df_doc->set_size(int(EDITOR_DEF("help/help_font_size",16))*EDSCALE); df_doc->set_font_data(dfd); p_theme->set_font("doc","EditorFonts",df_doc); @@ -105,16 +108,25 @@ void editor_register_fonts(Ref p_theme) { Ref df_code; df_code.instance(); - df_code->set_size(int(EditorSettings::get_singleton()->get("global/source_font_size"))); + df_code->set_size(int(EditorSettings::get_singleton()->get("global/source_font_size"))*EDSCALE); df_code->set_font_data(dfmono); p_theme->set_font("source","EditorFonts",df_code); Ref df_doc_code; df_doc_code.instance(); - df_doc_code->set_size(int(EDITOR_DEF("help/help_source_font_size",14))); + df_doc_code->set_size(int(EDITOR_DEF("help/help_source_font_size",14))*EDSCALE); df_doc_code->set_font_data(dfmono); + p_theme->set_font("doc_source","EditorFonts",df_doc_code); + if (editor_is_hidpi()) { + //replace default theme + Ref di; + Ref ds; + fill_default_theme(p_theme,df,df_doc,di,ds,true); + + } + } diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp index 8313e38f02b..1a050e59815 100644 --- a/tools/editor/editor_node.cpp +++ b/tools/editor/editor_node.cpp @@ -984,6 +984,7 @@ void EditorNode::_save_scene_with_preview(String p_file) { save.step(TTR("Creating Thumbnail"),3); Image img = VS::get_singleton()->viewport_get_screen_capture(viewport); int preview_size = EditorSettings::get_singleton()->get("file_dialog/thumbnail_size");; + preview_size*=EDSCALE; int width,height; if (img.get_width() > preview_size && img.get_width() >= img.get_height()) { @@ -2389,7 +2390,7 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { confirmation->get_ok()->set_text(TTR("Quit")); //confirmation->get_cancel()->show(); confirmation->set_text(TTR("Exit the editor?")); - confirmation->popup_centered(Size2(180,70)); + confirmation->popup_centered(Size2(180,70)*EDSCALE); break; } @@ -2826,7 +2827,7 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { } break; case SETTINGS_ABOUT: { - about->popup_centered(Size2(500,130)); + about->popup_centered(Size2(500,130)*EDSCALE); } break; case SOURCES_REIMPORT: { @@ -5381,7 +5382,7 @@ EditorNode::EditorNode() { dock_vb->add_child(dock_hb); dock_select = memnew( Control ); - dock_select->set_custom_minimum_size(Size2(128,64)); + dock_select->set_custom_minimum_size(Size2(128,64)*EDSCALE); dock_select->connect("input_event",this,"_dock_select_input"); dock_select->connect("draw",this,"_dock_select_draw"); dock_select->connect("mouse_exit",this,"_dock_popup_exit"); @@ -5396,7 +5397,7 @@ EditorNode::EditorNode() { //dock_select_popoup->set_(Size2(20,20)); for(int i=0;iset_custom_minimum_size(Size2(230,220)); + dock_slot[i]->set_custom_minimum_size(Size2(230,220)*EDSCALE); dock_slot[i]->set_v_size_flags(Control::SIZE_EXPAND_FILL); dock_slot[i]->set_popup(dock_select_popoup); dock_slot[i]->connect("pre_popup_pressed",this,"_dock_pre_popup",varray(i)); @@ -5436,7 +5437,7 @@ EditorNode::EditorNode() { srt->add_child(scene_tabs); scene_root_parent = memnew( PanelContainer ); - scene_root_parent->set_custom_minimum_size(Size2(0,80)); + scene_root_parent->set_custom_minimum_size(Size2(0,80)*EDSCALE); //Ref sp = scene_root_parent->get_stylebox("panel","TabContainer"); @@ -5553,7 +5554,7 @@ EditorNode::EditorNode() { { Control *sp = memnew( Control ); - sp->set_custom_minimum_size(Size2(30,0)); + sp->set_custom_minimum_size(Size2(30,0)*EDSCALE); menu_hb->add_child(sp); } @@ -5742,7 +5743,7 @@ EditorNode::EditorNode() { { Control *sp = memnew( Control ); - sp->set_custom_minimum_size(Size2(30,0)); + sp->set_custom_minimum_size(Size2(30,0)*EDSCALE); menu_hb->add_child(sp); } @@ -5764,7 +5765,7 @@ EditorNode::EditorNode() { { Control *sp = memnew( Control ); - sp->set_custom_minimum_size(Size2(30,0)); + sp->set_custom_minimum_size(Size2(30,0)*EDSCALE); menu_hb->add_child(sp); } @@ -5800,7 +5801,7 @@ EditorNode::EditorNode() { layout_dialog = memnew( EditorNameDialog ); gui_base->add_child(layout_dialog); layout_dialog->set_hide_on_ok(false); - layout_dialog->set_size(Size2(175, 70)); + layout_dialog->set_size(Size2(175, 70)*EDSCALE); layout_dialog->connect("name_confirmed", this,"_dialog_action"); sources_button = memnew( ToolButton ); diff --git a/tools/editor/editor_node.h b/tools/editor/editor_node.h index db589bb1c34..e580931df34 100644 --- a/tools/editor/editor_node.h +++ b/tools/editor/editor_node.h @@ -85,6 +85,7 @@ #include "progress_dialog.h" +#include "editor_scale.h" /** @author Juan Linietsky */ diff --git a/tools/editor/editor_resource_preview.cpp b/tools/editor/editor_resource_preview.cpp index d31cf9e0fdf..13b424c231a 100644 --- a/tools/editor/editor_resource_preview.cpp +++ b/tools/editor/editor_resource_preview.cpp @@ -4,7 +4,7 @@ #include "io/resource_loader.h" #include "io/resource_saver.h" #include "globals.h" - +#include "editor_scale.h" Ref EditorResourcePreviewGenerator::generate_from_path(const String& p_path) { @@ -91,6 +91,7 @@ Ref EditorResourcePreview::_generate_preview(const QueueItem& p_item,co if (generated.is_valid()) { //print_line("was generated"); int thumbnail_size = EditorSettings::get_singleton()->get("file_dialog/thumbnail_size"); + thumbnail_size*=EDSCALE; //wow it generated a preview... save cache ResourceSaver::save(cache_base+".png",generated); FileAccess *f=FileAccess::open(cache_base+".txt",FileAccess::WRITE); @@ -132,6 +133,7 @@ void EditorResourcePreview::_thread() { uint64_t modtime = FileAccess::get_modified_time(item.path); int thumbnail_size = EditorSettings::get_singleton()->get("file_dialog/thumbnail_size"); + thumbnail_size*=EDSCALE; if (cache.has(item.path)) { //already has it because someone loaded it, just let it know it's ready diff --git a/tools/editor/editor_scale.cpp b/tools/editor/editor_scale.cpp new file mode 100644 index 00000000000..ecb1e1816fd --- /dev/null +++ b/tools/editor/editor_scale.cpp @@ -0,0 +1,7 @@ +#include "editor_scale.h" +#include "os/os.h" + +bool editor_is_hidpi() { + + return OS::get_singleton()->get_screen_dpi(0) > 150; +} diff --git a/tools/editor/editor_scale.h b/tools/editor/editor_scale.h new file mode 100644 index 00000000000..0f0e90595c3 --- /dev/null +++ b/tools/editor/editor_scale.h @@ -0,0 +1,8 @@ +#ifndef EDITOR_SCALE_H +#define EDITOR_SCALE_H + + +bool editor_is_hidpi(); + +#define EDSCALE (editor_is_hidpi() ? 2 : 1) +#endif // EDITOR_SCALE_H diff --git a/tools/editor/icons/SCsub b/tools/editor/icons/SCsub index 14d2be66f6e..f3216b092da 100644 --- a/tools/editor/icons/SCsub +++ b/tools/editor/icons/SCsub @@ -11,6 +11,7 @@ def make_editor_icons_action(target, source, env): s = cStringIO.StringIO() s.write("#include \"editor_icons.h\"\n\n") + s.write("#include \"editor_scale.h\"\n\n") s.write("#include \"scene/resources/theme.h\"\n\n") for x in pixmaps: @@ -36,7 +37,7 @@ def make_editor_icons_action(target, source, env): s.write("static Ref make_icon(const uint8_t* p_png) {\n") s.write("\tRef texture( memnew( ImageTexture ) );\n") s.write("\tImage img(p_png);\n") - #s.write("\timg.expand_x2_hq2x();\n") + s.write("\tif (editor_is_hidpi()) img.expand_x2_hq2x();\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/io_plugins/editor_font_import_plugin.cpp b/tools/editor/io_plugins/editor_font_import_plugin.cpp index f4d6af7e108..d5e6e3077ee 100644 --- a/tools/editor/io_plugins/editor_font_import_plugin.cpp +++ b/tools/editor/io_plugins/editor_font_import_plugin.cpp @@ -510,13 +510,13 @@ class EditorFontImportDialog : public ConfirmationDialog { if (source->get_line_edit()->get_text()=="") { error_dialog->set_text(TTR("No source font file!")); - error_dialog->popup_centered(Size2(200,100)); + error_dialog->popup_centered(Size2(200,100)*EDSCALE); return; } if (dest->get_line_edit()->get_text()=="") { error_dialog->set_text(TTR("No target font resource!")); - error_dialog->popup_centered(Size2(200,100)); + error_dialog->popup_centered(Size2(200,100)*EDSCALE); return; } @@ -528,7 +528,7 @@ class EditorFontImportDialog : public ConfirmationDialog { if (rimd.is_null()) { error_dialog->set_text(TTR("Can't load/process source font.")); - error_dialog->popup_centered(Size2(200,100)); + error_dialog->popup_centered(Size2(200,100)*EDSCALE); return; } @@ -536,7 +536,7 @@ class EditorFontImportDialog : public ConfirmationDialog { if (err!=OK) { error_dialog->set_text(TTR("Couldn't save font.")); - error_dialog->popup_centered(Size2(200,100)); + error_dialog->popup_centered(Size2(200,100)*EDSCALE); return; } @@ -573,7 +573,7 @@ public: void popup_import(const String& p_path) { - popup_centered(Size2(600,500)); + popup_centered(Size2(600,500)*EDSCALE); if (p_path!="") { diff --git a/tools/editor/io_plugins/editor_mesh_import_plugin.cpp b/tools/editor/io_plugins/editor_mesh_import_plugin.cpp index 45da42969c7..c20515f0f30 100644 --- a/tools/editor/io_plugins/editor_mesh_import_plugin.cpp +++ b/tools/editor/io_plugins/editor_mesh_import_plugin.cpp @@ -173,7 +173,7 @@ public: void popup_import(const String& p_path) { - popup_centered(Size2(400,400)); + popup_centered(Size2(400,400)*EDSCALE); if (p_path!="") { diff --git a/tools/editor/io_plugins/editor_sample_import_plugin.cpp b/tools/editor/io_plugins/editor_sample_import_plugin.cpp index 120bdc6f44f..ac0795f522d 100644 --- a/tools/editor/io_plugins/editor_sample_import_plugin.cpp +++ b/tools/editor/io_plugins/editor_sample_import_plugin.cpp @@ -221,7 +221,7 @@ public: void popup_import(const String& p_path) { - popup_centered(Size2(400,400)); + popup_centered(Size2(400,400)*EDSCALE); if (p_path!="") { Ref rimd = ResourceLoader::load_import_metadata(p_path); @@ -252,7 +252,7 @@ public: if (samples.size()==0) { error_dialog->set_text(TTR("No samples to import!")); - error_dialog->popup_centered(Size2(200,100)); + error_dialog->popup_centered(Size2(200,100)*EDSCALE); } if (save_path->get_text().strip_edges()=="") { @@ -293,7 +293,7 @@ public: String dst = save_path->get_text(); if (dst=="") { error_dialog->set_text(TTR("Save path is empty!")); - error_dialog->popup_centered(Size2(200,100)); + error_dialog->popup_centered(Size2(200,100)*EDSCALE); } dst = dst.plus_file(samples[i].get_file().basename()+".smp"); diff --git a/tools/editor/io_plugins/editor_scene_import_plugin.cpp b/tools/editor/io_plugins/editor_scene_import_plugin.cpp index 3effb1d0aa4..41dfb748fc8 100644 --- a/tools/editor/io_plugins/editor_scene_import_plugin.cpp +++ b/tools/editor/io_plugins/editor_scene_import_plugin.cpp @@ -674,7 +674,7 @@ void EditorSceneImportDialog::_open_and_import() { if (unsaved) { - confirm_open->popup_centered_minsize(Size2(300,80)); + confirm_open->popup_centered_minsize(Size2(300,80)*EDSCALE); } else { _import(true); } @@ -735,7 +735,7 @@ void EditorSceneImportDialog::_import(bool p_and_open) { Ref