From 4e817452368c0ca9edb0784fef8d7155c634652f Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Wed, 12 Apr 2017 13:09:44 +0200 Subject: info rendering --- drmtest.c | 6 +++--- gtktest.c | 2 +- render.c | 40 ++++++++++++++++++++++++++-------------- render.h | 3 ++- 4 files changed, 32 insertions(+), 19 deletions(-) diff --git a/drmtest.c b/drmtest.c index 7fd080e..76dc2b1 100644 --- a/drmtest.c +++ b/drmtest.c @@ -172,10 +172,10 @@ static void drm_draw(const char *text) cairo_t *cr; drm_conn_name(conn, name, sizeof(name)); - snprintf(info, sizeof(info), "%s: %dx%d, %s", - name, mode->hdisplay, mode->vdisplay, text); + snprintf(info, sizeof(info), "drmtest: %dx%d at %s", + mode->hdisplay, mode->vdisplay, name); cr = cairo_create(cs); - render_test(cr, mode->hdisplay, mode->vdisplay, info); + render_test(cr, mode->hdisplay, mode->vdisplay, info, text); cairo_destroy(cr); } diff --git a/gtktest.c b/gtktest.c index 8deb52b..43cb2dc 100644 --- a/gtktest.c +++ b/gtktest.c @@ -13,7 +13,7 @@ static gboolean on_draw_event(GtkWidget *widget, cairo_t *cr, height = gtk_widget_get_allocated_height(widget); snprintf(info, sizeof(info), "gtktest: %dx%d", width, height); - render_test(cr, width, height, info); + render_test(cr, width, height, info, NULL); return FALSE; } diff --git a/render.c b/render.c index af40688..9558d9e 100644 --- a/render.c +++ b/render.c @@ -1,3 +1,4 @@ +#include #include #include "render.h" @@ -5,7 +6,8 @@ static int pad = 15; static void render_color_bar(cairo_t *cr, int x, int y, int w, int h, - double r, double g, double b, const char *name) + double r, double g, double b, + const char *l1, const char *l2) { cairo_font_extents_t ext; cairo_pattern_t *gr; @@ -18,17 +20,27 @@ static void render_color_bar(cairo_t *cr, int x, int y, int w, int h, cairo_fill (cr); cairo_pattern_destroy(gr); - cairo_set_source_rgb(cr, r, g, b); cairo_select_font_face(cr, "mono", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); - cairo_set_font_size(cr, h - 2*pad); - cairo_font_extents (cr, &ext); - cairo_move_to(cr, x + pad, y + pad + ext.ascent); - cairo_show_text(cr, name); + if (l2) { + cairo_set_source_rgb(cr, 1, 1, 1); + cairo_set_font_size(cr, h/2 - pad); + cairo_font_extents (cr, &ext); + cairo_move_to(cr, x + pad, y + pad + ext.ascent); + cairo_show_text(cr, l1); + cairo_move_to(cr, x + pad, y + pad + ext.ascent + ext.height); + cairo_show_text(cr, l2); + } else { + cairo_set_source_rgb(cr, r, g, b); + cairo_set_font_size(cr, h - 2*pad); + cairo_font_extents (cr, &ext); + cairo_move_to(cr, x + pad, y + pad + ext.ascent); + cairo_show_text(cr, l1); + } } -void render_test(cairo_t *cr, int width, int height, const char *info) +void render_test(cairo_t *cr, int width, int height, const char *l1, const char *l2) { int bar = 120; @@ -46,13 +58,13 @@ void render_test(cairo_t *cr, int width, int height, const char *info) cairo_stroke (cr); render_color_bar(cr, pad, bar * 0 + pad, width - 2*pad, bar, - 0.8, 0.8, 0.8, info); - render_color_bar(cr, pad, bar * 1 + pad, width - 2*pad, bar, 1, 0, 0, "red"); - render_color_bar(cr, pad, bar * 2 + pad, width - 2*pad, bar, 1, 1, 0, "yellow"); - render_color_bar(cr, pad, bar * 3 + pad, width - 2*pad, bar, 0, 1, 0, "green"); - render_color_bar(cr, pad, bar * 4 + pad, width - 2*pad, bar, 0, 1, 1, "cyan"); - render_color_bar(cr, pad, bar * 5 + pad, width - 2*pad, bar, 0, 0, 1, "blue"); - render_color_bar(cr, pad, bar * 6 + pad, width - 2*pad, bar, 1, 0, 1, "magenta"); + 0.6, 0.6, 0.6, l1, l2); + render_color_bar(cr, pad, bar * 1 + pad, width - 2*pad, bar, 1, 0, 0, "red", NULL); + render_color_bar(cr, pad, bar * 2 + pad, width - 2*pad, bar, 1, 1, 0, "yellow", NULL); + render_color_bar(cr, pad, bar * 3 + pad, width - 2*pad, bar, 0, 1, 0, "green", NULL); + render_color_bar(cr, pad, bar * 4 + pad, width - 2*pad, bar, 0, 1, 1, "cyan", NULL); + render_color_bar(cr, pad, bar * 5 + pad, width - 2*pad, bar, 0, 0, 1, "blue", NULL); + render_color_bar(cr, pad, bar * 6 + pad, width - 2*pad, bar, 1, 0, 1, "magenta", NULL); } diff --git a/render.h b/render.h index d6aa9ba..2a15568 100644 --- a/render.h +++ b/render.h @@ -1 +1,2 @@ -void render_test(cairo_t *cr, int width, int height, const char *info); +void render_test(cairo_t *cr, int width, int height, + const char *l1, const char *l2); -- cgit