From: Harishankar Date: Sat, 2 May 2020 12:13:30 +0000 (+0530) Subject: Started work on the GUI for the wordblox player X-Git-Tag: 0.1a~18 X-Git-Url: https://harishankar.org/repos/?p=wordblah.git;a=commitdiff_plain;h=0928dab5614bccdf0f4839833b93e66005f5dff0 Started work on the GUI for the wordblox player Started work on GTK+ GUI for the wordblox player. --- diff --git a/Makefile b/Makefile index 90cbb91..23de2da 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,6 @@ wordblox: wordblox.c wordblox.h constantstrings.h clang wordblox.c -lgd -lz -lcrypt -o wordblox +wordblox_player: wordblox_player.c wordblox_resource.c wordblox.gresource.xml wordblox_player.glade constantstrings.h + glib-compile-resources wordblox.gresource.xml --target wordblox_resource.c --generate-source + clang -rdynamic -o wordblox_player wordblox_player.c -Wall `pkg-config --cflags --libs gtk+-3.0` diff --git a/constantstrings.h b/constantstrings.h index 6b8a0bb..1c0dd49 100644 --- a/constantstrings.h +++ b/constantstrings.h @@ -1,6 +1,7 @@ #ifndef __CONSTANTSTRINGS_H #define __CONSTANTSTRINGS_H +#define VERSION "0.1a" #define FROZEN_GRID "Grid is frozen. Unfreeze grid first!" #define UNFROZEN_GRID "Grid is unfrozen. Freeze grid first!" #define EXCEED_GRID_SIZE "Row/col exceeded grid size!" @@ -38,6 +39,18 @@ and is irreversible (y/N): " #define USAGE_LINE_3 "new - create new puzzle with grid \ columns (warning: existing file name may be overwritten)\n" +/* for wordblox_player */ +#define ERROR_ICON "Unable to load icon!" +#define ERROR_WINDOW "Error loading Window!" + +/* about box info */ +const char *AUTHOR[] = { "V. Harishankar", NULL}; +const char *COPYRIGHT = "Copyright 2020 V.Harishankar"; +const char *COMMENTS = "A player for wordblox (crossword puzzles)"; +const char *PROGRAM_NAME = "Wordblox Player"; +const char *WEBSITE = "http://harishankar.org/"; +const char *WEBSITE_LABEL = "Author's HomePage"; + char *MAIN_MENU[] = {"1. New puzzle", "2. Open existing puzzle", diff --git a/wordblox.gresource.xml b/wordblox.gresource.xml new file mode 100644 index 0000000..ae2f5f0 --- /dev/null +++ b/wordblox.gresource.xml @@ -0,0 +1,8 @@ + + + + + wordblox_player.glade + wordblox.svg + + diff --git a/wordblox.svg b/wordblox.svg new file mode 100644 index 0000000..d7e6745 --- /dev/null +++ b/wordblox.svg @@ -0,0 +1,106 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + diff --git a/wordblox_player.c b/wordblox_player.c new file mode 100644 index 0000000..cf9e0bc --- /dev/null +++ b/wordblox_player.c @@ -0,0 +1,69 @@ +#include + +#include "constantstrings.h" +#include "wordblox_resource.c" + +/* slot for exit menu */ +void on_menu_exit_activate (GtkMenuItem *item, gpointer data) +{ + gtk_main_quit (); +} + +/* slot for about menu */ +void on_menu_about_activate (GtkMenuItem *item, gpointer data) +{ + const char *AUTHOR[] = {"V.Harishankar", NULL}; + gtk_show_about_dialog (NULL, "authors",AUTHOR, + "program-name", PROGRAM_NAME, + "copyright", COPYRIGHT, + "comments", COMMENTS, + "website", WEBSITE, + "website-label", WEBSITE_LABEL, + "license-type", GTK_LICENSE_GPL_2_0, + "version", VERSION, + (char*)NULL); +} + +int main (int argc, char *argv []) +{ + gtk_init (&argc, &argv); + GtkBuilder *builder; + GtkWindow *window; + GdkPixbuf *icon; + + icon = gdk_pixbuf_new_from_resource + ("/org/harishankar/wordblox/wordblox.svg", NULL); + if (icon == NULL) + fprintf (stderr, ERROR_ICON); + + builder = gtk_builder_new (); + guint ret = gtk_builder_add_from_resource (builder, + "/org/harishankar/wordblox/wordblox_player.glade", NULL); + + if (ret == 0) + { + fprintf (stderr, ERROR_WINDOW); + g_object_unref (builder); + return 1; + } + else + { + window = GTK_WINDOW (gtk_builder_get_object (builder, "main_window") ); + if (window != NULL) + { + gtk_window_set_default_icon (icon); + + gtk_builder_connect_signals (builder, NULL); + g_object_unref (builder); + gtk_widget_show (GTK_WIDGET(window)); + gtk_main (); + return 0; + } + else + { + g_object_unref (builder); + fprintf (stderr, ERROR_WINDOW); + return 1; + } + } +}