[gtk+/wip/actor: 6/24] actors: Add GtkBinLayout



commit cc86c700eb910f80e56c0ea1bba9e2c1abe1706d
Author: Benjamin Otte <otte redhat com>
Date:   Sun Dec 9 23:31:26 2012 +0100

    actors: Add GtkBinLayout
    
    Also mostly copied from Clutter - at least in name and function.

 gtk/actors/Makefile.am           |    2 +
 gtk/actors/gtkbinlayout.c        |  163 ++++++++++++++++++++++++++++++++++++++
 gtk/actors/gtkbinlayoutprivate.h |   80 +++++++++++++++++++
 3 files changed, 245 insertions(+), 0 deletions(-)
---
diff --git a/gtk/actors/Makefile.am b/gtk/actors/Makefile.am
index 2b60c5d..d5288c7 100644
--- a/gtk/actors/Makefile.am
+++ b/gtk/actors/Makefile.am
@@ -4,10 +4,12 @@ noinst_LTLIBRARIES = libgtkactors.la
 
 gtkactors_c_sources =			\
 	gtkactor.c			\
+	gtkbinlayout.c			\
 	gtklayoutmanager.c
 
 gtkactors_private_h_sources =		\
 	gtkactorprivate.h		\
+	gtkbinlayoutprivate.h		\
 	gtklayoutmanagerprivate.h
 
 libgtkactors_la_SOURCES = 		\
diff --git a/gtk/actors/gtkbinlayout.c b/gtk/actors/gtkbinlayout.c
new file mode 100644
index 0000000..83ad858
--- /dev/null
+++ b/gtk/actors/gtkbinlayout.c
@@ -0,0 +1,163 @@
+/*
+ * Gtk.
+ *
+ * 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:_gtk-bin-layout
+ * @short_description: A simple layout manager
+ *
+ * #GtkBinLayout is a layout manager which implements the following
+ * policy:
+ *
+ * <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>
+ * </itemizedlist>
+ *
+ * <figure id="bin-layout">
+ *   <title>Bin layout</title>
+ *   <para>The image shows a #GtkBinLayout with three layers:
+ *   a background #GtkCairoTexture, set to fill on both the X
+ *   and Y axis; a #GtkTexture, set to center on both the X and
+ *   Y axis; and a #GtkRectangle, set to %GTK_BIN_ALIGNMENT_END
+ *   on both the X and Y axis.</para>
+ *   <graphic fileref="bin-layout.png" format="PNG"/>
+ * </figure>
+ *
+ * <example id="example-_gtk-bin-layout">
+ *  <title>How to pack actors inside a BinLayout</title>
+ *  <programlisting>
+ * <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"; parse="text" href="../../../../examples/bin-layout.c">
+ *   <xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback>
+ * </xi:include>
+ *  </programlisting>
+ * </example>
+ *
+ * #GtkBinLayout is available since Gtk 1.2
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "gtkbinlayoutprivate.h"
+
+struct _GtkBinLayoutPrivate {
+  gint dummy;
+};
+
+G_DEFINE_TYPE (GtkBinLayout,
+               _gtk_bin_layout,
+               GTK_TYPE_LAYOUT_MANAGER);
+
+/*
+ * GtkBinLayout
+ */
+
+static void
+gtk_bin_layout_get_preferred_size (GtkLayoutManager *manager,
+                                   GtkOrientation    orientation,
+                                   gfloat            for_size,
+                                   gfloat           *min_size_p,
+                                   gfloat           *nat_size_p)
+{
+  GtkActor *actor = _gtk_layout_manager_get_actor (manager);
+  GtkActor *child;
+  gfloat min_size, nat_size;
+
+  min_size = nat_size = 0.0;
+
+  for (child = _gtk_actor_get_first_child (actor);
+       child;
+       child = _gtk_actor_get_next_sibling (child))
+    {
+      gfloat minimum, natural;
+
+      _gtk_actor_get_preferred_size (child,
+                                     orientation,
+                                     for_size,
+                                     &minimum,
+                                     &natural);
+
+      min_size = MAX (min_size, minimum);
+      nat_size = MAX (nat_size, natural);
+    }
+
+  *min_size_p = min_size;
+  *nat_size_p = nat_size;
+}
+
+static void
+gtk_bin_layout_allocate (GtkLayoutManager     *manager,
+                         const cairo_matrix_t *transform,
+                         gfloat                width,
+                         gfloat                height)
+{
+  GtkActor *actor, *child;
+
+  actor = _gtk_layout_manager_get_actor (manager);
+
+  for (child = _gtk_actor_get_first_child (actor);
+       child;
+       child = _gtk_actor_get_next_sibling (child))
+    {
+      _gtk_actor_allocate (child, transform, width, height);
+    }
+}
+
+static void
+_gtk_bin_layout_class_init (GtkBinLayoutClass *klass)
+{
+  GtkLayoutManagerClass *layout_class = GTK_LAYOUT_MANAGER_CLASS (klass);
+
+  g_type_class_add_private (klass, sizeof (GtkBinLayoutPrivate));
+
+  layout_class->get_preferred_size = gtk_bin_layout_get_preferred_size;
+  layout_class->allocate = gtk_bin_layout_allocate;
+}
+
+static void
+_gtk_bin_layout_init (GtkBinLayout *self)
+{
+  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+                                            GTK_TYPE_BIN_LAYOUT,
+                                            GtkBinLayoutPrivate);
+}
+
+/**
+ * _gtk_bin_layout_new:
+ *
+ * Creates a new #GtkBinLayout layout manager
+ *
+ * Return value: the newly created layout manager
+ *
+ * Since: 1.2
+ */
+GtkLayoutManager *
+_gtk_bin_layout_new (void)
+{
+  return g_object_new (GTK_TYPE_BIN_LAYOUT, NULL);
+}
diff --git a/gtk/actors/gtkbinlayoutprivate.h b/gtk/actors/gtkbinlayoutprivate.h
new file mode 100644
index 0000000..c002423
--- /dev/null
+++ b/gtk/actors/gtkbinlayoutprivate.h
@@ -0,0 +1,80 @@
+/*
+ * Gtk.
+ *
+ * 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>
+ */
+
+#ifndef __GTK_BIN_LAYOUT_PRIVATE_H__
+#define __GTK_BIN_LAYOUT_PRIVATE_H__
+
+#include <gtk/actors/gtklayoutmanagerprivate.h>
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_BIN_LAYOUT                 (_gtk_bin_layout_get_type ())
+#define GTK_BIN_LAYOUT(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_BIN_LAYOUT, GtkBinLayout))
+#define GTK_IS_BIN_LAYOUT(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_BIN_LAYOUT))
+#define GTK_BIN_LAYOUT_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_BIN_LAYOUT, GtkBinLayoutClass))
+#define GTK_IS_BIN_LAYOUT_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_BIN_LAYOUT))
+#define GTK_BIN_LAYOUT_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_BIN_LAYOUT, GtkBinLayoutClass))
+
+typedef struct _GtkBinLayout                GtkBinLayout;
+typedef struct _GtkBinLayoutPrivate         GtkBinLayoutPrivate;
+typedef struct _GtkBinLayoutClass           GtkBinLayoutClass;
+
+/**
+ * GtkBinLayout:
+ *
+ * The #GtkBinLayout structure contains only private data
+ * and should be accessed using the provided API
+ *
+ * Since: 1.2
+ */
+struct _GtkBinLayout
+{
+  /*< private >*/
+  GtkLayoutManager parent_instance;
+
+  GtkBinLayoutPrivate *priv;
+};
+
+/**
+ * GtkBinLayoutClass:
+ *
+ * The #GtkBinLayoutClass structure contains only private
+ * data and should be accessed using the provided API
+ *
+ * Since: 1.2
+ */
+struct _GtkBinLayoutClass
+{
+  /*< private >*/
+  GtkLayoutManagerClass parent_class;
+};
+
+GType                   _gtk_bin_layout_get_type                 (void) G_GNUC_CONST;
+
+GtkLayoutManager *      _gtk_bin_layout_new                      (void);
+
+
+G_END_DECLS
+
+#endif /* __GTK_BIN_LAYOUT_H__ */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]