aboutsummaryrefslogtreecommitdiff
path: root/include/Chatbar.hpp
blob: 701220aea86608cee275bfeeca242545b4164e78 (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 "Text.hpp"
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Graphics/RectangleShape.hpp>
#include <SFML/Window/Event.hpp>
#include <SFML/System/Clock.hpp>
#include <dchat/StringView.hpp>
#include <string>
#include <unordered_map>
#include <memory>

namespace dchat
{
    class Cache;
    class Room;
    class MessageBoard;
    
    class Chatbar
    {
    public:
        Chatbar();
        
        bool isFocused() const;
        
        void processEvent(const sf::Event &event, Cache *cache, std::shared_ptr<Room> room, MessageBoard *messageBoard);
        void draw(sf::RenderWindow &window, Cache *cache);
        
        static sf::Vector2f getInputPosition(sf::RenderWindow &window);
        static sf::Vector2f getInputSize(sf::RenderWindow &window);
        static float getHeight();
        
        static bool addBind(const std::string &key, const std::string &value, bool updateFile = true);
        static bool removeBind(const std::string &key, bool updateFile = true);
        static void loadBindsFromFile();
        static const std::unordered_map<std::string, std::string>& getBinds();
    private:
        void processChatCommand(const StringView &cmd);
    private:
        Text text;
        sf::RectangleShape background;
        sf::RectangleShape inputBackground;
        bool focused;
    };
}