From f90a5705bd65a4ebb5edc9df003a383039fec555 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 29 Apr 2018 08:17:30 +0200 Subject: Change design, fix crash when closing application --- src/ChannelSidePanel.cpp | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'src/ChannelSidePanel.cpp') diff --git a/src/ChannelSidePanel.cpp b/src/ChannelSidePanel.cpp index f5a4063..18b581c 100644 --- a/src/ChannelSidePanel.cpp +++ b/src/ChannelSidePanel.cpp @@ -1,4 +1,5 @@ #include "../include/ChannelSidePanel.hpp" +#include "../include/ChannelTopPanel.hpp" #include "../include/ResourceCache.hpp" #include "../include/Settings.hpp" #include "../include/Channel.hpp" @@ -12,8 +13,10 @@ using namespace std; namespace dchat { vector channels; - const float width = 200.0f; + const float WIDTH = 200.0f; const unsigned int FONT_SIZE = 20; + const float PADDING_BOTTOM = 10.0f; + const float CHANNEL_NAME_BOX_HEIGHT_RATIO = 1.5f; void ChannelSidePanel::addChannel(Channel *channel) { @@ -27,27 +30,42 @@ namespace dchat void ChannelSidePanel::draw(sf::RenderWindow &window) { + float posY = ChannelTopPanel::getHeight(); auto windowSize = window.getSize(); - sf::RectangleShape rect(sf::Vector2f(width, windowSize.y)); - rect.setFillColor(sf::Color(30, 30, 30)); + sf::RectangleShape rect(sf::Vector2f(WIDTH, windowSize.y)); + rect.setPosition(0.0f, posY); + rect.setFillColor(sf::Color(35, 35, 35)); window.draw(rect); + //posY += 10.0f; const sf::Font *font = ResourceCache::getFont("fonts/Roboto-Regular.ttf"); - sf::Vector2f position(10.0f, 10.0f); + const float fontSize = FONT_SIZE * Settings::getScaling(); + const float fontHeight = font->getLineSpacing(fontSize); + const float channelBoxHeight = floor(fontHeight * CHANNEL_NAME_BOX_HEIGHT_RATIO); + + sf::Vector2f position(10.0f, posY); for(Channel *channel : channels) { + if(channel == Channel::getCurrent()) + { + rect.setFillColor(sf::Color(50, 50, 50)); + rect.setSize(sf::Vector2f(WIDTH, channelBoxHeight)); + rect.setPosition(sf::Vector2f(0.0f, position.y)); + window.draw(rect); + } + // TODO: Remove this shit sf::String str = "# "; str += sf::String::fromUtf8(channel->getName().begin(), channel->getName().end()); - sf::Text text(str, *font, FONT_SIZE * Settings::getScaling()); - text.setPosition(position); + sf::Text text(str, *font, fontSize); + text.setPosition(sf::Vector2f(position.x, floor(position.y + channelBoxHeight * 0.5f - fontHeight * 0.5f))); window.draw(text); - position.y += font->getLineSpacing(FONT_SIZE * Settings::getScaling()); + position.y += floor(fontHeight + PADDING_BOTTOM); } } float ChannelSidePanel::getWidth() { - return width; + return WIDTH; } } -- cgit v1.2.3