aboutsummaryrefslogtreecommitdiff
path: root/src/MessageBoard.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-04-23 13:30:03 +0200
committerdec05eba <dec05eba@protonmail.com>2018-04-23 13:30:58 +0200
commit3ab4127ae3fc3b837f5350509c78db03467500cd (patch)
tree5f56c61c0129b8dff0f8feea4d6f93d4cd656560 /src/MessageBoard.cpp
parentddff0f1b7ea84f6a1321b8eb8a4d47317873d955 (diff)
Add support for big emoji if it's the only thing on a line
TODO: Currently message board renders directly to window, it should render to render target for optimization purpose
Diffstat (limited to 'src/MessageBoard.cpp')
-rw-r--r--src/MessageBoard.cpp52
1 files changed, 35 insertions, 17 deletions
diff --git a/src/MessageBoard.cpp b/src/MessageBoard.cpp
index fd41f02..0b0e2fe 100644
--- a/src/MessageBoard.cpp
+++ b/src/MessageBoard.cpp
@@ -19,7 +19,9 @@ namespace dchat
MessageBoard::MessageBoard(const sf::Vector2u &size) :
selectingText(false),
- leftMouseButtonPressed(false)
+ leftMouseButtonPressed(false),
+ scroll(0.0),
+ scrollSpeed(0.0)
{
updateStaticContentTexture(size);
}
@@ -74,6 +76,10 @@ namespace dchat
mousePos.x = event.mouseMove.x;
mousePos.y = event.mouseMove.y;
}
+ else if(event.type == sf::Event::MouseWheelScrolled && event.mouseWheelScroll.wheel == sf::Mouse::Wheel::VerticalWheel)
+ {
+ scrollSpeed += (event.mouseWheelScroll.delta * 30.0);
+ }
if(selectingText && !leftMouseButtonPressed)
{
@@ -93,41 +99,53 @@ namespace dchat
sf::Vector2u backgroundSize(floor(windowSize.x * 0.7f), floor(windowSize.y));
sf::Vector2f backgroundPos(floor(windowSize.x * 0.5f - backgroundSize.x * 0.5f), 0.0f);
- if(backgroundSize != staticContentTexture.getSize())
- updateStaticContentTexture(backgroundSize);
+ //if(backgroundSize != staticContentTexture.getSize())
+ // updateStaticContentTexture(backgroundSize);
// TODO: Remove this when dchat::Text can render to static and dynamic render target
dirty = true;
- if(dirty)
- staticContentTexture.clear(BACKGROUND_COLOR);
+ //if(dirty)
+ // staticContentTexture.clear(BACKGROUND_COLOR);
const sf::Font &usernameFont = ResourceCache::getFont("fonts/Roboto-Regular.ttf");
+ double deltaTimeMicro = (double)frameTimer.getElapsedTime().asMicroseconds();
+ frameTimer.restart();
+
+ scroll += scrollSpeed;
+ scrollSpeed /= (deltaTimeMicro * 0.0001);
+
if(dirty)
{
- sf::Vector2f position;
+ sf::Vector2f position = backgroundPos;
+ position.y += scroll;
for(Message *message : messages)
{
- sf::Text usernameText(message->user->getName(), usernameFont, 20 * Settings::getScaling());
- usernameText.setFillColor(sf::Color(15, 192, 252));
- usernameText.setPosition(position);
- staticContentTexture.draw(usernameText);
- position.y += usernameText.getFont()->getLineSpacing(usernameText.getCharacterSize()) + USERNAME_PADDING_BOTTOM;
+ sf::Text usernameText(message->user->getName(), usernameFont, 24 * 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)));
+ window.draw(usernameText);
+ }
+ position.y += usernameTextHeight + USERNAME_PADDING_BOTTOM;
+ // No need to perform culling here, that is done in @Text draw function
message->text.setMaxWidth(backgroundSize.x);
- message->text.setPosition(position);
- message->text.draw(staticContentTexture, cache);
+ message->text.setPosition(sf::Vector2f(floor(position.x), floor(position.y)));
+ message->text.draw(window, cache);
position.y += message->text.getHeight() + MESSAGE_PADDING_BOTTOM;
}
}
- staticContentTexture.display();
+ //staticContentTexture.display();
dirty = false;
// TODO: Save this, expensive to create on fly?
- sf::Sprite textureSprite(staticContentTexture.getTexture());
- textureSprite.setPosition(backgroundPos);
- window.draw(textureSprite);
+ //sf::Sprite textureSprite(staticContentTexture.getTexture());
+ //textureSprite.setPosition(backgroundPos);
+ //window.draw(textureSprite);
if(!selectingText) return;