-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerScreen.cpp
More file actions
130 lines (108 loc) · 3.8 KB
/
ServerScreen.cpp
File metadata and controls
130 lines (108 loc) · 3.8 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include "ServerScreen.h"
#include <rapidjson/document.h>
std::pair<Dasher::screenint, Dasher::screenint> ServerScreen::TextSize(Label* Label, unsigned iFontSize)
{
return FontMeasureService->Measure(Label->m_strText, iFontSize);
}
ServerScreen::~ServerScreen()
{
GeometryToDraw.clear();
}
void ServerScreen::DrawString(Label* label, Dasher::screenint x, Dasher::screenint y, unsigned iFontSize, int iColour)
{
GeometryToDraw.push_back(std::make_unique<StringToDraw>(label,x,y,iFontSize,iColour));
}
void ServerScreen::DrawRectangle(Dasher::screenint x1, Dasher::screenint y1, Dasher::screenint x2, Dasher::screenint y2, int Colour, int iOutlineColour, int iThickness)
{
GeometryToDraw.push_back(std::make_unique<RectangleToDraw>(x1,y1,x2,y2,Colour,iOutlineColour,iThickness));
}
void ServerScreen::DrawCircle(Dasher::screenint iCX, Dasher::screenint iCY, Dasher::screenint iR, int iFillColour, int iLineColour, int iLineWidth)
{
GeometryToDraw.push_back(std::make_unique<CircleToDraw>(iCX, iCY, iR, iFillColour, iLineColour, iLineWidth));
}
void ServerScreen::Polyline(point* Points, int Number, int iWidth, int Colour)
{
std::vector<point> pointsVector;
pointsVector.insert(pointsVector.end(), Points, Points + Number);
GeometryToDraw.push_back(std::make_unique<PolylineToDraw>(pointsVector, iWidth, Colour));
}
void ServerScreen::Polygon(point* Points, int Number, int fillColour, int outlineColour, int lineWidth)
{
std::vector<point> pointsVector;
pointsVector.insert(pointsVector.end(), Points, Points + Number);
GeometryToDraw.push_back(std::make_unique<PolygonToDraw>(pointsVector, fillColour, outlineColour, lineWidth));
}
void ServerScreen::Display()
{
/* Serializes into this format:
* {
* "T" : "F",
* "D" : [{<Geometry_0>},...,],
* }
*/
rapidjson::StringBuffer Buffer;
rapidjson::Writer<rapidjson::StringBuffer> Writer(Buffer);
Writer.StartObject();
Writer.Key("T");
Writer.String("F");
Writer.Key("G");
Writer.StartArray();
for(std::unique_ptr<DasherDrawGeometry>& G : GeometryToDraw )
{
G->Serialize(Writer);
}
Writer.EndArray();
Writer.EndObject();
//Send "Frame" to Client
if(ServerInstance->get_con_from_hdl(Connection)->get_state() == websocketpp::session::state::open)
{
ServerInstance->send(Connection, Buffer.GetString(), Buffer.GetSize(), websocketpp::frame::opcode::TEXT);
}
//Empty buffers
GeometryToDraw.clear();
}
void ServerScreen::SetColourScheme(const Dasher::CColourIO::ColourInfo* pColourScheme)
{
this->pColorScheme = pColourScheme;
if (!pColorScheme) return;
/* Serializes into this format:
* {
* "T" : "C",
* "I" : "<ColourID>",
* "C" : [[red_0,green_0,blue_0],...,],
* }
*/
rapidjson::StringBuffer Buffer;
rapidjson::Writer<rapidjson::StringBuffer> Writer(Buffer);
Writer.StartObject();
Writer.Key("T");
Writer.String("C");
Writer.Key("I");
Writer.String(pColorScheme->ColourID.c_str(), static_cast<rapidjson::SizeType>(pColorScheme->ColourID.length()));
Writer.Key("C");
Writer.StartArray();
for (int i = 0; i < pColorScheme->Colors.size(); i++)
{
Writer.StartArray();
Writer.Int(pColorScheme->Colors[i].Red);
Writer.Int(pColorScheme->Colors[i].Green);
Writer.Int(pColorScheme->Colors[i].Blue);
Writer.EndArray();
}
Writer.EndArray();
Writer.EndObject();
if(ServerInstance->get_con_from_hdl(Connection)->get_state() == websocketpp::session::state::open){
ServerInstance->send(Connection, Buffer.GetString(), Buffer.GetSize(), websocketpp::frame::opcode::TEXT);
}
}
bool ServerScreen::IsPointVisible(Dasher::screenint, Dasher::screenint){
return true;
}
void ServerScreen::SendCurrentColorScheme()
{
SetColourScheme(pColorScheme); //Set to current one and thus force to resend it
}
void ServerScreen::Resize(unsigned Width, unsigned Height)
{
resize(static_cast<int>(Width), static_cast<int>(Height));
}