#include "../include/RoomTopPanel.hpp" #include "../include/Settings.hpp" #include "../include/ResourceCache.hpp" #include "../include/ColorScheme.hpp" #include "../include//RoomSidePanel.hpp" #include "../include/UsersSidePanel.hpp" #include "../include/Room.hpp" #include #include #include #include namespace dchat { struct LineColor { sf::Color sideColor, centerColor; }; const float FONT_SIZE = 30.0f; const float BOTTOM_LINE_HEIGHT = 2.0f; const float PADDING_TOP = 15.0f; const float PADDING_BOTTOM = PADDING_TOP; const float PADDING_SIDE = 20.0f; 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 RoomTopPanel::draw(sf::RenderWindow &window) { const sf::Color lineSideColor = ColorScheme::getBackgroundColor() + sf::Color(20, 0, 0); const sf::Color lineCenterColor = lineSideColor + sf::Color(40, 0, 0); auto windowSize = window.getSize(); sf::RectangleShape rect(sf::Vector2f(floor(windowSize.x - RoomSidePanel::getWidth()), getHeight() - BOTTOM_LINE_HEIGHT)); rect.setPosition(RoomSidePanel::getWidth(), 0.0f); rect.setFillColor(ColorScheme::getBackgroundColor()); window.draw(rect); sf::Vector2f bottomLinePos(floor(RoomSidePanel::getWidth() + PADDING_SIDE * Settings::getScaling()), getHeight() - BOTTOM_LINE_HEIGHT); sf::Vector2f bottomLineSize(floor(windowSize.x - RoomSidePanel::getWidth() - PADDING_SIDE * Settings::getScaling() * 2.0f), BOTTOM_LINE_HEIGHT); LineColor lineColor; lineColor.sideColor = lineSideColor; lineColor.centerColor = lineCenterColor; drawGradientLine(bottomLinePos, bottomLineSize, lineColor, window); std::shared_ptr currentRoom = getCurrentRoom(); if(!currentRoom) return; sf::String str = "# "; str += sf::String::fromUtf8(currentRoom->name.begin(), currentRoom->name.end()); float fontSize = FONT_SIZE * Settings::getScaling(); sf::Text text(str, *ResourceCache::getFont("fonts/Nunito-Regular.ttf"), fontSize); text.setPosition(floor(RoomSidePanel::getWidth() + PADDING_SIDE * Settings::getScaling()), PADDING_TOP); text.setFillColor(ColorScheme::getTextRegularColor()); window.draw(text); } float RoomTopPanel::getHeight() { float fontSize = FONT_SIZE * Settings::getScaling(); return floor(ResourceCache::getFont("fonts/Nunito-Regular.ttf")->getLineSpacing(fontSize) + PADDING_TOP + PADDING_BOTTOM + BOTTOM_LINE_HEIGHT); } }