altos: Fill in more of the draw code
[fw/altos] / src / draw / draw-test.c
1 /*
2  * Copyright © 2023 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  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 #define WIDTH   128
20 #define HEIGHT  64
21
22 #define DEFAULT_WIDTH   WIDTH
23 #define DEFAULT_HEIGHT  HEIGHT
24
25 #include "frame.c"
26 #include "ao_draw.h"
27
28 #define STRIDE  ((WIDTH + 31) / 32)
29
30 static uint32_t bits[STRIDE * HEIGHT];
31
32 static struct ao_bitmap fb = {
33         .base = bits,
34         .stride = STRIDE,
35         .width = WIDTH,
36         .height = HEIGHT
37 };
38
39 #define BIG_FONT FrutigerLT_Roman_64_font
40 #define SMALL_FONT FrutigerLT_Roman_12_font
41
42 #define VALUE_Y         BIG_FONT.ascent
43 #define LABEL_Y         BIG_FONT.ascent + SMALL_FONT.ascent + 2
44 #define BOX_X           2
45 #define PAD_X           90
46 #define BOX_LABEL_X     30
47 #define PAD_LABEL_X     95
48 #define SEP_X           (PAD_X - 8)
49
50 void HandleExpose(Display *dpy, Window win, GC gc)
51 {
52         ao_rect(&fb, 0, 0, WIDTH, HEIGHT, 0xffffffff, AO_COPY);
53
54         ao_text(&fb, &BIG_FONT, BOX_X, VALUE_Y, "32", 0x00000000, AO_COPY);
55         ao_text(&fb, &SMALL_FONT, BOX_LABEL_X, LABEL_Y, "box", 0x00000000, AO_COPY);
56
57         ao_text(&fb, &BIG_FONT, PAD_X, VALUE_Y, "2", 0x00000000, AO_COPY);
58         ao_text(&fb, &SMALL_FONT, PAD_LABEL_X, LABEL_Y, "pad", 0x00000000, AO_COPY);
59
60         ao_line(&fb, SEP_X, 0, SEP_X, HEIGHT, 0x00000000, AO_COPY);
61
62         XImage *image = XCreateImage(dpy, visual, 1, XYBitmap, 0, (char *) bits, WIDTH, HEIGHT, 32, STRIDE*4);
63         XSetForeground(dpy, gc, WhitePixel(dpy, screen));
64         XSetBackground(dpy, gc, BlackPixel(dpy, screen));
65         XPutImage(dpy, win, gc, image, 0, 0, 0, 0, WIDTH, HEIGHT);
66         free(image);
67 }