OpenMiner/include/gui/Image.hpp

59 lines
1.3 KiB
C++
Raw Normal View History

2018-06-20 05:43:52 +02:00
/*
* =====================================================================================
*
* Filename: Image.hpp
*
* Description:
*
* Created: 20/09/2014 16:21:56
*
* Author: Quentin Bazin, <gnidmoo@gmail.com>
*
* =====================================================================================
*/
#ifndef IMAGE_HPP_
#define IMAGE_HPP_
#include "Color.hpp"
2018-06-20 05:43:52 +02:00
#include "IDrawable.hpp"
#include "Rect.hpp"
#include "Texture.hpp"
#include "Transformable.hpp"
2018-06-20 05:43:52 +02:00
#include "VertexBuffer.hpp"
class Image : public IDrawable, public Transformable {
2018-06-20 05:43:52 +02:00
public:
Image() = default;
Image(const std::string &textureName);
2018-06-20 05:43:52 +02:00
Image(const Texture &texture);
void load(const std::string &textureName);
2018-06-20 05:43:52 +02:00
void load(const Texture &texture);
const FloatRect &clipRect() const { return m_clipRect; }
2018-06-20 05:43:52 +02:00
void setClipRect(float x, float y, u16 width, u16 height);
u16 width() const { return m_width; }
u16 height() const { return m_height; }
void setColor(const Color &color) { m_color = color; updateVertexBuffer(); }
2018-06-20 05:43:52 +02:00
private:
void updateVertexBuffer() const;
void draw(RenderTarget &target, RenderStates states) const override;
const Texture *m_texture = nullptr;
u16 m_width = 0;
u16 m_height = 0;
FloatRect m_clipRect;
VertexBuffer m_vbo;
Color m_color = Color::white;
2018-06-20 05:43:52 +02:00
};
#endif // IMAGE_HPP_