[gedit] Fix the search popup animation.
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] Fix the search popup animation.
- Date: Sat, 11 Dec 2010 16:21:19 +0000 (UTC)
commit 8aaf2665d32b1c8f6c1549c03808736b1020d8dc
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Sat Dec 11 17:19:34 2010 +0100
Fix the search popup animation.
Now we don't get an snapshot of the widget when it is destroyed,
instead we make a slide out animation and after it we destroy the
widget.
gedit/gedit-overlay.c | 154 +++++++++------------
gedit/gedit-overlay.h | 5 +-
gedit/gedit-view-frame.c | 37 ++++--
gedit/theatrics/gedit-theatrics-animated-widget.c | 114 +---------------
gedit/theatrics/gedit-theatrics-animated-widget.h | 5 -
tests/test-overlay.c | 25 ++--
6 files changed, 115 insertions(+), 225 deletions(-)
---
diff --git a/gedit/gedit-overlay.c b/gedit/gedit-overlay.c
index 666210d..d1b188c 100644
--- a/gedit/gedit-overlay.c
+++ b/gedit/gedit-overlay.c
@@ -556,7 +556,6 @@ on_actor_step (GeditTheatricsStage *stage,
switch (animation_state)
{
case GEDIT_THEATRICS_ANIMATION_STATE_COMING:
- {
gtk_widget_queue_draw (GTK_WIDGET (anim_widget));
gedit_theatrics_animated_widget_set_percent (anim_widget,
gedit_theatrics_actor_get_percent (actor));
@@ -566,9 +565,7 @@ on_actor_step (GeditTheatricsStage *stage,
GEDIT_THEATRICS_ANIMATION_STATE_IDLE);
}
break;
- }
case GEDIT_THEATRICS_ANIMATION_STATE_INTENDING_TO_GO:
- {
gedit_theatrics_animated_widget_set_animation_state (anim_widget,
GEDIT_THEATRICS_ANIMATION_STATE_GOING);
gedit_theatrics_animated_widget_set_bias (anim_widget,
@@ -576,78 +573,21 @@ on_actor_step (GeditTheatricsStage *stage,
gedit_theatrics_actor_reset (actor, gedit_theatrics_animated_widget_get_duration (anim_widget) *
gedit_theatrics_actor_get_percent (actor));
break;
- }
case GEDIT_THEATRICS_ANIMATION_STATE_GOING:
- {
if (gedit_theatrics_actor_get_expired (actor))
{
- gtk_container_remove (GTK_CONTAINER (overlay),
- GTK_WIDGET (anim_widget));
+ gtk_widget_destroy (GTK_WIDGET (anim_widget));
return;
}
+ gtk_widget_queue_draw (GTK_WIDGET (anim_widget));
gedit_theatrics_animated_widget_set_percent (anim_widget, 1.0 - gedit_theatrics_actor_get_percent (actor));
break;
- }
default:
break;
}
}
static void
-remove_core (GeditOverlay *overlay,
- GeditTheatricsAnimatedWidget *aw)
-{
- GeditTheatricsAnimationState animation_state;
-
- animation_state = gedit_theatrics_animated_widget_get_animation_state (aw);
-
- if (animation_state == GEDIT_THEATRICS_ANIMATION_STATE_COMING)
- {
- gedit_theatrics_animated_widget_set_animation_state (aw, GEDIT_THEATRICS_ANIMATION_STATE_INTENDING_TO_GO);
- }
- else
- {
- GeditTheatricsChoreographerEasing easing;
-
- easing = gedit_theatrics_animated_widget_get_easing (aw);
-
- switch (easing)
- {
- case GEDIT_THEATRICS_CHOREOGRAPHER_EASING_QUADRATIC_IN:
- gedit_theatrics_animated_widget_set_easing (
- aw, GEDIT_THEATRICS_CHOREOGRAPHER_EASING_QUADRATIC_OUT);
- break;
- case GEDIT_THEATRICS_CHOREOGRAPHER_EASING_QUADRATIC_OUT:
- gedit_theatrics_animated_widget_set_easing (
- aw, GEDIT_THEATRICS_CHOREOGRAPHER_EASING_QUADRATIC_IN);
- break;
- case GEDIT_THEATRICS_CHOREOGRAPHER_EASING_EXPONENTIAL_IN:
- gedit_theatrics_animated_widget_set_easing (
- aw, GEDIT_THEATRICS_CHOREOGRAPHER_EASING_EXPONENTIAL_OUT);
- break;
- case GEDIT_THEATRICS_CHOREOGRAPHER_EASING_EXPONENTIAL_OUT:
- gedit_theatrics_animated_widget_set_easing (
- aw, GEDIT_THEATRICS_CHOREOGRAPHER_EASING_EXPONENTIAL_IN);
- break;
- default:
- break;
- }
-
- gedit_theatrics_animated_widget_set_animation_state (aw, GEDIT_THEATRICS_ANIMATION_STATE_GOING);
- gedit_theatrics_stage_add_with_duration (overlay->priv->stage,
- G_OBJECT (aw),
- gedit_theatrics_animated_widget_get_duration (aw));
- }
-}
-
-static void
-on_remove_core (GeditTheatricsAnimatedWidget *aw,
- GeditOverlay *overlay)
-{
- remove_core (overlay, aw);
-}
-
-static void
gedit_overlay_init (GeditOverlay *overlay)
{
overlay->priv = GEDIT_OVERLAY_GET_PRIVATE (overlay);
@@ -668,40 +608,72 @@ gedit_overlay_new (GtkWidget *main_widget)
NULL));
}
+static GeditTheatricsAnimatedWidget *
+get_animated_widget (GeditOverlay *overlay,
+ GtkWidget *widget)
+{
+ GSList *l;
+
+ for (l = overlay->priv->children; l != NULL; l = g_slist_next (l))
+ {
+ OverlayChild *child = (OverlayChild *)l->data;
+ GtkWidget *in_widget;
+
+ if (!child->is_animated)
+ continue;
+
+ g_object_get (child->child, "widget", &in_widget, NULL);
+ g_assert (in_widget != NULL);
+
+ if (in_widget == widget)
+ {
+ return GEDIT_THEATRICS_ANIMATED_WIDGET (child->child);
+ }
+ }
+
+ return NULL;
+}
+
/* Note: see that we use the gravity as a position */
void
-gedit_overlay_add_animated_widget (GeditOverlay *overlay,
- GtkWidget *widget,
- guint duration,
- GeditTheatricsChoreographerEasing easing,
- GeditTheatricsChoreographerBlocking blocking,
- GtkOrientation orientation,
- GdkGravity gravity,
- guint offset)
+gedit_overlay_slide (GeditOverlay *overlay,
+ GtkWidget *widget,
+ guint duration,
+ GeditTheatricsChoreographerEasing easing,
+ GeditTheatricsChoreographerBlocking blocking,
+ GtkOrientation orientation,
+ GdkGravity gravity,
+ guint offset,
+ gboolean in)
{
GeditTheatricsAnimatedWidget *anim_widget;
- GeditTheatricsActor *actor;
- GtkAllocation widget_alloc;
-
- anim_widget = gedit_theatrics_animated_widget_new (widget, duration,
- easing,
- blocking,
- orientation);
- gtk_widget_show (GTK_WIDGET (anim_widget));
-
- g_signal_connect (anim_widget,
- "remove-core",
- G_CALLBACK (on_remove_core),
- overlay);
- gtk_widget_get_allocation (widget, &widget_alloc);
- gedit_theatrics_animated_widget_set_end_padding (anim_widget,
- widget_alloc.height);
+ anim_widget = get_animated_widget (overlay, widget);
+
+ if (anim_widget == NULL)
+ {
+ anim_widget = gedit_theatrics_animated_widget_new (widget, duration,
+ easing,
+ blocking,
+ orientation);
+ gtk_widget_show (GTK_WIDGET (anim_widget));
+
+ add_toplevel_widget (overlay, GTK_WIDGET (anim_widget), TRUE,
+ TRUE, gravity, offset);
+ }
+ else
+ {
+ /* we are only interested in the easing and the blocking */
+ gedit_theatrics_animated_widget_set_easing (anim_widget, easing);
+ gedit_theatrics_animated_widget_set_blocking (anim_widget, blocking);
+ }
- actor = gedit_theatrics_stage_add_with_duration (overlay->priv->stage,
- G_OBJECT (anim_widget),
- duration);
+ if (!in)
+ {
+ gedit_theatrics_animated_widget_set_animation_state (anim_widget, GEDIT_THEATRICS_ANIMATION_STATE_GOING);
+ }
- add_toplevel_widget (overlay, GTK_WIDGET (anim_widget), TRUE,
- TRUE, gravity, offset);
+ gedit_theatrics_stage_add_with_duration (overlay->priv->stage,
+ G_OBJECT (anim_widget),
+ duration);
}
diff --git a/gedit/gedit-overlay.h b/gedit/gedit-overlay.h
index c12cd27..8f90f13 100644
--- a/gedit/gedit-overlay.h
+++ b/gedit/gedit-overlay.h
@@ -61,14 +61,15 @@ GType gedit_overlay_get_type (void) G_GNUC_CONST;
GtkWidget *gedit_overlay_new (GtkWidget *main_widget);
-void gedit_overlay_add_animated_widget (GeditOverlay *overlay,
+void gedit_overlay_slide (GeditOverlay *overlay,
GtkWidget *widget,
guint duration,
GeditTheatricsChoreographerEasing easing,
GeditTheatricsChoreographerBlocking blocking,
GtkOrientation orientation,
GdkGravity gravity,
- guint offset);
+ guint offset,
+ gboolean in);
G_END_DECLS
diff --git a/gedit/gedit-view-frame.c b/gedit/gedit-view-frame.c
index bf23b67..39a209a 100644
--- a/gedit/gedit-view-frame.c
+++ b/gedit/gedit-view-frame.c
@@ -148,6 +148,7 @@ hide_search_widget (GeditViewFrame *frame,
gboolean cancel)
{
GtkTextBuffer *buffer;
+ GdkGravity gravity;
if (frame->priv->disable_popdown)
{
@@ -174,7 +175,24 @@ hide_search_widget (GeditViewFrame *frame,
frame->priv->typeselect_flush_timeout = 0;
}
- gtk_widget_destroy (frame->priv->search_widget);
+ if (gtk_widget_get_direction (frame->priv->search_entry) == GTK_TEXT_DIR_RTL)
+ {
+ gravity = GDK_GRAVITY_NORTH_WEST;
+ }
+ else
+ {
+ gravity = GDK_GRAVITY_NORTH_EAST;
+ }
+
+ gedit_overlay_slide (GEDIT_OVERLAY (frame->priv->overlay),
+ frame->priv->search_widget,
+ 300,
+ GEDIT_THEATRICS_CHOREOGRAPHER_EASING_EXPONENTIAL_IN_OUT,
+ GEDIT_THEATRICS_CHOREOGRAPHER_BLOCKING_UPSTAGE,
+ GTK_ORIENTATION_VERTICAL,
+ gravity,
+ SEARCH_POPUP_OFFSET,
+ FALSE);
frame->priv->search_widget = NULL;
if (cancel)
@@ -1302,14 +1320,15 @@ start_interactive_search_real (GeditViewFrame *frame)
gravity = GDK_GRAVITY_NORTH_EAST;
}
- gedit_overlay_add_animated_widget (GEDIT_OVERLAY (frame->priv->overlay),
- frame->priv->search_widget,
- 300,
- GEDIT_THEATRICS_CHOREOGRAPHER_EASING_EXPONENTIAL_IN_OUT,
- GEDIT_THEATRICS_CHOREOGRAPHER_BLOCKING_DOWNSTAGE,
- GTK_ORIENTATION_VERTICAL,
- gravity,
- SEARCH_POPUP_OFFSET);
+ gedit_overlay_slide (GEDIT_OVERLAY (frame->priv->overlay),
+ frame->priv->search_widget,
+ 300,
+ GEDIT_THEATRICS_CHOREOGRAPHER_EASING_EXPONENTIAL_IN_OUT,
+ GEDIT_THEATRICS_CHOREOGRAPHER_BLOCKING_DOWNSTAGE,
+ GTK_ORIENTATION_VERTICAL,
+ gravity,
+ SEARCH_POPUP_OFFSET,
+ TRUE);
init_search_entry (frame);
diff --git a/gedit/theatrics/gedit-theatrics-animated-widget.c b/gedit/theatrics/gedit-theatrics-animated-widget.c
index 2dece3c..e2bf621 100644
--- a/gedit/theatrics/gedit-theatrics-animated-widget.c
+++ b/gedit/theatrics/gedit-theatrics-animated-widget.c
@@ -39,13 +39,6 @@ struct _GeditTheatricsAnimatedWidgetPrivate
gdouble bias;
gdouble percent;
GtkAllocation widget_alloc;
-
- cairo_surface_t *surface;
-
- gint width;
- gint height;
- gint start_padding;
- gint end_padding;
};
enum
@@ -60,14 +53,6 @@ enum
PROP_ORIENTATION
};
-enum
-{
- REMOVE_CORE,
- LAST_SIGNAL
-};
-
-static guint signals[LAST_SIGNAL] = { 0 };
-
G_DEFINE_TYPE_EXTENDED (GeditTheatricsAnimatedWidget,
gedit_theatrics_animated_widget,
GTK_TYPE_BIN,
@@ -76,40 +61,6 @@ G_DEFINE_TYPE_EXTENDED (GeditTheatricsAnimatedWidget,
NULL))
static void
-on_widget_destroyed (GtkWidget *widget,
- GeditTheatricsAnimatedWidget *aw)
-{
- GdkWindow *window;
- cairo_t *img_cr;
-
- if (!gtk_widget_get_realized (GTK_WIDGET (aw)))
- return;
-
- aw->priv->width = aw->priv->widget_alloc.width;
- aw->priv->height = aw->priv->widget_alloc.height;
-
- aw->priv->surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
- aw->priv->width,
- aw->priv->height);
-
- img_cr = cairo_create (aw->priv->surface);
-
- window = gtk_widget_get_window (GTK_WIDGET (aw));
-
- gdk_cairo_set_source_window (img_cr, window,
- aw->priv->widget_alloc.x,
- aw->priv->widget_alloc.y);
-
- cairo_paint (img_cr);
- cairo_destroy (img_cr);
-
- if (aw->priv->animation_state != GEDIT_THEATRICS_ANIMATION_STATE_GOING)
- {
- g_signal_emit (G_OBJECT (aw), signals[REMOVE_CORE], 0);
- }
-}
-
-static void
gedit_theatrics_animated_widget_finalize (GObject *object)
{
G_OBJECT_CLASS (gedit_theatrics_animated_widget_parent_class)->finalize (object);
@@ -241,9 +192,7 @@ gedit_theatrics_animated_widget_get_preferred_width (GtkWidget *widget,
if (aw->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
{
width = gedit_theatrics_choreographer_pixel_compose (aw->priv->percent,
- aw->priv->widget_alloc.width +
- aw->priv->start_padding +
- aw->priv->end_padding,
+ aw->priv->widget_alloc.width,
aw->priv->easing);
}
else
@@ -278,9 +227,7 @@ gedit_theatrics_animated_widget_get_preferred_height (GtkWidget *widget,
else
{
height = gedit_theatrics_choreographer_pixel_compose (aw->priv->percent,
- aw->priv->widget_alloc.height +
- aw->priv->start_padding +
- aw->priv->end_padding,
+ aw->priv->widget_alloc.height,
aw->priv->easing);
}
@@ -300,17 +247,17 @@ gedit_theatrics_animated_widget_size_allocate (GtkWidget *widget,
if (aw->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
{
aw->priv->widget_alloc.height = allocation->height;
- aw->priv->widget_alloc.x = aw->priv->start_padding;
+ aw->priv->widget_alloc.x = 0;
if (aw->priv->blocking == GEDIT_THEATRICS_CHOREOGRAPHER_BLOCKING_DOWNSTAGE)
{
- aw->priv->widget_alloc.x += allocation->width - aw->priv->widget_alloc.width;
+ aw->priv->widget_alloc.x = allocation->width - aw->priv->widget_alloc.width;
}
}
else
{
aw->priv->widget_alloc.width = allocation->width;
- aw->priv->widget_alloc.y = aw->priv->start_padding;
+ aw->priv->widget_alloc.y = 0;
if (aw->priv->blocking == GEDIT_THEATRICS_CHOREOGRAPHER_BLOCKING_DOWNSTAGE)
{
@@ -326,33 +273,6 @@ gedit_theatrics_animated_widget_size_allocate (GtkWidget *widget,
}
}
-static gboolean
-gedit_theatrics_animated_widget_draw (GtkWidget *widget,
- cairo_t *cr)
-{
- GeditTheatricsAnimatedWidget *aw = GEDIT_THEATRICS_ANIMATED_WIDGET (widget);
-
- if (aw->priv->surface != NULL)
- {
- /* Do not scale if the size is 0 */
- if (aw->priv->width > 0 && aw->priv->height > 0)
- {
- cairo_scale (cr,
- aw->priv->widget_alloc.width / aw->priv->width,
- aw->priv->widget_alloc.height / aw->priv->height);
- cairo_set_source_surface (cr, aw->priv->surface, 0, 0);
-
- cairo_paint (cr);
- }
-
- return TRUE;
- }
- else
- {
- return GTK_WIDGET_CLASS (gedit_theatrics_animated_widget_parent_class)->draw (widget, cr);
- }
-}
-
static void
gedit_theatrics_animated_widget_add (GtkContainer *container,
GtkWidget *widget)
@@ -361,10 +281,6 @@ gedit_theatrics_animated_widget_add (GtkContainer *container,
aw->priv->widget = widget;
- g_signal_connect (widget, "destroy",
- G_CALLBACK (on_widget_destroyed),
- aw);
-
GTK_CONTAINER_CLASS (gedit_theatrics_animated_widget_parent_class)->add (container, widget);
}
@@ -394,7 +310,6 @@ gedit_theatrics_animated_widget_class_init (GeditTheatricsAnimatedWidgetClass *k
widget_class->get_preferred_width = gedit_theatrics_animated_widget_get_preferred_width;
widget_class->get_preferred_height = gedit_theatrics_animated_widget_get_preferred_height;
widget_class->size_allocate = gedit_theatrics_animated_widget_size_allocate;
- widget_class->draw = gedit_theatrics_animated_widget_draw;
container_class->add = gedit_theatrics_animated_widget_add;
container_class->remove = gedit_theatrics_animated_widget_remove;
@@ -464,16 +379,6 @@ gedit_theatrics_animated_widget_class_init (GeditTheatricsAnimatedWidgetClass *k
PROP_ORIENTATION,
"orientation");
- signals[REMOVE_CORE] =
- g_signal_new ("remove-core",
- G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GeditTheatricsAnimatedWidgetClass, remove_core),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE,
- 0);
-
g_type_class_add_private (object_class, sizeof (GeditTheatricsAnimatedWidgetPrivate));
}
@@ -625,13 +530,4 @@ gedit_theatrics_animated_widget_set_bias (GeditTheatricsAnimatedWidget *aw,
aw->priv->bias = bias;
}
-void
-gedit_theatrics_animated_widget_set_end_padding (GeditTheatricsAnimatedWidget *aw,
- gint end_padding)
-{
- g_return_if_fail (GEDIT_IS_THEATRICS_ANIMATED_WIDGET (aw));
-
- aw->priv->end_padding = end_padding;
-}
-
/* ex:set ts=8 noet: */
diff --git a/gedit/theatrics/gedit-theatrics-animated-widget.h b/gedit/theatrics/gedit-theatrics-animated-widget.h
index c26a5bd..2f5b00c 100644
--- a/gedit/theatrics/gedit-theatrics-animated-widget.h
+++ b/gedit/theatrics/gedit-theatrics-animated-widget.h
@@ -53,8 +53,6 @@ struct _GeditTheatricsAnimatedWidget
struct _GeditTheatricsAnimatedWidgetClass
{
GtkBinClass parent_class;
-
- void (* remove_core) (GeditTheatricsAnimatedWidget *aw);
};
GType gedit_theatrics_animated_widget_get_type (void) G_GNUC_CONST;
@@ -97,9 +95,6 @@ void gedit_theatrics_animated_widget_set_percent (GeditTheatricsAnimatedWidg
void gedit_theatrics_animated_widget_set_bias (GeditTheatricsAnimatedWidget *aw,
gdouble bias);
-void gedit_theatrics_animated_widget_set_end_padding(GeditTheatricsAnimatedWidget *aw,
- gint end_padding);
-
G_END_DECLS
#endif /* __GEDIT_THEATRICS_ANIMATED_WIDGET_H__ */
diff --git a/tests/test-overlay.c b/tests/test-overlay.c
index 6d3d395..811d4b6 100644
--- a/tests/test-overlay.c
+++ b/tests/test-overlay.c
@@ -3,11 +3,19 @@
#include "gedit-overlay.h"
#include "gedit-rounded-frame.h"
+static GtkWidget *overlay;
+
static void
on_button_clicked (GtkWidget *button,
GtkWidget *frame)
{
- gtk_widget_destroy (frame);
+ gedit_overlay_slide (GEDIT_OVERLAY (overlay),
+ frame,
+ 1000,
+ GEDIT_THEATRICS_CHOREOGRAPHER_EASING_EXPONENTIAL_IN_OUT,
+ GEDIT_THEATRICS_CHOREOGRAPHER_BLOCKING_DOWNSTAGE,
+ GTK_ORIENTATION_VERTICAL,
+ GDK_GRAVITY_STATIC, 0, FALSE);
}
gint
@@ -15,7 +23,6 @@ main ()
{
GtkWidget *window;
GtkWidget *textview;
- GtkWidget *overlay;
GtkWidget *frame;
GtkWidget *entry;
GtkWidget *vbox;
@@ -40,13 +47,13 @@ main ()
gtk_container_add (GTK_CONTAINER (frame), entry);
- gedit_overlay_add_animated_widget (GEDIT_OVERLAY (overlay),
- frame,
- 1000,
- GEDIT_THEATRICS_CHOREOGRAPHER_EASING_EXPONENTIAL_IN_OUT,
- GEDIT_THEATRICS_CHOREOGRAPHER_BLOCKING_DOWNSTAGE,
- GTK_ORIENTATION_VERTICAL,
- GDK_GRAVITY_STATIC, 0);
+ gedit_overlay_slide (GEDIT_OVERLAY (overlay),
+ frame,
+ 1000,
+ GEDIT_THEATRICS_CHOREOGRAPHER_EASING_EXPONENTIAL_IN_OUT,
+ GEDIT_THEATRICS_CHOREOGRAPHER_BLOCKING_DOWNSTAGE,
+ GTK_ORIENTATION_VERTICAL,
+ GDK_GRAVITY_STATIC, 0, TRUE);
button = gtk_button_new_with_label ("Hide");
gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE, 0);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]