Commit 7c5eab2c authored by Colomban Wendling's avatar Colomban Wendling
Browse files

Import base of OVCC-GTK, a GTK+ client.

parent 16c9e918
#!/bin/bash
## have() check for a program
# Usage: have [-r|-o] [-m <error message>] <program>
#
# Options:
# -o: The <program> is optional; don't exit on failure [default]
# -r: The <program> is required; exit if not found
# -m <message>: Message to show if program is not found in place of the
# default one.
have () {
local optional=true, message=""
for o; do
case "$o" in
-o) optional=true;;
-r) optional=false;;
-m) message="$1"; shift;;
*) break;;
esac
shift
done
echo -n "checking for \`$1'... "
cmd="`which "$1" 2>/dev/null`"
if [ "x$cmd" = "x" ]; then
echo "not found!" >&2
if [ "x$message" != "x" ]; then
echo "$message" >&2
else
echo "The program \`$1' cannot be found on your system." >&2
if $optional; then
echo "Continuing without." >&2
else
echo "Cannot continue without it;" \
"please fix this problem and retry." >&2
fi
fi
$optional && return 1 || exit 127
else
echo "ok, \`$cmd'."
fi
return 0
}
# check for needed autotools
have -r automake
have -r autoconf
have -r autoheader
have -r autoreconf
have -r libtool
have -r libtoolize
have -r gtkdocize
mkdir -p build/aux || exit 1
mkdir -p build/m4 || exit 1
#gtkdocize --flavour no-tmpl || exit 1;
autoreconf -vfi || exit 1
#~ ./configure "$@"
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.63])
AC_INIT([ovcc-gtk], [0.0], [dev@ovcc.tuxfamily.org])
AC_CONFIG_SRCDIR([src/ovcc-gtk.c])
AC_CONFIG_AUX_DIR([build/aux])
AC_CONFIG_MACRO_DIR([build/m4])
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
AC_CONFIG_HEADERS([config.h])
m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
ovccgtkdatadir="${datadir}/ovcc-gtk/"
AC_SUBST([ovccgtkdatadir])
# Checks for programs.
AC_PROG_CC
AM_PROG_VALAC([0.7])
# check for gtk-doc
#GTK_DOC_CHECK(1.11)
# Checks for libraries.
GLIB_REQUIRE=2.12
GMODULE_REQUIRE=2.0
GTK_REQUIRE=2.12
OVCC_REQUIRE=0.0
PKG_CHECK_MODULES([OVCCGTK], [glib-2.0 >= ${GLIB_REQUIRE}
gthread-2.0 >= ${GLIB_REQUIRE}
gmodule-export-2.0 >= ${GMODULE_REQUIRE}
gtk+-2.0 >= ${GTK_REQUIRE}
ovcc >= ${OVCC_REQUIRE}])
CFLAGS="${CFLAGS} ${OVCCGTK_CFLAGS} -Werror-implicit-function-declaration"
LIBS="${LIBS} ${OVCCGTK_LIBS}"
VALAFLAGS="${VALAFLAGS} --pkg=glib-2.0 --pkg=gtk+-2.0 --pkg=ovcc --vapidir=/tmp/test"
AC_SUBST(VALAFLAGS)
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
# Paranoiac (debugging) options
AC_ARG_ENABLE([paranoia],
AC_HELP_STRING([--enable-paranoia],
[enable excessively strict compiler options \
(works only with GCC and compatible) [[default=no]]]),
[enable_paranoia="$enableval"],
[enable_paranoia="no"])
AC_MSG_CHECKING([[whether to enable paranoiac compiler options]])
if test "x$enable_paranoia" = "xyes"; then
CFLAGS="$CFLAGS \
-Wall -W -Wchar-subscripts -Wcomment -Wformat=2 -Wimplicit-int \
-Werror-implicit-function-declaration -Wmain -Wparentheses -Wsequence-point \
-Wreturn-type -Wswitch -Wtrigraphs -Wunused -Wuninitialized -Wunknown-pragmas \
-Wfloat-equal -Wundef -Wshadow -Wpointer-arith -Wbad-function-cast \
-Wwrite-strings -Wconversion -Wsign-compare -Waggregate-return \
-Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations \
-Wmissing-noreturn -Wformat -Wmissing-format-attribute \
-Wno-deprecated-declarations -Wpacked -Wredundant-decls -Wnested-externs \
-Winline -Wlong-long -Wunreachable-code -pedantic"
AC_MSG_RESULT([[yes]])
else
AC_MSG_RESULT([[no]])
fi
AC_CONFIG_FILES([Makefile
src/Makefile
])
AC_OUTPUT
bin_PROGRAMS = ovcc-gtk
ovcc_gtk_VALAFLAGS = $(VALAFLAGS)
ovcc_gtk_CFLAGS = $(CFLAGS) -Wl,--export-dynamic \
-DDATADIR='"$(ovccgtkdatadir)"'
ovcc_gtk_SOURCES = ovcc-gtk.c \
board-widget.c \
utils.c \
tiles.c \
#board.vala
/*
*
* Copyright (C) 2009 Colomban Wendling <ban@herbesfolles.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "board-widget.h"
#include <gtk/gtk.h>
#include "tiles.h"
typedef struct _OVCCGtkBoardPrivate OVCCGtkBoardPrivate;
#define GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), OVCCGTK_BOARD_TYPE, OVCCGtkBoardPrivate))
struct _OVCCGtkBoardPrivate
{
/*OVCCBoard *board;*/
};
static gboolean ovccgtk_board_expose (GtkWidget *self,
GdkEventExpose *event);
static void ovccgtk_board_set_scroll_adjustments (OVCCGtkBoard *board,
GtkAdjustment *hadjustment,
GtkAdjustment *vadjustment);
G_DEFINE_TYPE (OVCCGtkBoard, ovccgtk_board, GTK_TYPE_DRAWING_AREA)
static void ovccgtk_board_class_init (OVCCGtkBoardClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
widget_class->expose_event = ovccgtk_board_expose;
klass->set_scroll_adjustments = ovccgtk_board_set_scroll_adjustments;
/*widget_class->set_scroll_adjustments_signal =
g_signal_new ("set-scroll-adjustments",
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (OVCCGtkBoardClass, set_scroll_adjustments),
NULL, NULL,
_gtk_marshal_VOID__OBJECT_OBJECT,
G_TYPE_NONE, 2,
GTK_TYPE_ADJUSTMENT,
GTK_TYPE_ADJUSTMENT);*/
/*g_type_class_add_private ((gpointer)klass, sizeof(OVCCGtkBoardPrivate));*/
}
static void ovccgtk_board_init (OVCCGtkBoard *self)
{
}
static void
ovccgtk_board_set_scroll_adjustments (OVCCGtkBoard *board,
GtkAdjustment *hadjustment,
GtkAdjustment *vadjustment)
{
}
static gboolean
ovccgtk_board_expose (GtkWidget *self,
GdkEventExpose *event)
{
GdkGC *gc = self->style->fg_gc[GTK_WIDGET_STATE (self)];
guint x, y;
gdk_gc_set_clip_region (gc, event->region);
/*gdk_draw_arc (self->window, gc,
TRUE,
0, 0, self->allocation.width, self->allocation.height,
0, 64 * 360);*/
for (x = 0; x < self->allocation.width; ) {
guint w = 0;
for (y = 0; y < self->allocation.height; ) {
GdkPixbuf *pix;
guint h;
pix = tile_get_pixbuf (/*g_random_int_range (1, 72)*/
(((x+1) * (y+1)) % 72) + 1);
w = gdk_pixbuf_get_width (pix);
h = gdk_pixbuf_get_height (pix);
gdk_draw_pixbuf (self->window, gc, pix, 0, 0, x, y, w, h,
GDK_RGB_DITHER_NORMAL, 0, 0);
y += h + 1;
}
x += w + 1;
}
return TRUE;
}
GtkWidget *ovccgtk_board_new (void)
{
return g_object_new (OVCCGTK_BOARD_TYPE, NULL);
}
/*
*
* Copyright (C) 2009 Colomban Wendling <ban@herbesfolles.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef H_OVCCGTK_BOARD_WIDGET
#define H_OVCCGTK_BOARD_WIDGET
#include <glib.h>
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define OVCCGTK_BOARD_TYPE (ovccgtk_board_get_type ())
#define OVCCGTK_BOARD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), OVCCGTK_BOARD_TYPE, OVCCGtkBoard))
#define OVCCGTK_BOARD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), OVCCGTK_BOARD_TYPE, OVCCGtkBoardClass))
#define IS_OVCCGTK_BOARD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), OVCCGTK_BOARD_TYPE))
#define IS_OVCCGTK_BOARD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), OVCCGTK_BOARD_TYPE))
typedef struct _OVCCGtkBoard OVCCGtkBoard;
typedef struct _OVCCGtkBoardClass OVCCGtkBoardClass;
struct _OVCCGtkBoard
{
GtkDrawingArea parent;
};
struct _OVCCGtkBoardClass
{
GtkDrawingAreaClass parent_class;
void (*set_scroll_adjustments) (OVCCGtkBoard *board,
GtkAdjustment *hadjustment,
GtkAdjustment *vadjustment);
};
GType ovccgtk_board_get_type (void) G_GNUC_CONST;
GtkWidget *ovccgtk_board_new (void);
G_END_DECLS
#endif /* guard */
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include "utils.h"
#include "tiles.h"
#include "board-widget.h"
#define UI_FILE "ovcc-gtk.ui"
static gboolean
load_ui (GtkBuilder *builder,
const gchar *filename)
{
GError *err = NULL;
gboolean loaded = FALSE;
gchar *path = data_get_path (filename);
loaded = gtk_builder_add_from_file (builder, path, &err) > 0;
if (! loaded) {
GtkWidget *dialog;
dialog = gtk_message_dialog_new (NULL, 0,
GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
_("Failed to load UI file \"%s\""),
path);
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
"%s", err->message);
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
}
g_free (path);
return loaded;
}
G_MODULE_EXPORT gboolean
main_window_delete_event_cb (GtkWidget *window,
GdkEvent *event,
gpointer data)
{
gtk_main_quit ();
return FALSE;
}
static gboolean
ovcc_gtk (int argc,
char **argv)
{
GtkBuilder *builder;
gboolean success = FALSE;
builder = gtk_builder_new ();
if (load_ui (builder, UI_FILE)) {
GtkWidget *window;
GtkWidget *board_cnt;
GtkWidget *players_cnt;
GtkWidget *current_tile_image;
gtk_builder_connect_signals (builder, NULL);
window = GTK_WIDGET (gtk_builder_get_object (builder, "main-window"));
board_cnt = GTK_WIDGET (gtk_builder_get_object (builder, "board-container"));
players_cnt = GTK_WIDGET (gtk_builder_get_object (builder, "players-container"));
current_tile_image = GTK_WIDGET (gtk_builder_get_object (builder, "current-tile-image"));
{
GtkWidget *viewport;
viewport = gtk_viewport_new (NULL, NULL);
gtk_container_add (GTK_CONTAINER (viewport), ovccgtk_board_new ());
gtk_container_add (GTK_CONTAINER (board_cnt), viewport);
}
gtk_image_set_from_pixbuf (GTK_IMAGE (current_tile_image),
tile_get_pixbuf (1));
gtk_widget_show_all (window);
gtk_main ();
success = TRUE;
}
return success;
}
int
main (int argc,
char **argv)
{
int rv = 1;
if (! g_thread_supported ()) {
g_thread_init (NULL);
}
gdk_threads_init ();
gtk_init (&argc, &argv);
gdk_threads_enter ();
rv = ovcc_gtk (argc, argv) ? 0 : 1;
gdk_threads_leave ();
return rv;
}
/*
*
* Copyright (C) 2009 Colomban Wendling <ban@herbesfolles.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "tiles.h"
#include <glib/gi18n.h>
#include <gdk/gdk.h>
#include "utils.h"
static GHashTable *ST_loaded_tiles = NULL;
#define ENSURE_HAVE_TABLE \
G_STMT_START { \
if G_UNLIKELY (ST_loaded_tiles == NULL) { \
ST_loaded_tiles = g_hash_table_new_full (NULL, NULL, \
NULL, (GDestroyNotify)gdk_pixbuf_unref); \
} \
} G_STMT_END
#define LOOKUP(id) \
(g_hash_table_lookup (ST_loaded_tiles, GINT_TO_POINTER (id)))
#define INSERT(id, pix) \
(g_hash_table_insert (ST_loaded_tiles, GINT_TO_POINTER (id), pix))
/* Invalid tile XPM image */
static const gchar * tile_invalid_xpm[] = {
"64 64 2 1",
" c #FF0000",
". c #FFFFFF",
" .................................................. ",
" ................................................ ",
" .............................................. ",
" ............................................ ",
" .......................................... ",
" ........................................ ",
" ...................................... ",
". .................................... .",
".. .................................. ..",
"... ................................ ...",
".... .............................. ....",
"..... ............................ .....",
"...... .......................... ......",
"....... ........................ .......",
"........ ...................... ........",
"......... .................... .........",
".......... .................. ..........",
"........... ................ ...........",
"............ .............. ............",
"............. ............ .............",
".............. .......... ..............",
"............... ........ ...............",
"................ ...... ................",
"................. .... .................",
".................. .. ..................",
"................... ...................",
".................... ....................",
"..................... .....................",
"...................... ......................",
"....................... .......................",
"........................ ........................",
"......................... .........................",
"......................... .........................",
"........................ ........................",
"....................... .......................",
"...................... ......................",
"..................... .....................",
".................... ....................",
"................... ...................",
".................. .. ..................",
"................. .... .................",
"................ ...... ................",
"............... ........ ...............",
".............. .......... ..............",
"............. ............ .............",
"............ .............. ............",
"........... ................ ...........",
".......... .................. ..........",
"......... .................... .........",
"........ ...................... ........",
"....... ........................ .......",
"...... .......................... ......",
"..... ............................ .....",
".... .............................. ....",
"... ................................ ...",
".. .................................. ..",
". .................................... .",
" ...................................... ",
" ........................................ ",
" .......................................... ",
" ............................................ ",
" .............................................. ",
" ................................................ ",
" .................................................. "};
static gchar *
get_tile_path (OVCCTileID id)
{
gchar *path;
gchar *file;
file = g_strdup_printf ("tiles/carso%u.gif", id);
path = data_get_path (file);
g_free (file);
return path;
}
static GdkPixbuf *
load_tile (OVCCTileID id)
{
gchar *path;
GdkPixbuf *pixbuf;
GError *err = NULL;
path = get_tile_path (id);
pixbuf = gdk_pixbuf_new_from_file (path, &err);
if (! pixbuf) {
/*g_warning ("Failed to load tile #%d: %s", id, err->message);*/
msg_error /*msg_warning*/ (_("Failed to load tile #%d: %s"), id, err->message);
g_error_free (err);
pixbuf = gdk_pixbuf_new_from_xpm_data (tile_invalid_xpm);
} /*else*/ {
INSERT (id, pixbuf);
}
return pixbuf;
}
GdkPixbuf *
tile_get_pixbuf (OVCCTileID id)
{
GdkPixbuf *pixbuf;
ENSURE_HAVE_TABLE;
pixbuf = LOOKUP (id);
if (! pixbuf) {
pixbuf = load_tile (id);
}
return pixbuf;
}
gboolean
tile_exists (OVCCTileID id)
{
return tile_get_pixbuf (id) != NULL;
}
/*
*
* Copyright (C) 2009 Colomban Wendling <ban@herbesfolles.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef H_OVCCGTK_TILES
#define H_OVCCGTK_TILES
#include <glib.h>
#include <gdk/gdk.h>
#include "ovcc/tile.h"