diff options
author | Filippo Argiolas <filippo.argiolas@gmail.com> | 2009-04-25 21:24:09 +0200 |
---|---|---|
committer | Filippo Argiolas <filippo.argiolas@gmail.com> | 2009-04-25 23:10:02 +0200 |
commit | 702f7483dcf1c14860e06e3bf67475f047d21cf5 (patch) | |
tree | 8bfc9b75ff708efccfbd827a833bdc29da68ed6c | |
parent | bc455c2218313fcbead104b52469818a4732ec53 (diff) |
Rework cheese-grid to scale its children
Remove unused functions copied from tidygrid and reduce the layout manager
to just a scaling manager that keeps the aspect ratio
-rw-r--r-- | src/cheese-grid.c | 646 | ||||
-rw-r--r-- | src/cheese-grid.h | 24 | ||||
-rw-r--r-- | src/cheese-stage.c | 7 |
3 files changed, 51 insertions, 626 deletions
diff --git a/src/cheese-grid.c b/src/cheese-grid.c index d08484f..8a2e43a 100644 --- a/src/cheese-grid.c +++ b/src/cheese-grid.c @@ -39,16 +39,7 @@ typedef struct _CheeseGridActorData CheeseGridActorData; static void cheese_grid_dispose (GObject *object); static void cheese_grid_finalize (GObject *object); -static void cheese_grid_finalize (GObject *object); - -static void cheese_grid_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec); -static void cheese_grid_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); + static void cheese_grid_finalize (GObject *object); static void clutter_container_iface_init (ClutterContainerIface *iface); @@ -111,16 +102,6 @@ struct _CheeseGridPrivate GHashTable *hash_table; GList *list; - gboolean homogenous_rows; - gboolean homogenous_columns; - gboolean end_align; - ClutterUnit column_gap, row_gap; - gdouble valign, halign; - - gboolean column_major; - - gboolean first_of_batch; - ClutterUnit a_current_sum, a_wrap; ClutterUnit max_extent_a; ClutterUnit max_extent_b; }; @@ -128,14 +109,6 @@ struct _CheeseGridPrivate enum { PROP_0, - PROP_HOMOGENOUS_ROWS, - PROP_HOMOGENOUS_COLUMNS, - PROP_ROW_GAP, - PROP_COLUMN_GAP, - PROP_VALIGN, - PROP_HALIGN, - PROP_END_ALIGN, - PROP_COLUMN_MAJOR, }; struct _CheeseGridActorData @@ -154,9 +127,6 @@ cheese_grid_class_init (CheeseGridClass *klass) gobject_class->dispose = cheese_grid_dispose; gobject_class->finalize = cheese_grid_finalize; - gobject_class->set_property = cheese_grid_set_property; - gobject_class->get_property = cheese_grid_get_property; - actor_class->paint = cheese_grid_paint; actor_class->pick = cheese_grid_pick; actor_class->get_preferred_width = cheese_grid_get_preferred_width; @@ -164,85 +134,9 @@ cheese_grid_class_init (CheeseGridClass *klass) actor_class->allocate = cheese_grid_allocate; g_type_class_add_private (klass, sizeof (CheeseGridPrivate)); - - - g_object_class_install_property - (gobject_class, - PROP_ROW_GAP, - clutter_param_spec_unit ("row-gap", - "Row gap", - "gap between rows in the layout", - 0, CLUTTER_MAXUNIT, - 0, - G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); - - g_object_class_install_property - (gobject_class, - PROP_COLUMN_GAP, - clutter_param_spec_unit ("column-gap", - "Column gap", - "gap between columns in the layout", - 0, CLUTTER_MAXUNIT, - 0, - G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); - - - g_object_class_install_property - (gobject_class, - PROP_HOMOGENOUS_ROWS, - g_param_spec_boolean ("homogenous-rows", - "homogenous rows", - "Should all rows have the same height?", - FALSE, - G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); - - g_object_class_install_property - (gobject_class, - PROP_HOMOGENOUS_COLUMNS, - g_param_spec_boolean ("homogenous-columns", - "homogenous columns", - "Should all columns have the same height?", - FALSE, - G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); - - g_object_class_install_property - (gobject_class, - PROP_COLUMN_MAJOR, - g_param_spec_boolean ("column-major", - "column-major", - "Do a column filling first instead of row filling first", - FALSE, - G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); - - g_object_class_install_property - (gobject_class, - PROP_END_ALIGN, - g_param_spec_boolean ("end-align", - "end-align", - "Right/bottom aligned rows/columns", - FALSE, - G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); - - g_object_class_install_property - (gobject_class, - PROP_VALIGN, - g_param_spec_double ("valign", - "Vertical align", - "Vertical alignment of items within cells", - 0.0, 1.0, 0.0, - G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); - - g_object_class_install_property - (gobject_class, - PROP_HALIGN, - g_param_spec_double ("halign", - "Horizontal align", - "Horizontal alignment of items within cells", - 0.0, 1.0, 0.0, - G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); - } + static void clutter_container_iface_init (ClutterContainerIface *iface) { @@ -299,234 +193,6 @@ cheese_grid_finalize (GObject *object) G_OBJECT_CLASS (cheese_grid_parent_class)->finalize (object); } - -void -cheese_grid_set_end_align (CheeseGrid *self, - gboolean value) -{ - CheeseGridPrivate *priv = CHEESE_GRID_GET_PRIVATE (self); - priv->end_align = value; - clutter_actor_queue_relayout (CLUTTER_ACTOR (self)); -} - -gboolean -cheese_grid_get_end_align (CheeseGrid *self) -{ - CheeseGridPrivate *priv = CHEESE_GRID_GET_PRIVATE (self); - return priv->end_align; -} - -void -cheese_grid_set_homogenous_rows (CheeseGrid *self, - gboolean value) -{ - CheeseGridPrivate *priv = CHEESE_GRID_GET_PRIVATE (self); - priv->homogenous_rows = value; - clutter_actor_queue_relayout (CLUTTER_ACTOR (self)); -} - -gboolean -cheese_grid_get_homogenous_rows (CheeseGrid *self) -{ - CheeseGridPrivate *priv = CHEESE_GRID_GET_PRIVATE (self); - return priv->homogenous_rows; -} - - -void -cheese_grid_set_homogenous_columns (CheeseGrid *self, - gboolean value) -{ - CheeseGridPrivate *priv = CHEESE_GRID_GET_PRIVATE (self); - priv->homogenous_columns = value; - clutter_actor_queue_relayout (CLUTTER_ACTOR (self)); -} - - -gboolean -cheese_grid_get_homogenous_columns (CheeseGrid *self) -{ - CheeseGridPrivate *priv = CHEESE_GRID_GET_PRIVATE (self); - return priv->homogenous_columns; -} - - -void -cheese_grid_set_column_major (CheeseGrid *self, - gboolean value) -{ - CheeseGridPrivate *priv = CHEESE_GRID_GET_PRIVATE (self); - priv->column_major = value; - clutter_actor_queue_relayout (CLUTTER_ACTOR (self)); -} - -gboolean -cheese_grid_get_column_major (CheeseGrid *self) -{ - CheeseGridPrivate *priv = CHEESE_GRID_GET_PRIVATE (self); - return priv->column_major; -} - -void -cheese_grid_set_column_gap (CheeseGrid *self, - ClutterUnit value) -{ - CheeseGridPrivate *priv = CHEESE_GRID_GET_PRIVATE (self); - priv->column_gap = value; - clutter_actor_queue_relayout (CLUTTER_ACTOR (self)); -} - -ClutterUnit -cheese_grid_get_column_gap (CheeseGrid *self) -{ - CheeseGridPrivate *priv = CHEESE_GRID_GET_PRIVATE (self); - return priv->column_gap; -} - - - -void -cheese_grid_set_row_gap (CheeseGrid *self, - ClutterUnit value) -{ - CheeseGridPrivate *priv = CHEESE_GRID_GET_PRIVATE (self); - priv->row_gap = value; - clutter_actor_queue_relayout (CLUTTER_ACTOR (self)); -} - -ClutterUnit -cheese_grid_get_row_gap (CheeseGrid *self) -{ - CheeseGridPrivate *priv = CHEESE_GRID_GET_PRIVATE (self); - return priv->row_gap; -} - - -void -cheese_grid_set_valign (CheeseGrid *self, - gdouble value) -{ - CheeseGridPrivate *priv = CHEESE_GRID_GET_PRIVATE (self); - priv->valign = value; - clutter_actor_queue_relayout (CLUTTER_ACTOR (self)); -} - -gdouble -cheese_grid_get_valign (CheeseGrid *self) -{ - CheeseGridPrivate *priv = CHEESE_GRID_GET_PRIVATE (self); - return priv->valign; -} - - - -void -cheese_grid_set_halign (CheeseGrid *self, - gdouble value) - -{ - CheeseGridPrivate *priv = CHEESE_GRID_GET_PRIVATE (self); - priv->halign = value; - clutter_actor_queue_relayout (CLUTTER_ACTOR (self)); -} - -gdouble -cheese_grid_get_halign (CheeseGrid *self) -{ - CheeseGridPrivate *priv = CHEESE_GRID_GET_PRIVATE (self); - return priv->halign; -} - - -static void -cheese_grid_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - CheeseGrid *grid = CHEESE_GRID (object); - - CheeseGridPrivate *priv; - - priv = CHEESE_GRID_GET_PRIVATE (object); - - switch (prop_id) - { - case PROP_END_ALIGN: - cheese_grid_set_end_align (grid, g_value_get_boolean (value)); - break; - case PROP_HOMOGENOUS_ROWS: - cheese_grid_set_homogenous_rows (grid, g_value_get_boolean (value)); - break; - case PROP_HOMOGENOUS_COLUMNS: - cheese_grid_set_homogenous_columns (grid, g_value_get_boolean (value)); - break; - case PROP_COLUMN_MAJOR: - cheese_grid_set_column_major (grid, g_value_get_boolean (value)); - break; - case PROP_COLUMN_GAP: - cheese_grid_set_column_gap (grid, clutter_value_get_unit (value)); - break; - case PROP_ROW_GAP: - cheese_grid_set_row_gap (grid, clutter_value_get_unit (value)); - break; - case PROP_VALIGN: - cheese_grid_set_valign (grid, g_value_get_double (value)); - break; - case PROP_HALIGN: - cheese_grid_set_halign (grid, g_value_get_double (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -cheese_grid_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - CheeseGrid *grid = CHEESE_GRID (object); - - CheeseGridPrivate *priv; - - priv = CHEESE_GRID_GET_PRIVATE (object); - - switch (prop_id) - { - case PROP_HOMOGENOUS_ROWS: - g_value_set_boolean (value, cheese_grid_get_homogenous_rows (grid)); - break; - case PROP_HOMOGENOUS_COLUMNS: - g_value_set_boolean (value, cheese_grid_get_homogenous_columns (grid)); - break; - case PROP_END_ALIGN: - g_value_set_boolean (value, cheese_grid_get_end_align (grid)); - break; - case PROP_COLUMN_MAJOR: - g_value_set_boolean (value, cheese_grid_get_column_major (grid)); - break; - case PROP_COLUMN_GAP: - clutter_value_set_unit (value, cheese_grid_get_column_gap (grid)); - break; - case PROP_ROW_GAP: - clutter_value_set_unit (value, cheese_grid_get_row_gap (grid)); - break; - case PROP_VALIGN: - g_value_set_double (value, cheese_grid_get_valign (grid)); - break; - case PROP_HALIGN: - g_value_set_double (value, cheese_grid_get_halign (grid)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - - static void cheese_grid_free_actor_data (gpointer data) { @@ -706,124 +372,6 @@ cheese_grid_get_preferred_height (ClutterActor *self, *natural_height_p = natural_height; } -static ClutterUnit -compute_row_height (GList *siblings, - ClutterUnit best_yet, - ClutterUnit current_a, - CheeseGridPrivate *priv) -{ - GList *l; - - gboolean homogenous_a; - gboolean homogenous_b; - ClutterUnit gap; - - if (priv->column_major) - { - homogenous_b = priv->homogenous_columns; - homogenous_a = priv->homogenous_rows; - gap = priv->row_gap; - } - else - { - homogenous_a = priv->homogenous_columns; - homogenous_b = priv->homogenous_rows; - gap = priv->column_gap; - } - - for (l = siblings; l != NULL; l = l->next) - { - ClutterActor *child = l->data; - ClutterUnit natural_width, natural_height; - - /* each child will get as much space as they require */ - clutter_actor_get_preferred_size (CLUTTER_ACTOR (child), - NULL, NULL, - &natural_width, &natural_height); - - if (priv->column_major) - { - ClutterUnit temp = natural_height; - natural_height = natural_width; - natural_width = temp; - } - - /* if the primary axis is homogenous, each additional item is the same - * width */ - if (homogenous_a) - natural_width = priv->max_extent_a; - - if (natural_height > best_yet) - best_yet = natural_height; - - /* if the child is overflowing, we wrap to next line */ - if (current_a + natural_width + gap > priv->a_wrap) - { - return best_yet; - } - current_a += natural_width + gap; - } - return best_yet; -} - - - - -static ClutterUnit -compute_row_start (GList *siblings, - ClutterUnit start_x, - CheeseGridPrivate *priv) -{ - ClutterUnit current_a = start_x; - GList *l; - - gboolean homogenous_a; - gboolean homogenous_b; - ClutterUnit gap; - - if (priv->column_major) - { - homogenous_b = priv->homogenous_columns; - homogenous_a = priv->homogenous_rows; - gap = priv->row_gap; - } - else - { - homogenous_a = priv->homogenous_columns; - homogenous_b = priv->homogenous_rows; - gap = priv->column_gap; - } - - for (l = siblings; l != NULL; l = l->next) - { - ClutterActor *child = l->data; - ClutterUnit natural_width, natural_height; - - /* each child will get as much space as they require */ - clutter_actor_get_preferred_size (CLUTTER_ACTOR (child), - NULL, NULL, - &natural_width, &natural_height); - - - if (priv->column_major) - natural_width = natural_height; - - /* if the primary axis is homogenous, each additional item is the same width */ - if (homogenous_a) - natural_width = priv->max_extent_a; - - /* if the child is overflowing, we wrap to next line */ - if (current_a + natural_width + gap > priv->a_wrap) - { - if (current_a == start_x) - return start_x; - return (priv->a_wrap - current_a); - } - current_a += natural_width + gap; - } - return (priv->a_wrap - current_a); -} - static void cheese_grid_allocate (ClutterActor *self, const ClutterActorBox *box, @@ -859,152 +407,58 @@ cheese_grid_allocate (ClutterActor *self, /* what does this do? */ clutter_actor_get_preferred_size (self, NULL, NULL, NULL, NULL); - - if (priv->column_major) - { - priv->a_wrap = priv->alloc_height; - homogenous_b = priv->homogenous_columns; - homogenous_a = priv->homogenous_rows; - aalign = priv->valign; - balign = priv->halign; - agap = priv->row_gap; - bgap = priv->column_gap; - } - else - { - priv->a_wrap = priv->alloc_width; - homogenous_a = priv->homogenous_columns; - homogenous_b = priv->homogenous_rows; - aalign = priv->halign; - balign = priv->valign; - agap = priv->column_gap; - bgap = priv->row_gap; - } - priv->max_extent_a = 0; priv->max_extent_b = 0; - priv->first_of_batch = TRUE; - - if (homogenous_a || - homogenous_b) - { - for (iter = priv->list; iter; iter = iter->next) - { - ClutterActor *child = iter->data; - ClutterUnit natural_width; - ClutterUnit natural_height; - - /* each child will get as much space as they require */ - clutter_actor_get_preferred_size (CLUTTER_ACTOR (child), - NULL, NULL, - &natural_width, &natural_height); - if (natural_width > priv->max_extent_a) - priv->max_extent_a = natural_width; - if (natural_height > priv->max_extent_b) - priv->max_extent_b = natural_width; - } + gint i = 0; + gint j = 0; + + for (iter = priv->list; iter; iter = iter->next) + { + ClutterActor *child = iter->data; + ClutterUnit natural_width; + ClutterUnit natural_height; + + + /* each child will get as much space as they require */ + clutter_actor_get_preferred_size (CLUTTER_ACTOR (child), + NULL, NULL, + &natural_width, &natural_height); + if (natural_width > priv->max_extent_a) + priv->max_extent_a = natural_width; + if (natural_height > priv->max_extent_b) + priv->max_extent_b = natural_width; + + ClutterUnit ratio = natural_width/natural_height; + ClutterUnit alloc_ratio = priv->alloc_width/priv->alloc_height; + + ClutterUnit child_width = priv->alloc_width / 3.0; + ClutterUnit child_height = priv->alloc_height / 3.0; + ClutterActorBox child_box; + + if (alloc_ratio < ratio) { + child_box.x1 = child_width * i; + child_box.x2 = child_box.x1 + child_width; + + child_box.y1 = child_height * j; + child_box.y2 = child_box.y1 + child_width/ratio; } - - if (priv->column_major) - { - ClutterUnit temp = priv->max_extent_a; - priv->max_extent_a = priv->max_extent_b; - priv->max_extent_b = temp; + else { + child_box.x1 = child_width * i; + child_box.x2 = child_box.x1 + child_height*ratio; + + child_box.y1 = child_height * j; + child_box.y2 = child_box.y1 + child_height; } - - for (iter = priv->list; iter; iter=iter->next) - { - ClutterActor *child = iter->data; - ClutterUnit natural_a; - ClutterUnit natural_b; - - /* each child will get as much space as they require */ - clutter_actor_get_preferred_size (CLUTTER_ACTOR (child), - NULL, NULL, - &natural_a, &natural_b); - - if (priv->column_major) /* swap axes around if column is major */ - { - ClutterUnit temp = natural_a; - natural_a = natural_b; - natural_b = temp; - } - - /* if the child is overflowing, we wrap to next line */ - if (current_a + natural_a > priv->a_wrap || - (homogenous_a && current_a + priv->max_extent_a > priv->a_wrap)) - { - current_b = next_b + bgap; - current_a = 0; - next_b = current_b + bgap; - priv->first_of_batch = TRUE; - } - - if (priv->end_align && - priv->first_of_batch) - { - current_a = compute_row_start (iter, current_a, priv); - priv->first_of_batch = FALSE; - } - - if (next_b-current_b < natural_b) - next_b = current_b + natural_b; - - { - ClutterUnit row_height; - ClutterActorBox child_box; - - if (homogenous_b) - { - row_height = priv->max_extent_b; - } - else - { - row_height = compute_row_height (iter, next_b-current_b, - current_a, priv); - } - - if (homogenous_a) - { - child_box.x1 = current_a + (priv->max_extent_a-natural_a) * aalign; - child_box.x2 = child_box.x1 + natural_a; - - } - else - { - child_box.x1 = current_a; - child_box.x2 = child_box.x1 + natural_a; - } - - child_box.y1 = current_b + (row_height-natural_b) * balign; - child_box.y2 = child_box.y1 + natural_b; - - - if (priv->column_major) - { - ClutterUnit temp = child_box.x1; - child_box.x1 = child_box.y1; - child_box.y1 = temp; - - temp = child_box.x2; - child_box.x2 = child_box.y2; - child_box.y2 = temp; - } - - /* update the allocation */ - clutter_actor_allocate (CLUTTER_ACTOR (child), - &child_box, - absolute_origin_changed); - - if (homogenous_a) - { - current_a += priv->max_extent_a + agap; - } - else - { - current_a += natural_a + agap; - } - } + + /* update the allocation */ + clutter_actor_allocate (CLUTTER_ACTOR (child), + &child_box, + absolute_origin_changed); + i++; + if (i == 3) { + i = 0; + j++; } + } } diff --git a/src/cheese-grid.h b/src/cheese-grid.h index 18d78dd..ff17556 100644 --- a/src/cheese-grid.h +++ b/src/cheese-grid.h @@ -69,30 +69,6 @@ struct _CheeseGrid GType cheese_grid_get_type (void) G_GNUC_CONST; ClutterActor *cheese_grid_new (void); -void cheese_grid_set_end_align (CheeseGrid *self, - gboolean value); -gboolean cheese_grid_get_end_align (CheeseGrid *self); -void cheese_grid_set_homogenous_rows (CheeseGrid *self, - gboolean value); -gboolean cheese_grid_get_homogenous_rows (CheeseGrid *self); -void cheese_grid_set_homogenous_columns (CheeseGrid *self, - gboolean value); -gboolean cheese_grid_get_homogenous_columns (CheeseGrid *self); -void cheese_grid_set_column_major (CheeseGrid *self, - gboolean value); -gboolean cheese_grid_get_column_major (CheeseGrid *self); -void cheese_grid_set_row_gap (CheeseGrid *self, - ClutterUnit value); -ClutterUnit cheese_grid_get_row_gap (CheeseGrid *self); -void cheese_grid_set_column_gap (CheeseGrid *self, - ClutterUnit value); -ClutterUnit cheese_grid_get_column_gap (CheeseGrid *self); -void cheese_grid_set_valign (CheeseGrid *self, - gdouble value); -gdouble cheese_grid_get_valign (CheeseGrid *self); -void cheese_grid_set_halign (CheeseGrid *self, - gdouble value); -gdouble cheese_grid_get_halign (CheeseGrid *self); G_END_DECLS diff --git a/src/cheese-stage.c b/src/cheese-stage.c index b4703d1..376acff 100644 --- a/src/cheese-stage.c +++ b/src/cheese-stage.c @@ -189,12 +189,7 @@ main (int argc, char *argv[]) clutter_color_from_string (&color, "DarkSlateBlue"); clutter_stage_set_color (CLUTTER_STAGE (stage), &color); - layout = g_object_new (CHEESE_TYPE_GRID, - "valign", 0.5, - "halign", 0.5, - "row-gap", CLUTTER_UNITS_FROM_INT(5), - "column-gap", CLUTTER_UNITS_FROM_INT(5), - NULL); + layout = g_object_new (CHEESE_TYPE_GRID, NULL); clutter_container_add_actor (CLUTTER_CONTAINER (stage), layout); |