aboutsummaryrefslogtreecommitdiff
path: root/src/UsersSidePanel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/UsersSidePanel.cpp')
-rw-r--r--src/UsersSidePanel.cpp92
1 files changed, 53 insertions, 39 deletions
diff --git a/src/UsersSidePanel.cpp b/src/UsersSidePanel.cpp
index 7d7970f..39321d5 100644
--- a/src/UsersSidePanel.cpp
+++ b/src/UsersSidePanel.cpp
@@ -1,15 +1,17 @@
#include "../include/UsersSidePanel.hpp"
-#include "../include/ChannelTopPanel.hpp"
-#include "../include/ChannelSidePanel.hpp"
+#include "../include/RoomTopPanel.hpp"
+#include "../include/RoomSidePanel.hpp"
#include "../include/ResourceCache.hpp"
+#include "../include/StaticImage.hpp"
+#include "../include/Gif.hpp"
#include "../include/Settings.hpp"
-#include "../include/Channel.hpp"
#include "../include/ColorScheme.hpp"
-#include "../include/Gif.hpp"
+#include "../include/Room.hpp"
#include <SFML/Graphics/RectangleShape.hpp>
#include <SFML/Graphics/CircleShape.hpp>
#include <SFML/Graphics/Sprite.hpp>
#include <SFML/Graphics/Text.hpp>
+#include <dchat/Room.hpp>
#include <vector>
#include <cmath>
#include <sibs/Functional.hpp>
@@ -26,21 +28,22 @@ namespace dchat
const float PADDING_BOTTOM = 20.0f;
const i64 USER_TIMEOUT_SEC = 25;
- static void renderUser(Cache &cache, const User *user, sf::Shader *circleShader, sf::RenderWindow &window, sf::Vector2f &position, const sf::Font *font, const float textHeight, bool isUserOnline)
+ static void renderUser(Cache *cache, const User *user, sf::Shader *circleShader, sf::RenderWindow &window, sf::Vector2f &position, const sf::Font *font, const float textHeight, bool isUserOnline)
{
if(position.y + AVATAR_DIAMETER > 0.0f && position.y < window.getSize().y)
{
// Max avatar size = 1mb
- const ContentByUrlResult avatarResult = cache.getContentByUrl(user->avatarUrl, 1024 * 1024);
+ const ContentByUrlResult avatarResult = cache->getContentByUrl(user->avatarUrl, 1024 * 1024);
if(avatarResult.type == ContentByUrlResult::Type::CACHED)
{
circleShader->setUniform("texture", sf::Shader::CurrentTexture);
- if(avatarResult.cachedType == ContentByUrlResult::CachedType::TEXTURE)
+ if(avatarResult.cachedType == ContentByUrlResult::CachedType::STATIC_IMAGE)
{
+ auto *staticImage = static_cast<SfmlStaticImage*>(avatarResult.staticImage);
// TODO: Store this sprite somewhere, might not be efficient to create a new sprite object every frame
- sf::Sprite sprite(*avatarResult.texture);
- auto textureSize = avatarResult.texture->getSize();
+ sf::Sprite sprite(staticImage->texture);
+ auto textureSize = staticImage->texture.getSize();
sprite.setPosition(sf::Vector2f(floor(position.x), floor(position.y)));
sprite.setScale(sf::Vector2f(AVATAR_DIAMETER * Settings::getScaling() / (float)textureSize.x, AVATAR_DIAMETER * Settings::getScaling() / (float)textureSize.y));
sprite.setColor(isUserOnline ? sf::Color::White : sf::Color(255, 255, 255, 100));
@@ -48,11 +51,15 @@ namespace dchat
}
else if(avatarResult.cachedType == ContentByUrlResult::CachedType::GIF)
{
- auto gifSize = avatarResult.gif->getSize();
- avatarResult.gif->setPosition(sf::Vector2f(floor(position.x), floor(position.y)));
- avatarResult.gif->setScale(sf::Vector2f(AVATAR_DIAMETER * Settings::getScaling() / (float)gifSize.x, AVATAR_DIAMETER * Settings::getScaling() / (float)gifSize.y));
- avatarResult.gif->setColor(isUserOnline ? sf::Color::White : sf::Color(255, 255, 255, 100));
- avatarResult.gif->draw(window, circleShader);
+ auto *gif = static_cast<SfmlGif*>(avatarResult.gif);
+ gif->update();
+ auto gifSize = gif->getSize();
+
+ sf::Sprite sprite(gif->texture);
+ sprite.setPosition(sf::Vector2f(floor(position.x), floor(position.y)));
+ sprite.setScale(sf::Vector2f(AVATAR_DIAMETER * Settings::getScaling() / (float)gifSize.x, AVATAR_DIAMETER * Settings::getScaling() / (float)gifSize.y));
+ sprite.setColor(isUserOnline ? sf::Color::White : sf::Color(255, 255, 255, 100));
+ window.draw(sprite, circleShader);
}
}
else
@@ -64,7 +71,7 @@ namespace dchat
}
// TODO: Remove this shit
- sf::String str = sf::String::fromUtf8(user->getName().begin(), user->getName().end());
+ sf::String str = sf::String::fromUtf8(user->nickname.begin(), user->nickname.end());
sf::Text text(str, *font, FONT_SIZE * Settings::getScaling());
text.setPosition(floor(position.x + (AVATAR_DIAMETER + AVATAR_PADDING_SIDE) * Settings::getScaling()), floor(position.y + AVATAR_DIAMETER * 0.5f - textHeight * 0.5f));
text.setFillColor(isUserOnline ? sf::Color(15, 192, 252) : sf::Color(15, 192, 252, 100));
@@ -73,36 +80,38 @@ namespace dchat
position.y += ((AVATAR_DIAMETER + PADDING_BOTTOM) * Settings::getScaling());
}
- void UsersSidePanel::draw(sf::RenderWindow &window, Cache &cache)
+ void UsersSidePanel::draw(sf::RenderWindow &window, Cache *cache)
{
auto windowSize = window.getSize();
- float posY = std::min((windowSize.y - ChannelTopPanel::getHeight()) * 0.5f, ChannelSidePanel::getHeight());
+ float posY = std::min((windowSize.y - RoomTopPanel::getHeight()) * 0.5f, RoomSidePanel::getHeight());
- Channel *currentChannel = Channel::getCurrent();
- if(!currentChannel) return;
+ std::shared_ptr<Room> currentRoom = getCurrentRoom();
+ if(!currentRoom) return;
const sf::Font *font = ResourceCache::getFont("fonts/Nunito-Regular.ttf");
sf::Vector2f position(10.0f, posY);
const float textHeight = font->getLineSpacing(FONT_SIZE * Settings::getScaling());
- i64 timestampSec = currentChannel->getSyncedTimestampUtcInSec();
- auto &channelUsers = currentChannel->getUsers();
- auto currentChannelUsers = sibs::makeFunction(channelUsers.data(), channelUsers.data() + channelUsers.size());
- for(BridgeService *bridgeService : currentChannel->getBridgeServices())
- {
- auto &bridgeServiceUsers = bridgeService->getUsers();
- currentChannelUsers.merge(sibs::makeFunction(bridgeServiceUsers.data(), bridgeServiceUsers.data() + bridgeServiceUsers.size()));
- }
+ //i64 timestampSec = currentRoom->getSyncedTimestampUtcInSec();
+ auto &channelUsers = currentRoom->getUsers();
+ // auto currentChannelUsers = sibs::makeFunction(channelUsers.data(), channelUsers.data() + channelUsers.size());
+ // for(BridgeService *bridgeService : currentRoom->getBridgeServices())
+ // {
+ // auto &bridgeServiceUsers = bridgeService->getUsers();
+ // currentChannelUsers.merge(sibs::makeFunction(bridgeServiceUsers.data(), bridgeServiceUsers.data() + bridgeServiceUsers.size()));
+ // }
u32 numOnlineUsers = 0;
u32 numOfflineUsers = 0;
- for(const User *user : currentChannelUsers)
+ for(auto &it : channelUsers)
{
- if(user->isConnected(timestampSec))
- ++numOnlineUsers;
- else
- ++numOfflineUsers;
+ const User *user = it.second.get();
+ // TODO: Fix this
+ //if(user->isConnected(timestampSec))
+ // ++numOnlineUsers;
+ //else
+ // ++numOfflineUsers;
}
// TODO: Remove this shit
@@ -117,9 +126,11 @@ namespace dchat
sf::Shader *circleShader = ResourceCache::getShader("shaders/circleMask.glsl", sf::Shader::Fragment);
- for(const User *user : currentChannelUsers)
+ for(auto &it : channelUsers)
{
- if(user->isConnected(timestampSec))
+ const User *user = it.second.get();
+ // TODO: Fix this
+ //if(user->isConnected(timestampSec))
renderUser(cache, user, circleShader, window, position, font, textHeight, true);
}
@@ -136,11 +147,14 @@ namespace dchat
position.y += floor(font->getLineSpacing(text.getCharacterSize()));
position.y += PADDING_BOTTOM * Settings::getScaling() * 0.5f;
- for(const User *user : currentChannelUsers)
- {
- if(!user->isConnected(timestampSec))
- renderUser(cache, user, circleShader, window, position, font, textHeight, false);
- }
+ // TODO: Fix this
+ //for(const User *user : channelUsers)
+ //{
+ // const User *user = it.second.get();
+ // TODO: Fix this
+ //if(!user->isConnected(timestampSec))
+ // renderUser(cache, user, circleShader, window, position, font, textHeight, false);
+ // }
}
float UsersSidePanel::getWidth()