From 39ff5573f152b98755bbafcdc3e015ff015ca61d Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Fri, 25 Apr 2014 05:02:43 -0400 Subject: implement rgb colors --- src/display.c | 27 ++++++++++++++++++++------- src/screen.c | 28 ++++++++++++++++------------ src/screen.h | 6 ++++-- 3 files changed, 40 insertions(+), 21 deletions(-) diff --git a/src/display.c b/src/display.c index 4686d26..dff5173 100644 --- a/src/display.c +++ b/src/display.c @@ -152,6 +152,7 @@ static void runes_display_draw_cell(RunesTerm *t, int row, int col) { struct runes_cell *cell = &t->scr.rows[row].cells[col]; cairo_pattern_t *bg = NULL, *fg = NULL; + int bg_is_custom = 0, fg_is_custom = 0; switch (cell->attrs.bgcolor.type) { case RUNES_COLOR_DEFAULT: @@ -161,8 +162,11 @@ static void runes_display_draw_cell(RunesTerm *t, int row, int col) bg = t->colors[cell->attrs.bgcolor.idx]; break; case RUNES_COLOR_RGB: - /* XXX */ - fprintf(stderr, "rgb colors nyi\n"); + bg = cairo_pattern_create_rgb( + cell->attrs.bgcolor.r / 255.0, + cell->attrs.bgcolor.g / 255.0, + cell->attrs.bgcolor.b / 255.0); + bg_is_custom = 1; break; } @@ -180,8 +184,11 @@ static void runes_display_draw_cell(RunesTerm *t, int row, int col) break; } case RUNES_COLOR_RGB: - /* XXX */ - fprintf(stderr, "rgb colors nyi\n"); + fg = cairo_pattern_create_rgb( + cell->attrs.fgcolor.r / 255.0, + cell->attrs.fgcolor.g / 255.0, + cell->attrs.fgcolor.b / 255.0); + fg_is_custom = 1; break; } @@ -197,14 +204,20 @@ static void runes_display_draw_cell(RunesTerm *t, int row, int col) } } - if (bg) { - runes_display_paint_rectangle(t, t->cr, bg, row, col, 1, 1); - } + runes_display_paint_rectangle(t, t->cr, bg, row, col, 1, 1); if (cell->len) { runes_display_draw_glyph( t, t->cr, fg, cell->attrs, cell->contents, cell->len, row, col); } + + if (bg_is_custom) { + cairo_pattern_destroy(bg); + } + + if (fg_is_custom) { + cairo_pattern_destroy(fg); + } } static void runes_display_paint_rectangle( diff --git a/src/screen.c b/src/screen.c index 0f62667..0c8ced5 100644 --- a/src/screen.c +++ b/src/screen.c @@ -251,13 +251,15 @@ void runes_screen_set_fg_color(RunesTerm *t, int idx) scr->attrs.fgcolor.idx = idx; } -void runes_screen_set_fg_color_rgb(RunesTerm *t, int r, int g, int b) +void runes_screen_set_fg_color_rgb( + RunesTerm *t, unsigned char r, unsigned char g, unsigned char b) { - UNUSED(t); - UNUSED(r); - UNUSED(g); - UNUSED(b); - fprintf(stderr, "set_fg_color_rgb nyi\n"); + RunesScreen *scr = &t->scr; + + scr->attrs.fgcolor.type = RUNES_COLOR_RGB; + scr->attrs.fgcolor.r = r; + scr->attrs.fgcolor.g = g; + scr->attrs.fgcolor.b = b; } void runes_screen_reset_fg_color(RunesTerm *t) @@ -275,13 +277,15 @@ void runes_screen_set_bg_color(RunesTerm *t, int idx) scr->attrs.bgcolor.idx = idx; } -void runes_screen_set_bg_color_rgb(RunesTerm *t, int r, int g, int b) +void runes_screen_set_bg_color_rgb( + RunesTerm *t, unsigned char r, unsigned char g, unsigned char b) { - UNUSED(t); - UNUSED(r); - UNUSED(g); - UNUSED(b); - fprintf(stderr, "set_bg_color_rgb nyi\n"); + RunesScreen *scr = &t->scr; + + scr->attrs.bgcolor.type = RUNES_COLOR_RGB; + scr->attrs.bgcolor.r = r; + scr->attrs.bgcolor.g = g; + scr->attrs.bgcolor.b = b; } void runes_screen_reset_bg_color(RunesTerm *t) diff --git a/src/screen.h b/src/screen.h index 4fd9e83..73b9360 100644 --- a/src/screen.h +++ b/src/screen.h @@ -107,10 +107,12 @@ void runes_screen_set_scroll_region( RunesTerm *t, int top, int bottom, int left, int right); void runes_screen_reset_text_attributes(RunesTerm *t); void runes_screen_set_fg_color(RunesTerm *t, int idx); -void runes_screen_set_fg_color_rgb(RunesTerm *t, int r, int g, int b); +void runes_screen_set_fg_color_rgb( + RunesTerm *t, unsigned char r, unsigned char g, unsigned char b); void runes_screen_reset_fg_color(RunesTerm *t); void runes_screen_set_bg_color(RunesTerm *t, int idx); -void runes_screen_set_bg_color_rgb(RunesTerm *t, int r, int g, int b); +void runes_screen_set_bg_color_rgb( + RunesTerm *t, unsigned char r, unsigned char g, unsigned char b); void runes_screen_reset_bg_color(RunesTerm *t); void runes_screen_set_bold(RunesTerm *t); void runes_screen_set_italic(RunesTerm *t); -- cgit v1.2.3