Skip to content

Commit

Permalink
[TextInput] Fixed background. [InterfaceState] Added setting to be ab…
Browse files Browse the repository at this point in the history
…le to not display the background.
  • Loading branch information
Unarelith committed Feb 20, 2020
1 parent 836e92e commit d208a0c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
8 changes: 6 additions & 2 deletions client/include/gui/TextInput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,20 @@ class TextInput : public gk::Drawable, public gk::Transformable {

void onEvent(const SDL_Event &event);

void setBackgroundColor(const gk::Color &color) { m_background.setFillColor(color); }
void setBackgroundSize(unsigned int width, unsigned int height) { m_background.setSize(width, height); }

void setPadding(int x, int y) { m_text.setPosition(x, y); }

private:
void draw(gk::RenderTarget &target, gk::RenderStates states) const override;

Text m_text;
std::string m_content;
char m_cursor = '_';

u16 m_characterLimit = 0;

char m_cursor = '_';

gk::RectangleShape m_background;
};

Expand Down
2 changes: 2 additions & 0 deletions client/include/states/InterfaceState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class InterfaceState : public gk::ApplicationState {

void prepareDraw(gk::RenderTarget &target, gk::RenderStates &states) const;

bool m_drawBackground = true;

private:
gk::Shader m_shader;
// gk::View m_view;
Expand Down
4 changes: 3 additions & 1 deletion client/source/gui/TextInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
*
* =====================================================================================
*/
#include <gk/resource/ResourceHandler.hpp>

#include "TextInput.hpp"

TextInput::TextInput() {
Expand Down Expand Up @@ -48,7 +50,7 @@ void TextInput::onEvent(const SDL_Event &event) {
void TextInput::draw(gk::RenderTarget &target, gk::RenderStates states) const {
states.transform *= getTransform();

target.draw(m_text, states);
target.draw(m_background, states);
target.draw(m_text, states);
}

5 changes: 5 additions & 0 deletions client/source/states/ChatState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ ChatState::ChatState(gk::ApplicationState *parent) : InterfaceState(parent) {
gk::Mouse::setCursorVisible(true);
gk::Mouse::resetToWindowCenter();

m_drawBackground = false;

m_textInput.setScale(Config::guiScale, Config::guiScale);
m_textInput.setBackgroundColor(gk::Color{0, 0, 0, 127});
m_textInput.setBackgroundSize(200, 10);
m_textInput.setPadding(1, 1);
}

void ChatState::onEvent(const SDL_Event &event) {
Expand Down
2 changes: 1 addition & 1 deletion client/source/states/InterfaceState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void InterfaceState::prepareDraw(gk::RenderTarget &target, gk::RenderStates &sta

// target.setView(m_view);

if (m_parent)
if (m_parent && m_drawBackground)
target.draw(m_background, states);
}

0 comments on commit d208a0c

Please sign in to comment.