Tscope5
primitives.c
Go to the documentation of this file.
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 #include "../include/tscope5/primitives.h"
12 #include "../include/tscope5/graphics.h"
13 #include "../include/tscope5/primitives_internal.h"
14 #include "../include/tscope5/system_internal.h"
15 #include "../include/tscope5/graphics_internal.h"
16 
17 #include <allegro5/allegro_primitives.h>
18 
19 
24 
25 
26 
27 
34 void ts5_draw_pixel(double x, double y)
35 {
36  ts5_check_primitives("ts5_draw_pixel");
37  ts5_log(TS5_LOGLEVEL_5, "ts5_draw_pixel(%f,%f)\n", x, y);
38 
39  if (_ts5_status.graphics_status.coordinate_scale == TS5_RELATIVE_COORDINATES) {
42  }
43 
44  if (_ts5_status.graphics_status.coordinate_system == TS5_CARTESIAN_COORDINATES) {
47  }
48 
49  if (_ts5_status.graphics_status.drawing_thickness <= 0.0) {
50  al_draw_pixel(x, y, _ts5_status.graphics_status.foreground_color);
51  }
52  else {
53  al_draw_filled_circle(x, y, _ts5_status.graphics_status.drawing_thickness,
54  _ts5_status.graphics_status.foreground_color);
55  }
56 }
57 
58 
68 TS5_COLOR ts5_get_pixel_color(double x, double y)
69 {
70  ts5_check_primitives("ts5_get_pixel_color");
71  ts5_log(TS5_LOGLEVEL_5, "ts5_get_pixel_color(%f,%f)\n", x, y);
72 
73  if (_ts5_status.graphics_status.coordinate_scale == TS5_RELATIVE_COORDINATES) {
76  }
77 
78  if (_ts5_status.graphics_status.coordinate_system == TS5_CARTESIAN_COORDINATES) {
81  }
82 
83  return (al_get_pixel(_ts5_status.target, x, y));
84 }
85 
86 
95 void ts5_draw_line(double x1, double y1, double x2, double y2)
96 {
97  ts5_check_primitives("ts5_draw_line");
98  ts5_log(TS5_LOGLEVEL_5, "ts5_draw_line(%f,%f,%f,%f)\n", x1, y1, x2, y2);
99 
100  if (_ts5_status.graphics_status.coordinate_scale == TS5_RELATIVE_COORDINATES) {
105  }
106 
107  if (_ts5_status.graphics_status.coordinate_system == TS5_CARTESIAN_COORDINATES) {
112  }
113 
114  al_draw_line(x1, y1, x2, y2, _ts5_status.graphics_status.foreground_color,
115  _ts5_status.graphics_status.drawing_thickness);
116 }
117 
118 
127 void ts5_draw_rectangle(double x1, double y1, double x2, double y2)
128 {
129  ts5_check_primitives("ts5_draw_rectangle");
130  ts5_log(TS5_LOGLEVEL_5, "ts5_draw_rectangle(%f,%f,%f,%f)\n", x1, y1, x2, y2);
131 
132  if (_ts5_status.graphics_status.coordinate_scale == TS5_RELATIVE_COORDINATES) {
137  }
138 
139  if (_ts5_status.graphics_status.coordinate_system == TS5_CARTESIAN_COORDINATES) {
144  }
145 
146  if (!_ts5_status.graphics_status.fill_mode) {
147  al_draw_rectangle(x1, y1, x2, y2, _ts5_status.graphics_status.foreground_color,
148  _ts5_status.graphics_status.drawing_thickness);
149  }
150  else {
151  al_draw_filled_rectangle(x1, y1, x2, y2, _ts5_status.graphics_status.foreground_color);
152  }
153 }
154 
155 
166 void ts5_draw_rounded_rectangle(double x1, double y1, double x2, double y2, double rx, double ry)
167 {
168  ts5_check_primitives("ts5_draw_rounded_rectangle");
169  ts5_log(TS5_LOGLEVEL_5, "ts5_draw_rounded_rectangle(%f,%f,%f,%f,%f,%f)\n", x1, y1, x2, y2, rx, ry);
170 
171  if (_ts5_status.graphics_status.coordinate_scale == TS5_RELATIVE_COORDINATES) {
178  }
179 
180  if (_ts5_status.graphics_status.coordinate_system == TS5_CARTESIAN_COORDINATES) {
185  }
186 
187  if (x1 > x2) {
188  double t = x1;
189  x1 = x2;
190  x2 = t;
191  }
192 
193  if (y1 > y2) {
194  double t = y1;
195  y1 = y2;
196  y2 = t;
197  }
198 
199  double w = x2 - x1;
200 
201  if (rx>w/2.0) {
202  rx=w/2.0;
203  }
204 
205  double h = y2 - y1;
206 
207  if (ry>h/2.0) {
208  ry=h/2.0;
209  }
210 
211 
212  if (!_ts5_status.graphics_status.fill_mode) {
213  al_draw_rounded_rectangle(x1, y1, x2, y2, rx, ry,
214  _ts5_status.graphics_status.foreground_color,
215  _ts5_status.graphics_status.drawing_thickness);
216  }
217  else {
218  al_draw_filled_rounded_rectangle(x1, y1, x2, y2, rx, ry,
219  _ts5_status.graphics_status.foreground_color);
220  }
221 }
222 
223 
234 void ts5_draw_triangle(double x1, double y1, double x2, double y2, double x3, double y3)
235 {
236  ts5_check_primitives("ts5_draw_triangle");
237  ts5_log(TS5_LOGLEVEL_5, "ts5_draw_triangle(%f,%f,%f,%f,%f,%f)\n", x1, y1, x2, y2, x3, y3);
238 
239  if (_ts5_status.graphics_status.coordinate_scale == TS5_RELATIVE_COORDINATES) {
246  }
247 
248  if (_ts5_status.graphics_status.coordinate_system == TS5_CARTESIAN_COORDINATES) {
255  }
256 
257  if (!_ts5_status.graphics_status.fill_mode) {
258  al_draw_triangle(x1, y1, x2, y2, x3, y3,
259  _ts5_status.graphics_status.foreground_color,
260  _ts5_status.graphics_status.drawing_thickness);
261  }
262  else {
263  al_draw_filled_triangle(x1, y1, x2, y2, x3, y3, _ts5_status.graphics_status.foreground_color);
264  }
265 }
266 
267 
275 void ts5_draw_circle(double cx, double cy, double r)
276 {
277  ts5_check_primitives("ts5_draw_circle");
278  ts5_log(TS5_LOGLEVEL_5, "ts5_draw_circle(%f,%f,%f)\n", cx, cy, r);
279 
280  if (_ts5_status.graphics_status.coordinate_scale == TS5_RELATIVE_COORDINATES) {
284  }
285 
286  if (_ts5_status.graphics_status.coordinate_system == TS5_CARTESIAN_COORDINATES) {
289  }
290 
291  if (!_ts5_status.graphics_status.fill_mode) {
292  al_draw_circle(cx, cy, r, _ts5_status.graphics_status.foreground_color,
293  _ts5_status.graphics_status.drawing_thickness);
294  }
295  else {
296  al_draw_filled_circle(cx, cy, r, _ts5_status.graphics_status.foreground_color);
297  }
298 }
299 
300 
309 void ts5_draw_ellipse(double cx, double cy, double rx, double ry)
310 {
311  ts5_check_primitives("ts5_draw_ellipse");
312  ts5_log(TS5_LOGLEVEL_5, "ts5_draw_ellipse(%f,%f,%f,%f)\n", cx, cy, rx, ry);
313 
314  if (_ts5_status.graphics_status.coordinate_scale == TS5_RELATIVE_COORDINATES) {
319  }
320 
321  if (_ts5_status.graphics_status.coordinate_system == TS5_CARTESIAN_COORDINATES) {
324  }
325 
326  if (!_ts5_status.graphics_status.fill_mode) {
327  al_draw_ellipse(cx, cy, rx, ry, _ts5_status.graphics_status.foreground_color,
328  _ts5_status.graphics_status.drawing_thickness);
329  }
330  else {
331  al_draw_filled_ellipse(cx, cy, rx, ry, _ts5_status.graphics_status.foreground_color);
332  }
333 }
334 
335 
345 void ts5_draw_arc(double cx, double cy, double r, double start, double delta)
346 {
347  ts5_check_primitives("ts5_draw_arc");
348  ts5_log(TS5_LOGLEVEL_5, "ts5_draw_arc(%f,%f,%f,%f,%f)\n", cx, cy, r, start, delta);
349 
350  if (_ts5_status.graphics_status.coordinate_scale == TS5_RELATIVE_COORDINATES) {
354  }
355 
356  if (_ts5_status.graphics_status.coordinate_system == TS5_CARTESIAN_COORDINATES) {
359  }
360 
361  start = start * TS5_PI / 180;
362  delta = delta * TS5_PI / 180;
363  al_draw_arc(cx, cy, r, start, delta, _ts5_status.graphics_status.foreground_color,
364  _ts5_status.graphics_status.drawing_thickness);
365 }
366 
367 
369 
370