-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathText.cpp
More file actions
42 lines (37 loc) · 1.41 KB
/
Copy pathText.cpp
File metadata and controls
42 lines (37 loc) · 1.41 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
34
35
36
37
38
39
40
41
42
#include "Text.h"
Text::Text(std::string value_, TTF_Font* font_){
value = value_;
font = font_;
}
void Text::setString(std::string newValue){
value = newValue;
}
std::string Text::getString(){
return value;
}
void Text::drawSolid(SDL_Renderer* renderer, SDL_Rect* dstRect, SDL_Color color){
SDL_Surface* textSurface = TTF_RenderUTF8_Solid(font, value.c_str(), color);
if(textSurface == NULL){
SDL_Log("Error when create text surface: %s", SDL_GetError());
}
SDL_Texture* textTexture = SDL_CreateTextureFromSurface(renderer, textSurface);
if(textTexture == NULL){
SDL_Log("Error when create texture from text surface: %s", SDL_GetError());
}
SDL_FreeSurface(textSurface);
SDL_RenderCopy(renderer, textTexture, NULL, dstRect);
SDL_DestroyTexture(textTexture);
}
void Text::drawBlended(SDL_Renderer* renderer, SDL_Rect* dstRect, SDL_Color color){
SDL_Surface* textSurface = TTF_RenderUTF8_Blended(font, value.c_str(), color);
if(textSurface == NULL){
SDL_Log("Error when create text surface: %s", SDL_GetError());
}
SDL_Texture* textTexture = SDL_CreateTextureFromSurface(renderer, textSurface);
if(textTexture == NULL){
SDL_Log("Error when create texture from text surface: %s", SDL_GetError());
}
SDL_FreeSurface(textSurface);
SDL_RenderCopy(renderer, textTexture, NULL, dstRect);
SDL_DestroyTexture(textTexture);
}