forked from AuroraMiddleware/gtk
progressbar: Store activity position as percentage
... instead of in absolute pixels.
This commit is contained in:
parent
02b440b466
commit
b39bb4400e
@ -75,7 +75,7 @@ struct _GtkProgressBarPrivate
|
||||
gdouble fraction;
|
||||
gdouble pulse_fraction;
|
||||
|
||||
gint activity_pos;
|
||||
double activity_pos;
|
||||
guint activity_blocks;
|
||||
|
||||
GtkOrientation orientation;
|
||||
@ -415,7 +415,6 @@ gtk_progress_bar_real_update (GtkProgressBar *pbar)
|
||||
{
|
||||
GtkProgressBarPrivate *priv;
|
||||
GtkWidget *widget;
|
||||
int activity_step;
|
||||
|
||||
g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
|
||||
|
||||
@ -424,68 +423,23 @@ gtk_progress_bar_real_update (GtkProgressBar *pbar)
|
||||
|
||||
if (priv->activity_mode)
|
||||
{
|
||||
GtkAllocation allocation;
|
||||
GtkStyleContext *context;
|
||||
GtkStateFlags state;
|
||||
GtkBorder padding;
|
||||
gint size;
|
||||
|
||||
gtk_widget_get_allocation (widget, &allocation);
|
||||
context = gtk_widget_get_style_context (widget);
|
||||
state = gtk_widget_get_state_flags (widget);
|
||||
gtk_style_context_get_padding (context, state, &padding);
|
||||
|
||||
/* advance the block */
|
||||
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
|
||||
if (priv->activity_dir == 0)
|
||||
{
|
||||
/* Update our activity step. */
|
||||
activity_step = allocation.width * priv->pulse_fraction;
|
||||
|
||||
size = MAX (2, allocation.width / priv->activity_blocks);
|
||||
|
||||
if (priv->activity_dir == 0)
|
||||
priv->activity_pos += priv->pulse_fraction;
|
||||
if (priv->activity_pos > 1.0)
|
||||
{
|
||||
priv->activity_pos += activity_step;
|
||||
if (priv->activity_pos + size >= allocation.width - padding.left)
|
||||
{
|
||||
priv->activity_pos = allocation.width - padding.left - size;
|
||||
priv->activity_dir = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
priv->activity_pos -= activity_step;
|
||||
if (priv->activity_pos <= padding.left)
|
||||
{
|
||||
priv->activity_pos = padding.left;
|
||||
priv->activity_dir = 0;
|
||||
}
|
||||
priv->activity_pos = 1.0;
|
||||
priv->activity_dir = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Update our activity step. */
|
||||
activity_step = allocation.height * priv->pulse_fraction;
|
||||
|
||||
size = MAX (2, allocation.height / priv->activity_blocks);
|
||||
|
||||
if (priv->activity_dir == 0)
|
||||
priv->activity_pos -= priv->pulse_fraction;
|
||||
if (priv->activity_pos <= 0)
|
||||
{
|
||||
priv->activity_pos += activity_step;
|
||||
if (priv->activity_pos + size >= allocation.height - padding.top)
|
||||
{
|
||||
priv->activity_pos = allocation.height - padding.top - size;
|
||||
priv->activity_dir = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
priv->activity_pos -= activity_step;
|
||||
if (priv->activity_pos <= padding.top)
|
||||
{
|
||||
priv->activity_pos = padding.top;
|
||||
priv->activity_dir = 0;
|
||||
}
|
||||
priv->activity_pos = 0;
|
||||
priv->activity_dir = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -650,7 +604,6 @@ static void
|
||||
gtk_progress_bar_act_mode_enter (GtkProgressBar *pbar)
|
||||
{
|
||||
GtkProgressBarPrivate *priv = pbar->priv;
|
||||
GtkAllocation allocation;
|
||||
GtkStyleContext *context;
|
||||
GtkStateFlags state;
|
||||
GtkBorder padding;
|
||||
@ -676,14 +629,12 @@ gtk_progress_bar_act_mode_enter (GtkProgressBar *pbar)
|
||||
{
|
||||
if (!inverted)
|
||||
{
|
||||
priv->activity_pos = padding.left;
|
||||
priv->activity_pos = 0.0;
|
||||
priv->activity_dir = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_widget_get_allocation (widget, &allocation);
|
||||
priv->activity_pos = allocation.width - padding.left -
|
||||
(allocation.height - padding.top - padding.bottom);
|
||||
priv->activity_pos = 1.0;
|
||||
priv->activity_dir = 1;
|
||||
}
|
||||
}
|
||||
@ -691,14 +642,12 @@ gtk_progress_bar_act_mode_enter (GtkProgressBar *pbar)
|
||||
{
|
||||
if (!inverted)
|
||||
{
|
||||
priv->activity_pos = padding.top;
|
||||
priv->activity_pos = 0.0;
|
||||
priv->activity_dir = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_widget_get_allocation (widget, &allocation);
|
||||
priv->activity_pos = allocation.height - padding.top -
|
||||
(allocation.width - padding.left - padding.right);
|
||||
priv->activity_pos = 1.0;
|
||||
priv->activity_dir = 1;
|
||||
}
|
||||
}
|
||||
@ -711,17 +660,25 @@ gtk_progress_bar_get_activity (GtkProgressBar *pbar,
|
||||
gint *amount)
|
||||
{
|
||||
GtkProgressBarPrivate *priv = pbar->priv;
|
||||
GtkAllocation allocation;
|
||||
GtkWidget *widget = GTK_WIDGET (pbar);
|
||||
GtkStyleContext *context;
|
||||
GtkAllocation allocation;
|
||||
GtkStateFlags state;
|
||||
GtkBorder padding;
|
||||
int size;
|
||||
|
||||
*offset = priv->activity_pos;
|
||||
|
||||
context = gtk_widget_get_style_context (widget);
|
||||
state = gtk_style_context_get_state (context);
|
||||
gtk_widget_get_allocation (widget, &allocation);
|
||||
gtk_style_context_get_padding (context, state, &padding);
|
||||
|
||||
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
||||
*amount = MAX (2, allocation.width / priv->activity_blocks);
|
||||
size = allocation.width - padding.left - padding.top;
|
||||
else
|
||||
*amount = MAX (2, allocation.height / priv->activity_blocks);
|
||||
size = allocation.height - padding.left - padding.top;
|
||||
|
||||
*amount = MAX (2, size / priv->activity_blocks);
|
||||
*offset = priv->activity_pos * (size - *amount);
|
||||
}
|
||||
|
||||
static void
|
||||
|
Loading…
Reference in New Issue
Block a user