aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/Cache.hpp91
-rw-r--r--include/Channel.hpp103
-rw-r--r--include/Chatbar.hpp13
-rw-r--r--include/FileUtil.hpp2
-rw-r--r--include/Gif.hpp51
-rw-r--r--include/ImagePreview.hpp1
-rw-r--r--include/Message.hpp27
-rw-r--r--include/MessageBoard.hpp40
-rw-r--r--include/ResourceCache.hpp3
-rw-r--r--include/Room.hpp15
-rw-r--r--include/RoomContainer.hpp26
-rw-r--r--include/RoomSidePanel.hpp (renamed from include/ChannelSidePanel.hpp)8
-rw-r--r--include/RoomTopPanel.hpp (renamed from include/ChannelTopPanel.hpp)2
-rw-r--r--include/Rpc.hpp21
-rw-r--r--include/StaticImage.hpp17
-rw-r--r--include/StringUtils.hpp18
-rw-r--r--include/StringView.hpp95
-rw-r--r--include/Suggestions.hpp5
-rw-r--r--include/Text.hpp12
-rw-r--r--include/User.hpp92
-rw-r--r--include/UsersSidePanel.hpp5
-rw-r--r--include/WebPagePreview.hpp11
22 files changed, 133 insertions, 525 deletions
diff --git a/include/Cache.hpp b/include/Cache.hpp
deleted file mode 100644
index fc702a7..0000000
--- a/include/Cache.hpp
+++ /dev/null
@@ -1,91 +0,0 @@
-#pragma once
-
-#include "types.hpp"
-#include <boost/filesystem/path.hpp>
-#include <SFML/Graphics/Texture.hpp>
-#include <string>
-#include <unordered_map>
-#include <thread>
-#include <mutex>
-#include <vector>
-#include <chrono>
-
-namespace TinyProcessLib
-{
- class Process;
-}
-
-namespace dchat
-{
- class Gif;
- class WebPagePreview;
-
- struct ContentByUrlResult
- {
- enum class Type
- {
- CACHED,
- DOWNLOADING,
- FAILED_DOWNLOAD
- };
-
- enum class CachedType
- {
- NONE,
- TEXTURE,
- GIF,
- WEB_PAGE_PREVIEW
- };
-
- ContentByUrlResult() : texture(nullptr), type(Type::DOWNLOADING), cachedType(CachedType::NONE) {}
- ContentByUrlResult(sf::Texture *_texture, Type _type) : texture(_texture), type(_type), cachedType(CachedType::TEXTURE) {}
- ContentByUrlResult(Gif *_gif, Type _type) : gif(_gif), type(_type), cachedType(CachedType::GIF) {}
- ContentByUrlResult(WebPagePreview *_webPagePreview, Type _type) : webPagePreview(_webPagePreview), type(_type), cachedType(CachedType::WEB_PAGE_PREVIEW) {}
-
- // @texture is null if @type is DOWNLOADING or FAILED_DOWNLOAD
- union
- {
- sf::Texture *texture;
- Gif *gif;
- WebPagePreview *webPagePreview;
- };
-
- Type type;
- CachedType cachedType;
- i64 lastAccessed;
- };
-
- class Cache
- {
- public:
- Cache();
- ~Cache();
-
- // Creates directory if it doesn't exist (recursively). Throws boost exception on failure
- static boost::filesystem::path getDchatDir();
-
- // Creates directory if it doesn't exist (recursively). Throws boost exception on failure
- static boost::filesystem::path getImagesDir();
-
- static void loadBindsFromFile();
- static void replaceBindsInFile(const std::unordered_map<std::string, std::string> &binds);
-
- // Get cached content or download it.
- // Default download file limit is 12MB
- // Returns ContentByUrlResult describing texture status.
- const ContentByUrlResult getContentByUrl(const std::string &url, int downloadLimitBytes = 12582912);
- private:
- struct ImageDownloadInfo
- {
- TinyProcessLib::Process *process;
- std::string url;
- };
-
- std::thread downloadWaitThread;
- std::thread checkContentAccessTimeThread;
- std::vector<ImageDownloadInfo> imageDownloadProcesses;
- std::vector<ImageDownloadInfo> imageDownloadProcessesQueue;
- std::mutex imageDownloadMutex;
- bool alive;
- };
-}
diff --git a/include/Channel.hpp b/include/Channel.hpp
deleted file mode 100644
index 58bbcc3..0000000
--- a/include/Channel.hpp
+++ /dev/null
@@ -1,103 +0,0 @@
-#pragma once
-
-#include "MessageBoard.hpp"
-#include "Chatbar.hpp"
-#include "User.hpp"
-#include "Channel.hpp"
-#include "types.hpp"
-#include "Suggestions.hpp"
-#include "../bridge/DiscordService.hpp"
-#include <vector>
-#include <unordered_map>
-#include <SFML/System/Clock.hpp>
-#include <odhtdb/DatabaseNode.hpp>
-#include <odhtdb/Signature.hpp>
-#include <odhtdb/Group.hpp>
-#include <odhtdb/Hash.hpp>
-#include <odhtdb/DhtKey.hpp>
-#include <odhtdb/Database.hpp>
-
-
-namespace dchat
-{
- enum class ChannelDataType : u8
- {
- ADD_MESSAGE,
- EDIT_MESSAGE,
- DELETE_MESSAGE,
- NICKNAME_CHANGE,
- CHANGE_AVATAR,
- CHANGE_CHANNEL_NAME,
- };
-
- class Channel
- {
- public:
- Channel(const std::string &name, const odhtdb::DatabaseNode &databaseNodeInfo = odhtdb::DatabaseNode(), User *localUser = nullptr, std::shared_ptr<odhtdb::Database> database = nullptr);
- virtual ~Channel();
- Channel(const Channel& other) = delete;
- Channel& operator = (const Channel &other) = delete;
-
- User* getLocalUser();
- SystemUser* getSystemUser();
- MessageBoard& getMessageBoard();
-
- const std::string& getName() const;
- const std::vector<User*>& getUsers() const;
- OnlineUser* getUserByPublicKey(const odhtdb::Signature::PublicKey &publicKey);
- const odhtdb::DatabaseNode& getNodeInfo() const;
- Message* getLatestMessage();
-
- // If timestamp is 0, then current time is used
- void addLocalMessage(const std::string &msg, User *owner, u64 timestampSeconds = 0);
- void addLocalMessage(const std::string &msg, User *owner, u64 timestampSeconds, const odhtdb::Hash &id);
- void addLocalDiscordMessage(const std::string &discordUserName, u64 discordUserId, const std::string &msg, User *owner, u64 timestampSeconds, const odhtdb::Hash &id);
- void addSystemMessage(const std::string &msg, bool plainText = true);
- void addMessage(const std::string &msg);
- void deleteLocalMessage(const odhtdb::Hash &id, const odhtdb::Signature::PublicKey &requestedByUser);
- void deleteMessage(const odhtdb::Hash &id, const odhtdb::Signature::PublicKey &requestedByUser);
-
- void addUserLocally(User *user);
- bool addUser(const odhtdb::Signature::PublicKey &userId, const odhtdb::DataView &groupId);
- void replaceLocalUser(OnlineLocalUser *newOnlineLocalUser);
- void changeNick(const std::string &newNick);
- void setAvatar(const std::string &newAvatarUrl);
- void setNameLocally(const std::string &name);
- void setName(const std::string &name);
-
- // Returns -1 on failure
- int getUserLowestPermissionLevel(OnlineUser *user) const;
-
- void processEvent(const sf::Event &event, Cache &cache);
- void draw(sf::RenderWindow &window, Cache &cache);
-
- void update();
- // Returns 0 if we are offline
- u32 getSyncedTimestampUtcInSec();
-
- const std::vector<BridgeService*>& getBridgeServices() const;
- DiscordService* getDiscordService();
-
- static void setCurrent(Channel *channel);
- static Channel* getCurrent();
- private:
- void sendPing(u32 pingTimestampSec);
- protected:
- std::shared_ptr<odhtdb::Database> database;
- odhtdb::DatabaseNode databaseNodeInfo;
- std::string name;
- MessageBoard messageBoard;
- Chatbar chatbar;
- Suggestions suggestions;
- User *localUser;
- SystemUser systemUser;
- std::vector<User*> users;
- std::unordered_map<u64, OnlineDiscordUser*> discordUserById;
- odhtdb::Signature::MapPublicKey<OnlineUser*> publicKeyOnlineUsersMap;
- odhtdb::InfoHash pingKey;
- sibs::ListenHandle pingListener;
- sf::Clock pingTimer;
-
- std::vector<BridgeService*> bridgeServices;
- };
-}
diff --git a/include/Chatbar.hpp b/include/Chatbar.hpp
index 10bbebd..701220a 100644
--- a/include/Chatbar.hpp
+++ b/include/Chatbar.hpp
@@ -1,18 +1,20 @@
#pragma once
-#include "StringView.hpp"
#include "Text.hpp"
-#include "Cache.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 Channel;
+ class Cache;
+ class Room;
+ class MessageBoard;
class Chatbar
{
@@ -21,8 +23,8 @@ namespace dchat
bool isFocused() const;
- void processEvent(const sf::Event &event, Cache &cache, Channel *channel);
- void draw(sf::RenderWindow &window, Cache &cache);
+ 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);
@@ -30,6 +32,7 @@ namespace dchat
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);
diff --git a/include/FileUtil.hpp b/include/FileUtil.hpp
index 097b607..420ed72 100644
--- a/include/FileUtil.hpp
+++ b/include/FileUtil.hpp
@@ -1,6 +1,6 @@
#pragma once
-#include "StringView.hpp"
+#include <dchat/StringView.hpp>
#include <boost/filesystem/path.hpp>
#include <stdexcept>
diff --git a/include/Gif.hpp b/include/Gif.hpp
index ebcb5d4..6edef92 100644
--- a/include/Gif.hpp
+++ b/include/Gif.hpp
@@ -1,52 +1,19 @@
#pragma once
-#include "StringView.hpp"
-#include <SFML/Graphics/RenderTarget.hpp>
+#include <dchat/Gif.hpp>
#include <SFML/Graphics/Texture.hpp>
-#include <SFML/Graphics/Sprite.hpp>
-#include <SFML/System/Clock.hpp>
-#include <boost/filesystem/path.hpp>
-#include <stdexcept>
-extern "C"
-{
-#include <libnsgif.h>
-}
namespace dchat
{
- class GifLoadException : public std::runtime_error
- {
- public:
- GifLoadException(const std::string &errMsg) : std::runtime_error(errMsg) {}
- };
-
- class Gif
+ class SfmlGif : public Gif
{
public:
- // Throws GifLoadException on error
- Gif(const boost::filesystem::path &filepath);
- Gif(StringView &&fileContent);
- ~Gif();
-
- sf::Vector2u getSize() const;
-
- void setPosition(const sf::Vector2f &position);
- sf::Vector2f getPosition() const;
-
- void setScale(const sf::Vector2f &scale);
- void setColor(sf::Color color);
- void draw(sf::RenderTarget &target, const sf::RenderStates &renderStates = sf::RenderStates::Default);
-
- static bool isDataGif(const StringView &data);
- private:
- void init();
- private:
- gif_animation gif;
- StringView fileContent;
- unsigned int currentFrame;
- sf::Sprite sprite;
+ SfmlGif(StringView fileContent);
+ virtual ~SfmlGif(){}
+
+ bool createTexture() override;
+ void updateTexture(void *textureData) override;
+
sf::Texture texture;
- double timeElapsedCs;
- sf::Clock frameTimer;
};
-}
+} \ No newline at end of file
diff --git a/include/ImagePreview.hpp b/include/ImagePreview.hpp
index 1d20fe8..0f42465 100644
--- a/include/ImagePreview.hpp
+++ b/include/ImagePreview.hpp
@@ -38,6 +38,7 @@ namespace dchat
sf::Vector2u calculateImageSize(sf::Vector2u windowSize) const;
private:
+ sf::Vector2f position;
sf::Sprite sprite;
sf::Vector2u size;
sf::Clock lastSeenTimer;
diff --git a/include/Message.hpp b/include/Message.hpp
index 2327a0b..0541574 100644
--- a/include/Message.hpp
+++ b/include/Message.hpp
@@ -1,29 +1,20 @@
#pragma once
-#include "User.hpp"
+#include <memory>
#include "Text.hpp"
-#include <string>
-#include <vector>
-#include <odhtdb/Hash.hpp>
namespace dchat
{
+ struct RoomMessage;
+
class Message
{
public:
- enum class Type
- {
- REGULAR,
- EDITED
- };
-
- // If timestamp is 0, then timestamp is not used
- Message(User *user, const std::string &text, u64 timestampSeconds = 0, bool plainText = false);
-
- const User *user;
+ Message(std::shared_ptr<RoomMessage> roomMessage, bool plainText);
+
+ std::shared_ptr<RoomMessage> roomMessage;
Text text;
- const u64 timestampSeconds;
- Type type;
- odhtdb::Hash id;
+
+ bool onlineUser;
};
-}
+} \ No newline at end of file
diff --git a/include/MessageBoard.hpp b/include/MessageBoard.hpp
index 1d1f523..c1eecb0 100644
--- a/include/MessageBoard.hpp
+++ b/include/MessageBoard.hpp
@@ -1,9 +1,8 @@
#pragma once
-#include "Message.hpp"
#include "types.hpp"
-#include "../include/Cache.hpp"
-#include "../include/Scrollbar.hpp"
+#include "Message.hpp"
+#include "Scrollbar.hpp"
#include <SFML/Graphics/RenderTexture.hpp>
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Window/Event.hpp>
@@ -11,37 +10,41 @@
#include <odhtdb/Signature.hpp>
#include <stdexcept>
#include <mutex>
+#include <memory>
namespace dchat
{
- class Channel;
+ class Room;
+ struct RoomMessage;
+ class Cache;
+ class User;
class MessageBoard
{
- friend class Channel;
public:
- MessageBoard(Channel *channel);
+ MessageBoard(std::shared_ptr<Room> room);
~MessageBoard();
- void processEvent(const sf::Event &event, Cache &cache);
- void draw(sf::RenderWindow &window, Cache &cache);
-
- Message* getLatestMessage();
- const std::vector<Message*>& getMessages() const;
+ void processEvent(const sf::Event &event, Cache *cache);
+ void draw(sf::RenderWindow &window, Cache *cache);
+
+ bool addMessage(Message *message);
+ void deleteMessage(const odhtdb::Hash &id, const odhtdb::Signature::PublicKey &requestedByUser);
+
+ void addOfflineUserMessage(std::string msg, bool plainText);
+ void addSystemUserMessage(std::string msg, bool plainText);
private:
usize findPositionToInsertMessageByTimestamp(Message *message);
void updateStaticContentTexture(const sf::Vector2u &newSize);
- bool 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);
+ void drawDefault(sf::RenderWindow &window, Cache *cache);
+ void drawSimple(sf::RenderWindow &window, Cache *cache);
private:
- Channel *channel;
+ std::shared_ptr<Room> room;
bool dirty;
- std::vector<Message*> messages;
odhtdb::MapHash<Message*> messageIdMap;
+ std::vector<Message*> messages;
double scroll;
double scrollSpeed;
double totalHeight;
@@ -54,5 +57,8 @@ namespace dchat
usize visibleMessageStartIndex;
usize visibleMessageEndIndex;
Scrollbar scrollbar;
+
+ std::shared_ptr<User> offlineUser;
+ std::shared_ptr<User> systemUser;
};
}
diff --git a/include/ResourceCache.hpp b/include/ResourceCache.hpp
index 75ebd88..ab7a921 100644
--- a/include/ResourceCache.hpp
+++ b/include/ResourceCache.hpp
@@ -3,6 +3,7 @@
#include <SFML/Graphics/Font.hpp>
#include <SFML/Graphics/Texture.hpp>
#include <SFML/Graphics/Shader.hpp>
+#include <dchat/Cache.hpp>
#include <string>
#include <stdexcept>
@@ -24,5 +25,7 @@ namespace dchat
static sf::Texture* getTexture(const std::string &filepath);
static sf::Shader* getShader(const std::string &filepath, sf::Shader::Type shaderType);
+
+ static Cache* getCache();
};
}
diff --git a/include/Room.hpp b/include/Room.hpp
new file mode 100644
index 0000000..bcdadc0
--- /dev/null
+++ b/include/Room.hpp
@@ -0,0 +1,15 @@
+#pragma once
+
+#include <memory>
+
+namespace dchat
+{
+ class Room;
+ class Rooms;
+
+ std::shared_ptr<Room> getCurrentRoom();
+ void setCurrentRoom(std::shared_ptr<Room> room);
+
+ std::shared_ptr<Rooms> getRooms();
+ void setRooms(std::shared_ptr<Rooms> rooms);
+} \ No newline at end of file
diff --git a/include/RoomContainer.hpp b/include/RoomContainer.hpp
new file mode 100644
index 0000000..fc3e8ae
--- /dev/null
+++ b/include/RoomContainer.hpp
@@ -0,0 +1,26 @@
+#pragma once
+
+#include "MessageBoard.hpp"
+#include "Chatbar.hpp"
+#include <SFML/Graphics/RenderWindow.hpp>
+#include <memory>
+
+namespace dchat
+{
+ class Room;
+ class Cache;
+
+ class RoomContainer
+ {
+ public:
+ RoomContainer(std::shared_ptr<Room> room);
+
+ void processEvent(const sf::Event &event, Cache *cache);
+ void draw(sf::RenderWindow &window, Cache *cache);
+
+ std::shared_ptr<Room> room;
+ MessageBoard messageBoard;
+ Chatbar chatbar;
+ bool offlineRoom;
+ };
+} \ No newline at end of file
diff --git a/include/ChannelSidePanel.hpp b/include/RoomSidePanel.hpp
index 265ee67..95000ba 100644
--- a/include/ChannelSidePanel.hpp
+++ b/include/RoomSidePanel.hpp
@@ -1,17 +1,13 @@
#pragma once
#include <SFML/Graphics/RenderWindow.hpp>
+#include <memory>
namespace dchat
{
- class Channel;
-
- class ChannelSidePanel
+ class RoomSidePanel
{
public:
- static void addChannel(Channel *channel);
- static void removeAllChannels();
-
static void draw(sf::RenderWindow &window);
static float getWidth();
static float getHeight();
diff --git a/include/ChannelTopPanel.hpp b/include/RoomTopPanel.hpp
index 41fe9a2..1787753 100644
--- a/include/ChannelTopPanel.hpp
+++ b/include/RoomTopPanel.hpp
@@ -4,7 +4,7 @@
namespace dchat
{
- class ChannelTopPanel
+ class RoomTopPanel
{
public:
static void draw(sf::RenderWindow &window);
diff --git a/include/Rpc.hpp b/include/Rpc.hpp
deleted file mode 100644
index c8b47e0..0000000
--- a/include/Rpc.hpp
+++ /dev/null
@@ -1,21 +0,0 @@
-#pragma once
-
-#include <zmq.hpp>
-#include "types.hpp"
-#include <functional>
-
-namespace dchat
-{
- using RpcRecvCallbackFunc = std::function<void(zmq::message_t*)>;
-
- class Rpc
- {
- public:
- Rpc(u16 port);
- void recv(RpcRecvCallbackFunc recvCallbackFunc);
- bool send(const void *data, const usize size);
- private:
- zmq::context_t context;
- zmq::socket_t socket;
- };
-} \ No newline at end of file
diff --git a/include/StaticImage.hpp b/include/StaticImage.hpp
new file mode 100644
index 0000000..3ede61c
--- /dev/null
+++ b/include/StaticImage.hpp
@@ -0,0 +1,17 @@
+#pragma once
+
+#include <dchat/StaticImage.hpp>
+#include <dchat/StringView.hpp>
+#include <SFML/Graphics/Texture.hpp>
+
+namespace dchat
+{
+ class SfmlStaticImage : public StaticImage
+ {
+ public:
+ SfmlStaticImage(const boost::filesystem::path &path);
+ virtual ~SfmlStaticImage(){}
+
+ sf::Texture texture;
+ };
+} \ No newline at end of file
diff --git a/include/StringUtils.hpp b/include/StringUtils.hpp
deleted file mode 100644
index 6b237dd..0000000
--- a/include/StringUtils.hpp
+++ /dev/null
@@ -1,18 +0,0 @@
-#pragma once
-
-#include <string>
-
-namespace dchat
-{
- static std::string stringReplaceChar(const std::string &str, const std::string &from, const std::string &to)
- {
- std::string result = str;
- size_t pos = 0;
- while((pos = result.find(from, pos)) != std::string::npos)
- {
- result.replace(pos, from.size(), to);
- pos += to.size();
- }
- return result;
- }
-}
diff --git a/include/StringView.hpp b/include/StringView.hpp
deleted file mode 100644
index d320a85..0000000
--- a/include/StringView.hpp
+++ /dev/null
@@ -1,95 +0,0 @@
-#pragma once
-
-#include "types.hpp"
-#include <cstring>
-#include <cassert>
-
-namespace dchat
-{
- template <typename CharType>
- class BasicStringView
- {
- public:
- BasicStringView() : data(nullptr), size(0)
- {
-
- }
-
- BasicStringView(const BasicStringView<CharType> &other) : data(other.data), size(other.size)
- {
-
- }
-
- BasicStringView(const CharType *_data) : data(_data), size(strlen(_data))
- {
-
- }
-
- BasicStringView(const CharType *_data, usize _size) : data(_data), size(_size)
- {
-
- }
-
- BasicStringView<CharType>& operator = (const BasicStringView<CharType> &other)
- {
- data = other.data;
- size = other.size;
- return *this;
- }
-
- BasicStringView(BasicStringView<CharType> &&other)
- {
- data = other.data;
- size = other.size;
-
- other.data = nullptr;
- other.size = 0;
- }
-
- bool equals(const BasicStringView<CharType> &other) const
- {
- if(size != other.size) return false;
- return memcmp(data, other.data, size * sizeof(CharType)) == 0;
- }
-
- bool operator == (const BasicStringView<CharType> &other) const
- {
- return equals(other);
- }
-
- bool operator != (const BasicStringView<CharType> &other) const
- {
- return !equals(other);
- }
-
- CharType operator [] (usize index) const
- {
- assert(index < size);
- return data[index];
- }
-
- // Returns -1 if substr not found.
- // TODO: Make this more efficient
- usize find(const BasicStringView<CharType> &substr, usize offset = 0) const
- {
- if(substr.size == 0)
- return -1;
-
- if(offset + substr.size > size)
- return -1;
-
- for(usize i = offset; i < size - (substr.size - 1); ++i)
- {
- if(memcmp(data + i, substr.data, substr.size * sizeof(CharType)) == 0)
- return i;
- }
- return -1;
- }
-
- const CharType *data;
- usize size;
- };
-
- using StringView = BasicStringView<char>;
- using StringViewUtf32 = BasicStringView<u32>;
-}
diff --git a/include/Suggestions.hpp b/include/Suggestions.hpp
index 56f3afa..b2d19f9 100644
--- a/include/Suggestions.hpp
+++ b/include/Suggestions.hpp
@@ -1,18 +1,19 @@
#pragma once
#include "Text.hpp"
-#include "Cache.hpp"
#include <vector>
#include <string>
#include <SFML/Graphics/RenderWindow.hpp>
namespace dchat
{
+ class Cache;
+
class Suggestions
{
public:
void show(const std::vector<std::string> &texts);
- void draw(sf::RenderWindow &window, Cache &cache);
+ void draw(sf::RenderWindow &window, Cache *cache);
private:
std::vector<std::unique_ptr<Text>> texts;
};
diff --git a/include/Text.hpp b/include/Text.hpp
index 24ea02a..86814a3 100644
--- a/include/Text.hpp
+++ b/include/Text.hpp
@@ -1,17 +1,18 @@
#pragma once
-#include "StringView.hpp"
-#include "Cache.hpp"
#include <SFML/Graphics/VertexArray.hpp>
#include <SFML/Graphics/Font.hpp>
#include <SFML/Graphics/RenderTarget.hpp>
#include <SFML/Window/Event.hpp>
#include <SFML/System/String.hpp>
#include <SFML/System/Clock.hpp>
+#include <dchat/StringView.hpp>
#include <vector>
namespace dchat
{
+ class Cache;
+
struct TextElement
{
enum class Type
@@ -59,13 +60,13 @@ namespace dchat
// Warning: won't update until @draw is called
float getHeight() const;
- void processEvent(const sf::Event &event, Cache &cache);
+ void processEvent(const sf::Event &event, Cache *cache);
// Performs culling. @updateGeometry is called even if text is not visible if text is dirty, because updateGeometry might change the dimension of the text and make is visible.
// Returns true if text was drawn on screen (if text is within window borders)
- bool draw(sf::RenderTarget &target, Cache &cache);
+ bool draw(sf::RenderTarget &target, Cache *cache);
private:
- void onMouseClick(const sf::Event::MouseButtonEvent &event, Cache &cache);
+ void onMouseClick(const sf::Event::MouseButtonEvent &event, Cache *cache);
private:
enum class CaretMoveDirection : u8
{
@@ -110,5 +111,6 @@ namespace dchat
int caretIndex;
sf::Vector2f caretPosition;
sf::Clock lastSeenTimer;
+ sf::Vector2u renderTargetSize;
};
}
diff --git a/include/User.hpp b/include/User.hpp
deleted file mode 100644
index 7e99c60..0000000
--- a/include/User.hpp
+++ /dev/null
@@ -1,92 +0,0 @@
-#pragma once
-
-#include "types.hpp"
-#include <string>
-#include <odhtdb/Signature.hpp>
-
-namespace dchat
-{
- class User
- {
- public:
- enum class Type
- {
- OTHER,
- ONLINE_REMOTE_USER,
- ONLINE_LOCAL_USER,
- ONLINE_DISCORD_USER,
- OFFLINE,
- SYSTEM
- };
-
- User(Type type);
- virtual ~User(){}
- virtual const std::string& getName() const = 0;
- virtual bool isOnlineUser() const { return false; }
-
- virtual bool isConnected(i64 timestampUtcSec) const { return true; }
-
- const Type type;
- std::string avatarUrl;
- };
-
- class OnlineUser : public User
- {
- public:
- OnlineUser(const std::string &name, Type type);
- virtual ~OnlineUser(){}
-
- virtual const std::string& getName() const override;
- virtual const odhtdb::Signature::PublicKey& getPublicKey() const = 0;
-
- bool isConnected(i64 timestampUtcSec) const override;
- bool isOnlineUser() const override { return true; }
-
- std::string name;
- u32 pingTimestampSec;
- };
-
- class OnlineRemoteUser : public OnlineUser
- {
- public:
- OnlineRemoteUser(const std::string &name, const odhtdb::Signature::PublicKey &publicKey);
- virtual const odhtdb::Signature::PublicKey& getPublicKey() const override;
-
- const odhtdb::Signature::PublicKey publicKey;
- };
-
- class OnlineLocalUser : public OnlineUser
- {
- public:
- OnlineLocalUser(const std::string &name, const odhtdb::Signature::KeyPair &keyPair);
- virtual const odhtdb::Signature::PublicKey& getPublicKey() const override;
-
- const odhtdb::Signature::KeyPair keyPair;
- };
-
- class OnlineDiscordUser : public OnlineUser
- {
- public:
- OnlineDiscordUser(const std::string &discordUserName, u64 discordUserId, User *bridgeOwner);
- virtual const odhtdb::Signature::PublicKey& getPublicKey() const override;
-
- u64 discordUserId;
- User *bridgeOwner;
- };
-
- class OfflineUser : public User
- {
- public:
- OfflineUser(const std::string &name);
- virtual const std::string& getName() const override;
-
- const std::string name;
- };
-
- class SystemUser : public User
- {
- public:
- SystemUser();
- virtual const std::string& getName() const override;
- };
-}
diff --git a/include/UsersSidePanel.hpp b/include/UsersSidePanel.hpp
index 9e48ee6..b76eb5e 100644
--- a/include/UsersSidePanel.hpp
+++ b/include/UsersSidePanel.hpp
@@ -1,16 +1,15 @@
#pragma once
-#include "Cache.hpp"
#include <SFML/Graphics/RenderWindow.hpp>
namespace dchat
{
- class Channel;
+ class Cache;
class UsersSidePanel
{
public:
- static void draw(sf::RenderWindow &window, Cache &cache);
+ static void draw(sf::RenderWindow &window, Cache *cache);
static float getWidth();
};
}
diff --git a/include/WebPagePreview.hpp b/include/WebPagePreview.hpp
index 6f6c0f0..fde653d 100644
--- a/include/WebPagePreview.hpp
+++ b/include/WebPagePreview.hpp
@@ -1,16 +1,17 @@
#pragma once
-#include <SFML/System/String.hpp>
#include "Text.hpp"
+#include <dchat/WebPagePreview.hpp>
+#include <string>
namespace dchat
{
- class WebPagePreview
+ class SfmlWebPagePreview : public WebPagePreview
{
public:
- WebPagePreview(const sf::String &title, const sf::String &description);
-
+ SfmlWebPagePreview(const std::string &title, const std::string &description);
+
Text title;
Text description;
};
-}
+} \ No newline at end of file