[gtk+/wip/watson/progress-tracker: 50/60] progressbar: port to progress tracker
- From: Matthew Watson <watson src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/watson/progress-tracker: 50/60] progressbar: port to progress tracker
- Date: Mon, 28 Mar 2016 22:12:27 +0000 (UTC)
commit 5779779a6cc4496fe37a460a394803d21020c214
Author: Matt Watson <mattdangerw gmail com>
Date: Mon Mar 28 01:09:02 2016 -0700
progressbar: port to progress tracker
gtk/gtkprogressbar.c | 36 ++++++++++++++++++++++--------------
1 files changed, 22 insertions(+), 14 deletions(-)
---
diff --git a/gtk/gtkprogressbar.c b/gtk/gtkprogressbar.c
index 0942234..91dc693 100644
--- a/gtk/gtkprogressbar.c
+++ b/gtk/gtkprogressbar.c
@@ -38,6 +38,7 @@
#include "gtkcssstylepropertyprivate.h"
#include "gtkcsscustomgadgetprivate.h"
#include "gtkcssnumbervalueprivate.h"
+#include "gtkprogresstrackerprivate.h"
#include "a11y/gtkprogressbaraccessible.h"
@@ -92,6 +93,7 @@
#define MIN_VERTICAL_BAR_WIDTH 7
#define MIN_VERTICAL_BAR_HEIGHT 80
+#define DEFAULT_PULSE_DURATION 250000000
struct _GtkProgressBarPrivate
{
@@ -111,9 +113,10 @@ struct _GtkProgressBarPrivate
GtkOrientation orientation;
guint tick_id;
+ GtkProgressTracker tracker;
gint64 pulse1;
gint64 pulse2;
- gint64 frame1;
+ gdouble last_iteration;
guint activity_dir : 1;
guint activity_mode : 1;
@@ -1142,25 +1145,29 @@ tick_cb (GtkWidget *widget,
{
GtkProgressBar *pbar = GTK_PROGRESS_BAR (widget);
GtkProgressBarPrivate *priv = pbar->priv;
- gint64 frame2;
- gdouble fraction;
+ guint64 frame_time;
+ gdouble iteration, pulse_iterations, fraction;
- frame2 = gdk_frame_clock_get_frame_time (frame_clock);
- if (priv->frame1 == 0)
- priv->frame1 = frame2 - 16667;
- if (priv->pulse1 == 0)
- priv->pulse1 = priv->pulse2 - 250 * 1000000;
+ frame_time = gdk_frame_clock_get_frame_time (frame_clock);
- g_assert (priv->pulse2 > priv->pulse1);
- g_assert (frame2 > priv->frame1);
+ gtk_progress_tracker_next_frame (&priv->tracker, frame_time);
+ /* Tracker will complete an iteration every DEFAULT_PULSE_DURATION. If we don't have any
+ * pulses yet, we'll take that long to move our progress by pulse_fraction.
+ */
+ pulse_iterations = 1.0;
+ if (priv->pulse2 != 0 && priv->pulse1 != 0)
+ pulse_iterations = (priv->pulse2 - priv->pulse1) / (gdouble) DEFAULT_PULSE_DURATION;
+ if (priv->pulse2 != 0)
+ pulse_iterations = MAX ((frame_time - priv->pulse2) / (gdouble) DEFAULT_PULSE_DURATION,
pulse_iterations);
+
+ iteration = gtk_progress_tracker_get_iteration (&priv->tracker);
/* Determine the fraction to move the block from one frame
* to the next when pulse_fraction is how far the block should
* move between two calls to gtk_progress_bar_pulse().
*/
- fraction = priv->pulse_fraction * (frame2 - priv->frame1) / MAX (frame2 - priv->pulse2, priv->pulse2 -
priv->pulse1);
-
- priv->frame1 = frame2;
+ fraction = priv->pulse_fraction * (iteration - priv->last_iteration) / pulse_iterations;
+ priv->last_iteration = iteration;
/* advance the block */
if (priv->activity_dir == 0)
@@ -1237,10 +1244,11 @@ gtk_progress_bar_act_mode_enter (GtkProgressBar *pbar)
}
update_node_classes (pbar);
+ gtk_progress_tracker_start (&priv->tracker, DEFAULT_PULSE_DURATION, 0, INFINITY);
priv->tick_id = gtk_widget_add_tick_callback (widget, tick_cb, NULL, NULL);
priv->pulse2 = 0;
priv->pulse1 = 0;
- priv->frame1 = 0;
+ priv->last_iteration = 0;
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]