aboutsummaryrefslogtreecommitdiff
path: root/src/comet.c
blob: d4965901a62af4fad6d4a78882b34db9058b0036 (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include <stdlib.h>
#include <locale.h>
#include <unistd.h>

#include "window.h"
#include "layout.h"

#define ANY_LOG_IMPLEMENT
#include "any_log.h"

cairo_surface_t *render(layout_t *layout, layout_info_t info)
{
    cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, info.width, info.height);
    log_value_trace("Created cairo surface",
                    "i:width", info.width,
                    "i:height", info.height);

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

    color_t color = layout->block->color;
    cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a);
    cairo_paint(cr);

    layout_render(layout, cr);
    log_trace("Rendered layouts");

    cairo_destroy(cr);
    return surface;
}


int main(int argc, char **argv)
{
    setlocale(LC_CTYPE, "");
    any_log_init(stdout, ANY_LOG_DEBUG);

    display_t display;
    display_init(&display);

    window_t window;
    window_init(&window, &display);

    window_move(&window, 100, 100);
    window_resize(&window, 1000, 1000);

    block_t blocks[2] = {
        {
            .hidden = false,
            .color = { 0.2, 0.2, 0.2, 1 },
            .line_color = { 0 },
            .line_width = 0,
            .x_padding = 0,
            .y_padding = 0,
            .min_width = 0,
            .max_width = 0,
            .update_interval = 0,
            .update_last = { 0 },
            .update_cb = NULL,
            .event_cb = NULL,
            .type = BLOCK_TEXT,
            .text = {
                .text = "A",
                .text_color = { 0.8, 0.9, 0.3, 1 },
            },
        },
        {
            .hidden = false,
            .color = { 0.2, 0.2, 0.8, 1 },
            .line_color = { 0 },
            .line_width = 0,
            .x_padding = 0,
            .y_padding = 0,
            .min_width = 0,
            .max_width = 0,
            .update_interval = 0,
            .update_last = { 0 },
            .update_cb = NULL,
            .event_cb = NULL,
            .type = BLOCK_TEXT,
            .text = {
                .text = "B",
                .text_color = { 0.8, 0.9, 0.2, 1 },
            },
        },
    };

    block_t top = {
        .hidden = false,
        .color = { 0.3, 0.2, 0.5, 1 },
        .line_color = { 0 },
        .line_width = 0,
        .x_padding = 0,
        .y_padding = 0,
        .min_width = 0,
        .max_width = 0,
        .update_interval = 0,
        .update_last = { 0 },
        .update_cb = NULL,
        .event_cb = NULL,
        .type = BLOCK_GROUP,
        .group = {
            .spacing = 10,
            .n_children = 2,
            .children = blocks,
        },
    };

    int width = 1200;
    int height = 200;
    int x_padding = 20;
    int y_padding = 40;

    layout_info_t info = {
        .fontdesc = pango_font_description_from_string("Hack 13"),
        .context = pango_cairo_create_context(window.cr),
        .x_offset = 0,
        .height = height,
        .width = width,
    };

    window_resize(&window, width, height);
    window_move(&window, x_padding, y_padding);

    while (true) {
        layout_t *layout = layout_create(&top, info);
        cairo_surface_t *surface = render(layout, info);
        window_present(&window, surface, width, height);
        cairo_surface_destroy(surface);
        layout_free(layout);

        sleep(1);
    }

    window_close(&window);
    display_close(&display);

    return 0;
}