1 /******************************************************************************
2  *  Warmux is a convivial mass murder game.
3  *  Copyright (C) 2007 Jon de Andres
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
18  ******************************************************************************
19  * List of Text Clases.
20  * TextBox is not valid while playing game
21  * nefertum - Jon de Andres
22  *****************************************************************************/
23 
24 #include "graphic/text_list.h"
25 #include "graphic/text.h"
26 
~TextList()27 TextList::~TextList()
28 {
29   for (std::list<Text*>::iterator t=list.begin(); t!=list.end(); t++)
30      delete *t;
31 
32   list.clear();
33 }
34 
AddText(const std::string & txt,const Color & color,uint maxlines)35 void TextList::AddText(const std::string &txt, const Color& color, uint maxlines){
36   Text* new_txt = new Text(txt, color);
37   list.push_back(new_txt);
38 
39   if(list.size() >= maxlines)
40     list.pop_front();
41 }
42 
Draw(int x,int y,int height)43 void TextList::Draw(int x, int y, int height){
44   iterator it = list.begin(), end = list.end();
45 
46   for(; it!=end; it++){
47     //Draw each item in the list
48     (*it)->DrawLeftTop(Point2i(x, y));
49     y+=height;
50   }
51 }
52 
DrawLine(const Text * newline,int x,int y,int height) const53 void TextList::DrawLine(const Text* newline, int x, int y, int height) const {
54   int size = list.size();
55 
56   y += (size * height);
57   newline->DrawLeftTop(Point2i(x, y));
58 }
59