Began garglk_set_zcolors() implementation
authorMarijn van Vliet <w.m.vanvliet@student.utwente.nl>
Sat, 29 Jan 2011 16:02:04 +0000 (17:02 +0100)
committerMarijn van Vliet <w.m.vanvliet@student.utwente.nl>
Sat, 29 Jan 2011 16:02:04 +0000 (17:02 +0100)
libchimara/garglk.c
libchimara/strio.c
libchimara/style.c
libchimara/window.h

index df5c6b35e4f0240289fa1c2bd983b3418ce51b0f..eba89a8ab19f024a419a6bf29ddb71f0cbfe806f 100644 (file)
@@ -3,6 +3,7 @@
 #include "chimara-glk-private.h"
 #include "stream.h"
 #include "fileref.h"
+#include "style.h"
 
 extern GPrivate *glk_data_key;
 
@@ -177,8 +178,28 @@ garglk_set_zcolors(glui32 fg, glui32 bg)
        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);
        
-       WARNING(_("Not implemented"));
+       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;
 }
 
 static void
index b1df8ae570a712d7bf111f05115abdff1b549a60..6d54e825c50bcbd1ccf6c7fb9361a1495c6af7c8 100644 (file)
@@ -44,22 +44,39 @@ flush_window_buffer(winid_t win)
        switch(win->type) {
        case wintype_TextBuffer:
        {
-               GtkTextIter iter;
-               gtk_text_buffer_get_end_iter(buffer, &iter);
+               GtkTextIter start, end;
+               gtk_text_buffer_get_end_iter(buffer, &start);
 
                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);
 
+               gtk_text_buffer_insert(buffer, &start, win->buffer->str, -1);
+               gtk_text_buffer_get_end_iter(buffer, &end);
+
+               // Default style
+               gtk_text_buffer_apply_tag(buffer, default_tag, &start, &end);
+
+               // Player's style overrides
+               gtk_text_buffer_apply_tag(buffer, style_tag, &start, &end);
+
+               // GLK Program's style overrides
+               gtk_text_buffer_apply_tag(buffer, glk_style_tag, &start, &end);
+
+               // 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, &iter, win->buffer->str, -1, default_tag, style_tag, glk_style_tag, link_style_tag, link_tag, NULL);
-               } else {
-                       gtk_text_buffer_insert_with_tags(buffer, &iter, win->buffer->str, -1, default_tag, style_tag, glk_style_tag, NULL);
+                       gtk_text_buffer_apply_tag(buffer, link_style_tag, &start, &end);
+                       gtk_text_buffer_apply_tag(buffer, link_tag, &start, &end);
                }
 
+               // GLK Program's style overrides using garglk_set_zcolors()
+               if(win->zcolor != NULL)
+                       gtk_text_buffer_apply_tag(buffer, win->zcolor, &start, &end);
+
                ChimaraGlk *glk = CHIMARA_GLK(gtk_widget_get_ancestor(win->widget, CHIMARA_TYPE_GLK));
                g_assert(glk);
                g_signal_emit_by_name(glk, "text-buffer-output", win->rock, win->buffer->str);
@@ -80,25 +97,40 @@ flush_window_buffer(winid_t win)
                /* Spaces available on this line */
                gint available_space = win->width - gtk_text_iter_get_line_offset(&start);
                
+               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);
+               GtkTextTag *link_style_tag = gtk_text_tag_table_lookup(tags, "hyperlink");
+
                while(chars_left > available_space && !gtk_text_iter_is_end(&start))
                {
                        GtkTextIter end = start;
                        gtk_text_iter_forward_to_line_end(&end);
                        gtk_text_buffer_delete(buffer, &start, &end);
 
-                       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);
+                       gtk_text_buffer_insert(buffer, &start, win->buffer->str + (length - chars_left), available_space);
+
+                       // Default style
+                       gtk_text_buffer_apply_tag(buffer, default_tag, &start, &end);
 
+                       // Player's style overrides
+                       gtk_text_buffer_apply_tag(buffer, style_tag, &start, &end);
+
+                       // GLK Program's style overrides
+                       gtk_text_buffer_apply_tag(buffer, glk_style_tag, &start, &end);
+
+                       // 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), available_space, 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), available_space, default_tag, style_tag, glk_style_tag, NULL);
+                               gtk_text_buffer_apply_tag(buffer, link_style_tag, &start, &end);
+                               gtk_text_buffer_apply_tag(buffer, link_tag, &start, &end);
                        }
 
+                       // GLK Program's style overrides using garglk_set_zcolors()
+                       if(win->zcolor != NULL)
+                               gtk_text_buffer_apply_tag(buffer, win->zcolor, &start, &end);
+
                        chars_left -= available_space;
                        gtk_text_iter_forward_line(&start);
                        available_space = win->width;
index e9bfd888d5bcdcd29de79b1a736035a114432a96..48883a94a0ba4d3e6d55c707a897f5181b308b19 100644 (file)
@@ -749,7 +749,6 @@ apply_stylehint_to_tag(GtkTextTag *tag, GtkTextTag *default_tag, glui32 wintype,
                                        step be a scaling of 1.2 */
                                        scale = pow(1.2, (double)val);
                        }
-                       g_printerr("Setting tag to %f\n", scale);
                        g_object_set(tag_object, "scale", scale, "scale-set", TRUE, NULL);
                }
                break;
index bb9a2f66f945c2b61b4dfc69fadc8432154e9b25..7ba31121e75b45b192ab585e25b9ade565bb53b2 100644 (file)
@@ -82,6 +82,9 @@ struct glk_window_struct
        gulong pager_adjustment_handler;
        /* Window buffer */
        GString *buffer;
+       /* Styles */
+       GtkTextTag *zcolor;
+       glui32 last_zcolor_id;
        /* Hyperlinks */
        GHashTable *hyperlinks;
        struct hyperlink *current_hyperlink;