Changed TextBox to TextLine

This commit is contained in:
2015-08-13 22:46:45 +10:00
parent 8b0d2a700e
commit d618023a91
4 changed files with 13 additions and 26 deletions
+5 -9
View File
@@ -45,30 +45,26 @@ SDL_Texture* renderTextTexture(SDL_Renderer* renderer, TTF_Font* font, std::stri
return texture;
}
TextBox::TextBox() {
TextLine::TextLine() {
//
}
TextBox::~TextBox() {
TextLine::~TextLine() {
ClearText();
}
void TextBox::DrawTo(SDL_Renderer* renderer) {
void TextLine::DrawTo(SDL_Renderer* renderer, int posX, int posY) {
SDL_Rect dclip = {posX, posY, 0, 0};
SDL_QueryTexture(texture, nullptr, nullptr, &dclip.w, &dclip.h);
SDL_RenderCopy(renderer, texture, nullptr, &dclip);
}
void TextBox::SetText(SDL_Renderer* renderer, TTF_Font* font, std::string str, SDL_Color color) {
void TextLine::SetText(SDL_Renderer* renderer, TTF_Font* font, std::string str, SDL_Color color) {
//just use the above global function
SDL_DestroyTexture(texture);
texture = renderTextTexture(renderer, font, str, color);
}
void TextBox::AddText(SDL_Renderer* renderer, TTF_Font* font, std::string str, SDL_Color color) {
//TODO: empty
}
void TextBox::ClearText() {
void TextLine::ClearText() {
SDL_DestroyTexture(texture);
}
+4 -12
View File
@@ -30,24 +30,16 @@ constexpr SDL_Color COLOR_WHITE = {255, 255, 255, 255};
SDL_Texture* renderTextTexture(SDL_Renderer*, TTF_Font*, std::string, SDL_Color color);
class TextBox {
class TextLine {
public:
TextBox();
~TextBox();
TextLine();
~TextLine();
void DrawTo(SDL_Renderer*);
void DrawTo(SDL_Renderer*, int posX, int posY);
void SetText(SDL_Renderer*, TTF_Font*, std::string, SDL_Color color);
void AddText(SDL_Renderer*, TTF_Font*, std::string, SDL_Color color);
void ClearText();
//position
int SetX(int x) { return posX = x; }
int SetY(int y) { return posY = y; }
int SetX() { return posX; }
int SetY() { return posY; }
protected:
SDL_Texture* texture = nullptr;
int posX = 0, posY = 0;
};
+3 -4
View File
@@ -62,9 +62,8 @@ ExampleScene::ExampleScene(lua_State* L) {
button.SetY(200);
// {140, 62, 54, 255}
//DEBUG: testing TextBox
textBox.SetY(500);
textBox.SetText(GetRenderer(), font, "Button Text", {255, 255, 255, 255});
//DEBUG: testing textLine
textLine.SetText(GetRenderer(), font, "Button Text", {255, 255, 255, 255});
}
ExampleScene::~ExampleScene() {
@@ -95,7 +94,7 @@ void ExampleScene::RenderFrame(SDL_Renderer* renderer) {
//DEBUG: testing UI
button.DrawTo(renderer);
textBox.DrawTo(renderer);
textLine.DrawTo(renderer, 0, 550);
}
//-------------------------
+1 -1
View File
@@ -67,5 +67,5 @@ private:
TTF_Font* font = nullptr;
Image buttonBG;
Button button;
TextBox textBox;
TextLine textLine;
};