From 2208fc06321d476f5c7066de9bc538bba6f94dcd Mon Sep 17 00:00:00 2001 From: Gregor Parzefall Date: Fri, 6 Sep 2024 21:05:38 +0200 Subject: [PATCH] Move Minetest GUISkin -> Irrlicht CGUISkin --- irr/include/IGUISkin.h | 8 +++ src/gui/guiSkin.cpp => irr/src/CGUISkin.cpp | 56 +++++++++---------- src/gui/guiSkin.h => irr/src/CGUISkin.h | 60 ++------------------- src/client/renderingengine.cpp | 27 ---------- src/gui/CMakeLists.txt | 1 - src/gui/guiButton.cpp | 4 +- src/gui/guiButton.h | 1 - 7 files changed, 42 insertions(+), 115 deletions(-) rename src/gui/guiSkin.cpp => irr/src/CGUISkin.cpp (94%) rename src/gui/guiSkin.h => irr/src/CGUISkin.h (89%) diff --git a/irr/include/IGUISkin.h b/irr/include/IGUISkin.h index 36b510606..b323983ae 100644 --- a/irr/include/IGUISkin.h +++ b/irr/include/IGUISkin.h @@ -437,6 +437,10 @@ public: virtual void draw3DButtonPaneStandard(IGUIElement *element, const core::rect &rect, const core::rect *clip = 0) = 0; + virtual void drawColored3DButtonPaneStandard(IGUIElement* element, + const core::rect& rect, + const core::rect* clip=0, + const video::SColor* colors=0) = 0; //! draws a pressed 3d button pane /** Used for drawing for example buttons in pressed state. @@ -450,6 +454,10 @@ public: virtual void draw3DButtonPanePressed(IGUIElement *element, const core::rect &rect, const core::rect *clip = 0) = 0; + virtual void drawColored3DButtonPanePressed(IGUIElement* element, + const core::rect& rect, + const core::rect* clip=0, + const video::SColor* colors=0) = 0; //! draws a sunken 3d pane /** Used for drawing the background of edit, combo or check boxes. diff --git a/src/gui/guiSkin.cpp b/irr/src/CGUISkin.cpp similarity index 94% rename from src/gui/guiSkin.cpp rename to irr/src/CGUISkin.cpp index 0ecc80f02..e9721a5fa 100644 --- a/src/gui/guiSkin.cpp +++ b/irr/src/CGUISkin.cpp @@ -4,7 +4,7 @@ // This file is part of the "Irrlicht Engine". // For conditions of distribution and use, see copyright notice in irrlicht.h -#include "guiSkin.h" +#include "CGUISkin.h" #include "IGUIFont.h" #include "IGUISpriteBank.h" @@ -17,11 +17,11 @@ namespace irr namespace gui { -GUISkin::GUISkin(EGUI_SKIN_TYPE type, video::IVideoDriver* driver) +CGUISkin::CGUISkin(EGUI_SKIN_TYPE type, video::IVideoDriver* driver) : SpriteBank(0), Driver(driver), Type(type) { #ifdef _DEBUG - setDebugName("GUISkin"); + setDebugName("CGUISkin"); #endif if ((Type == EGST_WINDOWS_CLASSIC) || (Type == EGST_WINDOWS_METALLIC)) @@ -167,7 +167,7 @@ GUISkin::GUISkin(EGUI_SKIN_TYPE type, video::IVideoDriver* driver) //! destructor -GUISkin::~GUISkin() +CGUISkin::~CGUISkin() { for (u32 i=0; i= EGDF_COUNT) return; @@ -244,14 +244,14 @@ void GUISkin::setFont(IGUIFont* font, EGUI_DEFAULT_FONT which) //! gets the sprite bank stored -IGUISpriteBank* GUISkin::getSpriteBank() const +IGUISpriteBank* CGUISkin::getSpriteBank() const { return SpriteBank; } //! set a new sprite bank or remove one by passing 0 -void GUISkin::setSpriteBank(IGUISpriteBank* bank) +void CGUISkin::setSpriteBank(IGUISpriteBank* bank) { if (bank) bank->grab(); @@ -264,7 +264,7 @@ void GUISkin::setSpriteBank(IGUISpriteBank* bank) //! Returns a default icon -u32 GUISkin::getIcon(EGUI_DEFAULT_ICON icon) const +u32 CGUISkin::getIcon(EGUI_DEFAULT_ICON icon) const { if ((u32)icon < EGDI_COUNT) return Icons[icon]; @@ -274,7 +274,7 @@ u32 GUISkin::getIcon(EGUI_DEFAULT_ICON icon) const //! Sets a default icon -void GUISkin::setIcon(EGUI_DEFAULT_ICON icon, u32 index) +void CGUISkin::setIcon(EGUI_DEFAULT_ICON icon, u32 index) { if ((u32)icon < EGDI_COUNT) Icons[icon] = index; @@ -283,7 +283,7 @@ void GUISkin::setIcon(EGUI_DEFAULT_ICON icon, u32 index) //! Returns a default text. For example for Message box button captions: //! "OK", "Cancel", "Yes", "No" and so on. -const wchar_t* GUISkin::getDefaultText(EGUI_DEFAULT_TEXT text) const +const wchar_t* CGUISkin::getDefaultText(EGUI_DEFAULT_TEXT text) const { if ((u32)text < EGDT_COUNT) return Texts[text].c_str(); @@ -294,7 +294,7 @@ const wchar_t* GUISkin::getDefaultText(EGUI_DEFAULT_TEXT text) const //! Sets a default text. For example for Message box button captions: //! "OK", "Cancel", "Yes", "No" and so on. -void GUISkin::setDefaultText(EGUI_DEFAULT_TEXT which, const wchar_t* newText) +void CGUISkin::setDefaultText(EGUI_DEFAULT_TEXT which, const wchar_t* newText) { if ((u32)which < EGDT_COUNT) Texts[which] = newText; @@ -311,7 +311,7 @@ EGDC_3D_FACE for this. See EGUI_DEFAULT_COLOR for details. is usually not used by ISkin, but can be used for example by more complex implementations to find out how to draw the part exactly. */ // PATCH -void GUISkin::drawColored3DButtonPaneStandard(IGUIElement* element, +void CGUISkin::drawColored3DButtonPaneStandard(IGUIElement* element, const core::rect& r, const core::rect* clip, const video::SColor* colors) @@ -373,7 +373,7 @@ EGDC_3D_FACE for this. See EGUI_DEFAULT_COLOR for details. is usually not used by ISkin, but can be used for example by more complex implementations to find out how to draw the part exactly. */ // PATCH -void GUISkin::drawColored3DButtonPanePressed(IGUIElement* element, +void CGUISkin::drawColored3DButtonPanePressed(IGUIElement* element, const core::rect& r, const core::rect* clip, const video::SColor* colors) @@ -423,7 +423,7 @@ deep into the ground. \param rect: Defining area where to draw. \param clip: Clip area. */ // PATCH -void GUISkin::drawColored3DSunkenPane(IGUIElement* element, video::SColor bgcolor, +void CGUISkin::drawColored3DSunkenPane(IGUIElement* element, video::SColor bgcolor, bool flat, bool fillBackGround, const core::rect& r, const core::rect* clip, @@ -512,7 +512,7 @@ void GUISkin::drawColored3DSunkenPane(IGUIElement* element, video::SColor bgcolo //! draws a window background // return where to draw title bar text. // PATCH -core::rect GUISkin::drawColored3DWindowBackground(IGUIElement* element, +core::rect CGUISkin::drawColored3DWindowBackground(IGUIElement* element, bool drawTitleBar, video::SColor titleBarColor, const core::rect& r, const core::rect* clip, @@ -667,7 +667,7 @@ implementations to find out how to draw the part exactly. \param rect: Defining area where to draw. \param clip: Clip area. */ // PATCH -void GUISkin::drawColored3DMenuPane(IGUIElement* element, +void CGUISkin::drawColored3DMenuPane(IGUIElement* element, const core::rect& r, const core::rect* clip, const video::SColor* colors) { @@ -751,7 +751,7 @@ implementations to find out how to draw the part exactly. \param rect: Defining area where to draw. \param clip: Clip area. */ // PATCH -void GUISkin::drawColored3DToolBar(IGUIElement* element, +void CGUISkin::drawColored3DToolBar(IGUIElement* element, const core::rect& r, const core::rect* clip, const video::SColor* colors) @@ -804,7 +804,7 @@ implementations to find out how to draw the part exactly. \param rect: Defining area where to draw. \param clip: Clip area. */ // PATCH -void GUISkin::drawColored3DTabButton(IGUIElement* element, bool active, +void CGUISkin::drawColored3DTabButton(IGUIElement* element, bool active, const core::rect& frameRect, const core::rect* clip, EGUI_ALIGNMENT alignment, const video::SColor* colors) { @@ -891,7 +891,7 @@ implementations to find out how to draw the part exactly. \param rect: Defining area where to draw. \param clip: Clip area. */ // PATCH -void GUISkin::drawColored3DTabBody(IGUIElement* element, bool border, bool background, +void CGUISkin::drawColored3DTabBody(IGUIElement* element, bool border, bool background, const core::rect& rect, const core::rect* clip, s32 tabHeight, EGUI_ALIGNMENT alignment, const video::SColor* colors) { @@ -989,7 +989,7 @@ by more complex implementations to find out how to draw the part exactly. \param loop: Whether the animation should loop or not \param clip: Clip area. */ // PATCH -void GUISkin::drawColoredIcon(IGUIElement* element, EGUI_DEFAULT_ICON icon, +void CGUISkin::drawColoredIcon(IGUIElement* element, EGUI_DEFAULT_ICON icon, const core::position2di position, u32 starttime, u32 currenttime, bool loop, const core::rect* clip, @@ -1008,14 +1008,14 @@ void GUISkin::drawColoredIcon(IGUIElement* element, EGUI_DEFAULT_ICON icon, // END PATCH -EGUI_SKIN_TYPE GUISkin::getType() const +EGUI_SKIN_TYPE CGUISkin::getType() const { return Type; } //! draws a 2d rectangle. -void GUISkin::draw2DRectangle(IGUIElement* element, +void CGUISkin::draw2DRectangle(IGUIElement* element, const video::SColor &color, const core::rect& pos, const core::rect* clip) { @@ -1025,7 +1025,7 @@ void GUISkin::draw2DRectangle(IGUIElement* element, //! gets the colors // PATCH -void GUISkin::getColors(video::SColor* colors) +void CGUISkin::getColors(video::SColor* colors) { u32 i; for (i=0; isetColor(EGDC_3D_FACE, button_color); \ - skin->setColor(EGDC_3D_DARK_SHADOW, button_color, 0.25f); \ - skin->setColor(EGDC_3D_SHADOW, button_color, 0.5f); \ - skin->setColor(EGDC_3D_LIGHT, button_color); \ - skin->setColor(EGDC_3D_HIGH_LIGHT, button_color, 1.5f); \ - } - - #define getElementSkinColor(color) \ - { \ - if (!Colors) \ - { \ - IGUISkin* skin = Environment->getSkin(); \ - if (skin) \ - return skin->getColor(color); \ - } \ - return Colors[color]; \ - } - - #define setElementSkinColor(which, newColor, shading) \ - { \ - if (!Colors) \ - { \ - Colors = new video::SColor[EGDC_COUNT]; \ - GUISkin* skin = (GUISkin *)Environment->getSkin(); \ - if (skin) \ - skin->getColors(Colors); \ - } \ - Colors[which] = newColor; \ - setShading(Colors[which],shading); \ - } } // end namespace gui -//! Sets the shading -inline void setShading(video::SColor &color,f32 s) // :PATCH: -{ - if (s < 1.0f) - { - color.setRed(color.getRed() * s); - color.setGreen(color.getGreen() * s); - color.setBlue(color.getBlue() * s); - } - else if (s > 1.0f) - { - s -= 1.0f; - - color.setRed(color.getRed() + (255 - color.getRed()) * s); - color.setGreen(color.getGreen() + (255 - color.getGreen()) * s); - color.setBlue(color.getBlue() + (255 - color.getBlue()) * s); - } -} } // end namespace irr -#endif diff --git a/src/client/renderingengine.cpp b/src/client/renderingengine.cpp index 4400dd90e..c4933e062 100644 --- a/src/client/renderingengine.cpp +++ b/src/client/renderingengine.cpp @@ -36,7 +36,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "inputhandler.h" #include "gettext.h" #include "filesys.h" -#include "../gui/guiSkin.h" #include "irrlicht_changes/static_text.h" #include "irr_ptr.h" @@ -126,27 +125,6 @@ IShaderConstantSetter *FogShaderConstantSetterFactory::create() /* Other helpers */ -static gui::GUISkin *createSkin(gui::IGUIEnvironment *environment, - gui::EGUI_SKIN_TYPE type, video::IVideoDriver *driver) -{ - gui::GUISkin *skin = new gui::GUISkin(type, driver); - - gui::IGUIFont *builtinfont = environment->getBuiltInFont(); - gui::IGUIFontBitmap *bitfont = nullptr; - if (builtinfont && builtinfont->getType() == gui::EGFT_BITMAP) - bitfont = (gui::IGUIFontBitmap*)builtinfont; - - gui::IGUISpriteBank *bank = 0; - skin->setFont(builtinfont); - - if (bitfont) - bank = bitfont->getSpriteBank(); - - skin->setSpriteBank(bank); - - return skin; -} - static std::optional chooseVideoDriver() { auto &&configured_name = g_settings->get("video_driver"); @@ -250,11 +228,6 @@ RenderingEngine::RenderingEngine(IEventReceiver *receiver) s_singleton = this; - auto skin = createSkin(m_device->getGUIEnvironment(), - gui::EGST_WINDOWS_METALLIC, driver); - m_device->getGUIEnvironment()->setSkin(skin); - skin->drop(); - g_settings->registerChangedCallback("fullscreen", settingChangedCallback, this); g_settings->registerChangedCallback("window_maximized", settingChangedCallback, this); } diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 73bbecb02..04a03609d 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -19,7 +19,6 @@ set(gui_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/guiScene.cpp ${CMAKE_CURRENT_SOURCE_DIR}/guiScrollBar.cpp ${CMAKE_CURRENT_SOURCE_DIR}/guiScrollContainer.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/guiSkin.cpp ${CMAKE_CURRENT_SOURCE_DIR}/guiTable.cpp ${CMAKE_CURRENT_SOURCE_DIR}/guiHyperText.cpp ${CMAKE_CURRENT_SOURCE_DIR}/guiVolumeChange.cpp diff --git a/src/gui/guiButton.cpp b/src/gui/guiButton.cpp index d78433edd..9592ba922 100644 --- a/src/gui/guiButton.cpp +++ b/src/gui/guiButton.cpp @@ -253,8 +253,8 @@ void GUIButton::draw() setFromState(); } - GUISkin* skin = dynamic_cast(Environment->getSkin()); video::IVideoDriver* driver = Environment->getVideoDriver(); + IGUISkin *skin = Environment->getSkin(); // END PATCH if (DrawBorder) @@ -737,7 +737,7 @@ void GUIButton::setFromStyle(const StyleSpec& style) Padding.UpperLeftCorner + BgMiddle.UpperLeftCorner, Padding.LowerRightCorner + BgMiddle.LowerRightCorner); - GUISkin* skin = dynamic_cast(Environment->getSkin()); + IGUISkin *skin = Environment->getSkin(); core::vector2d defaultPressOffset( skin->getSize(irr::gui::EGDS_BUTTON_PRESSED_IMAGE_OFFSET_X), skin->getSize(irr::gui::EGDS_BUTTON_PRESSED_IMAGE_OFFSET_Y)); diff --git a/src/gui/guiButton.h b/src/gui/guiButton.h index 4fad8747c..dd71788ba 100644 --- a/src/gui/guiButton.h +++ b/src/gui/guiButton.h @@ -10,7 +10,6 @@ #include "IGUISpriteBank.h" #include "ITexture.h" #include "SColor.h" -#include "guiSkin.h" #include "StyleSpec.h" using namespace irr;