aboutsummaryrefslogtreecommitdiff
path: root/src/comet.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/comet.c')
-rw-r--r--src/comet.c113
1 files changed, 112 insertions, 1 deletions
diff --git a/src/comet.c b/src/comet.c
index 72bc3b5..d496590 100644
--- a/src/comet.c
+++ b/src/comet.c
@@ -1,11 +1,36 @@
#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, "");
@@ -20,7 +45,93 @@ int main(int argc, char **argv)
window_move(&window, 100, 100);
window_resize(&window, 1000, 1000);
- while (true);
+ 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);