diff options
Diffstat (limited to 'include/ContextMenu.hpp')
-rw-r--r-- | include/ContextMenu.hpp | 45 |
1 files changed, 45 insertions, 0 deletions
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; + }; +} |