-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLabel.cpp
More file actions
33 lines (33 loc) · 1.01 KB
/
Label.cpp
File metadata and controls
33 lines (33 loc) · 1.01 KB
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
//Code written by Christian Neij
#include "Label.h"
#include <SDL_ttf.h>
#include "System.h"
#include <string>
namespace minMotor {
Label* Label::getInstance(int x, int y, int w, int h, std::string txt) {
return new Label(x, y, w, h, txt);
}
Label::Label(int x, int y, int w, int h, std::string txt) : NonCollideAbleSprite(x, y, w, h), text(txt)
{
SDL_Surface* surf = TTF_RenderText_Solid(sys.getFont(), text.c_str(), { 0,0,0 });
texture = SDL_CreateTextureFromSurface(sys.getRen(), surf);
SDL_FreeSurface(surf);
}
void Label::draw() const {
SDL_RenderCopy(sys.getRen(), texture, NULL, &getRect());
}
Label::~Label()
{
SDL_DestroyTexture(texture);
}
std::string Label::getText() const {
return text;
}
void Label::setText(std::string newText) {
text = newText;
SDL_DestroyTexture(texture);
SDL_Surface* surf = TTF_RenderText_Solid(sys.getFont(), text.c_str(), { 0,0,0 });
texture = SDL_CreateTextureFromSurface(sys.getRen(), surf);
SDL_FreeSurface(surf);
}
}