From 2b7d030551a357272f9cc39e347855bd2e3faba2 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 7 May 2018 23:00:21 +0200 Subject: Improve text editing, use Text object for chatbar Improve text rendering by not using floating point position --- include/Chatbar.hpp | 20 ++++---------------- include/Text.hpp | 6 ++++++ 2 files changed, 10 insertions(+), 16 deletions(-) (limited to 'include') diff --git a/include/Chatbar.hpp b/include/Chatbar.hpp index 27b57f9..5d69448 100644 --- a/include/Chatbar.hpp +++ b/include/Chatbar.hpp @@ -1,7 +1,8 @@ #pragma once #include "StringView.hpp" -#include +#include "Text.hpp" +#include "Cache.hpp" #include #include #include @@ -18,20 +19,10 @@ namespace dchat public: Chatbar(); - void addChar(sf::Uint32 codePoint); - void addString(const std::string &strToAdd); - const sf::String& getString() const; - void removePreviousChar(); - void removeNextChar(); - void clear(); - - void moveCaretLeft(); - void moveCaretRight(); - bool isFocused() const; void processEvent(const sf::Event &event, Channel *channel); - void draw(sf::RenderWindow &window); + void draw(sf::RenderWindow &window, Cache &cache); static float getHeight(); @@ -41,12 +32,9 @@ namespace dchat private: void processChatCommand(const StringView &cmd); private: - sf::Text text; + Text text; sf::RectangleShape background; sf::RectangleShape inputBackground; - int caretIndex; - sf::Vector2f caretOffset; - sf::Clock blinkTimer; bool focused; }; } diff --git a/include/Text.hpp b/include/Text.hpp index 0bc3ced..d2809de 100644 --- a/include/Text.hpp +++ b/include/Text.hpp @@ -36,11 +36,17 @@ namespace dchat Text(const sf::String &str, const sf::Font *font, unsigned int characterSize, float maxWidth, bool plainText = true); void setString(const sf::String &str); + const sf::String& getString() const; void setPosition(float x, float y); void setPosition(const sf::Vector2f &position); void setMaxWidth(float maxWidth); + void setCharacterSize(unsigned int characterSize); + unsigned int getCharacterSize() const; + + const sf::Font* getFont() const; + void setFillColor(sf::Color color); void setLineSpacing(float lineSpacing); void setEditable(bool editable); -- cgit v1.2.3