src/graphic/text.h File Reference

#include <string>
#include "colors.h"
#include "font.h"
#include "surface.h"

Include dependency graph for text.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  Text

Functions

void DrawTmpBoxText (Font &font, Point2i pos, const std::string &txt, uint space=3, Color boxColor=defaultColorBox, Color rectColor=defaultColorRect)
void DrawTmpBoxTextWithReturns (Font &font, const Point2i &position, const std::string &txt, uint space=3, Color boxColor=defaultColorBox, Color rectColor=defaultColorRect)


Function Documentation

void DrawTmpBoxText ( Font font,
Point2i  pos,
const std::string &  txt,
uint  space = 3,
Color  boxColor = defaultColorBox,
Color  rectColor = defaultColorRect 
)

Definition at line 302 of file text.cpp.

00305 {
00306   Point2i size = font.GetSize(txt) + Point2i(space, space)*2;
00307   
00308   pos.y -= font.GetHeight(txt)/2;
00309 
00310   Rectanglei rect( pos - size/2, size);
00311   
00312   AppWormux * app = AppWormux::GetInstance();
00313 
00314   app->video.window.BoxColor(rect, boxColor);
00315   app->video.window.RectangleColor(rect, rectColor);  
00316 
00317   world.ToRedrawOnScreen( rect );
00318   font.WriteCenterTop( pos, txt, white_color);
00319 }

Here is the call graph for this function:

Here is the caller graph for this function:

void DrawTmpBoxTextWithReturns ( Font font,
const Point2i position,
const std::string &  txt,
uint  space = 3,
Color  boxColor = defaultColorBox,
Color  rectColor = defaultColorRect 
)

Definition at line 321 of file text.cpp.

00325 {
00326   size_t pos          = 0;
00327   size_t last_pos     = 0;
00328   size_t max_width    = 0;
00329   size_t total_height = 0;
00330   int    x, y;
00331   char  *lines        = strdup(txt.c_str());
00332 
00333   std::vector< size_t > offsets;
00334 
00335   // Store offsets
00336   offsets.push_back(0);
00337   while (lines[pos] != '\0')
00338   {
00339     if (lines[pos] == '\n')
00340     {
00341       lines[pos] = 0;
00342       if (!lines[pos+1]) break;
00343 
00344       offsets.push_back(pos+1);
00345       int w = font.GetWidth(lines+last_pos) + space*2;
00346       if ((int)max_width < w) max_width = w;
00347       total_height += font.GetHeight(lines+last_pos);
00348 #if DEBUG
00349       if (last_pos)
00350       {
00351         std::cerr << "(" << pos << "," << pos-last_pos
00352                   << ") >>> " << lines+last_pos << " <<<\n";
00353       }
00354 #endif
00355       last_pos = pos+1;
00356     }
00357     pos++;
00358   }
00359   if (max_width == 0) {
00360     max_width = font.GetWidth(lines) + space*2;
00361   }
00362 
00363   // Initial position
00364   total_height += 5*space;
00365   x = position.x - max_width / 2;
00366   y = position.y - total_height / 2;
00367 
00368   Rectanglei rect(x, y, max_width, total_height);
00369   
00370   AppWormux * app = AppWormux::GetInstance();
00371 
00372   app->video.window.BoxColor(rect, boxColor);
00373   app->video.window.RectangleColor(rect, rectColor);
00374 
00375   world.ToRedrawOnScreen(rect);
00376 
00377   for( std::vector<size_t>::iterator it=offsets.begin();
00378        it != offsets.end();
00379        ++it)
00380   {
00381     font.WriteLeft( Point2i(x+space, y+space), lines+(*it), white_color);
00382     y += font.GetHeight(lines+(*it));
00383   }
00384   offsets.clear();
00385   free(lines);
00386 }

Here is the call graph for this function:

Here is the caller graph for this function:


Generated on Mon Jan 1 13:14:10 2007 for Wormux by  doxygen 1.4.7