From 676f0937ecd1b5b8cbc590e07a4f9dead26021a8 Mon Sep 17 00:00:00 2001 From: Quentin Bazin Date: Fri, 21 Feb 2020 15:51:57 +0900 Subject: [PATCH] [ChatState] TextInput is now positionned correctly. --- client/include/states/ChatState.hpp | 2 ++ client/source/gui/TextInput.cpp | 2 ++ client/source/states/ChatState.cpp | 12 +++++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/client/include/states/ChatState.hpp b/client/include/states/ChatState.hpp index 95c1a1fb1..c349bf48e 100644 --- a/client/include/states/ChatState.hpp +++ b/client/include/states/ChatState.hpp @@ -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; diff --git a/client/source/gui/TextInput.cpp b/client/source/gui/TextInput.cpp index dfa5afd8f..ae9ac1d97 100644 --- a/client/source/gui/TextInput.cpp +++ b/client/source/gui/TextInput.cpp @@ -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) { diff --git a/client/source/states/ChatState.cpp b/client/source/states/ChatState.cpp index 2adab99dc..8c339d874 100644 --- a/client/source/states/ChatState.cpp +++ b/client/source/states/ChatState.cpp @@ -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);