5#include "fifechan/widgets/imagebutton.hpp"
11#include "fifechan/exception.hpp"
12#include "fifechan/font.hpp"
13#include "fifechan/graphics.hpp"
14#include "fifechan/image.hpp"
18 ImageButton::ImageButton() : mImages(6, static_cast<
Image const *>(nullptr)), mOwnedImages(6)
23 ImageButton::ImageButton(std::string
const & filename) :
34 ImageButton::~ImageButton() =
default;
46 mImages[
static_cast<size_t>(type)] = image;
62 return mImages[
static_cast<size_t>(ImageType::Up)];
77 return mImages[
static_cast<size_t>(ImageType::Down)];
82 setImage(filename, ImageType::Hover);
92 return mImages[
static_cast<size_t>(ImageType::Hover)];
97 setImage(filename, ImageType::Up_Inactive);
102 setImage(image, ImageType::Up_Inactive);
107 return mImages[
static_cast<size_t>(ImageType::Up_Inactive)];
112 setImage(filename, ImageType::Down_Inactive);
117 setImage(image, ImageType::Down_Inactive);
122 return mImages[
static_cast<size_t>(ImageType::Down_Inactive)];
127 setImage(filename, ImageType::Hover_Inactive);
132 setImage(image, ImageType::Hover_Inactive);
137 return mImages[
static_cast<size_t>(ImageType::Hover_Inactive)];
154 for (
unsigned int i = 0; i < 6; ++i) {
156 if (img !=
nullptr) {
204 if (img !=
nullptr) {
210 ((
getSelectionMode() & Widget::SelectionMode::Background) == Widget::SelectionMode::Background)) {
213 int const alpha = faceColor.
a;
216 faceColor = faceColor - 0x303030;
220 int const color =
static_cast<int>((faceColor.
r * 0.3) + (faceColor.
g * 0.59) + (faceColor.
b * 0.11));
238 case Graphics::Alignment::Left:
241 case Graphics::Alignment::Center:
245 case Graphics::Alignment::Right:
249 throwException(
"Unknown alignment.");
uint8_t a
Alpha color component (0-255).
uint8_t b
Blue color component (0-255).
uint8_t g
Green color component (0-255).
uint8_t r
Red color component (0-255).
virtual int getHeight() const =0
Gets the height of the glyphs in the font.
Abstract interface providing primitive drawing functions (lines, rectangles, etc.).
virtual void drawImage(Image const *image, int srcX, int srcY, int dstX, int dstY, int width, int height)=0
Draws a part of an image.
void drawText(std::string const &text, int x, int y)
Draws text with a default left alignment.
virtual void setFont(Font *font)
Sets the font to use when drawing text.
virtual void setColor(Color const &color)=0
Sets the color to use when drawing.
virtual void fillRectangle(Rectangle const &rectangle)=0
Draws a filled rectangle.
Abstract holder for image data.
virtual int getHeight() const =0
Gets the height of the image.
static Image * load(std::string const &filename, bool convertToDisplayFormat=true)
Loads an image by using the class' image loader.
virtual int getWidth() const =0
Gets the width of the image.
Represents a rectangular area (X, Y, Width, Height).
int width
Holds the width of the rectangle.
int y
Holds the x coordinate of the rectangle.
int x
Holds the x coordinate of the rectangle.
int height
Holds the height of the rectangle.