aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/Cache.hpp54
-rw-r--r--include/Channel.hpp23
-rw-r--r--include/ChannelSidePanel.hpp16
-rw-r--r--include/Message.hpp1
-rw-r--r--include/MessageBoard.hpp3
-rw-r--r--include/MessagePart.hpp17
-rw-r--r--include/ResourceCache.hpp12
-rw-r--r--include/env.hpp63
8 files changed, 187 insertions, 2 deletions
diff --git a/include/Cache.hpp b/include/Cache.hpp
new file mode 100644
index 0000000..89abe2c
--- /dev/null
+++ b/include/Cache.hpp
@@ -0,0 +1,54 @@
+#pragma once
+
+#include <boost/filesystem/path.hpp>
+#include <SFML/Graphics/Texture.hpp>
+#include <string>
+#include <thread>
+#include <mutex>
+#include <vector>
+
+namespace TinyProcessLib
+{
+ class Process;
+}
+
+namespace dchat
+{
+ struct ImageByUrlResult
+ {
+ enum class Type
+ {
+ CACHED,
+ DOWNLOADING,
+ FAILED_DOWNLOAD
+ };
+
+ // @texture is null if @type is DOWNLOADING or FAILED_DOWNLOAD
+ const sf::Texture *texture;
+ Type type;
+ };
+
+ class Cache
+ {
+ public:
+ Cache();
+
+ // Creates directory if it doesn't exist (recursively). Throws boost exception on failure
+ static boost::filesystem::path getDchatDir();
+
+ // Get cached image or downloads it.
+ // Default download file limit is 12MB
+ // Returns ImageByUrlResult describing texture status.
+ const ImageByUrlResult getImageByUrl(const std::string &url, int downloadLimitBytes = 12582912);
+ private:
+ struct ImageDownloadInfo
+ {
+ TinyProcessLib::Process *process;
+ std::string url;
+ };
+
+ std::thread downloadWaitThread;
+ std::vector<ImageDownloadInfo> imageDownloadProcesses;
+ std::mutex imageDownloadMutex;
+ };
+}
diff --git a/include/Channel.hpp b/include/Channel.hpp
new file mode 100644
index 0000000..fa52a4b
--- /dev/null
+++ b/include/Channel.hpp
@@ -0,0 +1,23 @@
+#pragma once
+
+#include "MessageBoard.hpp"
+#include "Chatbar.hpp"
+#include "User.hpp"
+#include "Channel.hpp"
+
+namespace dchat
+{
+ class Channel
+ {
+ public:
+ Channel();
+ ~Channel();
+
+ void processEvent(const sf::Event &event);
+ void draw(sf::RenderWindow &window, Cache &cache);
+ private:
+ MessageBoard messageBoard;
+ Chatbar chatbar;
+ OfflineUser localOfflineUser;
+ };
+}
diff --git a/include/ChannelSidePanel.hpp b/include/ChannelSidePanel.hpp
new file mode 100644
index 0000000..604dfcf
--- /dev/null
+++ b/include/ChannelSidePanel.hpp
@@ -0,0 +1,16 @@
+#pragma once
+
+#include <vector>
+
+namespace dchat
+{
+ class Channel;
+
+ class ChannelSidePanel
+ {
+ public:
+ void addChannel(Channel *channel);
+ private:
+ std::vector<Channel*> channels;
+ };
+}
diff --git a/include/Message.hpp b/include/Message.hpp
index c037eb3..efc1f4c 100644
--- a/include/Message.hpp
+++ b/include/Message.hpp
@@ -14,6 +14,7 @@ namespace dchat
virtual ~Message();
void addText(const std::string &text);
+ void addImage(const std::string &url);
std::vector<MessagePart*>& getParts();
const User *user;
diff --git a/include/MessageBoard.hpp b/include/MessageBoard.hpp
index f399761..105d675 100644
--- a/include/MessageBoard.hpp
+++ b/include/MessageBoard.hpp
@@ -1,6 +1,7 @@
#pragma once
#include "Message.hpp"
+#include "../include/Cache.hpp"
#include <SFML/Graphics/RenderTexture.hpp>
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Window/Event.hpp>
@@ -18,7 +19,7 @@ namespace dchat
void addMessage(Message *message);
void processEvent(const sf::Event &event);
- void draw(sf::RenderWindow &window);
+ void draw(sf::RenderWindow &window, Cache &cache);
private:
sf::RenderTexture staticContentTexture;
bool useStaticContentTexture;
diff --git a/include/MessagePart.hpp b/include/MessagePart.hpp
index e50852a..cbb0f26 100644
--- a/include/MessagePart.hpp
+++ b/include/MessagePart.hpp
@@ -1,6 +1,7 @@
#pragma once
#include <SFML/Graphics/Text.hpp>
+#include <SFML/Graphics/Sprite.hpp>
#include <SFML/System/Vector2.hpp>
#include <string>
@@ -11,7 +12,8 @@ namespace dchat
public:
enum class Type
{
- TEXT
+ TEXT,
+ EMOJI
};
MessagePart(Type _type) : type(_type) {}
@@ -35,4 +37,17 @@ namespace dchat
sf::Text text;
};
+
+ class MessagePartEmoji : public MessagePart
+ {
+ public:
+ MessagePartEmoji(const std::string &url);
+
+ static float getHeightScaled();
+ virtual sf::Vector2f getPosition() const override;
+ virtual sf::Vector2f getSize() const override;
+
+ sf::Sprite sprite;
+ std::string url;
+ };
}
diff --git a/include/ResourceCache.hpp b/include/ResourceCache.hpp
index d35eb8f..256e5a4 100644
--- a/include/ResourceCache.hpp
+++ b/include/ResourceCache.hpp
@@ -1,13 +1,25 @@
#pragma once
#include <SFML/Graphics/Font.hpp>
+#include <SFML/Graphics/Texture.hpp>
#include <string>
+#include <stdexcept>
namespace dchat
{
+ class FailedToLoadResourceException : public std::runtime_error
+ {
+ public:
+ FailedToLoadResourceException(const std::string &errMsg) : std::runtime_error(errMsg) {}
+ };
+
class ResourceCache
{
public:
+ // Throws FailedToLoadResourceException on failure
static const sf::Font& getFont(const std::string &filepath);
+
+ // Throws FailedToLoadResourceException on failure
+ static const sf::Texture* getTexture(const std::string &filepath);
};
}
diff --git a/include/env.hpp b/include/env.hpp
new file mode 100644
index 0000000..e0a5b03
--- /dev/null
+++ b/include/env.hpp
@@ -0,0 +1,63 @@
+#pragma once
+
+#define OS_FAMILY_WINDOWS 0
+#define OS_FAMILY_POSIX 1
+
+#define OS_TYPE_WINDOWS 0
+#define OS_TYPE_LINUX 1
+
+#if defined(_WIN32) || defined(_WIN64)
+ #if defined(_WIN64)
+ #define OS_ENV_64BIT
+ #else
+ #define OS_ENV_32BIT
+ #endif
+ #define OS_FAMILY OS_FAMILY_WINDOWS
+ #define OS_TYPE OS_TYPE_WINDOWS
+
+ #ifndef UNICODE
+ #define UNICODE
+ #endif
+
+ #ifndef _UNICODE
+ #define _UNICODE
+ #endif
+
+ #ifndef WIN32_LEAN_AND_MEAN
+ #define WIN32_LEAN_AND_MEAN
+ #endif
+
+ #include <Windows.h>
+#endif
+
+#if defined(__linux__) || defined(__unix__) || defined(__APPLE__) || defined(_POSIX_VERSION)
+ #define OS_FAMILY OS_FAMILY_POSIX
+#endif
+
+#ifdef __linux__
+ #define OS_TYPE OS_TYPE_LINUX
+#endif
+
+#if defined(__GNUC__)
+ #if defined(__x86_64__) || defined(__pc64__)
+ #define OS_ENV_64BIT
+ #else
+ #define OS_ENV_32BIT
+ #endif
+#endif
+
+#if !defined(OS_ENV_32BIT) && !defined(OS_ENV_64BIT)
+ #error "System is not detected as either 32-bit or 64-bit"
+#endif
+
+#if !defined(OS_FAMILY)
+ #error "System not supported. Only Windows and Posix systems supported right now"
+#endif
+
+#if !defined(OS_TYPE)
+ #error "System not supported. Only Windows and linux systems supported right now"
+#endif
+
+#if !defined(DEBUG) && !defined(NDEBUG)
+#define DEBUG
+#endif