-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtextBox.cpp
More file actions
62 lines (51 loc) · 1.7 KB
/
Copy pathtextBox.cpp
File metadata and controls
62 lines (51 loc) · 1.7 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
#include "textBox.h"
textBox::textBox(const char* textInput, const char* fontType, SDL_Color textColor, int textSize, SDL_Renderer *textRenderer)
{
text_color = textColor;
updated = false;
TTF_Init();
textBox::textInput = textInput;
textBox::fontType = fontType;
textBox::textSize = textSize;
textBox::textRenderer = textRenderer;
SDL_Surface *message;
font = TTF_OpenFont(textBox::fontType, textBox::textSize);
TTF_SetFontStyle(font, NULL);
message = TTF_RenderText_Blended(font,textBox::textInput,textColor);
textTexture = SDL_CreateTextureFromSurface(textBox::textRenderer,message);
SDL_FreeSurface(message);
SDL_QueryTexture(textTexture, NULL, NULL, &src.w, &src.h);
src.x = src.y = 0;
dst.h = src.h;
dst.w = src.w;
}
textBox::~textBox()
{
SDL_DestroyTexture(textTexture);
textRenderer = NULL;
font = NULL;
}
void textBox::render(int pX, int pY){
dst.x = pX;
dst.y = pY;
SDL_RenderCopy(textRenderer, textTexture, &src, &dst);
}
void textBox::render_fading(int pX, int pY){
SDL_SetTextureAlphaMod(textTexture, ((SDL_GetTicks() / 100) % 16)*16);
render(pX, pY);
}
void textBox::update_text(const char* textInput, SDL_Color text_color){
textBox::textInput = textInput;
SDL_Surface *message;
font = TTF_OpenFont(textBox::fontType, textBox::textSize);
TTF_SetFontStyle(font, NULL);
message = TTF_RenderText_Solid(font, textBox::textInput, text_color);
SDL_DestroyTexture(textTexture);
textTexture = SDL_CreateTextureFromSurface(textBox::textRenderer, message);
SDL_FreeSurface(message);
SDL_QueryTexture(textTexture, NULL, NULL, &src.w, &src.h);
src.x = src.y = 0;
dst.h = src.h;
dst.w = src.w;
updated = true;
}