From 725ea566a2b6a12e0a02e4f570b6e99102e2d21b Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 8 Apr 2019 21:04:12 +0200 Subject: Refactor, remove a lot of code and use dchat core instead --- src/RoomSidePanel.cpp | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 src/RoomSidePanel.cpp (limited to 'src/RoomSidePanel.cpp') diff --git a/src/RoomSidePanel.cpp b/src/RoomSidePanel.cpp new file mode 100644 index 0000000..a7baf8a --- /dev/null +++ b/src/RoomSidePanel.cpp @@ -0,0 +1,88 @@ +#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; + } +} -- cgit v1.2.3