X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=libchimara%2Fchimara-if.c;h=4e8c1d9490b4fcbc38f0e471703a2fcc35fd5c29;hb=87504b58306f29cf833637a9e9983e947e684ee1;hp=3298c795d397ef84754da5ceecfbb79f15b5e5fc;hpb=b9668b4d0922ce7cf0202eef4f157b778cf870c1;p=projects%2Fchimara%2Fchimara.git diff --git a/libchimara/chimara-if.c b/libchimara/chimara-if.c index 3298c79..4e8c1d9 100644 --- a/libchimara/chimara-if.c +++ b/libchimara/chimara-if.c @@ -6,6 +6,7 @@ #include #include "chimara-if.h" #include "chimara-glk.h" +#include "chimara-glk-private.h" #include "chimara-marshallers.h" #include "init.h" @@ -13,11 +14,17 @@ * SECTION:chimara-if * @short_description: Widget which plays an interactive fiction game * @stability: Unstable - * @include: chimara/chimara-if.h + * @include: libchimara/chimara-if.h * * The #ChimaraIF widget, given an interactive fiction game file to run, selects * an appropriate interpreter plugin and runs it. Interpreter options are set by * setting properties on the widget. + * + * Using it in a GTK program is similar to using #ChimaraGlk (which see). + * Threads must be initialized before using #ChimaraIF and the call to + * gtk_main() must be bracketed between gdk_threads_enter() and + * gdk_threads_leave(). Use chimara_if_run_game() to start playing an + * interactive fiction game. */ static gboolean supported_formats[CHIMARA_IF_NUM_FORMATS][CHIMARA_IF_NUM_INTERPRETERS] = { @@ -97,7 +104,9 @@ chimara_if_waiting(ChimaraGlk *glk) gchar *response = g_string_free(priv->response, FALSE); priv->response = g_string_new(""); + gdk_threads_enter(); g_signal_emit_by_name(glk, "command", priv->input, response); + gdk_threads_leave(); g_free(priv->input); g_free(response); @@ -116,6 +125,17 @@ chimara_if_stopped(ChimaraGlk *glk) priv->interpreter = CHIMARA_IF_INTERPRETER_NONE; } +static void +chimara_if_char_input(ChimaraGlk *glk, guint32 win_rock, guint keysym) +{ + CHIMARA_IF_USE_PRIVATE(glk, priv); + g_assert(priv->input == NULL); + + gchar outbuf[6]; + gint outbuflen = g_unichar_to_utf8(gdk_keyval_to_unicode(keysym), outbuf); + priv->input = g_strndup(outbuf, outbuflen); +} + static void chimara_if_line_input(ChimaraGlk *glk, guint32 win_rock, gchar *input) { @@ -152,6 +172,7 @@ chimara_if_init(ChimaraIF *self) /* Connect to signals of ChimaraGlk parent */ g_signal_connect(self, "stopped", G_CALLBACK(chimara_if_stopped), NULL); g_signal_connect(self, "waiting", G_CALLBACK(chimara_if_waiting), NULL); + g_signal_connect(self, "char-input", G_CALLBACK(chimara_if_char_input), NULL); g_signal_connect(self, "line-input", G_CALLBACK(chimara_if_line_input), NULL); g_signal_connect(self, "text-buffer-output", G_CALLBACK(chimara_if_text_buffer_output), NULL); } @@ -166,27 +187,35 @@ chimara_if_set_property(GObject *object, guint prop_id, const GValue *value, GPa { case PROP_PIRACY_MODE: PROCESS_FLAG(priv->flags, CHIMARA_IF_PIRACY_MODE, g_value_get_boolean(value)); + g_object_notify(object, "piracy-mode"); break; case PROP_TANDY_BIT: PROCESS_FLAG(priv->flags, CHIMARA_IF_TANDY_BIT, g_value_get_boolean(value)); + g_object_notify(object, "tandy-bit"); break; case PROP_EXPAND_ABBREVIATIONS: PROCESS_FLAG(priv->flags, CHIMARA_IF_EXPAND_ABBREVIATIONS, g_value_get_boolean(value)); + g_object_notify(object, "expand-abbreviations"); break; case PROP_IGNORE_ERRORS: PROCESS_FLAG(priv->flags, CHIMARA_IF_IGNORE_ERRORS, g_value_get_boolean(value)); + g_object_notify(object, "ignore-errors"); break; case PROP_TYPO_CORRECTION: PROCESS_FLAG(priv->flags, CHIMARA_IF_TYPO_CORRECTION, g_value_get_boolean(value)); + g_object_notify(object, "typo-correction"); break; case PROP_INTERPRETER_NUMBER: priv->interpreter_number = g_value_get_uint(value); + g_object_notify(object, "interpreter-number"); break; case PROP_RANDOM_SEED: priv->random_seed = g_value_get_int(value); + g_object_notify(object, "random-seed"); break; case PROP_RANDOM_SEED_SET: priv->random_seed_set = g_value_get_boolean(value); + g_object_notify(object, "random-seed-set"); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); @@ -240,9 +269,16 @@ chimara_if_command(ChimaraIF *self, gchar *input, gchar *response) /* Default signal handler */ } -/* G_PARAM_STATIC_STRINGS only appeared in GTK 2.13.0 */ +/* COMPAT: G_PARAM_STATIC_STRINGS only appeared in GTK 2.13.0 */ #ifndef G_PARAM_STATIC_STRINGS + +/* COMPAT: G_PARAM_STATIC_NAME and friends only appeared in GTK 2.8 */ +#if GTK_CHECK_VERSION(2,8,0) #define G_PARAM_STATIC_STRINGS (G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB) +#else +#define G_PARAM_STATIC_STRINGS (0) +#endif + #endif static void @@ -259,18 +295,21 @@ chimara_if_class_init(ChimaraIFClass *klass) /** * ChimaraIF::command: * @self: The widget that received the signal - * @input: The command typed into the game + * @input: The command typed into the game, or %NULL * @response: The game's response to the command * * Emitted once for each input-response cycle of an interactive fiction * game. Note that games with nontraditional input systems (i.e. not all - * taking place in the same text buffer window) may throw this signal for a - * loop. + * taking place in the same text buffer window) may confuse this signal. + * + * It may happen that @input is %NULL, in which case @response is not due to + * a user command, but contains the text printed at the beginning of the + * game, up until the first prompt. */ chimara_if_signals[COMMAND] = g_signal_new("command", G_OBJECT_CLASS_TYPE(klass), 0, G_STRUCT_OFFSET(ChimaraIFClass, command), NULL, NULL, - chimara_marshal_VOID__STRING_STRING, + _chimara_marshal_VOID__STRING_STRING, G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING); /* Properties */ @@ -533,11 +572,17 @@ chimara_if_run_game(ChimaraIF *self, gchar *gamefile, GError **error) ChimaraIFInterpreter interpreter = priv->preferred_interpreter[format]; gchar *pluginfile = g_strconcat(plugin_names[interpreter], "." G_MODULE_SUFFIX, NULL); + gchar *pluginpath; +#ifdef DEBUG +#ifndef LT_OBJDIR +#define LT_OBJDIR ".libs" /* Pre-2.2 libtool, so take a wild guess */ +#endif /* LT_OBJDIR */ /* If there is a plugin in the source tree, use that */ - gchar *pluginpath = g_build_filename("..", "interpreters", plugin_names[interpreter], LT_OBJDIR, pluginfile, NULL); + pluginpath = g_build_filename(PLUGINSOURCEDIR, plugin_names[interpreter], LT_OBJDIR, pluginfile, NULL); if( !g_file_test(pluginpath, G_FILE_TEST_EXISTS) ) { g_free(pluginpath); +#endif /* DEBUG */ pluginpath = g_build_filename(PLUGINDIR, pluginfile, NULL); if( !g_file_test(pluginpath, G_FILE_TEST_EXISTS) ) { @@ -546,7 +591,9 @@ chimara_if_run_game(ChimaraIF *self, gchar *gamefile, GError **error) g_set_error(error, CHIMARA_ERROR, CHIMARA_PLUGIN_NOT_FOUND, _("No appropriate %s interpreter plugin was found"), interpreter_names[interpreter]); return FALSE; } +#ifdef DEBUG } +#endif g_free(pluginfile); /* Decide what arguments to pass to the interpreters; currently only the @@ -614,7 +661,14 @@ chimara_if_run_game(ChimaraIF *self, gchar *gamefile, GError **error) GSList *ptr; for(count = 0, ptr = args; ptr; count++, ptr = g_slist_next(ptr)) argv[count] = ptr->data; - + + /* Set the story name */ + /* We peek into ChimaraGlk's private data here, because GObject has no + equivalent to "protected" */ + CHIMARA_GLK_USE_PRIVATE(self, glk_priv); + glk_priv->story_name = g_path_get_basename(gamefile); + g_object_notify(G_OBJECT(self), "story-name"); + gboolean retval = chimara_glk_run(CHIMARA_GLK(self), pluginpath, argc, argv, error); g_free(argv); if(terpnumstr)