1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
#include "../include/ChannelTopPanel.hpp"
#include "../include/Settings.hpp"
#include "../include/ResourceCache.hpp"
#include "../include/Channel.hpp"
#include "../include/ColorScheme.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;
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 lineSideColor = ColorScheme::getBackgroundColor();
const sf::Color lineCenterColor = lineSideColor + sf::Color(40, 0, 0);
auto windowSize = window.getSize();
sf::RectangleShape rect(sf::Vector2f(windowSize.x, getHeight() - BOTTOM_LINE_HEIGHT));
rect.setFillColor(ColorScheme::getBackgroundColor());
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, *ResourceCache::getFont("fonts/Roboto-Regular.ttf"), fontSize);
auto textBounds = text.getLocalBounds();
text.setPosition(floor((float)windowSize.x * 0.5f - textBounds.width * 0.5f), PADDING_TOP);
text.setFillColor(ColorScheme::getTextRegularColor());
window.draw(text);
}
float ChannelTopPanel::getHeight()
{
float fontSize = FONT_SIZE * Settings::getScaling();
return floor(ResourceCache::getFont("fonts/Roboto-Regular.ttf")->getLineSpacing(fontSize) + PADDING_TOP + PADDING_BOTTOM + BOTTOM_LINE_HEIGHT);
}
}
|