void ide_widget_show_with_fade (GtkWidget *widget) { GdkFrameClock *frame_clock; EggAnimation *anim; g_return_if_fail (GTK_IS_WIDGET (widget)); if (!gtk_widget_get_visible (widget)) { anim = g_object_get_data (G_OBJECT (widget), "FADE_ANIMATION"); if (anim != NULL) egg_animation_stop (anim); frame_clock = gtk_widget_get_frame_clock (widget); gtk_widget_set_opacity (widget, 0.0); gtk_widget_show (widget); anim = egg_object_animate_full (widget, EGG_ANIMATION_LINEAR, 500, frame_clock, show_callback, g_object_ref (widget), "opacity", 1.0, NULL); g_object_set_data_full (G_OBJECT (widget), "FADE_ANIMATION", g_object_ref (anim), g_object_unref); } }
static void on_window_draw (GtkWidget *widget, cairo_t *cr) { GdkRectangle allocation; double cx, cy, r; cairo_set_source_rgb (cr, 1., 1., 1.); cairo_paint (cr); cairo_set_source_rgb (cr, 0., 0., 0.); gtk_widget_get_allocation (widget, &allocation); cx = allocation.width / 2.; cy = allocation.height / 2.; r = MIN (allocation.width, allocation.height) / 2.; cairo_arc (cr, cx, cy, r, 0, 2 * M_PI); cairo_stroke (cr); if (displayed_frame) { cairo_move_to (cr, cx, cy); cairo_line_to (cr, cx + r * cos(displayed_frame->angle - M_PI / 2), cy + r * sin(displayed_frame->angle - M_PI / 2)); cairo_stroke (cr); if (displayed_frame->frame_counter == 0) { GdkFrameClock *frame_clock = gtk_widget_get_frame_clock (window); displayed_frame->frame_counter = gdk_frame_clock_get_frame_counter (frame_clock); } } }
static void gtk_switch_begin_toggle_animation (GtkSwitch *sw) { GtkSwitchPrivate *priv = sw->priv; gboolean animate; g_object_get (gtk_widget_get_settings (GTK_WIDGET (sw)), "gtk-enable-animations", &animate, NULL); if (animate) { GdkFrameClock *clock = gtk_widget_get_frame_clock (GTK_WIDGET (sw)); priv->start_time = gdk_frame_clock_get_frame_time (clock); priv->end_time = priv->start_time + 1000 * ANIMATION_DURATION; priv->offset = priv->handle_x; if (priv->tick_id == 0) { priv->tick_id = g_signal_connect (clock, "update", G_CALLBACK (gtk_switch_on_frame_clock_update), sw); gdk_frame_clock_begin_updating (clock); } } else { gtk_switch_set_active (sw, !priv->is_active); } }
static void gd_stack_start_transition (GdStack *stack) { GdStackPrivate *priv = stack->priv; GtkWidget *widget = GTK_WIDGET (stack); gboolean animations_enabled; g_object_get (gtk_widget_get_settings (widget), "gtk-enable-animations", &animations_enabled, NULL); if (gtk_widget_get_mapped (widget) && animations_enabled && priv->transition_type != GD_STACK_TRANSITION_TYPE_NONE && priv->last_visible_child != NULL) { gtk_widget_set_opacity (widget, 0.999); priv->transition_pos = 0.0; priv->start_time = gdk_frame_clock_get_frame_time (gtk_widget_get_frame_clock (widget)); priv->end_time = priv->start_time + (priv->transition_duration * 1000); gd_stack_schedule_ticks (stack); } else { gd_stack_unschedule_ticks (stack); gd_stack_set_transition_position (stack, 1.0); } }
static void gtk_revealer_start_animation (GtkRevealer *revealer, gdouble target) { GtkRevealerPrivate *priv = gtk_revealer_get_instance_private (revealer); GtkWidget *widget = GTK_WIDGET (revealer); GtkRevealerTransitionType transition; if (priv->target_pos == target) return; priv->target_pos = target; g_object_notify (G_OBJECT (revealer), "reveal-child"); transition = effective_transition (revealer); if (gtk_widget_get_mapped (widget) && priv->transition_duration != 0 && transition != GTK_REVEALER_TRANSITION_TYPE_NONE) { priv->source_pos = priv->current_pos; priv->start_time = gdk_frame_clock_get_frame_time (gtk_widget_get_frame_clock (widget)); priv->end_time = priv->start_time + (priv->transition_duration * 1000); if (priv->tick_id == 0) priv->tick_id = gtk_widget_add_tick_callback (widget, (GtkTickCallback)gtk_revealer_animate_cb, revealer, NULL); gtk_revealer_animate_step (revealer, priv->start_time); } else { gtk_revealer_set_position (revealer, target); } }
static void gtk_switch_end_toggle_animation (GtkSwitch *sw) { GtkSwitchPrivate *priv = sw->priv; if (priv->tick_id != 0) { GdkFrameClock *clock = gtk_widget_get_frame_clock (GTK_WIDGET (sw)); g_signal_handler_disconnect (clock, priv->tick_id); priv->tick_id = 0; gdk_frame_clock_end_updating (clock); } }
void pnl_dock_revealer_set_reveal_child (PnlDockRevealer *self, gboolean reveal_child) { PnlDockRevealerPrivate *priv = pnl_dock_revealer_get_instance_private (self); g_return_if_fail (PNL_IS_DOCK_REVEALER (self)); reveal_child = !!reveal_child; if (reveal_child != priv->reveal_child) { PnlAnimation *animation; GtkWidget *child; priv->reveal_child = reveal_child; child = gtk_bin_get_child (GTK_BIN (self)); if (child != NULL) { guint duration; if (priv->animation != NULL) { pnl_animation_stop (priv->animation); pnl_clear_weak_pointer (&priv->animation); } gtk_widget_set_child_visible (child, TRUE); duration = pnl_dock_revealer_calculate_duration (self); animation = pnl_object_animate_full (priv->adjustment, PNL_ANIMATION_EASE_IN_OUT_CUBIC, duration, gtk_widget_get_frame_clock (GTK_WIDGET (self)), pnl_dock_revealer_animation_done, g_object_ref (self), "value", reveal_child ? 1.0 : 0.0, NULL); pnl_set_weak_pointer (&priv->animation, animation); } g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_REVEAL_CHILD]); } }
static GdkFrameClock * gtk_css_widget_node_get_frame_clock (GtkCssNode *node) { GtkCssWidgetNode *widget_node = GTK_CSS_WIDGET_NODE (node); gboolean animate; if (widget_node->widget == NULL) return NULL; g_object_get (gtk_widget_get_settings (widget_node->widget), "gtk-enable-animations", &animate, NULL); if (animate == FALSE) return NULL; return gtk_widget_get_frame_clock (widget_node->widget); }
static void deepin_fixed_prepare_animation(DeepinFixed* self, ChildAnimationInfo* ai) { if (!gtk_widget_get_realized(GTK_WIDGET(self))) { gtk_widget_realize(GTK_WIDGET(self)); } DeepinFixedPrivate* priv = self->priv; ai->target_pos = 1.0; ai->current_pos = 0.0; ai->start_time = gdk_frame_clock_get_frame_time( gtk_widget_get_frame_clock(GTK_WIDGET(self))); ai->last_time = ai->start_time; ai->end_time = ai->start_time + (priv->animation_duration * 1000); ai->tick_id = gtk_widget_add_tick_callback(GTK_WIDGET(self), (GtkTickCallback)on_tick_callback, ai, g_free); }
static void collect_old_frames (void) { GdkFrameClock *frame_clock = gtk_widget_get_frame_clock (window); GList *l, *l_next; for (l = past_frames; l; l = l_next) { FrameData *frame_data = l->data; gboolean remove = FALSE; l_next = l->next; GdkFrameTimings *timings = gdk_frame_clock_get_timings (frame_clock, frame_data->frame_counter); if (timings == NULL) { remove = TRUE; } else if (gdk_frame_timings_get_complete (timings)) { gint64 presentation_time = gdk_frame_timings_get_predicted_presentation_time (timings); gint64 refresh_interval = gdk_frame_timings_get_refresh_interval (timings); if (pll && presentation_time && refresh_interval && presentation_time > frame_data->clock_time - refresh_interval / 2 && presentation_time < frame_data->clock_time + refresh_interval / 2) adjust_clock_for_phase (frame_data->clock_time, presentation_time); if (presentation_time) variable_add (&latency_error, presentation_time - frame_data->clock_time); remove = TRUE; } if (remove) { past_frames = g_list_delete_link (past_frames, l); g_slice_free (FrameData, frame_data); } } }
void nautilus_selection_canvas_item_fade_out (NautilusSelectionCanvasItem *self, guint transition_time) { EelCanvasItem *item = EEL_CANVAS_ITEM (self); GtkWidget *widget; GdkFrameClock *clock; self->priv->fade_out_fill_alpha = self->priv->fill_color.alpha; self->priv->fade_out_outline_alpha = self->priv->outline_color.alpha; widget = GTK_WIDGET (item->canvas); clock = gtk_widget_get_frame_clock (widget); self->priv->fade_out_start_time = gdk_frame_clock_get_frame_time (clock); self->priv->fade_out_end_time = self->priv->fade_out_start_time + 1000 * transition_time; self->priv->fade_out_tick_id = gtk_widget_add_tick_callback (GTK_WIDGET (item->canvas), fade_and_request_redraw, self, NULL); }
void gb_widget_fade_hide (GtkWidget *widget) { GdkFrameClock *frame_clock; g_return_if_fail (GTK_IS_WIDGET (widget)); if (gtk_widget_get_visible (widget)) { frame_clock = gtk_widget_get_frame_clock (widget); ide_object_animate_full (widget, IDE_ANIMATION_LINEAR, 1000, frame_clock, hide_callback, g_object_ref (widget), "opacity", 0.0, NULL); } }
void gb_widget_fade_show (GtkWidget *widget) { GdkFrameClock *frame_clock; g_return_if_fail (GTK_IS_WIDGET (widget)); if (!gtk_widget_get_visible (widget)) { frame_clock = gtk_widget_get_frame_clock (widget); gtk_widget_set_opacity (widget, 0.0); gtk_widget_show (widget); ide_object_animate_full (widget, IDE_ANIMATION_LINEAR, 500, frame_clock, NULL, NULL, "opacity", 1.0, NULL); } }
int main(int argc, char **argv) { GError *error = NULL; GdkFrameClock *frame_clock; if (!gtk_init_with_args (&argc, &argv, "", options, NULL, &error)) { g_printerr ("Option parsing failed: %s\n", error->message); return 1; } window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_widget_set_app_paintable (window, TRUE); gtk_window_set_default_size (GTK_WINDOW (window), 300, 300); g_signal_connect (window, "draw", G_CALLBACK (on_window_draw), NULL); g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); gtk_widget_show (window); frame_queue = g_queue_new (); g_mutex_init (&frame_mutex); g_cond_init (&frame_cond); g_thread_new ("Create Frames", create_frames_thread, NULL); frame_clock = gtk_widget_get_frame_clock (window); g_signal_connect (frame_clock, "update", G_CALLBACK (on_update), NULL); gdk_frame_clock_begin_updating (frame_clock); gtk_main (); return 0; }
static void on_frame (double progress) { GdkFrameClock *frame_clock = gtk_widget_get_frame_clock (window); int jitter; if (frame_clock) handle_frame_stats (frame_clock); angle = 2 * M_PI * progress; jitter = WINDOW_SIZE_JITTER * sin(angle); if (!cb_no_resize) { window_width = WIDTH + jitter; window_height = HEIGHT + jitter; } gtk_window_resize (GTK_WINDOW (window), window_width, window_height); gtk_widget_queue_draw (window); }
void _ide_frame_transfer (IdeFrame *self, IdeFrame *dest, IdePage *page) { IdeFramePrivate *priv = ide_frame_get_instance_private (self); IdeFramePrivate *dest_priv = ide_frame_get_instance_private (dest); const GdkRGBA *fg; const GdkRGBA *bg; g_return_if_fail (IDE_IS_FRAME (self)); g_return_if_fail (IDE_IS_FRAME (dest)); g_return_if_fail (IDE_IS_PAGE (page)); g_return_if_fail (GTK_WIDGET (priv->stack) == gtk_widget_get_parent (GTK_WIDGET (page))); /* * Inform the destination stack about our new primary colors so that it can * begin a transition to the new colors. We also want to do this upfront so * that we can reduce the amount of style invalidation caused during the * transitions. */ fg = ide_page_get_primary_color_fg (page); bg = ide_page_get_primary_color_bg (page); _ide_frame_header_set_foreground_rgba (dest_priv->header, fg); _ide_frame_header_set_background_rgba (dest_priv->header, bg); /* * If both the old and the new stacks are mapped, we can animate * between them using a snapshot of the page. Well, we also need * to be sure they have a valid allocation, but that check is done * slightly after this because it makes things easier. */ if (gtk_widget_get_mapped (GTK_WIDGET (self)) && gtk_widget_get_mapped (GTK_WIDGET (dest)) && gtk_widget_get_mapped (GTK_WIDGET (page))) { GtkAllocation alloc, dest_alloc; cairo_surface_t *surface = NULL; GdkWindow *window; GtkWidget *grid; gboolean enable_animations; grid = gtk_widget_get_ancestor (GTK_WIDGET (self), IDE_TYPE_GRID); gtk_widget_get_allocation (GTK_WIDGET (page), &alloc); gtk_widget_get_allocation (GTK_WIDGET (dest), &dest_alloc); g_object_get (gtk_settings_get_default (), "gtk-enable-animations", &enable_animations, NULL); if (enable_animations && grid != NULL && !is_uninitialized (&alloc) && !is_uninitialized (&dest_alloc) && dest_alloc.width > 0 && dest_alloc.height > 0 && NULL != (window = gtk_widget_get_window (GTK_WIDGET (page))) && NULL != (surface = gdk_window_create_similar_surface (window, CAIRO_CONTENT_COLOR, alloc.width, alloc.height))) { DzlBoxTheatric *theatric = NULL; AnimationState *state; cairo_t *cr; cr = cairo_create (surface); gtk_widget_draw (GTK_WIDGET (page), cr); cairo_destroy (cr); gtk_widget_translate_coordinates (GTK_WIDGET (priv->stack), grid, 0, 0, &alloc.x, &alloc.y); gtk_widget_translate_coordinates (GTK_WIDGET (dest_priv->stack), grid, 0, 0, &dest_alloc.x, &dest_alloc.y); theatric = g_object_new (DZL_TYPE_BOX_THEATRIC, "surface", surface, "height", alloc.height, "target", grid, "width", alloc.width, "x", alloc.x, "y", alloc.y, NULL); state = g_slice_new0 (AnimationState); state->source = g_object_ref (self); state->dest = g_object_ref (dest); state->page = g_object_ref (page); state->theatric = theatric; dzl_object_animate_full (theatric, DZL_ANIMATION_EASE_IN_OUT_CUBIC, TRANSITION_DURATION, gtk_widget_get_frame_clock (GTK_WIDGET (self)), animation_state_complete, state, "x", dest_alloc.x, "width", dest_alloc.width, "y", dest_alloc.y, "height", dest_alloc.height, NULL); /* * Mark the page as in-transition so that when we remove it * we can ignore the items-changed until the animation completes. */ g_ptr_array_add (priv->in_transition, g_object_ref (page)); gtk_container_remove (GTK_CONTAINER (priv->stack), GTK_WIDGET (page)); cairo_surface_destroy (surface); return; } } g_object_ref (page); gtk_container_remove (GTK_CONTAINER (priv->stack), GTK_WIDGET (page)); gtk_container_add (GTK_CONTAINER (dest_priv->stack), GTK_WIDGET (page)); g_object_unref (page); }
static void ide_frame_pan_end (IdeFrame *self, GdkEventSequence *sequence, GtkGesturePan *gesture) { IdeFramePrivate *priv = ide_frame_get_instance_private (self); IdeFramePrivate *dest_priv; IdeFrame *dest; GtkAllocation alloc; GtkWidget *grid; GtkWidget *column; gdouble x, y; gint direction; gint index = 0; IDE_ENTRY; g_assert (IDE_IS_FRAME (self)); g_assert (GTK_IS_GESTURE_PAN (gesture)); if (priv->pan_theatric == NULL || priv->pan_page == NULL) IDE_GOTO (cleanup); gtk_widget_get_allocation (GTK_WIDGET (self), &alloc); gtk_gesture_drag_get_offset (GTK_GESTURE_DRAG (gesture), &x, &y); if (x > DISTANCE_THRESHOLD (&alloc)) direction = 1; else if (x < -DISTANCE_THRESHOLD (&alloc)) direction = -1; else direction = 0; grid = gtk_widget_get_ancestor (GTK_WIDGET (self), IDE_TYPE_GRID); g_assert (grid != NULL); g_assert (IDE_IS_GRID (grid)); column = gtk_widget_get_ancestor (GTK_WIDGET (self), IDE_TYPE_GRID_COLUMN); g_assert (column != NULL); g_assert (IDE_IS_GRID_COLUMN (column)); gtk_container_child_get (GTK_CONTAINER (grid), GTK_WIDGET (column), "index", &index, NULL); dest = _ide_grid_get_nth_stack (IDE_GRID (grid), index + direction); dest_priv = ide_frame_get_instance_private (dest); g_assert (dest != NULL); g_assert (IDE_IS_FRAME (dest)); gtk_widget_get_allocation (GTK_WIDGET (dest), &alloc); if (!is_uninitialized (&alloc)) { AnimationState *state; state = g_slice_new0 (AnimationState); state->source = g_object_ref (self); state->dest = g_object_ref (dest); state->page = g_object_ref (priv->pan_page); state->theatric = g_object_ref (priv->pan_theatric); gtk_widget_translate_coordinates (GTK_WIDGET (dest_priv->top_stack), grid, 0, 0, &alloc.x, &alloc.y); /* * Use EASE_OUT_CUBIC, because user initiated the beginning of the * acceleration curve just by swiping. No need to duplicate. */ dzl_object_animate_full (state->theatric, DZL_ANIMATION_EASE_OUT_CUBIC, TRANSITION_DURATION, gtk_widget_get_frame_clock (GTK_WIDGET (self)), animation_state_complete, state, "x", alloc.x, "width", alloc.width, NULL); if (dest != self) { g_ptr_array_add (priv->in_transition, g_object_ref (priv->pan_page)); gtk_container_remove (GTK_CONTAINER (priv->stack), GTK_WIDGET (priv->pan_page)); } IDE_TRACE_MSG ("Animating transition to %s column", dest != self ? "another" : "same"); } else { g_autoptr(IdePage) page = g_object_ref (priv->pan_page); IDE_TRACE_MSG ("Moving page to a previously non-existant column"); gtk_container_remove (GTK_CONTAINER (priv->stack), GTK_WIDGET (page)); gtk_widget_show (GTK_WIDGET (page)); gtk_container_add (GTK_CONTAINER (dest_priv->stack), GTK_WIDGET (page)); } cleanup: g_clear_object (&priv->pan_theatric); g_clear_object (&priv->pan_page); gtk_widget_queue_draw (gtk_widget_get_toplevel (GTK_WIDGET (self))); ide_frame_set_cursor (self, "arrow"); IDE_EXIT; }
void gb_slider_set_position (GbSlider *self, GbSliderPosition position) { GbSliderPrivate *priv = gb_slider_get_instance_private (self); g_return_if_fail (GB_IS_SLIDER (self)); g_return_if_fail (position >= GB_SLIDER_NONE); g_return_if_fail (position <= GB_SLIDER_LEFT); if (priv->position != position) { GdkFrameClock *frame_clock; EggAnimation *anim; gdouble v_value; gdouble h_value; priv->position = position; if (priv->h_anim) egg_animation_stop (priv->h_anim); ide_clear_weak_pointer (&priv->h_anim); if (priv->v_anim) egg_animation_stop (priv->v_anim); ide_clear_weak_pointer (&priv->v_anim); switch (position) { case GB_SLIDER_NONE: h_value = 0.0; v_value = 0.0; break; case GB_SLIDER_TOP: h_value = 0.0; v_value = 1.0; break; case GB_SLIDER_RIGHT: h_value = -1.0; v_value = 0.0; break; case GB_SLIDER_BOTTOM: h_value = 0.0; v_value = -1.0; break; case GB_SLIDER_LEFT: h_value = 1.0; v_value = 0.0; break; default: g_assert_not_reached (); break; } frame_clock = gtk_widget_get_frame_clock (GTK_WIDGET (self)); anim = egg_object_animate (priv->h_adj, ANIMATION_MODE, ANIMATION_DURATION, frame_clock, "value", h_value, NULL); ide_set_weak_pointer (&priv->h_anim, anim); anim = egg_object_animate (priv->v_adj, ANIMATION_MODE, ANIMATION_DURATION, frame_clock, "value", v_value, NULL); ide_set_weak_pointer (&priv->v_anim, anim); g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_POSITION]); gtk_widget_queue_resize (GTK_WIDGET (self)); } }