ES-DE/src/components/ImageComponent.h

62 lines
2.6 KiB
C
Raw Normal View History

2013-06-02 15:08:32 +00:00
#ifndef _IMAGECOMPONENT_H_
#define _IMAGECOMPONENT_H_
#include "../platform.h"
#include GLHEADER
2013-06-02 15:08:32 +00:00
#include "../GuiComponent.h"
#include <string>
#include <memory>
#include "../resources/TextureResource.h"
2013-06-02 15:08:32 +00:00
class ImageComponent : public GuiComponent
{
public:
//Creates a new GuiImage at the given location. If given an image, it will be loaded. If maxWidth and/or maxHeight are nonzero, the image will be
//resized to fit. If only one axis is specified, the other will be set in accordance with the image's aspect ratio. If allowUpscale is false,
//the image will only be downscaled, never upscaled (the image's size must surpass at least one nonzero bound).
ImageComponent(Window* window, const Eigen::Vector2f& pos = Eigen::Vector2f::Zero(), const std::string& path = "");
2013-06-02 15:08:32 +00:00
virtual ~ImageComponent();
void setImage(std::string path, bool tile = false); //Loads the image at the given filepath.
void setImage(const char* image, size_t length, bool tile = false); //Loads image from memory.
void setImage(const std::shared_ptr<TextureResource>& texture); //Use an already existing texture.
void setOrigin(float originX, float originY); //Sets the origin as a percentage of this image (e.g. (0, 0) is top left, (0.5, 0.5) is the center)
inline void setOrigin(Eigen::Vector2f origin) { setOrigin(origin.x(), origin.y()); }
void setResize(float width, float height);
inline void setResize(const Eigen::Vector2f& size) { setResize(size.x(), size.y()); }
void setMaxSize(float width, float height);
inline void setMaxSize(const Eigen::Vector2f& size) { setMaxSize(size.x(), size.y()); }
void setColorShift(unsigned int color);
2012-10-07 22:25:51 +00:00
void setFlipX(bool flip);
void setFlipY(bool flip);
//You can get the rendered size of the ImageComponent with getSize().
Eigen::Vector2i getTextureSize() const;
2013-08-06 13:15:20 +00:00
Eigen::Vector2f getCenter() const;
bool hasImage();
void render(const Eigen::Affine3f& parentTrans) override;
virtual void applyTheme(const std::shared_ptr<ThemeData>& theme, const std::string& view, const std::string& element, unsigned int properties) override;
private:
Eigen::Vector2f mTargetSize;
Eigen::Vector2f mOrigin;
bool mFlipX, mFlipY, mTargetIsMax;
void resize();
void buildImageArray(int x, int y, GLfloat* points, GLfloat* texs, float percentageX = 1, float percentageY = 1); //writes 12 GLfloat points and 12 GLfloat texture coordinates to a given array at a given position
2012-10-17 17:15:58 +00:00
void drawImageArray(GLfloat* points, GLfloat* texs, GLubyte* colors, unsigned int count = 6); //draws the given set of points and texture coordinates, number of coordinate pairs may be specified (default 6)
2012-08-10 02:17:48 +00:00
unsigned int mColorShift;
std::shared_ptr<TextureResource> mTexture;
};
#endif