altos/telelco-v2.0: A bit fancier with the drag-mode LED show
[fw/altos] / src / draw / ao_rect.c
1 /*
2  * Copyright © 2016 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  */
14
15 #include "ao.h"
16 #include "ao_draw.h"
17 #include "ao_draw_int.h"
18
19 void
20 ao_rect(const struct ao_bitmap  *dst,
21         int16_t                 x,
22         int16_t                 y,
23         int16_t                 width,
24         int16_t                 height,
25         uint32_t                fill,
26         uint8_t                 rop)
27 {
28         int16_t x2 = x + width;
29         int16_t y2 = y + height;
30
31         ao_clip(x, 0, dst->width);
32         ao_clip(x2, 0, dst->width);
33         ao_clip(y, 0, dst->height);
34         ao_clip(y2, 0, dst->height);
35
36         if (x < x2 && y < y2) {
37                 ao_solid(ao_and(rop, fill),
38                          ao_xor(rop, fill),
39                          dst->base + y * dst->stride,
40                          dst->stride,
41                          x,
42                          x2 - x,
43                          y2 - y);
44         }
45 }
46