-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextObject.cpp
More file actions
83 lines (73 loc) · 1.76 KB
/
Copy pathTextObject.cpp
File metadata and controls
83 lines (73 loc) · 1.76 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
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
#include "game.h"
#include "TextObject.h"
#include <SDL_ttf.h>
#include <string>
TextObject::TextObject()
{
text_color.r = 255;
text_color.g = 255;
text_color.b = 255;
texture = NULL;
}
TextObject::~TextObject()
{
}
bool TextObject::loadFromRenderText(TTF_Font* font, SDL_Renderer* renderer)
{
SDL_Surface* text_surface = TTF_RenderText_Solid(font, str_val.c_str(), text_color);
if (text_surface)
{
texture = SDL_CreateTextureFromSurface(renderer, text_surface);
mWidth = text_surface->w;
mHeight = text_surface->h;
SDL_FreeSurface(text_surface);
}
return texture != NULL;
}
void TextObject::free()
{
if (texture != NULL)
{
SDL_DestroyTexture(texture);
texture = NULL;
}
}
void TextObject::setColor( Uint8 red, Uint8 green, Uint8 blue )
{
text_color.r = red;
text_color.g = green;
text_color.b = blue;
}
void TextObject::setColor(int type)
{
if (type == Red_Text)
{
SDL_Color color = {255,0,0};
text_color = color;
}
else if(type == White_Text)
{
SDL_Color color = {255,255,255};
text_color = color;
}
else if(type == Black_Text)
{
SDL_Color color = {0,0,0};
text_color = color;
}
}
void TextObject::render( SDL_Renderer* renderer,
int x, int y,
SDL_Rect* clip /*= NULL*/,
double angle /*= 0.0*/,
SDL_Point* center /*= NULL*/,
SDL_RendererFlip flip /*= SDL_FLIP_NONE*/ )
{
SDL_Rect renderQuad = {x,y,mWidth,mHeight};
if (clip != NULL)
{
renderQuad.w = clip->w;
renderQuad.h = clip->h;
}
SDL_RenderCopyEx(renderer, texture, clip, &renderQuad, angle, center, flip);
}