aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/Channel.hpp2
-rw-r--r--include/Chatbar.hpp2
-rw-r--r--include/Gif.hpp2
-rw-r--r--include/ImagePreview.hpp52
-rw-r--r--include/Message.hpp2
-rw-r--r--include/MessageBoard.hpp4
-rw-r--r--include/StringUtils.hpp18
-rw-r--r--include/Text.hpp9
8 files changed, 85 insertions, 6 deletions
diff --git a/include/Channel.hpp b/include/Channel.hpp
index 6e944c3..16c2fb3 100644
--- a/include/Channel.hpp
+++ b/include/Channel.hpp
@@ -55,7 +55,7 @@ namespace dchat
void replaceLocalUser(OnlineLocalUser *newOnlineLocalUser);
void changeNick(const std::string &newNick);
- void processEvent(const sf::Event &event);
+ void processEvent(const sf::Event &event, Cache &cache);
void draw(sf::RenderWindow &window, Cache &cache);
static void setCurrent(Channel *channel);
diff --git a/include/Chatbar.hpp b/include/Chatbar.hpp
index 5d69448..df492ac 100644
--- a/include/Chatbar.hpp
+++ b/include/Chatbar.hpp
@@ -21,7 +21,7 @@ namespace dchat
bool isFocused() const;
- void processEvent(const sf::Event &event, Channel *channel);
+ void processEvent(const sf::Event &event, Cache &cache, Channel *channel);
void draw(sf::RenderWindow &window, Cache &cache);
static float getHeight();
diff --git a/include/Gif.hpp b/include/Gif.hpp
index 8f5d4e7..1341049 100644
--- a/include/Gif.hpp
+++ b/include/Gif.hpp
@@ -31,6 +31,8 @@ namespace dchat
sf::Vector2u getSize() const;
void setPosition(const sf::Vector2f &position);
+ sf::Vector2f getPosition() const;
+
void setScale(const sf::Vector2f &scale);
void draw(sf::RenderTarget &target, const sf::RenderStates &renderStates = sf::RenderStates::Default);
diff --git a/include/ImagePreview.hpp b/include/ImagePreview.hpp
new file mode 100644
index 0000000..1d20fe8
--- /dev/null
+++ b/include/ImagePreview.hpp
@@ -0,0 +1,52 @@
+#pragma once
+
+#include <SFML/Graphics/RenderWindow.hpp>
+#include <SFML/Graphics/Sprite.hpp>
+#include <SFML/Graphics/Texture.hpp>
+#include <SFML/Window/Event.hpp>
+#include <SFML/System/Clock.hpp>
+#include <string>
+
+namespace dchat
+{
+ class Gif;
+
+ class ImagePreview
+ {
+ public:
+ // set @texture to nullptr if you wish to end preview
+ static void preview(sf::Texture *texture, const std::string &url = "");
+ // set gif to nullptr if you wish to end preview
+ static void preview(Gif *gif, const std::string &url = "");
+ static void* getPreviewContentPtr();
+ static sf::Int32 getTimeSinceLastSeenMs();
+
+ static void processEvent(const sf::Event &event);
+ static void draw(sf::RenderWindow &window);
+ private:
+ enum class ContentType
+ {
+ NONE,
+ TEXTURE,
+ GIF
+ };
+
+ ImagePreview() : texture(nullptr), contentType(ContentType::NONE) {}
+ ImagePreview(const ImagePreview&) = delete;
+ ImagePreview& operator=(const ImagePreview&) = delete;
+ static ImagePreview* getInstance();
+
+ sf::Vector2u calculateImageSize(sf::Vector2u windowSize) const;
+ private:
+ sf::Sprite sprite;
+ sf::Vector2u size;
+ sf::Clock lastSeenTimer;
+
+ union
+ {
+ sf::Texture *texture;
+ Gif *gif;
+ };
+ ContentType contentType;
+ };
+}
diff --git a/include/Message.hpp b/include/Message.hpp
index 8c7f57a..a2d67e8 100644
--- a/include/Message.hpp
+++ b/include/Message.hpp
@@ -4,6 +4,7 @@
#include "Text.hpp"
#include <string>
#include <vector>
+#include <odhtdb/Hash.hpp>
namespace dchat
{
@@ -23,5 +24,6 @@ namespace dchat
Text text;
const u64 timestampSeconds;
Type type;
+ odhtdb::Hash id;
};
}
diff --git a/include/MessageBoard.hpp b/include/MessageBoard.hpp
index a947c1b..861d195 100644
--- a/include/MessageBoard.hpp
+++ b/include/MessageBoard.hpp
@@ -22,7 +22,7 @@ namespace dchat
MessageBoard(Channel *channel);
~MessageBoard();
- void processEvent(const sf::Event &event);
+ void processEvent(const sf::Event &event, Cache &cache);
void draw(sf::RenderWindow &window, Cache &cache);
private:
usize findPositionToInsertMessageByTimestamp(Message *message);
@@ -47,5 +47,7 @@ namespace dchat
sf::Vector2f backgroundSize;
sf::Vector2f backgroundPos;
std::mutex messageProcessMutex;
+ usize visibleMessageStartIndex;
+ usize visibleMessageEndIndex;
};
}
diff --git a/include/StringUtils.hpp b/include/StringUtils.hpp
new file mode 100644
index 0000000..6b237dd
--- /dev/null
+++ b/include/StringUtils.hpp
@@ -0,0 +1,18 @@
+#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/Text.hpp b/include/Text.hpp
index d7d1e06..925dc94 100644
--- a/include/Text.hpp
+++ b/include/Text.hpp
@@ -57,10 +57,13 @@ namespace dchat
// Warning: won't update until @draw is called
float getHeight() const;
- void processEvent(const sf::Event &event);
+ 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
- void draw(sf::RenderTarget &target, 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);
+ private:
+ void onMouseClick(const sf::Event::MouseButtonEvent &event, Cache &cache);
private:
enum class CaretMoveDirection : u8
{