fbbc61c419cc909653c149ad7aaf92c2b707154a
[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 void
111 ao_logo(const struct ao_bitmap  *dst,
112         const struct ao_font    *font,
113         uint32_t                fill,
114         uint8_t                 rop);
115
116 extern const struct ao_font FrutigerLT_Roman_50_font;
117
118 #define AO_SHIFT        5
119 #define AO_UNIT         (1 << AO_SHIFT)
120 #define AO_MASK         (AO_UNIT - 1)
121 #define AO_ALLONES      ((uint32_t) -1)
122
123 /*
124  *          dst
125  *         0   1
126  *
127  *      0  a   b
128  *  src
129  *      1  c   d
130  *
131  *      ROP = abcd
132  */
133
134 #define AO_CLEAR         0x0    /* 0 */
135 #define AO_AND           0x1    /* src AND dst */
136 #define AO_AND_REVERSE   0x2    /* src AND NOT dst */
137 #define AO_COPY          0x3    /* src */
138 #define AO_AND_INVERTED  0x4    /* NOT src AND dst */
139 #define AO_NOOP          0x5    /* dst */
140 #define AO_XOR           0x6    /* src XOR dst */
141 #define AO_OR            0x7    /* src OR dst */
142 #define AO_NOR           0x8    /* NOT src AND NOT dst */
143 #define AO_EQUIV         0x9    /* NOT src XOR dst */
144 #define AO_INVERT        0xa    /* NOT dst */
145 #define AO_OR_REVERSE    0xb    /* src OR NOT dst */
146 #define AO_COPY_INVERTED 0xc    /* NOT src */
147 #define AO_OR_INVERTED   0xd    /* NOT src OR dst */
148 #define AO_NAND          0xe    /* NOT src OR NOT dst */
149 #define AO_SET           0xf    /* 1 */
150
151 #endif /* _AO_DRAW_H_ */