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
+wordblox_player: wordblox_player.c wordblox.h 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`
+ clang -rdynamic -lz -lgd -lcrypt -o wordblox_player wordblox_player.c -Wall `pkg-config --cflags --libs gtk+-3.0`
/* for wordblox_player */
#define ERROR_ICON "Unable to load icon!"
#define ERROR_WINDOW "Error loading Window!"
+#define OPEN_FILE "Open File"
+#define UNFROZEN_GRID_PLAYER "Puzzle is not finalized/frozen and hence cannot\
+ be played"
/* about box info */
const char *AUTHOR[] = { "V. Harishankar", NULL};
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
-#include <stdbool.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#define __WORDBLOX_H
#define _XOPEN_SOURCE
#include <unistd.h>
+#include <stdbool.h>
+#include <string.h>
+#include <ctype.h>
#include <gd.h>
#include <gdfontmb.h>
#include <gdfontg.h>
gzFile outdestfile = gzopen (file, "wb");
if (outdestfile == NULL)
{
- fprintf (stderr, ERROR_WRITING_FILE);
+ fprintf (stderr, "%s\n", ERROR_WRITING_FILE);
fclose (outfile);
exit (1);
}
int res = gzwrite (outdestfile, buf, strlen (buf) );
if (res == 0)
{
- fprintf (stderr, "%s %s", ERROR_WRITING_FILE, COMPRESSED);
+ fprintf (stderr, "%s %s\n", ERROR_WRITING_FILE, COMPRESSED);
fclose (outfile);
exit (1);
}
gzFile insourcefile = gzopen (file, "rb");
if (insourcefile == NULL)
{
- fprintf (stderr, "%s %s", ERROR_READING_FILE, COMPRESSED);
+ fprintf (stderr, "%s %s\n", ERROR_READING_FILE, COMPRESSED);
exit (1);
}
/* Open a temporary file to uncompress the contents */
FILE *infile = tmpfile ();
if (infile == NULL)
{
- fprintf (stderr, ERROR_READING_FILE);
+ fprintf (stderr, "%s\n", ERROR_READING_FILE);
exit (1);
}
/* Put the uncompressed content to the temp file */
int res = fwrite (buf, sizeof(char), strlen (buf), infile);
if (res == 0)
{
- fprintf (stderr, ERROR_READING_FILE);
+ fprintf (stderr, "%s\n", ERROR_READING_FILE);
fclose (infile);
gzclose (insourcefile);
exit (1);
#include "constantstrings.h"
#include "wordblox_resource.c"
+#include "wordblox.h"
+
+GtkWidget *window;
+
+/* slot for drawing the puzzle */
+gboolean on_puzzle_area_draw (GtkWidget *widget, cairo_t *cr, gpointer data)
+{
+ GdkRGBA colorfore, colorback;
+ gdk_rgba_parse (&colorfore, "#000000");
+ gdk_rgba_parse (&colorback, "#ffffff");
+ cairo_set_line_width (cr, 3);
+ gtk_widget_set_size_request (widget, 10*30+5, 10*30+5);
+ for (int i = 0; i < 10; i ++)
+ {
+ for (int j = 0; j < 10; j ++)
+ {
+ cairo_rectangle (cr, i*30+5, j*30+5, 30, 30);
+ gdk_cairo_set_source_rgba (cr, &colorfore);
+ cairo_stroke (cr);
+
+ cairo_rectangle (cr, i*30+5, j*30+5, 30, 30);
+ gdk_cairo_set_source_rgba (cr, &colorback);
+ cairo_fill (cr);
+ }
+ }
+
+ return FALSE;
+
+}
/* slot for exit menu */
void on_menu_exit_activate (GtkMenuItem *item, gpointer data)
gtk_main_quit ();
}
+/* slot for open menu */
+void on_menu_open_activate (GtkMenuItem *item, gpointer data)
+{
+ GtkWidget *dialog;
+ GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
+ gint res;
+ dialog = gtk_file_chooser_dialog_new (OPEN_FILE, GTK_WINDOW(window), action,
+ "_Cancel",
+ GTK_RESPONSE_CANCEL,
+ "_Open",
+ GTK_RESPONSE_ACCEPT,
+ NULL);
+ res = gtk_dialog_run (GTK_DIALOG (dialog));
+ if (res == GTK_RESPONSE_ACCEPT)
+ {
+ char *filename;
+ filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(dialog));
+ Puzzle p = load_puzzle (filename);
+ /* if the grid is not frozen then the game cannot be played */
+ if (p.grid_frozen == false)
+ {
+ GtkWidget *errordlg ;
+ errordlg = gtk_message_dialog_new (GTK_WINDOW(window),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ UNFROZEN_GRID_PLAYER);
+ gtk_dialog_run (GTK_DIALOG(errordlg));
+ gtk_widget_destroy (errordlg);
+
+ }
+
+ g_free (filename);
+ }
+
+ gtk_widget_destroy (dialog);
+}
+
/* 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,
+ gtk_show_about_dialog (GTK_WINDOW(window), "authors",AUTHOR,
"program-name", PROGRAM_NAME,
"copyright", COPYRIGHT,
"comments", COMMENTS,
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);
-
+
+ GtkBuilder *builder;
builder = gtk_builder_new ();
guint ret = gtk_builder_add_from_resource (builder,
"/org/harishankar/wordblox/wordblox_player.glade", NULL);
}
else
{
- window = GTK_WINDOW (gtk_builder_get_object (builder, "main_window") );
+ window = GTK_WIDGET (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_widget_show (window);
gtk_main ();
return 0;
}
<column type="gchararray"/>
</columns>
</object>
- <object class="GtkApplicationWindow" id="main_window">
+ <object class="GtkWindow" id="main_window">
<property name="can_focus">False</property>
<property name="title" translatable="yes">Wordblox Player</property>
<property name="default_width">540</property>
<property name="default_height">400</property>
- <signal name="destroy" handler="gtk_main_quit" swapped="no"/>
+ <signal name="destroy" handler="on_menu_exit_activate" swapped="no"/>
<child type="titlebar">
<placeholder/>
</child>
<property name="can_focus">True</property>
<child>
<object class="GtkScrolledWindow">
- <property name="width_request">70</property>
+ <property name="width_request">80</property>
+ <property name="height_request">80</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
+ <child>
+ <object class="GtkViewport">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="hscroll_policy">natural</property>
+ <property name="vscroll_policy">natural</property>
+ <child>
+ <object class="GtkDrawingArea" id="puzzle_area">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <signal name="draw" handler="on_puzzle_area_draw" swapped="no"/>
+ </object>
+ </child>
+ </object>
+ </child>
</object>
<packing>
<property name="resize">True</property>