libgui/include/gui/GuiImage.h

128 lines
4.0 KiB
C
Raw Normal View History

2017-10-29 10:28:14 +01:00
/****************************************************************************
* Copyright (C) 2015 Dimok
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#ifndef GUI_IMAGE_H_
#define GUI_IMAGE_H_
2019-08-14 23:24:55 +02:00
#include <gui/video/shaders/Shader.h>
2018-06-21 20:44:58 +02:00
#include <gui/GuiElement.h>
#include <gui/GuiImageData.h>
#include <gui/gx2_ext.h>
2017-10-29 10:28:14 +01:00
//!Display, manage, and manipulate images in the GUI
2018-06-21 20:44:58 +02:00
class GuiImage : public GuiElement {
2017-10-29 10:28:14 +01:00
public:
2018-06-21 20:44:58 +02:00
enum ImageTypes {
2017-10-29 10:28:14 +01:00
IMAGE_TEXTURE,
IMAGE_COLOR
};
//!\overload
//!\param img Pointer to GuiImageData element
2020-08-13 12:38:07 +02:00
GuiImage(GuiImageData *img);
2017-10-29 10:28:14 +01:00
//!\overload
//!Creates an image filled with the specified color
//!\param w Image width
//!\param h Image height
//!\param c Array with 4 x image color (BL, BR, TL, TR)
2020-08-13 12:38:07 +02:00
GuiImage(int32_t w, int32_t h, const GX2Color &c, int32_t imgType = IMAGE_COLOR);
GuiImage(int32_t w, int32_t h, const GX2Color *c, uint32_t colorCount = 1, int32_t imgType = IMAGE_COLOR);
2017-10-29 10:28:14 +01:00
//!Destructor
virtual ~GuiImage();
2020-08-13 12:38:07 +02:00
2017-10-29 10:28:14 +01:00
//!Sets the number of times to draw the image horizontally
//!\param t Number of times to draw the image
2018-06-21 20:44:58 +02:00
void setTileHorizontal(int32_t t) {
tileHorizontal = t;
}
2020-08-13 12:38:07 +02:00
2017-10-29 10:28:14 +01:00
//!Sets the number of times to draw the image vertically
//!\param t Number of times to draw the image
2018-06-21 20:44:58 +02:00
void setTileVertical(int32_t t) {
tileVertical = t;
}
2020-08-13 12:38:07 +02:00
2017-10-29 10:28:14 +01:00
//!Constantly called to draw the image
void draw(CVideo *pVideo);
2020-08-13 12:38:07 +02:00
2017-10-29 10:28:14 +01:00
//!Gets the image data
//!\return pointer to image data
2020-08-13 12:38:07 +02:00
GuiImageData *getImageData() const {
2018-06-21 20:44:58 +02:00
return imageData;
}
2020-08-13 12:38:07 +02:00
2017-10-29 10:28:14 +01:00
//!Sets up a new image using the GuiImageData object specified
//!\param img Pointer to GuiImageData object
2020-08-13 12:38:07 +02:00
void setImageData(GuiImageData *img);
2017-10-29 10:28:14 +01:00
//!Gets the pixel color at the specified coordinates of the image
//!\param x X coordinate
//!\param y Y coordinate
2018-06-21 20:44:58 +02:00
GX2Color getPixel(int32_t x, int32_t y);
2020-08-13 12:38:07 +02:00
2017-10-29 10:28:14 +01:00
//!Sets the pixel color at the specified coordinates of the image
//!\param x X coordinate
//!\param y Y coordinate
//!\param color Pixel color
2020-08-13 12:38:07 +02:00
void setPixel(int32_t x, int32_t y, const GX2Color &color);
2017-10-29 10:28:14 +01:00
//!Change ImageColor
2020-08-13 12:38:07 +02:00
void setImageColor(const GX2Color &c, int32_t idx = -1);
2017-10-29 10:28:14 +01:00
//!Change ImageColor
2018-06-21 20:44:58 +02:00
void setSize(int32_t w, int32_t h);
2017-10-29 10:28:14 +01:00
2018-06-21 20:44:58 +02:00
void setPrimitiveVertex(int32_t prim, const float *pos, const float *tex, uint32_t count);
2017-10-29 10:28:14 +01:00
2018-06-21 20:44:58 +02:00
void setBlurDirection(uint8_t dir, float value) {
2020-08-13 12:38:07 +02:00
if (dir < 2) {
2017-10-29 10:28:14 +01:00
blurDirection[dir] = value;
}
}
2020-08-13 12:38:07 +02:00
void setColorIntensity(const glm::vec4 &col) {
2017-10-29 10:28:14 +01:00
colorIntensity = col;
}
2020-08-13 12:38:07 +02:00
2017-10-29 10:28:14 +01:00
protected:
2018-06-21 20:44:58 +02:00
void internalInit(int32_t w, int32_t h);
2017-10-29 10:28:14 +01:00
2018-06-21 20:44:58 +02:00
int32_t imgType; //!< Type of image data (IMAGE_TEXTURE, IMAGE_COLOR, IMAGE_DATA)
2020-08-13 12:38:07 +02:00
GuiImageData *imageData; //!< Poiner to image data. May be shared with GuiImageData data
2018-06-21 20:44:58 +02:00
int32_t tileHorizontal; //!< Number of times to draw (tile) the image horizontally
int32_t tileVertical; //!< Number of times to draw (tile) the image vertically
2017-10-29 10:28:14 +01:00
//! Internally used variables for rendering
2018-06-21 20:44:58 +02:00
uint8_t *colorVtxs;
uint32_t colorCount;
2017-10-29 10:28:14 +01:00
bool colorVtxsDirty;
glm::vec3 positionOffsets;
glm::vec3 scaleFactor;
glm::vec4 colorIntensity;
2018-06-21 20:44:58 +02:00
float imageAngle;
2017-10-29 10:28:14 +01:00
glm::vec3 blurDirection;
2020-08-13 12:38:07 +02:00
const float *posVtxs;
const float *texCoords;
2018-06-21 20:44:58 +02:00
uint32_t vtxCount;
int32_t primitive;
2017-10-29 10:28:14 +01:00
};
#endif