aboutsummaryrefslogtreecommitdiff
path: root/src/MessageBoard.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-05-01 13:27:52 +0200
committerdec05eba <dec05eba@protonmail.com>2018-05-01 13:28:29 +0200
commit431c1dcded16649c10331b9dc4e57f20067cea0b (patch)
tree3f5327ca81f76ad7c77f36a930d56401a4ec458e /src/MessageBoard.cpp
parent9e576f9fbcbcc4603689b0b1215cf3d526bd9616 (diff)
Add 'add user', 'join channel'. Improve scrolling. Added locks
Diffstat (limited to 'src/MessageBoard.cpp')
-rw-r--r--src/MessageBoard.cpp34
1 files changed, 29 insertions, 5 deletions
diff --git a/src/MessageBoard.cpp b/src/MessageBoard.cpp
index bcdf5c7..031bbdf 100644
--- a/src/MessageBoard.cpp
+++ b/src/MessageBoard.cpp
@@ -61,7 +61,8 @@ namespace dchat
leftMouseButtonPressed(false),
scroll(0.0),
scrollSpeed(0.0),
- totalHeight(0.0)
+ totalHeight(0.0),
+ scrollToBottom(false)
{
updateStaticContentTexture(size);
}
@@ -85,6 +86,7 @@ namespace dchat
{
messages.push_back(message);
dirty = true;
+ scrollToBottom = true;
}
void MessageBoard::processEvent(const sf::Event &event)
@@ -118,7 +120,7 @@ namespace dchat
}
else if(event.type == sf::Event::MouseWheelScrolled && event.mouseWheelScroll.wheel == sf::Mouse::Wheel::VerticalWheel)
{
- scrollSpeed += (event.mouseWheelScroll.delta * 30.0);
+ scrollSpeed += (event.mouseWheelScroll.delta * 5.0);
}
if(selectingText && !leftMouseButtonPressed)
@@ -186,9 +188,10 @@ namespace dchat
{
time_t time = (time_t)message->timestampSeconds;
struct tm *localTimePtr = localtime(&time);
- char *timeStr = asctime(localTimePtr);
+ char date[30];
+ strftime(date, sizeof(date), "%Y-%m-%d at %T", localTimePtr);
- sf::Text timestamp(timeStr, *timestampFont, timestampTextCharacterSize);
+ sf::Text timestamp(date, *timestampFont, timestampTextCharacterSize);
timestamp.setFillColor(ColorScheme::getTextRegularColor() * sf::Color(255, 255, 255, 30));
timestamp.setPosition(sf::Vector2f(floor(position.x + PADDING_SIDE + usernameText.getLocalBounds().width + USERNAME_TIMESTAMP_SIDE_PADDING * Settings::getScaling()), floor(position.y + 2.0f * Settings::getScaling() + usernameTextHeight * 0.5f - timestampTextHeight * 0.5f)));
window.draw(timestamp);
@@ -216,7 +219,19 @@ namespace dchat
}
scroll += scrollSpeed;
- scrollSpeed /= (deltaTimeMicro * 0.0001);
+
+ double deltaTimeScrollMultiplier = deltaTimeMicro * 0.00004;
+ if(scrollSpeed > 0.0)
+ {
+ scrollSpeed -= deltaTimeScrollMultiplier;
+ }
+ else
+ {
+ scrollSpeed += deltaTimeScrollMultiplier;
+ }
+
+ if(abs(scrollSpeed - deltaTimeScrollMultiplier) <= deltaTimeScrollMultiplier)
+ scrollSpeed = 0.0;
double textOverflow = backgroundSize.y - totalHeight;
if(scroll > 0.0 || textOverflow > 0.0)
@@ -230,6 +245,15 @@ namespace dchat
scrollSpeed = 0.0;
}
+ if(scrollToBottom)
+ {
+ scrollToBottom = false;
+ if(textOverflow < 0.0)
+ scroll = textOverflow;
+ else
+ scroll = 0.0;
+ }
+
//staticContentTexture.display();
dirty = false;