diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-04-29 08:17:30 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2018-04-29 08:17:36 +0200 |
commit | f90a5705bd65a4ebb5edc9df003a383039fec555 (patch) | |
tree | f0180d946bddc15a0a13d9148562418cb3a4108e /src/MessageBoard.cpp | |
parent | 68dcd3c4e17355e1c2b640fe1382743d7cb61ea2 (diff) |
Change design, fix crash when closing application
Diffstat (limited to 'src/MessageBoard.cpp')
-rw-r--r-- | src/MessageBoard.cpp | 52 |
1 files changed, 45 insertions, 7 deletions
diff --git a/src/MessageBoard.cpp b/src/MessageBoard.cpp index a0f1e20..58d54f2 100644 --- a/src/MessageBoard.cpp +++ b/src/MessageBoard.cpp @@ -4,6 +4,7 @@ #include "../include/Gif.hpp" #include "../include/ChannelSidePanel.hpp" #include "../include/UsersSidePanel.hpp" +#include "../include/ChannelTopPanel.hpp" #include <SFML/Graphics/RectangleShape.hpp> #include <SFML/Graphics/Sprite.hpp> #include <SFML/Window/Mouse.hpp> @@ -15,11 +16,43 @@ using namespace std; namespace dchat { + struct LineColor + { + sf::Color sideColor, centerColor; + }; + const sf::Color BACKGROUND_COLOR(40, 40, 40); const float USERNAME_PADDING_BOTTOM = 0.0f; - const float MESSAGE_PADDING_BOTTOM = 20.0f; + const float MESSAGE_PADDING_TOP = 25.0f; + const float MESSAGE_PADDING_BOTTOM = 30.0f; - const float PADDING_SIDE = 20.0f; + const float PADDING_SIDE = 40.0f; + const float PADDING_TOP = 5.0f; + const float LINE_SIDE_PADDING = 20.0f; + const float LINE_HEIGHT = 1.0f; + + const LineColor LINE_COLOR + { + .sideColor = sf::Color(50, 50, 50), + .centerColor = sf::Color(50, 50, 50) + }; + + 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); + } MessageBoard::MessageBoard(const sf::Vector2u &size) : selectingText(false), @@ -100,6 +133,7 @@ namespace dchat void MessageBoard::draw(sf::RenderWindow &window, Cache &cache) { auto windowSize = window.getSize(); + const float backgroundWidthWithoutPadding = floor(windowSize.x - ChannelSidePanel::getWidth() - UsersSidePanel::getWidth()); sf::Vector2u backgroundSize(floor(windowSize.x - ChannelSidePanel::getWidth() - UsersSidePanel::getWidth() - PADDING_SIDE * 2.0f), floor(windowSize.y)); //if(backgroundSize != staticContentTexture.getSize()) @@ -120,26 +154,30 @@ namespace dchat if(dirty) { - sf::Vector2f position; - position.x = ChannelSidePanel::getWidth() + PADDING_SIDE; + sf::Vector2f position(ChannelSidePanel::getWidth(), ChannelTopPanel::getHeight() + PADDING_TOP); position.y += scroll; for(Message *message : messages) { - sf::Text usernameText(message->user->getName(), *usernameFont, 24 * Settings::getScaling()); + position.y += MESSAGE_PADDING_TOP; + sf::Text usernameText(message->user->getName(), *usernameFont, 20 * Settings::getScaling()); float usernameTextHeight = usernameText.getFont()->getLineSpacing(usernameText.getCharacterSize()); if(position.y + usernameTextHeight > 0.0f && position.y < backgroundSize.y) { usernameText.setFillColor(sf::Color(15, 192, 252)); - usernameText.setPosition(sf::Vector2f(floor(position.x), floor(position.y))); + usernameText.setPosition(sf::Vector2f(floor(position.x + PADDING_SIDE), floor(position.y))); window.draw(usernameText); } position.y += usernameTextHeight + USERNAME_PADDING_BOTTOM; // No need to perform culling here, that is done in @Text draw function + message->text.setCharacterSize(18 * Settings::getScaling()); message->text.setMaxWidth(backgroundSize.x); - message->text.setPosition(sf::Vector2f(floor(position.x), floor(position.y))); + message->text.setPosition(sf::Vector2f(floor(position.x + PADDING_SIDE), floor(position.y))); message->text.draw(window, cache); position.y += message->text.getHeight() + MESSAGE_PADDING_BOTTOM; + + if(position.y + LINE_HEIGHT > 0.0f && position.y < backgroundSize.y) + drawGradientLine(sf::Vector2f(position.x + LINE_SIDE_PADDING, floor(position.y)), sf::Vector2f(backgroundWidthWithoutPadding - LINE_SIDE_PADDING * 2.0f, LINE_HEIGHT), LINE_COLOR, window); } } |