summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2019-03-05 20:44:45 +0100
committerBenjamin Otte <otte@redhat.com>2019-03-05 20:44:45 +0100
commit3a8db343b8f5d8fe16712b19b9759083148508be (patch)
tree703f8942f129f106aacb57fbf30b9832cb895a90
parent08d904a732145895d680408aa69df419dd3a143a (diff)
downloadgtk+-wip/otte/transform.tar.gz
wip: Add a cube stack transitionwip/otte/transform
-rw-r--r--demos/widget-factory/widget-factory.c2
-rw-r--r--demos/widget-factory/widget-factory.ui2
-rw-r--r--gtk/gtkstack.c85
-rw-r--r--gtk/gtkstack.h3
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,
@@ -2170,6 +2172,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 {