2009-07-21 01:16:56 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Matthias Clasen <mclasen@redhat.com>
|
|
|
|
* Copyright (C) 2008 Richard Hughes <richard@hughsie.com>
|
|
|
|
* Copyright (C) 2009 Bastien Nocera <hadess@hadess.net>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2009-07-21 01:16:56 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Modified by the GTK+ Team and others 2007. See the AUTHORS
|
|
|
|
* file for a list of people on the GTK+ Team. See the ChangeLog
|
|
|
|
* files for a list of changes. These files are distributed with
|
|
|
|
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gtkcellrendererspinner.h"
|
2017-11-15 04:30:58 +00:00
|
|
|
#include "gtkiconhelperprivate.h"
|
2009-10-21 18:21:20 +00:00
|
|
|
#include "gtkintl.h"
|
2012-03-03 18:22:22 +00:00
|
|
|
#include "gtksettings.h"
|
2016-12-23 10:11:52 +00:00
|
|
|
#include "gtksnapshot.h"
|
2012-03-03 18:22:22 +00:00
|
|
|
#include "gtktypebuiltins.h"
|
2017-11-15 04:30:58 +00:00
|
|
|
#include "gtkstylecontextprivate.h"
|
|
|
|
#include "gtkcssnumbervalueprivate.h"
|
2011-11-08 04:01:32 +00:00
|
|
|
|
2016-10-06 14:41:41 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
2009-10-14 17:25:23 +00:00
|
|
|
/**
|
2021-03-02 03:38:49 +00:00
|
|
|
* GtkCellRendererSpinner:
|
|
|
|
*
|
|
|
|
* Renders a spinning animation in a cell
|
2009-10-14 17:25:23 +00:00
|
|
|
*
|
2021-05-20 13:17:04 +00:00
|
|
|
* `GtkCellRendererSpinner` renders a spinning animation in a cell, very
|
|
|
|
* similar to `GtkSpinner`. It can often be used as an alternative
|
|
|
|
* to a `GtkCellRendererProgress` for displaying indefinite activity,
|
2009-10-14 17:25:23 +00:00
|
|
|
* instead of actual progress.
|
|
|
|
*
|
2021-05-20 13:17:04 +00:00
|
|
|
* To start the animation in a cell, set the `GtkCellRendererSpinner:active`
|
|
|
|
* property to %TRUE and increment the `GtkCellRendererSpinner:pulse` property
|
2009-10-14 17:25:23 +00:00
|
|
|
* at regular intervals. The usual way to set the cell renderer properties
|
|
|
|
* for each cell is to bind them to columns in your tree model using e.g.
|
|
|
|
* gtk_tree_view_column_add_attribute().
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2009-07-21 01:16:56 +00:00
|
|
|
enum {
|
|
|
|
PROP_0,
|
|
|
|
PROP_ACTIVE,
|
|
|
|
PROP_PULSE,
|
|
|
|
PROP_SIZE
|
|
|
|
};
|
|
|
|
|
2019-05-27 00:30:04 +00:00
|
|
|
typedef struct _GtkCellRendererSpinnerClass GtkCellRendererSpinnerClass;
|
|
|
|
typedef struct _GtkCellRendererSpinnerPrivate GtkCellRendererSpinnerPrivate;
|
|
|
|
|
|
|
|
struct _GtkCellRendererSpinner
|
|
|
|
{
|
|
|
|
GtkCellRenderer parent;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _GtkCellRendererSpinnerClass
|
|
|
|
{
|
|
|
|
GtkCellRendererClass parent_class;
|
|
|
|
|
|
|
|
/* Padding for future expansion */
|
|
|
|
void (*_gtk_reserved1) (void);
|
|
|
|
void (*_gtk_reserved2) (void);
|
|
|
|
void (*_gtk_reserved3) (void);
|
|
|
|
void (*_gtk_reserved4) (void);
|
|
|
|
};
|
|
|
|
|
2009-07-21 01:16:56 +00:00
|
|
|
struct _GtkCellRendererSpinnerPrivate
|
|
|
|
{
|
|
|
|
gboolean active;
|
|
|
|
guint pulse;
|
2017-01-23 18:59:27 +00:00
|
|
|
GtkIconSize icon_size;
|
2020-07-24 13:54:49 +00:00
|
|
|
int size;
|
2009-07-21 01:16:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-10-14 17:25:23 +00:00
|
|
|
static void gtk_cell_renderer_spinner_get_property (GObject *object,
|
|
|
|
guint param_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gtk_cell_renderer_spinner_set_property (GObject *object,
|
|
|
|
guint param_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2020-11-28 18:36:28 +00:00
|
|
|
static void gtk_cell_renderer_spinner_get_size (GtkCellRendererSpinner *self,
|
|
|
|
GtkWidget *widget,
|
|
|
|
const GdkRectangle *cell_area,
|
|
|
|
int *x_offset,
|
|
|
|
int *y_offset,
|
|
|
|
int *width,
|
|
|
|
int *height);
|
2016-12-23 10:11:52 +00:00
|
|
|
static void gtk_cell_renderer_spinner_snapshot (GtkCellRenderer *cell,
|
|
|
|
GtkSnapshot *snapshot,
|
2010-08-21 11:18:14 +00:00
|
|
|
GtkWidget *widget,
|
|
|
|
const GdkRectangle *background_area,
|
|
|
|
const GdkRectangle *cell_area,
|
|
|
|
GtkCellRendererState flags);
|
2009-07-21 01:16:56 +00:00
|
|
|
|
2013-06-27 19:02:52 +00:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GtkCellRendererSpinner, gtk_cell_renderer_spinner, GTK_TYPE_CELL_RENDERER)
|
2009-07-21 01:16:56 +00:00
|
|
|
|
2020-11-28 18:36:28 +00:00
|
|
|
static GtkSizeRequestMode
|
|
|
|
gtk_cell_renderer_spinner_get_request_mode (GtkCellRenderer *cell)
|
|
|
|
{
|
|
|
|
return GTK_SIZE_REQUEST_CONSTANT_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_cell_renderer_spinner_get_preferred_width (GtkCellRenderer *cell,
|
|
|
|
GtkWidget *widget,
|
|
|
|
int *minimum,
|
|
|
|
int *natural)
|
|
|
|
{
|
|
|
|
int size = 0;
|
|
|
|
|
|
|
|
gtk_cell_renderer_spinner_get_size (GTK_CELL_RENDERER_SPINNER (cell), widget,
|
|
|
|
NULL,
|
|
|
|
NULL, NULL, &size, NULL);
|
|
|
|
|
|
|
|
if (minimum != NULL)
|
|
|
|
*minimum = size;
|
|
|
|
if (natural != NULL)
|
|
|
|
*natural = size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_cell_renderer_spinner_get_preferred_height (GtkCellRenderer *cell,
|
|
|
|
GtkWidget *widget,
|
|
|
|
int *minimum,
|
|
|
|
int *natural)
|
|
|
|
{
|
|
|
|
int size = 0;
|
|
|
|
|
|
|
|
gtk_cell_renderer_spinner_get_size (GTK_CELL_RENDERER_SPINNER (cell), widget,
|
|
|
|
NULL,
|
|
|
|
NULL, NULL, NULL, &size);
|
|
|
|
|
|
|
|
if (minimum != NULL)
|
|
|
|
*minimum = size;
|
|
|
|
if (natural != NULL)
|
|
|
|
*natural = size;
|
|
|
|
}
|
|
|
|
|
2009-07-21 01:16:56 +00:00
|
|
|
static void
|
|
|
|
gtk_cell_renderer_spinner_class_init (GtkCellRendererSpinnerClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->get_property = gtk_cell_renderer_spinner_get_property;
|
|
|
|
object_class->set_property = gtk_cell_renderer_spinner_set_property;
|
|
|
|
|
2020-11-28 18:36:28 +00:00
|
|
|
cell_class->get_request_mode = gtk_cell_renderer_spinner_get_request_mode;
|
|
|
|
cell_class->get_preferred_width = gtk_cell_renderer_spinner_get_preferred_width;
|
|
|
|
cell_class->get_preferred_height = gtk_cell_renderer_spinner_get_preferred_height;
|
2016-12-23 10:11:52 +00:00
|
|
|
cell_class->snapshot = gtk_cell_renderer_spinner_snapshot;
|
2009-07-21 01:16:56 +00:00
|
|
|
|
2009-10-14 17:25:23 +00:00
|
|
|
/* GtkCellRendererSpinner:active:
|
2009-07-21 01:16:56 +00:00
|
|
|
*
|
|
|
|
* Whether the spinner is active (ie. shown) in the cell
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_ACTIVE,
|
|
|
|
g_param_spec_boolean ("active",
|
|
|
|
P_("Active"),
|
|
|
|
P_("Whether the spinner is active (ie. shown) in the cell"),
|
|
|
|
FALSE,
|
2014-06-07 15:47:30 +00:00
|
|
|
G_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
|
|
|
|
|
2009-10-14 17:25:23 +00:00
|
|
|
/**
|
|
|
|
* GtkCellRendererSpinner:pulse:
|
|
|
|
*
|
|
|
|
* Pulse of the spinner. Increment this value to draw the next frame of the
|
|
|
|
* spinner animation. Usually, you would update this value in a timeout.
|
2009-07-21 01:16:56 +00:00
|
|
|
*
|
2021-05-20 13:17:04 +00:00
|
|
|
* By default, the `GtkSpinner` widget draws one full cycle of the animation,
|
2011-01-06 04:21:52 +00:00
|
|
|
* consisting of 12 frames, in 750 milliseconds.
|
2009-07-21 01:16:56 +00:00
|
|
|
*/
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_PULSE,
|
|
|
|
g_param_spec_uint ("pulse",
|
|
|
|
P_("Pulse"),
|
|
|
|
P_("Pulse of the spinner"),
|
|
|
|
0, G_MAXUINT, 0,
|
2014-06-07 15:47:30 +00:00
|
|
|
G_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
|
|
|
|
|
2009-10-14 17:25:23 +00:00
|
|
|
/**
|
|
|
|
* GtkCellRendererSpinner:size:
|
2009-07-21 01:16:56 +00:00
|
|
|
*
|
2021-05-20 13:17:04 +00:00
|
|
|
* The `GtkIconSize` value that specifies the size of the rendered spinner.
|
2009-07-21 01:16:56 +00:00
|
|
|
*/
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_SIZE,
|
|
|
|
g_param_spec_enum ("size",
|
|
|
|
P_("Size"),
|
2009-10-14 17:25:23 +00:00
|
|
|
P_("The GtkIconSize value that specifies the size of the rendered spinner"),
|
2017-11-15 02:14:47 +00:00
|
|
|
GTK_TYPE_ICON_SIZE, GTK_ICON_SIZE_INHERIT,
|
2014-06-07 15:47:30 +00:00
|
|
|
G_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
|
2009-07-21 01:16:56 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_cell_renderer_spinner_init (GtkCellRendererSpinner *cell)
|
|
|
|
{
|
2019-05-27 00:33:38 +00:00
|
|
|
GtkCellRendererSpinnerPrivate *priv = gtk_cell_renderer_spinner_get_instance_private (cell);
|
|
|
|
priv->pulse = 0;
|
|
|
|
priv->icon_size = GTK_ICON_SIZE_INHERIT;
|
2009-07-21 01:16:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-01-06 04:21:52 +00:00
|
|
|
* gtk_cell_renderer_spinner_new:
|
2009-07-21 01:16:56 +00:00
|
|
|
*
|
|
|
|
* Returns a new cell renderer which will show a spinner to indicate
|
|
|
|
* activity.
|
|
|
|
*
|
2021-05-20 13:17:04 +00:00
|
|
|
* Returns: a new `GtkCellRenderer`
|
2009-07-21 01:16:56 +00:00
|
|
|
*/
|
|
|
|
GtkCellRenderer *
|
|
|
|
gtk_cell_renderer_spinner_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (GTK_TYPE_CELL_RENDERER_SPINNER, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_cell_renderer_spinner_update_size (GtkCellRendererSpinner *cell,
|
2009-10-14 17:25:23 +00:00
|
|
|
GtkWidget *widget)
|
2009-07-21 01:16:56 +00:00
|
|
|
{
|
2019-05-27 00:33:38 +00:00
|
|
|
GtkCellRendererSpinnerPrivate *priv = gtk_cell_renderer_spinner_get_instance_private (cell);
|
2017-11-15 04:30:58 +00:00
|
|
|
GtkStyleContext *context;
|
|
|
|
GtkCssNode *node;
|
|
|
|
GtkCssStyle *style;
|
|
|
|
|
|
|
|
context = gtk_widget_get_style_context (widget);
|
|
|
|
gtk_style_context_save (context);
|
|
|
|
|
|
|
|
gtk_style_context_add_class (context, "spinner");
|
|
|
|
node = gtk_style_context_get_node (context);
|
|
|
|
gtk_icon_size_set_style_classes (node, priv->icon_size);
|
|
|
|
style = gtk_css_node_get_style (node);
|
2020-01-28 07:38:25 +00:00
|
|
|
priv->size = _gtk_css_number_value_get (style->icon->icon_size, 100);
|
2017-11-15 04:30:58 +00:00
|
|
|
|
|
|
|
gtk_style_context_restore (context);
|
2009-07-21 01:16:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_cell_renderer_spinner_get_property (GObject *object,
|
|
|
|
guint param_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkCellRendererSpinner *cell = GTK_CELL_RENDERER_SPINNER (object);
|
2019-05-27 00:33:38 +00:00
|
|
|
GtkCellRendererSpinnerPrivate *priv = gtk_cell_renderer_spinner_get_instance_private (cell);
|
2009-07-21 01:16:56 +00:00
|
|
|
|
|
|
|
switch (param_id)
|
|
|
|
{
|
|
|
|
case PROP_ACTIVE:
|
|
|
|
g_value_set_boolean (value, priv->active);
|
|
|
|
break;
|
|
|
|
case PROP_PULSE:
|
|
|
|
g_value_set_uint (value, priv->pulse);
|
|
|
|
break;
|
|
|
|
case PROP_SIZE:
|
|
|
|
g_value_set_enum (value, priv->icon_size);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_cell_renderer_spinner_set_property (GObject *object,
|
|
|
|
guint param_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkCellRendererSpinner *cell = GTK_CELL_RENDERER_SPINNER (object);
|
2019-05-27 00:33:38 +00:00
|
|
|
GtkCellRendererSpinnerPrivate *priv = gtk_cell_renderer_spinner_get_instance_private (cell);
|
2009-07-21 01:16:56 +00:00
|
|
|
|
|
|
|
switch (param_id)
|
|
|
|
{
|
|
|
|
case PROP_ACTIVE:
|
2014-06-07 15:47:30 +00:00
|
|
|
if (priv->active != g_value_get_boolean (value))
|
|
|
|
{
|
|
|
|
priv->active = g_value_get_boolean (value);
|
|
|
|
g_object_notify (object, "active");
|
|
|
|
}
|
2009-07-21 01:16:56 +00:00
|
|
|
break;
|
|
|
|
case PROP_PULSE:
|
2014-06-07 15:47:30 +00:00
|
|
|
if (priv->pulse != g_value_get_uint (value))
|
|
|
|
{
|
|
|
|
priv->pulse = g_value_get_uint (value);
|
|
|
|
g_object_notify (object, "pulse");
|
|
|
|
}
|
2009-07-21 01:16:56 +00:00
|
|
|
break;
|
|
|
|
case PROP_SIZE:
|
2014-06-07 15:47:30 +00:00
|
|
|
if (priv->icon_size != g_value_get_enum (value))
|
|
|
|
{
|
|
|
|
priv->icon_size = g_value_get_enum (value);
|
|
|
|
g_object_notify (object, "size");
|
|
|
|
}
|
2009-07-21 01:16:56 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-11-28 18:36:28 +00:00
|
|
|
gtk_cell_renderer_spinner_get_size (GtkCellRendererSpinner *self,
|
|
|
|
GtkWidget *widget,
|
|
|
|
const GdkRectangle *cell_area,
|
|
|
|
int *x_offset,
|
|
|
|
int *y_offset,
|
|
|
|
int *width,
|
|
|
|
int *height)
|
2009-07-21 01:16:56 +00:00
|
|
|
{
|
2020-11-28 18:36:28 +00:00
|
|
|
GtkCellRendererSpinnerPrivate *priv = gtk_cell_renderer_spinner_get_instance_private (self);
|
2020-07-24 20:32:16 +00:00
|
|
|
double align;
|
2020-07-24 13:54:49 +00:00
|
|
|
int w, h;
|
|
|
|
int xpad, ypad;
|
2020-07-24 20:25:56 +00:00
|
|
|
float xalign, yalign;
|
2009-07-21 01:16:56 +00:00
|
|
|
gboolean rtl;
|
|
|
|
|
|
|
|
rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
|
|
|
|
|
2020-11-28 18:36:28 +00:00
|
|
|
gtk_cell_renderer_spinner_update_size (self, widget);
|
2009-07-21 01:16:56 +00:00
|
|
|
|
2020-11-28 18:36:28 +00:00
|
|
|
g_object_get (self,
|
2009-07-21 01:16:56 +00:00
|
|
|
"xpad", &xpad,
|
|
|
|
"ypad", &ypad,
|
|
|
|
"xalign", &xalign,
|
|
|
|
"yalign", &yalign,
|
|
|
|
NULL);
|
2020-11-28 18:36:28 +00:00
|
|
|
|
2009-07-21 01:16:56 +00:00
|
|
|
w = h = priv->size;
|
|
|
|
|
|
|
|
if (cell_area)
|
|
|
|
{
|
|
|
|
if (x_offset)
|
|
|
|
{
|
|
|
|
align = rtl ? 1.0 - xalign : xalign;
|
|
|
|
*x_offset = align * (cell_area->width - w);
|
|
|
|
*x_offset = MAX (*x_offset, 0);
|
|
|
|
}
|
|
|
|
if (y_offset)
|
|
|
|
{
|
|
|
|
align = rtl ? 1.0 - yalign : yalign;
|
|
|
|
*y_offset = align * (cell_area->height - h);
|
|
|
|
*y_offset = MAX (*y_offset, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (x_offset)
|
|
|
|
*x_offset = 0;
|
|
|
|
if (y_offset)
|
|
|
|
*y_offset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (width)
|
|
|
|
*width = w;
|
|
|
|
if (height)
|
|
|
|
*height = h;
|
|
|
|
}
|
|
|
|
|
2016-10-06 14:41:41 +00:00
|
|
|
static void
|
|
|
|
gtk_paint_spinner (GtkStyleContext *context,
|
|
|
|
cairo_t *cr,
|
|
|
|
guint step,
|
2020-07-24 13:54:49 +00:00
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int width,
|
|
|
|
int height)
|
2016-10-06 14:41:41 +00:00
|
|
|
{
|
|
|
|
GdkRGBA color;
|
|
|
|
guint num_steps;
|
2020-07-24 20:32:16 +00:00
|
|
|
double dx, dy;
|
|
|
|
double radius;
|
|
|
|
double half;
|
2020-07-24 13:54:49 +00:00
|
|
|
int i;
|
2016-10-06 14:41:41 +00:00
|
|
|
guint real_step;
|
|
|
|
|
|
|
|
num_steps = 12;
|
|
|
|
real_step = step % num_steps;
|
|
|
|
|
|
|
|
/* set a clip region for the expose event */
|
|
|
|
cairo_rectangle (cr, x, y, width, height);
|
|
|
|
cairo_clip (cr);
|
|
|
|
|
|
|
|
cairo_translate (cr, x, y);
|
|
|
|
|
|
|
|
/* draw clip region */
|
|
|
|
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
|
|
|
|
|
2016-10-08 03:07:23 +00:00
|
|
|
gtk_style_context_get_color (context, &color);
|
2016-10-06 14:41:41 +00:00
|
|
|
dx = width / 2;
|
|
|
|
dy = height / 2;
|
|
|
|
radius = MIN (width / 2, height / 2);
|
|
|
|
half = num_steps / 2;
|
|
|
|
|
|
|
|
for (i = 0; i < num_steps; i++)
|
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
int inset = 0.7 * radius;
|
2016-10-06 14:41:41 +00:00
|
|
|
|
2020-05-28 08:00:03 +00:00
|
|
|
/* transparency is a function of time and initial value */
|
2020-07-24 20:32:16 +00:00
|
|
|
double t = (double) ((i + num_steps - real_step)
|
2016-10-06 14:41:41 +00:00
|
|
|
% num_steps) / num_steps;
|
|
|
|
|
|
|
|
cairo_save (cr);
|
|
|
|
|
|
|
|
cairo_set_source_rgba (cr,
|
|
|
|
color.red / 65535.,
|
|
|
|
color.green / 65535.,
|
|
|
|
color.blue / 65535.,
|
|
|
|
color.alpha * t);
|
|
|
|
|
|
|
|
cairo_set_line_width (cr, 2.0);
|
|
|
|
cairo_move_to (cr,
|
|
|
|
dx + (radius - inset) * cos (i * G_PI / half),
|
|
|
|
dy + (radius - inset) * sin (i * G_PI / half));
|
|
|
|
cairo_line_to (cr,
|
|
|
|
dx + radius * cos (i * G_PI / half),
|
|
|
|
dy + radius * sin (i * G_PI / half));
|
|
|
|
cairo_stroke (cr);
|
|
|
|
|
|
|
|
cairo_restore (cr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-21 01:16:56 +00:00
|
|
|
static void
|
2020-11-28 18:36:28 +00:00
|
|
|
gtk_cell_renderer_spinner_snapshot (GtkCellRenderer *cell,
|
2016-12-23 10:11:52 +00:00
|
|
|
GtkSnapshot *snapshot,
|
|
|
|
GtkWidget *widget,
|
|
|
|
const GdkRectangle *background_area,
|
|
|
|
const GdkRectangle *cell_area,
|
|
|
|
GtkCellRendererState flags)
|
2009-07-21 01:16:56 +00:00
|
|
|
{
|
2020-11-28 18:36:28 +00:00
|
|
|
GtkCellRendererSpinner *self = GTK_CELL_RENDERER_SPINNER (cell);
|
|
|
|
GtkCellRendererSpinnerPrivate *priv = gtk_cell_renderer_spinner_get_instance_private (self);
|
2009-07-21 01:16:56 +00:00
|
|
|
GdkRectangle pix_rect;
|
|
|
|
GdkRectangle draw_rect;
|
2020-07-24 13:54:49 +00:00
|
|
|
int xpad, ypad;
|
2016-12-23 10:11:52 +00:00
|
|
|
cairo_t *cr;
|
2009-07-21 01:16:56 +00:00
|
|
|
|
|
|
|
if (!priv->active)
|
|
|
|
return;
|
|
|
|
|
2020-11-28 18:36:28 +00:00
|
|
|
gtk_cell_renderer_spinner_get_size (self, widget, cell_area,
|
|
|
|
&pix_rect.x,
|
|
|
|
&pix_rect.y,
|
|
|
|
&pix_rect.width,
|
|
|
|
&pix_rect.height);
|
2009-07-21 01:16:56 +00:00
|
|
|
|
2020-11-28 18:36:28 +00:00
|
|
|
g_object_get (self,
|
2009-07-21 01:16:56 +00:00
|
|
|
"xpad", &xpad,
|
|
|
|
"ypad", &ypad,
|
|
|
|
NULL);
|
2020-11-28 18:36:28 +00:00
|
|
|
|
2009-07-21 01:16:56 +00:00
|
|
|
pix_rect.x += cell_area->x + xpad;
|
|
|
|
pix_rect.y += cell_area->y + ypad;
|
|
|
|
pix_rect.width -= xpad * 2;
|
|
|
|
pix_rect.height -= ypad * 2;
|
|
|
|
|
2010-08-21 11:18:14 +00:00
|
|
|
if (!gdk_rectangle_intersect (cell_area, &pix_rect, &draw_rect))
|
|
|
|
return;
|
2009-07-21 01:16:56 +00:00
|
|
|
|
2017-01-13 03:46:09 +00:00
|
|
|
cr = gtk_snapshot_append_cairo (snapshot,
|
|
|
|
&GRAPHENE_RECT_INIT (
|
|
|
|
cell_area->x, cell_area->y,
|
|
|
|
cell_area->width, cell_area->height
|
2018-04-24 01:17:23 +00:00
|
|
|
));
|
2010-12-15 23:07:08 +00:00
|
|
|
|
2016-10-06 14:41:41 +00:00
|
|
|
gtk_paint_spinner (gtk_widget_get_style_context (widget),
|
|
|
|
cr,
|
|
|
|
priv->pulse,
|
|
|
|
draw_rect.x, draw_rect.y,
|
|
|
|
draw_rect.width, draw_rect.height);
|
2010-12-15 23:07:08 +00:00
|
|
|
|
2016-12-23 10:11:52 +00:00
|
|
|
cairo_destroy (cr);
|
2009-07-21 01:16:56 +00:00
|
|
|
}
|