forked from BYOBMO/BMOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCLabel.cpp
More file actions
83 lines (62 loc) · 1.63 KB
/
CLabel.cpp
File metadata and controls
83 lines (62 loc) · 1.63 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 "CLabel.h"
#include "CText.h"
#include "Utils.h"
#include "CApplication.h"
#include <functional>
CLabel::CLabel() : CWindow()
{
mBorder = false;
mCanFocus = false;
}
void CLabel::SetText(std::string title)
{
mText.SetText(CText::sFontLarge, title, CText::cBlack);
CreateBlank(mText.mTexW, mText.mTexH, SDL_TEXTUREACCESS_TARGET);
}
void CLabel::SetText(std::string title, TTF_Font* font)
{
mText.SetText(font, title, CText::cBlack);
CreateBlank(mText.mTexW, mText.mTexH, SDL_TEXTUREACCESS_TARGET);
}
void CLabel::SetText(std::string title, TTF_Font* font, int w, int h)
{
mText.SetText(font, title, CText::cBlack, w, h, CTexture::HAlignment::Left);
CreateBlank(mText.mTexW, mText.mTexH, SDL_TEXTUREACCESS_TARGET);
}
void CLabel::Resize(int w, int h)
{
CreateBlank(w, h, SDL_TEXTUREACCESS_TARGET);
}
void CLabel::OnTextEvent(SDL_TextInputEvent e)
{
mText.SetText(CText::sFontSmall, mText.mText + e.text, CText::cBlack, 300, 40, CTexture::HAlignment::Left);
}
void CLabel::Draw()
{
SDL_Renderer* renderer = CApplication::sRenderer;
Uint8 r, g, b, a;
if (mVisible == false)
{
return;
}
SDL_GetRenderDrawColor(renderer, &r, &g, &b, &a);
SDL_SetRenderDrawColor(renderer, RChannel(mDrawColor), GChannel(mDrawColor), BChannel(mDrawColor), 255);
SDL_Rect rect;
rect.x = X;
rect.y = Y;
rect.w = Width();
rect.h = mTexH;
SDL_RenderFillRect(renderer, &rect);
mText.SetPosition(X, Y);
mText.Draw();
if (mBorder)
{
rect.x = X;
rect.y = Y;
rect.w = mTexW;
rect.h = mTexH;
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderDrawRect(renderer, &rect);
}
SDL_SetRenderDrawColor(renderer, r, g, b, a);
}