gui_font.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <guichan.hpp>
00026
00027
00028
00029
00030
00031 #include "util/structures/rect.h"
00032 #include "video/image.h"
00033 #include "video/renderbackend.h"
00034
00035 #include "gui_font.h"
00036
00037 namespace FIFE {
00038 GuiFont::GuiFont(AbstractFont* font): m_font(font) {
00039 assert(font);
00040 }
00041
00042 GuiFont::~GuiFont() {
00043 delete m_font;
00044 }
00045
00046 int GuiFont::getStringIndexAt(const std::string& text, int x) const {
00047 return m_font->getStringIndexAt(text, x);
00048 }
00049
00050 void GuiFont::drawString(gcn::Graphics* graphics, const std::string& text, int x, int y) {
00051 if (text == "") {
00052 return;
00053 }
00054
00055 int yoffset = getRowSpacing() / 2;
00056
00057 const gcn::ClipRectangle& clip = graphics->getCurrentClipArea();
00058 FIFE::Rect rect;
00059 rect.x = x + clip.xOffset;
00060 rect.y = y + clip.yOffset + yoffset;
00061 rect.w = getWidth(text);
00062 rect.h = getHeight();
00063
00064 if (!rect.intersects(Rect(clip.x,clip.y,clip.width,clip.height)) ) {
00065 return;
00066 }
00067
00068 Image* image = getAsImage(text);
00069 image->render(rect);
00070 }
00071
00072 void GuiFont::drawMultiLineString(gcn::Graphics* graphics, const std::string& text, int x, int y) {
00073 if (text == "") {
00074 return;
00075 }
00076
00077 int yoffset = getRowSpacing() / 2;
00078
00079 const gcn::ClipRectangle& clip = graphics->getCurrentClipArea();
00080
00081 Image* image = getAsImageMultiline(text);
00082
00083 FIFE::Rect rect;
00084 rect.x = x + clip.xOffset;
00085 rect.y = y + clip.yOffset + yoffset;
00086 rect.w = image->getWidth();
00087 rect.h = image->getHeight();
00088 if (!rect.intersects(Rect(clip.x,clip.y,clip.width,clip.height)) ) {
00089 return;
00090 }
00091 image->render(rect);
00092 }
00093
00094 void GuiFont::setRowSpacing (int spacing) {
00095 m_font->setRowSpacing(spacing);
00096 }
00097
00098 int GuiFont::getRowSpacing() const {
00099 return m_font->getRowSpacing();
00100 }
00101
00102 void GuiFont::setGlyphSpacing(int spacing) {
00103 m_font->setGlyphSpacing(spacing);
00104 }
00105
00106 int GuiFont::getGlyphSpacing() const {
00107 return m_font->getGlyphSpacing();
00108 }
00109
00110 void GuiFont::setAntiAlias(bool antiAlias) {
00111 m_font->setAntiAlias(antiAlias);
00112 }
00113
00114 bool GuiFont::isAntiAlias() {
00115 return m_font->isAntiAlias();
00116 }
00117
00118 Image* GuiFont::getAsImage(const std::string& text) {
00119 return m_font->getAsImage(text);
00120 }
00121
00122 Image* GuiFont::getAsImageMultiline(const std::string& text) {
00123 return m_font->getAsImageMultiline(text);
00124 }
00125
00126 std::string GuiFont::splitTextToWidth (const std::string& text, int render_width) {
00127 return m_font->splitTextToWidth(text,render_width);
00128 }
00129
00130 void GuiFont::setColor(uint8_t r,uint8_t g,uint8_t b) {
00131 m_font->setColor(r, g, b);
00132 }
00133
00134 SDL_Color GuiFont::getColor() const {
00135 return m_font->getColor();
00136 }
00137
00138 int GuiFont::getWidth(const std::string& text) const {
00139 return m_font->getWidth(text);
00140 }
00141
00142 int GuiFont::getHeight() const {
00143 return m_font->getHeight();
00144 }
00145 }