Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/sugar/sugar-grid.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sugar/sugar-grid.c')
-rw-r--r--src/sugar/sugar-grid.c117
1 files changed, 103 insertions, 14 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;
}
+