From 391f7fd6d832cb40f74fb37f9e0af7ff33db202f Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 20 Apr 2018 01:29:54 +0200 Subject: Add message board, in the middle of text selection --- include/Message.hpp | 23 +++++++++++++++++++++++ include/MessageBoard.hpp | 32 ++++++++++++++++++++++++++++++++ include/MessagePart.hpp | 38 ++++++++++++++++++++++++++++++++++++++ include/ResourceCache.hpp | 13 +++++++++++++ include/Settings.hpp | 10 ++++++++++ include/User.hpp | 22 ++++++++++++++++++++++ 6 files changed, 138 insertions(+) create mode 100644 include/Message.hpp create mode 100644 include/MessageBoard.hpp create mode 100644 include/MessagePart.hpp create mode 100644 include/ResourceCache.hpp create mode 100644 include/Settings.hpp create mode 100644 include/User.hpp (limited to 'include') diff --git a/include/Message.hpp b/include/Message.hpp new file mode 100644 index 0000000..c037eb3 --- /dev/null +++ b/include/Message.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include "MessagePart.hpp" +#include "User.hpp" +#include +#include + +namespace dchat +{ + class Message + { + public: + Message(User *user); + virtual ~Message(); + + void addText(const std::string &text); + std::vector& getParts(); + + const User *user; + private: + std::vector messageParts; + }; +} diff --git a/include/MessageBoard.hpp b/include/MessageBoard.hpp new file mode 100644 index 0000000..f399761 --- /dev/null +++ b/include/MessageBoard.hpp @@ -0,0 +1,32 @@ +#pragma once + +#include "Message.hpp" +#include +#include +#include +#include + +namespace dchat +{ + class MessageBoard + { + public: + MessageBoard(const sf::Vector2u &size); + ~MessageBoard(); + + void updateStaticContentTexture(const sf::Vector2u &newSize); + void addMessage(Message *message); + + void processEvent(const sf::Event &event); + void draw(sf::RenderWindow &window); + private: + sf::RenderTexture staticContentTexture; + bool useStaticContentTexture; + bool dirty; + bool selectingText; + bool leftMouseButtonPressed; + sf::Vector2f mousePos; + sf::Vector2f selectingTextStart; + std::vector messages; + }; +} diff --git a/include/MessagePart.hpp b/include/MessagePart.hpp new file mode 100644 index 0000000..e50852a --- /dev/null +++ b/include/MessagePart.hpp @@ -0,0 +1,38 @@ +#pragma once + +#include +#include +#include + +namespace dchat +{ + class MessagePart + { + public: + enum class Type + { + TEXT + }; + + MessagePart(Type _type) : type(_type) {} + virtual ~MessagePart(){} + + static float getSizeScaled(); + virtual sf::Vector2f getPosition() const = 0; + virtual sf::Vector2f getSize() const = 0; + + const Type type; + }; + + class MessagePartText : public MessagePart + { + public: + MessagePartText(const std::string &text); + + static float getFontSizeScaled(); + virtual sf::Vector2f getPosition() const override; + virtual sf::Vector2f getSize() const override; + + sf::Text text; + }; +} diff --git a/include/ResourceCache.hpp b/include/ResourceCache.hpp new file mode 100644 index 0000000..d35eb8f --- /dev/null +++ b/include/ResourceCache.hpp @@ -0,0 +1,13 @@ +#pragma once + +#include +#include + +namespace dchat +{ + class ResourceCache + { + public: + static const sf::Font& getFont(const std::string &filepath); + }; +} diff --git a/include/Settings.hpp b/include/Settings.hpp new file mode 100644 index 0000000..ab757ec --- /dev/null +++ b/include/Settings.hpp @@ -0,0 +1,10 @@ +#pragma once + +namespace dchat +{ + class Settings + { + public: + static float getScaling(); + }; +} diff --git a/include/User.hpp b/include/User.hpp new file mode 100644 index 0000000..2a8f46b --- /dev/null +++ b/include/User.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include + +namespace dchat +{ + class User + { + public: + virtual ~User(){} + virtual const std::string& getName() const = 0; + }; + + class OfflineUser : public User + { + public: + OfflineUser(const std::string &name); + virtual const std::string& getName() const override; + + std::string name; + }; +} -- cgit v1.2.3