diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-05-08 18:06:43 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2018-05-08 18:06:51 +0200 |
commit | 15c4434de0c2cd12e09c2f41e898c0b124194a97 (patch) | |
tree | 0bf01cd49a22b7aa79304ed0e9d34ac265d8393c /include | |
parent | 4f6c843523f45708d8bbed25b3677f69c4208a38 (diff) |
Add context menu, add context menu to delete message
Diffstat (limited to 'include')
-rw-r--r-- | include/Channel.hpp | 9 | ||||
-rw-r--r-- | include/ColorScheme.hpp | 4 | ||||
-rw-r--r-- | include/ContextMenu.hpp | 45 | ||||
-rw-r--r-- | include/GlobalContextMenu.hpp | 19 | ||||
-rw-r--r-- | include/Message.hpp | 7 | ||||
-rw-r--r-- | include/MessageBoard.hpp | 15 | ||||
-rw-r--r-- | include/Text.hpp | 3 |
7 files changed, 94 insertions, 8 deletions
diff --git a/include/Channel.hpp b/include/Channel.hpp index 1acfcd1..7d4cb08 100644 --- a/include/Channel.hpp +++ b/include/Channel.hpp @@ -9,6 +9,7 @@ #include <odhtdb/DatabaseNode.hpp> #include <odhtdb/Signature.hpp> #include <odhtdb/Group.hpp> +#include <odhtdb/Hash.hpp> namespace odhtdb { @@ -19,7 +20,9 @@ namespace dchat { enum class ChannelDataType : u8 { - MESSAGE, + ADD_MESSAGE, + EDIT_MESSAGE, + DELETE_MESSAGE, NICKNAME_CHANGE }; @@ -42,7 +45,11 @@ namespace dchat // If timestamp is 0, then current time is used void addLocalMessage(const std::string &msg, User *owner, u64 timestampSeconds = 0); + void addLocalMessage(const std::string &msg, User *owner, u64 timestampSeconds, const odhtdb::Hash &id); void addMessage(const std::string &msg); + void deleteLocalMessage(const odhtdb::Hash &id); + void deleteMessage(const odhtdb::Hash &id); + void addUserLocally(User *user); bool addUser(const odhtdb::Signature::PublicKey &userId, const std::string &groupId); void replaceLocalUser(User *newLocalUser); diff --git a/include/ColorScheme.hpp b/include/ColorScheme.hpp index 64dbeec..93aa640 100644 --- a/include/ColorScheme.hpp +++ b/include/ColorScheme.hpp @@ -19,5 +19,9 @@ namespace dchat static sf::Color getBackgroundColor(); static sf::Color getPanelColor(); static sf::Color getTextRegularColor(); + + static sf::Color getContextMenuBackgroundColor(); + static sf::Color getContextMenuTextColor(); + static sf::Color getContextMenuSelectedItemBackgroundColor(); }; } diff --git a/include/ContextMenu.hpp b/include/ContextMenu.hpp new file mode 100644 index 0000000..1e08d7d --- /dev/null +++ b/include/ContextMenu.hpp @@ -0,0 +1,45 @@ +#pragma once + +#include "types.hpp" +#include <string> +#include <vector> +#include <SFML/Window/Event.hpp> +#include <SFML/Graphics/Text.hpp> +#include <SFML/Graphics/RenderWindow.hpp> +#include <functional> + +namespace dchat +{ + class ContextMenuItem; + using MenuItemClickCallbackFunc = std::function<void(ContextMenuItem *menuItem)>; + + class ContextMenuItem + { + public: + ContextMenuItem(const std::string &text, MenuItemClickCallbackFunc clickCallbackFunc); + + sf::Text text; + MenuItemClickCallbackFunc clickCallbackFunc; + }; + + class ContextMenu + { + public: + ContextMenu(); + + void addItem(const ContextMenuItem &item); + void setPosition(const sf::Vector2f &position); + void setVisible(bool visible); + + ContextMenuItem& getItemByIndex(usize index); + + void processEvent(const sf::Event &event); + void draw(sf::RenderWindow &window); + private: + std::vector<ContextMenuItem> menuItems; + sf::Vector2f position; + int focusedItem; + int pressedItem; + bool visible; + }; +} diff --git a/include/GlobalContextMenu.hpp b/include/GlobalContextMenu.hpp new file mode 100644 index 0000000..ab45e50 --- /dev/null +++ b/include/GlobalContextMenu.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include "ContextMenu.hpp" +#include <SFML/Window/Event.hpp> +#include <SFML/Graphics/RenderWindow.hpp> + +namespace dchat +{ + class GlobalContextMenu + { + public: + static ContextMenu* getEditMessageContextMenu(); + static void setClickEditMessageCallbackFunc(MenuItemClickCallbackFunc callbackFunc); + static void setClickDeleteMessageCallbackFunc(MenuItemClickCallbackFunc callbackFunc); + + static void processEvent(const sf::Event &event); + static void draw(sf::RenderWindow &window); + }; +} diff --git a/include/Message.hpp b/include/Message.hpp index 2e52603..8c7f57a 100644 --- a/include/Message.hpp +++ b/include/Message.hpp @@ -10,11 +10,18 @@ namespace dchat class Message { public: + enum class Type + { + REGULAR, + EDITED + }; + // If timestamp is 0, then timestamp is not used Message(User *user, const std::string &text, u64 timestampSeconds = 0); const User *user; Text text; const u64 timestampSeconds; + Type type; }; } diff --git a/include/MessageBoard.hpp b/include/MessageBoard.hpp index a4dc5a6..a6867d2 100644 --- a/include/MessageBoard.hpp +++ b/include/MessageBoard.hpp @@ -6,7 +6,9 @@ #include <SFML/Graphics/RenderTexture.hpp> #include <SFML/Graphics/RenderWindow.hpp> #include <SFML/Window/Event.hpp> +#include <odhtdb/Hash.hpp> #include <stdexcept> +#include <mutex> namespace dchat { @@ -16,25 +18,23 @@ namespace dchat { friend class Channel; public: - MessageBoard(const sf::Vector2u &size); + MessageBoard(Channel *channel); ~MessageBoard(); void processEvent(const sf::Event &event); void draw(sf::RenderWindow &window, Cache &cache); private: void updateStaticContentTexture(const sf::Vector2u &newSize); - void addMessage(Message *message); + void addMessage(Message *message, const odhtdb::Hash &id); + void deleteMessage(const odhtdb::Hash &id); void drawDefault(sf::RenderWindow &window, Cache &cache); void drawSimple(sf::RenderWindow &window, Cache &cache); private: - sf::RenderTexture staticContentTexture; + Channel *channel; bool dirty; - bool selectingText; - bool leftMouseButtonPressed; - sf::Vector2f mousePos; - sf::Vector2f selectingTextStart; std::vector<Message*> messages; + odhtdb::MapHash<Message*> messageIdMap; double scroll; double scrollSpeed; sf::Clock frameTimer; @@ -43,5 +43,6 @@ namespace dchat sf::Vector2f backgroundSizeWithoutPadding; sf::Vector2f backgroundSize; sf::Vector2f backgroundPos; + std::mutex messageProcessMutex; }; } diff --git a/include/Text.hpp b/include/Text.hpp index d2809de..d7d1e06 100644 --- a/include/Text.hpp +++ b/include/Text.hpp @@ -40,7 +40,10 @@ namespace dchat void setPosition(float x, float y); void setPosition(const sf::Vector2f &position); + sf::Vector2f getPosition() const; + void setMaxWidth(float maxWidth); + float getMaxWidth() const; void setCharacterSize(unsigned int characterSize); unsigned int getCharacterSize() const; |