Commit 231da2d1 authored by ruxandraS's avatar ruxandraS Committed by Robert Roth

Use libgnome-games-support

parent 8d25c941
......@@ -27,6 +27,7 @@ PKG_CHECK_MODULES(FIVE_OR_MORE, [
glib-2.0 >= $GLIB_REQUIRED
gio-2.0 >= $GLIB_REQUIRED
gtk+-3.0 >= $GTK_REQUIRED
libgnome-games-support-1
librsvg-2.0 >= $RSVG_REQUIRED
])
......
......@@ -15,11 +15,12 @@ pkgdata_dir = join_paths (data_dir, 'five-or-more')
# Dependencies
glib_min_version = '2.32'
librsvg = dependency('librsvg-2.0', version: '>= 2.32.0')
gio = dependency('gio-2.0', version: '>= ' + glib_min_version)
glib = dependency('glib-2.0', version: '>= ' + glib_min_version)
gmodule_export = dependency('gmodule-export-2.0')
gtk = dependency('gtk+-3.0', version: '>= 3.20.0')
libgnome_games_support = dependency('libgnome-games-support-1')
librsvg = dependency('librsvg-2.0', version: '>= 2.32.0')
# Libraries
cc = meson.get_compiler('c')
......
......@@ -8,7 +8,6 @@ data/menu.ui
data/org.gnome.five-or-more.gschema.xml
data/translatable_themes.h
src/five-or-more.c
src/games-scores-dialog.c
src/five-or-more-app.c
src/game-area.c
src/balls-preview.c
......@@ -8,14 +8,6 @@ five_or_more_SOURCES = \
games-gridframe.h \
games-preimage.c \
games-preimage.h \
games-score.h \
games-score.c \
games-scores.c \
games-scores.h \
games-scores-dialog.c \
games-scores-dialog.h \
games-scores-backend.c \
games-scores-backend.h \
five-or-more-app.h \
five-or-more-app.c \
balls-preview.c \
......
......@@ -33,12 +33,10 @@
#include <gtk/gtk.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gdk/gdkkeysyms.h>
#include <libgnome-games-support.h>
#include "games-file-list.h"
#include "games-preimage.h"
#include "games-gridframe.h"
#include "games-scores.h"
#include "games-scores-dialog.h"
#include "game-area.h"
#include "five-or-more-app.h"
#include "balls-preview.h"
......@@ -50,7 +48,12 @@
#define KEY_BACKGROUND_COLOR "background-color"
#define KEY_BALL_THEME "ball-theme"
static const GamesScoresCategory scorecats[] = {
typedef struct {
gchar *key;
gchar *name;
} key_value;
static const key_value scorecats[] = {
{ "Small", NC_("board size", "Small") },
{ "Medium", NC_("board size", "Medium") },
{ "Large", NC_("board size", "Large") }
......@@ -77,7 +80,11 @@ static GtkWidget *size_radio_s, *size_radio_m, *size_radio_l;
static int move_timeout = 100;
static gboolean window_is_fullscreen = FALSE, window_is_maximized = FALSE;
static gint window_width = 0, window_height = 0;
static GamesScores *highscores;
static gint no_categories = 3;
static gchar *score_current_category = NULL;
static GamesScoresContext *highscores;
static GSettings *settings;
static GtkBuilder *builder;
static GtkBuilder *builder_preferences;
......@@ -93,12 +100,6 @@ get_settings ()
return &settings;
}
const GamesScoresCategory *
get_scorecats ()
{
return scorecats;
}
gint *
get_game_size ()
{
......@@ -129,12 +130,6 @@ get_move_timeout ()
return move_timeout;
}
GamesScores *
get_highscores()
{
return highscores;
}
void
update_score (guint value)
{
......@@ -170,9 +165,11 @@ set_backgnd_color (const gchar * str)
}
static void
show_scores (gint pos)
show_scores ()
{
static GtkWidget *dialog;
games_scores_context_run_dialog (highscores);
/* static GtkWidget *dialog;
if (dialog == NULL) {
dialog = games_scores_dialog_new (GTK_WINDOW (app), highscores, _("Five or More Scores"));
......@@ -186,7 +183,7 @@ show_scores (gint pos)
gtk_window_present (GTK_WINDOW (dialog));
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_hide (dialog);
gtk_widget_hide (dialog);*/
}
static void
......@@ -205,15 +202,46 @@ load_properties (void)
load_theme ();
}
static void
add_score_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
GamesScoresContext *context = GAMES_SCORES_CONTEXT (source_object);
GError *error = NULL;
games_scores_context_add_score_finish (context, res, &error);
if (error != NULL) {
g_warning ("Failed to add score: %s", error->message);
g_error_free (error);
}
}
const gchar *
category_name_from_key (const gchar *key)
{
int i;
for (i = 0; i < no_categories; i++) {
if (g_strcmp0 (scorecats[i].key, key) == 0)
return scorecats[i].name;
}
return NULL;
}
void
game_over (void)
{
int pos;
set_status_message (_("Game Over!"));
if (score > 0)
pos = games_scores_add_plain_score (highscores, score);
show_scores (pos);
if (score > 0) {
const gchar *name = category_name_from_key (score_current_category);
GamesScoresCategory *current_category = games_scores_category_new (score_current_category, name);
games_scores_context_add_score (highscores,
score,
current_category,
NULL,
add_score_cb,
NULL);
}
show_scores ();
}
static void
......@@ -263,6 +291,8 @@ conf_value_changed_cb (GSettings *settings, gchar *key)
if (size_tmp != game_size) {
set_sizes (size_tmp);
score_current_category = scorecats[size_tmp - 1].key;
reset_game ();
start_game ();
}
......@@ -282,6 +312,7 @@ init_config (void)
game_size = CLAMP (game_size, SMALL, MAX_SIZE - 1);
set_sizes (game_size);
score_current_category = scorecats[game_size - 1].key;
}
static gboolean
......@@ -318,7 +349,7 @@ game_top_ten_callback (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
show_scores (0);
show_scores ();
}
......@@ -561,6 +592,16 @@ game_quit_callback (GSimpleAction *action,
g_application_quit (G_APPLICATION (user_data));
}
static GamesScoresCategory *
create_category_from_key (const char *key, gpointer user_data)
{
const gchar *name = category_name_from_key (key);
if (name == NULL)
return NULL;
return games_scores_category_new (key, name);
}
void
startup_cb (GApplication *application)
{
......@@ -570,6 +611,7 @@ startup_cb (GApplication *application)
GtkWidget *new_game_button;
guint i;
GError *error = NULL;
GamesScoresDirectoryImporter *importer;
GActionEntry app_actions[] = {
{ "new-game", game_new_callback },
......@@ -588,11 +630,6 @@ startup_cb (GApplication *application)
settings = g_settings_new ("org.gnome.five-or-more");
highscores = games_scores_new ("five-or-more",
scorecats, G_N_ELEMENTS (scorecats),
"board size", NULL,
0 /* default category */,
GAMES_SCORES_STYLE_PLAIN_DESCENDING);
init_config ();
builder = gtk_builder_new ();
ui_path = g_build_filename (DATA_DIRECTORY, "menu.ui", NULL);
......@@ -644,13 +681,22 @@ startup_cb (GApplication *application)
GtkWidget *draw_area = game_area_init ();
gridframe = games_grid_frame_new (get_hfieldsize(), get_vfieldsize());
gridframe = GTK_WIDGET (games_grid_frame_new (get_hfieldsize(), get_vfieldsize()));
games_grid_frame_set_padding (GAMES_GRID_FRAME (gridframe), 1, 1);
gtk_container_add (GTK_CONTAINER (gridframe), draw_area);
gtk_box_pack_start (GTK_BOX (hbox), gridframe, TRUE, TRUE, 0);
new_game_button = GTK_WIDGET (gtk_builder_get_object (builder, "new_game_button"));
importer = games_scores_directory_importer_new ();
highscores = games_scores_context_new_with_importer ("five-or-more",
_("Board Size: "),
GTK_WINDOW (app),
create_category_from_key,
NULL,
GAMES_SCORES_STYLE_POINTS_GREATER_IS_BETTER,
GAMES_SCORES_IMPORTER (importer));
load_properties ();
gtk_builder_connect_signals (builder, NULL);
......@@ -692,4 +738,4 @@ set_application_callbacks(GtkApplication *application)
g_signal_connect (application, "startup", G_CALLBACK (startup_cb), NULL);
g_signal_connect (application, "activate", G_CALLBACK (activate_cb), NULL);
g_signal_connect (application, "shutdown", G_CALLBACK (shutdown_cb), NULL);
}
\ No newline at end of file
}
......@@ -24,7 +24,6 @@
#define FIVE_OR_MORE_APP_H
#include <gtk/gtk.h>
#include "games-scores.h"
typedef struct _background background;
struct _background{
......@@ -33,7 +32,6 @@ struct _background{
gint set;
} ;
GamesScores *get_highscores ();
GtkWidget *get_gridframe ();
char *get_ball_filename ();
background get_backgnd ();
......@@ -41,11 +39,10 @@ void set_status_message (gchar * message);
void game_over (void);
void set_application_callbacks (GtkApplication *application);
gint *get_game_size ();
const GamesScoresCategory *get_scorecats ();
GSettings **get_settings ();
int get_move_timeout ();
void game_props_callback (GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
void update_score (guint value);
#endif
\ No newline at end of file
#endif
......@@ -51,7 +51,6 @@ main (int argc, char *argv[])
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
games_scores_startup ();
GRand **rgen = get_rgen();
*rgen = g_rand_new ();
......
......@@ -33,8 +33,8 @@
#include <gtk/gtk.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gdk/gdkkeysyms.h>
#include <libgnome-games-support.h>
#include "games-gridframe.h"
#include "game-area.h"
#include "five-or-more-app.h"
#include "balls-preview.h"
......@@ -82,8 +82,7 @@ static const gint field_sizes[MAX_SIZE][4] = {
};
static scoretable sctab[] =
{ {5, 10}, {6, 12}, {7, 18}, {8, 28}, {9, 42}, {10, 82}, {11, 108}, {12,
138},
{ {5, 10}, {6, 12}, {7, 18}, {8, 28}, {9, 42}, {10, 82}, {11, 108}, {12, 138},
{13, 172}, {14, 210}, {0, 0} };
static gchar *warning_message = NULL;
......@@ -98,8 +97,6 @@ set_sizes (gint size)
npieces = field_sizes[size][3];
gint *game_size = get_game_size();
*game_size = size;
GamesScoresCategory *scorecats = get_scorecats();
games_scores_set_category (get_highscores(), scorecats[size - 1].key);
g_settings_set_int (*(get_settings()), KEY_SIZE, size);
GtkWidget *gridframe = get_gridframe();
......@@ -321,7 +318,6 @@ check_gameover (void)
static int
addscore (int num)
{
gchar string[20];
int i = 0;
int retval;
......@@ -670,7 +666,6 @@ cell_clicked (GtkWidget * widget, int fx, int fy)
static gint
button_press_event (GtkWidget * widget, GdkEvent * event)
{
int x, y;
int fx, fy;
if (inmove)
......@@ -1054,4 +1049,4 @@ game_area_init (void)
gtk_widget_set_can_focus (draw_area, TRUE);
gtk_widget_grab_focus (draw_area);
return draw_area;
}
\ No newline at end of file
}
/* games-gridframe.c: Create a container that guarantees that the internal
* allocated space is a fixed multiple of an integer.
*
* Copyright 2004 by Callum McKenzie
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <https://www.gnu.org/licenses/>.
*/
/* A lot of this was written by following the sorce for GtkFrame and
* GtkAspectFrame. */
#include <config.h>
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include "games-gridframe.h"
enum {
PROP_0,
PROP_X_PADDING,
PROP_Y_PADDING,
PROP_WIDTH,
PROP_HEIGHT,
PROP_X_ALIGN,
PROP_Y_ALIGN
};
G_DEFINE_TYPE (GamesGridFrame, games_grid_frame,GTK_TYPE_BIN)
struct GamesGridFramePrivate {
gint xmult;
gint ymult;
gint xpadding;
gint ypadding;
gfloat xalign;
gfloat yalign;
GtkAllocation old_allocation;
};
void
games_grid_frame_set (GamesGridFrame * frame, gint newxmult, gint newymult)
{
if (newxmult > 0)
frame->priv->xmult = newxmult;
if (newymult > 0)
frame->priv->ymult = newymult;
gtk_widget_queue_resize (GTK_WIDGET (frame));
}
void
games_grid_frame_set_padding (GamesGridFrame * frame, gint newxpadding,
gint newypadding)
{
if (newxpadding >= 0)
frame->priv->xpadding = newxpadding;
if (newypadding >= 0)
frame->priv->ypadding = newypadding;
gtk_widget_queue_resize (GTK_WIDGET (frame));
}
void
games_grid_frame_set_alignment (GamesGridFrame * frame, gfloat xalign,
gfloat yalign)
{
if (xalign < 0.0)
xalign = 0.0;
else if (xalign > 1.0)
xalign = 1.0;
if (yalign < 0.0)
yalign = 0.0;
else if (yalign > 1.0)
yalign = 1.0;
frame->priv->xalign = xalign;
frame->priv->yalign = yalign;
gtk_widget_queue_resize (GTK_WIDGET (frame));
}
static void
games_grid_frame_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
GamesGridFrame *frame = GAMES_GRID_FRAME (object);
switch (prop_id) {
case PROP_X_PADDING:
games_grid_frame_set_padding (frame, g_value_get_int (value), -1);
break;
case PROP_Y_PADDING:
games_grid_frame_set_padding (frame, -1, g_value_get_int (value));
break;
case PROP_X_ALIGN:
games_grid_frame_set_alignment (frame, g_value_get_float (value),
frame->priv->yalign);
break;
case PROP_Y_ALIGN:
games_grid_frame_set_alignment (frame, frame->priv->xalign,
g_value_get_float (value));
break;
case PROP_WIDTH:
games_grid_frame_set (frame, g_value_get_int (value), -1);
break;
case PROP_HEIGHT:
games_grid_frame_set (frame, -1, g_value_get_int (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
games_grid_frame_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
GamesGridFrame *frame = GAMES_GRID_FRAME (object);
switch (prop_id) {
case PROP_X_PADDING:
g_value_set_int (value, frame->priv->xpadding);
break;
case PROP_Y_PADDING:
g_value_set_int (value, frame->priv->ypadding);
break;
case PROP_X_ALIGN:
g_value_set_float (value, frame->priv->xalign);
break;
case PROP_Y_ALIGN:
g_value_set_float (value, frame->priv->yalign);
break;
case PROP_WIDTH:
g_value_set_int (value, frame->priv->xmult);
break;
case PROP_HEIGHT:
g_value_set_int (value, frame->priv->ymult);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
games_grid_frame_size_allocate (GtkWidget * widget,
GtkAllocation * allocation)
{
GamesGridFrame *frame = GAMES_GRID_FRAME (widget);
GtkWidget *child = gtk_bin_get_child (GTK_BIN (widget));
GtkAllocation child_allocation;
gint xsize, ysize, size;
gtk_widget_set_allocation (widget, allocation);
xsize = MAX (1, (allocation->width - frame->priv->xpadding) / frame->priv->xmult);
ysize = MAX (1, (allocation->height - frame->priv->ypadding) / frame->priv->ymult);
size = MIN (xsize, ysize);
child_allocation.width = size * frame->priv->xmult + frame->priv->xpadding;
child_allocation.height = size * frame->priv->ymult + frame->priv->ypadding;
child_allocation.x =
(allocation->width - child_allocation.width) * frame->priv->xalign +
allocation->x;
child_allocation.y =
(allocation->height - child_allocation.height) * frame->priv->yalign +
allocation->y;
if (gtk_widget_get_mapped (widget) &&
(child_allocation.x != frame->priv->old_allocation.x ||
child_allocation.y != frame->priv->old_allocation.y ||
child_allocation.width != frame->priv->old_allocation.width ||
child_allocation.height != frame->priv->old_allocation.height))
gdk_window_invalidate_rect (gtk_widget_get_window (widget), allocation, FALSE);
if (child && gtk_widget_get_visible (child))
gtk_widget_size_allocate (child, &child_allocation);
frame->priv->old_allocation = child_allocation;
}
static void
games_grid_frame_class_init (GamesGridFrameClass * class)
{
GObjectClass *object_class;
GtkWidgetClass *widget_class;
object_class = G_OBJECT_CLASS (class);
widget_class = GTK_WIDGET_CLASS (class);
object_class->set_property = games_grid_frame_set_property;
object_class->get_property = games_grid_frame_get_property;
widget_class->size_allocate = games_grid_frame_size_allocate;
g_type_class_add_private (object_class, sizeof (GamesGridFramePrivate));
g_object_class_install_property (object_class, PROP_X_PADDING,
g_param_spec_int ("x_padding", "X Padding", "X Padding",
0, G_MAXINT, 0,
G_PARAM_READABLE |
G_PARAM_WRITABLE));
g_object_class_install_property (object_class, PROP_Y_PADDING,
g_param_spec_int ("y_padding", "Y Padding", "Y Padding",
0, G_MAXINT, 0,
G_PARAM_READABLE |
G_PARAM_WRITABLE));
g_object_class_install_property (object_class, PROP_WIDTH,
g_param_spec_int ("width_multiple", "Width Multiple", "Width Multiple",
1, G_MAXINT, 1,
G_PARAM_READABLE |
G_PARAM_WRITABLE));
g_object_class_install_property (object_class, PROP_HEIGHT,
g_param_spec_int ("height_multiple", "Height Multiple", "Height Multiple",
1, G_MAXINT, 1,
G_PARAM_READABLE |
G_PARAM_WRITABLE));
g_object_class_install_property (object_class, PROP_X_ALIGN,
g_param_spec_float ("xalign", "X Alignment", "X Alignment",
0.0, 1.0, 0.5,
G_PARAM_READABLE |
G_PARAM_WRITABLE));
g_object_class_install_property (object_class, PROP_Y_ALIGN,
g_param_spec_float ("yalign", "Y Alignment", "Y Alignment",
0.0, 1.0, 0.5,
G_PARAM_READWRITE |
G_PARAM_WRITABLE));
}
static void
games_grid_frame_init (GamesGridFrame * frame)
{
frame->priv = G_TYPE_INSTANCE_GET_PRIVATE (frame, GAMES_TYPE_GRID_FRAME, GamesGridFramePrivate);
frame->priv->xmult = 1;
frame->priv->ymult = 1;
frame->priv->xalign = 0.5;
frame->priv->yalign = 0.5;
}
GtkWidget *
games_grid_frame_new (gint width, gint height)
{
GamesGridFrame *frame;
frame = g_object_new (GAMES_TYPE_GRID_FRAME, NULL);
frame->priv->xmult = MAX (width, 1);
frame->priv->ymult = MAX (height, 1);
return GTK_WIDGET (frame);
}
/* EOF */
/* games-gridframe.h: Create a container that guarantees that the internal
* allocated space is a fixed multiple of an integer.
*
* Copyright 2004 by Callum McKenzie
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <https://www.gnu.org/licenses/>.
*/
#ifndef GAMES_GRID_FRAME_H
#define GAMES_GRID_FRAME_H
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define GAMES_TYPE_GRID_FRAME (games_grid_frame_get_type ())
#define GAMES_GRID_FRAME(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_GRID_FRAME, GamesGridFrame))
#define GAMES_GRID_FRAME_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_GRID_FRAME, GamesGridFrameClass))
#define GAMES_IS_GRID_FRAME(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_GRID_FRAME))
#define GAMES_IS_GRID_FRAME_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_GRID_FRAME))
#define GAMES_GRID_FRAME_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_GRID_FRAME))
typedef struct GamesGridFramePrivate GamesGridFramePrivate;
typedef struct {
GtkBin bin;
/*< private >*/
GamesGridFramePrivate *priv;
} GamesGridFrame;
typedef struct {
GtkBinClass parent;
} GamesGridFrameClass;
GType games_grid_frame_get_type (void);
GtkWidget *games_grid_frame_new (gint width,
gint height);
void games_grid_frame_set (GamesGridFrame * frame,
gint width,
gint height);
void games_grid_frame_set_padding (GamesGridFrame * frame,
gint xpadding,
gint ypadding);
void games_grid_frame_set_alignment (GamesGridFrame * frame,
gfloat xalign,
gfloat yalign);
G_END_DECLS
#endif /* GAMES_GRID_FRAME_H */
/* EOF */
/*
* Copyright (C) 2005 Callum McKenzie
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <https://www.gnu.org/licenses/>.
*/
#include <config.h>
#include "games-score.h"
G_DEFINE_TYPE (GamesScore, games_score, G_TYPE_OBJECT)
struct GamesScorePrivate {
union {
guint32 plain;
gdouble time_double; /* minutes.seconds */
} value;
time_t time;
};
/**
* games_score_new:
*
* Creates a new score object.
*
* Return value: the new #GamesScore
**/
GamesScore *
games_score_new ()
{
return g_object_new (GAMES_TYPE_SCORE, NULL);
}
/**
* games_score_new_plain:
* @value: The value of the score.
*
* Creates a new score object.
*
* Return value: the new #GamesScore
**/
GamesScore *
games_score_new_plain (guint32 value)