summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralex <alex@ASUS>2018-09-07 16:11:25 +0200
committeralex <alex@ASUS>2018-09-07 16:11:25 +0200
commitaa028666ba96b3210bf4e873cd6209b20bc42cf7 (patch)
tree8553a677fdcfdc845897704996a3142c889f0de9
parent1d9157589c6498a73c31b340aa3bad27f0e11bd7 (diff)
Add gtk iface
-rw-r--r--Makefile6
-rw-r--r--modules/menu/inc/menu_gui.h41
-rw-r--r--modules/menu/inc/menu_iface.h1
-rw-r--r--modules/menu/obj/Makefile28
-rw-r--r--modules/menu/src/menu_gui.c448
-rw-r--r--modules/menu/src/menu_iface.c17
-rw-r--r--modules/menu/src/parser.c4
-rw-r--r--src/main.c23
8 files changed, 554 insertions, 14 deletions
diff --git a/Makefile b/Makefile
index da1d386..86f68de 100644
--- a/Makefile
+++ b/Makefile
@@ -141,23 +141,25 @@ export LD
################################################################################
CFLAGS = -std=c11
+CFLAGS += `pkg-config --cflags gtk+-2.0`
CFLAGS += -D PROG_VERSION=\"$(PROGRAMVERSION)\"
CFLAGS += -D 'INSTALL_SHARE_DIR="$(INSTALL_SHARE_DIR)"'
CFLAGS += -D SHARE_DIR=\"$(SHARE_DIR)\"
CFLAGS += -D 'INSTALL_VAR_DIR="$(INSTALL_VAR_DIR)"'
CFLAGS += -D VAR_DIR=\"$(VAR_DIR)\"
+GTK_LIBS = `pkg-config --libs gtk+-2.0`
ifeq ($(OS), linux)
CFLAGS += -D OS_LINUX
- LIBS = -l m -l ncursesw
+ LIBS = -l m -l ncursesw $(GTK_LIBS)
else ifeq ($(OS), win)
CFLAGS += -D OS_WIN
# curses
CFLAGS += -D _XOPEN_SOURCE=500 -I /mingw/include/ncursesw -I /mingw/include
CURSES_LIBS = -L /mingw/lib -l ncursesw -l psapi
- LIBS = -static -l m $(CURSES_LIBS)
+ LIBS = -static -l m $(CURSES_LIBS) $(GTK_LIBS)
endif
export CFLAGS
diff --git a/modules/menu/inc/menu_gui.h b/modules/menu/inc/menu_gui.h
new file mode 100644
index 0000000..e2515d8
--- /dev/null
+++ b/modules/menu/inc/menu_gui.h
@@ -0,0 +1,41 @@
+/******************************************************************************
+ * Copyright (C) 2015 Alejandro Colomar Andrés *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+# ifndef MSW_MENU_GUI_H
+ # define MSW_MENU_GUI_H
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+ /* GtkWidget */
+ #include <gtk/gtk.h>
+
+
+/******************************************************************************
+ ******* variables ************************************************************
+ ******************************************************************************/
+extern GtkWidget *window_gui;
+
+
+/******************************************************************************
+ ******* functions ************************************************************
+ ******************************************************************************/
+ void menu_gui_init (void);
+ void menu_gui (void);
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+# endif /* menu_gui.h */
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/modules/menu/inc/menu_iface.h b/modules/menu/inc/menu_iface.h
index a7ac23b..89e4326 100644
--- a/modules/menu/inc/menu_iface.h
+++ b/modules/menu/inc/menu_iface.h
@@ -50,6 +50,7 @@ extern struct Menu_Iface_Variables menu_iface_variables;
******* functions ************************************************************
******************************************************************************/
void menu_iface_init (void);
+void menu_iface_init_iface (void);
void menu_iface_board (int *level, int *rows, int *cols, int *mines);
void menu_iface (void);
diff --git a/modules/menu/obj/Makefile b/modules/menu/obj/Makefile
index c32d449..5b72d54 100644
--- a/modules/menu/obj/Makefile
+++ b/modules/menu/obj/Makefile
@@ -17,7 +17,7 @@ SRC_DIR = $(MENU_DIR)/src/
# dependencies
-_ALL = parser.o menu_iface.o menu_clui.o menu_tui.o
+_ALL = parser.o menu_iface.o menu_clui.o menu_tui.o menu_gui.o
ALL = $(_ALL) menu_mod.o
PARS_INC_LIBALX = alx_seed.h
@@ -45,7 +45,7 @@ PARS_INC_DIRS = -I $(INC_DIR) \
MENUI_INC_CTRL = start.h
MENUI_INC_GAME = game_iface.h
-MENUI_INC = menu_iface.h menu_clui.h menu_tui.h
+MENUI_INC = menu_iface.h menu_clui.h menu_tui.h menu_gui.h
MENUI_DEPS = $(SRC_DIR)/menu_iface.c \
$(patsubst %,$(INC_DIR)/%,$(MENUI_INC)) \
$(patsubst %,$(CTRL_INC_DIR)/%,$(MENUI_INC_CTRL)) \
@@ -94,6 +94,26 @@ MENUTUI_INC_DIRS = -I $(INC_DIR) \
-I $(GAME_INC_DIR) \
-I $(SAVE_INC_DIR)
+MENUGUI_INC_LIBALX = alx_ncur.h
+MENUGUI_INC_ABOUT = about.h
+MENUGUI_INC_CTRL = start.h
+MENUGUI_INC_GAME = game_iface.h
+MENUGUI_INC_SAVE = save.h score.h
+MENUGUI_INC = menu_gui.h menu_iface.h
+MENUGUI_DEPS = $(SRC_DIR)/menu_gui.c \
+ $(patsubst %,$(INC_DIR)/%,$(MENUGUI_INC)) \
+ $(patsubst %,$(LIBALX_INC_DIR)/%,$(MENUGUI_INC_LIBALX)) \
+ $(patsubst %,$(ABOUT_INC_DIR)/%,$(MENUGUI_INC_ABOUT)) \
+ $(patsubst %,$(GAME_INC_DIR)/%,$(MENUGUI_INC_GAME)) \
+ $(patsubst %,$(CTRL_INC_DIR)/%,$(MENUGUI_INC_CTRL)) \
+ $(patsubst %,$(SAVE_INC_DIR)/%,$(MENUGUI_INC_SAVE))
+MENUGUI_INC_DIRS = -I $(INC_DIR) \
+ -I $(LIBALX_INC_DIR) \
+ -I $(ABOUT_INC_DIR) \
+ -I $(CTRL_INC_DIR) \
+ -I $(GAME_INC_DIR) \
+ -I $(SAVE_INC_DIR)
+
# target: dependencies
# action
@@ -122,6 +142,10 @@ menu_tui.o: $(MENUTUI_DEPS)
$(Q)$(CC) $(CFLAGS) $(MENUTUI_INC_DIRS) -c $< -o $@
@echo "\tCC $@"
+menu_gui.o: $(MENUGUI_DEPS)
+ $(Q)$(CC) $(CFLAGS) $(MENUGUI_INC_DIRS) -c $< -o $@
+ @echo "\tCC $@"
+
clean:
$(Q)rm -f *.o
diff --git a/modules/menu/src/menu_gui.c b/modules/menu/src/menu_gui.c
new file mode 100644
index 0000000..23e9bff
--- /dev/null
+++ b/modules/menu/src/menu_gui.c
@@ -0,0 +1,448 @@
+/******************************************************************************
+ * Copyright (C) 2015 Alejandro Colomar Andrés *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+/* * * * * * * * * *
+ * * * Standard * * * * * *
+ * * * * * * * * * */
+ #include <gtk/gtk.h>
+ /* INFINITY */
+ #include <math.h>
+ #include <stdbool.h>
+ /* srand() */
+ #include <stdlib.h>
+
+/* * * * * * * * * *
+ * * * Other * * * * * * *
+ * * * * * * * * * */
+ #include "about.h"
+ #include "game_iface.h"
+ #include "save.h"
+ #include "score.h"
+ #include "start.h"
+
+ #include "menu_iface.h"
+
+ #include "menu_gui.h"
+
+
+/******************************************************************************
+ ******* macros ***************************************************************
+ ******************************************************************************/
+ # define ROWS_GUI_MAX (22)
+#if (ROWS_GUI_MAX > ROWS_MAX)
+# error "rows max (tui)"
+#endif
+
+ # define COLS_GUI_MAX (33)
+#if (COLS_GUI_MAX > COLS_MAX)
+# error "cols max (tui)"
+#endif
+
+
+/******************************************************************************
+ ******* variables ************************************************************
+ ******************************************************************************/
+GtkWidget *window_gui;
+
+
+/******************************************************************************
+ ******* static functions *****************************************************
+ ******************************************************************************/
+#if 0
+static void menu_tui_continue (void);
+static void menu_tui_select (void);
+static void menu_tui_level (void);
+static void menu_tui_custom (void);
+static void menu_tui_devel (void);
+static void menu_tui_verbose (void);
+#endif
+
+
+/******************************************************************************
+ ******* main *****************************************************************
+ ******************************************************************************/
+void menu_gui_init (void)
+{
+ window_gui = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+}
+
+void menu_gui (void)
+{
+ gtk_widget_show(window_gui);
+ gtk_main();
+
+#if 0
+ alx_resume_curses();
+
+ /* Menu dimensions & options */
+ int h;
+ int w;
+ h = 10;
+ w = 34;
+ int N;
+ N = 4;
+ struct Alx_Menu mnu[4] = {
+ {7, 4, "[0] Exit program"},
+ {2, 4, "[1] Continue"},
+ {4, 4, "[2] Disclaimer of warranty"},
+ {5, 4, "[3] Terms and conditions"}
+ };
+
+ /* Menu */
+ bool wh;
+ int sw;
+ wh = true;
+ while (wh) {
+ /* Menu loop */
+ sw = alx_menu(h, w, N, mnu, "MENU:");
+
+ /* Selection */
+ switch (sw) {
+ case 0:
+ wh = false;
+ break;
+
+ case 1:
+ menu_tui_continue();
+ break;
+
+ case 2:
+ alx_pause_curses();
+ print_disclaim();
+ getchar();
+ alx_resume_curses();
+ break;
+
+ case 3:
+ alx_pause_curses();
+ print_license();
+ getchar();
+ alx_resume_curses();
+ break;
+ }
+ }
+
+ alx_pause_curses();
+#endif
+}
+
+
+/******************************************************************************
+ ******* static functions *****************************************************
+ ******************************************************************************/
+#if 0
+static void menu_tui_continue (void)
+{
+ /* Menu dimensions & options */
+ WINDOW *win;
+ int h;
+ int w;
+ int r;
+ int c;
+ h = 18;
+ w = 50;
+ r = 1;
+ c = (80 - w) / 2;
+ int N;
+ /* N = 7 if DEVEL option is enabled */
+ N = 6;
+ struct Alx_Menu mnu[6] = {
+ {11, 4, "[0] Back"},
+ {2, 4, "[1] Start"},
+ {4, 4, "[2] Select map"},
+ {5, 4, "[3] Change difficulty"},
+ {6, 4, "[4] Change file name"},
+ {7, 4, "[5] Hi scores"}/*,
+ {9, 4, "[6] DEVEL"}*/
+ };
+
+ /* Input box */
+ int w2;
+ int r2;
+ w2 = w - 8;
+ r2 = r + h - 5;
+ char *txt[] = {"File name:"};
+
+ /* Menu */
+ bool wh;
+ int sw;
+ wh = true;
+ while (wh) {
+ /* Menu loop */
+ win = newwin(h, w, r, c);
+ mvwprintw(win, mnu[4].r, mnu[4].c, "%s (File: \"%s\")", mnu[4].t, saved_name);
+ wrefresh(win);
+ sw = alx_menu_2(win, N, mnu, "CONTINUE:");
+
+ /* Selection */
+ switch (sw) {
+ case 0:
+ alx_win_del(win);
+ wh = false;
+ break;
+
+ case 1:
+ alx_win_del(win);
+ alx_pause_curses();
+ start_switch();
+ alx_resume_curses();
+ break;
+
+ case 2:
+ alx_win_del(win);
+ menu_tui_select();
+ break;
+
+ case 3:
+ alx_win_del(win);
+ menu_tui_level();
+ break;
+
+ case 4:
+ save_clr();
+ alx_w_getfname(saved_path, saved_name, true, w2, r2,
+ txt[0], NULL);
+ alx_win_del(win);
+ break;
+
+ case 5:
+ alx_win_del(win);
+ alx_pause_curses();
+ read_scores();
+ getchar();
+ alx_resume_curses();
+ break;
+/*
+ case 6:
+ alx_win_del(win);
+ menu_tui_devel();
+ break;
+*/
+ }
+ }
+}
+
+static void menu_tui_select (void)
+{
+ /* 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"}
+ };
+
+ /* 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);
+
+ /* Selection */
+ switch (sw) {
+ case 1:
+ start_mode = START_RAND;
+ break;
+
+ case 2:
+ start_mode = START_LOAD;
+ break;
+ }
+
+}
+
+static void menu_tui_level (void)
+{
+ /* 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"}
+ };
+
+ /* Menu loop */
+ int sw;
+ sw = alx_menu(h, w, N, mnu, "SELECT LEVEL:");
+
+ /* 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();
+ break;
+ }
+
+}
+
+static void menu_tui_custom (void)
+{
+ /* 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);
+
+ /* 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);
+
+ /* Selection */
+ sw = alx_menu_2(win, N, mnu, "Custom:");
+
+ 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);
+ break;
+
+ case 2:
+ 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);
+ break;
+ }
+
+ }
+
+ /* Cleanup */
+ alx_win_del(win);
+}
+
+static void menu_tui_devel (void)
+{
+ 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);
+
+ /* Menu loop */
+ bool wh;
+ int sw;
+ wh = true;
+ int seed;
+ while (wh) {
+ /* Selection */
+ sw = alx_menu_2(win, N, mnu, "DEVELOPER OPTIONS:");
+
+ switch (sw) {
+ case 0:
+ wh = false;
+ break;
+
+ case 1:
+ seed = alx_w_getint(w2, r2, txt[0],
+ -INFINITY, 1, INFINITY, NULL);
+ srand(seed);
+ break;
+ }
+ }
+
+ /* Cleanup */
+ alx_win_del(win);
+}
+#endif
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/modules/menu/src/menu_iface.c b/modules/menu/src/menu_iface.c
index 3394293..19ce393 100644
--- a/modules/menu/src/menu_iface.c
+++ b/modules/menu/src/menu_iface.c
@@ -20,6 +20,7 @@
#include "menu_clui.h"
#include "menu_tui.h"
+ #include "menu_gui.h"
#include "menu_iface.h"
@@ -43,6 +44,21 @@ void menu_iface_init (void)
menu_iface_variables.p = 0.16;
}
+void menu_iface_init_iface (void)
+{
+ switch (menu_iface_mode) {
+ case MENU_IFACE_CLUI:
+ break;
+
+ case MENU_IFACE_TUI:
+ break;
+
+ case MENU_IFACE_GUI:
+ menu_gui_init();
+ break;
+ }
+}
+
void menu_iface_board (int *level, int *rows, int *cols, int *mines)
{
*level = menu_iface_variables.level;
@@ -103,6 +119,7 @@ void menu_iface (void)
break;
case MENU_IFACE_GUI:
+ menu_gui();
break;
}
}
diff --git a/modules/menu/src/parser.c b/modules/menu/src/parser.c
index 8449e59..fc2aaf1 100644
--- a/modules/menu/src/parser.c
+++ b/modules/menu/src/parser.c
@@ -185,9 +185,9 @@ static void parse_iface (char* argument)
{
menu_iface_mode = atoi(argument);
player_iface_mode = menu_iface_mode;
- if (menu_iface_mode < MENU_IFACE_CLUI || menu_iface_mode > MENU_IFACE_TUI) {
+ if (menu_iface_mode < MENU_IFACE_CLUI || menu_iface_mode > MENU_IFACE_GUI) {
printf("--iface argument not valid\n");
- printf("It must be an integer [%i U %i]\n", MENU_IFACE_CLUI, MENU_IFACE_TUI);
+ printf("It must be an integer [%i U %i]\n", MENU_IFACE_CLUI, MENU_IFACE_GUI);
exit(EXIT_FAILURE);
}
}
diff --git a/src/main.c b/src/main.c
index 3559ef7..0698866 100644
--- a/src/main.c
+++ b/src/main.c
@@ -9,6 +9,7 @@
/* * * * * * * * * *
* * * Standard * * * * * *
* * * * * * * * * */
+ #include <gtk/gtk.h>
/* getchar() */
#include <stdio.h>
@@ -31,7 +32,7 @@
/******************************************************************************
******* static functions *****************************************************
******************************************************************************/
-void init_all (void);
+void init_all (int *argc, char *(*argv[]));
void cleanup (void);
@@ -40,10 +41,7 @@ void cleanup (void);
******************************************************************************/
int main (int argc, char *argv[])
{
- init_all();
-
- /* Parse command line options */
- parser(argc, argv);
+ init_all(&argc, &argv);
/* Print copyright () and wait for any key to continue */
print_cpright();
@@ -64,12 +62,15 @@ int main (int argc, char *argv[])
/******************************************************************************
******* static functions *****************************************************
******************************************************************************/
-void init_all (void)
+void init_all (int *argc, char *(*argv[]))
{
- /* Init modules */
+ /* Init gtk & curses */
+ gtk_init_check(argc, argv);
alx_start_curses();
- menu_iface_init();
alx_pause_curses();
+
+ /* Init modules */
+ menu_iface_init();
game_init();
about_init();
save_init();
@@ -80,6 +81,12 @@ void init_all (void)
flag_exit = false;
menu_iface_mode = MENU_IFACE_TUI;
player_iface_mode = PLAYER_IFACE_TUI;
+
+ /* Parse command line options */
+ parser(*argc, *argv);
+
+ /* Init iface */
+ menu_iface_init_iface();
}
void cleanup (void)