altos/telelco-v2.0: A bit fancier with the drag-mode LED show
[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 struct ao_pattern {
26         uint8_t         pattern[8];
27 };
28
29 void
30 ao_copy(const struct ao_bitmap  *dst,
31         int16_t                 dst_x,
32         int16_t                 dst_y,
33         int16_t                 width,
34         int16_t                 height,
35         const struct ao_bitmap  *src,
36         int16_t                 src_x,
37         int16_t                 src_y,
38         uint8_t                 rop);
39
40 void
41 ao_rect(const struct ao_bitmap  *dst,
42         int16_t                 x,
43         int16_t                 y,
44         int16_t                 width,
45         int16_t                 height,
46         uint32_t                fill,
47         uint8_t                 rop);
48
49 void
50 ao_pattern(const struct ao_bitmap       *dst,
51            int16_t                      x,
52            int16_t                      y,
53            int16_t                      width,
54            int16_t                      height,
55            const struct ao_pattern      *pattern,
56            int16_t                      pat_x,
57            int16_t                      pat_y,
58            uint8_t                      rop);
59
60 void
61 ao_line(const struct ao_bitmap  *dst,
62         int16_t                 x1,
63         int16_t                 y1,
64         int16_t                 x2,
65         int16_t                 y2,
66         uint32_t                fill,
67         uint8_t                 rop);
68
69 void
70 ao_text(const struct ao_bitmap  *dst,
71         int16_t                 x,
72         int16_t                 y,
73         char                    *string,
74         uint32_t                fill,
75         uint8_t                 rop);
76
77 struct ao_font {
78         int     width;
79         int     height;
80         int     ascent;
81         int     descent;
82 };
83
84 extern const struct ao_font ao_font;
85
86 #define AO_SHIFT        5
87 #define AO_UNIT         (1 << AO_SHIFT)
88 #define AO_MASK         (AO_UNIT - 1)
89 #define AO_ALLONES      ((uint32_t) -1)
90
91 /*
92  *          dst
93  *         0   1
94  *
95  *      0  a   b
96  *  src
97  *      1  c   d
98  *
99  *      ROP = abcd
100  */
101
102 #define AO_CLEAR         0x0    /* 0 */
103 #define AO_AND           0x1    /* src AND dst */
104 #define AO_AND_REVERSE   0x2    /* src AND NOT dst */
105 #define AO_COPY          0x3    /* src */
106 #define AO_AND_INVERTED  0x4    /* NOT src AND dst */
107 #define AO_NOOP          0x5    /* dst */
108 #define AO_XOR           0x6    /* src XOR dst */
109 #define AO_OR            0x7    /* src OR dst */
110 #define AO_NOR           0x8    /* NOT src AND NOT dst */
111 #define AO_EQUIV         0x9    /* NOT src XOR dst */
112 #define AO_INVERT        0xa    /* NOT dst */
113 #define AO_OR_REVERSE    0xb    /* src OR NOT dst */
114 #define AO_COPY_INVERTED 0xc    /* NOT src */
115 #define AO_OR_INVERTED   0xd    /* NOT src OR dst */
116 #define AO_NAND          0xe    /* NOT src OR NOT dst */
117 #define AO_SET           0xf    /* 1 */
118
119 #endif /* _AO_DRAW_H_ */