#include "stream.h"
#include "fileref.h"
#include "style.h"
+#include "garglk.h"
extern GPrivate *glk_data_key;
garglk_set_zcolors_stream(strid_t str, glui32 fg, glui32 bg)
{
VALID_STREAM(str, return);
- WARNING(_("Not implemented"));
+ g_return_if_fail(str->window != NULL);
+
+ if (fg == zcolor_Transparent && fg == zcolor_Cursor) {
+ WARNING(_("zcolor_Transparent and zcolor_Cursor not implemented"));
+ return;
+ }
+
+ winid_t window = str->window;
+
+ GtkTextBuffer *buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(window->widget) );
+ GtkTextTagTable *tags = gtk_text_buffer_get_tag_table(buffer);
+ GdkColor fore, back;
+ glkcolor_to_gdkcolor(fg, &fore);
+ glkcolor_to_gdkcolor(bg, &back);
+
+ char *name = g_strdup_printf("zcolor:#%02X%02X%02X/#%02X%02X%02x",
+ ((fg & 0xff0000) >> 16),
+ ((fg & 0x00ff00) >> 8),
+ (fg & 0x0000ff),
+ ((bg & 0xff0000) >> 16),
+ ((bg & 0x00ff00) >> 8),
+ (bg & 0x0000ff)
+ );
+
+ if(fg == zcolor_Default) {
+ window->zcolor = NULL;
+ } else {
+ GtkTextTag *tag = gtk_text_tag_table_lookup(tags, name);
+ if(tag == NULL) {
+ tag = gtk_text_buffer_create_tag(
+ buffer,
+ name,
+ "foreground-gdk", &fore,
+ "foreground-set", TRUE,
+ "background-gdk", &back,
+ "background-set", TRUE,
+ NULL
+ );
+ }
+
+ window->zcolor = tag;
+ }
}
/**
{
ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
g_return_if_fail(glk_data->current_stream != NULL);
- g_return_if_fail(glk_data->current_stream->window != NULL);
-
- winid_t window = glk_data->current_stream->window;
- GtkTextBuffer *buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(window->widget) );
- //GtkTextTagTable *tags = gtk_text_buffer_get_tag_table(buffer);
- GdkColor fore, back;
- glkcolor_to_gdkcolor(fg, &fore);
- glkcolor_to_gdkcolor(bg, &back);
-
- gchar *id = g_strdup_printf("%d", ++window->last_zcolor_id);
- printf("id = %s\nfg = %08X\nbg = %08X\n\n", id, fg, bg);
-
- GtkTextTag *tag = gtk_text_buffer_create_tag(
- buffer,
- g_strdup_printf("%d", ++window->last_zcolor_id),
- "foreground-gdk", &fore,
- "foreground-set", TRUE,
- "background-gdk", &back,
- "background-set", TRUE,
- NULL
- );
- window->zcolor = tag;
+ garglk_set_zcolors_stream(glk_data->current_stream, fg, bg);
}
static void
case wintype_TextBuffer:
{
GtkTextIter start, end;
- gtk_text_buffer_get_end_iter(buffer, &start);
+ gtk_text_buffer_get_end_iter(buffer, &end);
+ gint start_offset;
GtkTextTagTable *tags = gtk_text_buffer_get_tag_table(buffer);
GtkTextTag *style_tag = gtk_text_tag_table_lookup(tags, win->window_stream->style);
GtkTextTag *glk_style_tag = gtk_text_tag_table_lookup(tags, win->window_stream->glk_style);
- gtk_text_buffer_insert(buffer, &start, win->buffer->str, -1);
- gtk_text_buffer_get_end_iter(buffer, &end);
+ start_offset = gtk_text_iter_get_offset(&end);
+ gtk_text_buffer_insert(buffer, &end, win->buffer->str, -1);
+ gtk_text_buffer_get_iter_at_offset(buffer, &start, start_offset);
// Default style
gtk_text_buffer_apply_tag(buffer, default_tag, &start, &end);
GtkTextMark *cursor = gtk_text_buffer_get_mark(buffer, "cursor_position");
/* Get cursor position */
- GtkTextIter start;
- gtk_text_buffer_get_iter_at_mark(buffer, &start, cursor);
+ GtkTextIter start, insert;
+ gint start_offset;
+
+ gtk_text_buffer_get_iter_at_mark(buffer, &insert, cursor);
/* Spaces available on this line */
- gint available_space = win->width - gtk_text_iter_get_line_offset(&start);
+ gint available_space = win->width - gtk_text_iter_get_line_offset(&insert);
GtkTextTagTable *tags = gtk_text_buffer_get_tag_table(buffer);
GtkTextTag *default_tag = gtk_text_tag_table_lookup(tags, "default");
{
GtkTextIter end = start;
gtk_text_iter_forward_to_line_end(&end);
- gtk_text_buffer_delete(buffer, &start, &end);
+ gtk_text_buffer_delete(buffer, &insert, &end);
- gtk_text_buffer_insert(buffer, &start, win->buffer->str + (length - chars_left), available_space);
+ start_offset = gtk_text_iter_get_offset(&insert);
+ gtk_text_buffer_insert(buffer, &insert, win->buffer->str + (length - chars_left), available_space);
+ gtk_text_buffer_get_iter_at_offset(buffer, &start, start_offset);
// Default style
- gtk_text_buffer_apply_tag(buffer, default_tag, &start, &end);
+ gtk_text_buffer_apply_tag(buffer, default_tag, &start, &insert);
// Player's style overrides
- gtk_text_buffer_apply_tag(buffer, style_tag, &start, &end);
+ gtk_text_buffer_apply_tag(buffer, style_tag, &start, &insert);
// GLK Program's style overrides
- gtk_text_buffer_apply_tag(buffer, glk_style_tag, &start, &end);
+ gtk_text_buffer_apply_tag(buffer, glk_style_tag, &start, &insert);
// Link style overrides
if(win->window_stream->hyperlink_mode) {
GtkTextTag *link_tag = win->current_hyperlink->tag;
- gtk_text_buffer_apply_tag(buffer, link_style_tag, &start, &end);
- gtk_text_buffer_apply_tag(buffer, link_tag, &start, &end);
+ gtk_text_buffer_apply_tag(buffer, link_style_tag, &start, &insert);
+ gtk_text_buffer_apply_tag(buffer, link_tag, &start, &insert);
}
// GLK Program's style overrides using garglk_set_zcolors()
+ /*
if(win->zcolor != NULL)
- gtk_text_buffer_apply_tag(buffer, win->zcolor, &start, &end);
+ gtk_text_buffer_apply_tag(buffer, win->zcolor, &start, &insert);
+ */
+
chars_left -= available_space;
- gtk_text_iter_forward_line(&start);
+ gtk_text_iter_forward_line(&insert);
available_space = win->width;
}
- if(!gtk_text_iter_is_end(&start))
+ if(!gtk_text_iter_is_end(&insert))
{
- GtkTextIter end = start;
+ GtkTextIter end = insert;
gtk_text_iter_forward_chars(&end, chars_left);
- gtk_text_buffer_delete(buffer, &start, &end);
+ gtk_text_buffer_delete(buffer, &insert, &end);
+
+ start_offset = gtk_text_iter_get_offset(&insert);
+ gtk_text_buffer_insert(buffer, &insert, win->buffer->str + (length - chars_left), -1);
+ gtk_text_buffer_get_iter_at_offset(buffer, &start, start_offset);
- GtkTextTagTable *tags = gtk_text_buffer_get_tag_table(buffer);
- GtkTextTag *default_tag = gtk_text_tag_table_lookup(tags, "default");
- GtkTextTag *style_tag = gtk_text_tag_table_lookup(tags, win->window_stream->style);
- GtkTextTag *glk_style_tag = gtk_text_tag_table_lookup(tags, win->window_stream->glk_style);
+ // Default style
+ gtk_text_buffer_apply_tag(buffer, default_tag, &start, &insert);
+ // Player's style overrides
+ gtk_text_buffer_apply_tag(buffer, style_tag, &start, &insert);
+
+ // GLK Program's style overrides
+ gtk_text_buffer_apply_tag(buffer, glk_style_tag, &start, &insert);
+
+ // Link style overrides
if(win->window_stream->hyperlink_mode) {
- GtkTextTag *link_style_tag = gtk_text_tag_table_lookup(tags, "hyperlink");
GtkTextTag *link_tag = win->current_hyperlink->tag;
- gtk_text_buffer_insert_with_tags(buffer, &start, win->buffer->str + (length - chars_left), -1, default_tag, style_tag, glk_style_tag, link_style_tag, link_tag, NULL);
- } else {
- gtk_text_buffer_insert_with_tags(buffer, &start, win->buffer->str + (length - chars_left), -1, default_tag, style_tag, glk_style_tag, NULL);
+ gtk_text_buffer_apply_tag(buffer, link_style_tag, &start, &insert);
+ gtk_text_buffer_apply_tag(buffer, link_tag, &start, &insert);
}
+
+ // GLK Program's style overrides using garglk_set_zcolors()
+ /*
+ if(win->zcolor != NULL)
+ gtk_text_buffer_apply_tag(buffer, win->zcolor, &start, &insert);
+ */
}
gtk_text_buffer_move_mark(buffer, cursor, &start);
return TRUE;
}
-/* Internal function: parses a glk color to a #hex-value */
-static void
-glkcolor_to_hex(glui32 val, gchar *buffer)
-{
- g_return_if_fail(buffer != NULL);
-
- sprintf(buffer, "#%02X%02X%02X",
- ((val & 0xff0000) >> 16),
- ((val & 0x00ff00) >> 8),
- (val & 0x0000ff)
- );
-}
-
/* Internal function: parses a glk color to a GdkColor */
void
glkcolor_to_gdkcolor(glui32 val, GdkColor *color)
gint reverse_color = GPOINTER_TO_INT( g_object_get_data(tag_object, "reverse-color") );
int i = 0;
- gchar color[20];
+ GdkColor color;
switch(hint) {
case stylehint_Indentation:
g_object_set(tag_object, "left-margin", 5*val, "left-margin-set", TRUE, NULL);
break;
case stylehint_TextColor:
- glkcolor_to_hex(val, color);
+ glkcolor_to_gdkcolor(val, &color);
if(!reverse_color)
- g_object_set(tag_object, "foreground", color, "foreground-set", TRUE, NULL);
+ g_object_set(tag_object, "foreground", &color, "foreground-set", TRUE, NULL);
else
- g_object_set(tag_object, "background", color, "background-set", TRUE, NULL);
+ g_object_set(tag_object, "background", &color, "background-set", TRUE, NULL);
break;
case stylehint_BackColor:
- glkcolor_to_hex(val, color);
+ glkcolor_to_gdkcolor(val, &color);
if(!reverse_color)
- g_object_set(tag_object, "background", color, "background-set", TRUE, NULL);
+ g_object_set(tag_object, "background", &color, "background-set", TRUE, NULL);
else
- g_object_set(tag_object, "foreground", color, "background-set", TRUE, NULL);
+ g_object_set(tag_object, "foreground", &color, "background-set", TRUE, NULL);
break;