-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathText.cpp
76 lines (66 loc) · 1.21 KB
/
Text.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "Text.h"
#include "MyWindow.h"
#include <iostream>
#include <string>
Text::Text(LWindow &window, std::string txt, TTF_Font *font, SDL_Color textColor) : mWindow(window), mText(txt), mTextColor(textColor), mFont(font)
{
if (txt != "")
{
mWindow.loadText(mTexture, txt, font, textColor);
}
}
int Text::getWidth()
{
return mText != "" ? mTexture.getWidth() : 0;
}
int Text::getHeight()
{
return mText != "" ? mTexture.getHeight() : 0;
}
void Text::render(SDL_Renderer *renderer, int x, int y)
{
if (mText != "")
{
mTexture.render(renderer, x, y);
}
}
void Text::cleanUp()
{
if (mText != "")
{
mTexture.free();
}
}
void Text::setText(std::string txt)
{
mText = txt;
mTexture.free();
if (mText != "")
{
mWindow.loadText(mTexture, txt, mFont, mTextColor);
}
}
int Text::length()
{
return mText.length();
}
std::string Text::getText()
{
return mText;
}
void Text::pop_back()
{
if (mText != "")
{
mText.pop_back();
mTexture.free();
if (mText != "")
{
mWindow.loadText(mTexture, mText, mFont, mTextColor);
}
}
}
SDL_Color Text::getColor()
{
return mTextColor;
}