diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-09-28 13:32:34 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-09-28 13:32:34 +0200 |
commit | 4277763df5c1dac8ff389d3bfd138f03acc7f1e2 (patch) | |
tree | b0c3fc77ea601f105308d42840adb1ce2050b414 /include | |
parent | a16cfdc4f6cd14d576760c100a817c08f45be394 (diff) |
Implement text editing with navigation and multilingual fonts
Diffstat (limited to 'include')
-rw-r--r-- | include/Body.hpp | 6 | ||||
-rw-r--r-- | include/Entry.hpp | 37 | ||||
-rw-r--r-- | include/ImageViewer.hpp | 7 | ||||
-rw-r--r-- | include/SearchBar.hpp | 9 | ||||
-rw-r--r-- | include/Text.hpp | 30 |
5 files changed, 74 insertions, 15 deletions
diff --git a/include/Body.hpp b/include/Body.hpp index 35b3f30..a5c346e 100644 --- a/include/Body.hpp +++ b/include/Body.hpp @@ -1,10 +1,8 @@ #pragma once #include "Text.hpp" -#include <SFML/Graphics/Font.hpp> #include <SFML/Graphics/Text.hpp> #include <SFML/Graphics/Texture.hpp> -#include <SFML/Graphics/RenderWindow.hpp> #include <SFML/Graphics/RectangleShape.hpp> #include <SFML/Graphics/Sprite.hpp> #include "../external/RoundedRectangleShape.hpp" @@ -12,6 +10,10 @@ #include <thread> #include <future> +namespace sf { + class RenderWindow; +} + namespace QuickMedia { class Program; diff --git a/include/Entry.hpp b/include/Entry.hpp new file mode 100644 index 0000000..6f96e58 --- /dev/null +++ b/include/Entry.hpp @@ -0,0 +1,37 @@ +#pragma once + +#include "Text.hpp" +#include "../external/RoundedRectangleShape.hpp" +#include <SFML/Graphics/Text.hpp> +#include <functional> + +namespace sf { + class Font; + class Event; + class RenderWindow; +} + +namespace QuickMedia { + // Return true to clear the text + using OnEntrySubmit = std::function<bool(const sf::String& text)>; + + class Entry { + public: + Entry(const std::string &placeholder_text, sf::Font *font, sf::Font *cjk_font); + void process_event(sf::Event &event); + void draw(sf::RenderWindow &window); + + void set_editable(bool editable); + void set_position(const sf::Vector2f &pos); + void set_max_width(float width); + + float get_height(); + + OnEntrySubmit on_submit_callback; + private: + Text text; + float width; + sf::RoundedRectangleShape background; + sf::Text placeholder; + }; +}
\ No newline at end of file diff --git a/include/ImageViewer.hpp b/include/ImageViewer.hpp index fe0b6f3..b8063ee 100644 --- a/include/ImageViewer.hpp +++ b/include/ImageViewer.hpp @@ -3,14 +3,17 @@ #include "Path.hpp" #include <string> #include <vector> -#include <SFML/Graphics/RenderWindow.hpp> #include <SFML/Graphics/Texture.hpp> #include <SFML/Graphics/Sprite.hpp> -#include <SFML/Graphics/Font.hpp> #include <SFML/Graphics/Text.hpp> #include <SFML/System/Clock.hpp> +#include <SFML/Window/Cursor.hpp> #include <thread> +namespace sf { + class RenderWindow; +} + namespace QuickMedia { class Manga; diff --git a/include/SearchBar.hpp b/include/SearchBar.hpp index a90c69d..8a1a8a0 100644 --- a/include/SearchBar.hpp +++ b/include/SearchBar.hpp @@ -1,13 +1,18 @@ #pragma once -#include <SFML/Graphics/RenderWindow.hpp> -#include <SFML/Graphics/Font.hpp> #include <SFML/Graphics/Text.hpp> #include <SFML/Graphics/RectangleShape.hpp> #include <SFML/Graphics/Sprite.hpp> +#include <SFML/System/Clock.hpp> #include "../external/RoundedRectangleShape.hpp" #include <functional> +namespace sf { + class Font; + class RenderWindow; + class Event; +} + namespace QuickMedia { using TextUpdateCallback = std::function<void(const sf::String &text)>; // Return true to consume the search (clear the search field) diff --git a/include/Text.hpp b/include/Text.hpp index bc6f7ab..d34fd47 100644 --- a/include/Text.hpp +++ b/include/Text.hpp @@ -1,15 +1,18 @@ #pragma once #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 <SFML/System/Clock.hpp> #include <vector> #include "types.hpp" #include <assert.h> +namespace sf { + class Font; + class Event; + class RenderTarget; +} + namespace QuickMedia { struct StringViewUtf32 { @@ -69,6 +72,7 @@ namespace QuickMedia void setLineSpacing(float lineSpacing); void setCharacterSpacing(float characterSpacing); void setEditable(bool editable); + bool isEditable() const; // Note: won't update until @draw is called float getWidth() const; @@ -92,21 +96,27 @@ namespace QuickMedia HOME, END }; - -#if 0 + + struct VertexRef { + int vertices_index; // index to |vertices| VertexArray + int index; // index within vertices[vertices_index] + int line; + sf::Uint32 codepoint; + }; + 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; -#endif void splitTextByFont(); + + float get_text_quad_left_side(const VertexRef &vertex_ref) const; + float get_text_quad_right_side(const VertexRef &vertex_ref) const; private: - sf::String str; + sf::String str; // TODO: Remove this for non-editable text??? const sf::Font *font; const sf::Font *cjk_font; unsigned int characterSize; @@ -131,5 +141,7 @@ namespace QuickMedia sf::Vector2f caretPosition; sf::Clock lastSeenTimer; sf::Vector2u renderTargetSize; + + std::vector<VertexRef> vertices_linear; // TODO: Use textElements instead }; } |