27#include <guichan/exception.hpp>
62 float dstX,
float dstY,
63 int width,
int height,
64 float desiredWidth,
float desiredHeight,
69 static_cast<int>(dstX),
70 static_cast<int>(dstY),
72 static_cast<int>(desiredWidth),
73 static_cast<int>(desiredHeight),
80 int width,
int height,
87 width, height, useColor);
96 width, height, useColor);
111 int scaledWidth,
int scaledHeight)
125 const int srcGridX[4] = {0,
128 imgRect.
image->getWidth()};
129 const int srcGridY[4] = {0,
132 imgRect.
image->getHeight()};
134 const int dstGridX[4] = {x, x + imgRect.
left, x + w - imgRect.
right, x + w};
135 const int dstGridY[4] = {y, y + imgRect.
top, y + h - imgRect.
bottom, y + h};
137 for (
unsigned ix = 0; ix < 3; ix++)
139 for (
unsigned iy = 0; iy < 3; iy++)
141 const int srcW = srcGridX[ix + 1] - srcGridX[ix];
142 const int srcH = srcGridY[iy + 1] - srcGridY[iy];
144 const int dstW = dstGridX[ix + 1] - dstGridX[ix];
145 const int dstH = dstGridY[iy + 1] - dstGridY[iy];
147 if (srcW <= 0 || srcH <= 0 || dstW <= 0 || dstH <= 0)
178 gcn::Graphics::Alignment alignment,
179 const gcn::Color &color,
183 const std::optional<gcn::Color> &outlineColor,
184 const std::optional<gcn::Color> &shadowColor)
188 case gcn::Graphics::LEFT:
190 case gcn::Graphics::CENTER:
191 x -= font->getWidth(text) / 2;
193 case gcn::Graphics::RIGHT:
194 x -= font->getWidth(text);
197 throw GCN_EXCEPTION(
"Unknown alignment.");
200 auto realOutlineColor = outlineColor;
201 auto realShadowColor = shadowColor;
203 if (shadow && !realShadowColor)
207 realShadowColor = sc;
210 if (outline && !realOutlineColor)
214 realOutlineColor = oc;
226 gcn::Graphics::Alignment align,
254 const gcn::ClipRectangle &carea = mClipStack.top();
256 rect.y + carea.yOffset,
virtual void drawImagePattern(const Image *image, int x, int y, int w, int h)
std::stack< gcn::Rectangle > mClipRects
bool drawImageF(const Image *image, float x, float y)
Blits an image onto the screen.
void drawImageRect(const ImageRect &imgRect, int x, int y, int w, int h)
Draws a rectangle using images.
bool drawRescaledImage(const Image *image, int x, int y, int width, int height)
Draws a rescaled version of the image.
void drawRescaledImagePattern(const Image *image, int x, int y, int w, int h, int scaledWidth, int scaledHeight)
Draw a pattern based on a rescaled version of the given image.
void drawText(const std::string &text, int x, int y, gcn::Graphics::Alignment alignment, const gcn::Color &color, gcn::Font *font, bool outline=false, bool shadow=false, const std::optional< gcn::Color > &outlineColor={}, const std::optional< gcn::Color > &shadowColor={})
void setColor(const gcn::Color &color) override
virtual void updateClipRect()=0
bool drawImage(const Image *image, int x, int y)
Blits an image onto the screen.
void pushClipRect(const gcn::Rectangle &rect)
void _beginDraw() override
virtual void updateSize(int width, int height, float scale)
Called when the window size or scale has changed.
virtual bool drawRescaledImageF(const Image *image, int srcX, int srcY, float dstX, float dstY, int width, int height, float desiredWidth, float desiredHeight, bool useColor=false)
Draws a rescaled version of the image.
Defines a class for loading and storing images.
int getHeight() const
Returns the height of the image.
int getWidth() const
Returns the width of the image.
static const gcn::Color & getThemeColor(int type)
Gets the color associated with the type in the default palette (0).
A wrapper around SDL_ttf for allowing the use of TrueType fonts.
An image reference along with the margins specifying how to render this image at different sizes.
std::unique_ptr< Image > image
std::optional< gcn::Color > shadowColor
std::optional< gcn::Color > outlineColor