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, 30 insertions, 5 deletions
diff --git a/src/MessageBoard.cpp b/src/MessageBoard.cpp
index cd73c6d..bcdf5c7 100644
--- a/src/MessageBoard.cpp
+++ b/src/MessageBoard.cpp
@@ -23,7 +23,7 @@ namespace dchat
sf::Color sideColor, centerColor;
};
- const float USERNAME_PADDING_BOTTOM = 0.0f;
+ const float USERNAME_PADDING_BOTTOM = 5.0f;
const float MESSAGE_PADDING_TOP = 25.0f;
const float MESSAGE_PADDING_BOTTOM = 30.0f;
@@ -31,6 +31,7 @@ namespace dchat
const float PADDING_TOP = 0.0f;
const float LINE_SIDE_PADDING = 20.0f;
const float LINE_HEIGHT = 1.0f;
+ const float USERNAME_TIMESTAMP_SIDE_PADDING = 10.0f;
const LineColor LINE_COLOR
{
@@ -153,27 +154,47 @@ namespace dchat
window.draw(backgroundRect);
const sf::Font *usernameFont = ResourceCache::getFont("fonts/Roboto-Regular.ttf");
+ const int usernameTextCharacterSize = 20 * Settings::getScaling();
+ const float usernameTextHeight = usernameFont->getLineSpacing(usernameTextCharacterSize);
+
+ const sf::Font *timestampFont = ResourceCache::getFont("fonts/Roboto-Regular.ttf");
+ const int timestampTextCharacterSize = 15 * Settings::getScaling();
+ const float timestampTextHeight = timestampFont->getLineSpacing(timestampTextCharacterSize);
double deltaTimeMicro = (double)frameTimer.getElapsedTime().asMicroseconds();
frameTimer.restart();
if(dirty)
{
+ sf::RectangleShape lineRect(sf::Vector2f(backgroundSizeWithoutPadding.x - LINE_SIDE_PADDING * 2.0f, LINE_HEIGHT));
+ lineRect.setFillColor(ColorScheme::getBackgroundColor() + sf::Color(10, 10, 10));
+
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 < backgroundPos.y + backgroundSize.y)
{
+ sf::Text usernameText(message->user->getName(), *usernameFont, usernameTextCharacterSize);
usernameText.setFillColor(sf::Color(15, 192, 252));
usernameText.setPosition(sf::Vector2f(floor(position.x + PADDING_SIDE), floor(position.y)));
window.draw(usernameText);
+
+ if(message->timestampSeconds)
+ {
+ time_t time = (time_t)message->timestampSeconds;
+ struct tm *localTimePtr = localtime(&time);
+ char *timeStr = asctime(localTimePtr);
+
+ sf::Text timestamp(timeStr, *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);
+ }
}
- position.y += usernameTextHeight + USERNAME_PADDING_BOTTOM;
+ position.y += usernameTextHeight + USERNAME_PADDING_BOTTOM * Settings::getScaling();
// No need to perform culling here, that is done in @Text draw function
message->text.setCharacterSize(18 * Settings::getScaling());
@@ -183,7 +204,11 @@ namespace dchat
position.y += message->text.getHeight() + MESSAGE_PADDING_BOTTOM;
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);
+ {
+ lineRect.setPosition(sf::Vector2f(position.x + LINE_SIDE_PADDING, floor(position.y)));
+ window.draw(lineRect);
+ //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);
+ }
position.y += LINE_HEIGHT;
}