2009-09-14 11:04:42 +00: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 10:38:43 +00: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 16:32:18 +00: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 10:38:43 +00:00
|
|
|
* <example id="example-clutter-bin-layout">
|
|
|
|
* <title>How to pack actors inside a BinLayout</title>
|
|
|
|
* <programlisting>
|
2012-05-01 17:30:10 +00:00
|
|
|
* <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../examples/bin-layout.c">
|
2012-03-29 16:20:45 +00:00
|
|
|
* <xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback>
|
|
|
|
* </xi:include>
|
2009-09-17 10:38:43 +00:00
|
|
|
* </programlisting>
|
|
|
|
* </example>
|
2009-09-14 11:04:42 +00:00
|
|
|
*
|
|
|
|
* #ClutterBinLayout is available since Clutter 1.2
|
|
|
|
*/
|
|
|
|
|
2009-09-11 12:51:23 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2009-10-15 13:12:37 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
2012-03-29 15:34:36 +00:00
|
|
|
#include "clutter-actor-private.h"
|
2009-09-11 12:51:23 +00:00
|
|
|
#include "clutter-animatable.h"
|
2012-08-24 09:42:26 +00:00
|
|
|
#include "clutter-bin-layout.h"
|
2009-09-14 20:51:49 +00:00
|
|
|
#include "clutter-child-meta.h"
|
2009-09-11 12:51:23 +00:00
|
|
|
#include "clutter-debug.h"
|
|
|
|
#include "clutter-enum-types.h"
|
2009-09-15 16:37:11 +00:00
|
|
|
#include "clutter-layout-meta.h"
|
2009-09-11 12:51:23 +00: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 16:37:11 +00:00
|
|
|
typedef struct _ClutterLayoutMetaClass ClutterBinLayerClass;
|
2009-09-14 20:51:49 +00:00
|
|
|
|
2009-09-11 12:51:23 +00:00
|
|
|
struct _ClutterBinLayoutPrivate
|
|
|
|
{
|
2009-09-16 14:51:13 +00:00
|
|
|
ClutterContainer *container;
|
2009-09-11 12:51:23 +00:00
|
|
|
};
|
|
|
|
|
2012-08-24 09:42:26 +00:00
|
|
|
G_DEFINE_TYPE (ClutterBinLayout, clutter_bin_layout, CLUTTER_TYPE_LAYOUT_MANAGER)
|
2009-09-11 12:51:23 +00: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 10:29:01 +00:00
|
|
|
ClutterActor *actor = CLUTTER_ACTOR (container);
|
2012-01-30 10:55:30 +00:00
|
|
|
ClutterActorIter iter;
|
2011-12-18 10:29:01 +00:00
|
|
|
ClutterActor *child;
|
2009-09-11 12:51:23 +00:00
|
|
|
gfloat min_width, nat_width;
|
|
|
|
|
|
|
|
min_width = nat_width = 0.0;
|
|
|
|
|
2012-01-30 10:55:30 +00:00
|
|
|
clutter_actor_iter_init (&iter, actor);
|
|
|
|
while (clutter_actor_iter_next (&iter, &child))
|
2009-09-11 12:51:23 +00:00
|
|
|
{
|
|
|
|
gfloat minimum, natural;
|
|
|
|
|
2012-06-05 08:55:17 +00:00
|
|
|
if (!CLUTTER_ACTOR_IS_VISIBLE (child))
|
|
|
|
continue;
|
|
|
|
|
2009-09-11 12:51:23 +00: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 10:29:01 +00:00
|
|
|
ClutterActor *actor = CLUTTER_ACTOR (container);
|
2012-01-30 10:55:30 +00:00
|
|
|
ClutterActorIter iter;
|
2011-12-18 10:29:01 +00:00
|
|
|
ClutterActor *child;
|
2009-09-11 12:51:23 +00:00
|
|
|
gfloat min_height, nat_height;
|
|
|
|
|
|
|
|
min_height = nat_height = 0.0;
|
|
|
|
|
2012-01-30 10:55:30 +00:00
|
|
|
clutter_actor_iter_init (&iter, actor);
|
|
|
|
while (clutter_actor_iter_next (&iter, &child))
|
2009-09-11 12:51:23 +00:00
|
|
|
{
|
|
|
|
gfloat minimum, natural;
|
|
|
|
|
2012-06-05 08:55:17 +00:00
|
|
|
if (!CLUTTER_ACTOR_IS_VISIBLE (child))
|
|
|
|
continue;
|
|
|
|
|
2009-09-11 12:51:23 +00: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 17:38:17 +00:00
|
|
|
gfloat allocation_x, allocation_y;
|
2009-09-11 12:51:23 +00:00
|
|
|
gfloat available_w, available_h;
|
2011-12-18 10:29:01 +00:00
|
|
|
ClutterActor *actor, *child;
|
2012-01-30 10:55:30 +00:00
|
|
|
ClutterActorIter iter;
|
2009-09-11 12:51:23 +00:00
|
|
|
|
2011-08-24 17:38:17 +00:00
|
|
|
clutter_actor_box_get_origin (allocation, &allocation_x, &allocation_y);
|
|
|
|
clutter_actor_box_get_size (allocation, &available_w, &available_h);
|
2009-09-11 12:51:23 +00:00
|
|
|
|
2011-12-18 10:29:01 +00:00
|
|
|
actor = CLUTTER_ACTOR (container);
|
|
|
|
|
2012-01-30 10:55:30 +00:00
|
|
|
clutter_actor_iter_init (&iter, actor);
|
|
|
|
while (clutter_actor_iter_next (&iter, &child))
|
2009-09-11 12:51:23 +00:00
|
|
|
{
|
|
|
|
ClutterActorBox child_alloc = { 0, };
|
2012-08-24 09:42:26 +00:00
|
|
|
gboolean is_fixed_position_set;
|
2012-08-09 16:11:10 +00:00
|
|
|
float fixed_x, fixed_y;
|
2009-09-11 12:51:23 +00:00
|
|
|
|
2012-06-08 09:29:43 +00:00
|
|
|
if (!CLUTTER_ACTOR_IS_VISIBLE (child))
|
|
|
|
continue;
|
|
|
|
|
2012-08-09 16:11:10 +00: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 09:42:26 +00:00
|
|
|
if (is_fixed_position_set)
|
2012-06-07 14:44:08 +00:00
|
|
|
{
|
2012-08-24 09:42:26 +00:00
|
|
|
child_alloc.x1 = fixed_x;
|
|
|
|
child_alloc.y1 = fixed_y;
|
2012-06-07 14:44:08 +00:00
|
|
|
}
|
2012-03-29 15:34:36 +00:00
|
|
|
else
|
|
|
|
{
|
2012-08-24 09:42:26 +00:00
|
|
|
child_alloc.x1 = allocation_x;
|
|
|
|
child_alloc.y1 = allocation_y;
|
2012-03-29 15:34:36 +00:00
|
|
|
}
|
|
|
|
|
2012-08-24 09:42:26 +00:00
|
|
|
child_alloc.x2 = available_w;
|
|
|
|
child_alloc.y2 = available_h;
|
2009-09-11 12:51:23 +00:00
|
|
|
|
2012-08-24 09:42:26 +00:00
|
|
|
clutter_actor_allocate (child, &child_alloc, flags);
|
2009-09-11 12:51:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-16 14:51:13 +00:00
|
|
|
static void
|
|
|
|
clutter_bin_layout_set_container (ClutterLayoutManager *manager,
|
|
|
|
ClutterContainer *container)
|
|
|
|
{
|
|
|
|
ClutterBinLayoutPrivate *priv;
|
2010-06-07 20:34:36 +00:00
|
|
|
ClutterLayoutManagerClass *parent_class;
|
2009-09-16 14:51:13 +00:00
|
|
|
|
|
|
|
priv = CLUTTER_BIN_LAYOUT (manager)->priv;
|
|
|
|
priv->container = container;
|
2010-06-07 20:34:36 +00:00
|
|
|
|
|
|
|
parent_class = CLUTTER_LAYOUT_MANAGER_CLASS (clutter_bin_layout_parent_class);
|
|
|
|
parent_class->set_container (manager, container);
|
2009-09-16 14:51:13 +00:00
|
|
|
}
|
|
|
|
|
2009-09-11 12:51:23 +00: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 10:55:30 +00: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 12:51:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_bin_layout_init (ClutterBinLayout *self)
|
|
|
|
{
|
|
|
|
self->priv = CLUTTER_BIN_LAYOUT_GET_PRIVATE (self);
|
|
|
|
}
|
|
|
|
|
2009-09-14 11:04:42 +00:00
|
|
|
/**
|
|
|
|
* clutter_bin_layout_new:
|
|
|
|
*
|
|
|
|
* Creates a new #ClutterBinLayout layout manager
|
|
|
|
*
|
|
|
|
* Return value: the newly created layout manager
|
|
|
|
*/
|
2009-09-11 12:51:23 +00:00
|
|
|
ClutterLayoutManager *
|
2012-08-24 09:42:26 +00:00
|
|
|
clutter_bin_layout_new (void)
|
2009-09-11 12:51:23 +00:00
|
|
|
{
|
2012-08-24 09:42:26 +00:00
|
|
|
return g_object_new (CLUTTER_TYPE_BIN_LAYOUT, NULL);
|
2009-09-16 14:51:13 +00:00
|
|
|
}
|