aboutsummaryrefslogtreecommitdiff
path: root/include/Chatbar.hpp
blob: d24b2af14b41d73c5c2847f2a0a6e90fc4364385 (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
#pragma once

#include <SFML/Graphics/Text.hpp>
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Graphics/RectangleShape.hpp>
#include <SFML/Window/Event.hpp>
#include <SFML/System/Clock.hpp>

namespace dchat
{
    class Channel;
    
    class Chatbar
    {
    public:
        Chatbar();
        
        void addChar(sf::Uint32 codePoint);
        const sf::String& getString() const;
        void removePreviousChar();
        void removeNextChar();
        void clear();
        
        void moveCaretLeft();
        void moveCaretRight();
        
        bool isFocused() const;
        
        void processEvent(const sf::Event &event, Channel *channel);
        void draw(sf::RenderWindow &window);
    private:
        sf::Text text;
        sf::RectangleShape background;
        int caretIndex;
        sf::Vector2f caretOffset;
        sf::Clock blinkTimer;
        bool focused;
    };
}