Skip to content

Commit

Permalink
[ChatState] TextInput is now positionned correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
Unarelith committed Feb 21, 2020
1 parent 8b906d1 commit 676f093
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions client/include/states/ChatState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class ChatState : public InterfaceState {
public:
ChatState(gk::ApplicationState *parent = nullptr);

void updateTextInputGeometry();

void onEvent(const SDL_Event &event) override;

void update() override;
Expand Down
2 changes: 2 additions & 0 deletions client/source/gui/TextInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

TextInput::TextInput() {
m_background.setFillColor(gk::Color::Transparent);

m_text.setText(std::string{m_cursor});
}

void TextInput::onEvent(const SDL_Event &event) {
Expand Down
12 changes: 11 additions & 1 deletion client/source/states/ChatState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,27 @@ ChatState::ChatState(gk::ApplicationState *parent) : InterfaceState(parent) {

m_drawBackground = false;

updateTextInputGeometry();

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::updateTextInputGeometry() {
m_textInput.setPosition(4, Config::screenHeight - 35);
m_textInput.setBackgroundSize(Config::screenWidth / Config::guiScale - 4, 10);
}

void ChatState::onEvent(const SDL_Event &event) {
InterfaceState::onEvent(event);

m_textInput.onEvent(event);

if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
updateTextInputGeometry();
}

if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) {
gk::Mouse::setCursorGrabbed(true);
gk::Mouse::setCursorVisible(false);
Expand Down

0 comments on commit 676f093

Please sign in to comment.