aboutsummaryrefslogtreecommitdiff
path: root/include/ContextMenu.hpp
blob: 1e08d7d9665615350845c1d349e4efe10ffffba0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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;
    };
}