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; return texture;
} }
TextBox::TextBox() { TextLine::TextLine() {
// //
} }
TextBox::~TextBox() { TextLine::~TextLine() {
ClearText(); 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_Rect dclip = {posX, posY, 0, 0};
SDL_QueryTexture(texture, nullptr, nullptr, &dclip.w, &dclip.h); SDL_QueryTexture(texture, nullptr, nullptr, &dclip.w, &dclip.h);
SDL_RenderCopy(renderer, texture, nullptr, &dclip); 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 //just use the above global function
SDL_DestroyTexture(texture); SDL_DestroyTexture(texture);
texture = renderTextTexture(renderer, font, str, color); texture = renderTextTexture(renderer, font, str, color);
} }
void TextBox::AddText(SDL_Renderer* renderer, TTF_Font* font, std::string str, SDL_Color color) { void TextLine::ClearText() {
//TODO: empty
}
void TextBox::ClearText() {
SDL_DestroyTexture(texture); 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); SDL_Texture* renderTextTexture(SDL_Renderer*, TTF_Font*, std::string, SDL_Color color);
class TextBox { class TextLine {
public: public:
TextBox(); TextLine();
~TextBox(); ~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 SetText(SDL_Renderer*, TTF_Font*, std::string, SDL_Color color);
void AddText(SDL_Renderer*, TTF_Font*, std::string, SDL_Color color);
void ClearText(); 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: protected:
SDL_Texture* texture = nullptr; 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); button.SetY(200);
// {140, 62, 54, 255} // {140, 62, 54, 255}
//DEBUG: testing TextBox //DEBUG: testing textLine
textBox.SetY(500); textLine.SetText(GetRenderer(), font, "Button Text", {255, 255, 255, 255});
textBox.SetText(GetRenderer(), font, "Button Text", {255, 255, 255, 255});
} }
ExampleScene::~ExampleScene() { ExampleScene::~ExampleScene() {
@@ -95,7 +94,7 @@ void ExampleScene::RenderFrame(SDL_Renderer* renderer) {
//DEBUG: testing UI //DEBUG: testing UI
button.DrawTo(renderer); button.DrawTo(renderer);
textBox.DrawTo(renderer); textLine.DrawTo(renderer, 0, 550);
} }
//------------------------- //-------------------------
+1 -1
View File
@@ -67,5 +67,5 @@ private:
TTF_Font* font = nullptr; TTF_Font* font = nullptr;
Image buttonBG; Image buttonBG;
Button button; Button button;
TextBox textBox; TextLine textLine;
}; };