| 1 |
/* |
| 2 |
* This file is part of the DXX-Rebirth project <https://www.dxx-rebirth.com/>. |
| 3 |
* It is copyright by its individual contributors, as recorded in the |
| 4 |
* project's Git history. See COPYING.txt at the top level for license |
| 5 |
* terms and a link to the Git history. |
| 6 |
*/ |
| 7 |
/* |
| 8 |
* |
| 9 |
* Graphical routines for drawing a disk. |
| 10 |
* |
| 11 |
*/ |
| 12 |
|
| 13 |
#include "u_mem.h" |
| 14 |
#include "gr.h" |
| 15 |
|
| 16 |
namespace dcx { |
| 17 |
|
| 18 |
#if !DXX_USE_OGL |
| 19 |
int gr_disk(grs_canvas &canvas, const fix xc1, const fix yc1, const fix r1, const uint8_t color) |
| 20 |
{ |
| 21 |
int p,x, y, xc, yc, r; |
| 22 |
|
| 23 |
r = f2i(r1); |
| 24 |
xc = f2i(xc1); |
| 25 |
yc = f2i(yc1); |
| 26 |
p=3-(r*2); |
| 27 |
x=0; |
| 28 |
y=r; |
| 29 |
|
| 30 |
// Big clip |
| 31 |
if (xc + r < 0) |
| 32 |
return 1; |
| 33 |
if (xc - r > canvas.cv_bitmap.bm_w) |
| 34 |
return 1; |
| 35 |
if (yc + r < 0) |
| 36 |
return 1; |
| 37 |
if (yc - r > canvas.cv_bitmap.bm_h) |
| 38 |
return 1; |
| 39 |
|
| 40 |
while(x<y) |
| 41 |
{ |
| 42 |
// Draw the first octant |
| 43 |
gr_scanline(canvas, xc-y, xc+y, yc-x, color); |
| 44 |
gr_scanline(canvas, xc-y, xc+y, yc+x, color); |
| 45 |
|
| 46 |
if (p<0) |
| 47 |
p=p+(x<<2)+6; |
| 48 |
else { |
| 49 |
// Draw the second octant |
| 50 |
gr_scanline(canvas, xc-x, xc+x, yc-y, color); |
| 51 |
gr_scanline(canvas, xc-x, xc+x, yc+y, color); |
| 52 |
p=p+((x-y)<<2)+10; |
| 53 |
y--; |
| 54 |
} |
| 55 |
x++; |
| 56 |
} |
| 57 |
if(x==y) { |
| 58 |
gr_scanline(canvas, xc-x, xc+x, yc-y, color); |
| 59 |
gr_scanline(canvas, xc-x, xc+x, yc+y, color); |
| 60 |
} |
| 61 |
return 0; |
| 62 |
} |
| 63 |
|
| 64 |
#endif |
| 65 |
|
| 66 |
} |