From eee4d0cf128d86aaac5c81c6ac404819770c49d0 Mon Sep 17 00:00:00 2001 From: Marijn van Vliet Date: Sun, 30 Jan 2011 16:36:30 +0100 Subject: [PATCH] Background color of windows now changes with garglk_set_reversevideo() --- libchimara/garglk.c | 34 +++++++++++++++++++------------- libchimara/style.c | 47 +++++++++++++++++++-------------------------- libchimara/style.h | 5 +++-- 3 files changed, 44 insertions(+), 42 deletions(-) diff --git a/libchimara/garglk.c b/libchimara/garglk.c index 4eb59a5..9e503b3 100644 --- a/libchimara/garglk.c +++ b/libchimara/garglk.c @@ -199,7 +199,7 @@ garglk_set_zcolors_stream(strid_t str, glui32 fg, glui32 bg) // Get the current foreground color GdkColor *current_color; g_object_get(window->zcolor, "foreground-gdk", ¤t_color, NULL); - fore_name = g_strdup_printf("%02X%02X%02X", current_color->red, current_color->green, current_color->blue); + fore_name = gdkcolor_to_hex(current_color); // Copy the color and use it fore.red = current_color->red; @@ -214,11 +214,7 @@ garglk_set_zcolors_stream(strid_t str, glui32 fg, glui32 bg) default: glkcolor_to_gdkcolor(fg, &fore); fore_pointer = &fore; - fore_name = g_strdup_printf("%02X%02X%02X", - ((fg & 0xff0000) >> 16), - ((fg & 0x00ff00) >> 8), - (fg & 0x0000ff) - ); + fore_name = glkcolor_to_hex(fg); } switch(bg) { @@ -235,7 +231,7 @@ garglk_set_zcolors_stream(strid_t str, glui32 fg, glui32 bg) // Get the current background color GdkColor *current_color; g_object_get(window->zcolor, "background-gdk", ¤t_color, NULL); - back_name = g_strdup_printf("%02X%02X%02X", current_color->red, current_color->green, current_color->blue); + back_name = gdkcolor_to_hex(current_color); // Copy the color and use it back.red = current_color->red; @@ -250,11 +246,7 @@ garglk_set_zcolors_stream(strid_t str, glui32 fg, glui32 bg) default: glkcolor_to_gdkcolor(bg, &back); back_pointer = &back; - back_name = g_strdup_printf("%02X%02X%02X", - ((bg & 0xff0000) >> 16), - ((bg & 0x00ff00) >> 8), - (bg & 0x0000ff) - ); + back_name = glkcolor_to_hex(bg); } if(fore_pointer == NULL && back_pointer == NULL) { @@ -283,6 +275,16 @@ garglk_set_zcolors_stream(strid_t str, glui32 fg, glui32 bg) // From now on, text will be drawn in the specified colors window->zcolor = tag; + + // Update the reversed version if necessary + if(str->window->zcolor_reversed) { + gint reversed = GPOINTER_TO_INT( g_object_get_data( G_OBJECT(str->window->zcolor_reversed), "reverse-color" ) ); + + gdk_threads_leave(); + garglk_set_reversevideo_stream(str, reversed != 0); + gdk_threads_enter(); + } + } gdk_threads_leave(); @@ -367,11 +369,17 @@ garglk_set_reversevideo_stream(strid_t str, glui32 reverse) "background-set", TRUE, NULL ); + g_object_set_data( G_OBJECT(tag), "reverse-color", GINT_TO_POINTER(reverse) ); } // From now on, text will be drawn in the specified colors str->window->zcolor_reversed = tag; - + + // Update the background of the gtktextview to correspond with the current background color + if(current_background != NULL) { + gtk_widget_modify_base(str->window->widget, GTK_STATE_NORMAL, current_background); + } + gdk_threads_leave(); } diff --git a/libchimara/style.c b/libchimara/style.c index 6cd3bd0..0df3bbd 100644 --- a/libchimara/style.c +++ b/libchimara/style.c @@ -13,7 +13,6 @@ extern GPrivate *glk_data_key; static gboolean style_accept(GScanner *scanner, GTokenType token); static gboolean style_accept_style_selector(GScanner *scanner, ChimaraGlk *glk); static gboolean style_accept_style_hint(GScanner *scanner, GtkTextTag *current_tag); -static void style_add_tag_to_textbuffer(gpointer key, gpointer tag, gpointer tag_table); static void style_copy_tag_to_textbuffer(gpointer key, gpointer tag, gpointer target_table); static void text_tag_to_attr_list(GtkTextTag *tag, PangoAttrList *list); GtkTextTag* gtk_text_tag_copy(GtkTextTag *tag); @@ -165,17 +164,6 @@ style_init_textgrid(GtkTextBuffer *buffer) g_hash_table_foreach(glk_data->glk_styles->text_grid, style_copy_tag_to_textbuffer, gtk_text_buffer_get_tag_table(buffer)); } -/* Internal function used to iterate over the default text tag table, applying them to a textbuffer */ -static void -style_add_tag_to_textbuffer(gpointer key, gpointer tag, gpointer tag_table) -{ - g_return_if_fail(key != NULL); - g_return_if_fail(tag != NULL); - g_return_if_fail(tag_table != NULL); - - gtk_text_tag_table_add(tag_table, tag); -} - /* Internal function used to iterate over a style table, copying it */ static void style_copy_tag_to_textbuffer(gpointer key, gpointer tag, gpointer target_table) @@ -400,21 +388,6 @@ reset_default_styles(ChimaraGlk *glk) /* TODO: write this function */ } -/* Copy the default styles to the current styles - FIXME: This function is temporary and will not be needed later on */ -void -copy_default_styles_to_current_styles(ChimaraGlk *glk) -{ - /* - CHIMARA_GLK_USE_PRIVATE(glk, priv); - g_hash_table_foreach(priv->styles->text_grid, style_table_copy, priv->glk_styles->text_grid); - g_hash_table_foreach(priv->styles->text_buffer, style_table_copy, priv->glk_styles->text_buffer); - - GtkTextTag *pager_tag = GTK_TEXT_TAG( g_hash_table_lookup(priv->styles->text_buffer, "pager") ); - text_tag_to_attr_list(pager_tag, priv->pager_attr_list); - */ -} - /* Create the CSS file scanner */ GScanner * create_css_file_scanner(void) @@ -672,6 +645,26 @@ glkcolor_to_gdkcolor(glui32 val, GdkColor *color) color->blue = 256 * (val & 0x0000ff); } +/* Internal function: parses a glk color to a hex string */ +gchar* +glkcolor_to_hex(glui32 val) +{ + return g_strdup_printf("%04X%04X%04X", + 256 * ((val & 0xff0000) >> 16), + 256 * ((val & 0x00ff00) >> 8), + 256 * (val & 0x0000ff) + ); +} + +/* Internal function: parses a gdk color to a hex string */ +gchar* +gdkcolor_to_hex(GdkColor *color) +{ + return g_strdup_printf("%04X%04X%04X", + color->red, color->green, color->blue + ); +} + /* Internal function: parses a GdkColor to a glk color */ static glui32 gdkcolor_to_glkcolor(GdkColor *color) diff --git a/libchimara/style.h b/libchimara/style.h index 0cfbbdd..6140473 100644 --- a/libchimara/style.h +++ b/libchimara/style.h @@ -14,12 +14,13 @@ G_GNUC_INTERNAL void style_init(ChimaraGlk *glk); G_GNUC_INTERNAL void style_update(ChimaraGlk *glk); G_GNUC_INTERNAL const gchar** style_get_tag_names(); G_GNUC_INTERNAL void reset_default_styles(ChimaraGlk *glk); -/*G_GNUC_INTERNAL void copy_default_styles_to_current_styles(ChimaraGlk *glk);*/ G_GNUC_INTERNAL GScanner *create_css_file_scanner(void); G_GNUC_INTERNAL void scan_css_file(GScanner *scanner, ChimaraGlk *glk); G_GNUC_INTERNAL PangoFontDescription *get_current_font(guint32 wintype); G_GNUC_INTERNAL GtkTextTag* gtk_text_tag_copy(GtkTextTag *tag); G_GNUC_INTERNAL void glkcolor_to_gdkcolor(glui32 val, GdkColor *color); +G_GNUC_INTERNAL gchar* glkcolor_to_hex(glui32 val); +G_GNUC_INTERNAL gchar* gdkcolor_to_hex(GdkColor *color); G_GNUC_INTERNAL void style_stream_colors(strid_t str, GdkColor **foreground, GdkColor **background); typedef struct StyleSet { @@ -29,7 +30,7 @@ typedef struct StyleSet { #define CHIMARA_NUM_STYLES 13 -// #define DEBUG_STYLES +//#define DEBUG_STYLES #define ACTUAL_FG(tag) \ (GPOINTER_TO_INT( g_object_get_data(G_OBJECT((tag)), "reverse-color")) ? "background-gdk":"foreground-gdk") -- 2.30.2