aboutsummaryrefslogtreecommitdiff
path: root/draw.c
blob: 0eac18a76f3bd1bdb4ee62ae5f0c268e32a90453 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <math.h>
#include <cairo.h>

#include "x11.h"
#include "log.h"

#define EVEN(n) ((int)(n) - ((int)(n) % 2 != 0))

void draw(Window *win)
{
    double scale = window_get_scale(win);

    int screen_width, screen_height;
    window_get_screen_size(win, &screen_width, &screen_height);

    int width  = EVEN(round(screen_width  * 0.9875 * scale));
    int height = EVEN(round(screen_height * 0.0225 * scale));

    cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);

    cairo_t *cr = cairo_create(surface);
    cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD);
    cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);

    int radius = height / 2;
    double degree = M_PI / 180.0;

    cairo_set_source_rgb(cr, 0.3, 0.3, 0.3);
    cairo_arc(cr, radius, radius, radius, 90.0 * degree, 270 * degree);
    cairo_arc(cr, width - radius, radius, radius, 270 * degree, 450 * degree);
    cairo_fill(cr);

    cairo_set_line_width(cr, 1 * scale);

    for (int i = 0; i < 9; i++) {

        int x = (height + cairo_get_line_width(cr) * scale * 2) * i;

        // purple
        cairo_set_source_rgb(cr, 0.502, 0.168, 0.886);
        cairo_arc(cr, x + radius, radius, radius, 0 * degree, 360 * degree);
        cairo_fill(cr);

        cairo_set_source_rgb(cr, 0.8, 0.8, 0.8);
        cairo_arc(cr, x + radius, radius, radius - 1, 0 * degree, 360 * degree);
        cairo_stroke(cr);

        cairo_select_font_face(cr, "Hack", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
        cairo_set_source_rgb(cr, 1, 1, 1);
        cairo_set_font_size(cr, 20.0);

        char btn[] = { '1' + i, '\0' };

        cairo_text_extents_t te;
        cairo_text_extents(cr, btn, &te);

        cairo_move_to(cr, x + (height / 2) - te.x_bearing - te.width / 2,
                          (height / 2) - te.y_bearing - te.height / 2);
        cairo_show_text(cr, btn);
    }

    cairo_destroy(cr);

    int x = EVEN((screen_width - width) / 2.0);
    int y = EVEN(screen_height * 0.005);

    // TODO: Move these somewhere else
    window_move(win, x, y);
    window_resize(win, width, height);

    window_paint_surface(win, surface, width, height);
    cairo_surface_destroy(surface);
}

// vim: ts=4 sw=4 et