From f19a76ff3e39bc868951fd2c237ddbdc8369c345 Mon Sep 17 00:00:00 2001 From: Maksim Date: Mon, 28 Mar 2022 11:12:08 +0200 Subject: [PATCH] Few improvements to GUI scaling Co-Authored-By: Vitaliy --- src/client/clientlauncher.cpp | 34 +++++++----------- src/gui/guiSkin.cpp | 11 ++++++ .../pack/{checkbox_64.png => checkbox.png} | Bin textures/base/pack/checkbox_16.png | Bin 125 -> 0 bytes textures/base/pack/checkbox_32.png | Bin 174 -> 0 bytes 5 files changed, 24 insertions(+), 21 deletions(-) rename textures/base/pack/{checkbox_64.png => checkbox.png} (100%) delete mode 100644 textures/base/pack/checkbox_16.png delete mode 100644 textures/base/pack/checkbox_32.png diff --git a/src/client/clientlauncher.cpp b/src/client/clientlauncher.cpp index 64bb95837..fa6b8dd17 100644 --- a/src/client/clientlauncher.cpp +++ b/src/client/clientlauncher.cpp @@ -158,31 +158,23 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args) skin->setColor(gui::EGDC_3D_SHADOW, video::SColor(255, 0, 0, 0)); skin->setColor(gui::EGDC_HIGH_LIGHT, video::SColor(255, 70, 120, 50)); skin->setColor(gui::EGDC_HIGH_LIGHT_TEXT, video::SColor(255, 255, 255, 255)); -#ifdef HAVE_TOUCHSCREENGUI - float density = RenderingEngine::getDisplayDensity(); - skin->setSize(gui::EGDS_CHECK_BOX_WIDTH, (s32)(17.0f * density)); + float density = RenderingEngine::getDisplayDensity() * g_settings->getFloat("gui_scaling"); + skin->setSize(gui::EGDS_CHECK_BOX_WIDTH, (s32)(18.0f * density)); skin->setSize(gui::EGDS_SCROLLBAR_SIZE, (s32)(14.0f * density)); skin->setSize(gui::EGDS_WINDOW_BUTTON_WIDTH, (s32)(15.0f * density)); - if (density > 1.5f) { - std::string sprite_path = porting::path_share + DIR_DELIM + "textures" - + DIR_DELIM + "base" + DIR_DELIM + "pack" + DIR_DELIM; - if (density > 3.5f) - sprite_path.append("checkbox_64.png"); - else if (density > 2.0f) - sprite_path.append("checkbox_32.png"); - else - sprite_path.append("checkbox_16.png"); - // Texture dimensions should be a power of 2 - gui::IGUISpriteBank *sprites = skin->getSpriteBank(); - video::IVideoDriver *driver = RenderingEngine::get_video_driver(); - video::ITexture *sprite_texture = driver->getTexture(sprite_path.c_str()); - if (sprite_texture) { - s32 sprite_id = sprites->addTextureAsSprite(sprite_texture); - if (sprite_id != -1) - skin->setIcon(gui::EGDI_CHECK_BOX_CHECKED, sprite_id); - } +#if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR >= 9 + // Load check icon for the checkbox + // TODO other icons + std::string sprite_path = porting::path_share + DIR_DELIM + "textures" + + DIR_DELIM + "base" + DIR_DELIM + "pack" + DIR_DELIM + "checkbox.png"; + if (auto *sprite_texture = RenderingEngine::get_video_driver()->getTexture(sprite_path.c_str())) { + auto *sprites = skin->getSpriteBank(); + s32 sprite_id = sprites->addTextureAsSprite(sprite_texture); + if (sprite_id != -1) + skin->setIcon(gui::EGDI_CHECK_BOX_CHECKED, sprite_id); } #endif + g_fontengine = new FontEngine(guienv); FATAL_ERROR_IF(g_fontengine == NULL, "Font engine creation failed."); diff --git a/src/gui/guiSkin.cpp b/src/gui/guiSkin.cpp index 8892a00b4..1cb4b52c2 100644 --- a/src/gui/guiSkin.cpp +++ b/src/gui/guiSkin.cpp @@ -1003,6 +1003,17 @@ void GUISkin::drawColoredIcon(IGUIElement* element, EGUI_DEFAULT_ICON icon, colors = Colors; bool gray = element && !element->isEnabled(); +#if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR >= 9 + if (icon == EGDI_CHECK_BOX_CHECKED) { + // Scale checkbox check specifically + // TODO other icons + int radius = getSize(EGDS_CHECK_BOX_WIDTH) * .38; + core::recti rect{position.X - radius, position.Y - radius, position.X + radius, position.Y + radius}; + SpriteBank->draw2DSprite(Icons[icon], rect, 0, + &colors[gray? EGDC_GRAY_WINDOW_SYMBOL : EGDC_WINDOW_SYMBOL], currenttime - starttime, loop); + return; + } +#endif SpriteBank->draw2DSprite(Icons[icon], position, clip, colors[gray? EGDC_GRAY_WINDOW_SYMBOL : EGDC_WINDOW_SYMBOL], starttime, currenttime, loop, true); } diff --git a/textures/base/pack/checkbox_64.png b/textures/base/pack/checkbox.png similarity index 100% rename from textures/base/pack/checkbox_64.png rename to textures/base/pack/checkbox.png diff --git a/textures/base/pack/checkbox_16.png b/textures/base/pack/checkbox_16.png deleted file mode 100644 index d56d935be075aab6c9ff0423aff90c41e8231b00..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 125 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!60wlNoGJgf6Ts&PILn;`P7syVSG}%sJU5o#( zbywk4UrJgR1Ar*{oE^TCVFc4{Z$isL; zjDdmKy^O;tfzY34!^Lh@w39WeM;XZ4v&~l*%Axtu}C)zdt-!tRmpNiVaGOuS> z{&@OJ%~Hs_?y0lrY2~E)F9}?J^;SI(87KUgESfo