25 #include <guichan.hpp>
31 #include "util/structures/rect.h"
32 #include "video/image.h"
33 #include "video/renderbackend.h"
38 GuiFont::GuiFont(IFont* font): m_font(font) {
46 int32_t GuiFont::getStringIndexAt(
const std::string& text, int32_t x)
const {
47 return m_font->getStringIndexAt(text, x);
50 void GuiFont::drawString(gcn::Graphics* graphics,
const std::string& text, int32_t x, int32_t y) {
55 int32_t yoffset = getRowSpacing() / 2;
57 const gcn::ClipRectangle& clip = graphics->getCurrentClipArea();
59 rect.
x = x + clip.xOffset;
60 rect.
y = y + clip.yOffset + yoffset;
61 rect.
w = getWidth(text);
64 if (!rect.
intersects(Rect(clip.x,clip.y,clip.width,clip.height)) ) {
68 Image* image = getAsImage(text);
72 void GuiFont::drawMultiLineString(gcn::Graphics* graphics,
const std::string& text, int32_t x, int32_t y) {
77 int32_t yoffset = getRowSpacing() / 2;
79 const gcn::ClipRectangle& clip = graphics->getCurrentClipArea();
81 Image* image = getAsImageMultiline(text);
84 rect.
x = x + clip.xOffset;
85 rect.
y = y + clip.yOffset + yoffset;
86 rect.
w = image->getWidth();
87 rect.
h = image->getHeight();
88 if (!rect.
intersects(Rect(clip.x,clip.y,clip.width,clip.height)) ) {
94 void GuiFont::setRowSpacing (int32_t spacing) {
95 m_font->setRowSpacing(spacing);
98 int32_t GuiFont::getRowSpacing()
const {
99 return m_font->getRowSpacing();
102 void GuiFont::setGlyphSpacing(int32_t spacing) {
103 m_font->setGlyphSpacing(spacing);
106 int32_t GuiFont::getGlyphSpacing()
const {
107 return m_font->getGlyphSpacing();
110 void GuiFont::setAntiAlias(
bool antiAlias) {
111 m_font->setAntiAlias(antiAlias);
114 bool GuiFont::isAntiAlias() {
115 return m_font->isAntiAlias();
118 Image* GuiFont::getAsImage(
const std::string& text) {
119 return m_font->getAsImage(text);
122 Image* GuiFont::getAsImageMultiline(
const std::string& text) {
123 return m_font->getAsImageMultiline(text);
126 std::string GuiFont::splitTextToWidth (
const std::string& text, int32_t render_width) {
127 return m_font->splitTextToWidth(text,render_width);
130 void GuiFont::setColor(uint8_t r,uint8_t g,uint8_t b, uint8_t a) {
131 m_font->setColor(r, g, b, a);
134 SDL_Color GuiFont::getColor()
const {
135 return m_font->getColor();
138 int32_t GuiFont::getWidth(
const std::string& text)
const {
139 return m_font->getWidth(text);
142 int32_t GuiFont::getHeight()
const {
143 return m_font->getHeight();
146 void GuiFont::invalidate() {
147 m_font->invalidate();