diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2017-04-12 13:09:44 +0200 |
---|---|---|
committer | Gerd Hoffmann <kraxel@redhat.com> | 2017-04-12 13:09:44 +0200 |
commit | 4e817452368c0ca9edb0784fef8d7155c634652f (patch) | |
tree | fbce6622180ceef6d0720612a849c904ecd270f3 | |
parent | 4b29807b655e59715d0ca3256484271df63a90f9 (diff) | |
download | drminfo-4e817452368c0ca9edb0784fef8d7155c634652f.tar.gz |
info rendering
-rw-r--r-- | drmtest.c | 6 | ||||
-rw-r--r-- | gtktest.c | 2 | ||||
-rw-r--r-- | render.c | 40 | ||||
-rw-r--r-- | render.h | 3 |
4 files changed, 32 insertions, 19 deletions
@@ -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); } @@ -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; } @@ -1,3 +1,4 @@ +#include <stddef.h> #include <cairo.h> #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); } @@ -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); |