266f13461e253062c4edbeaa80c7a9d65f45e196
[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_draw.h"
16 #include "ao_draw_int.h"
17
18 void
19 ao_rect(const struct ao_bitmap  *dst,
20         int16_t                 x,
21         int16_t                 y,
22         int16_t                 width,
23         int16_t                 height,
24         uint32_t                fill,
25         uint8_t                 rop)
26 {
27         int16_t x2 = x + width;
28         int16_t y2 = y + height;
29
30         ao_clip(x, 0, dst->width);
31         ao_clip(x2, 0, dst->width);
32         ao_clip(y, 0, dst->height);
33         ao_clip(y2, 0, dst->height);
34
35         if (x < x2 && y < y2) {
36                 ao_solid(ao_and(rop, fill),
37                          ao_xor(rop, fill),
38                          dst->base + y * dst->stride,
39                          dst->stride,
40                          x,
41                          x2 - x,
42                          y2 - y);
43         }
44 }
45