aboutsummaryrefslogtreecommitdiff
path: root/src/ChannelTopPanel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ChannelTopPanel.cpp')
-rw-r--r--src/ChannelTopPanel.cpp97
1 files changed, 97 insertions, 0 deletions
diff --git a/src/ChannelTopPanel.cpp b/src/ChannelTopPanel.cpp
new file mode 100644
index 0000000..534f989
--- /dev/null
+++ b/src/ChannelTopPanel.cpp
@@ -0,0 +1,97 @@
+#include "../include/ChannelTopPanel.hpp"
+#include "../include/Settings.hpp"
+#include "../include/ResourceCache.hpp"
+#include "../include/Channel.hpp"
+#include <SFML/Graphics/RectangleShape.hpp>
+#include <cmath>
+
+namespace dchat
+{
+ struct LineColor
+ {
+ sf::Color sideColor, centerColor;
+ };
+
+ const float FONT_SIZE = 40.0f;
+ const float BOTTOM_LINE_HEIGHT = 2.0f;
+ const float PADDING_TOP = 20.0f;
+ const float PADDING_BOTTOM = PADDING_TOP;
+ const sf::Font *FONT = ResourceCache::getFont("fonts/Roboto-Regular.ttf");
+
+ static void drawGradientLine(const sf::Vector2f &position, const sf::Vector2f &size, const LineColor &color, sf::RenderWindow &window)
+ {
+ sf::Vertex rectangle[] =
+ {
+ sf::Vertex(position, color.sideColor),
+ sf::Vertex(sf::Vector2f(position.x + size.x * 0.5f, position.y), color.centerColor),
+ sf::Vertex(sf::Vector2f(position.x + size.x * 0.5f, position.y + size.y), color.centerColor),
+ sf::Vertex(sf::Vector2f(position.x, position.y + size.y), color.sideColor),
+
+ sf::Vertex(sf::Vector2f(position.x + size.x * 0.5f, position.y), color.centerColor),
+ sf::Vertex(sf::Vector2f(position.x + size.x, position.y), color.sideColor),
+ sf::Vertex(sf::Vector2f(position.x + size.x, position.y + size.y), color.sideColor),
+ sf::Vertex(sf::Vector2f(position.x + size.x * 0.5f, position.y + size.y), color.centerColor)
+ };
+ window.draw(rectangle, 8, sf::Quads);
+ }
+
+ void ChannelTopPanel::draw(sf::RenderWindow &window)
+ {
+ const sf::Color backgroundColor(40, 40, 40);
+ const sf::Color lineSideColor(40, 40, 40);
+ const sf::Color lineCenterColor(80, 40, 40);
+
+ auto windowSize = window.getSize();
+ sf::RectangleShape rect(sf::Vector2f(windowSize.x, getHeight() - BOTTOM_LINE_HEIGHT));
+ rect.setFillColor(backgroundColor);
+ window.draw(rect);
+
+ /*
+ rect.setFillColor(sf::Color(70, 40, 40));
+ rect.setSize(sf::Vector2f(windowSize.x, BOTTOM_LINE_HEIGHT));
+ rect.setPosition(0.0f, getHeight() - BOTTOM_LINE_HEIGHT);
+ window.draw(rect);
+ */
+ sf::Vector2f bottomLinePos(0.0f, getHeight() - BOTTOM_LINE_HEIGHT);
+ sf::Vector2f bottomLineSize(windowSize.x, BOTTOM_LINE_HEIGHT);
+
+ LineColor lineColor
+ {
+ .sideColor = lineSideColor,
+ .centerColor = lineCenterColor
+ };
+ drawGradientLine(bottomLinePos, bottomLineSize, lineColor, window);
+
+ Channel *currentChannel = Channel::getCurrent();
+ if(!currentChannel) return;
+
+ sf::String str = "# ";
+ str += sf::String::fromUtf8(currentChannel->getName().begin(), currentChannel->getName().end());
+ float fontSize = FONT_SIZE * Settings::getScaling();
+ sf::Text text(str, *FONT, fontSize);
+ auto textBounds = text.getLocalBounds();
+ text.setPosition(floor((float)windowSize.x * 0.5f - textBounds.width * 0.5f), PADDING_TOP);
+ text.setFillColor(sf::Color(240, 240, 240));
+ window.draw(text);
+ /*
+ const sf::Font *font = ResourceCache::getFont("fonts/Roboto-Regular.ttf");
+ sf::Vector2f position(10.0f, 10.0f);
+ for(Channel *channel : channels)
+ {
+ // TODO: Remove this shit
+ sf::String str = "# ";
+ str += sf::String::fromUtf8(channel->getName().begin(), channel->getName().end());
+ sf::Text text(str, *font, FONT_SIZE * Settings::getScaling());
+ text.setPosition(position);
+ window.draw(text);
+ position.y += font->getLineSpacing(FONT_SIZE * Settings::getScaling());
+ }
+ */
+ }
+
+ float ChannelTopPanel::getHeight()
+ {
+ float fontSize = FONT_SIZE * Settings::getScaling();
+ return floor(FONT->getLineSpacing(fontSize) + PADDING_TOP + PADDING_BOTTOM);
+ }
+}