#include "../include/ChannelTopPanel.hpp" #include "../include/Settings.hpp" #include "../include/ResourceCache.hpp" #include "../include/Channel.hpp" #include "../include/ColorScheme.hpp" #include #include namespace dchat { struct LineColor { sf::Color sideColor, centerColor; }; const float FONT_SIZE = 40.0f; const float BOTTOM_LINE_HEIGHT = 2.0f; const float PADDING_TOP = 20.0f; const float PADDING_BOTTOM = PADDING_TOP; static void drawGradientLine(const sf::Vector2f &position, const sf::Vector2f &size, const LineColor &color, sf::RenderWindow &window) { sf::Vertex rectangle[] = { sf::Vertex(position, color.sideColor), sf::Vertex(sf::Vector2f(position.x + size.x * 0.5f, position.y), color.centerColor), sf::Vertex(sf::Vector2f(position.x + size.x * 0.5f, position.y + size.y), color.centerColor), sf::Vertex(sf::Vector2f(position.x, position.y + size.y), color.sideColor), sf::Vertex(sf::Vector2f(position.x + size.x * 0.5f, position.y), color.centerColor), sf::Vertex(sf::Vector2f(position.x + size.x, position.y), color.sideColor), sf::Vertex(sf::Vector2f(position.x + size.x, position.y + size.y), color.sideColor), sf::Vertex(sf::Vector2f(position.x + size.x * 0.5f, position.y + size.y), color.centerColor) }; window.draw(rectangle, 8, sf::Quads); } void ChannelTopPanel::draw(sf::RenderWindow &window) { const sf::Color lineSideColor = ColorScheme::getBackgroundColor(); const sf::Color lineCenterColor = lineSideColor + sf::Color(40, 0, 0); auto windowSize = window.getSize(); sf::RectangleShape rect(sf::Vector2f(windowSize.x, getHeight() - BOTTOM_LINE_HEIGHT)); rect.setFillColor(ColorScheme::getBackgroundColor()); window.draw(rect); sf::Vector2f bottomLinePos(0.0f, getHeight() - BOTTOM_LINE_HEIGHT); sf::Vector2f bottomLineSize(windowSize.x, BOTTOM_LINE_HEIGHT); LineColor lineColor { .sideColor = lineSideColor, .centerColor = lineCenterColor }; drawGradientLine(bottomLinePos, bottomLineSize, lineColor, window); Channel *currentChannel = Channel::getCurrent(); if(!currentChannel) return; sf::String str = "# "; str += sf::String::fromUtf8(currentChannel->getName().begin(), currentChannel->getName().end()); float fontSize = FONT_SIZE * Settings::getScaling(); sf::Text text(str, *ResourceCache::getFont("fonts/Roboto-Regular.ttf"), fontSize); auto textBounds = text.getLocalBounds(); text.setPosition(floor((float)windowSize.x * 0.5f - textBounds.width * 0.5f), PADDING_TOP); text.setFillColor(ColorScheme::getTextRegularColor()); window.draw(text); } float ChannelTopPanel::getHeight() { float fontSize = FONT_SIZE * Settings::getScaling(); return floor(ResourceCache::getFont("fonts/Roboto-Regular.ttf")->getLineSpacing(fontSize) + PADDING_TOP + PADDING_BOTTOM); } }