[gtk/wip/otte/transform: 2/2] wip: Add a cube stack transition
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/transform: 2/2] wip: Add a cube stack transition
- Date: Tue, 5 Mar 2019 19:45:44 +0000 (UTC)
commit 3a8db343b8f5d8fe16712b19b9759083148508be
Author: Benjamin Otte <otte redhat com>
Date: Tue Mar 5 20:44:45 2019 +0100
wip: Add a cube stack transition
demos/widget-factory/widget-factory.c | 2 +-
demos/widget-factory/widget-factory.ui | 2 +-
gtk/gtkstack.c | 85 +++++++++++++++++++++++++++++++++-
gtk/gtkstack.h | 3 +-
4 files changed, 88 insertions(+), 4 deletions(-)
---
diff --git a/demos/widget-factory/widget-factory.c b/demos/widget-factory/widget-factory.c
index dcd4760e97..07c6cdd686 100644
--- a/demos/widget-factory/widget-factory.c
+++ b/demos/widget-factory/widget-factory.c
@@ -48,7 +48,7 @@ change_transition_state (GSimpleAction *action,
GtkStackTransitionType transition;
if (g_variant_get_boolean (state))
- transition = GTK_STACK_TRANSITION_TYPE_SLIDE_LEFT_RIGHT;
+ transition = GTK_STACK_TRANSITION_TYPE_CUBE;
else
transition = GTK_STACK_TRANSITION_TYPE_NONE;
diff --git a/demos/widget-factory/widget-factory.ui b/demos/widget-factory/widget-factory.ui
index f7b624c7a0..bed044268a 100644
--- a/demos/widget-factory/widget-factory.ui
+++ b/demos/widget-factory/widget-factory.ui
@@ -429,7 +429,7 @@ Suspendisse feugiat quam quis dolor accumsan cursus.</property>
<property name="margin">10</property>
<child>
<object class="GtkStack" id="toplevel_stack">
- <property name="transition-duration">30000</property>
+ <property name="transition-duration">3000</property>
<child>
<object class="GtkStackPage">
<property name="name">page1</property>
diff --git a/gtk/gtkstack.c b/gtk/gtkstack.c
index f9a7723448..2d264fb020 100644
--- a/gtk/gtkstack.c
+++ b/gtk/gtkstack.c
@@ -104,6 +104,7 @@
* @GTK_STACK_TRANSITION_TYPE_OVER_DOWN_UP: Cover the old page sliding down or uncover the new page sliding
up, according to order
* @GTK_STACK_TRANSITION_TYPE_OVER_LEFT_RIGHT: Cover the old page sliding left or uncover the new page
sliding right, according to order
* @GTK_STACK_TRANSITION_TYPE_OVER_RIGHT_LEFT: Cover the old page sliding right or uncover the new page
sliding left, according to order
+ * @GTK_STACK_TRANSITION_TYPE_CUBE: Pretend the pages are sides of a cube and rotate that cube
*
* These enumeration values describe the possible transitions
* between pages in a #GtkStack widget.
@@ -911,6 +912,7 @@ get_simple_transition_type (gboolean new_child_first,
case GTK_STACK_TRANSITION_TYPE_UNDER_LEFT:
case GTK_STACK_TRANSITION_TYPE_UNDER_RIGHT:
case GTK_STACK_TRANSITION_TYPE_CROSSFADE:
+ case GTK_STACK_TRANSITION_TYPE_CUBE:
default:
return transition_type;
}
@@ -1071,6 +1073,7 @@ effective_transition_type (GtkStack *stack,
case GTK_STACK_TRANSITION_TYPE_OVER_LEFT_RIGHT:
case GTK_STACK_TRANSITION_TYPE_OVER_RIGHT_LEFT:
case GTK_STACK_TRANSITION_TYPE_CROSSFADE:
+ case GTK_STACK_TRANSITION_TYPE_CUBE:
default:
return transition_type;
}
@@ -2047,7 +2050,6 @@ gtk_stack_forall (GtkContainer *container,
}
}
-#include <gsk/gskrendernodeprivate.h>
static void
gtk_stack_compute_expand (GtkWidget *widget,
gboolean *hexpand_p,
@@ -2169,6 +2171,84 @@ gtk_stack_snapshot_under (GtkWidget *widget,
}
}
+static void
+gtk_stack_snapshot_cube (GtkWidget *widget,
+ GtkSnapshot *snapshot)
+{
+ GtkStack *stack = GTK_STACK (widget);
+ GtkStackPrivate *priv = gtk_stack_get_instance_private (stack);
+ double progress = gtk_progress_tracker_get_progress (&priv->tracker, FALSE);
+
+ if (priv->last_visible_node && progress > 0.5)
+ {
+ gtk_snapshot_save (snapshot);
+ gtk_snapshot_translate_3d (snapshot, &GRAPHENE_POINT3D_INIT (
+ gtk_widget_get_width (widget) / 2.f,
+ gtk_widget_get_height (widget) / 2.f,
+ 0));
+ gtk_snapshot_perspective (snapshot, 2 * gtk_widget_get_width (widget) / 1.f);
+ gtk_snapshot_translate_3d (snapshot, &GRAPHENE_POINT3D_INIT (
+ 0, 0,
+ - gtk_widget_get_width (widget) / 2.f));
+ gtk_snapshot_rotate_3d (snapshot, -90 * progress, graphene_vec3_y_axis());
+ gtk_snapshot_translate_3d (snapshot, &GRAPHENE_POINT3D_INIT (
+ - gtk_widget_get_width (widget) / 2.f,
+ - gtk_widget_get_height (widget) / 2.f,
+ gtk_widget_get_width (widget) / 2.f));
+ gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (
+ priv->last_visible_surface_allocation.x,
+ priv->last_visible_surface_allocation.y));
+ gtk_snapshot_append_node (snapshot, priv->last_visible_node);
+ gtk_snapshot_restore (snapshot);
+ }
+
+ gtk_snapshot_save (snapshot);
+ gtk_snapshot_translate_3d (snapshot, &GRAPHENE_POINT3D_INIT (
+ gtk_widget_get_width (widget) / 2.f,
+ gtk_widget_get_height (widget) / 2.f,
+ 0));
+ gtk_snapshot_perspective (snapshot, 2 * gtk_widget_get_width (widget) / 1.f);
+ gtk_snapshot_translate_3d (snapshot, &GRAPHENE_POINT3D_INIT (
+ 0, 0,
+ - gtk_widget_get_width (widget) / 2.f));
+ gtk_snapshot_rotate_3d (snapshot, 90 * (1.0 - progress), graphene_vec3_y_axis());
+ gtk_snapshot_translate_3d (snapshot, &GRAPHENE_POINT3D_INIT (
+ - gtk_widget_get_width (widget) / 2.f,
+ - gtk_widget_get_height (widget) / 2.f,
+ gtk_widget_get_width (widget) / 2.f));
+ gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (
+ priv->last_visible_surface_allocation.x,
+ priv->last_visible_surface_allocation.y));
+
+ gtk_widget_snapshot_child (widget,
+ priv->visible_child->widget,
+ snapshot);
+ gtk_snapshot_restore (snapshot);
+
+ if (priv->last_visible_node && progress <= 0.5)
+ {
+ gtk_snapshot_save (snapshot);
+ gtk_snapshot_translate_3d (snapshot, &GRAPHENE_POINT3D_INIT (
+ gtk_widget_get_width (widget) / 2.f,
+ gtk_widget_get_height (widget) / 2.f,
+ 0));
+ gtk_snapshot_perspective (snapshot, 2 * gtk_widget_get_width (widget) / 1.f);
+ gtk_snapshot_translate_3d (snapshot, &GRAPHENE_POINT3D_INIT (
+ 0, 0,
+ - gtk_widget_get_width (widget) / 2.f));
+ gtk_snapshot_rotate_3d (snapshot, -90 * progress, graphene_vec3_y_axis());
+ gtk_snapshot_translate_3d (snapshot, &GRAPHENE_POINT3D_INIT (
+ - gtk_widget_get_width (widget) / 2.f,
+ - gtk_widget_get_height (widget) / 2.f,
+ gtk_widget_get_width (widget) / 2.f));
+ gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (
+ priv->last_visible_surface_allocation.x,
+ priv->last_visible_surface_allocation.y));
+ gtk_snapshot_append_node (snapshot, priv->last_visible_node);
+ gtk_snapshot_restore (snapshot);
+ }
+}
+
static void
gtk_stack_snapshot_slide (GtkWidget *widget,
GtkSnapshot *snapshot)
@@ -2285,6 +2365,9 @@ gtk_stack_snapshot (GtkWidget *widget,
case GTK_STACK_TRANSITION_TYPE_UNDER_RIGHT:
gtk_stack_snapshot_under (widget, snapshot);
break;
+ case GTK_STACK_TRANSITION_TYPE_CUBE:
+ gtk_stack_snapshot_cube (widget, snapshot);
+ break;
case GTK_STACK_TRANSITION_TYPE_NONE:
case GTK_STACK_TRANSITION_TYPE_SLIDE_LEFT_RIGHT:
case GTK_STACK_TRANSITION_TYPE_SLIDE_UP_DOWN:
diff --git a/gtk/gtkstack.h b/gtk/gtkstack.h
index 658ef8bb6a..1309ea2c7d 100644
--- a/gtk/gtkstack.h
+++ b/gtk/gtkstack.h
@@ -72,7 +72,8 @@ typedef enum {
GTK_STACK_TRANSITION_TYPE_OVER_UP_DOWN,
GTK_STACK_TRANSITION_TYPE_OVER_DOWN_UP,
GTK_STACK_TRANSITION_TYPE_OVER_LEFT_RIGHT,
- GTK_STACK_TRANSITION_TYPE_OVER_RIGHT_LEFT
+ GTK_STACK_TRANSITION_TYPE_OVER_RIGHT_LEFT,
+ GTK_STACK_TRANSITION_TYPE_CUBE
} GtkStackTransitionType;
struct _GtkStack {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]