2013-06-02 15:08:32 +00:00
# ifndef _IMAGECOMPONENT_H_
# define _IMAGECOMPONENT_H_
2012-08-02 01:43:55 +00:00
2013-05-13 19:53:28 +00:00
# include "../platform.h"
# include GLHEADER
2013-06-02 15:08:32 +00:00
# include "../GuiComponent.h"
2012-08-02 01:43:55 +00:00
# include <string>
2013-06-21 16:49:29 +00:00
# include <memory>
# include "../resources/TextureResource.h"
2012-08-02 01:43:55 +00:00
2013-06-02 15:08:32 +00:00
class ImageComponent : public GuiComponent
2012-08-02 01:43:55 +00:00
{
public :
2012-09-07 21:44:07 +00:00
//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
2013-06-02 21:05:29 +00:00
//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,
2012-09-07 21:44:07 +00:00
//the image will only be downscaled, never upscaled (the image's size must surpass at least one nonzero bound).
2014-01-10 23:45:47 +00:00
ImageComponent ( Window * window , const Eigen : : Vector2f & pos = Eigen : : Vector2f : : Zero ( ) , const std : : string & path = " " ) ;
2013-06-02 15:08:32 +00:00
virtual ~ ImageComponent ( ) ;
2012-08-02 01:43:55 +00:00
2013-06-21 16:49:29 +00:00
void copyScreen ( ) ; //Copy the entire screen into a texture for us to use.
2012-09-07 21:44:07 +00:00
void setImage ( std : : string path ) ; //Loads the image at the given filepath.
2013-09-20 23:55:05 +00:00
void setImage ( const char * image , size_t length ) ; //Loads image from memory.
2013-11-12 23:28:15 +00:00
void setImage ( const std : : shared_ptr < TextureResource > & texture ) ; //Use an already existing texture.
2012-09-07 21:44:07 +00:00
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)
2013-12-30 23:23:34 +00:00
inline void setOrigin ( Eigen : : Vector2f origin ) { setOrigin ( origin . x ( ) , origin . y ( ) ) ; }
2012-09-07 21:44:07 +00:00
void setTiling ( bool tile ) ; //Enables or disables tiling. Must be called before loading an image or resizing will be weird.
2014-01-10 23:45:47 +00:00
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 ( ) ) ; }
2013-08-07 22:40:27 +00:00
void setColorShift ( unsigned int color ) ;
2012-08-02 01:43:55 +00:00
2012-10-07 22:25:51 +00:00
void setFlipX ( bool flip ) ;
void setFlipY ( bool flip ) ;
2013-06-02 22:33:49 +00:00
//You can get the rendered size of the ImageComponent with getSize().
2013-07-10 11:29:43 +00:00
Eigen : : Vector2i getTextureSize ( ) const ;
2013-06-02 22:33:49 +00:00
2013-08-06 13:15:20 +00:00
Eigen : : Vector2f getCenter ( ) const ;
2012-10-10 13:51:48 +00:00
bool hasImage ( ) ;
2013-07-10 11:29:43 +00:00
void render ( const Eigen : : Affine3f & parentTrans ) override ;
2013-06-02 19:34:50 +00:00
2014-01-01 05:39:22 +00:00
virtual void applyTheme ( const std : : shared_ptr < ThemeData > & theme , const std : : string & view , const std : : string & element , unsigned int properties ) override ;
2012-08-02 01:43:55 +00:00
private :
2013-07-10 11:29:43 +00:00
Eigen : : Vector2f mTargetSize ;
Eigen : : Vector2f mOrigin ;
2013-06-02 21:05:29 +00:00
2014-01-10 23:45:47 +00:00
bool mTiled , mFlipX , mFlipY , mTargetIsMax ;
2012-08-09 21:19:07 +00:00
2012-10-05 20:04:12 +00:00
void resize ( ) ;
2012-10-10 15:21:03 +00:00
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
2013-08-07 22:40:27 +00:00
unsigned int mColorShift ;
2013-06-21 16:49:29 +00:00
std : : shared_ptr < TextureResource > mTexture ;
2012-08-02 01:43:55 +00:00
} ;
# endif