mirror of
https://github.com/minetest/irrlicht.git
synced 2024-11-18 16:20:31 +01:00
59fc4401f1
The commit also establishes a precedent of leaving off the `virtual` keyword in overrides. Although not strictly necessary, I believe this is good for readability because it makes it clear it is an override and not a pure virtual function, and it helps keep line lengths shorter. We should move towards eliminating the macro altogether, but the definition has been left in with a note on deprecation so that in-progress work will not suffer merge conflicts.
108 lines
3.0 KiB
C++
108 lines
3.0 KiB
C++
// Copyright (C) 2002-2012 Nikolaus Gebhardt
|
|
// This file is part of the "Irrlicht Engine".
|
|
// For conditions of distribution and use, see copyright notice in irrlicht.h
|
|
|
|
#ifndef __C_GUI_IMAGE_H_INCLUDED__
|
|
#define __C_GUI_IMAGE_H_INCLUDED__
|
|
|
|
#include "IrrCompileConfig.h"
|
|
#ifdef _IRR_COMPILE_WITH_GUI_
|
|
|
|
#include "IGUIImage.h"
|
|
|
|
namespace irr
|
|
{
|
|
namespace gui
|
|
{
|
|
|
|
class CGUIImage : public IGUIImage
|
|
{
|
|
public:
|
|
|
|
//! constructor
|
|
CGUIImage(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle);
|
|
|
|
//! destructor
|
|
virtual ~CGUIImage();
|
|
|
|
//! sets an image
|
|
void setImage(video::ITexture* image) override;
|
|
|
|
//! Gets the image texture
|
|
video::ITexture* getImage() const override;
|
|
|
|
//! sets the color of the image
|
|
void setColor(video::SColor color) override;
|
|
|
|
//! sets if the image should scale to fit the element
|
|
void setScaleImage(bool scale) override;
|
|
|
|
//! draws the element and its children
|
|
void draw() override;
|
|
|
|
//! sets if the image should use its alpha channel to draw itself
|
|
void setUseAlphaChannel(bool use) override;
|
|
|
|
//! Gets the color of the image
|
|
video::SColor getColor() const override;
|
|
|
|
//! Returns true if the image is scaled to fit, false if not
|
|
bool isImageScaled() const override;
|
|
|
|
//! Returns true if the image is using the alpha channel, false if not
|
|
bool isAlphaChannelUsed() const override;
|
|
|
|
//! Sets the source rectangle of the image. By default the full image is used.
|
|
void setSourceRect(const core::rect<s32>& sourceRect) override;
|
|
|
|
//! Returns the customized source rectangle of the image to be used.
|
|
core::rect<s32> getSourceRect() const override;
|
|
|
|
//! Restrict drawing-area.
|
|
void setDrawBounds(const core::rect<f32>& drawBoundUVs) override;
|
|
|
|
//! Get drawing-area restrictions.
|
|
core::rect<f32> getDrawBounds() const override;
|
|
|
|
//! Sets whether to draw a background color (EGDC_3D_DARK_SHADOW) when no texture is set
|
|
void setDrawBackground(bool draw) override
|
|
{
|
|
DrawBackground = draw;
|
|
}
|
|
|
|
//! Checks if a background is drawn when no texture is set
|
|
bool isDrawBackgroundEnabled() const override
|
|
{
|
|
return DrawBackground;
|
|
}
|
|
|
|
protected:
|
|
void checkBounds(core::rect<s32>& rect)
|
|
{
|
|
f32 clipWidth = (f32)rect.getWidth();
|
|
f32 clipHeight = (f32)rect.getHeight();
|
|
|
|
rect.UpperLeftCorner.X += core::round32(DrawBounds.UpperLeftCorner.X*clipWidth);
|
|
rect.UpperLeftCorner.Y += core::round32(DrawBounds.UpperLeftCorner.Y*clipHeight);
|
|
rect.LowerRightCorner.X -= core::round32((1.f-DrawBounds.LowerRightCorner.X)*clipWidth);
|
|
rect.LowerRightCorner.Y -= core::round32((1.f-DrawBounds.LowerRightCorner.Y)*clipHeight);
|
|
}
|
|
|
|
private:
|
|
video::ITexture* Texture;
|
|
video::SColor Color;
|
|
bool UseAlphaChannel;
|
|
bool ScaleImage;
|
|
core::rect<s32> SourceRect;
|
|
core::rect<f32> DrawBounds;
|
|
bool DrawBackground;
|
|
};
|
|
|
|
|
|
} // end namespace gui
|
|
} // end namespace irr
|
|
|
|
#endif // _IRR_COMPILE_WITH_GUI_
|
|
|
|
#endif // __C_GUI_IMAGE_H_INCLUDED__
|