From 7e7dfd227eacaa80b21ca8ed99e8a99ccbd47769 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 23 Apr 2018 18:49:45 +0200 Subject: Add side bar, make submodule public --- .gitmodules | 2 +- include/Channel.hpp | 6 ++++-- include/ChannelSidePanel.hpp | 6 ++++++ include/Chatbar.hpp | 2 +- include/MessageBoard.hpp | 2 +- src/Channel.cpp | 26 +++++++++++++++++++++----- src/ChannelSidePanel.cpp | 33 +++++++++++++++++++++++++++++++++ src/Chatbar.cpp | 4 ++-- src/Gif.cpp | 3 +++ src/MessageBoard.cpp | 8 ++++---- src/main.cpp | 9 +++++---- 11 files changed, 81 insertions(+), 20 deletions(-) diff --git a/.gitmodules b/.gitmodules index 39ba254..4d7ad9f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "depends/odhtdb"] path = depends/odhtdb - url = git@github.com:DEC05EBA/odhtdb.git + url = https://github.com/DEC05EBA/odhtdb.git diff --git a/include/Channel.hpp b/include/Channel.hpp index b70803c..4d1f528 100644 --- a/include/Channel.hpp +++ b/include/Channel.hpp @@ -10,17 +10,19 @@ namespace dchat class Channel { public: - Channel(); + Channel(const std::string &name); ~Channel(); User* getLocalUser(); MessageBoard& getMessageBoard(); + const std::string& getName() const; void processEvent(const sf::Event &event); - void draw(sf::RenderWindow &window, Cache &cache); + void draw(sf::RenderWindow &window, const sf::Vector2f &position, Cache &cache); private: MessageBoard messageBoard; Chatbar chatbar; OfflineUser localOfflineUser; + std::string name; }; } diff --git a/include/ChannelSidePanel.hpp b/include/ChannelSidePanel.hpp index 604dfcf..8331787 100644 --- a/include/ChannelSidePanel.hpp +++ b/include/ChannelSidePanel.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include namespace dchat { @@ -9,7 +10,12 @@ namespace dchat class ChannelSidePanel { public: + ChannelSidePanel(float width); void addChannel(Channel *channel); + + void draw(sf::RenderWindow &window); + + float width; private: std::vector channels; }; diff --git a/include/Chatbar.hpp b/include/Chatbar.hpp index d24b2af..c98db48 100644 --- a/include/Chatbar.hpp +++ b/include/Chatbar.hpp @@ -27,7 +27,7 @@ namespace dchat bool isFocused() const; void processEvent(const sf::Event &event, Channel *channel); - void draw(sf::RenderWindow &window); + void draw(sf::RenderWindow &window, const sf::Vector2f &position); private: sf::Text text; sf::RectangleShape background; diff --git a/include/MessageBoard.hpp b/include/MessageBoard.hpp index ca1405f..523fb16 100644 --- a/include/MessageBoard.hpp +++ b/include/MessageBoard.hpp @@ -20,7 +20,7 @@ namespace dchat void addMessage(Message *message); void processEvent(const sf::Event &event); - void draw(sf::RenderWindow &window, Cache &cache); + void draw(sf::RenderWindow &window, const sf::Vector2f &position, Cache &cache); private: sf::RenderTexture staticContentTexture; bool dirty; diff --git a/src/Channel.cpp b/src/Channel.cpp index e16b25f..347a6a6 100644 --- a/src/Channel.cpp +++ b/src/Channel.cpp @@ -5,9 +5,10 @@ using namespace std; namespace dchat { - Channel::Channel() : + Channel::Channel(const std::string &_name) : messageBoard(sf::Vector2u(1.0f, 1.0f)), - localOfflineUser("You") + localOfflineUser("You"), + name(_name) { { Message *message = new Message(&localOfflineUser, u8"hello, worldåäö1![emoji](https://discordemoji.com/assets/emoji/playtime.png)"); @@ -24,6 +25,11 @@ namespace dchat messageBoard.addMessage(message); } + { + Message *message = new Message(&localOfflineUser, u8"Lorem ipsumdolorsitamet,consecteturadipiscingelit,seddoeiusmodtemporincididuntutaboreetdoloremagnaaliqua.Utenimadminimveniam"); + messageBoard.addMessage(message); + } + { Message *message = new Message(&localOfflineUser, u8"xddd"); messageBoard.addMessage(message); @@ -38,6 +44,11 @@ namespace dchat Message *message = new Message(&localOfflineUser, u8"Message after big emoji"); messageBoard.addMessage(message); } + + { + Message *message = new Message(&localOfflineUser, u8"aaa\n[emoji](https://discordemoji.com/assets/emoji/Feels3DMan.gif)\nbbb"); + messageBoard.addMessage(message); + } } Channel::~Channel() @@ -55,15 +66,20 @@ namespace dchat return messageBoard; } + const string& Channel::getName() const + { + return name; + } + void Channel::processEvent(const sf::Event &event) { chatbar.processEvent(event, this); messageBoard.processEvent(event); } - void Channel::draw(sf::RenderWindow &window, Cache &cache) + void Channel::draw(sf::RenderWindow &window, const sf::Vector2f &position, Cache &cache) { - messageBoard.draw(window, cache); - chatbar.draw(window); + messageBoard.draw(window, position, cache); + chatbar.draw(window, position); } } diff --git a/src/ChannelSidePanel.cpp b/src/ChannelSidePanel.cpp index 23693b3..3958376 100644 --- a/src/ChannelSidePanel.cpp +++ b/src/ChannelSidePanel.cpp @@ -1,9 +1,42 @@ #include "../include/ChannelSidePanel.hpp" +#include "../include/ResourceCache.hpp" +#include "../include/Settings.hpp" +#include "../include/Channel.hpp" +#include +#include +#include namespace dchat { + ChannelSidePanel::ChannelSidePanel(float _width) : + width(floor(_width)) + { + + } + void ChannelSidePanel::addChannel(Channel *channel) { channels.push_back(channel); } + + void ChannelSidePanel::draw(sf::RenderWindow &window) + { + auto windowSize = window.getSize(); + sf::RectangleShape rect(sf::Vector2f(width, windowSize.y)); + rect.setFillColor(sf::Color(30, 30, 30)); + window.draw(rect); + + const sf::Font &font = ResourceCache::getFont("fonts/Roboto-Regular.ttf"); + sf::Vector2f position; + for(Channel *channel : channels) + { + // TODO: Remove this shit + sf::String str = "# "; + str += sf::String::fromUtf8(channel->getName().begin(), channel->getName().end()); + sf::Text text(str, font, 24 * Settings::getScaling()); + text.setPosition(position); + window.draw(text); + position.y += font.getLineSpacing(24 * Settings::getScaling()); + } + } } diff --git a/src/Chatbar.cpp b/src/Chatbar.cpp index d775db4..fcfec36 100644 --- a/src/Chatbar.cpp +++ b/src/Chatbar.cpp @@ -137,12 +137,12 @@ namespace dchat } } - void Chatbar::draw(sf::RenderWindow &window) + void Chatbar::draw(sf::RenderWindow &window, const sf::Vector2f &position) { auto windowSize = window.getSize(); sf::Vector2f backgroundSize(floor(windowSize.x * 0.7f), floor(text.getCharacterSize() * 1.7f + BOX_PADDING_Y * 2.0f)); - sf::Vector2f backgroundPos(floor(windowSize.x * 0.5f - backgroundSize.x * 0.5f), floor(windowSize.y - backgroundSize.y - 20.0f)); + sf::Vector2f backgroundPos(floor(position.x), floor(position.y + windowSize.y - backgroundSize.y - 20.0f)); background.setSize(backgroundSize); background.setPosition(backgroundPos); text.setPosition(floor(backgroundPos.x + BOX_PADDING_X), floor(backgroundPos.y + backgroundSize.y * 0.5f - text.getCharacterSize() * 0.5f)); diff --git a/src/Gif.cpp b/src/Gif.cpp index b1f4fd3..eed5b98 100644 --- a/src/Gif.cpp +++ b/src/Gif.cpp @@ -107,6 +107,7 @@ namespace dchat if(!texture.create(gif.width, gif.height)) throw GifLoadException("Failed to create texture for gif"); + texture.setSmooth(true); sprite.setTexture(texture, true); } @@ -157,6 +158,8 @@ namespace dchat if(currentFrame != startFrame) { texture.update(image); + // TODO: Check if this is too heavy + texture.generateMipmap(); sprite.setTexture(texture, true); } target.draw(sprite); diff --git a/src/MessageBoard.cpp b/src/MessageBoard.cpp index 0b0e2fe..4cab31d 100644 --- a/src/MessageBoard.cpp +++ b/src/MessageBoard.cpp @@ -93,11 +93,10 @@ namespace dchat } } - void MessageBoard::draw(sf::RenderWindow &window, Cache &cache) + void MessageBoard::draw(sf::RenderWindow &window, const sf::Vector2f &pos, Cache &cache) { auto windowSize = window.getSize(); - sf::Vector2u backgroundSize(floor(windowSize.x * 0.7f), floor(windowSize.y)); - sf::Vector2f backgroundPos(floor(windowSize.x * 0.5f - backgroundSize.x * 0.5f), 0.0f); + sf::Vector2u backgroundSize(floor(windowSize.x - pos.x * 2.0f), floor(windowSize.y)); //if(backgroundSize != staticContentTexture.getSize()) // updateStaticContentTexture(backgroundSize); @@ -117,7 +116,8 @@ namespace dchat if(dirty) { - sf::Vector2f position = backgroundPos; + sf::Vector2f position = pos; + position.x += 20.0f; position.y += scroll; for(Message *message : messages) { diff --git a/src/main.cpp b/src/main.cpp index 6d718e5..67f4865 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,9 +30,9 @@ int main(int argc, char **argv) Cache cache; - Channel channel; - //ChannelSidePanel channelSidePanel; - //channelSidePanel.addChannel(&channel); + Channel channel("latenightshiendjs"); + ChannelSidePanel channelSidePanel(300.0f); + channelSidePanel.addChannel(&channel); sf::Event event; while (window.isOpen()) @@ -50,7 +50,8 @@ int main(int argc, char **argv) } window.clear(sf::Color(40, 40, 40)); - channel.draw(window, cache); + channel.draw(window, sf::Vector2f(channelSidePanel.width, 0.0f), cache); + channelSidePanel.draw(window); window.display(); } -- cgit v1.2.3