HOG2
Graphics.cpp
Go to the documentation of this file.
1 //
2 // Graphics.cpp
3 // hog2
4 //
5 // Created by Nathan Sturtevant on 7/10/16.
6 // Copyright © 2016 NS Software. All rights reserved.
7 //
8 
9 #include "Graphics.h"
10 
11 namespace Graphics {
12 //bool PointInRect(const point3d &p, const rect &r)
13 //{
14 // return p.y >= r.top && p.x >= r.left && p.y <= r.bottom && p.x <= r.right;
15 //}
16 
17 bool PointInRect(const point &p, const rect &r)
18 {
19  return p.y >= r.top && p.x >= r.left && p.y <= r.bottom && p.x <= r.right;
20 }
21 
23 {
24  viewport = 0;
25  numViewports = 1;
27  drawingBackground = false; }
28 
30 {
31  drawCommands.clear();
32  text.clear();
33  lineSegments.clear();
35 }
36 
38 {
39 }
40 
42 {
44  {
45  backgroundDrawCommands.clear();
46  backgroundText.clear();
47  backgroundLineSegments.clear();
48  }
50  drawingBackground = true;
51 }
52 
54 {
55  drawingBackground = false;
56 }
57 
59 {
61 }
62 
63 void Display::SetNumViewports(uint8_t v)
64 {
65  numViewports = v;
66 }
67 
68 void Display::SetViewport(uint8_t v)
69 {
70  viewport = v;
71 }
72 
73 void Display::FrameRect(rect r, rgbColor c, float lineWidth)
74 {
75  drawInfo i = {r, c, lineWidth};
78  else
79  drawCommands.push_back({i, kFrameRectangle, viewport});
80 }
81 
82 void Display::FrameSquare(point p, float radius, rgbColor c, float lineWidth)
83 {
84  drawInfo i = {{p.x-radius, p.y-radius, p.x+radius, p.y+radius}, c, lineWidth};
87  else
88  drawCommands.push_back({i, kFrameRectangle, viewport});
89 
90 }
91 
92 void Display::FillSquare(point p, float radius, rgbColor c)
93 {
94  drawInfo i = {{p.x-radius, p.y-radius, p.x+radius, p.y+radius}, c, 0};
97  else
98  drawCommands.push_back({i, kFillRectangle, viewport});
99 }
100 
102 {
103  drawInfo i = {r, c, 0};
104  if (drawingBackground)
106  else
107  drawCommands.push_back({i, kFillRectangle, viewport});
108 }
109 
110 void Display::FrameCircle(rect r, rgbColor c, float lineWidth)
111 {
112  drawInfo i = {r, c, lineWidth};
113  if (drawingBackground)
114  backgroundDrawCommands.push_back({i, kFrameOval, viewport});
115  else
116  drawCommands.push_back({i, kFrameOval, viewport});
117 }
118 
119 void Display::FrameCircle(point p, float radius, rgbColor c, float lineWidth)
120 {
121  drawInfo i = {{p.x-radius, p.y-radius, p.x+radius, p.y+radius}, c, lineWidth};
122  if (drawingBackground)
123  backgroundDrawCommands.push_back({i, kFrameOval, viewport});
124  else
125  drawCommands.push_back({i, kFrameOval, viewport});
126 }
127 
129 {
130  drawInfo i = {r, c, 0};
131  if (drawingBackground)
132  backgroundDrawCommands.push_back({i, kFillOval, viewport});
133  else
134  drawCommands.push_back({i, kFillOval, viewport});
135 }
136 
137 void Display::FillCircle(point p, float radius, rgbColor c)
138 {
139  drawInfo i = {{p.x-radius, p.y-radius, p.x+radius, p.y+radius}, c, 0};
140  if (drawingBackground)
141  backgroundDrawCommands.push_back({i, kFillOval, viewport});
142  else
143  drawCommands.push_back({i, kFillOval, viewport});
144 }
145 
147 {
148  triangleInfo i = {p1, p2, p3, c, 0};
149  if (drawingBackground)
151  else
152  drawCommands.push_back({i, kFillTriangle, viewport});
153 }
154 
155 void Display::FrameTriangle(point p1, point p2, point p3, float lineWidth, rgbColor c)
156 {
157  triangleInfo i = {p1, p2, p3, c, lineWidth};
158  if (drawingBackground)
160  else
161  drawCommands.push_back({i, kFrameTriangle, viewport});
162 }
163 
164 void Display::FillNGon(point p, float radius, int sides, float rotation, rgbColor c)
165 {
166  shapeInfo i = {p, c, radius, sides, rotation, 0};
167  if (drawingBackground)
168  backgroundDrawCommands.push_back({i, kFillNGon, viewport});
169  else
170  drawCommands.push_back({i, kFillNGon, viewport});
171 }
172 
173 void Display::FrameNGon(point p, float radius, float width, int sides, float rotation, rgbColor c)
174 {
175  shapeInfo i = {p, c, radius, sides, rotation, width};
176 
177  if (drawingBackground)
178  backgroundDrawCommands.push_back({i, kFrameNGon, viewport});
179  else
180  drawCommands.push_back({i, kFrameNGon, viewport});
181 }
182 
183 
184 void Display::DrawLine(point start, point end, float lineWidth, rgbColor c)
185 {
186  lineInfo i = {start, end, c, lineWidth, false};
187  if (drawingBackground)
188  backgroundDrawCommands.push_back({i, viewport});
189  else
190  drawCommands.push_back({i, viewport});
191 }
192 
193 void Display::DrawArrow(point start, point end, float lineWidth, rgbColor c)
194 {
195  lineInfo i = {start, end, c, lineWidth, true};
196  if (drawingBackground)
197  backgroundDrawCommands.push_back({i, viewport});
198  else
199  drawCommands.push_back({i, viewport});
200 }
201 
202 void Display::DrawText(const char *textString, point location, rgbColor c, float height,
203  textAlign align, textBaseline base, const char *typeface)
204 {
205  textInfo i = {std::string(textString), location, c, height, std::string((typeface==0)?"Helvetica":typeface), align, base, viewport};
206  if (drawingBackground)
207  backgroundText.push_back(i);
208  else
209  text.push_back(i);
210 }
211 
212 void Display::DrawText(const char *textString, point location, rgbColor c, float height, textAlign align, const char *typeface)
213 {
214  textInfo i = {std::string(textString), location, c, height, std::string((typeface==0)?"Helvetica":typeface), align, textBaselineBottom, viewport};
215  if (drawingBackground)
216  backgroundText.push_back(i);
217  else
218  text.push_back(i);
219 }
220 
221 void Display::DrawText(const char *textString, point location, rgbColor c, float height, const char *typeface)
222 {
223  textInfo i = {std::string(textString), location, c, height, std::string((typeface==0)?"Helvetica":typeface), textAlignLeft, textBaselineBottom, viewport};
224  if (drawingBackground)
225  backgroundText.push_back(i);
226  else
227  text.push_back(i);
228 }
229 
230 void Display::DrawLineSegments(const std::vector<point> &points, float lineWidth, rgbColor c)
231 {
232  segments s = {c, lineWidth, points, false, viewport};
233  if (drawingBackground)
234  backgroundLineSegments.push_back(s);
235  else
236  lineSegments.push_back(s);
237 }
238 
239 void Display::FillLineSegments(const std::vector<point> &points, float lineWidth, rgbColor c)
240 {
241  segments s = {c, lineWidth, points, true, viewport};
242  if (drawingBackground)
243  backgroundLineSegments.push_back(s);
244  else
245  lineSegments.push_back(s);
246 }
247 
248 }
Graphics::Display::DrawLine
void DrawLine(point start, point end, float lineWidth, rgbColor c)
Definition: Graphics.cpp:184
Graphics::point
Definition: Graphics.h:32
Graphics::point::y
float y
Definition: Graphics.h:36
rgbColor
A color; r/g/b are between 0...1.
Definition: Colors.h:17
Graphics::Display::backgroundText
std::vector< textInfo > backgroundText
Definition: Graphics.h:273
Graphics::Display::FillSquare
void FillSquare(point p, float radius, rgbColor c)
Definition: Graphics.cpp:92
Graphics::Display::backgroundFrame
uint64_t backgroundFrame
Definition: Graphics.h:275
Graphics::Display::SetNumViewports
void SetNumViewports(uint8_t v)
Definition: Graphics.cpp:63
Graphics::Display::EndFrame
void EndFrame()
Definition: Graphics.cpp:37
Graphics::Display::FillTriangle
void FillTriangle(point p1, point p2, point p3, rgbColor c)
Definition: Graphics.cpp:146
Graphics::textBaseline
textBaseline
Definition: Graphics.h:25
Graphics::Display::FillLineSegments
void FillLineSegments(const std::vector< point > &points, float lineWidth, rgbColor c)
Definition: Graphics.cpp:239
Graphics::Display::kFrameRectangle
@ kFrameRectangle
Definition: Graphics.h:217
Graphics::Display::backgroundDrawCommands
std::vector< data > backgroundDrawCommands
Definition: Graphics.h:272
Graphics::rect
Definition: Graphics.h:94
Graphics::Display::shapeInfo
Definition: Graphics.h:190
Graphics::Display::triangleInfo
Definition: Graphics.h:185
Graphics::Display::segments
Definition: Graphics.h:260
Graphics::Display::kFillRectangle
@ kFillRectangle
Definition: Graphics.h:216
Graphics::Display::textInfo
Definition: Graphics.h:204
width
int width
Definition: SFML_HOG.cpp:54
rotation
float rotation[3][3]
Definition: RC.cpp:21
Graphics::Display::StartBackground
void StartBackground()
Definition: Graphics.cpp:41
Graphics::Display::EndBackground
void EndBackground()
Definition: Graphics.cpp:53
Graphics::Display::Display
Display()
Definition: Graphics.cpp:22
Graphics::Display::SetViewport
void SetViewport(uint8_t v)
Definition: Graphics.cpp:68
Graphics::Display::FillNGon
void FillNGon(point p, float radius, int sides, float rotation, rgbColor c)
Definition: Graphics.cpp:164
Graphics::Display::StartFrame
void StartFrame()
Definition: Graphics.cpp:29
Graphics::Display::kFillTriangle
@ kFillTriangle
Definition: Graphics.h:218
Graphics::Display::numViewports
uint8_t numViewports
Definition: Graphics.h:279
Graphics::Display::kFrameOval
@ kFrameOval
Definition: Graphics.h:221
Graphics::Display::drawInfo
Definition: Graphics.h:180
viewport
Definition: Common.h:56
Graphics::Display::FrameNGon
void FrameNGon(point p, float radius, float width, int sides, float rotation, rgbColor c)
Definition: Graphics.cpp:173
Graphics::PointInRect
bool PointInRect(const point &p, const rect &r)
Definition: Graphics.cpp:17
Graphics::Display::kFrameNGon
@ kFrameNGon
Definition: Graphics.h:223
Graphics::Display::BackgroundNeedsRedraw
bool BackgroundNeedsRedraw() const
Definition: Graphics.cpp:58
Graphics::rect::top
float top
Definition: Graphics.h:100
Graphics::Display::drawingBackground
bool drawingBackground
Definition: Graphics.h:280
Graphics::Display::drawCommands
std::vector< data > drawCommands
Definition: Graphics.h:268
Graphics::Display::kFillOval
@ kFillOval
Definition: Graphics.h:220
Graphics::Display::lineInfo
Definition: Graphics.h:198
Graphics::Display::FrameSquare
void FrameSquare(point p, float radius, rgbColor c, float lineWidth)
Definition: Graphics.cpp:82
Graphics
Definition: Graphics.cpp:11
Graphics::rect::right
float right
Definition: Graphics.h:100
Graphics::Display::kFillNGon
@ kFillNGon
Definition: Graphics.h:222
height
int height
Definition: SFML_HOG.cpp:54
Graphics::Display::foregroundFrame
uint64_t foregroundFrame
Definition: Graphics.h:276
Graphics::Display::FrameCircle
void FrameCircle(rect r, rgbColor c, float lineWidth)
Definition: Graphics.cpp:110
Graphics.h
Graphics::Display::text
std::vector< textInfo > text
Definition: Graphics.h:269
Graphics::Display::DrawArrow
void DrawArrow(point start, point end, float lineWidth, rgbColor c)
Definition: Graphics.cpp:193
Graphics::point::x
float x
Definition: Graphics.h:36
Graphics::Display::FillCircle
void FillCircle(rect r, rgbColor c)
Definition: Graphics.cpp:128
Graphics::Display::FrameRect
void FrameRect(rect r, rgbColor c, float lineWidth)
Definition: Graphics.cpp:73
Graphics::textAlign
textAlign
Definition: Graphics.h:19
Graphics::Display::FrameTriangle
void FrameTriangle(point p1, point p2, point p3, float lineWidth, rgbColor c)
Definition: Graphics.cpp:155
Graphics::Display::lineSegments
std::vector< segments > lineSegments
Definition: Graphics.h:270
Graphics::textAlignLeft
@ textAlignLeft
Definition: Graphics.h:21
Graphics::rect::left
float left
Definition: Graphics.h:100
Graphics::Display::DrawLineSegments
void DrawLineSegments(const std::vector< point > &points, float lineWidth, rgbColor c)
Definition: Graphics.cpp:230
Graphics::textBaselineBottom
@ textBaselineBottom
Definition: Graphics.h:28
Graphics::Display::kFrameTriangle
@ kFrameTriangle
Definition: Graphics.h:219
Graphics::Display::DrawText
void DrawText(const char *text, point location, rgbColor c, float height, const char *typeface=0)
Definition: Graphics.cpp:221
Graphics::rect::bottom
float bottom
Definition: Graphics.h:100
Graphics::Display::FillRect
void FillRect(rect r, rgbColor c)
Definition: Graphics.cpp:101
Graphics::Display::backgroundLineSegments
std::vector< segments > backgroundLineSegments
Definition: Graphics.h:274