aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-05-06 17:15:51 +0200
committerdec05eba <dec05eba@protonmail.com>2018-05-06 17:18:19 +0200
commit7a2cb2c4b81a8a0696d3a11ce8781542f181bb12 (patch)
tree0d77fa05f4a99c4c1ff06f12ba76fae62550fc9b /include
parentb2f6a0235c5de32a3fcd359e28f4d1e3bd6950df (diff)
Make dchat Text editable
Not finished yet. Currently text can be entered, removed and you can move caret using arrow keys (up, down, left, right), home and end. Need to implement text selection and remove focus from chatbar when editing message board text. Chatbar should be replaced with dchat Text for proper multiline editable text.
Diffstat (limited to 'include')
-rw-r--r--include/Text.hpp31
1 files changed, 29 insertions, 2 deletions
diff --git a/include/Text.hpp b/include/Text.hpp
index daea7ca..9df973d 100644
--- a/include/Text.hpp
+++ b/include/Text.hpp
@@ -5,6 +5,7 @@
#include <SFML/Graphics/VertexArray.hpp>
#include <SFML/Graphics/Font.hpp>
#include <SFML/Graphics/RenderTarget.hpp>
+#include <SFML/Window/Event.hpp>
#include <SFML/System/String.hpp>
#include <vector>
@@ -35,7 +36,6 @@ 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);
- void appendStringNewLine(const sf::String &str);
void setPosition(float x, float y);
void setPosition(const sf::Vector2f &position);
@@ -43,16 +43,36 @@ namespace dchat
void setCharacterSize(unsigned int characterSize);
void setFillColor(sf::Color color);
void setLineSpacing(float lineSpacing);
+ void setEditable(bool editable);
// Warning: won't update until @draw is called
float getHeight() const;
+ void processEvent(const sf::Event &event);
+
// Performs culling. @updateGeometry is called even if text is not visible if text is dirty, because updateGeometry might change the dimension of the text and make is visible
void draw(sf::RenderTarget &target, Cache &cache);
private:
+ enum class CaretMoveDirection : u8
+ {
+ NONE,
+ UP,
+ DOWN,
+ HOME,
+ END
+ };
+
void stringSplitElements(sf::String &stringToSplit, usize startIndex);
void updateGeometry();
- private:
+ void updateCaret();
+ bool isCaretAtEnd() const;
+ int getStartOfLine(int startIndex) const;
+ int getEndOfLine(int startIndex) const;
+ int getRowByPosition(const sf::Vector2f &position) const;
+
+ int getPreviousLineClosestPosition(int startIndex) const;
+ int getNextLineClosestPosition(int startIndex) const;
+ private:
sf::String str;
const sf::Font *font;
unsigned int characterSize;
@@ -62,9 +82,16 @@ namespace dchat
sf::Color color;
sf::Color urlColor;
bool dirty;
+ bool dirtyText;
+ bool dirtyCaret;
bool plainText;
+ bool editable;
+ CaretMoveDirection caretMoveDirection;
float totalHeight;
float lineSpacing;
std::vector<TextElement> textElements;
+
+ int caretIndex;
+ sf::Vector2f caretPosition;
};
}