diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-04-29 12:29:01 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2018-04-29 12:29:13 +0200 |
commit | 607b15dbc2e1dfa8633e7ae679b709fe21c94599 (patch) | |
tree | 6e323ec65de8c5f362a08abf8fef5c12b8398d4f /src/MessageBoard.cpp | |
parent | e7caed2208893723181892d5e197b924311373fb (diff) |
Fix image ratio, implement scroll locking (cant scroll outside messages)
Diffstat (limited to 'src/MessageBoard.cpp')
-rw-r--r-- | src/MessageBoard.cpp | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/src/MessageBoard.cpp b/src/MessageBoard.cpp index fbc7484..d16d16c 100644 --- a/src/MessageBoard.cpp +++ b/src/MessageBoard.cpp @@ -5,6 +5,7 @@ #include "../include/ChannelSidePanel.hpp" #include "../include/UsersSidePanel.hpp" #include "../include/ChannelTopPanel.hpp" +#include "../include/Chatbar.hpp" #include "../include/ColorScheme.hpp" #include <SFML/Graphics/RectangleShape.hpp> #include <SFML/Graphics/Sprite.hpp> @@ -58,7 +59,8 @@ namespace dchat selectingText(false), leftMouseButtonPressed(false), scroll(0.0), - scrollSpeed(0.0) + scrollSpeed(0.0), + totalHeight(0.0) { updateStaticContentTexture(size); } @@ -133,8 +135,9 @@ namespace dchat void MessageBoard::draw(sf::RenderWindow &window, Cache &cache) { auto windowSize = window.getSize(); - sf::Vector2f backgroundSizeWithoutPadding(floor(windowSize.x - ChannelSidePanel::getWidth() - UsersSidePanel::getWidth()), floor(windowSize.y - ChannelTopPanel::getHeight())); - sf::Vector2u backgroundSize(floor(windowSize.x - ChannelSidePanel::getWidth() - UsersSidePanel::getWidth() - PADDING_SIDE * 2.0f), floor(windowSize.y)); + sf::Vector2f backgroundSizeWithoutPadding(floor(windowSize.x - ChannelSidePanel::getWidth() - UsersSidePanel::getWidth()), floor(windowSize.y - ChannelTopPanel::getHeight() - Chatbar::getHeight())); + sf::Vector2u backgroundSize(floor(windowSize.x - ChannelSidePanel::getWidth() - UsersSidePanel::getWidth() - PADDING_SIDE * 2.0f), floor(windowSize.y - ChannelTopPanel::getHeight() - Chatbar::getHeight() - PADDING_TOP)); + sf::Vector2f backgroundPos(ChannelSidePanel::getWidth(), ChannelTopPanel::getHeight()); //if(backgroundSize != staticContentTexture.getSize()) // updateStaticContentTexture(backgroundSize); @@ -154,19 +157,17 @@ namespace dchat double deltaTimeMicro = (double)frameTimer.getElapsedTime().asMicroseconds(); frameTimer.restart(); - scroll += scrollSpeed; - scrollSpeed /= (deltaTimeMicro * 0.0001); - if(dirty) { - sf::Vector2f position(ChannelSidePanel::getWidth(), ChannelTopPanel::getHeight() + PADDING_TOP); + sf::Vector2<double> position(ChannelSidePanel::getWidth(), ChannelTopPanel::getHeight() + PADDING_TOP); + double startHeight = position.y; position.y += scroll; for(Message *message : messages) { 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) + if(position.y + usernameTextHeight > 0.0f && position.y < backgroundPos.y + backgroundSize.y) { usernameText.setFillColor(sf::Color(15, 192, 252)); usernameText.setPosition(sf::Vector2f(floor(position.x + PADDING_SIDE), floor(position.y))); @@ -181,9 +182,25 @@ namespace dchat message->text.draw(window, cache); position.y += message->text.getHeight() + MESSAGE_PADDING_BOTTOM; - if(position.y + LINE_HEIGHT > 0.0f && position.y < backgroundSize.y) + if(position.y + LINE_HEIGHT > 0.0f && position.y < backgroundPos.y + backgroundSize.y) drawGradientLine(sf::Vector2f(position.x + LINE_SIDE_PADDING, floor(position.y)), sf::Vector2f(backgroundSizeWithoutPadding.x - LINE_SIDE_PADDING * 2.0f, LINE_HEIGHT), LINE_COLOR, window); } + totalHeight = (position.y - scroll) - startHeight; + } + + scroll += scrollSpeed; + scrollSpeed /= (deltaTimeMicro * 0.0001); + + double textOverflow = backgroundSize.y - totalHeight; + if(scroll > 0.0 || textOverflow > 0.0) + { + scroll = 0.0; + scrollSpeed = 0.0; + } + else if(textOverflow < 0.0 && scroll < textOverflow) + { + scroll = textOverflow; + scrollSpeed = 0.0; } //staticContentTexture.display(); |