ShapeRenderedText.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2004-2005 The Pentagram team
00003 
00004 This program is free software; you can redistribute it and/or
00005 modify it under the terms of the GNU General Public License
00006 as published by the Free Software Foundation; either version 2
00007 of the License, or (at your option) any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 */
00018 
00019 #include "pent_include.h"
00020 #include "ShapeRenderedText.h"
00021 
00022 #include "ShapeFont.h"
00023 #include "RenderSurface.h"
00024 
00025 DEFINE_RUNTIME_CLASSTYPE_CODE(ShapeRenderedText,RenderedText);
00026 
00027 
00028 ShapeRenderedText::ShapeRenderedText(std::list<PositionedText>& lines_,
00029                                                                          int width_, int height_, int vlead_,
00030                                                                          ShapeFont* font_)
00031         : lines(lines_), font(font_)
00032 {
00033         width = width_;
00034         height = height_;
00035         vlead = vlead_;
00036 }
00037 
00038 ShapeRenderedText::~ShapeRenderedText()
00039 {
00040 
00041 }
00042 
00043 void ShapeRenderedText::draw(RenderSurface* surface, int x, int y, bool /*destmasked*/)
00044 {
00045         // TODO support masking here???
00046 
00047         std::list<PositionedText>::iterator iter;
00048 
00049         for (iter = lines.begin(); iter != lines.end(); ++iter)
00050         {
00051                 int line_x = x + iter->dims.x;
00052                 int line_y = y + iter->dims.y;
00053 
00054                 std::size_t textsize = iter->text.size();
00055 
00056                 for (std::size_t i = 0; i < textsize; ++i) {
00057                         surface->Paint(font, static_cast<unsigned char>(iter->text[i]),
00058                                                    line_x, line_y);
00059 
00060                         if (i == iter->cursor) {
00061                                 surface->Fill32(0xFF000000, line_x, line_y-font->getBaseline(),
00062                                                                 1, iter->dims.h);
00063                         }
00064 
00065                         line_x += font->getWidth(iter->text[i])-font->getHlead();
00066                 }
00067 
00068                 if (iter->cursor == textsize) {
00069                         surface->Fill32(0xFF000000, line_x, line_y-font->getBaseline(),
00070                                                         1, iter->dims.h);
00071                 }
00072         }
00073 }
00074 
00075 void ShapeRenderedText::drawBlended(RenderSurface* surface, int x, int y,
00076                                                                         uint32 col, bool /*destmasked*/)
00077 {
00078         // TODO Support masking here ????
00079 
00080         std::list<PositionedText>::iterator iter;
00081 
00082         for (iter = lines.begin(); iter != lines.end(); ++iter)
00083         {
00084                 int line_x = x + iter->dims.x;
00085                 int line_y = y + iter->dims.y;
00086 
00087                 std::size_t textsize = iter->text.size();
00088 
00089                 for (std::size_t i = 0; i < textsize; ++i) {
00090                         surface->PaintHighlight(font,
00091                                                                         static_cast<unsigned char>(iter->text[i]),
00092                                                                         line_x, line_y, false, false, col);
00093                         line_x += font->getWidth(iter->text[i])-font->getHlead();
00094                 }
00095                 
00096         }
00097 }

Generated on Fri Jul 27 22:27:37 2007 for pentagram by  doxygen 1.4.7