aboutsummaryrefslogtreecommitdiff
path: root/src/MessageBoard.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/MessageBoard.cpp')
-rw-r--r--src/MessageBoard.cpp35
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();