2009-09-14 07:04:42 -04:00
|
|
|
/*
|
|
|
|
* Clutter.
|
|
|
|
*
|
|
|
|
* An OpenGL based 'interactive canvas' library.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Intel Corporation.
|
|
|
|
*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Author:
|
|
|
|
* Emmanuele Bassi <ebassi@linux.intel.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:clutter-bin-layout
|
|
|
|
* @short_description: A simple layout manager
|
|
|
|
*
|
|
|
|
* #ClutterBinLayout is a layout manager which implements the following
|
|
|
|
* policy:
|
|
|
|
*
|
2009-09-17 06:38:43 -04:00
|
|
|
* <itemizedlist>
|
|
|
|
* <listitem><simpara>the preferred size is the maximum preferred size
|
|
|
|
* between all the children of the container using the
|
|
|
|
* layout;</simpara></listitem>
|
|
|
|
* <listitem><simpara>each child is allocated in "layers", on on top
|
|
|
|
* of the other;</simpara></listitem>
|
|
|
|
* <listitem><simpara>for each layer there are horizontal and vertical
|
|
|
|
* alignment policies.</simpara></listitem>
|
|
|
|
* </itemizedlist>
|
|
|
|
*
|
2009-10-23 12:32:18 -04:00
|
|
|
* <figure id="bin-layout">
|
|
|
|
* <title>Bin layout</title>
|
|
|
|
* <para>The image shows a #ClutterBinLayout with three layers:
|
|
|
|
* a background #ClutterCairoTexture, set to fill on both the X
|
|
|
|
* and Y axis; a #ClutterTexture, set to center on both the X and
|
|
|
|
* Y axis; and a #ClutterRectangle, set to %CLUTTER_BIN_ALIGNMENT_END
|
|
|
|
* on both the X and Y axis.</para>
|
|
|
|
* <graphic fileref="bin-layout.png" format="PNG"/>
|
|
|
|
* </figure>
|
|
|
|
*
|
2009-09-17 06:38:43 -04:00
|
|
|
* <example id="example-clutter-bin-layout">
|
|
|
|
* <title>How to pack actors inside a BinLayout</title>
|
|
|
|
* <programlisting>
|
2012-05-01 13:30:10 -04:00
|
|
|
* <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../examples/bin-layout.c">
|
2012-03-29 12:20:45 -04:00
|
|
|
* <xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback>
|
|
|
|
* </xi:include>
|
2009-09-17 06:38:43 -04:00
|
|
|
* </programlisting>
|
|
|
|
* </example>
|
2009-09-14 07:04:42 -04:00
|
|
|
*
|
|
|
|
* #ClutterBinLayout is available since Clutter 1.2
|
|
|
|
*/
|
|
|
|
|
2009-09-11 08:51:23 -04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2009-10-15 09:12:37 -04:00
|
|
|
#include <math.h>
|
|
|
|
|
2012-03-29 11:34:36 -04:00
|
|
|
#include "clutter-actor-private.h"
|
2009-09-11 08:51:23 -04:00
|
|
|
#include "clutter-animatable.h"
|
2012-08-24 05:42:26 -04:00
|
|
|
#include "clutter-bin-layout.h"
|
2009-09-14 16:51:49 -04:00
|
|
|
#include "clutter-child-meta.h"
|
2009-09-11 08:51:23 -04:00
|
|
|
#include "clutter-debug.h"
|
|
|
|
#include "clutter-enum-types.h"
|
2009-09-15 12:37:11 -04:00
|
|
|
#include "clutter-layout-meta.h"
|
2009-09-11 08:51:23 -04:00
|
|
|
#include "clutter-private.h"
|
|
|
|
|
|
|
|
#define CLUTTER_BIN_LAYOUT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), CLUTTER_TYPE_BIN_LAYOUT, ClutterBinLayoutPrivate))
|
|
|
|
|
2009-09-15 12:37:11 -04:00
|
|
|
typedef struct _ClutterLayoutMetaClass ClutterBinLayerClass;
|
2009-09-14 16:51:49 -04:00
|
|
|
|
2009-09-11 08:51:23 -04:00
|
|
|
struct _ClutterBinLayoutPrivate
|
|
|
|
{
|
2009-09-16 10:51:13 -04:00
|
|
|
ClutterContainer *container;
|
2009-09-11 08:51:23 -04:00
|
|
|
};
|
|
|
|
|
2012-08-24 05:42:26 -04:00
|
|
|
G_DEFINE_TYPE (ClutterBinLayout, clutter_bin_layout, CLUTTER_TYPE_LAYOUT_MANAGER)
|
2009-09-11 08:51:23 -04:00
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_bin_layout_get_preferred_width (ClutterLayoutManager *manager,
|
|
|
|
ClutterContainer *container,
|
|
|
|
gfloat for_height,
|
|
|
|
gfloat *min_width_p,
|
|
|
|
gfloat *nat_width_p)
|
|
|
|
{
|
2011-12-18 05:29:01 -05:00
|
|
|
ClutterActor *actor = CLUTTER_ACTOR (container);
|
2012-01-30 05:55:30 -05:00
|
|
|
ClutterActorIter iter;
|
2011-12-18 05:29:01 -05:00
|
|
|
ClutterActor *child;
|
2009-09-11 08:51:23 -04:00
|
|
|
gfloat min_width, nat_width;
|
|
|
|
|
|
|
|
min_width = nat_width = 0.0;
|
|
|
|
|
2012-01-30 05:55:30 -05:00
|
|
|
clutter_actor_iter_init (&iter, actor);
|
|
|
|
while (clutter_actor_iter_next (&iter, &child))
|
2009-09-11 08:51:23 -04:00
|
|
|
{
|
|
|
|
gfloat minimum, natural;
|
|
|
|
|
2012-06-05 04:55:17 -04:00
|
|
|
if (!CLUTTER_ACTOR_IS_VISIBLE (child))
|
|
|
|
continue;
|
|
|
|
|
2009-09-11 08:51:23 -04:00
|
|
|
clutter_actor_get_preferred_width (child, for_height,
|
|
|
|
&minimum,
|
|
|
|
&natural);
|
|
|
|
|
|
|
|
min_width = MAX (min_width, minimum);
|
|
|
|
nat_width = MAX (nat_width, natural);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (min_width_p)
|
|
|
|
*min_width_p = min_width;
|
|
|
|
|
|
|
|
if (nat_width_p)
|
|
|
|
*nat_width_p = nat_width;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_bin_layout_get_preferred_height (ClutterLayoutManager *manager,
|
|
|
|
ClutterContainer *container,
|
|
|
|
gfloat for_width,
|
|
|
|
gfloat *min_height_p,
|
|
|
|
gfloat *nat_height_p)
|
|
|
|
{
|
2011-12-18 05:29:01 -05:00
|
|
|
ClutterActor *actor = CLUTTER_ACTOR (container);
|
2012-01-30 05:55:30 -05:00
|
|
|
ClutterActorIter iter;
|
2011-12-18 05:29:01 -05:00
|
|
|
ClutterActor *child;
|
2009-09-11 08:51:23 -04:00
|
|
|
gfloat min_height, nat_height;
|
|
|
|
|
|
|
|
min_height = nat_height = 0.0;
|
|
|
|
|
2012-01-30 05:55:30 -05:00
|
|
|
clutter_actor_iter_init (&iter, actor);
|
|
|
|
while (clutter_actor_iter_next (&iter, &child))
|
2009-09-11 08:51:23 -04:00
|
|
|
{
|
|
|
|
gfloat minimum, natural;
|
|
|
|
|
2012-06-05 04:55:17 -04:00
|
|
|
if (!CLUTTER_ACTOR_IS_VISIBLE (child))
|
|
|
|
continue;
|
|
|
|
|
2009-09-11 08:51:23 -04:00
|
|
|
clutter_actor_get_preferred_height (child, for_width,
|
|
|
|
&minimum,
|
|
|
|
&natural);
|
|
|
|
|
|
|
|
min_height = MAX (min_height, minimum);
|
|
|
|
nat_height = MAX (nat_height, natural);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (min_height_p)
|
|
|
|
*min_height_p = min_height;
|
|
|
|
|
|
|
|
if (nat_height_p)
|
|
|
|
*nat_height_p = nat_height;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_bin_layout_allocate (ClutterLayoutManager *manager,
|
|
|
|
ClutterContainer *container,
|
|
|
|
const ClutterActorBox *allocation,
|
|
|
|
ClutterAllocationFlags flags)
|
|
|
|
{
|
2011-08-24 13:38:17 -04:00
|
|
|
gfloat allocation_x, allocation_y;
|
2009-09-11 08:51:23 -04:00
|
|
|
gfloat available_w, available_h;
|
2011-12-18 05:29:01 -05:00
|
|
|
ClutterActor *actor, *child;
|
2012-01-30 05:55:30 -05:00
|
|
|
ClutterActorIter iter;
|
2009-09-11 08:51:23 -04:00
|
|
|
|
2011-08-24 13:38:17 -04:00
|
|
|
clutter_actor_box_get_origin (allocation, &allocation_x, &allocation_y);
|
|
|
|
clutter_actor_box_get_size (allocation, &available_w, &available_h);
|
2009-09-11 08:51:23 -04:00
|
|
|
|
2011-12-18 05:29:01 -05:00
|
|
|
actor = CLUTTER_ACTOR (container);
|
|
|
|
|
2012-01-30 05:55:30 -05:00
|
|
|
clutter_actor_iter_init (&iter, actor);
|
|
|
|
while (clutter_actor_iter_next (&iter, &child))
|
2009-09-11 08:51:23 -04:00
|
|
|
{
|
|
|
|
ClutterActorBox child_alloc = { 0, };
|
2012-08-24 05:42:26 -04:00
|
|
|
gboolean is_fixed_position_set;
|
2012-08-09 12:11:10 -04:00
|
|
|
float fixed_x, fixed_y;
|
2009-09-11 08:51:23 -04:00
|
|
|
|
2012-06-08 05:29:43 -04:00
|
|
|
if (!CLUTTER_ACTOR_IS_VISIBLE (child))
|
|
|
|
continue;
|
|
|
|
|
2012-08-09 12:11:10 -04:00
|
|
|
fixed_x = fixed_y = 0.f;
|
|
|
|
g_object_get (child,
|
|
|
|
"fixed-position-set", &is_fixed_position_set,
|
|
|
|
"fixed-x", &fixed_x,
|
|
|
|
"fixed-y", &fixed_y,
|
|
|
|
NULL);
|
|
|
|
|
2012-08-24 05:42:26 -04:00
|
|
|
if (is_fixed_position_set)
|
2012-06-07 10:44:08 -04:00
|
|
|
{
|
2012-08-24 05:42:26 -04:00
|
|
|
child_alloc.x1 = fixed_x;
|
|
|
|
child_alloc.y1 = fixed_y;
|
2012-06-07 10:44:08 -04:00
|
|
|
}
|
2012-03-29 11:34:36 -04:00
|
|
|
else
|
|
|
|
{
|
2012-08-24 05:42:26 -04:00
|
|
|
child_alloc.x1 = allocation_x;
|
|
|
|
child_alloc.y1 = allocation_y;
|
2012-03-29 11:34:36 -04:00
|
|
|
}
|
|
|
|
|
2012-08-24 05:42:26 -04:00
|
|
|
child_alloc.x2 = available_w;
|
|
|
|
child_alloc.y2 = available_h;
|
2009-09-11 08:51:23 -04:00
|
|
|
|
2012-08-24 05:42:26 -04:00
|
|
|
clutter_actor_allocate (child, &child_alloc, flags);
|
2009-09-11 08:51:23 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-16 10:51:13 -04:00
|
|
|
static void
|
|
|
|
clutter_bin_layout_set_container (ClutterLayoutManager *manager,
|
|
|
|
ClutterContainer *container)
|
|
|
|
{
|
|
|
|
ClutterBinLayoutPrivate *priv;
|
2010-06-07 16:34:36 -04:00
|
|
|
ClutterLayoutManagerClass *parent_class;
|
2009-09-16 10:51:13 -04:00
|
|
|
|
|
|
|
priv = CLUTTER_BIN_LAYOUT (manager)->priv;
|
|
|
|
priv->container = container;
|
2010-06-07 16:34:36 -04:00
|
|
|
|
|
|
|
parent_class = CLUTTER_LAYOUT_MANAGER_CLASS (clutter_bin_layout_parent_class);
|
|
|
|
parent_class->set_container (manager, container);
|
2009-09-16 10:51:13 -04:00
|
|
|
}
|
|
|
|
|
2009-09-11 08:51:23 -04:00
|
|
|
static void
|
|
|
|
clutter_bin_layout_class_init (ClutterBinLayoutClass *klass)
|
|
|
|
{
|
|
|
|
ClutterLayoutManagerClass *layout_class =
|
|
|
|
CLUTTER_LAYOUT_MANAGER_CLASS (klass);
|
|
|
|
|
|
|
|
g_type_class_add_private (klass, sizeof (ClutterBinLayoutPrivate));
|
|
|
|
|
2012-01-30 05:55:30 -05:00
|
|
|
layout_class->get_preferred_width = clutter_bin_layout_get_preferred_width;
|
|
|
|
layout_class->get_preferred_height = clutter_bin_layout_get_preferred_height;
|
|
|
|
layout_class->allocate = clutter_bin_layout_allocate;
|
|
|
|
layout_class->set_container = clutter_bin_layout_set_container;
|
2009-09-11 08:51:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_bin_layout_init (ClutterBinLayout *self)
|
|
|
|
{
|
|
|
|
self->priv = CLUTTER_BIN_LAYOUT_GET_PRIVATE (self);
|
|
|
|
}
|
|
|
|
|
2009-09-14 07:04:42 -04:00
|
|
|
/**
|
|
|
|
* clutter_bin_layout_new:
|
2009-09-14 16:51:49 -04:00
|
|
|
* @x_align: the default alignment policy to be used on the
|
2009-09-14 07:04:42 -04:00
|
|
|
* horizontal axis
|
2009-09-14 16:51:49 -04:00
|
|
|
* @y_align: the default alignment policy to be used on the
|
2009-09-14 07:04:42 -04:00
|
|
|
* vertical axis
|
|
|
|
*
|
|
|
|
* Creates a new #ClutterBinLayout layout manager
|
|
|
|
*
|
|
|
|
* Return value: the newly created layout manager
|
|
|
|
*
|
2012-08-27 04:48:36 -04:00
|
|
|
*
|
2009-09-14 07:04:42 -04:00
|
|
|
*/
|
2009-09-11 08:51:23 -04:00
|
|
|
ClutterLayoutManager *
|
2012-08-24 05:42:26 -04:00
|
|
|
clutter_bin_layout_new (void)
|
2009-09-11 08:51:23 -04:00
|
|
|
{
|
2012-08-24 05:42:26 -04:00
|
|
|
return g_object_new (CLUTTER_TYPE_BIN_LAYOUT, NULL);
|
2009-09-16 10:51:13 -04:00
|
|
|
}
|