Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomeu Vizoso <tomeu@sugarlabs.org>2009-12-02 10:30:29 (GMT)
committer Tomeu Vizoso <tomeu.vizoso@collabora.co.uk>2010-08-18 18:08:32 (GMT)
commite83f0907beafd1dbd721c3f732b54235a53c8191 (patch)
treea843ca65d1847c2bcd24ce4ba8d56cac7c204503
parente337d3b26e9e1baa37fc63af8a2daa7fc92296e2 (diff)
Move fields in SugarGrid to properties
-rw-r--r--src/sugar/sugar-grid.c117
-rw-r--r--src/sugar/sugar-grid.h13
2 files changed, 104 insertions, 26 deletions
diff --git a/src/sugar/sugar-grid.c b/src/sugar/sugar-grid.c
index 3fa7de5..c77ac26 100644
--- a/src/sugar/sugar-grid.c
+++ b/src/sugar/sugar-grid.c
@@ -19,28 +19,46 @@
#include "sugar-grid.h"
-static void sugar_grid_class_init (SugarGridClass *grid_class);
-static void sugar_grid_init (SugarGrid *grid);
+enum {
+ PROP_0,
+ PROP_WIDTH,
+ PROP_HEIGHT,
+};
+struct _SugarGrid {
+ GObject base_instance;
+
+ SugarGridPrivate *priv;
+};
+
+struct _SugarGridClass {
+ GObjectClass base_class;
+};
+
+struct _SugarGridPrivate {
+ guint width;
+ guint height;
+ guchar *weights;
+};
G_DEFINE_TYPE(SugarGrid, sugar_grid, G_TYPE_OBJECT)
void
sugar_grid_setup(SugarGrid *grid, gint width, gint height)
{
- g_free(grid->weights);
+ g_free(grid->priv->weights);
- grid->weights = g_new0(guchar, width * height);
- grid->width = width;
- grid->height = height;
+ grid->priv->weights = g_new0(guchar, width * height);
+ grid->priv->width = width;
+ grid->priv->height = height;
}
static gboolean
check_bounds(SugarGrid *grid, GdkRectangle *rect)
{
- return (grid->weights != NULL &&
- grid->width >= rect->x + rect->width &&
- grid->height >= rect->y + rect->height);
+ return (grid->priv->weights != NULL &&
+ grid->priv->width >= rect->x + rect->width &&
+ grid->priv->height >= rect->y + rect->height);
}
void
@@ -55,7 +73,7 @@ sugar_grid_add_weight(SugarGrid *grid, GdkRectangle *rect)
for (k = rect->y; k < rect->y + rect->height; k++) {
for (i = rect->x; i < rect->x + rect->width; i++) {
- grid->weights[i + k * grid->width] += 1;
+ grid->priv->weights[i + k * grid->priv->width] += 1;
}
}
}
@@ -72,7 +90,7 @@ sugar_grid_remove_weight(SugarGrid *grid, GdkRectangle *rect)
for (k = rect->y; k < rect->y + rect->height; k++) {
for (i = rect->x; i < rect->x + rect->width; i++) {
- grid->weights[i + k * grid->width] -= 1;
+ grid->priv->weights[i + k * grid->priv->width] -= 1;
}
}
}
@@ -89,7 +107,7 @@ sugar_grid_compute_weight(SugarGrid *grid, GdkRectangle *rect)
for (k = rect->y; k < rect->y + rect->height; k++) {
for (i = rect->x; i < rect->x + rect->width; i++) {
- sum += grid->weights[i + k * grid->width];
+ sum += grid->priv->weights[i + k * grid->priv->width];
}
}
@@ -97,24 +115,95 @@ sugar_grid_compute_weight(SugarGrid *grid, GdkRectangle *rect)
}
static void
+sugar_grid_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ SugarGrid *self = SUGAR_GRID (object);
+
+ switch (property_id)
+ {
+ case PROP_WIDTH:
+ g_value_set_uint ((GValue *)value, self->priv->width);
+ break;
+ case PROP_HEIGHT:
+ g_value_set_uint ((GValue *)value, self->priv->height);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+sugar_grid_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ SugarGrid *self = SUGAR_GRID (object);
+
+ switch (property_id)
+ {
+ case PROP_WIDTH:
+ g_value_set_uint (value, self->priv->width);
+ break;
+ case PROP_HEIGHT:
+ g_value_set_uint (value, self->priv->height);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
sugar_grid_finalize(GObject *object)
{
SugarGrid *grid = SUGAR_GRID(object);
- g_free(grid->weights);
+ g_free(grid->priv->weights);
}
static void
sugar_grid_class_init(SugarGridClass *grid_class)
{
GObjectClass *gobject_class;
+ GParamSpec *pspec;
gobject_class = G_OBJECT_CLASS(grid_class);
gobject_class->finalize = sugar_grid_finalize;
+ gobject_class->set_property = sugar_grid_set_property;
+ gobject_class->get_property = sugar_grid_get_property;
+
+ g_type_class_add_private (grid_class, sizeof (SugarGridPrivate));
+
+ pspec = g_param_spec_uint ("width", NULL,
+ "Width of the Grid",
+ 0, G_MAXUINT, 0,
+ G_PARAM_READWRITE);
+ g_object_class_install_property (gobject_class,
+ PROP_WIDTH,
+ pspec);
+
+ pspec = g_param_spec_uint ("height", NULL,
+ "Height of the Grid",
+ 0, G_MAXUINT, 0,
+ G_PARAM_READWRITE);
+ g_object_class_install_property (gobject_class,
+ PROP_HEIGHT,
+ pspec);
}
static void
sugar_grid_init(SugarGrid *grid)
{
- grid->weights = NULL;
+ grid->priv = G_TYPE_INSTANCE_GET_PRIVATE (grid, SUGAR_TYPE_GRID, SugarGridPrivate);
+ grid->priv->width = 0;
+ grid->priv->height = 0;
+ grid->priv->weights = NULL;
}
+
diff --git a/src/sugar/sugar-grid.h b/src/sugar/sugar-grid.h
index d493a60..90fcf83 100644
--- a/src/sugar/sugar-grid.h
+++ b/src/sugar/sugar-grid.h
@@ -27,6 +27,7 @@ G_BEGIN_DECLS
typedef struct _SugarGrid SugarGrid;
typedef struct _SugarGridClass SugarGridClass;
+typedef struct _SugarGridPrivate SugarGridPrivate;
#define SUGAR_TYPE_GRID (sugar_grid_get_type())
#define SUGAR_GRID(object) (G_TYPE_CHECK_INSTANCE_CAST((object), SUGAR_TYPE_GRID, SugarGrid))
@@ -35,18 +36,6 @@ typedef struct _SugarGridClass SugarGridClass;
#define SUGAR_IS_GRID_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SUGAR_TYPE_GRID))
#define SUGAR_GRID_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), SUGAR_TYPE_GRID, SugarGridClass))
-struct _SugarGrid {
- GObject base_instance;
-
- gint width;
- gint height;
- guchar *weights;
-};
-
-struct _SugarGridClass {
- GObjectClass base_class;
-};
-
GType sugar_grid_get_type (void);
void sugar_grid_setup (SugarGrid *grid,
gint width,