#include "../include/RoomSidePanel.hpp" #include "../include/RoomTopPanel.hpp" #include "../include/ResourceCache.hpp" #include "../include/Settings.hpp" #include "../include/ColorScheme.hpp" #include "../include/Room.hpp" #include #include #include #include #include #include using namespace std; namespace dchat { static sf::Vector2f position; const float WIDTH = 300.0f; const unsigned int FONT_SIZE = 20; const float PADDING_BOTTOM = 10.0f; const float CHANNEL_NAME_BOX_HEIGHT_RATIO = 1.5f; void RoomSidePanel::draw(sf::RenderWindow &window) { std::shared_ptr rooms = getRooms(); if(!rooms) return; float posY = RoomTopPanel::getHeight(); auto windowSize = window.getSize(); sf::RectangleShape rect(sf::Vector2f(getWidth(), windowSize.y)); rect.setPosition(0.0f, 0.0f); rect.setFillColor(ColorScheme::getPanelColor()); window.draw(rect); const sf::Font *font = ResourceCache::getFont("fonts/Nunito-Regular.ttf"); const float fontSize = FONT_SIZE * Settings::getScaling(); const float fontHeight = font->getLineSpacing(fontSize); const float channelBoxHeight = floor(fontHeight * CHANNEL_NAME_BOX_HEIGHT_RATIO); auto mousePos = sf::Mouse::getPosition(window); position.y = posY; for(auto &it : rooms->getRooms()) { const std::shared_ptr room = it.second; sf::FloatRect box(0.0f, position.y, getWidth(), channelBoxHeight); if(room == getCurrentRoom()) { rect.setFillColor(ColorScheme::getBackgroundColor() + sf::Color(15, 15, 15)); rect.setSize(sf::Vector2f(box.width, box.height)); rect.setPosition(sf::Vector2f(0.0f, position.y)); window.draw(rect); } else if(box.contains(mousePos.x, mousePos.y)) { rect.setFillColor(ColorScheme::getBackgroundColor() + sf::Color(5, 5, 5)); rect.setSize(sf::Vector2f(box.width, box.height)); rect.setPosition(sf::Vector2f(0.0f, position.y)); window.draw(rect); if(sf::Mouse::isButtonPressed(sf::Mouse::Button::Left)) { setCurrentRoom(room); } } // TODO: Remove this shit sf::String str = "# "; str += sf::String::fromUtf8(room->name.begin(), room->name.end()); sf::Text text(str, *font, fontSize); text.setPosition(sf::Vector2f(position.x, floor(position.y + channelBoxHeight * 0.5f - fontHeight * 0.5f))); text.setFillColor(ColorScheme::getTextRegularColor()); window.draw(text); position.y += floor(fontHeight + PADDING_BOTTOM); } } float RoomSidePanel::getWidth() { return floor(WIDTH * Settings::getScaling()); } float RoomSidePanel::getHeight() { return position.y; } }