6#include "fifechan/widgets/imagebutton.hpp"
14#include "fifechan/exception.hpp"
15#include "fifechan/font.hpp"
16#include "fifechan/graphics.hpp"
17#include "fifechan/image.hpp"
21 ImageButton::ImageButton() : mImages(6, static_cast<
Image const *>(nullptr)), mOwnedImages(6)
26 ImageButton::ImageButton(std::string
const & filename) :
37 ImageButton::~ImageButton() =
default;
49 mImages.at(
static_cast<size_t>(type)) = image;
65 return mImages.at(
static_cast<size_t>(ImageType::Up));
80 return mImages.at(
static_cast<size_t>(ImageType::Down));
85 setImage(filename, ImageType::Hover);
95 return mImages.at(
static_cast<size_t>(ImageType::Hover));
100 setImage(filename, ImageType::Up_Inactive);
105 setImage(image, ImageType::Up_Inactive);
110 return mImages.at(
static_cast<size_t>(ImageType::Up_Inactive));
115 setImage(filename, ImageType::Down_Inactive);
120 setImage(image, ImageType::Down_Inactive);
125 return mImages.at(
static_cast<size_t>(ImageType::Down_Inactive));
130 setImage(filename, ImageType::Hover_Inactive);
135 setImage(image, ImageType::Hover_Inactive);
140 return mImages.at(
static_cast<size_t>(ImageType::Hover_Inactive));
157 for (
unsigned int i = 0; i < 6; ++i) {
159 if (img !=
nullptr) {
207 if (img !=
nullptr) {
213 ((
getSelectionMode() & Widget::SelectionMode::Background) == Widget::SelectionMode::Background)) {
216 int const alpha = faceColor.
a;
219 faceColor = faceColor - 0x303030;
223 int const color =
static_cast<int>((faceColor.
r * 0.3) + (faceColor.
g * 0.59) + (faceColor.
b * 0.11));
241 case Graphics::Alignment::Left:
244 case Graphics::Alignment::Center:
248 case Graphics::Alignment::Right:
261 unsigned char const first =
static_cast<unsigned char>(cap.at(0));
263 if (first >= 0xF0 || first == 0xE2) {
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.
Used replacement tokens by configure_file():
void throwException(std::string const &message, std::source_location location=std::source_location::current())
Throw an Exception capturing the current source location.