8d487a9975e57658ae0a602e0958a401c55a5035
[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 #include <stdint.h>
19 #include <stdbool.h>
20 #include "ao_font.h"
21
22 struct ao_bitmap {
23         uint32_t        *base;
24         int16_t         stride; /* in units */
25         int16_t         width;  /* in pixels */
26         int16_t         height; /* in pixels */
27 };
28
29 struct ao_coord {
30         float   x, y;
31 };
32
33 struct ao_pattern {
34         uint8_t         pattern[8];
35 };
36
37 struct ao_glyph_metrics {
38         int8_t  width;
39         int8_t  height;
40         int8_t  x_off;
41         int8_t  y_off;
42         int8_t  advance;
43 };
44
45 struct ao_font {
46         const uint8_t   *bytes;
47         const uint16_t  *pos;
48         const struct ao_glyph_metrics *metrics;
49         int     max_width;
50         int     max_height;
51         int     ascent;
52 };
53
54 void
55 ao_copy(const struct ao_bitmap  *dst,
56         int16_t                 dst_x,
57         int16_t                 dst_y,
58         int16_t                 width,
59         int16_t                 height,
60         const struct ao_bitmap  *src,
61         int16_t                 src_x,
62         int16_t                 src_y,
63         uint8_t                 rop);
64
65 void
66 ao_rect(const struct ao_bitmap  *dst,
67         int16_t                 x,
68         int16_t                 y,
69         int16_t                 width,
70         int16_t                 height,
71         uint32_t                fill,
72         uint8_t                 rop);
73
74 void
75 ao_pattern(const struct ao_bitmap       *dst,
76            int16_t                      x,
77            int16_t                      y,
78            int16_t                      width,
79            int16_t                      height,
80            const struct ao_pattern      *pattern,
81            int16_t                      pat_x,
82            int16_t                      pat_y,
83            uint8_t                      rop);
84
85 void
86 ao_line(const struct ao_bitmap  *dst,
87         int16_t                 x1,
88         int16_t                 y1,
89         int16_t                 x2,
90         int16_t                 y2,
91         uint32_t                fill,
92         uint8_t                 rop);
93
94 void
95 ao_poly(const struct ao_bitmap  *dst,
96         const struct ao_coord   *coords,
97         uint16_t                ncoords,
98         uint32_t                fill,
99         uint8_t                 rop);
100
101 void
102 ao_text(const struct ao_bitmap  *dst,
103         const struct ao_font    *font,
104         int16_t                 x,
105         int16_t                 y,
106         char                    *string,
107         uint32_t                fill,
108         uint8_t                 rop);
109
110 extern const struct ao_font FrutigerLT_Roman_50_font;
111
112 #define AO_SHIFT        5
113 #define AO_UNIT         (1 << AO_SHIFT)
114 #define AO_MASK         (AO_UNIT - 1)
115 #define AO_ALLONES      ((uint32_t) -1)
116
117 /*
118  *          dst
119  *         0   1
120  *
121  *      0  a   b
122  *  src
123  *      1  c   d
124  *
125  *      ROP = abcd
126  */
127
128 #define AO_CLEAR         0x0    /* 0 */
129 #define AO_AND           0x1    /* src AND dst */
130 #define AO_AND_REVERSE   0x2    /* src AND NOT dst */
131 #define AO_COPY          0x3    /* src */
132 #define AO_AND_INVERTED  0x4    /* NOT src AND dst */
133 #define AO_NOOP          0x5    /* dst */
134 #define AO_XOR           0x6    /* src XOR dst */
135 #define AO_OR            0x7    /* src OR dst */
136 #define AO_NOR           0x8    /* NOT src AND NOT dst */
137 #define AO_EQUIV         0x9    /* NOT src XOR dst */
138 #define AO_INVERT        0xa    /* NOT dst */
139 #define AO_OR_REVERSE    0xb    /* src OR NOT dst */
140 #define AO_COPY_INVERTED 0xc    /* NOT src */
141 #define AO_OR_INVERTED   0xd    /* NOT src OR dst */
142 #define AO_NAND          0xe    /* NOT src OR NOT dst */
143 #define AO_SET           0xf    /* 1 */
144
145 #endif /* _AO_DRAW_H_ */