]>
git.defcon.no Git - avrfbosd/blob - draw.c
4 extern uint8_t* screen_buffer
;
5 extern uint8_t hres_bytes
;
7 void sp(uint8_t x
, uint8_t y
, uint8_t color
)
9 if (color
==0) screen_buffer
[(x
/8) + (y
*hres_bytes
)] &= ~0x80 >> (x
&7);
10 else if (color
==1) screen_buffer
[(x
/8) + (y
*hres_bytes
)] |= 0x80 >> (x
&7);
11 else screen_buffer
[(x
/8) + (y
*hres_bytes
)] ^= 0x80 >> (x
&7);
14 void set_pixel(uint8_t x
, uint8_t y
, uint8_t color
)
16 if (x
>= hres_bytes
*8 || y
>= VRES
)
21 void fill(uint8_t color
)
25 for (int i
= 0; i
< (hres_bytes
*VRES
); i
++)
29 for (int i
= 0; i
< (hres_bytes
*VRES
); i
++)
30 screen_buffer
[i
] = 0xFF;
33 for (int i
= 0; i
< (hres_bytes
*VRES
); i
++)
34 screen_buffer
[i
] = ~screen_buffer
[i
];
41 Bresenham's line algorithm, optimized and simplified.
42 function line(x0, y0, x1, y1)
45 if x0 < x1 then sx := 1 else sx := -1
46 if y0 < y1 then sy := 1 else sy := -1
51 if x0 = x1 and y0 = y1 exit loop
63 void draw_line(uint8_t x0
, uint8_t y0
, uint8_t x1
, uint8_t y1
, uint8_t c
)
66 if (x0
> hres_bytes
*8 || y0
> VRES
|| x1
> hres_bytes
*8 || y1
> VRES
)
69 int dx
, dy
, sx
, sy
, err
, p
;
73 if ( x0
< x1
) sx
= 1; else sx
= -1;
74 if ( y0
< y1
) sy
= 1; else sy
= -1;
80 if ( ( x0
== x1
) && ( y0
== y1
) ) return;
94 // draw_row and draw_col ...
95 // These whould really be used for optimization.
96 // As is, they exist for conveniance, not speed :P
97 void draw_col(uint8_t x
, uint8_t y0
, uint8_t y1
, uint8_t c
)
99 draw_line( x
, y0
, x
, y1
, c
);
101 void draw_row(uint8_t y
, uint8_t x0
, uint8_t x1
, uint8_t c
)
103 draw_line( x0
, y
, x1
, y
, c
);
107 void _draw_rect(uint8_t x0
, uint8_t y0
, uint8_t w
, uint8_t h
, int8_t c
, int8_t fc
)
110 for (unsigned char i
= 0; i
< h
; i
++)
111 draw_line(x0
,y0
+i
,x0
+w
,y0
+i
,c
);
113 draw_line(x0
,y0
,x0
+w
,y0
,c
);
114 draw_line(x0
,y0
,x0
,y0
+h
,c
);
115 draw_line(x0
+w
,y0
,x0
+w
,y0
+h
,c
);
116 draw_line(x0
,y0
+h
,x0
+w
,y0
+h
,c
);
119 void _draw_circle(uint8_t x0
, uint8_t y0
, uint8_t radius
, int8_t c
, int8_t fc
) {
123 int ddF_y
= -2 * radius
;
126 uint8_t pyy
= y
,pyx
= x
;
128 //there is a fill color
130 draw_row(y0
,x0
-radius
,x0
+radius
,fc
);
132 sp(x0
, y0
+ radius
,c
);
133 sp(x0
, y0
- radius
,c
);
134 sp(x0
+ radius
, y0
,c
);
135 sp(x0
- radius
, y0
,c
);
146 //there is a fill color
148 //prevent double draws on the same rows
150 draw_row(y0
+y
,x0
-x
,x0
+x
,fc
);
151 draw_row(y0
-y
,x0
-x
,x0
+x
,fc
);
153 if (pyx
!= x
&& x
!= y
) {
154 draw_row(y0
+x
,x0
-y
,x0
+y
,fc
);
155 draw_row(y0
-x
,x0
-y
,x0
+y
,fc
);
161 sp(x0
+ x
, y0
+ y
,c
);
162 sp(x0
- x
, y0
+ y
,c
);
163 sp(x0
+ x
, y0
- y
,c
);
164 sp(x0
- x
, y0
- y
,c
);
165 sp(x0
+ y
, y0
+ x
,c
);
166 sp(x0
- y
, y0
+ x
,c
);
167 sp(x0
+ y
, y0
- x
,c
);
168 sp(x0
- y
, y0
- x
,c
);
172 void draw_rect(uint8_t x0
, uint8_t y0
, uint8_t w
, uint8_t h
, uint8_t c
)
174 _draw_rect(x0
, y0
, w
, h
, c
, -1);
177 void fill_rect(uint8_t x0
, uint8_t y0
, uint8_t w
, uint8_t h
, uint8_t c
)
179 _draw_rect(x0
, y0
, w
, h
, c
, c
);
182 void draw_circle(uint8_t x0
, uint8_t y0
, uint8_t radius
, char c
)
184 _draw_circle(x0
, y0
, radius
, c
, -1);
187 void fill_circle(uint8_t x0
, uint8_t y0
, uint8_t radius
, char c
)
189 _draw_circle(x0
, y0
, radius
, c
, c
);