app: port GimpCircle and its subclasses to G_DECLARE_DERIVABLE_TYPE()
This commit is contained in:
parent
d2ca61d5e2
commit
5a66ceda13
6 changed files with 205 additions and 212 deletions
|
|
@ -46,6 +46,8 @@ enum
|
|||
};
|
||||
|
||||
|
||||
typedef struct _GimpCirclePrivate GimpCirclePrivate;
|
||||
|
||||
struct _GimpCirclePrivate
|
||||
{
|
||||
gint size;
|
||||
|
|
@ -58,6 +60,10 @@ struct _GimpCirclePrivate
|
|||
gboolean in_widget;
|
||||
};
|
||||
|
||||
#define GET_PRIVATE(obj) \
|
||||
((GimpCirclePrivate *) gimp_circle_get_instance_private ((GimpCircle *) obj))
|
||||
|
||||
|
||||
|
||||
static void gimp_circle_dispose (GObject *object);
|
||||
static void gimp_circle_set_property (GObject *object,
|
||||
|
|
@ -160,8 +166,6 @@ gimp_circle_class_init (GimpCircleClass *klass)
|
|||
static void
|
||||
gimp_circle_init (GimpCircle *circle)
|
||||
{
|
||||
circle->priv = gimp_circle_get_instance_private (circle);
|
||||
|
||||
gtk_widget_set_has_window (GTK_WIDGET (circle), FALSE);
|
||||
gtk_widget_add_events (GTK_WIDGET (circle),
|
||||
GDK_POINTER_MOTION_MASK |
|
||||
|
|
@ -175,9 +179,9 @@ gimp_circle_init (GimpCircle *circle)
|
|||
static void
|
||||
gimp_circle_dispose (GObject *object)
|
||||
{
|
||||
GimpCircle *circle = GIMP_CIRCLE (object);
|
||||
GimpCirclePrivate *priv = GET_PRIVATE (object);
|
||||
|
||||
g_clear_pointer (&circle->priv->surface, cairo_surface_destroy);
|
||||
g_clear_pointer (&priv->surface, cairo_surface_destroy);
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->dispose (object);
|
||||
}
|
||||
|
|
@ -188,24 +192,24 @@ gimp_circle_set_property (GObject *object,
|
|||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GimpCircle *circle = GIMP_CIRCLE (object);
|
||||
GimpCirclePrivate *priv = GET_PRIVATE (object);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_SIZE:
|
||||
circle->priv->size = g_value_get_int (value);
|
||||
gtk_widget_queue_resize (GTK_WIDGET (circle));
|
||||
priv->size = g_value_get_int (value);
|
||||
gtk_widget_queue_resize (GTK_WIDGET (object));
|
||||
break;
|
||||
|
||||
case PROP_BORDER_WIDTH:
|
||||
circle->priv->border_width = g_value_get_int (value);
|
||||
gtk_widget_queue_resize (GTK_WIDGET (circle));
|
||||
priv->border_width = g_value_get_int (value);
|
||||
gtk_widget_queue_resize (GTK_WIDGET (object));
|
||||
break;
|
||||
|
||||
case PROP_BACKGROUND:
|
||||
circle->priv->background = g_value_get_enum (value);
|
||||
g_clear_pointer (&circle->priv->surface, cairo_surface_destroy);
|
||||
gtk_widget_queue_draw (GTK_WIDGET (circle));
|
||||
priv->background = g_value_get_enum (value);
|
||||
g_clear_pointer (&priv->surface, cairo_surface_destroy);
|
||||
gtk_widget_queue_draw (GTK_WIDGET (object));
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
@ -220,20 +224,20 @@ gimp_circle_get_property (GObject *object,
|
|||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GimpCircle *circle = GIMP_CIRCLE (object);
|
||||
GimpCirclePrivate *priv = GET_PRIVATE (object);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_SIZE:
|
||||
g_value_set_int (value, circle->priv->size);
|
||||
g_value_set_int (value, priv->size);
|
||||
break;
|
||||
|
||||
case PROP_BORDER_WIDTH:
|
||||
g_value_set_int (value, circle->priv->border_width);
|
||||
g_value_set_int (value, priv->border_width);
|
||||
break;
|
||||
|
||||
case PROP_BACKGROUND:
|
||||
g_value_set_enum (value, circle->priv->background);
|
||||
g_value_set_enum (value, priv->background);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
@ -245,10 +249,10 @@ gimp_circle_get_property (GObject *object,
|
|||
static void
|
||||
gimp_circle_realize (GtkWidget *widget)
|
||||
{
|
||||
GimpCircle *circle = GIMP_CIRCLE (widget);
|
||||
GtkAllocation allocation;
|
||||
GdkWindowAttr attributes;
|
||||
gint attributes_mask;
|
||||
GimpCirclePrivate *priv = GET_PRIVATE (widget);
|
||||
GtkAllocation allocation;
|
||||
GdkWindowAttr attributes;
|
||||
gint attributes_mask;
|
||||
|
||||
GTK_WIDGET_CLASS (parent_class)->realize (widget);
|
||||
|
||||
|
|
@ -264,21 +268,21 @@ gimp_circle_realize (GtkWidget *widget)
|
|||
|
||||
attributes_mask = GDK_WA_X | GDK_WA_Y;
|
||||
|
||||
circle->priv->event_window = gdk_window_new (gtk_widget_get_window (widget),
|
||||
&attributes, attributes_mask);
|
||||
gdk_window_set_user_data (circle->priv->event_window, circle);
|
||||
priv->event_window = gdk_window_new (gtk_widget_get_window (widget),
|
||||
&attributes, attributes_mask);
|
||||
gdk_window_set_user_data (priv->event_window, widget);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_circle_unrealize (GtkWidget *widget)
|
||||
{
|
||||
GimpCircle *circle = GIMP_CIRCLE (widget);
|
||||
GimpCirclePrivate *priv = GET_PRIVATE (widget);
|
||||
|
||||
if (circle->priv->event_window)
|
||||
if (priv->event_window)
|
||||
{
|
||||
gdk_window_set_user_data (circle->priv->event_window, NULL);
|
||||
gdk_window_destroy (circle->priv->event_window);
|
||||
circle->priv->event_window = NULL;
|
||||
gdk_window_set_user_data (priv->event_window, NULL);
|
||||
gdk_window_destroy (priv->event_window);
|
||||
priv->event_window = NULL;
|
||||
}
|
||||
|
||||
GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
|
||||
|
|
@ -287,27 +291,27 @@ gimp_circle_unrealize (GtkWidget *widget)
|
|||
static void
|
||||
gimp_circle_map (GtkWidget *widget)
|
||||
{
|
||||
GimpCircle *circle = GIMP_CIRCLE (widget);
|
||||
GimpCirclePrivate *priv = GET_PRIVATE (widget);
|
||||
|
||||
GTK_WIDGET_CLASS (parent_class)->map (widget);
|
||||
|
||||
if (circle->priv->event_window)
|
||||
gdk_window_show (circle->priv->event_window);
|
||||
if (priv->event_window)
|
||||
gdk_window_show (priv->event_window);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_circle_unmap (GtkWidget *widget)
|
||||
{
|
||||
GimpCircle *circle = GIMP_CIRCLE (widget);
|
||||
GimpCirclePrivate *priv = GET_PRIVATE (widget);
|
||||
|
||||
if (circle->priv->has_grab)
|
||||
if (priv->has_grab)
|
||||
{
|
||||
gtk_grab_remove (widget);
|
||||
circle->priv->has_grab = FALSE;
|
||||
priv->has_grab = FALSE;
|
||||
}
|
||||
|
||||
if (circle->priv->event_window)
|
||||
gdk_window_hide (circle->priv->event_window);
|
||||
if (priv->event_window)
|
||||
gdk_window_hide (priv->event_window);
|
||||
|
||||
GTK_WIDGET_CLASS (parent_class)->unmap (widget);
|
||||
}
|
||||
|
|
@ -317,9 +321,9 @@ gimp_circle_get_preferred_width (GtkWidget *widget,
|
|||
gint *minimum_width,
|
||||
gint *natural_width)
|
||||
{
|
||||
GimpCircle *circle = GIMP_CIRCLE (widget);
|
||||
GimpCirclePrivate *priv = GET_PRIVATE (widget);
|
||||
|
||||
*minimum_width = *natural_width = 2 * circle->priv->border_width + circle->priv->size;
|
||||
*minimum_width = *natural_width = 2 * priv->border_width + priv->size;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -327,36 +331,36 @@ gimp_circle_get_preferred_height (GtkWidget *widget,
|
|||
gint *minimum_height,
|
||||
gint *natural_height)
|
||||
{
|
||||
GimpCircle *circle = GIMP_CIRCLE (widget);
|
||||
GimpCirclePrivate *priv = GET_PRIVATE (widget);
|
||||
|
||||
*minimum_height = *natural_height = 2 * circle->priv->border_width + circle->priv->size;
|
||||
*minimum_height = *natural_height = 2 * priv->border_width + priv->size;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_circle_size_allocate (GtkWidget *widget,
|
||||
GtkAllocation *allocation)
|
||||
{
|
||||
GimpCircle *circle = GIMP_CIRCLE (widget);
|
||||
GimpCirclePrivate *priv = GET_PRIVATE (widget);
|
||||
|
||||
GTK_WIDGET_CLASS (parent_class)->size_allocate (widget, allocation);
|
||||
|
||||
if (gtk_widget_get_realized (widget))
|
||||
gdk_window_move_resize (circle->priv->event_window,
|
||||
gdk_window_move_resize (priv->event_window,
|
||||
allocation->x,
|
||||
allocation->y,
|
||||
allocation->width,
|
||||
allocation->height);
|
||||
|
||||
g_clear_pointer (&circle->priv->surface, cairo_surface_destroy);
|
||||
g_clear_pointer (&priv->surface, cairo_surface_destroy);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gimp_circle_draw (GtkWidget *widget,
|
||||
cairo_t *cr)
|
||||
{
|
||||
GimpCircle *circle = GIMP_CIRCLE (widget);
|
||||
GtkAllocation allocation;
|
||||
gint size = circle->priv->size;
|
||||
GimpCirclePrivate *priv = GET_PRIVATE (widget);
|
||||
GtkAllocation allocation;
|
||||
gint size = priv->size;
|
||||
|
||||
gtk_widget_get_allocation (widget, &allocation);
|
||||
|
||||
|
|
@ -366,7 +370,8 @@ gimp_circle_draw (GtkWidget *widget,
|
|||
(allocation.width - size) / 2,
|
||||
(allocation.height - size) / 2);
|
||||
|
||||
gimp_circle_draw_background (circle, cr, size, circle->priv->background);
|
||||
gimp_circle_draw_background (GIMP_CIRCLE (widget), cr,
|
||||
size, priv->background);
|
||||
|
||||
cairo_restore (cr);
|
||||
|
||||
|
|
@ -377,13 +382,13 @@ static gboolean
|
|||
gimp_circle_button_press_event (GtkWidget *widget,
|
||||
GdkEventButton *bevent)
|
||||
{
|
||||
GimpCircle *circle = GIMP_CIRCLE (widget);
|
||||
GimpCirclePrivate *priv = GET_PRIVATE (widget);
|
||||
|
||||
if (bevent->type == GDK_BUTTON_PRESS &&
|
||||
bevent->button == 1)
|
||||
{
|
||||
gtk_grab_add (widget);
|
||||
circle->priv->has_grab = TRUE;
|
||||
priv->has_grab = TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
|
|
@ -393,14 +398,15 @@ static gboolean
|
|||
gimp_circle_button_release_event (GtkWidget *widget,
|
||||
GdkEventButton *bevent)
|
||||
{
|
||||
GimpCircle *circle = GIMP_CIRCLE (widget);
|
||||
GimpCircle *circle = GIMP_CIRCLE (widget);
|
||||
GimpCirclePrivate *priv = GET_PRIVATE (widget);
|
||||
|
||||
if (bevent->button == 1)
|
||||
{
|
||||
gtk_grab_remove (widget);
|
||||
circle->priv->has_grab = FALSE;
|
||||
priv->has_grab = FALSE;
|
||||
|
||||
if (! circle->priv->in_widget)
|
||||
if (! priv->in_widget)
|
||||
GIMP_CIRCLE_GET_CLASS (circle)->reset_target (circle);
|
||||
}
|
||||
|
||||
|
|
@ -411,9 +417,9 @@ static gboolean
|
|||
gimp_circle_enter_notify_event (GtkWidget *widget,
|
||||
GdkEventCrossing *event)
|
||||
{
|
||||
GimpCircle *circle = GIMP_CIRCLE (widget);
|
||||
GimpCirclePrivate *priv = GET_PRIVATE (widget);
|
||||
|
||||
circle->priv->in_widget = TRUE;
|
||||
priv->in_widget = TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
|
@ -422,11 +428,12 @@ static gboolean
|
|||
gimp_circle_leave_notify_event (GtkWidget *widget,
|
||||
GdkEventCrossing *event)
|
||||
{
|
||||
GimpCircle *circle = GIMP_CIRCLE (widget);
|
||||
GimpCircle *circle = GIMP_CIRCLE (widget);
|
||||
GimpCirclePrivate *priv = GET_PRIVATE (widget);
|
||||
|
||||
circle->priv->in_widget = FALSE;
|
||||
priv->in_widget = FALSE;
|
||||
|
||||
if (! circle->priv->has_grab)
|
||||
if (! priv->has_grab)
|
||||
GIMP_CIRCLE_GET_CLASS (circle)->reset_target (circle);
|
||||
|
||||
return FALSE;
|
||||
|
|
@ -473,9 +480,11 @@ get_angle_and_distance (gdouble center_x,
|
|||
gboolean
|
||||
_gimp_circle_has_grab (GimpCircle *circle)
|
||||
{
|
||||
GimpCirclePrivate *priv = GET_PRIVATE (circle);
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_CIRCLE (circle), FALSE);
|
||||
|
||||
return circle->priv->has_grab;
|
||||
return priv->has_grab;
|
||||
}
|
||||
|
||||
gdouble
|
||||
|
|
@ -484,9 +493,10 @@ _gimp_circle_get_angle_and_distance (GimpCircle *circle,
|
|||
gdouble event_y,
|
||||
gdouble *distance)
|
||||
{
|
||||
GtkAllocation allocation;
|
||||
gdouble center_x;
|
||||
gdouble center_y;
|
||||
GimpCirclePrivate *priv = GET_PRIVATE (circle);
|
||||
GtkAllocation allocation;
|
||||
gdouble center_x;
|
||||
gdouble center_y;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_CIRCLE (circle), 0.0);
|
||||
|
||||
|
|
@ -495,7 +505,7 @@ _gimp_circle_get_angle_and_distance (GimpCircle *circle,
|
|||
center_x = allocation.width / 2.0;
|
||||
center_y = allocation.height / 2.0;
|
||||
|
||||
return get_angle_and_distance (center_x, center_y, circle->priv->size / 2.0,
|
||||
return get_angle_and_distance (center_x, center_y, priv->size / 2.0,
|
||||
event_x, event_y,
|
||||
distance);
|
||||
}
|
||||
|
|
@ -526,6 +536,8 @@ gimp_circle_draw_background (GimpCircle *circle,
|
|||
gint size,
|
||||
GimpCircleBackground background)
|
||||
{
|
||||
GimpCirclePrivate *priv = GET_PRIVATE (circle);
|
||||
|
||||
cairo_save (cr);
|
||||
|
||||
if (background == GIMP_CIRCLE_BACKGROUND_PLAIN)
|
||||
|
|
@ -542,17 +554,17 @@ gimp_circle_draw_background (GimpCircle *circle,
|
|||
}
|
||||
else
|
||||
{
|
||||
if (! circle->priv->surface)
|
||||
if (! priv->surface)
|
||||
{
|
||||
guchar *data;
|
||||
gint stride;
|
||||
gint x, y;
|
||||
|
||||
circle->priv->surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
|
||||
size, size);
|
||||
priv->surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
|
||||
size, size);
|
||||
|
||||
data = cairo_image_surface_get_data (circle->priv->surface);
|
||||
stride = cairo_image_surface_get_stride (circle->priv->surface);
|
||||
data = cairo_image_surface_get_data (priv->surface);
|
||||
stride = cairo_image_surface_get_stride (priv->surface);
|
||||
|
||||
for (y = 0; y < size; y++)
|
||||
{
|
||||
|
|
@ -582,10 +594,10 @@ gimp_circle_draw_background (GimpCircle *circle,
|
|||
}
|
||||
}
|
||||
|
||||
cairo_surface_mark_dirty (circle->priv->surface);
|
||||
cairo_surface_mark_dirty (priv->surface);
|
||||
}
|
||||
|
||||
cairo_set_source_surface (cr, circle->priv->surface, 0.0, 0.0);
|
||||
cairo_set_source_surface (cr, priv->surface, 0.0, 0.0);
|
||||
|
||||
cairo_arc (cr, size / 2.0, size / 2.0, size / 2.0, 0.0, 2 * G_PI);
|
||||
cairo_clip (cr);
|
||||
|
|
|
|||
|
|
@ -26,24 +26,13 @@
|
|||
#define __GIMP_CIRCLE_H__
|
||||
|
||||
|
||||
#define GIMP_TYPE_CIRCLE (gimp_circle_get_type ())
|
||||
#define GIMP_CIRCLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_CIRCLE, GimpCircle))
|
||||
#define GIMP_CIRCLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_CIRCLE, GimpCircleClass))
|
||||
#define GIMP_IS_CIRCLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, GIMP_TYPE_CIRCLE))
|
||||
#define GIMP_IS_CIRCLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_CIRCLE))
|
||||
#define GIMP_CIRCLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_CIRCLE, GimpCircleClass))
|
||||
#define GIMP_TYPE_CIRCLE (gimp_circle_get_type ())
|
||||
G_DECLARE_DERIVABLE_TYPE (GimpCircle,
|
||||
gimp_circle,
|
||||
GIMP, CIRCLE,
|
||||
GtkWidget)
|
||||
|
||||
|
||||
typedef struct _GimpCirclePrivate GimpCirclePrivate;
|
||||
typedef struct _GimpCircleClass GimpCircleClass;
|
||||
|
||||
struct _GimpCircle
|
||||
{
|
||||
GtkWidget parent_instance;
|
||||
|
||||
GimpCirclePrivate *priv;
|
||||
};
|
||||
|
||||
struct _GimpCircleClass
|
||||
{
|
||||
GtkWidgetClass parent_class;
|
||||
|
|
@ -52,15 +41,15 @@ struct _GimpCircleClass
|
|||
};
|
||||
|
||||
|
||||
GType gimp_circle_get_type (void) G_GNUC_CONST;
|
||||
GType gimp_circle_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GtkWidget * gimp_circle_new (void);
|
||||
GtkWidget * gimp_circle_new (void);
|
||||
|
||||
gboolean _gimp_circle_has_grab (GimpCircle *circle);
|
||||
gdouble _gimp_circle_get_angle_and_distance (GimpCircle *circle,
|
||||
gdouble event_x,
|
||||
gdouble event_y,
|
||||
gdouble *distance);
|
||||
gboolean _gimp_circle_has_grab (GimpCircle *circle);
|
||||
gdouble _gimp_circle_get_angle_and_distance (GimpCircle *circle,
|
||||
gdouble event_x,
|
||||
gdouble event_y,
|
||||
gdouble *distance);
|
||||
|
||||
|
||||
#endif /* __GIMP_CIRCLE_H__ */
|
||||
|
|
|
|||
|
|
@ -63,6 +63,8 @@ typedef enum
|
|||
} DialTarget;
|
||||
|
||||
|
||||
typedef struct _GimpDialPrivate GimpDialPrivate;
|
||||
|
||||
struct _GimpDialPrivate
|
||||
{
|
||||
gdouble alpha;
|
||||
|
|
@ -75,6 +77,9 @@ struct _GimpDialPrivate
|
|||
gdouble last_angle;
|
||||
};
|
||||
|
||||
#define GET_PRIVATE(obj) \
|
||||
((GimpDialPrivate *) gimp_dial_get_instance_private ((GimpDial *) obj))
|
||||
|
||||
|
||||
static void gimp_dial_set_property (GObject *object,
|
||||
guint property_id,
|
||||
|
|
@ -170,7 +175,6 @@ gimp_dial_class_init (GimpDialClass *klass)
|
|||
static void
|
||||
gimp_dial_init (GimpDial *dial)
|
||||
{
|
||||
dial->priv = gimp_dial_get_instance_private (dial);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -179,33 +183,33 @@ gimp_dial_set_property (GObject *object,
|
|||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GimpDial *dial = GIMP_DIAL (object);
|
||||
GimpDialPrivate *priv = GET_PRIVATE (object);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_ALPHA:
|
||||
dial->priv->alpha = g_value_get_double (value);
|
||||
gtk_widget_queue_draw (GTK_WIDGET (dial));
|
||||
priv->alpha = g_value_get_double (value);
|
||||
gtk_widget_queue_draw (GTK_WIDGET (object));
|
||||
break;
|
||||
|
||||
case PROP_BETA:
|
||||
dial->priv->beta = g_value_get_double (value);
|
||||
gtk_widget_queue_draw (GTK_WIDGET (dial));
|
||||
priv->beta = g_value_get_double (value);
|
||||
gtk_widget_queue_draw (GTK_WIDGET (object));
|
||||
break;
|
||||
|
||||
case PROP_CLOCKWISE_ANGLES:
|
||||
dial->priv->clockwise_angles = g_value_get_boolean (value);
|
||||
gtk_widget_queue_draw (GTK_WIDGET (dial));
|
||||
priv->clockwise_angles = g_value_get_boolean (value);
|
||||
gtk_widget_queue_draw (GTK_WIDGET (object));
|
||||
break;
|
||||
|
||||
case PROP_CLOCKWISE_DELTA:
|
||||
dial->priv->clockwise_delta = g_value_get_boolean (value);
|
||||
gtk_widget_queue_draw (GTK_WIDGET (dial));
|
||||
priv->clockwise_delta = g_value_get_boolean (value);
|
||||
gtk_widget_queue_draw (GTK_WIDGET (object));
|
||||
break;
|
||||
|
||||
case PROP_DRAW_BETA:
|
||||
dial->priv->draw_beta = g_value_get_boolean (value);
|
||||
gtk_widget_queue_draw (GTK_WIDGET (dial));
|
||||
priv->draw_beta = g_value_get_boolean (value);
|
||||
gtk_widget_queue_draw (GTK_WIDGET (object));
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
@ -220,28 +224,28 @@ gimp_dial_get_property (GObject *object,
|
|||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GimpDial *dial = GIMP_DIAL (object);
|
||||
GimpDialPrivate *priv = GET_PRIVATE (object);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_ALPHA:
|
||||
g_value_set_double (value, dial->priv->alpha);
|
||||
g_value_set_double (value, priv->alpha);
|
||||
break;
|
||||
|
||||
case PROP_BETA:
|
||||
g_value_set_double (value, dial->priv->beta);
|
||||
g_value_set_double (value, priv->beta);
|
||||
break;
|
||||
|
||||
case PROP_CLOCKWISE_ANGLES:
|
||||
g_value_set_boolean (value, dial->priv->clockwise_angles);
|
||||
g_value_set_boolean (value, priv->clockwise_angles);
|
||||
break;
|
||||
|
||||
case PROP_CLOCKWISE_DELTA:
|
||||
g_value_set_boolean (value, dial->priv->clockwise_delta);
|
||||
g_value_set_boolean (value, priv->clockwise_delta);
|
||||
break;
|
||||
|
||||
case PROP_DRAW_BETA:
|
||||
g_value_set_boolean (value, dial->priv->draw_beta);
|
||||
g_value_set_boolean (value, priv->draw_beta);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
@ -254,11 +258,11 @@ static gboolean
|
|||
gimp_dial_draw (GtkWidget *widget,
|
||||
cairo_t *cr)
|
||||
{
|
||||
GimpDial *dial = GIMP_DIAL (widget);
|
||||
GtkAllocation allocation;
|
||||
gint size;
|
||||
gdouble alpha = dial->priv->alpha;
|
||||
gdouble beta = dial->priv->beta;
|
||||
GimpDialPrivate *priv = GET_PRIVATE (widget);
|
||||
GtkAllocation allocation;
|
||||
gint size;
|
||||
gdouble alpha = priv->alpha;
|
||||
gdouble beta = priv->beta;
|
||||
|
||||
GTK_WIDGET_CLASS (parent_class)->draw (widget, cr);
|
||||
|
||||
|
|
@ -268,7 +272,7 @@ gimp_dial_draw (GtkWidget *widget,
|
|||
|
||||
gtk_widget_get_allocation (widget, &allocation);
|
||||
|
||||
if (dial->priv->clockwise_angles)
|
||||
if (priv->clockwise_angles)
|
||||
{
|
||||
alpha = -alpha;
|
||||
beta = -beta;
|
||||
|
|
@ -282,9 +286,9 @@ gimp_dial_draw (GtkWidget *widget,
|
|||
|
||||
gimp_dial_draw_arrows (cr, size,
|
||||
alpha, beta,
|
||||
dial->priv->clockwise_delta,
|
||||
dial->priv->target,
|
||||
dial->priv->draw_beta);
|
||||
priv->clockwise_delta,
|
||||
priv->target,
|
||||
priv->draw_beta);
|
||||
|
||||
cairo_restore (cr);
|
||||
|
||||
|
|
@ -295,36 +299,36 @@ static gboolean
|
|||
gimp_dial_button_press_event (GtkWidget *widget,
|
||||
GdkEventButton *bevent)
|
||||
{
|
||||
GimpDial *dial = GIMP_DIAL (widget);
|
||||
GimpDialPrivate *priv = GET_PRIVATE (widget);
|
||||
|
||||
if (bevent->type == GDK_BUTTON_PRESS &&
|
||||
bevent->button == 1 &&
|
||||
dial->priv->target != DIAL_TARGET_NONE)
|
||||
priv->target != DIAL_TARGET_NONE)
|
||||
{
|
||||
gdouble angle;
|
||||
|
||||
GTK_WIDGET_CLASS (parent_class)->button_press_event (widget, bevent);
|
||||
|
||||
angle = _gimp_circle_get_angle_and_distance (GIMP_CIRCLE (dial),
|
||||
angle = _gimp_circle_get_angle_and_distance (GIMP_CIRCLE (widget),
|
||||
bevent->x, bevent->y,
|
||||
NULL);
|
||||
|
||||
if (dial->priv->clockwise_angles && angle)
|
||||
if (priv->clockwise_angles && angle)
|
||||
angle = 2.0 * G_PI - angle;
|
||||
|
||||
if (bevent->state & GDK_SHIFT_MASK)
|
||||
angle = SNAP (angle, G_PI / 12.0);
|
||||
|
||||
dial->priv->last_angle = angle;
|
||||
priv->last_angle = angle;
|
||||
|
||||
switch (dial->priv->target)
|
||||
switch (priv->target)
|
||||
{
|
||||
case DIAL_TARGET_ALPHA:
|
||||
g_object_set (dial, "alpha", angle, NULL);
|
||||
g_object_set (widget, "alpha", angle, NULL);
|
||||
break;
|
||||
|
||||
case DIAL_TARGET_BETA:
|
||||
g_object_set (dial, "beta", angle, NULL);
|
||||
g_object_set (widget, "beta", angle, NULL);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
@ -339,39 +343,39 @@ static gboolean
|
|||
gimp_dial_motion_notify_event (GtkWidget *widget,
|
||||
GdkEventMotion *mevent)
|
||||
{
|
||||
GimpDial *dial = GIMP_DIAL (widget);
|
||||
gdouble angle;
|
||||
gdouble distance;
|
||||
GimpDialPrivate *priv = GET_PRIVATE (widget);
|
||||
gdouble angle;
|
||||
gdouble distance;
|
||||
|
||||
angle = _gimp_circle_get_angle_and_distance (GIMP_CIRCLE (dial),
|
||||
angle = _gimp_circle_get_angle_and_distance (GIMP_CIRCLE (widget),
|
||||
mevent->x, mevent->y,
|
||||
&distance);
|
||||
|
||||
if (dial->priv->clockwise_angles && angle)
|
||||
if (priv->clockwise_angles && angle)
|
||||
angle = 2.0 * G_PI - angle;
|
||||
|
||||
if (_gimp_circle_has_grab (GIMP_CIRCLE (dial)))
|
||||
if (_gimp_circle_has_grab (GIMP_CIRCLE (widget)))
|
||||
{
|
||||
gdouble delta;
|
||||
|
||||
if (mevent->state & GDK_SHIFT_MASK)
|
||||
angle = SNAP (angle, G_PI / 12.0);
|
||||
|
||||
delta = angle - dial->priv->last_angle;
|
||||
dial->priv->last_angle = angle;
|
||||
delta = angle - priv->last_angle;
|
||||
priv->last_angle = angle;
|
||||
|
||||
if (delta != 0.0)
|
||||
{
|
||||
gdouble alpha = dial->priv->alpha;
|
||||
gdouble alpha = priv->alpha;
|
||||
|
||||
switch (dial->priv->target)
|
||||
switch (priv->target)
|
||||
{
|
||||
case DIAL_TARGET_ALPHA:
|
||||
g_object_set (dial, "alpha", angle, NULL);
|
||||
g_object_set (widget, "alpha", angle, NULL);
|
||||
break;
|
||||
|
||||
case DIAL_TARGET_BETA:
|
||||
g_object_set (dial, "beta", angle, NULL);
|
||||
g_object_set (widget, "beta", angle, NULL);
|
||||
break;
|
||||
|
||||
case DIAL_TARGET_BOTH:
|
||||
|
|
@ -379,9 +383,11 @@ gimp_dial_motion_notify_event (GtkWidget *widget,
|
|||
if (mevent->state & GDK_SHIFT_MASK)
|
||||
delta = SNAP (alpha + delta, G_PI / 12.0) - alpha;
|
||||
|
||||
g_object_set (dial,
|
||||
"alpha", gimp_dial_normalize_angle (dial->priv->alpha + delta),
|
||||
"beta", gimp_dial_normalize_angle (dial->priv->beta + delta),
|
||||
g_object_set (widget,
|
||||
"alpha",
|
||||
gimp_dial_normalize_angle (priv->alpha + delta),
|
||||
"beta",
|
||||
gimp_dial_normalize_angle (priv->beta + delta),
|
||||
NULL);
|
||||
break;
|
||||
|
||||
|
|
@ -396,10 +402,10 @@ gimp_dial_motion_notify_event (GtkWidget *widget,
|
|||
gdouble dist_alpha;
|
||||
gdouble dist_beta;
|
||||
|
||||
dist_alpha = gimp_dial_get_angle_distance (dial->priv->alpha, angle);
|
||||
dist_beta = gimp_dial_get_angle_distance (dial->priv->beta, angle);
|
||||
dist_alpha = gimp_dial_get_angle_distance (priv->alpha, angle);
|
||||
dist_beta = gimp_dial_get_angle_distance (priv->beta, angle);
|
||||
|
||||
if (dial->priv->draw_beta &&
|
||||
if (priv->draw_beta &&
|
||||
distance > SEGMENT_FRACTION &&
|
||||
MIN (dist_alpha, dist_beta) < G_PI / 12)
|
||||
{
|
||||
|
|
@ -417,7 +423,7 @@ gimp_dial_motion_notify_event (GtkWidget *widget,
|
|||
target = DIAL_TARGET_BOTH;
|
||||
}
|
||||
|
||||
gimp_dial_set_target (dial, target);
|
||||
gimp_dial_set_target (GIMP_DIAL (widget), target);
|
||||
}
|
||||
|
||||
gdk_event_request_motions (mevent);
|
||||
|
|
@ -447,9 +453,11 @@ static void
|
|||
gimp_dial_set_target (GimpDial *dial,
|
||||
DialTarget target)
|
||||
{
|
||||
if (target != dial->priv->target)
|
||||
GimpDialPrivate *priv = GET_PRIVATE (dial);
|
||||
|
||||
if (target != priv->target)
|
||||
{
|
||||
dial->priv->target = target;
|
||||
priv->target = target;
|
||||
gtk_widget_queue_draw (GTK_WIDGET (dial));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,33 +29,22 @@
|
|||
#include "gimpcircle.h"
|
||||
|
||||
|
||||
#define GIMP_TYPE_DIAL (gimp_dial_get_type ())
|
||||
#define GIMP_DIAL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_DIAL, GimpDial))
|
||||
#define GIMP_DIAL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_DIAL, GimpDialClass))
|
||||
#define GIMP_IS_DIAL(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, GIMP_TYPE_DIAL))
|
||||
#define GIMP_IS_DIAL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_DIAL))
|
||||
#define GIMP_DIAL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_DIAL, GimpDialClass))
|
||||
#define GIMP_TYPE_DIAL (gimp_dial_get_type ())
|
||||
G_DECLARE_DERIVABLE_TYPE (GimpDial,
|
||||
gimp_dial,
|
||||
GIMP, DIAL,
|
||||
GimpCircle)
|
||||
|
||||
|
||||
typedef struct _GimpDialPrivate GimpDialPrivate;
|
||||
typedef struct _GimpDialClass GimpDialClass;
|
||||
|
||||
struct _GimpDial
|
||||
{
|
||||
GimpCircle parent_instance;
|
||||
|
||||
GimpDialPrivate *priv;
|
||||
};
|
||||
|
||||
struct _GimpDialClass
|
||||
{
|
||||
GimpCircleClass parent_class;
|
||||
};
|
||||
|
||||
|
||||
GType gimp_dial_get_type (void) G_GNUC_CONST;
|
||||
GType gimp_dial_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GtkWidget * gimp_dial_new (void);
|
||||
GtkWidget * gimp_dial_new (void);
|
||||
|
||||
|
||||
#endif /* __GIMP_DIAL_H__ */
|
||||
|
|
|
|||
|
|
@ -55,6 +55,8 @@ typedef enum
|
|||
} PolarTarget;
|
||||
|
||||
|
||||
typedef struct _GimpPolarPrivate GimpPolarPrivate;
|
||||
|
||||
struct _GimpPolarPrivate
|
||||
{
|
||||
gdouble angle;
|
||||
|
|
@ -63,6 +65,9 @@ struct _GimpPolarPrivate
|
|||
PolarTarget target;
|
||||
};
|
||||
|
||||
#define GET_PRIVATE(obj) \
|
||||
((GimpPolarPrivate *) gimp_polar_get_instance_private ((GimpPolar *) obj))
|
||||
|
||||
|
||||
static void gimp_polar_set_property (GObject *object,
|
||||
guint property_id,
|
||||
|
|
@ -135,7 +140,6 @@ gimp_polar_class_init (GimpPolarClass *klass)
|
|||
static void
|
||||
gimp_polar_init (GimpPolar *polar)
|
||||
{
|
||||
polar->priv = gimp_polar_get_instance_private (polar);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -144,18 +148,18 @@ gimp_polar_set_property (GObject *object,
|
|||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GimpPolar *polar = GIMP_POLAR (object);
|
||||
GimpPolarPrivate *priv = GET_PRIVATE (object);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_ANGLE:
|
||||
polar->priv->angle = g_value_get_double (value);
|
||||
gtk_widget_queue_draw (GTK_WIDGET (polar));
|
||||
priv->angle = g_value_get_double (value);
|
||||
gtk_widget_queue_draw (GTK_WIDGET (object));
|
||||
break;
|
||||
|
||||
case PROP_RADIUS:
|
||||
polar->priv->radius = g_value_get_double (value);
|
||||
gtk_widget_queue_draw (GTK_WIDGET (polar));
|
||||
priv->radius = g_value_get_double (value);
|
||||
gtk_widget_queue_draw (GTK_WIDGET (object));
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
@ -170,16 +174,16 @@ gimp_polar_get_property (GObject *object,
|
|||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GimpPolar *polar = GIMP_POLAR (object);
|
||||
GimpPolarPrivate *priv = GET_PRIVATE (object);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_ANGLE:
|
||||
g_value_set_double (value, polar->priv->angle);
|
||||
g_value_set_double (value, priv->angle);
|
||||
break;
|
||||
|
||||
case PROP_RADIUS:
|
||||
g_value_set_double (value, polar->priv->radius);
|
||||
g_value_set_double (value, priv->radius);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
@ -192,9 +196,9 @@ static gboolean
|
|||
gimp_polar_draw (GtkWidget *widget,
|
||||
cairo_t *cr)
|
||||
{
|
||||
GimpPolar *polar = GIMP_POLAR (widget);
|
||||
GtkAllocation allocation;
|
||||
gint size;
|
||||
GimpPolarPrivate *priv = GET_PRIVATE (widget);
|
||||
GtkAllocation allocation;
|
||||
gint size;
|
||||
|
||||
GTK_WIDGET_CLASS (parent_class)->draw (widget, cr);
|
||||
|
||||
|
|
@ -211,8 +215,8 @@ gimp_polar_draw (GtkWidget *widget,
|
|||
(allocation.height - size) / 2.0);
|
||||
|
||||
gimp_polar_draw_circle (cr, size,
|
||||
polar->priv->angle, polar->priv->radius,
|
||||
polar->priv->target);
|
||||
priv->angle, priv->radius,
|
||||
priv->target);
|
||||
|
||||
cairo_restore (cr);
|
||||
|
||||
|
|
@ -223,18 +227,18 @@ static gboolean
|
|||
gimp_polar_button_press_event (GtkWidget *widget,
|
||||
GdkEventButton *bevent)
|
||||
{
|
||||
GimpPolar *polar = GIMP_POLAR (widget);
|
||||
GimpPolarPrivate *priv = GET_PRIVATE (widget);
|
||||
|
||||
if (bevent->type == GDK_BUTTON_PRESS &&
|
||||
bevent->button == 1 &&
|
||||
polar->priv->target != POLAR_TARGET_NONE)
|
||||
priv->target != POLAR_TARGET_NONE)
|
||||
{
|
||||
gdouble angle;
|
||||
gdouble radius;
|
||||
|
||||
GTK_WIDGET_CLASS (parent_class)->button_press_event (widget, bevent);
|
||||
|
||||
angle = _gimp_circle_get_angle_and_distance (GIMP_CIRCLE (polar),
|
||||
angle = _gimp_circle_get_angle_and_distance (GIMP_CIRCLE (widget),
|
||||
bevent->x, bevent->y,
|
||||
&radius);
|
||||
if (bevent->state & GDK_SHIFT_MASK)
|
||||
|
|
@ -242,7 +246,7 @@ gimp_polar_button_press_event (GtkWidget *widget,
|
|||
|
||||
radius = MIN (radius, 1.0);
|
||||
|
||||
g_object_set (polar,
|
||||
g_object_set (widget,
|
||||
"angle", angle,
|
||||
"radius", radius,
|
||||
NULL);
|
||||
|
|
@ -255,22 +259,22 @@ static gboolean
|
|||
gimp_polar_motion_notify_event (GtkWidget *widget,
|
||||
GdkEventMotion *mevent)
|
||||
{
|
||||
GimpPolar *polar = GIMP_POLAR (widget);
|
||||
gdouble angle;
|
||||
gdouble radius;
|
||||
GimpPolarPrivate *priv = GET_PRIVATE (widget);
|
||||
gdouble angle;
|
||||
gdouble radius;
|
||||
|
||||
angle = _gimp_circle_get_angle_and_distance (GIMP_CIRCLE (polar),
|
||||
angle = _gimp_circle_get_angle_and_distance (GIMP_CIRCLE (widget),
|
||||
mevent->x, mevent->y,
|
||||
&radius);
|
||||
|
||||
if (_gimp_circle_has_grab (GIMP_CIRCLE (polar)))
|
||||
if (_gimp_circle_has_grab (GIMP_CIRCLE (widget)))
|
||||
{
|
||||
radius = MIN (radius, 1.0);
|
||||
|
||||
if (mevent->state & GDK_SHIFT_MASK)
|
||||
angle = SNAP (angle, G_PI / 12.0);
|
||||
|
||||
g_object_set (polar,
|
||||
g_object_set (widget,
|
||||
"angle", angle,
|
||||
"radius", radius,
|
||||
NULL);
|
||||
|
|
@ -281,10 +285,10 @@ gimp_polar_motion_notify_event (GtkWidget *widget,
|
|||
gdouble dist_angle;
|
||||
gdouble dist_radius;
|
||||
|
||||
dist_angle = gimp_polar_get_angle_distance (polar->priv->angle, angle);
|
||||
dist_radius = ABS (polar->priv->radius - radius);
|
||||
dist_angle = gimp_polar_get_angle_distance (priv->angle, angle);
|
||||
dist_radius = ABS (priv->radius - radius);
|
||||
|
||||
if ((radius < 0.2 && polar->priv->radius < 0.2) ||
|
||||
if ((radius < 0.2 && priv->radius < 0.2) ||
|
||||
(dist_angle < (G_PI / 12) && dist_radius < 0.2))
|
||||
{
|
||||
target = POLAR_TARGET_CIRCLE;
|
||||
|
|
@ -294,7 +298,7 @@ gimp_polar_motion_notify_event (GtkWidget *widget,
|
|||
target = POLAR_TARGET_NONE;
|
||||
}
|
||||
|
||||
gimp_polar_set_target (polar, target);
|
||||
gimp_polar_set_target (GIMP_POLAR (widget), target);
|
||||
}
|
||||
|
||||
gdk_event_request_motions (mevent);
|
||||
|
|
@ -324,9 +328,11 @@ static void
|
|||
gimp_polar_set_target (GimpPolar *polar,
|
||||
PolarTarget target)
|
||||
{
|
||||
if (target != polar->priv->target)
|
||||
GimpPolarPrivate *priv = GET_PRIVATE (polar);
|
||||
|
||||
if (target != priv->target)
|
||||
{
|
||||
polar->priv->target = target;
|
||||
priv->target = target;
|
||||
gtk_widget_queue_draw (GTK_WIDGET (polar));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,24 +29,13 @@
|
|||
#include "gimpcircle.h"
|
||||
|
||||
|
||||
#define GIMP_TYPE_POLAR (gimp_polar_get_type ())
|
||||
#define GIMP_POLAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_POLAR, GimpPolar))
|
||||
#define GIMP_POLAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_POLAR, GimpPolarClass))
|
||||
#define GIMP_IS_POLAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, GIMP_TYPE_POLAR))
|
||||
#define GIMP_IS_POLAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_POLAR))
|
||||
#define GIMP_POLAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_POLAR, GimpPolarClass))
|
||||
#define GIMP_TYPE_POLAR (gimp_polar_get_type ())
|
||||
G_DECLARE_DERIVABLE_TYPE (GimpPolar,
|
||||
gimp_polar,
|
||||
GIMP, POLAR,
|
||||
GimpCircle)
|
||||
|
||||
|
||||
typedef struct _GimpPolarPrivate GimpPolarPrivate;
|
||||
typedef struct _GimpPolarClass GimpPolarClass;
|
||||
|
||||
struct _GimpPolar
|
||||
{
|
||||
GimpCircle parent_instance;
|
||||
|
||||
GimpPolarPrivate *priv;
|
||||
};
|
||||
|
||||
struct _GimpPolarClass
|
||||
{
|
||||
GimpCircleClass parent_class;
|
||||
|
|
|
|||
Loading…
Reference in a new issue