PS2SDK
PS2 Homebrew Libraries
draw2d.c
1 #include <math.h>
2 
3 #include <draw.h>
4 #include <draw2d.h>
5 #include <draw3d.h>
6 
7 #include <gif_tags.h>
8 
9 #include <gs_gp.h>
10 
11 // Normal offset
12 #define OFFSET 2048.0f
13 
14 // Leftmost/Topmost offset (2048.0f - 0.4375f + 1)
15 #define START_OFFSET 2047.5625f
16 
17 // Bottommost/Rightmost offset (2048.0f + 0.5625f + 1)
18 #define END_OFFSET 2048.5625f
19 
20 #define DRAW_POINT_NREG 4
21 #define DRAW_POINT_REGLIST \
22  ((u64)GIF_REG_PRIM) << 0 | \
23  ((u64)GIF_REG_RGBAQ) << 4 | \
24  ((u64)GIF_REG_XYZ2) << 8 | \
25  ((u64)GIF_REG_NOP) << 12
26 
27 static char blending = 0;
28 
30 {
31  blending = 1;
32 }
33 
35 {
36  blending = 0;
37 }
38 
39 qword_t *draw_point(qword_t *q, int context, point_t *point)
40 {
41 
42  PACK_GIFTAG(q,GIF_SET_TAG(1,0,0,0,GIF_FLG_REGLIST,DRAW_POINT_NREG),DRAW_POINT_REGLIST);
43  q++;
44 
45  q->dw[0] = GIF_SET_PRIM(PRIM_POINT,0,0,0,blending,0,0,context,0);
46  q->dw[1] = point->color.rgbaq;
47  q++;
48 
49  q->dw[0] = GIF_SET_XYZ(ftoi4(point->v0.x + OFFSET),ftoi4(point->v0.y + OFFSET),point->v0.z);
50  q->dw[1] = 0;
51  q++;
52 
53  return q;
54 
55 }
56 
57 #define DRAW_LINE_NREG 4
58 #define DRAW_LINE_REGLIST \
59  ((u64)GIF_REG_PRIM) << 0 | \
60  ((u64)GIF_REG_RGBAQ) << 4 | \
61  ((u64)GIF_REG_XYZ2) << 8 | \
62  ((u64)GIF_REG_XYZ2) << 12
63 
64 qword_t *draw_line(qword_t *q, int context, line_t *line)
65 {
66 
67  PACK_GIFTAG(q,GIF_SET_TAG(1,0,0,0,GIF_FLG_REGLIST,DRAW_LINE_NREG),DRAW_LINE_REGLIST);
68  q++;
69 
70  q->dw[0] = GIF_SET_PRIM(PRIM_LINE,0,0,0,blending,0,0,context,0);
71  q->dw[1] = line->color.rgbaq;
72  q++;
73 
74  q->dw[0] = GIF_SET_XYZ(ftoi4(line->v0.x + START_OFFSET),ftoi4(line->v0.y + START_OFFSET),line->v0.z);
75  q->dw[1] = GIF_SET_XYZ(ftoi4(line->v1.x + END_OFFSET),ftoi4(line->v1.y + END_OFFSET),line->v0.z);
76  q++;
77 
78  return q;
79 
80 }
81 
82 #define DRAW_TRIANGLE_OUT_NREG 6
83 #define DRAW_TRIANGLE_OUT_REGLIST \
84  ((u64)GIF_REG_PRIM) << 0 | \
85  ((u64)GIF_REG_RGBAQ) << 4 | \
86  ((u64)GIF_REG_XYZ2) << 8 | \
87  ((u64)GIF_REG_XYZ2) << 12 | \
88  ((u64)GIF_REG_XYZ2) << 16 | \
89  ((u64)GIF_REG_XYZ2) << 20
90 
91 qword_t *draw_triangle_outline(qword_t *q, int context, triangle_t *triangle)
92 {
93 
94  int __xi0 = ftoi4(triangle->v0.x + OFFSET);
95  int __yi0 = ftoi4(triangle->v0.y + OFFSET);
96 
97  PACK_GIFTAG(q,GIF_SET_TAG(1,0,0,0,GIF_FLG_REGLIST,DRAW_TRIANGLE_OUT_NREG),DRAW_TRIANGLE_OUT_REGLIST);
98  q++;
99 
100  q->dw[0] = GIF_SET_PRIM(PRIM_LINE_STRIP,0,0,0,blending,0,0,context,0);
101  q->dw[1] = triangle->color.rgbaq;
102  q++;
103 
104  q->dw[0] = GIF_SET_XYZ(__xi0,__yi0,triangle->v0.z);
105  q->dw[1] = GIF_SET_XYZ(ftoi4(triangle->v1.x + OFFSET),ftoi4(triangle->v1.y + OFFSET),triangle->v0.z);
106  q++;
107 
108  q->dw[0] = GIF_SET_XYZ(ftoi4(triangle->v2.x + OFFSET),ftoi4(triangle->v2.y + OFFSET),triangle->v0.z);
109  q->dw[1] = GIF_SET_XYZ(__xi0,__yi0,triangle->v0.z);
110  q++;
111 
112 
113  return q;
114 
115 }
116 
117 #define DRAW_TRIANGLE_NREG 6
118 #define DRAW_TRIANGLE_REGLIST \
119  ((u64)GIF_REG_PRIM) << 0 | \
120  ((u64)GIF_REG_RGBAQ) << 4 | \
121  ((u64)GIF_REG_XYZ2) << 8 | \
122  ((u64)GIF_REG_XYZ2) << 12 | \
123  ((u64)GIF_REG_XYZ2) << 16 | \
124  ((u64)GIF_REG_NOP) << 20
125 
126 qword_t *draw_triangle_filled(qword_t *q, int context,triangle_t *triangle)
127 {
128 
129  PACK_GIFTAG(q,GIF_SET_TAG(1,0,0,0,GIF_FLG_REGLIST,DRAW_TRIANGLE_NREG),DRAW_TRIANGLE_REGLIST);
130  q++;
131 
132  q->dw[0] = GIF_SET_PRIM(PRIM_TRIANGLE,0,0,0,blending,0,0,context,0);
133  q->dw[1] = triangle->color.rgbaq;
134  q++;
135 
136  q->dw[0] = GIF_SET_XYZ(ftoi4(triangle->v0.x + OFFSET),ftoi4(triangle->v0.y + OFFSET),triangle->v0.z);
137  q->dw[1] = GIF_SET_XYZ(ftoi4(triangle->v1.x + OFFSET ),ftoi4(triangle->v1.y + OFFSET),triangle->v0.z);
138  q++;
139 
140  q->dw[0] = GIF_SET_XYZ(ftoi4(triangle->v2.x + OFFSET),ftoi4(triangle->v2.y + OFFSET),triangle->v0.z);
141  q->dw[1] = 0;
142  q++;
143 
144  return q;
145 
146 }
147 
148 #define DRAW_RECT_OUT_NREG 8
149 #define DRAW_RECT_OUT_REGLIST \
150  ((u64)GIF_REG_PRIM) << 0 | \
151  ((u64)GIF_REG_RGBAQ) << 4 | \
152  ((u64)GIF_REG_XYZ2) << 8 | \
153  ((u64)GIF_REG_XYZ2) << 12 | \
154  ((u64)GIF_REG_XYZ2) << 16 | \
155  ((u64)GIF_REG_XYZ2) << 20 | \
156  ((u64)GIF_REG_XYZ2) << 24 | \
157  ((u64)GIF_REG_NOP) << 28
158 
159 qword_t *draw_rect_outline(qword_t *q, int context, rect_t *rect)
160 {
161 
162  int __xi0 = ftoi4(rect->v0.x + START_OFFSET);
163  int __yi0 = ftoi4(rect->v0.y + START_OFFSET);
164  int __xi1 = ftoi4(rect->v1.x + END_OFFSET);
165  int __yi1 = ftoi4(rect->v1.y + END_OFFSET);
166 
167  PACK_GIFTAG(q,GIF_SET_TAG(1,0,0,0,GIF_FLG_REGLIST,DRAW_RECT_OUT_NREG),DRAW_RECT_OUT_REGLIST);
168  q++;
169 
170  q->dw[0] = GIF_SET_PRIM(PRIM_LINE_STRIP,0,0,0,blending,0,0,context,0);
171  q->dw[1] = rect->color.rgbaq;
172  q++;
173 
174  q->dw[0] = GIF_SET_XYZ(__xi0,__yi0,rect->v0.z);
175  q->dw[1] = GIF_SET_XYZ(__xi1,__yi0,rect->v0.z);
176  q++;
177 
178  q->dw[0] = GIF_SET_XYZ(__xi1,__yi1,rect->v0.z);
179  q->dw[1] = GIF_SET_XYZ(__xi0,__yi1,rect->v0.z);
180  q++;
181 
182  q->dw[0] = GIF_SET_XYZ(__xi0,__yi0,rect->v0.z);
183  q->dw[1] = 0;
184  q++;
185 
186  return q;
187 
188 }
189 
190 #define DRAW_SPRITE_NREG 4
191 #define DRAW_SPRITE_REGLIST \
192  ((u64)GIF_REG_PRIM) << 0 | \
193  ((u64)GIF_REG_RGBAQ) << 4 | \
194  ((u64)GIF_REG_XYZ2) << 8 | \
195  ((u64)GIF_REG_XYZ2) << 12
196 
197 qword_t *draw_rect_filled(qword_t *q, int context, rect_t *rect)
198 {
199 
200  PACK_GIFTAG(q,GIF_SET_TAG(1,0,0,0,GIF_FLG_REGLIST,DRAW_SPRITE_NREG),DRAW_SPRITE_REGLIST);
201  q++;
202 
203  q->dw[0] = GIF_SET_PRIM(PRIM_SPRITE,0,0,0,blending,0,0,context,0);
204  q->dw[1] = rect->color.rgbaq;
205  q++;
206 
207  q->dw[0] = GIF_SET_XYZ(ftoi4(rect->v0.x + START_OFFSET),ftoi4(rect->v0.y + START_OFFSET),rect->v0.z);
208  q->dw[1] = GIF_SET_XYZ(ftoi4(rect->v1.x + END_OFFSET),ftoi4(rect->v1.y + END_OFFSET),rect->v0.z);
209  q++;
210 
211  return q;
212 
213 }
214 
215 #define DRAW_SPRITE_TEX_NREG 6
216 #define DRAW_SPRITE_TEX_REGLIST \
217  ((u64)GIF_REG_PRIM) << 0 | \
218  ((u64)GIF_REG_RGBAQ) << 4 | \
219  ((u64)GIF_REG_UV) << 8 | \
220  ((u64)GIF_REG_XYZ2) << 12 | \
221  ((u64)GIF_REG_UV) << 16 | \
222  ((u64)GIF_REG_XYZ2) << 20
223 
224 qword_t *draw_rect_textured(qword_t *q, int context, texrect_t *rect)
225 {
226 
227  // Start primitive
228  PACK_GIFTAG(q,GIF_SET_TAG(1,0,0,0,GIF_FLG_REGLIST,DRAW_SPRITE_TEX_NREG),DRAW_SPRITE_TEX_REGLIST);
229  q++;
230 
231  // Fill vertex information
232  q->dw[0] = GIF_SET_PRIM(PRIM_SPRITE,0,DRAW_ENABLE,0,blending,0,PRIM_MAP_UV,context,0);
233  q->dw[1] = rect->color.rgbaq;
234  q++;
235 
236  q->dw[0] = GIF_SET_UV(ftoi4(rect->t0.u),ftoi4(rect->t0.v));
237  q->dw[1] = GIF_SET_XYZ(ftoi4(rect->v0.x + START_OFFSET),ftoi4(rect->v0.y + START_OFFSET),rect->v0.z);
238  q++;
239 
240  q->dw[0] = GIF_SET_UV(ftoi4(rect->t1.u),ftoi4(rect->t1.v));
241  q->dw[1] = GIF_SET_XYZ(ftoi4(rect->v1.x + END_OFFSET),ftoi4(rect->v1.y + END_OFFSET),rect->v0.z);
242  q++;
243 
244  return q;
245 
246 }
247 
248 qword_t *draw_rect_filled_strips(qword_t *q, int context, rect_t *rect)
249 {
250 
251  qword_t *giftag;
252 
253  int __xi0 = ftoi4(rect->v0.x);
254  int __yi0 = ftoi4(rect->v0.y + START_OFFSET);
255 
256  int __xi1 = ftoi4(rect->v1.x);
257  int __yi1 = ftoi4(rect->v1.y + END_OFFSET);
258 
259  // Start primitive
260  PACK_GIFTAG(q,GIF_SET_TAG(2,0,0,0,GIF_FLG_PACKED,1),GIF_REG_AD);
261  q++;
262 
263  PACK_GIFTAG(q,GIF_SET_PRIM(PRIM_SPRITE,0,0,0,blending,0,0,context,0),GIF_REG_PRIM);
264  q++;
265 
266  PACK_GIFTAG(q,rect->color.rgbaq,GIF_REG_RGBAQ);
267  q++;
268 
269  giftag = q;
270  q++;
271 
272  // Fill vertex information in 32 pixel wide strips
273  while(__xi0 < __xi1)
274  {
275 
276  //q->dw[0] = GIF_SET_XYZ(ftoi4(__xf0 + START_OFFSET),__yi0,rect->v0.z);
277  q->dw[0] = GIF_SET_XYZ(__xi0 + ftoi4(START_OFFSET),__yi0,rect->v0.z);
278 
279  // 31<<4
280  __xi0 += 496;
281 
282  // Uneven...
283  if (__xi0 >= __xi1)
284  {
285  __xi0 = __xi1;
286  }
287 
288  q->dw[1] = GIF_SET_XYZ(__xi0 + ftoi4(END_OFFSET),__yi1,rect->v0.z);
289 
290  // 1<<4
291  __xi0 += 16;
292 
293  q++;
294 
295  }
296 
297  PACK_GIFTAG(giftag,GIF_SET_TAG(q-giftag-1,0,0,0,GIF_FLG_REGLIST,2),DRAW_XYZ_REGLIST);
298 
299  return q;
300 
301 }
302 
303 qword_t *draw_rect_textured_strips(qword_t *q, int context, texrect_t *rect)
304 {
305 
306  qword_t *giftag;
307 
308  // Texel coordinates
309  float __uf0 = rect->t0.u;
310  int __vi0 = ftoi4(rect->t0.v);
311  int __vi1 = ftoi4(rect->t1.v);
312 
313  // Primitive coordinates
314  int __xi0 = ftoi4(rect->v0.x);
315  int __yi0 = ftoi4(rect->v0.y + START_OFFSET);
316 
317  int __xi1 = ftoi4(rect->v1.x);
318  int __yi1 = ftoi4(rect->v1.y + END_OFFSET);
319  float strip = 0.0f;
320 
321  // Start primitive
322  PACK_GIFTAG(q,GIF_SET_TAG(2,0,0,0,GIF_FLG_PACKED,1),GIF_REG_AD);
323  q++;
324 
325  PACK_GIFTAG(q,GIF_SET_PRIM(PRIM_SPRITE,0,DRAW_ENABLE,0,blending,0,PRIM_MAP_UV,context,0),GIF_REG_PRIM);
326  q++;
327 
328  PACK_GIFTAG(q,rect->color.rgbaq,GIF_REG_RGBAQ);
329  q++;
330 
331  giftag = q;
332  q++;
333 
334  // Fill vertex information in 32 pixel wide strips along with texel information
335  while(__xi0 < __xi1)
336  {
337 
338  q->dw[0] = GIF_SET_UV(ftoi4(__uf0),__vi0);
339  q->dw[1] = GIF_SET_XYZ(__xi0 + ftoi4(START_OFFSET),__yi0,rect->v0.z);
340  q++;
341 
342  // Due to the GS DDA, 0-32 only draws pixels 0-31
343  // Due to the above, texels 0.5 - 30.5 will map 0-31
344 
345  strip += 32.0f;
346 
347  __xi0 += 496;
348 
349  if (__xi0 >= __xi1)
350  {
351  __xi0 = __xi1;
352  }
353 
354  __uf0 = rect->t0.u + (strip - 1.5f);
355 
356  q->dw[0] = GIF_SET_UV(ftoi4(__uf0),__vi1);
357  q->dw[1] = GIF_SET_XYZ(__xi0 + ftoi4(END_OFFSET),__yi1,rect->v0.z);
358 
359  __xi0 += 16;
360  q++;
361 
362  }
363 
364  PACK_GIFTAG(giftag,GIF_SET_TAG(q-giftag-1,0,0,0,GIF_FLG_REGLIST,2),DRAW_UV_REGLIST);
365 
366  return q;
367 
368 }
369 
370 qword_t *draw_arc_outline(qword_t *q, int context, point_t *center, float radius, float angle_start, float angle_end)
371 {
372 
373  qword_t *giftag;
374 
375  u64 *dw;
376  u64 pdw;
377 
378  int __xi0 = ftoi4(center->v0.x + OFFSET);
379  int __yi0 = ftoi4(center->v0.y + OFFSET);
380 
381  // Start primitive
382  PACK_GIFTAG(q,GIF_SET_TAG(2,0,0,0,GIF_FLG_PACKED,1),GIF_REG_AD);
383  q++;
384 
385  PACK_GIFTAG(q,GIF_SET_PRIM(PRIM_LINE_STRIP,0,0,0,blending,0,0,context,0),GIF_REG_PRIM);
386  q++;
387 
388  PACK_GIFTAG(q,center->color.rgbaq,GIF_REG_RGBAQ);
389  q++;
390 
391  giftag = q;
392  q++;
393 
394  dw = (u64*)q;
395 
396  // Fill vertex information
397  for( ; angle_start <= angle_end; angle_start++)
398  {
399  int __xi1;
400  int __yi1;
401  float __arc_radians;
402  __arc_radians = angle_start * 0.017453293f;
403  __xi1 = (int)((cosf(__arc_radians) * radius) * 16.0f);
404  __yi1 = (int)((sinf(__arc_radians) * radius) * 16.0f);
405  *dw++ = GIF_SET_XYZ(__xi0 + __xi1,__yi0 + __yi1,center->v0.z);
406  }
407 
408  // Copy the last 64-bits if we haven't completed the last qword
409  if ((u32)dw % 16)
410  {
411 
412  pdw = *(dw-1);
413  *dw++ = pdw;
414 
415  }
416 
417  q = (qword_t*)dw;
418 
419  PACK_GIFTAG(giftag,GIF_SET_TAG(q-giftag-1,0,0,0,GIF_FLG_REGLIST,2),DRAW_XYZ_REGLIST);
420 
421  return q;
422 
423 }
424 
425 qword_t *draw_arc_filled(qword_t *q, int context, point_t *center, float radius, float angle_start, float angle_end)
426 {
427 
428  qword_t *giftag;
429 
430  u64 *dw;
431  u64 pdw;
432 
433  int __xi0 = ftoi4(center->v0.x + OFFSET);
434  int __yi0 = ftoi4(center->v0.y + OFFSET);
435 
436  // Start primitive
437  PACK_GIFTAG(q,GIF_SET_TAG(2,0,0,0,GIF_FLG_PACKED,1),GIF_REG_AD);
438  q++;
439 
440  PACK_GIFTAG(q,GIF_SET_PRIM(PRIM_TRIANGLE_FAN,0,0,0,blending,0,0,context,0),GIF_REG_PRIM);
441  q++;
442 
443  PACK_GIFTAG(q,center->color.rgbaq,GIF_REG_RGBAQ);
444  q++;
445 
446  giftag = q;
447  q++;
448 
449  dw = (u64*)q;
450 
451  // Fill vertex information
452  *dw++ = GIF_SET_XYZ(__xi0,__yi0,center->v0.z);
453 
454  for( ; angle_start <= angle_end; angle_start++)
455  {
456  int __xi1;
457  int __yi1;
458  float __arc_radians;
459  __arc_radians = 0.017453293f * angle_start;
460  __xi1 = (int)((cosf(__arc_radians) * radius) * 16.0f);
461  __yi1 = (int)((sinf(__arc_radians) * radius) * 16.0f);
462  *dw++ = GIF_SET_XYZ(__xi0 + __xi1,__yi0 + __yi1,center->v0.z);
463  }
464 
465  // Copy the last vertex if we're uneven
466  if ((u32)dw % 16)
467  {
468 
469  pdw = *(dw-1);
470  *dw++ = pdw;
471 
472  }
473 
474  q = (qword_t*)dw;
475 
476  PACK_GIFTAG(giftag,GIF_SET_TAG(q-giftag-1,0,0,0,GIF_FLG_REGLIST,2),DRAW_XYZ_REGLIST);
477 
478  return q;
479 
480 }
481 
482 qword_t *draw_round_rect_filled(qword_t *q, int context, rect_t *rect)
483 {
484 
485  rect_t rect_center;
486  rect_t rect_side;
487  point_t point_corner;
488 
489  int center_width;
490  int center_height;
491 
492  float corner_size = 15.0f;
493 
494  int width = rect->v1.x - rect->v0.x;
495  int height = rect->v1.y - rect->v0.y;
496 
497  center_width = width - (int)(2.0f*corner_size);
498  center_height = height - (int)(2.0f*corner_size);
499 
500  rect_center.color = rect->color;
501  rect_side.color = rect->color;
502  rect_center.v0.z = rect->v0.z;
503  rect_side.v0.z = rect->v0.z;
504 
505  // Inside rectangle
506  rect_center.v0.x = rect->v0.x + corner_size;
507  rect_center.v0.y = rect->v0.y + corner_size;
508  rect_center.v1.x = rect_center.v0.x + (float)center_width;
509  rect_center.v1.y = rect_center.v0.y + (float)center_height;
510 
511  q = draw_rect_filled_strips(q,context,&rect_center);
512 
513  // sides
514  // top
515  rect_side.v0.x = rect_center.v0.x;
516  rect_side.v0.y = rect_center.v0.y - corner_size;
517  rect_side.v1.x = rect_center.v1.x;
518  rect_side.v1.y = rect_center.v0.y - 1.0f;
519 
520  q = draw_rect_filled_strips(q,context,&rect_side);
521 
522  // right
523  rect_side.v0.x = rect_center.v1.x + 1.0f;
524  rect_side.v0.y = rect_center.v0.y;
525  rect_side.v1.x = rect_center.v1.x + corner_size;
526  rect_side.v1.y = rect_center.v1.y;
527 
528  q = draw_rect_filled(q,context,&rect_side);
529 
530  // bottom
531  rect_side.v0.x = rect_center.v0.x;
532  rect_side.v0.y = rect_center.v1.y + 1.0f;
533  rect_side.v1.x = rect_center.v1.x;
534  rect_side.v1.y = rect_center.v1.y + corner_size;
535 
536  q = draw_rect_filled_strips(q,context,&rect_side);
537 
538  // left
539  rect_side.v0.x = rect_center.v0.x - corner_size;
540  rect_side.v0.y = rect_center.v0.y;
541  rect_side.v1.x = rect_center.v0.x - 1.0f;
542  rect_side.v1.y = rect_center.v1.y;
543 
544  q = draw_rect_filled(q,context,&rect_side);
545 
546  // corners
547  // top right
548  point_corner.v0.x = rect_center.v1.x + 1.0f;
549  point_corner.v0.y = rect_center.v0.y;
550  point_corner.color = rect->color;
551 
552  q = draw_arc_filled(q,context,&point_corner,corner_size,270.0f,360.0f);
553 
554  // bottom right
555  point_corner.v0.x = rect_center.v1.x + 1.0f;
556  point_corner.v0.y = rect_center.v1.y + 1.0f;
557  point_corner.color = rect->color;
558 
559  q = draw_arc_filled(q,context,&point_corner,corner_size,0.0f,90.0f);
560 
561  // bottom left
562  point_corner.v0.x = rect_center.v0.x;
563  point_corner.v0.y = rect_center.v1.y + 1.0f;
564  point_corner.color = rect->color;
565 
566  q = draw_arc_filled(q,context,&point_corner,corner_size,90.0f,180.0f);
567 
568  // top left
569  point_corner.v0.x = rect_center.v0.x;
570  point_corner.v0.y = rect_center.v0.y;
571  point_corner.color = rect->color;
572 
573  q = draw_arc_filled(q,context,&point_corner,corner_size,180.0f,270.0f);
574 
575  return q;
576 
577 }
578 
579 qword_t *draw_round_rect_outline(qword_t *q, int context, rect_t *rect)
580 {
581 
582  rect_t rect_center;
583  line_t line_side;
584  point_t point_corner;
585 
586  int center_width;
587  int center_height;
588 
589  float corner_size = 15.0f;
590 
591  int width = rect->v1.x - rect->v0.x;
592  int height = rect->v1.y - rect->v0.y;
593 
594  center_width = width - (int)(2.0f*corner_size);
595  center_height = height - (int)(2.0f*corner_size);
596 
597  rect_center.color = rect->color;
598  line_side.color = rect->color;
599  rect_center.v0.z = rect->v0.z;
600  line_side.v0.z = rect->v0.z;
601 
602  // Inside rectangle
603  rect_center.v0.x = rect->v0.x + corner_size;
604  rect_center.v0.y = rect->v0.y + corner_size;
605  rect_center.v1.x = rect_center.v0.x + (float)center_width;
606  rect_center.v1.y = rect_center.v0.y + (float)center_height;
607 
608  //q = draw_rect_filled_strips(q,context,&rect_center);
609 
610  // sides
611  // top
612  line_side.v0.x = rect_center.v0.x;
613  line_side.v0.y = rect_center.v0.y - corner_size + 1.0f;
614  line_side.v1.x = rect_center.v1.x;
615  line_side.v1.y = rect_center.v0.y - corner_size;
616 
617  q = draw_line(q,context,&line_side);
618 
619  // right
620  line_side.v0.x = rect_center.v1.x + corner_size;
621  line_side.v0.y = rect_center.v0.y;
622  line_side.v1.x = rect_center.v1.x + corner_size - 1.0f;
623  line_side.v1.y = rect_center.v1.y;
624 
625  q = draw_line(q,context,&line_side);
626 
627  // bottom
628  line_side.v0.x = rect_center.v0.x;
629  line_side.v0.y = rect_center.v1.y + corner_size + 1.0f;
630  line_side.v1.x = rect_center.v1.x;
631  line_side.v1.y = rect_center.v1.y + corner_size;
632 
633  q = draw_line(q,context,&line_side);
634 
635  // left
636  line_side.v0.x = rect_center.v0.x - corner_size;
637  line_side.v0.y = rect_center.v0.y;
638  line_side.v1.x = rect_center.v0.x - corner_size - 1.0f;
639  line_side.v1.y = rect_center.v1.y;
640 
641  q = draw_line(q,context,&line_side);
642 
643  // corners
644  // top right
645  point_corner.v0.x = rect_center.v1.x;
646  point_corner.v0.y = rect_center.v0.y;
647  point_corner.color = rect->color;
648 
649  q = draw_arc_outline(q,context,&point_corner,corner_size,270.0f,360.0f);
650 
651  // bottom right
652  point_corner.v0.x = rect_center.v1.x;
653  point_corner.v0.y = rect_center.v1.y;
654  point_corner.color = rect->color;
655 
656  q = draw_arc_outline(q,context,&point_corner,corner_size,0.0f,90.0f);
657 
658  // bottom left
659  point_corner.v0.x = rect_center.v0.x;
660  point_corner.v0.y = rect_center.v1.y;
661  point_corner.color = rect->color;
662 
663  q = draw_arc_outline(q,context,&point_corner,corner_size,90.0f,180.0f);
664 
665  // top left
666  point_corner.v0.x = rect_center.v0.x;
667  point_corner.v0.y = rect_center.v0.y;
668  point_corner.color = rect->color;
669 
670  q = draw_arc_outline(q,context,&point_corner,corner_size,180.0f,270.0f);
671 
672  return q;
673 
674 }
gs_gp.h
point_t
Definition: draw2d.h:13
GIF_REG_PRIM
#define GIF_REG_PRIM
Definition: gif_tags.h:42
draw_rect_textured
qword_t * draw_rect_textured(qword_t *q, int context, texrect_t *rect)
Definition: draw2d.c:224
draw_disable_blending
void draw_disable_blending()
Definition: draw2d.c:34
GIF_REG_AD
#define GIF_REG_AD
Definition: gif_tags.h:72
triangle_t
Definition: draw2d.h:24
draw_round_rect_outline
qword_t * draw_round_rect_outline(qword_t *q, int context, rect_t *rect)
Definition: draw2d.c:579
line_t
Definition: draw2d.h:18
draw_triangle_outline
qword_t * draw_triangle_outline(qword_t *q, int context, triangle_t *triangle)
Definition: draw2d.c:91
draw_rect_filled
qword_t * draw_rect_filled(qword_t *q, int context, rect_t *rect)
Definition: draw2d.c:197
draw3d.h
draw_rect_textured_strips
qword_t * draw_rect_textured_strips(qword_t *q, int context, texrect_t *rect)
Definition: draw2d.c:303
draw_round_rect_filled
qword_t * draw_round_rect_filled(qword_t *q, int context, rect_t *rect)
Definition: draw2d.c:482
draw_arc_outline
qword_t * draw_arc_outline(qword_t *q, int context, point_t *center, float radius, float angle_start, float angle_end)
Definition: draw2d.c:370
GIF_FLG_REGLIST
#define GIF_FLG_REGLIST
Definition: gif_tags.h:37
GIF_REG_RGBAQ
#define GIF_REG_RGBAQ
Definition: gif_tags.h:44
GIF_FLG_PACKED
#define GIF_FLG_PACKED
Definition: gif_tags.h:35
draw_triangle_filled
qword_t * draw_triangle_filled(qword_t *q, int context, triangle_t *triangle)
Definition: draw2d.c:126
draw_enable_blending
void draw_enable_blending()
Definition: draw2d.c:29
draw_rect_filled_strips
qword_t * draw_rect_filled_strips(qword_t *q, int context, rect_t *rect)
Definition: draw2d.c:248
draw.h
PRIM_POINT
#define PRIM_POINT
Definition: draw_primitives.h:12
DRAW_XYZ_REGLIST
#define DRAW_XYZ_REGLIST
Definition: draw3d.h:16
draw2d.h
draw_rect_outline
qword_t * draw_rect_outline(qword_t *q, int context, rect_t *rect)
Definition: draw2d.c:159
draw_line
qword_t * draw_line(qword_t *q, int context, line_t *line)
Definition: draw2d.c:64
gif_tags.h
draw_point
qword_t * draw_point(qword_t *q, int context, point_t *point)
Definition: draw2d.c:39
draw_arc_filled
qword_t * draw_arc_filled(qword_t *q, int context, point_t *center, float radius, float angle_start, float angle_end)
Definition: draw2d.c:425
texrect_t
Definition: draw2d.h:37
rect_t
Definition: draw2d.h:31