diff --git a/data/interface.ui b/data/interface.ui index e36bc6f5434f981ecf21de4cc997ec80db99f6ab..31b510b8574266663d46f7123ac5ff1a4223dd9d 100644 --- a/data/interface.ui +++ b/data/interface.ui @@ -20,21 +20,9 @@ <template class="RugbyAppWindow" parent="GtkApplicationWindow"> <property name="can_focus">False</property> <child> - <object class="GtkScrolledWindow"> - <property name="height_request">300</property> + <object class="GtkListBox" id="listbox"> <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="shadow_type">in</property> - <child> - <object class="GtkTreeView" id="treeview"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="tooltip_column">3</property> - <child internal-child="selection"> - <object class="GtkTreeSelection"/> - </child> - </object> - </child> + <property name="can_focus">False</property> </object> </child> <child type="titlebar"> diff --git a/meson.build b/meson.build index 7dae6c60d8c8b1348917908186ae60109601bc60..eed8780b9e8695f320ddef36211d1121d83a170f 100644 --- a/meson.build +++ b/meson.build @@ -1,12 +1,12 @@ project('rugby', 'c', license:'LGPL') add_project_arguments('-Wdeprecated-declarations', language: 'c') -add_project_arguments('-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_32', language: 'c') -add_project_arguments('-DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_32', language: 'c') +add_project_arguments('-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_44', language: 'c') +add_project_arguments('-DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_44', language: 'c') add_project_arguments('-DGDK_VERSION_MIN_REQUIRED=GDK_VERSION_3_16', language: 'c') add_project_arguments('-DGDK_VERSION_MAX_ALLOWED=GDK_VERSION_3_16', language: 'c') -glib_dep = dependency('glib-2.0', version: '>=2.32') +gio_dep = dependency('gio-2.0', version: '>=2.44') gtk_dep = dependency('gtk+-3.0', version: '>=3.16') subdir('data') diff --git a/src/meson.build b/src/meson.build index 98fdb69f3189f5c0eb409006398340e44e912599..27c4017bb277b14aa47a023f318cb04218724398 100644 --- a/src/meson.build +++ b/src/meson.build @@ -4,15 +4,13 @@ sources = files( 'rugby.c', 'rugby-application.c', 'rugby-app-window.c', - 'rugby-cell-renderer-score.c', 'rugby-possibility.c', - 'rugby-score-store.c', 'rugby-scoring.c' ) sources += resources -deps = [glib_dep, gtk_dep] +deps = [gio_dep, gtk_dep] executable('rugby', sources, diff --git a/src/rugby-app-window.c b/src/rugby-app-window.c index 777a227466ccf8cc466465a00d1c4f435d7915dc..e8fdcffdce9131f0cad8b09d0e2bc5e4ad3d5533 100644 --- a/src/rugby-app-window.c +++ b/src/rugby-app-window.c @@ -20,22 +20,20 @@ #include "rugby-application.h" #include "rugby-app-window.h" -#include "rugby-cell-renderer-score.h" -#include "rugby-score-store.h" +#include "rugby-possibility.h" #include "rugby-scoring.h" struct _RugbyAppWindow { GtkApplicationWindow parent; - RugbyScoreStore *store; - GtkTreeModel *filter; + GListStore *store; GtkWidget *tryfilter; GtkWidget *kickfilter; GtkWidget *tryscale; GtkWidget *kickscale; - GtkWidget *treeview; + GtkWidget *listbox; }; G_DEFINE_TYPE(RugbyAppWindow, rugby_app_window, GTK_TYPE_APPLICATION_WINDOW); @@ -45,7 +43,8 @@ scorespin_value_changed_cb (GtkSpinButton *spin, RugbyAppWindow *self) { gint score = gtk_spin_button_get_value_as_int (spin); - rugby_score_store_set_score (self->store, score); + + rugby_scoring_get_possibilities (self->store, score); gint max_tries = MAX (rugby_scoring_get_max_tries (score), 1.0); gtk_range_set_range (GTK_RANGE (self->tryscale), 0.0, max_tries); @@ -58,39 +57,27 @@ static void scale_value_changed_cb (GtkRange *range, RugbyAppWindow *self) { - gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (self->filter)); + // pass } -static gboolean -filter_visible_func (GtkTreeModel *model, - GtkTreeIter *iter, - gpointer data) +static GtkWidget * +listbox_widget_func (gpointer item, + gpointer user_data) { - RugbyAppWindow *self = RUGBY_APP_WINDOW (data); + RugbyPossibility *possibility = RUGBY_POSSIBILITY (item); + RugbyAppWindow *self = RUGBY_APP_WINDOW (user_data); gint tries, utries, kicks; + g_object_get (possibility, + "tries", &tries, + "utries", &utries, + "kicks", &kicks, + NULL); + + g_autofree gchar *text = + g_strdup_printf ("%d tries, %d unconverted tries, %d kicks", tries, utries, kicks); - gint ftries = gtk_range_get_value (GTK_RANGE (self->tryscale)); - gint fkicks = gtk_range_get_value (GTK_RANGE (self->kickscale)); - gtk_tree_model_get (model, iter, - RUGBY_SCORE_STORE_TRIES, &tries, - RUGBY_SCORE_STORE_UTRIES, &utries, - RUGBY_SCORE_STORE_KICKS, &kicks, - -1); - - gboolean try_filter = gtk_switch_get_active (GTK_SWITCH (self->tryfilter)); - gboolean kick_filter = gtk_switch_get_active (GTK_SWITCH (self->kickfilter)); - gboolean try_equal = ((tries + utries) == ftries); - gboolean kick_equal = (kicks == fkicks); - - if (try_filter && kick_filter) - return try_equal && kick_equal; - else if (try_filter) - return try_equal; - else if (kick_filter) - return kick_equal; - else - return TRUE; + return gtk_label_new (text); } static void @@ -98,22 +85,12 @@ rugby_app_window_init (RugbyAppWindow *self) { gtk_widget_init_template (GTK_WIDGET (self)); - GtkCellRenderer *renderer = rugby_cell_renderer_score_new (); - GtkTreeViewColumn *column = - gtk_tree_view_column_new_with_attributes ("Score", renderer, - "tries", RUGBY_SCORE_STORE_TRIES, - "utries", RUGBY_SCORE_STORE_UTRIES, - "kicks", RUGBY_SCORE_STORE_KICKS, - NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW (self->treeview), column); - - // TODO: put this in the builder file instead - self->store = rugby_score_store_new (); - self->filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (self->store), NULL); - - gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (self->filter), - filter_visible_func, self, NULL); - gtk_tree_view_set_model (GTK_TREE_VIEW (self->treeview), self->filter); + self->store = g_list_store_new (RUGBY_TYPE_POSSIBILITY); + gtk_list_box_bind_model (GTK_LIST_BOX (self->listbox), + G_LIST_MODEL (self->store), + listbox_widget_func, + self, + NULL); g_object_bind_property (self->tryfilter, "active", self->tryscale, "sensitive", @@ -121,7 +98,6 @@ rugby_app_window_init (RugbyAppWindow *self) g_object_bind_property (self->kickfilter, "active", self->kickscale, "sensitive", G_BINDING_DEFAULT); - } static void @@ -130,7 +106,6 @@ rugby_app_window_dispose (GObject *object) RugbyAppWindow *self = RUGBY_APP_WINDOW (object); g_clear_object (&self->store); - g_clear_object (&self->filter); G_OBJECT_CLASS (rugby_app_window_parent_class)->dispose (object); } @@ -149,7 +124,7 @@ rugby_app_window_class_init (RugbyAppWindowClass *klass) gtk_widget_class_bind_template_child (widget_class, RugbyAppWindow, kickfilter); gtk_widget_class_bind_template_child (widget_class, RugbyAppWindow, tryscale); gtk_widget_class_bind_template_child (widget_class, RugbyAppWindow, kickscale); - gtk_widget_class_bind_template_child (widget_class, RugbyAppWindow, treeview); + gtk_widget_class_bind_template_child (widget_class, RugbyAppWindow, listbox); gtk_widget_class_bind_template_callback (widget_class, scorespin_value_changed_cb); gtk_widget_class_bind_template_callback (widget_class, scale_value_changed_cb); diff --git a/src/rugby-cell-renderer-score.c b/src/rugby-cell-renderer-score.c deleted file mode 100644 index be654b341a86d43e97004b00c26d854b67cbbb26..0000000000000000000000000000000000000000 --- a/src/rugby-cell-renderer-score.c +++ /dev/null @@ -1,275 +0,0 @@ -/* rugby-cell-renderer-score.c - * - * Copyright © 2012, 2013, 2016, 2018 Bruce Cowan <bruce@bcowan.eu> - * - * This file 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 3 of the - * License, or (at your option) any later version. - * - * This file 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 General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "rugby-cell-renderer-score.h" -#include "rugby-scoring.h" - -enum -{ - PROP_0, - PROP_TRIES, - PROP_UTRIES, - PROP_KICKS -}; - -struct _RugbyCellRendererScore -{ - GtkCellRenderer parent_instance; - - gint tries; - gint utries; - gint kicks; -}; - -/* Style classes for the different types of score */ -#define RUGBY_STYLE_CLASS_TRY "score-try" -#define RUGBY_STYLE_CLASS_UTRY "score-utry" -#define RUGBY_STYLE_CLASS_KICK "score-kick" - -G_DEFINE_TYPE (RugbyCellRendererScore, rugby_cell_renderer_score, GTK_TYPE_CELL_RENDERER) - -static void -rugby_cell_renderer_score_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - RugbyCellRendererScore *self = RUGBY_CELL_RENDERER_SCORE (object); - - switch (prop_id) - { - case PROP_TRIES: - self->tries = g_value_get_int (value); - break; - case PROP_UTRIES: - self->utries = g_value_get_int (value); - break; - case PROP_KICKS: - self->kicks = g_value_get_int (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -rugby_cell_renderer_score_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - RugbyCellRendererScore *self = RUGBY_CELL_RENDERER_SCORE (object); - - switch (prop_id) - { - case PROP_TRIES: - g_value_set_int (value, self->tries); - break; - case PROP_UTRIES: - g_value_set_int (value, self->utries); - break; - case PROP_KICKS: - g_value_set_int (value, self->kicks); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -#define FIXED_WIDTH 400 -#define FIXED_HEIGHT 20 - -static void -rugby_cell_renderer_score_get_preferred_width (GtkCellRenderer *cell, - GtkWidget *widget, - gint *minimum_width, - gint *natural_width) -{ - gint xpad; - gint width; - - gtk_cell_renderer_get_padding (cell, &xpad, NULL); - width = xpad * 2 + FIXED_WIDTH; - - if (minimum_width) - *minimum_width = width; - if (natural_width) - *natural_width = width; -} - -static void -rugby_cell_renderer_score_get_preferred_height (GtkCellRenderer *cell, - GtkWidget *widget, - gint *minimum_height, - gint *natural_height) -{ - gint ypad; - gint height; - - gtk_cell_renderer_get_padding (cell, NULL, &ypad); - height = ypad * 2 + FIXED_HEIGHT; - - if (minimum_height) - *minimum_height = height; - if (natural_height) - *natural_height = height; -} - -static void -render_bar (GtkStyleContext *context, - cairo_t *cr, - gdouble x, - gdouble y, - gdouble width, - gdouble height, - RugbyScoreType type) -{ - gtk_style_context_save (context); - - switch (type) - { - case RUGBY_SCORE_TYPE_TRY: - gtk_style_context_add_class (context, RUGBY_STYLE_CLASS_TRY); - break; - case RUGBY_SCORE_TYPE_UTRY: - gtk_style_context_add_class (context, RUGBY_STYLE_CLASS_UTRY); - break; - case RUGBY_SCORE_TYPE_KICK: - gtk_style_context_add_class (context, RUGBY_STYLE_CLASS_KICK); - break; - } - - gtk_render_background (context, cr, x, y, width, height); - - gtk_style_context_restore (context); -} - -static void -rugby_cell_renderer_score_render (GtkCellRenderer *cell, - cairo_t *cr, - GtkWidget *widget, - const GdkRectangle *background_area, - const GdkRectangle *cell_area, - GtkCellRendererState flags) -{ - RugbyCellRendererScore *self = RUGBY_CELL_RENDERER_SCORE (cell); - GtkStyleContext *context; - gint xpad, ypad; - gdouble x, y, total_w, w, h; - GtkBorder border; - gint tries, utries, kicks; - gint total; - gint i; - - context = gtk_widget_get_style_context (widget); - - gtk_cell_renderer_get_padding (cell, &xpad, &ypad); - x = cell_area->x + xpad; - y = cell_area->y + ypad; - total_w = cell_area->width - xpad * 2; - h = cell_area->height - ypad * 2; - - gtk_style_context_save (context); - gtk_style_context_add_class (context, "level-cell"); - - gtk_render_background (context, cr, x, y, total_w, h); - gtk_render_frame (context, cr, x, y, total_w, h); - - tries = self->tries; - utries = self->utries; - kicks = self->kicks; - total = tries * TRY_POINTS + utries * UTRY_POINTS + kicks * KICK_POINTS; - - gtk_style_context_get_border (context, GTK_STATE_FLAG_NORMAL, &border); - x += border.left; - y += border.top; - total_w -= border.left + border.right; - h -= border.top + border.bottom; - - gtk_style_context_add_class (context, "fill-block"); - - w = total_w / (total / 7.0); - for (i = 0; i < tries; i++) - { - render_bar (context, cr, x, y, w, h, RUGBY_SCORE_TYPE_TRY); - x += w; - } - - w = total_w / (total / 5.0); - for (i = 0; i < utries; i++) - { - render_bar (context, cr, x, y, w, h, RUGBY_SCORE_TYPE_UTRY); - x += w; - } - - w = total_w / (total / 3.0); - for (i = 0; i < kicks; i++) - { - render_bar (context, cr, x, y, w, h, RUGBY_SCORE_TYPE_KICK); - x += w; - } - - gtk_style_context_restore (context); -} - -static void -rugby_cell_renderer_score_class_init (RugbyCellRendererScoreClass *klass) -{ - GObjectClass *obj_class = G_OBJECT_CLASS (klass); - GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (klass); - - obj_class->get_property = rugby_cell_renderer_score_get_property; - obj_class->set_property = rugby_cell_renderer_score_set_property; - - cell_class->get_preferred_width = rugby_cell_renderer_score_get_preferred_width; - cell_class->get_preferred_height = rugby_cell_renderer_score_get_preferred_height; - cell_class->render = rugby_cell_renderer_score_render; - - g_object_class_install_property (obj_class, PROP_TRIES, - g_param_spec_int ("tries", "Tries", "Number of tries", - 0, 50, 0, - G_PARAM_READWRITE)); - - g_object_class_install_property (obj_class, PROP_UTRIES, - g_param_spec_int ("utries", "Unconverted Tries", "Number of Unconverted Tries", - 0, 50, 0, - G_PARAM_READWRITE)); - - g_object_class_install_property (obj_class, PROP_KICKS, - g_param_spec_int ("kicks", "Kicks", "Number of kicks", - 0, 50, 0, - G_PARAM_READWRITE)); -} - -static void -rugby_cell_renderer_score_init (RugbyCellRendererScore *self) -{ - self->tries = 0; - self->utries = 0; - self->kicks = 0; - - gtk_cell_renderer_set_padding (GTK_CELL_RENDERER (self), 2, 2); -} - -GtkCellRenderer * -rugby_cell_renderer_score_new (void) -{ - return g_object_new (RUGBY_TYPE_CELL_RENDERER_SCORE, NULL); -} diff --git a/src/rugby-cell-renderer-score.h b/src/rugby-cell-renderer-score.h deleted file mode 100644 index 0d290b14a6e27467f96ac0e410b6243e0ba053f6..0000000000000000000000000000000000000000 --- a/src/rugby-cell-renderer-score.h +++ /dev/null @@ -1,30 +0,0 @@ -/* rugby-cell-renderer-score.h - * - * Copyright © 2012, 2016 Bruce Cowan <bruce@bcowan.eu> - * - * This file 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 3 of the - * License, or (at your option) any later version. - * - * This file 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 General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#pragma once - -#include <gtk/gtk.h> - -G_BEGIN_DECLS - -#define RUGBY_TYPE_CELL_RENDERER_SCORE rugby_cell_renderer_score_get_type () -G_DECLARE_FINAL_TYPE (RugbyCellRendererScore, rugby_cell_renderer_score, RUGBY, CELL_RENDERER_SCORE, GtkCellRenderer) - -GtkCellRenderer * rugby_cell_renderer_score_new (void); - -G_END_DECLS diff --git a/src/rugby-score-store.c b/src/rugby-score-store.c deleted file mode 100644 index 13652264f6cdf84417904826c1ff296e7843c651..0000000000000000000000000000000000000000 --- a/src/rugby-score-store.c +++ /dev/null @@ -1,201 +0,0 @@ -/* rugby-score-store.c - * - * Copyright © 2012, 2016-2018 Bruce Cowan <bruce@bcowan.eu> - * - * This file 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 3 of the - * License, or (at your option) any later version. - * - * This file 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 General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "rugby-possibility.h" -#include "rugby-score-store.h" -#include "rugby-scoring.h" - -enum -{ - FINISHED, - LAST_SIGNAL -}; - -enum -{ - PROP_0, - PROP_SCORE, - PROP_LAST -}; - -static GParamSpec *pspecs[PROP_LAST]; - -struct _RugbyScoreStore -{ - GtkListStore parent_instance; - - gint score; -}; - -G_DEFINE_TYPE (RugbyScoreStore, rugby_score_store, GTK_TYPE_LIST_STORE) - -static guint signals[LAST_SIGNAL] = { 0, }; - -static void -rugby_score_store_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - RugbyScoreStore *self = RUGBY_SCORE_STORE (object); - - switch (prop_id) - { - case PROP_SCORE: - rugby_score_store_set_score (self, g_value_get_int (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -rugby_score_store_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - RugbyScoreStore *self = RUGBY_SCORE_STORE (object); - - switch (prop_id) - { - case PROP_SCORE: - g_value_set_int (value, rugby_score_store_get_score (self)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -rugby_score_store_class_init (RugbyScoreStoreClass *klass) -{ - GObjectClass *obj_class = G_OBJECT_CLASS (klass); - - obj_class->get_property = rugby_score_store_get_property; - obj_class->set_property = rugby_score_store_set_property; - - pspecs[PROP_SCORE] = g_param_spec_int ("score", "Score", "The score", - 0, 200, 0, - G_PARAM_READWRITE); - g_object_class_install_property (obj_class, PROP_SCORE, pspecs[PROP_SCORE]); - - signals[FINISHED] = - g_signal_new ("finished", - G_TYPE_FROM_CLASS (obj_class), - G_SIGNAL_RUN_LAST, - 0, - NULL, NULL, NULL, - G_TYPE_NONE, 1, - G_TYPE_INT); -} - -static void -populate_store_foreach (gpointer data, - gpointer user_data) -{ - RugbyPossibility *possiblity = RUGBY_POSSIBILITY (data); - GtkListStore *store = GTK_LIST_STORE (user_data); - - gint tries, utries, kicks; - GtkTreeIter iter; - - g_object_get (possiblity, - "tries", &tries, - "utries", &utries, - "kicks", &kicks, - NULL); - - g_autoptr (GString) string = g_string_new (NULL); - - if (tries > 0 || utries > 0) - g_string_append_printf (string, "%d tries, %d converted", - tries + utries, tries); - if (kicks > 0) - { - if (string->len == 0) - g_string_append_printf (string, "%d kicks", kicks); - else - g_string_append_printf (string, ", %d kicks", kicks); - } - - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, - RUGBY_SCORE_STORE_TRIES, tries, - RUGBY_SCORE_STORE_UTRIES, utries, - RUGBY_SCORE_STORE_KICKS, kicks, - RUGBY_SCORE_STORE_TOOLTIP, string->str, - -1); -} - -static void -populate_store (RugbyScoreStore *self) -{ - GtkListStore *store = GTK_LIST_STORE (self); - - g_autoptr(GPtrArray) possibilities = NULL; - - /* Clear the store */ - gtk_list_store_clear (store); - - possibilities = rugby_scoring_get_possibilities (self->score); - if (possibilities->len == 0) - return; - - g_ptr_array_foreach (possibilities, populate_store_foreach, store); - - g_signal_emit (self, signals[FINISHED], 0, (gint) possibilities->len); -} - -static void -rugby_score_store_init (RugbyScoreStore *self) -{ - GType types[] = { G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING }; - - gtk_list_store_set_column_types (GTK_LIST_STORE (self), RUGBY_SCORE_STORE_COLUMNS, types); - self->score = 0; -} - -RugbyScoreStore * -rugby_score_store_new (void) -{ - return g_object_new (RUGBY_TYPE_SCORE_STORE, NULL); -} - -gint -rugby_score_store_get_score (RugbyScoreStore *self) -{ - g_return_val_if_fail (RUGBY_IS_SCORE_STORE (self), 0); - - return self->score; -} - -void -rugby_score_store_set_score (RugbyScoreStore *self, - gint score) -{ - g_return_if_fail (RUGBY_IS_SCORE_STORE (self)); - g_return_if_fail (score >= 0 && score <= 200); - - self->score = score; - g_object_notify_by_pspec (G_OBJECT (self), pspecs[PROP_SCORE]); - - populate_store (self); -} diff --git a/src/rugby-score-store.h b/src/rugby-score-store.h deleted file mode 100644 index 38b33da69066a83d9e1b68defd79156c0b7484bc..0000000000000000000000000000000000000000 --- a/src/rugby-score-store.h +++ /dev/null @@ -1,42 +0,0 @@ -/* rugby-score-store.h - * - * Copyright © 2012, 2016 Bruce Cowan <bruce@bcowan.eu> - * - * This file 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 3 of the - * License, or (at your option) any later version. - * - * This file 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 General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#pragma once - -#include <gtk/gtk.h> - -G_BEGIN_DECLS - -enum -{ - RUGBY_SCORE_STORE_TRIES, - RUGBY_SCORE_STORE_UTRIES, - RUGBY_SCORE_STORE_KICKS, - RUGBY_SCORE_STORE_TOOLTIP, - RUGBY_SCORE_STORE_COLUMNS -}; - -#define RUGBY_TYPE_SCORE_STORE rugby_score_store_get_type () -G_DECLARE_FINAL_TYPE (RugbyScoreStore, rugby_score_store, RUGBY, SCORE_STORE, GtkListStore) - -RugbyScoreStore * rugby_score_store_new (void); -gint rugby_score_store_get_score (RugbyScoreStore *store); -void rugby_score_store_set_score (RugbyScoreStore *store, - gint score); - -G_END_DECLS diff --git a/src/rugby-scoring.c b/src/rugby-scoring.c index 1e2e889390f0b301616119b4ec08410b678e5b8b..9d377121fe469755b13a32623d89f31ce359c2a8 100644 --- a/src/rugby-scoring.c +++ b/src/rugby-scoring.c @@ -19,18 +19,14 @@ #include "rugby-possibility.h" #include "rugby-scoring.h" -GPtrArray * -rugby_scoring_get_possibilities (gint score) +void +rugby_scoring_get_possibilities (GListStore *store, gint score) { - GPtrArray *array; - - g_return_val_if_fail (score >= 0, NULL); - - array = g_ptr_array_new_with_free_func (g_object_unref); - gint max_tries = score / TRY_POINTS; gint max_utries = score / UTRY_POINTS; + g_list_store_remove_all (store); + for (gint tries = 0; tries <= max_tries; tries++) { for (gint utries = 0; utries <= max_utries; utries++) @@ -44,15 +40,13 @@ rugby_scoring_get_possibilities (gint score) { gint kicks = left / KICK_POINTS; - RugbyPossibility *possibility = rugby_possibility_new (tries, - utries, - kicks); - g_ptr_array_add (array, possibility); + g_autoptr(RugbyPossibility) possibility = rugby_possibility_new (tries, + utries, + kicks); + g_list_store_append (store, possibility); } } } - - return array; } gint diff --git a/src/rugby-scoring.h b/src/rugby-scoring.h index 3050b1768c52fd811b3954a68769c6481130f556..d7374ceca1d19eb8af67d6c95e15113aba1a8c9c 100644 --- a/src/rugby-scoring.h +++ b/src/rugby-scoring.h @@ -18,7 +18,7 @@ #pragma once -#include <glib.h> +#include <gio/gio.h> G_BEGIN_DECLS @@ -33,8 +33,9 @@ typedef enum RUGBY_SCORE_TYPE_KICK } RugbyScoreType; -GPtrArray * rugby_scoring_get_possibilities (gint score); -gint rugby_scoring_get_max_tries (gint score); -gint rugby_scoring_get_max_kicks (gint score); +void rugby_scoring_get_possibilities (GListStore *model, + gint score); +gint rugby_scoring_get_max_tries (gint score); +gint rugby_scoring_get_max_kicks (gint score); G_END_DECLS