From 237978cacde5eb4bdd84181c3b93547412c1a61e Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 10 Sep 2018 01:48:45 +0200 Subject: Add all gui menus --- modules/menu/src/menu_gui.c | 449 +++++++++++++++++++++++++++++--------------- 1 file changed, 296 insertions(+), 153 deletions(-) diff --git a/modules/menu/src/menu_gui.c b/modules/menu/src/menu_gui.c index 0b1e19c..b71458d 100644 --- a/modules/menu/src/menu_gui.c +++ b/modules/menu/src/menu_gui.c @@ -356,7 +356,7 @@ static void menu_gui_continue (void) gtk_widget_show(button[4].ptr); gtk_widget_show(button[5].ptr); gtk_widget_show(separator[2]); -// gtk_widget_show(button[6].ptr); + gtk_widget_show(button[6].ptr); gtk_widget_show(separator[3]); gtk_widget_show(button[0].ptr); gtk_widget_show(box); @@ -372,261 +372,404 @@ static void menu_gui_continue (void) gtk_widget_destroy(box); wh = false; break; - case 1: gtk_widget_destroy(box); // start_switch(); break; - case 2: gtk_widget_destroy(box); menu_gui_select(); break; - case 3: gtk_widget_destroy(box); menu_gui_level(); break; - case 4: save_clr(); // alx_w_getfname(saved_path, saved_name, true, w2, r2, // txt[0], NULL); gtk_widget_destroy(box); break; - case 5: gtk_widget_destroy(box); read_scores(); break; -/* case 6: gtk_widget_destroy(box); menu_gui_devel(); break; -*/ } } } static void menu_gui_select (void) { -#if 0 - /* Menu dimensions & options */ - WINDOW *win; - int h; - int w; - int r; - int c; - h = 9; - w = 70; - r = 1; - c = (80 - w) / 2; - int N; - N = 3; - struct Alx_Menu mnu[3] = { - {6, 4, "[0] Back"}, - {2, 4, "[1] New map"}, - {4, 4, "[2] Load map"} - }; + int sw; + GtkWidget *box; + GtkWidget *separator[3]; + struct Label_Data label; + struct Button_Data button [3]; - /* Menu loop */ - int sw; - win = newwin(h, w, r, c); - mvwprintw(win, mnu[2].r, mnu[2].c, "%s (File: \"%s\")", mnu[1].t, saved_name); - wrefresh(win); - sw = alx_menu_2(win, N, mnu, "SELECT MAP:"); - alx_win_del(win); + /* Text */ + sprintf(label.text, "Select map"); + sprintf(button[1].text, "New map"); + sprintf(button[2].text, "Load map (File: \"%s\")", saved_name); + sprintf(button[0].text, "Back"); + + /* Data */ + button[1].num = 1; + button[2].num = 2; + button[0].num = 0; + button[1].sw = &sw; + button[2].sw = &sw; + button[0].sw = &sw; + + /* Generate widgets */ + box = gtk_vbox_new(false, 0); + label.ptr = gtk_label_new(label.text); + separator[0] = gtk_hseparator_new(); + button[1].ptr = gtk_button_new_with_label(button[1].text); + separator[1] = gtk_hseparator_new(); + button[2].ptr = gtk_button_new_with_label(button[2].text); + separator[2] = gtk_hseparator_new(); + button[0].ptr = gtk_button_new_with_label(button[0].text); + + /* Events */ + g_signal_connect(button[1].ptr, "clicked", + G_CALLBACK(callback_button), (void *)&button[1]); + g_signal_connect(button[2].ptr, "clicked", + G_CALLBACK(callback_button), (void *)&button[2]); + g_signal_connect(button[0].ptr, "clicked", + G_CALLBACK(callback_button), (void *)&button[0]); + + /* Container */ + gtk_container_add(GTK_CONTAINER(window_gui), box); + + /* Box */ + gtk_box_pack_start(GTK_BOX(box), label.ptr, false, false, 0); + gtk_box_pack_start(GTK_BOX(box), separator[0], false, false, 5); + gtk_box_pack_start(GTK_BOX(box), button[1].ptr, true, true, 0); + gtk_box_pack_start(GTK_BOX(box), separator[1], false, false, 5); + gtk_box_pack_start(GTK_BOX(box), button[2].ptr, true, true, 0); + gtk_box_pack_start(GTK_BOX(box), separator[2], false, false, 5); + gtk_box_pack_start(GTK_BOX(box), button[0].ptr, true, true, 0); + + /* Show */ + gtk_widget_show(label.ptr); + gtk_widget_show(separator[0]); + gtk_widget_show(button[1].ptr); + gtk_widget_show(separator[1]); + gtk_widget_show(button[2].ptr); + gtk_widget_show(separator[2]); + gtk_widget_show(button[0].ptr); + gtk_widget_show(box); + gtk_widget_show(window_gui); + + /* GTK loop */ + sw = 0; + gtk_main(); + + /* Clear window */ + gtk_widget_destroy(box); /* Selection */ switch (sw) { + case 0: + break; case 1: start_mode = START_RAND; break; - case 2: start_mode = START_LOAD; break; } -#endif } static void menu_gui_level (void) { -#if 0 - /* Menu dimensions & options */ - WINDOW *win; - int h; - int w; - h = 10; - w = 70; - int N; - N = 5; - struct Alx_Menu mnu[5] = { - {7, 4, "[0] Back"}, - {2, 4, "[1] Beginner"}, - {3, 4, "[2] Intermediate"}, - {4, 4, "[3] Expert"}, - {5, 4, "[4] Custom"} - }; + int sw; + GtkWidget *box; + GtkWidget *separator[3]; + struct Label_Data label; + struct Button_Data button [5]; - /* Menu loop */ - int sw; - sw = alx_menu(h, w, N, mnu, "SELECT LEVEL:"); + /* Text */ + sprintf(label.text, "Select level"); + sprintf(button[1].text, "Beginner"); + sprintf(button[2].text, "Intermediate"); + sprintf(button[3].text, "Expert"); + sprintf(button[4].text, "Custom"); + sprintf(button[0].text, "Back"); + + /* Data */ + button[1].num = 1; + button[2].num = 2; + button[3].num = 3; + button[4].num = 4; + button[0].num = 0; + button[1].sw = &sw; + button[2].sw = &sw; + button[3].sw = &sw; + button[4].sw = &sw; + button[0].sw = &sw; + + /* Generate widgets */ + box = gtk_vbox_new(false, 0); + label.ptr = gtk_label_new(label.text); + separator[0] = gtk_hseparator_new(); + button[1].ptr = gtk_button_new_with_label(button[1].text); + button[2].ptr = gtk_button_new_with_label(button[2].text); + button[3].ptr = gtk_button_new_with_label(button[3].text); + separator[1] = gtk_hseparator_new(); + button[4].ptr = gtk_button_new_with_label(button[4].text); + separator[2] = gtk_hseparator_new(); + button[0].ptr = gtk_button_new_with_label(button[0].text); + + /* Events */ + g_signal_connect(button[1].ptr, "clicked", + G_CALLBACK(callback_button), (void *)&button[1]); + g_signal_connect(button[2].ptr, "clicked", + G_CALLBACK(callback_button), (void *)&button[2]); + g_signal_connect(button[3].ptr, "clicked", + G_CALLBACK(callback_button), (void *)&button[3]); + g_signal_connect(button[4].ptr, "clicked", + G_CALLBACK(callback_button), (void *)&button[4]); + g_signal_connect(button[0].ptr, "clicked", + G_CALLBACK(callback_button), (void *)&button[0]); + + /* Container */ + gtk_container_add(GTK_CONTAINER(window_gui), box); + + /* Box */ + gtk_box_pack_start(GTK_BOX(box), label.ptr, false, false, 0); + gtk_box_pack_start(GTK_BOX(box), separator[0], false, false, 5); + gtk_box_pack_start(GTK_BOX(box), button[1].ptr, true, true, 0); + gtk_box_pack_start(GTK_BOX(box), button[2].ptr, true, true, 0); + gtk_box_pack_start(GTK_BOX(box), button[3].ptr, true, true, 0); + gtk_box_pack_start(GTK_BOX(box), separator[1], false, false, 5); + gtk_box_pack_start(GTK_BOX(box), button[4].ptr, true, true, 0); + gtk_box_pack_start(GTK_BOX(box), separator[2], false, false, 5); + gtk_box_pack_start(GTK_BOX(box), button[0].ptr, true, true, 0); + + /* Show */ + gtk_widget_show(label.ptr); + gtk_widget_show(separator[0]); + gtk_widget_show(button[1].ptr); + gtk_widget_show(button[2].ptr); + gtk_widget_show(button[3].ptr); + gtk_widget_show(separator[1]); + gtk_widget_show(button[4].ptr); + gtk_widget_show(separator[2]); + gtk_widget_show(button[0].ptr); + gtk_widget_show(box); + gtk_widget_show(window_gui); + + /* GTK loop */ + sw = 0; + gtk_main(); + + /* Clear window */ + gtk_widget_destroy(box); /* Selection */ switch (sw) { case 1: menu_iface_variables.level = GAME_IFACE_LEVEL_BEGINNER; break; - case 2: menu_iface_variables.level = GAME_IFACE_LEVEL_INTERMEDIATE; break; - case 3: menu_iface_variables.level = GAME_IFACE_LEVEL_EXPERT; break; - case 4: menu_iface_variables.level = GAME_IFACE_LEVEL_CUSTOM; - menu_tui_custom(); + menu_gui_custom(); break; } -#endif } static void menu_gui_custom (void) { -#if 0 - /* Menu dimensions & options */ - WINDOW *win; - int h; - int w; - int r; - int c; - h = 16; - w = 76; - r = 1; - c = (80 - w) / 2; - int N; - N = 4; - struct Alx_Menu mnu[4] = { - {8, 4, "[0] Back"}, - {2, 4, "[1] Change rows:"}, - {4, 4, "[2] Change columns:"}, - {6, 4, "[3] Change proportion of mines:"} - }; - - /* Input box */ - int w2; - int r2; - w2 = w - 8; - r2 = r + h - 5; - char *txt[] = { - "Rows:", - "Columns:", - "Proportion:" - }; - - /* Menu */ - win = newwin(h, w, r, c); + bool wh; + int sw; + GtkWidget *box; + GtkWidget *separator[3]; + struct Label_Data label; + struct Button_Data button [4]; + + /* Text */ + sprintf(label.text, "Custom"); + sprintf(button[0].text, "Back"); + + /* Data */ + button[1].num = 1; + button[2].num = 2; + button[3].num = 3; + button[0].num = 0; + button[1].sw = &sw; + button[2].sw = &sw; + button[3].sw = &sw; + button[0].sw = &sw; /* Menu loop */ - bool wh; - int sw; wh = true; - while (wh) { - mvwprintw(win, mnu[1].r, mnu[1].c, "%s rows\t\t(%i)", mnu[1].t, menu_iface_variables.rows); - mvwprintw(win, mnu[2].r, mnu[2].c, "%s cols\t\t(%i)", mnu[2].t, menu_iface_variables.cols); - mvwprintw(win, mnu[3].r, mnu[3].c, "%s p\t(%lf)", mnu[3].t, menu_iface_variables.p); - wrefresh(win); + while (wh && gui_is_open) { + /* Text */ + sprintf(button[1].text, "Change rows: rows\t\t(%i)", menu_iface_variables.rows); + sprintf(button[2].text, "Change columns: cols\t(%i)", menu_iface_variables.cols); + sprintf(button[3].text, "Change proportion of mines: p\t(%lf)", menu_iface_variables.p); - /* Selection */ - sw = alx_menu_2(win, N, mnu, "Custom:"); + /* Generate widgets */ + box = gtk_vbox_new(false, 0); + label.ptr = gtk_label_new(label.text); + separator[0] = gtk_hseparator_new(); + button[1].ptr = gtk_button_new_with_label(button[1].text); + button[2].ptr = gtk_button_new_with_label(button[2].text); + separator[1] = gtk_hseparator_new(); + button[3].ptr = gtk_button_new_with_label(button[3].text); + separator[2] = gtk_hseparator_new(); + button[0].ptr = gtk_button_new_with_label(button[0].text); + /* Events */ + g_signal_connect(button[1].ptr, "clicked", + G_CALLBACK(callback_button), (void *)&button[1]); + g_signal_connect(button[2].ptr, "clicked", + G_CALLBACK(callback_button), (void *)&button[2]); + g_signal_connect(button[3].ptr, "clicked", + G_CALLBACK(callback_button), (void *)&button[3]); + g_signal_connect(button[0].ptr, "clicked", + G_CALLBACK(callback_button), (void *)&button[0]); + + /* Container */ + gtk_container_add(GTK_CONTAINER(window_gui), box); + + /* Box */ + gtk_box_pack_start(GTK_BOX(box), label.ptr, false, false, 0); + gtk_box_pack_start(GTK_BOX(box), separator[0], false, false, 5); + gtk_box_pack_start(GTK_BOX(box), button[1].ptr, true, true, 0); + gtk_box_pack_start(GTK_BOX(box), button[2].ptr, true, true, 0); + gtk_box_pack_start(GTK_BOX(box), separator[1], false, false, 5); + gtk_box_pack_start(GTK_BOX(box), button[3].ptr, true, true, 0); + gtk_box_pack_start(GTK_BOX(box), separator[2], false, false, 5); + gtk_box_pack_start(GTK_BOX(box), button[0].ptr, true, true, 0); + + /* Show */ + gtk_widget_show(label.ptr); + gtk_widget_show(separator[0]); + gtk_widget_show(button[1].ptr); + gtk_widget_show(button[2].ptr); + gtk_widget_show(separator[1]); + gtk_widget_show(button[3].ptr); + gtk_widget_show(separator[2]); + gtk_widget_show(button[0].ptr); + gtk_widget_show(box); + gtk_widget_show(window_gui); + + /* GTK loop */ + sw = 0; + gtk_main(); + + /* Selection */ switch (sw) { case 0: wh = false; break; - case 1: - menu_iface_variables.rows = alx_w_getint(w2, r2, - txt[sw - 1], 2, menu_iface_variables.rows, ROWS_TUI_MAX, NULL); +// menu_iface_variables.rows = alx_w_getint(w2, r2, +// txt[sw - 1], 2, menu_iface_variables.rows, ROWS_TUI_MAX, NULL); break; - case 2: - menu_iface_variables.cols = alx_w_getint(w2, r2, - txt[sw - 1], 2, menu_iface_variables.cols, COLS_TUI_MAX, NULL); +// menu_iface_variables.cols = alx_w_getint(w2, r2, +// txt[sw - 1], 2, menu_iface_variables.cols, COLS_TUI_MAX, NULL); break; - case 3: - menu_iface_variables.p = alx_w_getdbl(w2, r2, - txt[sw - 1], 0, menu_iface_variables.p, 1, NULL); +// menu_iface_variables.p = alx_w_getdbl(w2, r2, +// txt[sw - 1], 0, menu_iface_variables.p, 1, NULL); break; } + /* Clear window */ + gtk_widget_destroy(box); } - - /* Cleanup */ - alx_win_del(win); -#endif } static void menu_gui_devel (void) { -#if 0 - WINDOW *win; - int h; - int w; - int r; - int c; - h = 12; - w = 50; - r = 1; - c = (80 - w) / 2; - int N; - N = 2; - struct Alx_Menu mnu[2] = { - {5, 4, "[0] Back"}, - {2, 4, "[1] Change seed (srand)"} - }; - - /* Input box */ - int w2; - int r2; - w2 = w - 8; - r2 = r + h - 5; - char *txt[] = {"Seed:"}; - - /* Menu */ - win = newwin(h, w, r, c); + bool wh; + int sw; + GtkWidget *box; + GtkWidget *separator[2]; + struct Label_Data label; + struct Button_Data button [2]; + + /* Text */ + sprintf(label.text, "DEVELOPER OPTIONS"); + sprintf(button[1].text, "Change seed (srand)"); + sprintf(button[0].text, "Back"); + + /* Data */ + button[1].num = 1; + button[0].num = 0; + button[1].sw = &sw; + button[0].sw = &sw; /* Menu loop */ - bool wh; - int sw; - wh = true; int seed; - while (wh) { - /* Selection */ - sw = alx_menu_2(win, N, mnu, "DEVELOPER OPTIONS:"); + wh = true; + while (wh && gui_is_open) { + /* Generate widgets */ + box = gtk_vbox_new(false, 0); + label.ptr = gtk_label_new(label.text); + separator[0] = gtk_hseparator_new(); + button[1].ptr = gtk_button_new_with_label(button[1].text); + separator[1] = gtk_hseparator_new(); + button[0].ptr = gtk_button_new_with_label(button[0].text); + + /* Events */ + g_signal_connect(button[1].ptr, "clicked", + G_CALLBACK(callback_button), (void *)&button[1]); + g_signal_connect(button[0].ptr, "clicked", + G_CALLBACK(callback_button), (void *)&button[0]); + + /* Container */ + gtk_container_add(GTK_CONTAINER(window_gui), box); + + /* Box */ + gtk_box_pack_start(GTK_BOX(box), label.ptr, false, false, 0); + gtk_box_pack_start(GTK_BOX(box), separator[0], false, false, 5); + gtk_box_pack_start(GTK_BOX(box), button[1].ptr, true, true, 0); + gtk_box_pack_start(GTK_BOX(box), separator[1], false, false, 5); + gtk_box_pack_start(GTK_BOX(box), button[0].ptr, true, true, 0); + + /* Show */ + gtk_widget_show(label.ptr); + gtk_widget_show(separator[0]); + gtk_widget_show(button[1].ptr); + gtk_widget_show(separator[1]); + gtk_widget_show(button[0].ptr); + gtk_widget_show(box); + gtk_widget_show(window_gui); + /* GTK loop */ + sw = 0; + gtk_main(); + + /* Selection */ switch (sw) { case 0: wh = false; break; - case 1: - seed = alx_w_getint(w2, r2, txt[0], - -INFINITY, 1, INFINITY, NULL); +// seed = alx_w_getint(w2, r2, txt[0], +// -INFINITY, 1, INFINITY, NULL); srand(seed); break; } - } - /* Cleanup */ - alx_win_del(win); -#endif + /* Clear window */ + gtk_widget_destroy(box); + } } -- cgit v1.2.3