Loading

Paste #pzvrvn0tb

  1. diff --git a/demos/widget-factory/widget-factory.c b/demos/widget-factory/widget-factory.c
  2. index f19ae57d83..2c321079aa 100644
  3. --- a/demos/widget-factory/widget-factory.c
  4. +++ b/demos/widget-factory/widget-factory.c
  5. @@ -45,14 +45,34 @@ change_transition_state (GSimpleAction *action,
  6.                           GVariant      *state,
  7.                           gpointer       user_data)
  8.  {
  9. -  GtkStackTransitionType transition;
  10. -
  11.    if (g_variant_get_boolean (state))
  12. -    transition = GTK_STACK_TRANSITION_TYPE_SLIDE_LEFT_RIGHT;
  13. +    {
  14. +      GtkMatrix *start_matrix = NULL, *end_matrix = NULL;
  15. +
  16. +      start_matrix = gtk_matrix_translate (start_matrix, &GRAPHENE_POINT_INIT (0.5, 0.5));
  17. +      start_matrix = gtk_matrix_scale (start_matrix, 1, 1);
  18. +      start_matrix = gtk_matrix_rotate (start_matrix, 0);
  19. +      start_matrix = gtk_matrix_translate (start_matrix, &GRAPHENE_POINT_INIT (-0.5, -0.5));
  20. +
  21. +      end_matrix = gtk_matrix_translate (end_matrix, &GRAPHENE_POINT_INIT (0.5, 0.5));
  22. +      end_matrix = gtk_matrix_scale (end_matrix, 2, 2);
  23. +      end_matrix = gtk_matrix_rotate (end_matrix, 360);
  24. +      end_matrix = gtk_matrix_translate (end_matrix, &GRAPHENE_POINT_INIT (-0.5, -0.5));
  25. +
  26. +      gtk_stack_set_custom_transition (GTK_STACK (page_stack),
  27. +                                       start_matrix,
  28. +                                       end_matrix,
  29. +                                       1.0,
  30. +                                       1.0);
  31. +      gtk_matrix_unref (start_matrix);
  32. +      gtk_matrix_unref (end_matrix);
  33. +    }
  34.    else
  35. -    transition = GTK_STACK_TRANSITION_TYPE_NONE;
  36. +    {
  37. +      gtk_stack_set_transition_type (GTK_STACK (page_stack),
  38. +                                     GTK_STACK_TRANSITION_TYPE_NONE);
  39. +    }
  40.  
  41. -  gtk_stack_set_transition_type (GTK_STACK (page_stack), transition);
  42.  
  43.    g_simple_action_set_state (action, state);
  44.  }
  45. diff --git a/gtk/gtkstack.c b/gtk/gtkstack.c
  46. index 003bc2088e..2525d34fc0 100644
  47. --- a/gtk/gtkstack.c
  48. +++ b/gtk/gtkstack.c
  49. @@ -125,6 +125,10 @@ typedef struct {
  50.  
  51.    GtkStackTransitionType transition_type;
  52.    guint transition_duration;
  53. +  GtkMatrix *transition_target_start_matrix;
  54. +  GtkMatrix *transition_target_end_matrix;
  55. +  double transition_target_start_opacity;
  56. +  double transition_target_end_opacity;
  57.  
  58.    GtkStackPage *last_visible_child;
  59.    GskRenderNode *last_visible_node;
  60. @@ -618,6 +622,8 @@ gtk_stack_finalize (GObject *obj)
  61.    gtk_stack_unschedule_ticks (stack);
  62.  
  63.    g_clear_pointer (&priv->last_visible_node, gsk_render_node_unref);
  64. +  g_clear_pointer (&priv->transition_target_start_matrix, gtk_matrix_unref);
  65. +  g_clear_pointer (&priv->transition_target_end_matrix, gtk_matrix_unref);
  66.  
  67.    G_OBJECT_CLASS (gtk_stack_parent_class)->finalize (obj);
  68.  }
  69. @@ -911,6 +917,7 @@ get_simple_transition_type (gboolean               new_child_first,
  70.      case GTK_STACK_TRANSITION_TYPE_UNDER_LEFT:
  71.      case GTK_STACK_TRANSITION_TYPE_UNDER_RIGHT:
  72.      case GTK_STACK_TRANSITION_TYPE_CROSSFADE:
  73. +    case GTK_STACK_TRANSITION_TYPE_CUSTOM:
  74.      default:
  75.        return transition_type;
  76.      }
  77. @@ -1071,6 +1078,7 @@ effective_transition_type (GtkStack               *stack,
  78.          case GTK_STACK_TRANSITION_TYPE_OVER_LEFT_RIGHT:
  79.          case GTK_STACK_TRANSITION_TYPE_OVER_RIGHT_LEFT:
  80.          case GTK_STACK_TRANSITION_TYPE_CROSSFADE:
  81. +        case GTK_STACK_TRANSITION_TYPE_CUSTOM:
  82.          default:
  83.            return transition_type;
  84.          }
  85. @@ -1793,7 +1801,7 @@ gtk_stack_get_transition_type (GtkStack *stack)
  86.   */
  87.  void
  88.  gtk_stack_set_transition_type (GtkStack              *stack,
  89. -                              GtkStackTransitionType  transition)
  90. +                               GtkStackTransitionType  transition)
  91.  {
  92.    GtkStackPrivate *priv = gtk_stack_get_instance_private (stack);
  93.  
  94. @@ -1803,10 +1811,37 @@ gtk_stack_set_transition_type (GtkStack              *stack,
  95.      return;
  96.  
  97.    priv->transition_type = transition;
  98. +
  99. +  g_clear_pointer (&priv->transition_target_start_matrix, gtk_matrix_unref);
  100. +  g_clear_pointer (&priv->transition_target_end_matrix, gtk_matrix_unref);
  101. +  priv->transition_target_start_opacity = 1.0;
  102. +  priv->transition_target_end_opacity = 1.0;
  103. +
  104.    g_object_notify_by_pspec (G_OBJECT (stack),
  105.                              stack_props[PROP_TRANSITION_TYPE]);
  106.  }
  107.  
  108. +void
  109. +gtk_stack_set_custom_transition (GtkStack  *stack,
  110. +                                 GtkMatrix *target_start_matrix,
  111. +                                 GtkMatrix *target_end_matrix,
  112. +                                 double     target_start_opacity,
  113. +                                 double     target_end_opacity)
  114. +{
  115. +  GtkStackPrivate *priv = gtk_stack_get_instance_private (stack);
  116. +
  117. +  g_object_freeze_notify (G_OBJECT (stack));
  118. +
  119. +  gtk_stack_set_transition_type (stack, GTK_STACK_TRANSITION_TYPE_CUSTOM);
  120. +
  121. +  priv->transition_target_start_matrix = gtk_matrix_ref (target_start_matrix);
  122. +  priv->transition_target_end_matrix = gtk_matrix_ref (target_end_matrix);
  123. +  priv->transition_target_start_opacity = target_start_opacity;
  124. +  priv->transition_target_end_opacity = target_end_opacity;
  125. +
  126. +  g_object_thaw_notify (G_OBJECT (stack));
  127. +}
  128. +
  129.  /**
  130.   * gtk_stack_get_transition_running:
  131.   * @stack: a #GtkStack
  132. @@ -2236,6 +2271,38 @@ gtk_stack_snapshot_slide (GtkWidget   *widget,
  133.                               snapshot);
  134.  }
  135.  
  136. +static void
  137. +gtk_stack_snapshot_custom (GtkWidget   *widget,
  138. +                           GtkSnapshot *snapshot)
  139. +{
  140. +  GtkStack *stack = GTK_STACK (widget);
  141. +  GtkStackPrivate *priv = gtk_stack_get_instance_private (stack);
  142. +
  143. +  gtk_widget_snapshot_child (widget,
  144. +                             priv->visible_child->widget,
  145. +                             snapshot);
  146. +
  147. +  if (priv->last_visible_node)
  148. +    {
  149. +      graphene_matrix_t mat, tmp;
  150. +      GtkMatrix *progress_matrix;
  151. +
  152. +      graphene_matrix_init_scale (&mat, gtk_widget_get_width (widget), gtk_widget_get_height (widget), 1.0);
  153. +      progress_matrix = gtk_matrix_transition (priv->transition_target_start_matrix,
  154. +                                               priv->transition_target_end_matrix,
  155. +                                               gtk_progress_tracker_get_progress (&priv->tracker, FALSE));
  156. +      gtk_matrix_compute (progress_matrix, &tmp);
  157. +      gtk_matrix_unref (progress_matrix);
  158. +      graphene_matrix_multiply (&tmp, &mat, &mat);
  159. +      graphene_matrix_init_scale (&tmp, 1.0f / priv->last_visible_widget_width, 1.0f / priv->last_visible_widget_height, 1.0);
  160. +      graphene_matrix_multiply (&tmp, &mat, &mat);
  161. +
  162. +      gtk_snapshot_push_transform (snapshot, &mat);
  163. +      gtk_snapshot_append_node (snapshot, priv->last_visible_node);
  164. +      gtk_snapshot_pop (snapshot);
  165. +    }
  166. +}
  167. +
  168.  static void
  169.  gtk_stack_snapshot (GtkWidget   *widget,
  170.                      GtkSnapshot *snapshot)
  171. @@ -2287,6 +2354,9 @@ gtk_stack_snapshot (GtkWidget   *widget,
  172.              case GTK_STACK_TRANSITION_TYPE_UNDER_RIGHT:
  173.           gtk_stack_snapshot_under (widget, snapshot);
  174.                break;
  175. +            case GTK_STACK_TRANSITION_TYPE_CUSTOM:
  176. +         gtk_stack_snapshot_custom (widget, snapshot);
  177. +              break;
  178.              case GTK_STACK_TRANSITION_TYPE_NONE:
  179.              case GTK_STACK_TRANSITION_TYPE_SLIDE_LEFT_RIGHT:
  180.              case GTK_STACK_TRANSITION_TYPE_SLIDE_UP_DOWN:
  181. diff --git a/gtk/gtkstack.h b/gtk/gtkstack.h
  182. index 658ef8bb6a..381b7bbe0f 100644
  183. --- a/gtk/gtkstack.h
  184. +++ b/gtk/gtkstack.h
  185. @@ -27,6 +27,7 @@
  186.  #endif
  187.  
  188.  #include <gtk/gtkcontainer.h>
  189. +#include <gtk/gtkmatrix.h>
  190.  #include <gtk/gtkselectionmodel.h>
  191.  
  192.  G_BEGIN_DECLS
  193. @@ -72,7 +73,8 @@ typedef enum {
  194.    GTK_STACK_TRANSITION_TYPE_OVER_UP_DOWN,
  195.    GTK_STACK_TRANSITION_TYPE_OVER_DOWN_UP,
  196.    GTK_STACK_TRANSITION_TYPE_OVER_LEFT_RIGHT,
  197. -  GTK_STACK_TRANSITION_TYPE_OVER_RIGHT_LEFT
  198. +  GTK_STACK_TRANSITION_TYPE_OVER_RIGHT_LEFT,
  199. +  GTK_STACK_TRANSITION_TYPE_CUSTOM
  200.  } GtkStackTransitionType;
  201.  
  202.  struct _GtkStack {
  203. @@ -148,6 +150,12 @@ GDK_AVAILABLE_IN_ALL
  204.  void                   gtk_stack_set_transition_type     (GtkStack               *stack,
  205.                                                            GtkStackTransitionType  transition);
  206.  GDK_AVAILABLE_IN_ALL
  207. +void                   gtk_stack_set_custom_transition   (GtkStack               *stack,
  208. +                                                          GtkMatrix              *target_start_matrix,
  209. +                                                          GtkMatrix              *target_end_matrix,
  210. +                                                          double                  target_start_opacity,
  211. +                                                          double                  target_end_opacity);
  212. +GDK_AVAILABLE_IN_ALL
  213.  GtkStackTransitionType gtk_stack_get_transition_type     (GtkStack               *stack);
  214.  GDK_AVAILABLE_IN_ALL
  215.  gboolean               gtk_stack_get_transition_running  (GtkStack               *stack);