X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=libchimara%2Fgarglk.c;h=a879ca85c2a104a765749d953128c298074d4c40;hb=f17f704eb40ce5d3d6ec7f2daf2d67586225ff90;hp=4eb59a5fad97816fb17c869111a937513dde8cd7;hpb=207745dc22dd7d17bcb7bf26ec991cc1ac8199ed;p=projects%2Fchimara%2Fchimara.git
diff --git a/libchimara/garglk.c b/libchimara/garglk.c
index 4eb59a5..a879ca8 100644
--- a/libchimara/garglk.c
+++ b/libchimara/garglk.c
@@ -89,40 +89,19 @@ garglk_set_story_name(const char *name)
}
/**
- * garglk_set_line_terminators:
- * @win: A window.
- * @keycodes: An array of keycode_
constants.
- * @numkeycodes: The length of @keycodes.
+ * garglk_set_story_title:
+ * @title: Title bar text for the currently running story.
*
- * Amends the current line input request of @win to include terminating key
- * codes. Any of the specified key codes will terminate the line input request
- * (without printing a newline).
- *
- * Usually, in the event structure returned from a line input request, @val2 is
- * zero, but if garglk_set_line_terminators() has been called during that input
- * request, @val2 will be filled in with the key code that terminated the input
- * request.
- *
- * This function only applies to one input request; any subsequent line input
- * requests on that window are treated normally.
- *
- * If @numkeycodes is zero, then any previous call to
- * garglk_set_line_terminators() is cancelled and the input request is treated
- * normally.
+ * This function is a hint to the library to put @title in the title bar of the
+ * window that the Glk program is running in. It overrides
+ * garglk_set_program_name() and garglk_set_story_name(), if they were displayed
+ * in the title bar, although they may still be displayed somewhere else.
*
* This function is not currently implemented.
*/
-void
-garglk_set_line_terminators(winid_t win, const glui32 *keycodes, glui32 numkeycodes)
+void
+garglk_set_story_title(const char *title)
{
- VALID_WINDOW(win, return);
- g_return_if_fail(win->type != wintype_TextBuffer || win->type != wintype_TextGrid);
-
- if(win->input_request_type != INPUT_REQUEST_LINE && win->input_request_type != INPUT_REQUEST_LINE_UNICODE) {
- ILLEGAL(_("Tried to set the line terminators on a window without a line input request."));
- return;
- }
-
WARNING(_("Not implemented"));
}
@@ -162,7 +141,16 @@ garglk_unput_string_uni(glui32 *str)
WARNING(_("Not implemented"));
}
-/* TODO document */
+/**
+ * garglk_set_zcolors_stream:
+ * @str: a stream.
+ * @fg: a 24-bit foreground color.
+ * @bg: a 24-bit background color.
+ *
+ * This function changes the foreground color of @str to @fg and the background
+ * color to @bg. @fg and @bg are encoded the same way as described in
+ * %stylehint_TextColor. See garglk_set_zcolors() for more information.
+ */
void
garglk_set_zcolors_stream(strid_t str, glui32 fg, glui32 bg)
{
@@ -199,7 +187,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 +202,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 +219,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 +234,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 +263,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();
@@ -290,16 +280,15 @@ garglk_set_zcolors_stream(strid_t str, glui32 fg, glui32 bg)
/**
* garglk_set_zcolors:
- * @fg: one of the zcolor_
constants.
- * @bg: one of the zcolor_
constants.
+ * @fg: a 24-bit foreground color.
+ * @bg: a 24-bit background color.
*
* Glk works with styles, not specific colors. This is not quite compatible with
* the Z-machine, so this Glk extension implements Z-machine style colors.
*
* This function changes the foreground color of the current stream to @fg and
- * the background color to @bg.
- *
- * This function is not currently implemented.
+ * the background color to @bg. @fg and @bg are encoded the same way as
+ * described in %stylehint_TextColor.
*/
void
garglk_set_zcolors(glui32 fg, glui32 bg)
@@ -310,7 +299,15 @@ garglk_set_zcolors(glui32 fg, glui32 bg)
garglk_set_zcolors_stream(glk_data->current_stream, fg, bg);
}
-/* TODO document */
+/**
+ * garglk_set_reversevideo_stream:
+ * @str: a stream.
+ * @reverse: nonzero for reverse colors, zero for normal colors.
+ *
+ * If @reverse is not zero, uses the foreground color of @str as its background
+ * and vice versa. If @reverse is zero, changes the colors of @str back to
+ * normal.
+ */
void
garglk_set_reversevideo_stream(strid_t str, glui32 reverse)
{
@@ -367,11 +364,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();
}