-
Notifications
You must be signed in to change notification settings - Fork 22
/
TitleBar.cpp
90 lines (74 loc) · 2.85 KB
/
TitleBar.cpp
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "ClickableArea.h"
#include "TitleBar.h"
#include "euroscope/EuroscopeRadarLoopbackInterface.h"
#include "graphics/GdiGraphicsInterface.h"
namespace UKControllerPlugin::Components {
std::shared_ptr<TitleBar> TitleBar::Create(std::wstring title, Gdiplus::Rect area)
{
return std::shared_ptr<TitleBar>(new TitleBar(title, area));
}
std::shared_ptr<TitleBar> TitleBar::WithBackgroundBrush(std::shared_ptr<Gdiplus::Brush> brush)
{
this->backgroundBrush = brush;
return shared_from_this();
}
std::shared_ptr<TitleBar> TitleBar::WithTextBrush(std::shared_ptr<Gdiplus::Brush> brush)
{
this->textBrush = brush;
return shared_from_this();
}
std::shared_ptr<TitleBar> TitleBar::WithBorder(std::shared_ptr<Gdiplus::Pen> pen)
{
this->borderPen = pen;
return shared_from_this();
}
std::shared_ptr<TitleBar> TitleBar::WithDrag(int screenObjectId)
{
this->clickableArea = ClickableArea::Create(this->area, screenObjectId, "titleBar", true);
return shared_from_this();
}
std::shared_ptr<TitleBar> TitleBar::WithPosition(Gdiplus::Rect area)
{
this->area = std::move(area);
if (this->clickableArea != nullptr) {
this->clickableArea->WithPosition(this->area);
}
return shared_from_this();
}
std::shared_ptr<TitleBar> TitleBar::WithTitle(std::wstring title)
{
this->title = title;
return shared_from_this();
}
void TitleBar::Draw(
Windows::GdiGraphicsInterface& graphics, Euroscope::EuroscopeRadarLoopbackInterface& radarScreen) const
{
if (this->backgroundBrush) {
graphics.FillRect(this->area, *this->backgroundBrush);
}
if (this->textBrush) {
graphics.DrawString(this->title, this->area, *this->textBrush);
}
if (this->borderPen) {
graphics.DrawRect(this->area, *this->borderPen);
}
if (this->clickableArea != nullptr) {
this->clickableArea->Apply(graphics, radarScreen);
}
}
TitleBar::TitleBar(std::wstring title, Gdiplus::Rect area) : title(std::move(title)), area(area)
{
}
std::shared_ptr<TitleBar> TitleBar::WithDefaultBackgroundBrush()
{
return this->WithBackgroundBrush(std::make_shared<Gdiplus::SolidBrush>(Gdiplus::Color(130, 50, 154)));
}
std::shared_ptr<TitleBar> TitleBar::WithDefaultTextBrush()
{
return this->WithTextBrush(std::make_shared<Gdiplus::SolidBrush>(Gdiplus::Color(227, 227, 227)));
}
std::shared_ptr<TitleBar> TitleBar::WithDefaultBorder()
{
return this->WithBorder(std::make_shared<Gdiplus::Pen>(Gdiplus::Color(255, 255, 255)));
}
} // namespace UKControllerPlugin::Components