aboutsummaryrefslogtreecommitdiff
path: root/include/MessageBoard.hpp
blob: a4dc5a6ec96419780d3b20566ba2452bf8e678c8 (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
46
47
#pragma once

#include "Message.hpp"
#include "types.hpp"
#include "../include/Cache.hpp"
#include <SFML/Graphics/RenderTexture.hpp>
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Window/Event.hpp>
#include <stdexcept>

namespace dchat
{
    class Channel;
    
    class MessageBoard
    {
        friend class Channel;
    public:
        MessageBoard(const sf::Vector2u &size);
        ~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 drawDefault(sf::RenderWindow &window, Cache &cache);
        void drawSimple(sf::RenderWindow &window, Cache &cache);
    private:
        sf::RenderTexture staticContentTexture;
        bool dirty;
        bool selectingText;
        bool leftMouseButtonPressed;
        sf::Vector2f mousePos;
        sf::Vector2f selectingTextStart;
        std::vector<Message*> messages;
        double scroll;
        double scrollSpeed;
        sf::Clock frameTimer;
        double totalHeight;
        bool scrollToBottom;
        sf::Vector2f backgroundSizeWithoutPadding;
        sf::Vector2f backgroundSize;
        sf::Vector2f backgroundPos;
    };
}