-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMessageScreen.cpp
97 lines (87 loc) · 2.55 KB
/
MessageScreen.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "MessageScreen.h"
#include <iostream>
using namespace widgets;
MessageScreen::MessageScreen()
{
}
MessageScreen::~MessageScreen()
{
}
MessageScreen::MessageScreen(const int &x, const int &y, const int &width, const int &height, SDL_Texture *newtexture, SDL_Renderer *renderer, const bool &mini){
rect.x = x;
rect.y = y;
rect.w = width;
rect.h = height;
texture = newtexture;
color.a = 50;
color.b = 50;
color.g = 50;
color.r = 50;
timer = 0;
timeout = 0;
hxmlFile = new rapidxml::file<>("assets//xml//message_plaque_config.xml");
hdoc.parse<0>(hxmlFile->data());
hpRoot = hdoc.first_node();
if (!mini){
gNode = hpRoot->last_node("config");
}
else{
gNode = hpRoot->first_node("config");
}
pNode = gNode->first_node("message_plaque");
msg_pos.x = atoi(pNode->first_node("message_text")->first_node("pos")->first_node("x")->value());
msg_pos.y = atoi(pNode->first_node("message_text")->first_node("pos")->first_node("y")->value());
font_size = atoi(pNode->first_node("message_text")->first_node("font_size")->value());
font = pNode->first_node("message_text")->first_node("font")->value();
render_msg = new TtfWrapper(rect.x + msg_pos.x, rect.y + msg_pos.y, 50, 50, 50, SDL_BLENDMODE_BLEND, 0, color, font_size, font,600, true);
render_msg->loadFromRenderedText(renderer);
setTimer(0);
setTimeOut(0);
visible = false;
locked = false;
}
void MessageScreen::addMessage(const std::string &_msg){
msg = _msg;
render_msg->text = msg;
}
SDL_Texture* MessageScreen::loadTexture(std::string path, SDL_Renderer *renderer){
//The final texture
SDL_Texture* newTexture = NULL;
//Load image at specified path
SDL_Surface* loadedSurface = IMG_Load(path.c_str());
if (loadedSurface == NULL)
{
printf("Unable to load image %s! SDL_image Error: %s\n", path.c_str(), IMG_GetError());
}
else
{
//Create texture from surface pixels
newTexture = SDL_CreateTextureFromSurface(renderer, loadedSurface);
if (newTexture == NULL)
{
printf("Unable to create texture from %s! SDL Error: %s\n", path.c_str(), SDL_GetError());
}
//Get rid of old loaded surface
SDL_FreeSurface(loadedSurface);
}
return newTexture;
}
long MessageScreen::getTimeout(){
return timeout;
}
void MessageScreen::setTimeOut(const long &time){
timeout = time;
}
void MessageScreen::setTimer(const long &time){
timer = time;
}
long MessageScreen::getTimer(){
return timer;
}
void MessageScreen::Render(SDL_Renderer *renderer){
if (visible){
SDL_RenderCopy(renderer, texture, NULL, &rect);
render_msg->loadFromRenderedText(renderer);
render_msg->Render(renderer);
}
}