blob: a947c1beb5a531b82ab725a89897a9e55a890bfb (
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
48
49
50
51
|
#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 <odhtdb/Hash.hpp>
#include <odhtdb/Signature.hpp>
#include <stdexcept>
#include <mutex>
namespace dchat
{
class Channel;
class MessageBoard
{
friend class Channel;
public:
MessageBoard(Channel *channel);
~MessageBoard();
void processEvent(const sf::Event &event);
void draw(sf::RenderWindow &window, Cache &cache);
private:
usize findPositionToInsertMessageByTimestamp(Message *message);
void updateStaticContentTexture(const sf::Vector2u &newSize);
void addMessage(Message *message, const odhtdb::Hash &id);
void deleteMessage(const odhtdb::Hash &id, const odhtdb::Signature::PublicKey &requestedByUser);
void drawDefault(sf::RenderWindow &window, Cache &cache);
void drawSimple(sf::RenderWindow &window, Cache &cache);
private:
Channel *channel;
bool dirty;
std::vector<Message*> messages;
odhtdb::MapHash<Message*> messageIdMap;
double scroll;
double scrollSpeed;
sf::Clock frameTimer;
double totalHeight;
bool scrollToBottom;
sf::Vector2f backgroundSizeWithoutPadding;
sf::Vector2f backgroundSize;
sf::Vector2f backgroundPos;
std::mutex messageProcessMutex;
};
}
|