Move Minetest GUISkin -> Irrlicht CGUISkin

This commit is contained in:
Gregor Parzefall 2024-09-06 21:05:38 +02:00 committed by sfan5
parent c8ebc2e5d0
commit 2208fc0632
7 changed files with 42 additions and 115 deletions

@ -437,6 +437,10 @@ public:
virtual void draw3DButtonPaneStandard(IGUIElement *element, virtual void draw3DButtonPaneStandard(IGUIElement *element,
const core::rect<s32> &rect, const core::rect<s32> &rect,
const core::rect<s32> *clip = 0) = 0; const core::rect<s32> *clip = 0) = 0;
virtual void drawColored3DButtonPaneStandard(IGUIElement* element,
const core::rect<s32>& rect,
const core::rect<s32>* clip=0,
const video::SColor* colors=0) = 0;
//! draws a pressed 3d button pane //! draws a pressed 3d button pane
/** Used for drawing for example buttons in pressed state. /** Used for drawing for example buttons in pressed state.
@ -450,6 +454,10 @@ public:
virtual void draw3DButtonPanePressed(IGUIElement *element, virtual void draw3DButtonPanePressed(IGUIElement *element,
const core::rect<s32> &rect, const core::rect<s32> &rect,
const core::rect<s32> *clip = 0) = 0; const core::rect<s32> *clip = 0) = 0;
virtual void drawColored3DButtonPanePressed(IGUIElement* element,
const core::rect<s32>& rect,
const core::rect<s32>* clip=0,
const video::SColor* colors=0) = 0;
//! draws a sunken 3d pane //! draws a sunken 3d pane
/** Used for drawing the background of edit, combo or check boxes. /** Used for drawing the background of edit, combo or check boxes.

@ -4,7 +4,7 @@
// This file is part of the "Irrlicht Engine". // This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h // For conditions of distribution and use, see copyright notice in irrlicht.h
#include "guiSkin.h" #include "CGUISkin.h"
#include "IGUIFont.h" #include "IGUIFont.h"
#include "IGUISpriteBank.h" #include "IGUISpriteBank.h"
@ -17,11 +17,11 @@ namespace irr
namespace gui 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) : SpriteBank(0), Driver(driver), Type(type)
{ {
#ifdef _DEBUG #ifdef _DEBUG
setDebugName("GUISkin"); setDebugName("CGUISkin");
#endif #endif
if ((Type == EGST_WINDOWS_CLASSIC) || (Type == EGST_WINDOWS_METALLIC)) if ((Type == EGST_WINDOWS_CLASSIC) || (Type == EGST_WINDOWS_METALLIC))
@ -167,7 +167,7 @@ GUISkin::GUISkin(EGUI_SKIN_TYPE type, video::IVideoDriver* driver)
//! destructor //! destructor
GUISkin::~GUISkin() CGUISkin::~CGUISkin()
{ {
for (u32 i=0; i<EGDF_COUNT; ++i) for (u32 i=0; i<EGDF_COUNT; ++i)
{ {
@ -181,7 +181,7 @@ GUISkin::~GUISkin()
//! returns default color //! returns default color
video::SColor GUISkin::getColor(EGUI_DEFAULT_COLOR color) const video::SColor CGUISkin::getColor(EGUI_DEFAULT_COLOR color) const
{ {
if ((u32)color < EGDC_COUNT) if ((u32)color < EGDC_COUNT)
return Colors[color]; return Colors[color];
@ -191,7 +191,7 @@ video::SColor GUISkin::getColor(EGUI_DEFAULT_COLOR color) const
//! sets a default color //! sets a default color
void GUISkin::setColor(EGUI_DEFAULT_COLOR which, video::SColor newColor) void CGUISkin::setColor(EGUI_DEFAULT_COLOR which, video::SColor newColor)
{ {
if ((u32)which < EGDC_COUNT) if ((u32)which < EGDC_COUNT)
Colors[which] = newColor; Colors[which] = newColor;
@ -199,7 +199,7 @@ void GUISkin::setColor(EGUI_DEFAULT_COLOR which, video::SColor newColor)
//! returns size for the given size type //! returns size for the given size type
s32 GUISkin::getSize(EGUI_DEFAULT_SIZE size) const s32 CGUISkin::getSize(EGUI_DEFAULT_SIZE size) const
{ {
if ((u32)size < EGDS_COUNT) if ((u32)size < EGDS_COUNT)
return Sizes[size]; return Sizes[size];
@ -209,7 +209,7 @@ s32 GUISkin::getSize(EGUI_DEFAULT_SIZE size) const
//! sets a default size //! sets a default size
void GUISkin::setSize(EGUI_DEFAULT_SIZE which, s32 size) void CGUISkin::setSize(EGUI_DEFAULT_SIZE which, s32 size)
{ {
if ((u32)which < EGDS_COUNT) if ((u32)which < EGDS_COUNT)
Sizes[which] = size; Sizes[which] = size;
@ -217,7 +217,7 @@ void GUISkin::setSize(EGUI_DEFAULT_SIZE which, s32 size)
//! returns the default font //! returns the default font
IGUIFont* GUISkin::getFont(EGUI_DEFAULT_FONT which) const IGUIFont* CGUISkin::getFont(EGUI_DEFAULT_FONT which) const
{ {
if (((u32)which < EGDF_COUNT) && Fonts[which]) if (((u32)which < EGDF_COUNT) && Fonts[which])
return Fonts[which]; return Fonts[which];
@ -227,7 +227,7 @@ IGUIFont* GUISkin::getFont(EGUI_DEFAULT_FONT which) const
//! sets a default font //! sets a default font
void GUISkin::setFont(IGUIFont* font, EGUI_DEFAULT_FONT which) void CGUISkin::setFont(IGUIFont* font, EGUI_DEFAULT_FONT which)
{ {
if ((u32)which >= EGDF_COUNT) if ((u32)which >= EGDF_COUNT)
return; return;
@ -244,14 +244,14 @@ void GUISkin::setFont(IGUIFont* font, EGUI_DEFAULT_FONT which)
//! gets the sprite bank stored //! gets the sprite bank stored
IGUISpriteBank* GUISkin::getSpriteBank() const IGUISpriteBank* CGUISkin::getSpriteBank() const
{ {
return SpriteBank; return SpriteBank;
} }
//! set a new sprite bank or remove one by passing 0 //! set a new sprite bank or remove one by passing 0
void GUISkin::setSpriteBank(IGUISpriteBank* bank) void CGUISkin::setSpriteBank(IGUISpriteBank* bank)
{ {
if (bank) if (bank)
bank->grab(); bank->grab();
@ -264,7 +264,7 @@ void GUISkin::setSpriteBank(IGUISpriteBank* bank)
//! Returns a default icon //! 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) if ((u32)icon < EGDI_COUNT)
return Icons[icon]; return Icons[icon];
@ -274,7 +274,7 @@ u32 GUISkin::getIcon(EGUI_DEFAULT_ICON icon) const
//! Sets a default icon //! 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) if ((u32)icon < EGDI_COUNT)
Icons[icon] = index; 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: //! Returns a default text. For example for Message box button captions:
//! "OK", "Cancel", "Yes", "No" and so on. //! "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) if ((u32)text < EGDT_COUNT)
return Texts[text].c_str(); 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: //! Sets a default text. For example for Message box button captions:
//! "OK", "Cancel", "Yes", "No" and so on. //! "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) if ((u32)which < EGDT_COUNT)
Texts[which] = newText; 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 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. */ implementations to find out how to draw the part exactly. */
// PATCH // PATCH
void GUISkin::drawColored3DButtonPaneStandard(IGUIElement* element, void CGUISkin::drawColored3DButtonPaneStandard(IGUIElement* element,
const core::rect<s32>& r, const core::rect<s32>& r,
const core::rect<s32>* clip, const core::rect<s32>* clip,
const video::SColor* colors) 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 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. */ implementations to find out how to draw the part exactly. */
// PATCH // PATCH
void GUISkin::drawColored3DButtonPanePressed(IGUIElement* element, void CGUISkin::drawColored3DButtonPanePressed(IGUIElement* element,
const core::rect<s32>& r, const core::rect<s32>& r,
const core::rect<s32>* clip, const core::rect<s32>* clip,
const video::SColor* colors) const video::SColor* colors)
@ -423,7 +423,7 @@ deep into the ground.
\param rect: Defining area where to draw. \param rect: Defining area where to draw.
\param clip: Clip area. */ \param clip: Clip area. */
// PATCH // PATCH
void GUISkin::drawColored3DSunkenPane(IGUIElement* element, video::SColor bgcolor, void CGUISkin::drawColored3DSunkenPane(IGUIElement* element, video::SColor bgcolor,
bool flat, bool fillBackGround, bool flat, bool fillBackGround,
const core::rect<s32>& r, const core::rect<s32>& r,
const core::rect<s32>* clip, const core::rect<s32>* clip,
@ -512,7 +512,7 @@ void GUISkin::drawColored3DSunkenPane(IGUIElement* element, video::SColor bgcolo
//! draws a window background //! draws a window background
// return where to draw title bar text. // return where to draw title bar text.
// PATCH // PATCH
core::rect<s32> GUISkin::drawColored3DWindowBackground(IGUIElement* element, core::rect<s32> CGUISkin::drawColored3DWindowBackground(IGUIElement* element,
bool drawTitleBar, video::SColor titleBarColor, bool drawTitleBar, video::SColor titleBarColor,
const core::rect<s32>& r, const core::rect<s32>& r,
const core::rect<s32>* clip, const core::rect<s32>* clip,
@ -667,7 +667,7 @@ implementations to find out how to draw the part exactly.
\param rect: Defining area where to draw. \param rect: Defining area where to draw.
\param clip: Clip area. */ \param clip: Clip area. */
// PATCH // PATCH
void GUISkin::drawColored3DMenuPane(IGUIElement* element, void CGUISkin::drawColored3DMenuPane(IGUIElement* element,
const core::rect<s32>& r, const core::rect<s32>* clip, const core::rect<s32>& r, const core::rect<s32>* clip,
const video::SColor* colors) 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 rect: Defining area where to draw.
\param clip: Clip area. */ \param clip: Clip area. */
// PATCH // PATCH
void GUISkin::drawColored3DToolBar(IGUIElement* element, void CGUISkin::drawColored3DToolBar(IGUIElement* element,
const core::rect<s32>& r, const core::rect<s32>& r,
const core::rect<s32>* clip, const core::rect<s32>* clip,
const video::SColor* colors) 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 rect: Defining area where to draw.
\param clip: Clip area. */ \param clip: Clip area. */
// PATCH // PATCH
void GUISkin::drawColored3DTabButton(IGUIElement* element, bool active, void CGUISkin::drawColored3DTabButton(IGUIElement* element, bool active,
const core::rect<s32>& frameRect, const core::rect<s32>* clip, EGUI_ALIGNMENT alignment, const core::rect<s32>& frameRect, const core::rect<s32>* clip, EGUI_ALIGNMENT alignment,
const video::SColor* colors) 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 rect: Defining area where to draw.
\param clip: Clip area. */ \param clip: Clip area. */
// PATCH // PATCH
void GUISkin::drawColored3DTabBody(IGUIElement* element, bool border, bool background, void CGUISkin::drawColored3DTabBody(IGUIElement* element, bool border, bool background,
const core::rect<s32>& rect, const core::rect<s32>* clip, s32 tabHeight, EGUI_ALIGNMENT alignment, const core::rect<s32>& rect, const core::rect<s32>* clip, s32 tabHeight, EGUI_ALIGNMENT alignment,
const video::SColor* colors) 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 loop: Whether the animation should loop or not
\param clip: Clip area. */ \param clip: Clip area. */
// PATCH // PATCH
void GUISkin::drawColoredIcon(IGUIElement* element, EGUI_DEFAULT_ICON icon, void CGUISkin::drawColoredIcon(IGUIElement* element, EGUI_DEFAULT_ICON icon,
const core::position2di position, const core::position2di position,
u32 starttime, u32 currenttime, u32 starttime, u32 currenttime,
bool loop, const core::rect<s32>* clip, bool loop, const core::rect<s32>* clip,
@ -1008,14 +1008,14 @@ void GUISkin::drawColoredIcon(IGUIElement* element, EGUI_DEFAULT_ICON icon,
// END PATCH // END PATCH
EGUI_SKIN_TYPE GUISkin::getType() const EGUI_SKIN_TYPE CGUISkin::getType() const
{ {
return Type; return Type;
} }
//! draws a 2d rectangle. //! draws a 2d rectangle.
void GUISkin::draw2DRectangle(IGUIElement* element, void CGUISkin::draw2DRectangle(IGUIElement* element,
const video::SColor &color, const core::rect<s32>& pos, const video::SColor &color, const core::rect<s32>& pos,
const core::rect<s32>* clip) const core::rect<s32>* clip)
{ {
@ -1025,7 +1025,7 @@ void GUISkin::draw2DRectangle(IGUIElement* element,
//! gets the colors //! gets the colors
// PATCH // PATCH
void GUISkin::getColors(video::SColor* colors) void CGUISkin::getColors(video::SColor* colors)
{ {
u32 i; u32 i;
for (i=0; i<EGDC_COUNT; ++i) for (i=0; i<EGDC_COUNT; ++i)

@ -2,8 +2,7 @@
// This file is part of the "Irrlicht Engine". // This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h // For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __GUI_SKIN_H_INCLUDED__ #pragma once
#define __GUI_SKIN_H_INCLUDED__
#include "IGUISkin.h" #include "IGUISkin.h"
#include "irrString.h" #include "irrString.h"
@ -18,14 +17,14 @@ namespace video
} }
namespace gui namespace gui
{ {
class GUISkin : public IGUISkin class CGUISkin : public IGUISkin
{ {
public: public:
GUISkin(EGUI_SKIN_TYPE type, video::IVideoDriver* driver); CGUISkin(EGUI_SKIN_TYPE type, video::IVideoDriver* driver);
//! destructor //! destructor
virtual ~GUISkin(); virtual ~CGUISkin();
//! returns display density scaling factor //! returns display density scaling factor
virtual float getScale() const { return Scale; } virtual float getScale() const { return Scale; }
@ -311,57 +310,6 @@ namespace gui
EGUI_SKIN_TYPE Type; EGUI_SKIN_TYPE Type;
}; };
#define set3DSkinColors(skin, button_color) \
{ \
skin->setColor(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 } // 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 } // end namespace irr
#endif

@ -36,7 +36,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "inputhandler.h" #include "inputhandler.h"
#include "gettext.h" #include "gettext.h"
#include "filesys.h" #include "filesys.h"
#include "../gui/guiSkin.h"
#include "irrlicht_changes/static_text.h" #include "irrlicht_changes/static_text.h"
#include "irr_ptr.h" #include "irr_ptr.h"
@ -126,27 +125,6 @@ IShaderConstantSetter *FogShaderConstantSetterFactory::create()
/* Other helpers */ /* 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<video::E_DRIVER_TYPE> chooseVideoDriver() static std::optional<video::E_DRIVER_TYPE> chooseVideoDriver()
{ {
auto &&configured_name = g_settings->get("video_driver"); auto &&configured_name = g_settings->get("video_driver");
@ -250,11 +228,6 @@ RenderingEngine::RenderingEngine(IEventReceiver *receiver)
s_singleton = this; 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("fullscreen", settingChangedCallback, this);
g_settings->registerChangedCallback("window_maximized", settingChangedCallback, this); g_settings->registerChangedCallback("window_maximized", settingChangedCallback, this);
} }

@ -19,7 +19,6 @@ set(gui_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/guiScene.cpp ${CMAKE_CURRENT_SOURCE_DIR}/guiScene.cpp
${CMAKE_CURRENT_SOURCE_DIR}/guiScrollBar.cpp ${CMAKE_CURRENT_SOURCE_DIR}/guiScrollBar.cpp
${CMAKE_CURRENT_SOURCE_DIR}/guiScrollContainer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/guiScrollContainer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/guiSkin.cpp
${CMAKE_CURRENT_SOURCE_DIR}/guiTable.cpp ${CMAKE_CURRENT_SOURCE_DIR}/guiTable.cpp
${CMAKE_CURRENT_SOURCE_DIR}/guiHyperText.cpp ${CMAKE_CURRENT_SOURCE_DIR}/guiHyperText.cpp
${CMAKE_CURRENT_SOURCE_DIR}/guiVolumeChange.cpp ${CMAKE_CURRENT_SOURCE_DIR}/guiVolumeChange.cpp

@ -253,8 +253,8 @@ void GUIButton::draw()
setFromState(); setFromState();
} }
GUISkin* skin = dynamic_cast<GUISkin*>(Environment->getSkin());
video::IVideoDriver* driver = Environment->getVideoDriver(); video::IVideoDriver* driver = Environment->getVideoDriver();
IGUISkin *skin = Environment->getSkin();
// END PATCH // END PATCH
if (DrawBorder) if (DrawBorder)
@ -737,7 +737,7 @@ void GUIButton::setFromStyle(const StyleSpec& style)
Padding.UpperLeftCorner + BgMiddle.UpperLeftCorner, Padding.UpperLeftCorner + BgMiddle.UpperLeftCorner,
Padding.LowerRightCorner + BgMiddle.LowerRightCorner); Padding.LowerRightCorner + BgMiddle.LowerRightCorner);
GUISkin* skin = dynamic_cast<GUISkin*>(Environment->getSkin()); IGUISkin *skin = Environment->getSkin();
core::vector2d<s32> defaultPressOffset( core::vector2d<s32> defaultPressOffset(
skin->getSize(irr::gui::EGDS_BUTTON_PRESSED_IMAGE_OFFSET_X), skin->getSize(irr::gui::EGDS_BUTTON_PRESSED_IMAGE_OFFSET_X),
skin->getSize(irr::gui::EGDS_BUTTON_PRESSED_IMAGE_OFFSET_Y)); skin->getSize(irr::gui::EGDS_BUTTON_PRESSED_IMAGE_OFFSET_Y));

@ -10,7 +10,6 @@
#include "IGUISpriteBank.h" #include "IGUISpriteBank.h"
#include "ITexture.h" #include "ITexture.h"
#include "SColor.h" #include "SColor.h"
#include "guiSkin.h"
#include "StyleSpec.h" #include "StyleSpec.h"
using namespace irr; using namespace irr;