#include "gtkpixdata.h" #include "dynamicgtk.h" #include "build.h" #include "editor.h" #include "baselayer.h" enum { TAB_CONFIG, TAB_MESSAGES, }; static struct { GtkWidget *startwin; GtkWidget *hlayout; GtkWidget *banner; GtkWidget *vlayout; GtkWidget *tabs; GtkWidget *configtlayout; GtkWidget *vmode2dlabel; GtkWidget *vmode3dlabel; GtkWidget *vmode2dcombo; GtkWidget *vmode3dcombo; GtkWidget *fullscreencheck; GtkWidget *emptyhlayout; GtkWidget *alwaysshowcheck; GtkWidget *configtab; GtkWidget *messagesscroll; GtkWidget *messagestext; GtkWidget *messagestab; GtkWidget *buttons; GtkWidget *cancelbutton; GtkWidget *cancelbuttonalign; GtkWidget *cancelbuttonlayout; GtkWidget *cancelbuttonicon; GtkWidget *cancelbuttonlabel; GtkWidget *startbutton; GtkWidget *startbuttonalign; GtkWidget *startbuttonlayout; GtkWidget *startbuttonicon; GtkWidget *startbuttonlabel; GtkAccelGroup *accel_group; } stwidgets; static struct { int32_t fullscreen; int32_t xdim2d, ydim2d; int32_t xdim3d, ydim3d, bpp3d; int32_t forcesetup; } settings; static int32_t retval = -1, mode = TAB_MESSAGES; extern int32_t gtkenabled; static void PopulateForm(void); // -- EVENT CALLBACKS AND CREATION STUFF -------------------------------------- static void on_vmode2dcombo_changed(GtkComboBox *combobox, gpointer user_data) { GtkTreeModel *data; GtkTreeIter iter; int32_t val; UNREFERENCED_PARAMETER(user_data); if (!gtk_combo_box_get_active_iter(combobox, &iter)) return; if (!(data = gtk_combo_box_get_model(combobox))) return; gtk_tree_model_get(data, &iter, 1, &val, -1); settings.xdim2d = validmode[val].xdim; settings.ydim2d = validmode[val].ydim; } static void on_vmode3dcombo_changed(GtkComboBox *combobox, gpointer user_data) { GtkTreeModel *data; GtkTreeIter iter; int32_t val; UNREFERENCED_PARAMETER(user_data); if (!gtk_combo_box_get_active_iter(combobox, &iter)) return; if (!(data = gtk_combo_box_get_model(combobox))) return; gtk_tree_model_get(data, &iter, 1, &val, -1); settings.xdim3d = validmode[val].xdim; settings.ydim3d = validmode[val].ydim; settings.bpp3d = validmode[val].bpp; } static void on_fullscreencheck_toggled(GtkToggleButton *togglebutton, gpointer user_data) { UNREFERENCED_PARAMETER(user_data); settings.fullscreen = (gtk_toggle_button_get_active(togglebutton) == TRUE); PopulateForm(); } static void on_alwaysshowcheck_toggled(GtkToggleButton *togglebutton, gpointer user_data) { UNREFERENCED_PARAMETER(user_data); settings.forcesetup = (gtk_toggle_button_get_active(togglebutton) == TRUE); } static void on_cancelbutton_clicked(GtkButton *button, gpointer user_data) { UNREFERENCED_PARAMETER(button); UNREFERENCED_PARAMETER(user_data); if (mode == TAB_CONFIG) { retval = 0; gtk_main_quit(); } else quitevent++; } static void on_startbutton_clicked(GtkButton *button, gpointer user_data) { UNREFERENCED_PARAMETER(button); UNREFERENCED_PARAMETER(user_data); retval = 1; gtk_main_quit(); } static gboolean on_startwin_delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_data) { UNREFERENCED_PARAMETER(widget); UNREFERENCED_PARAMETER(event); UNREFERENCED_PARAMETER(user_data); if (mode == TAB_CONFIG) { retval = 0; gtk_main_quit(); } else quitevent++; return TRUE; // FALSE would let the event go through. we want the game to decide when to close } // -- SUPPORT FUNCTIONS ------------------------------------------------------- static GdkPixbuf *load_banner(void) { return gdk_pixbuf_from_pixdata((GdkPixdata const *)&startbanner_pixdata, FALSE, NULL); } static void SetPage(int32_t n) { if (!gtkenabled || !stwidgets.startwin) return; mode = n; gtk_notebook_set_current_page(GTK_NOTEBOOK(stwidgets.tabs), n); // each control in the config page vertical layout plus the start button should be made (in)sensitive if (n == TAB_CONFIG) n = TRUE; else n = FALSE; gtk_widget_set_sensitive(stwidgets.startbutton, n); gtk_container_foreach(GTK_CONTAINER(stwidgets.configtlayout), (GtkCallback)gtk_widget_set_sensitive, (gpointer)&n); } static void PopulateForm(void) { int32_t mode2d, mode3d, i; GtkListStore *modes2d, *modes3d; GtkTreeIter iter; GtkComboBox *box2d, *box3d; char buf[64]; mode2d = checkvideomode(&settings.xdim2d, &settings.ydim2d, 8, settings.fullscreen, 1); mode3d = checkvideomode(&settings.xdim3d, &settings.ydim3d, settings.bpp3d, settings.fullscreen, 1); if (mode2d < 0) mode2d = 0; if (mode3d < 0) { int32_t i, cd[] = { 32, 24, 16, 15, 8, 0 }; for (i=0; cd[i];) { if (cd[i] >= settings.bpp3d) i++; else break; } for (; cd[i]; i++) { mode3d = checkvideomode(&settings.xdim3d, &settings.ydim3d, cd[i], settings.fullscreen, 1); if (mode3d < 0) continue; settings.bpp3d = cd[i]; break; } } box2d = GTK_COMBO_BOX(stwidgets.vmode2dcombo); box3d = GTK_COMBO_BOX(stwidgets.vmode3dcombo); modes2d = GTK_LIST_STORE(gtk_combo_box_get_model(box2d)); modes3d = GTK_LIST_STORE(gtk_combo_box_get_model(box3d)); gtk_list_store_clear(modes2d); gtk_list_store_clear(modes3d); for (i=0; i aptr) gtk_text_buffer_insert(textbuffer, &enditer, (const gchar *)aptr, (gint)(bptr-aptr)-1); #if GTK_CHECK_VERSION(2,6,0) gtk_text_buffer_backspace(textbuffer, &enditer, FALSE, TRUE); #else { GtkTextIter iter2 = enditer; gtk_text_iter_backward_cursor_position(&iter2); //FIXME: this seems be deleting one too many chars somewhere! if (!gtk_text_iter_equal(&iter2, &enditer)) gtk_text_buffer_delete_interactive(textbuffer, &iter2, &enditer, TRUE); } #endif aptr = ++bptr; break; case 0: if (bptr > aptr) gtk_text_buffer_insert(textbuffer, &enditer, (const gchar *)aptr, (gint)(bptr-aptr)); aptr = bptr; break; case '\r': // FIXME default: bptr++; break; } } mark = gtk_text_buffer_create_mark(textbuffer, NULL, &enditer, 1); gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(textview), mark, 0.0, FALSE, 0.0, 1.0); gtk_text_buffer_delete_mark(textbuffer, mark); return 0; } int32_t startwin_settitle(const char *title) { if (!gtkenabled) return 0; if (!stwidgets.startwin) return 1; gtk_window_set_title(GTK_WINDOW(stwidgets.startwin), title); return 0; } int32_t startwin_idle(void *s) { UNREFERENCED_PARAMETER(s); if (!gtkenabled) return 0; //if (!stwidgets.startwin) return 1; gtk_main_iteration_do(FALSE); return 0; } int32_t startwin_run(void) { if (!gtkenabled) return 1; if (!stwidgets.startwin) return 1; SetPage(TAB_CONFIG); settings.fullscreen = fullscreen; settings.xdim2d = xdim2d; settings.ydim2d = ydim2d; settings.xdim3d = xdimgame; settings.ydim3d = ydimgame; settings.bpp3d = bppgame; settings.forcesetup = forcesetup; PopulateForm(); gtk_main(); SetPage(TAB_MESSAGES); if (retval) { fullscreen = settings.fullscreen; xdim2d = settings.xdim2d; ydim2d = settings.ydim2d; xdimgame = settings.xdim3d; ydimgame = settings.ydim3d; bppgame = settings.bpp3d; forcesetup = settings.forcesetup; } return retval; }