// 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;
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) {
// 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;
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) {
// 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();
"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();
}
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);
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)
/* 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)
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)
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 {
#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")