2012-08-02 01:43:55 +00:00
# ifndef _GUIIMAGE_H_
# define _GUIIMAGE_H_
# include "../GuiComponent.h"
# include <string>
2012-08-29 18:53:53 +00:00
# include <FreeImage.h>
2012-09-10 18:10:59 +00:00
# include "../platform.h"
# include GLHEADER
2012-08-02 01:43:55 +00:00
class GuiImage : public GuiComponent
{
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
//resized to fix. If only one axis is specified, the other will be resized in accordance with the image's aspect ratio. If resizeExact is false,
//the image will only be downscaled, never upscaled (the image's size must surpass at least one nonzero bound).
2012-08-10 19:28:34 +00:00
GuiImage ( int offsetX = 0 , int offsetY = 0 , std : : string path = " " , unsigned int maxWidth = 0 , unsigned int maxHeight = 0 , bool resizeExact = false ) ;
2012-08-02 01:43:55 +00:00
~ GuiImage ( ) ;
2012-09-07 21:44:07 +00:00
void setImage ( std : : string path ) ; //Loads the image at the given filepath.
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)
void setTiling ( bool tile ) ; //Enables or disables tiling. Must be called before loading an image or resizing will be weird.
2012-08-02 01:43:55 +00:00
2012-09-07 21:44:07 +00:00
unsigned int getWidth ( ) ; //Returns render width in pixels. May be different than actual texture width.
unsigned int getHeight ( ) ; //Returns render height in pixels. May be different than actual texture height.
2012-08-09 21:19:07 +00:00
2012-08-02 01:43:55 +00:00
void onRender ( ) ;
2012-08-09 21:19:07 +00:00
2012-09-07 21:44:07 +00:00
//Image textures will be deleted on renderer deinitialization, and recreated on reinitialization (if mPath is not empty).
2012-09-04 16:45:16 +00:00
void onInit ( ) ;
void onDeinit ( ) ;
2012-08-02 01:43:55 +00:00
private :
2012-08-29 21:52:25 +00:00
unsigned int mResizeWidth , mResizeHeight ;
2012-08-13 18:32:53 +00:00
float mOriginX , mOriginY ;
2012-09-04 16:45:16 +00:00
bool mResizeExact , mTiled ;
2012-08-09 21:19:07 +00:00
2012-08-10 02:17:48 +00:00
void loadImage ( std : : string path ) ;
2012-09-07 21:44:07 +00:00
void buildImageArray ( int x , int y , GLfloat * points , GLfloat * texs ) ; //writes 12 GLfloat points and 12 GLfloat texture coordinates to a given array at a given position
void drawImageArray ( GLfloat * points , GLfloat * texs , unsigned int count = 6 ) ; //draws the given set of points and texture coordinates, number of coordinate pairs may be specified (default 6)
2012-08-29 18:53:53 +00:00
void unloadImage ( ) ;
2012-08-10 02:17:48 +00:00
std : : string mPath ;
2012-08-09 21:19:07 +00:00
int mOffsetX , mOffsetY ;
2012-09-07 21:44:07 +00:00
unsigned int mWidth , mHeight ; //Our rendered size.
2012-08-29 18:53:53 +00:00
GLuint mTextureID ;
2012-08-02 01:43:55 +00:00
} ;
# endif