summaryrefslogtreecommitdiff
path: root/src/graphics.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/graphics.cpp')
-rw-r--r--src/graphics.cpp90
1 files changed, 70 insertions, 20 deletions
diff --git a/src/graphics.cpp b/src/graphics.cpp
index 5455f61a..68fc4e46 100644
--- a/src/graphics.cpp
+++ b/src/graphics.cpp
@@ -21,27 +21,11 @@
#include "graphics.h"
-#include "resources/image.h"
+#include "gui/truetypefont.h"
+#include "resources/theme.h"
#include <guichan/exception.hpp>
-#include <utility>
-
-ImageRect::ImageRect(ImageRect &&r)
-{
- image = std::exchange(r.image, nullptr);
- top = r.top;
- left = r.left;
- bottom = r.bottom;
- right = r.right;
- fillMode = r.fillMode;
-}
-
-ImageRect::~ImageRect()
-{
- delete image;
-}
-
void Graphics::updateSize(int width, int height, float /*scale*/)
{
@@ -166,7 +150,7 @@ void Graphics::drawImageRect(const ImageRect &imgRect, int x, int y, int w, int
switch (imgRect.fillMode)
{
case FillMode::Stretch:
- drawRescaledImage(imgRect.image,
+ drawRescaledImage(imgRect.image.get(),
srcGridX[ix],
srcGridY[iy],
dstGridX[ix],
@@ -175,7 +159,7 @@ void Graphics::drawImageRect(const ImageRect &imgRect, int x, int y, int w, int
dstW, dstH);
break;
case FillMode::Repeat:
- drawRescaledImagePattern(imgRect.image,
+ drawRescaledImagePattern(imgRect.image.get(),
srcGridX[ix],
srcGridY[iy],
srcW, srcH,
@@ -189,6 +173,72 @@ void Graphics::drawImageRect(const ImageRect &imgRect, int x, int y, int w, int
}
}
+void Graphics::drawText(const std::string &text,
+ int x, int y,
+ gcn::Graphics::Alignment alignment,
+ const gcn::Color &color,
+ gcn::Font *font,
+ bool outline,
+ bool shadow,
+ const std::optional<gcn::Color> &outlineColor,
+ const std::optional<gcn::Color> &shadowColor)
+{
+ switch (alignment)
+ {
+ case gcn::Graphics::LEFT:
+ break;
+ case gcn::Graphics::CENTER:
+ x -= font->getWidth(text) / 2;
+ break;
+ case gcn::Graphics::RIGHT:
+ x -= font->getWidth(text);
+ break;
+ default:
+ throw GCN_EXCEPTION("Unknown alignment.");
+ }
+
+ auto realOutlineColor = outlineColor;
+ auto realShadowColor = shadowColor;
+
+ if (shadow && !realShadowColor)
+ {
+ auto sc = Theme::getThemeColor(Theme::SHADOW);
+ sc.a = color.a / 2;
+ realShadowColor = sc;
+ }
+
+ if (outline && !realOutlineColor)
+ {
+ auto oc = Theme::getThemeColor(Theme::OUTLINE);
+ oc.a = color.a;
+ realOutlineColor = oc;
+ }
+
+ setColor(color);
+ static_cast<TrueTypeFont*>(font)->drawString(graphics, text, x, y,
+ realOutlineColor,
+ realShadowColor);
+}
+
+void Graphics::drawText(const std::string &text,
+ int x,
+ int y,
+ gcn::Graphics::Alignment align,
+ gcn::Font *font,
+ const TextFormat &format)
+{
+ drawText(text,
+ x,
+ y,
+ align,
+ format.color,
+ font,
+ format.outlineColor.has_value(),
+ format.shadowColor.has_value(),
+ format.outlineColor,
+ format.shadowColor);
+}
+
void Graphics::_beginDraw()
{
pushClipArea(gcn::Rectangle(0, 0, mWidth, mHeight));