diff --git a/src/common/text_box.cpp b/src/common/text_box.cpp index e80a014..be2c111 100644 --- a/src/common/text_box.cpp +++ b/src/common/text_box.cpp @@ -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); } diff --git a/src/common/text_box.hpp b/src/common/text_box.hpp index b606aa5..56561ff 100644 --- a/src/common/text_box.hpp +++ b/src/common/text_box.hpp @@ -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; }; \ No newline at end of file diff --git a/src/example_scene.cpp b/src/example_scene.cpp index 17172fd..46b81ba 100644 --- a/src/example_scene.cpp +++ b/src/example_scene.cpp @@ -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); } //------------------------- diff --git a/src/example_scene.hpp b/src/example_scene.hpp index 1feea6f..e5c7da6 100644 --- a/src/example_scene.hpp +++ b/src/example_scene.hpp @@ -67,5 +67,5 @@ private: TTF_Font* font = nullptr; Image buttonBG; Button button; - TextBox textBox; + TextLine textLine; };