Bubba-3D  0.9.0
Awesome game engine!
TextLayout.cpp
1 /*
2  * This file is part of Bubba-3D.
3  *
4  * Bubba-3D is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Bubba-3D is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with Bubba-3D. If not, see http://www.gnu.org/licenses/.
16  */
17 #include <TextLayout.h>
18 #include <IHudDrawable.h>
19 #include <TextObject.h>
20 
21 TextLayout::TextLayout(std::string text, Font* font, Dimension width, Dimension height):
22  text(text),
23  font(font),
24  width(width),
25  height(height) {
26 }
27 
28 Dimension TextLayout::getWidth() {
29  return width;
30 }
31 
32 Dimension TextLayout::getHeight() {
33  return height;
34 }
35 
36 void TextLayout::setText(std::string text) {
37  this->text = text;
38 }
39 
41  this->textId = id;
42  return this;
43 }
44 
45 TextLayout* TextLayout::setPadding(int pixels) {
46  setPadding(pixels,pixels);
47  return this;
48 }
49 
50 TextLayout* TextLayout::setPadding(int topAndBottom, int rightAndLeft) {
51  setPadding(topAndBottom,rightAndLeft,topAndBottom,rightAndLeft);
52  return this;
53 }
54 
55 TextLayout* TextLayout::setPadding(int top, int right, int bot, int left) {
56  padding[0] = top;
57  padding[1] = right;
58  padding[2] = bot;
59  padding[3] = left;
60  return this;
61 }
62 
63 void TextLayout::getGLSquares(float layoutXPos, float layoutYPos, float layoutWidth, float layoutHeight,
64  std::map<std::string, IHudDrawable *> *map) {
65 
66  Layout::getGLSquares(layoutXPos, layoutYPos, layoutWidth, layoutHeight, map);
67 
68  TextObject* textDrawer = new TextObject(text,font,layoutWidth-(padding[1]+padding[3]),
69  layoutHeight-(padding[0]+padding[2]),
70  layoutXPos + padding[3],padding[0]+layoutYPos);
71 
72  map->insert(std::pair<std::string, IHudDrawable*>(textId == "" ? getNextRandId() : textId,textDrawer));
73 }
Definition: Font.h:27
virtual std::map< std::string, IHudDrawable * > getGLSquares(float layoutXPos, float layoutYPos, float layoutWidth, float layoutHeight)
Definition: Layout.cpp:34
virtual void getGLSquares(float layoutXPos, float layoutYPos, float layoutWidth, float layoutHeight, std::map< std::string, IHudDrawable * > *map)
Definition: TextLayout.cpp:63
TextLayout * setTextId(std::string id)
Definition: TextLayout.cpp:40
TextLayout(std::string text, Font *font, Dimension width, Dimension height)
Definition: TextLayout.cpp:21
void setText(std::string text)
Definition: TextLayout.cpp:36