altos/draw: Add a reasonable API for drawing, add lines.
[fw/altos] / src / draw / ao_draw.h
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 #ifndef _AO_DRAW_H_
16 #define _AO_DRAW_H_
17
18 struct ao_bitmap {
19         uint32_t        *base;
20         int16_t         stride; /* in units */
21         int16_t         width;  /* in pixels */
22         int16_t         height; /* in pixels */
23 };
24
25 void
26 ao_copy(const struct ao_bitmap  *dst,
27         int16_t                 dst_x,
28         int16_t                 dst_y,
29         int16_t                 width,
30         int16_t                 height,
31         const struct ao_bitmap  *src,
32         int16_t                 src_x,
33         int16_t                 src_y,
34         uint8_t                 rop);
35
36 void
37 ao_rect(const struct ao_bitmap  *dst,
38         int16_t                 x,
39         int16_t                 y,
40         int16_t                 width,
41         int16_t                 height,
42         uint32_t                fill,
43         uint8_t                 rop);
44
45 void
46 ao_line(const struct ao_bitmap  *dst,
47         int16_t                 x1,
48         int16_t                 y1,
49         int16_t                 x2,
50         int16_t                 y2,
51         uint32_t                fill,
52         uint8_t                 rop);
53
54 void
55 ao_text(const struct ao_bitmap  *dst,
56         int16_t                 x,
57         int16_t                 y,
58         char                    *string,
59         uint32_t                fill,
60         uint8_t                 rop);
61
62 struct ao_font {
63         int     width;
64         int     height;
65         int     ascent;
66         int     descent;
67 };
68
69 extern const struct ao_font ao_font;
70
71 #define AO_SHIFT        5
72 #define AO_UNIT         (1 << AO_SHIFT)
73 #define AO_MASK         (AO_UNIT - 1)
74 #define AO_ALLONES      ((uint32_t) -1)
75
76 /*
77  *          dst
78  *         0   1
79  *
80  *      0  a   b
81  *  src
82  *      1  c   d
83  *
84  *      ROP = abcd
85  */
86
87 #define AO_CLEAR         0x0    /* 0 */
88 #define AO_AND           0x1    /* src AND dst */
89 #define AO_AND_REVERSE   0x2    /* src AND NOT dst */
90 #define AO_COPY          0x3    /* src */
91 #define AO_AND_INVERTED  0x4    /* NOT src AND dst */
92 #define AO_NOOP          0x5    /* dst */
93 #define AO_XOR           0x6    /* src XOR dst */
94 #define AO_OR            0x7    /* src OR dst */
95 #define AO_NOR           0x8    /* NOT src AND NOT dst */
96 #define AO_EQUIV         0x9    /* NOT src XOR dst */
97 #define AO_INVERT        0xa    /* NOT dst */
98 #define AO_OR_REVERSE    0xb    /* src OR NOT dst */
99 #define AO_COPY_INVERTED 0xc    /* NOT src */
100 #define AO_OR_INVERTED   0xd    /* NOT src OR dst */
101 #define AO_NAND          0xe    /* NOT src OR NOT dst */
102 #define AO_SET           0xf    /* 1 */
103
104 #endif /* _AO_DRAW_H_ */