aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-04-23 18:49:45 +0200
committerdec05eba <dec05eba@protonmail.com>2018-04-23 18:49:52 +0200
commit7e7dfd227eacaa80b21ca8ed99e8a99ccbd47769 (patch)
tree016e3907471ae1b588c35cf963ea2551efc57cfc /src
parent3ab4127ae3fc3b837f5350509c78db03467500cd (diff)
Add side bar, make submodule public
Diffstat (limited to 'src')
-rw-r--r--src/Channel.cpp26
-rw-r--r--src/ChannelSidePanel.cpp33
-rw-r--r--src/Chatbar.cpp4
-rw-r--r--src/Gif.cpp3
-rw-r--r--src/MessageBoard.cpp8
-rw-r--r--src/main.cpp9
6 files changed, 68 insertions, 15 deletions
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)");
@@ -25,6 +26,11 @@ namespace dchat
}
{
+ 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 <SFML/Graphics/RectangleShape.hpp>
+#include <SFML/Graphics/Text.hpp>
+#include <cmath>
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();
}