aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-05-07 23:00:21 +0200
committerdec05eba <dec05eba@protonmail.com>2018-05-07 23:01:04 +0200
commit2b7d030551a357272f9cc39e347855bd2e3faba2 (patch)
tree93d9eabaf6ba62629b9258a4314338ac8f89fc2a /include
parent29bd3e7c65af79b3f8837c7786ffbda3c93c3ebb (diff)
Improve text editing, use Text object for chatbar
Improve text rendering by not using floating point position
Diffstat (limited to 'include')
-rw-r--r--include/Chatbar.hpp20
-rw-r--r--include/Text.hpp6
2 files changed, 10 insertions, 16 deletions
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 <SFML/Graphics/Text.hpp>
+#include "Text.hpp"
+#include "Cache.hpp"
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Graphics/RectangleShape.hpp>
#include <SFML/Window/Event.hpp>
@@ -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);