2002-02-25 01:47:44 +00:00
|
|
|
|
1998-03-23 06:36:09 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
1998-04-13 02:02:47 +00:00
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
1998-03-23 06:36:09 +00:00
|
|
|
*/
|
|
|
|
#include <math.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <gtk/gtkmain.h>
|
|
|
|
#include <gtk/gtksignal.h>
|
|
|
|
|
|
|
|
#include "gtkdial.h"
|
|
|
|
|
|
|
|
#define SCROLL_DELAY_LENGTH 300
|
|
|
|
#define DIAL_DEFAULT_SIZE 100
|
|
|
|
|
1998-12-10 17:31:04 +00:00
|
|
|
/* Forward declarations */
|
1998-03-23 06:36:09 +00:00
|
|
|
|
2002-02-25 01:47:44 +00:00
|
|
|
static void gtk_dial_class_init (GtkDialClass *klass);
|
|
|
|
static void gtk_dial_init (GtkDial *dial);
|
|
|
|
static void gtk_dial_destroy (GtkObject *object);
|
|
|
|
static void gtk_dial_realize (GtkWidget *widget);
|
1998-03-23 06:36:09 +00:00
|
|
|
static void gtk_dial_size_request (GtkWidget *widget,
|
|
|
|
GtkRequisition *requisition);
|
2002-02-25 01:47:44 +00:00
|
|
|
static void gtk_dial_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation);
|
|
|
|
static gint gtk_dial_expose (GtkWidget *widget,
|
|
|
|
GdkEventExpose *event);
|
|
|
|
static gint gtk_dial_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *event);
|
|
|
|
static gint gtk_dial_button_release (GtkWidget *widget,
|
|
|
|
GdkEventButton *event);
|
|
|
|
static gint gtk_dial_motion_notify (GtkWidget *widget,
|
|
|
|
GdkEventMotion *event);
|
|
|
|
static gint gtk_dial_timer (GtkDial *dial);
|
1998-03-23 06:36:09 +00:00
|
|
|
|
|
|
|
static void gtk_dial_update_mouse (GtkDial *dial, gint x, gint y);
|
|
|
|
static void gtk_dial_update (GtkDial *dial);
|
2002-02-25 01:47:44 +00:00
|
|
|
static void gtk_dial_adjustment_changed (GtkAdjustment *adjustment,
|
|
|
|
gpointer data);
|
|
|
|
static void gtk_dial_adjustment_value_changed (GtkAdjustment *adjustment,
|
|
|
|
gpointer data);
|
1998-03-23 06:36:09 +00:00
|
|
|
|
|
|
|
/* Local data */
|
|
|
|
|
|
|
|
static GtkWidgetClass *parent_class = NULL;
|
|
|
|
|
2002-02-16 23:52:30 +00:00
|
|
|
GType
|
1998-03-23 06:36:09 +00:00
|
|
|
gtk_dial_get_type ()
|
|
|
|
{
|
2002-02-16 23:52:30 +00:00
|
|
|
static GType dial_type = 0;
|
1998-03-23 06:36:09 +00:00
|
|
|
|
|
|
|
if (!dial_type)
|
|
|
|
{
|
2002-02-16 23:52:30 +00:00
|
|
|
static const GTypeInfo dial_info =
|
1998-03-23 06:36:09 +00:00
|
|
|
{
|
|
|
|
sizeof (GtkDialClass),
|
2002-02-16 23:52:30 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc) gtk_dial_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof (GtkDial),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc) gtk_dial_init,
|
1998-03-23 06:36:09 +00:00
|
|
|
};
|
|
|
|
|
2002-02-16 23:52:30 +00:00
|
|
|
dial_type = g_type_register_static (GTK_TYPE_WIDGET, "GtkDial", &dial_info, 0);
|
1998-03-23 06:36:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return dial_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_dial_class_init (GtkDialClass *class)
|
|
|
|
{
|
|
|
|
GtkObjectClass *object_class;
|
|
|
|
GtkWidgetClass *widget_class;
|
|
|
|
|
|
|
|
object_class = (GtkObjectClass*) class;
|
|
|
|
widget_class = (GtkWidgetClass*) class;
|
|
|
|
|
|
|
|
parent_class = gtk_type_class (gtk_widget_get_type ());
|
|
|
|
|
|
|
|
object_class->destroy = gtk_dial_destroy;
|
|
|
|
|
|
|
|
widget_class->realize = gtk_dial_realize;
|
|
|
|
widget_class->expose_event = gtk_dial_expose;
|
|
|
|
widget_class->size_request = gtk_dial_size_request;
|
|
|
|
widget_class->size_allocate = gtk_dial_size_allocate;
|
|
|
|
widget_class->button_press_event = gtk_dial_button_press;
|
|
|
|
widget_class->button_release_event = gtk_dial_button_release;
|
|
|
|
widget_class->motion_notify_event = gtk_dial_motion_notify;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_dial_init (GtkDial *dial)
|
|
|
|
{
|
|
|
|
dial->button = 0;
|
|
|
|
dial->policy = GTK_UPDATE_CONTINUOUS;
|
|
|
|
dial->timer = 0;
|
|
|
|
dial->radius = 0;
|
|
|
|
dial->pointer_width = 0;
|
|
|
|
dial->angle = 0.0;
|
|
|
|
dial->old_value = 0.0;
|
|
|
|
dial->old_lower = 0.0;
|
|
|
|
dial->old_upper = 0.0;
|
|
|
|
dial->adjustment = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget*
|
|
|
|
gtk_dial_new (GtkAdjustment *adjustment)
|
|
|
|
{
|
|
|
|
GtkDial *dial;
|
|
|
|
|
2002-02-16 23:52:30 +00:00
|
|
|
dial = g_object_new (gtk_dial_get_type (), NULL);
|
1998-03-23 06:36:09 +00:00
|
|
|
|
|
|
|
if (!adjustment)
|
|
|
|
adjustment = (GtkAdjustment*) gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
|
|
|
|
|
|
|
|
gtk_dial_set_adjustment (dial, adjustment);
|
|
|
|
|
|
|
|
return GTK_WIDGET (dial);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_dial_destroy (GtkObject *object)
|
|
|
|
{
|
|
|
|
GtkDial *dial;
|
|
|
|
|
2002-02-25 01:47:44 +00:00
|
|
|
g_return_if_fail (object != NULL);
|
1998-03-23 06:36:09 +00:00
|
|
|
g_return_if_fail (GTK_IS_DIAL (object));
|
|
|
|
|
|
|
|
dial = GTK_DIAL (object);
|
|
|
|
|
2003-01-23 21:07:42 +00:00
|
|
|
if (dial->adjustment)
|
2002-10-11 20:36:21 +00:00
|
|
|
{
|
|
|
|
g_object_unref (GTK_OBJECT (dial->adjustment));
|
|
|
|
dial->adjustment = NULL;
|
|
|
|
}
|
1998-03-23 06:36:09 +00:00
|
|
|
|
|
|
|
if (GTK_OBJECT_CLASS (parent_class)->destroy)
|
|
|
|
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkAdjustment*
|
|
|
|
gtk_dial_get_adjustment (GtkDial *dial)
|
|
|
|
{
|
2002-02-25 01:47:44 +00:00
|
|
|
g_return_val_if_fail (dial != NULL, NULL);
|
1998-03-23 06:36:09 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_DIAL (dial), NULL);
|
|
|
|
|
|
|
|
return dial->adjustment;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_dial_set_update_policy (GtkDial *dial,
|
|
|
|
GtkUpdateType policy)
|
|
|
|
{
|
2002-02-25 01:47:44 +00:00
|
|
|
g_return_if_fail (dial != NULL);
|
1998-03-23 06:36:09 +00:00
|
|
|
g_return_if_fail (GTK_IS_DIAL (dial));
|
|
|
|
|
|
|
|
dial->policy = policy;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_dial_set_adjustment (GtkDial *dial,
|
|
|
|
GtkAdjustment *adjustment)
|
|
|
|
{
|
2002-02-25 01:47:44 +00:00
|
|
|
g_return_if_fail (dial != NULL);
|
1998-03-23 06:36:09 +00:00
|
|
|
g_return_if_fail (GTK_IS_DIAL (dial));
|
|
|
|
|
|
|
|
if (dial->adjustment)
|
|
|
|
{
|
2002-02-25 01:47:44 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (GTK_OBJECT (dial->adjustment), NULL, (gpointer) dial);
|
|
|
|
g_object_unref (GTK_OBJECT (dial->adjustment));
|
1998-03-23 06:36:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dial->adjustment = adjustment;
|
2002-02-25 01:47:44 +00:00
|
|
|
g_object_ref (GTK_OBJECT (dial->adjustment));
|
1998-03-23 06:36:09 +00:00
|
|
|
|
2002-02-25 01:47:44 +00:00
|
|
|
g_signal_connect (GTK_OBJECT (adjustment), "changed",
|
|
|
|
GTK_SIGNAL_FUNC (gtk_dial_adjustment_changed),
|
|
|
|
(gpointer) dial);
|
|
|
|
g_signal_connect (GTK_OBJECT (adjustment), "value_changed",
|
|
|
|
GTK_SIGNAL_FUNC (gtk_dial_adjustment_value_changed),
|
|
|
|
(gpointer) dial);
|
1998-03-23 06:36:09 +00:00
|
|
|
|
|
|
|
dial->old_value = adjustment->value;
|
|
|
|
dial->old_lower = adjustment->lower;
|
|
|
|
dial->old_upper = adjustment->upper;
|
|
|
|
|
|
|
|
gtk_dial_update (dial);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_dial_realize (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkDial *dial;
|
|
|
|
GdkWindowAttr attributes;
|
|
|
|
gint attributes_mask;
|
|
|
|
|
2002-02-25 01:47:44 +00:00
|
|
|
g_return_if_fail (widget != NULL);
|
1998-03-23 06:36:09 +00:00
|
|
|
g_return_if_fail (GTK_IS_DIAL (widget));
|
|
|
|
|
|
|
|
GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
|
|
|
|
dial = GTK_DIAL (widget);
|
|
|
|
|
|
|
|
attributes.x = widget->allocation.x;
|
|
|
|
attributes.y = widget->allocation.y;
|
|
|
|
attributes.width = widget->allocation.width;
|
|
|
|
attributes.height = widget->allocation.height;
|
|
|
|
attributes.wclass = GDK_INPUT_OUTPUT;
|
|
|
|
attributes.window_type = GDK_WINDOW_CHILD;
|
|
|
|
attributes.event_mask = gtk_widget_get_events (widget) |
|
|
|
|
GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK |
|
|
|
|
GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK |
|
|
|
|
GDK_POINTER_MOTION_HINT_MASK;
|
|
|
|
attributes.visual = gtk_widget_get_visual (widget);
|
|
|
|
attributes.colormap = gtk_widget_get_colormap (widget);
|
|
|
|
|
|
|
|
attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
|
|
|
|
widget->window = gdk_window_new (widget->parent->window, &attributes, attributes_mask);
|
|
|
|
|
|
|
|
widget->style = gtk_style_attach (widget->style, widget->window);
|
|
|
|
|
|
|
|
gdk_window_set_user_data (widget->window, widget);
|
|
|
|
|
|
|
|
gtk_style_set_background (widget->style, widget->window, GTK_STATE_ACTIVE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_dial_size_request (GtkWidget *widget,
|
|
|
|
GtkRequisition *requisition)
|
|
|
|
{
|
|
|
|
requisition->width = DIAL_DEFAULT_SIZE;
|
|
|
|
requisition->height = DIAL_DEFAULT_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_dial_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation)
|
|
|
|
{
|
|
|
|
GtkDial *dial;
|
|
|
|
|
2002-02-25 01:47:44 +00:00
|
|
|
g_return_if_fail (widget != NULL);
|
1998-03-23 06:36:09 +00:00
|
|
|
g_return_if_fail (GTK_IS_DIAL (widget));
|
|
|
|
g_return_if_fail (allocation != NULL);
|
|
|
|
|
|
|
|
widget->allocation = *allocation;
|
1998-04-08 05:28:56 +00:00
|
|
|
dial = GTK_DIAL (widget);
|
|
|
|
|
1998-03-23 06:36:09 +00:00
|
|
|
if (GTK_WIDGET_REALIZED (widget))
|
|
|
|
{
|
|
|
|
|
|
|
|
gdk_window_move_resize (widget->window,
|
|
|
|
allocation->x, allocation->y,
|
|
|
|
allocation->width, allocation->height);
|
|
|
|
|
|
|
|
}
|
2002-02-19 01:25:26 +00:00
|
|
|
dial->radius = MIN (allocation->width, allocation->height) * 0.45;
|
1998-04-08 05:28:56 +00:00
|
|
|
dial->pointer_width = dial->radius / 5;
|
1998-03-23 06:36:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
gtk_dial_expose (GtkWidget *widget,
|
|
|
|
GdkEventExpose *event)
|
|
|
|
{
|
|
|
|
GtkDial *dial;
|
1999-11-13 23:06:46 +00:00
|
|
|
GdkPoint points[6];
|
1998-03-23 06:36:09 +00:00
|
|
|
gdouble s,c;
|
1999-11-13 23:06:46 +00:00
|
|
|
gdouble theta, last, increment;
|
|
|
|
GtkStyle *blankstyle;
|
1998-03-23 06:36:09 +00:00
|
|
|
gint xc, yc;
|
1999-11-13 23:06:46 +00:00
|
|
|
gint upper, lower;
|
1998-03-23 06:36:09 +00:00
|
|
|
gint tick_length;
|
1999-11-13 23:06:46 +00:00
|
|
|
gint i, inc;
|
1998-03-23 06:36:09 +00:00
|
|
|
|
2002-02-25 01:47:44 +00:00
|
|
|
g_return_val_if_fail (widget != NULL, FALSE);
|
1998-03-23 06:36:09 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_DIAL (widget), FALSE);
|
|
|
|
g_return_val_if_fail (event != NULL, FALSE);
|
|
|
|
|
|
|
|
if (event->count > 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
dial = GTK_DIAL (widget);
|
|
|
|
|
1999-11-13 23:06:46 +00:00
|
|
|
/* gdk_window_clear_area (widget->window,
|
1998-03-23 06:36:09 +00:00
|
|
|
0, 0,
|
|
|
|
widget->allocation.width,
|
|
|
|
widget->allocation.height);
|
1999-11-13 23:06:46 +00:00
|
|
|
*/
|
2002-02-19 01:25:26 +00:00
|
|
|
xc = widget->allocation.width / 2;
|
|
|
|
yc = widget->allocation.height / 2;
|
1998-03-23 06:36:09 +00:00
|
|
|
|
1999-11-13 23:06:46 +00:00
|
|
|
upper = dial->adjustment->upper;
|
|
|
|
lower = dial->adjustment->lower;
|
|
|
|
|
|
|
|
/* Erase old pointer */
|
|
|
|
|
2002-02-19 01:25:26 +00:00
|
|
|
s = sin (dial->last_angle);
|
|
|
|
c = cos (dial->last_angle);
|
1999-11-13 23:06:46 +00:00
|
|
|
dial->last_angle = dial->angle;
|
|
|
|
|
|
|
|
points[0].x = xc + s*dial->pointer_width/2;
|
|
|
|
points[0].y = yc + c*dial->pointer_width/2;
|
|
|
|
points[1].x = xc + c*dial->radius;
|
|
|
|
points[1].y = yc - s*dial->radius;
|
|
|
|
points[2].x = xc - s*dial->pointer_width/2;
|
|
|
|
points[2].y = yc - c*dial->pointer_width/2;
|
|
|
|
points[3].x = xc - c*dial->radius/10;
|
|
|
|
points[3].y = yc + s*dial->radius/10;
|
|
|
|
points[4].x = points[0].x;
|
|
|
|
points[4].y = points[0].y;
|
|
|
|
|
|
|
|
blankstyle = gtk_style_new ();
|
|
|
|
blankstyle->bg_gc[GTK_STATE_NORMAL] =
|
|
|
|
widget->style->bg_gc[GTK_STATE_NORMAL];
|
|
|
|
blankstyle->dark_gc[GTK_STATE_NORMAL] =
|
|
|
|
widget->style->bg_gc[GTK_STATE_NORMAL];
|
|
|
|
blankstyle->light_gc[GTK_STATE_NORMAL] =
|
|
|
|
widget->style->bg_gc[GTK_STATE_NORMAL];
|
|
|
|
blankstyle->black_gc =
|
|
|
|
widget->style->bg_gc[GTK_STATE_NORMAL];
|
|
|
|
|
2002-02-16 23:52:30 +00:00
|
|
|
gtk_paint_polygon (blankstyle,
|
1999-11-13 23:06:46 +00:00
|
|
|
widget->window,
|
|
|
|
GTK_STATE_NORMAL,
|
|
|
|
GTK_SHADOW_OUT,
|
2002-02-16 23:52:30 +00:00
|
|
|
NULL,
|
|
|
|
widget,
|
|
|
|
NULL,
|
1999-11-13 23:06:46 +00:00
|
|
|
points, 5,
|
|
|
|
FALSE);
|
|
|
|
|
2002-02-19 01:25:26 +00:00
|
|
|
g_object_unref (blankstyle);
|
1999-11-13 23:06:46 +00:00
|
|
|
|
|
|
|
|
1998-03-23 06:36:09 +00:00
|
|
|
/* Draw ticks */
|
|
|
|
|
1999-11-13 23:06:46 +00:00
|
|
|
if ((upper - lower) == 0)
|
2002-02-16 23:52:30 +00:00
|
|
|
return FALSE;
|
1999-11-13 23:06:46 +00:00
|
|
|
|
2003-01-23 21:07:42 +00:00
|
|
|
increment = (100*M_PI) / (dial->radius*dial->radius);
|
1999-11-13 23:06:46 +00:00
|
|
|
|
|
|
|
inc = (upper - lower);
|
|
|
|
|
2002-02-19 01:25:26 +00:00
|
|
|
while (inc < 100) inc *= 10;
|
|
|
|
while (inc >= 1000) inc /= 10;
|
1999-11-13 23:06:46 +00:00
|
|
|
last = -1;
|
|
|
|
|
2002-02-19 01:25:26 +00:00
|
|
|
for (i = 0; i <= inc; i++)
|
1998-03-23 06:36:09 +00:00
|
|
|
{
|
2003-01-23 21:07:42 +00:00
|
|
|
theta = ((gfloat)i*M_PI / (18*inc/24.) - M_PI/6.);
|
1999-11-13 23:06:46 +00:00
|
|
|
|
|
|
|
if ((theta - last) < (increment))
|
|
|
|
continue;
|
|
|
|
last = theta;
|
|
|
|
|
2002-02-19 01:25:26 +00:00
|
|
|
s = sin (theta);
|
|
|
|
c = cos (theta);
|
1998-03-23 06:36:09 +00:00
|
|
|
|
2002-02-19 01:25:26 +00:00
|
|
|
tick_length = (i%(inc/10) == 0) ? dial->pointer_width : dial->pointer_width / 2;
|
1999-11-13 23:06:46 +00:00
|
|
|
|
1998-03-23 06:36:09 +00:00
|
|
|
gdk_draw_line (widget->window,
|
1999-11-13 23:06:46 +00:00
|
|
|
widget->style->fg_gc[widget->state],
|
|
|
|
xc + c*(dial->radius - tick_length),
|
|
|
|
yc - s*(dial->radius - tick_length),
|
|
|
|
xc + c*dial->radius,
|
|
|
|
yc - s*dial->radius);
|
1998-03-23 06:36:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw pointer */
|
|
|
|
|
2002-02-19 01:25:26 +00:00
|
|
|
s = sin (dial->angle);
|
|
|
|
c = cos (dial->angle);
|
1999-11-13 23:06:46 +00:00
|
|
|
dial->last_angle = dial->angle;
|
1998-03-23 06:36:09 +00:00
|
|
|
|
|
|
|
points[0].x = xc + s*dial->pointer_width/2;
|
|
|
|
points[0].y = yc + c*dial->pointer_width/2;
|
|
|
|
points[1].x = xc + c*dial->radius;
|
|
|
|
points[1].y = yc - s*dial->radius;
|
|
|
|
points[2].x = xc - s*dial->pointer_width/2;
|
|
|
|
points[2].y = yc - c*dial->pointer_width/2;
|
1999-11-13 23:06:46 +00:00
|
|
|
points[3].x = xc - c*dial->radius/10;
|
|
|
|
points[3].y = yc + s*dial->radius/10;
|
|
|
|
points[4].x = points[0].x;
|
|
|
|
points[4].y = points[0].y;
|
|
|
|
|
1998-03-23 06:36:09 +00:00
|
|
|
|
2002-02-16 23:52:30 +00:00
|
|
|
gtk_paint_polygon (widget->style,
|
1998-03-23 06:36:09 +00:00
|
|
|
widget->window,
|
|
|
|
GTK_STATE_NORMAL,
|
|
|
|
GTK_SHADOW_OUT,
|
2002-02-16 23:52:30 +00:00
|
|
|
NULL,
|
|
|
|
widget,
|
|
|
|
NULL,
|
1999-11-13 23:06:46 +00:00
|
|
|
points, 5,
|
1998-03-23 06:36:09 +00:00
|
|
|
TRUE);
|
1999-11-13 23:06:46 +00:00
|
|
|
|
1998-03-23 06:36:09 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
gtk_dial_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *event)
|
|
|
|
{
|
|
|
|
GtkDial *dial;
|
|
|
|
gint dx, dy;
|
|
|
|
double s, c;
|
|
|
|
double d_parallel;
|
|
|
|
double d_perpendicular;
|
|
|
|
|
2002-02-25 01:47:44 +00:00
|
|
|
g_return_val_if_fail (widget != NULL, FALSE);
|
1998-03-23 06:36:09 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_DIAL (widget), FALSE);
|
|
|
|
g_return_val_if_fail (event != NULL, FALSE);
|
|
|
|
|
|
|
|
dial = GTK_DIAL (widget);
|
|
|
|
|
|
|
|
/* Determine if button press was within pointer region - we
|
|
|
|
do this by computing the parallel and perpendicular distance of
|
|
|
|
the point where the mouse was pressed from the line passing through
|
|
|
|
the pointer */
|
|
|
|
|
|
|
|
dx = event->x - widget->allocation.width / 2;
|
|
|
|
dy = widget->allocation.height / 2 - event->y;
|
|
|
|
|
2002-02-19 01:25:26 +00:00
|
|
|
s = sin (dial->angle);
|
|
|
|
c = cos (dial->angle);
|
1998-03-23 06:36:09 +00:00
|
|
|
|
|
|
|
d_parallel = s*dy + c*dx;
|
2002-02-19 01:25:26 +00:00
|
|
|
d_perpendicular = fabs (s*dx - c*dy);
|
1998-03-23 06:36:09 +00:00
|
|
|
|
|
|
|
if (!dial->button &&
|
|
|
|
(d_perpendicular < dial->pointer_width/2) &&
|
|
|
|
(d_parallel > - dial->pointer_width))
|
|
|
|
{
|
|
|
|
gtk_grab_add (widget);
|
|
|
|
|
|
|
|
dial->button = event->button;
|
|
|
|
|
|
|
|
gtk_dial_update_mouse (dial, event->x, event->y);
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
gtk_dial_button_release (GtkWidget *widget,
|
|
|
|
GdkEventButton *event)
|
|
|
|
{
|
|
|
|
GtkDial *dial;
|
|
|
|
|
2002-02-25 01:47:44 +00:00
|
|
|
g_return_val_if_fail (widget != NULL, FALSE);
|
1998-03-23 06:36:09 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_DIAL (widget), FALSE);
|
|
|
|
g_return_val_if_fail (event != NULL, FALSE);
|
|
|
|
|
|
|
|
dial = GTK_DIAL (widget);
|
|
|
|
|
|
|
|
if (dial->button == event->button)
|
|
|
|
{
|
|
|
|
gtk_grab_remove (widget);
|
|
|
|
|
|
|
|
dial->button = 0;
|
|
|
|
|
|
|
|
if (dial->policy == GTK_UPDATE_DELAYED)
|
|
|
|
gtk_timeout_remove (dial->timer);
|
|
|
|
|
|
|
|
if ((dial->policy != GTK_UPDATE_CONTINUOUS) &&
|
|
|
|
(dial->old_value != dial->adjustment->value))
|
2002-02-25 01:47:44 +00:00
|
|
|
g_signal_emit_by_name (GTK_OBJECT (dial->adjustment), "value_changed");
|
1998-03-23 06:36:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
gtk_dial_motion_notify (GtkWidget *widget,
|
|
|
|
GdkEventMotion *event)
|
|
|
|
{
|
|
|
|
GtkDial *dial;
|
|
|
|
GdkModifierType mods;
|
|
|
|
gint x, y, mask;
|
|
|
|
|
2002-02-25 01:47:44 +00:00
|
|
|
g_return_val_if_fail (widget != NULL, FALSE);
|
1998-03-23 06:36:09 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_DIAL (widget), FALSE);
|
|
|
|
g_return_val_if_fail (event != NULL, FALSE);
|
|
|
|
|
|
|
|
dial = GTK_DIAL (widget);
|
|
|
|
|
|
|
|
if (dial->button != 0)
|
|
|
|
{
|
|
|
|
x = event->x;
|
|
|
|
y = event->y;
|
|
|
|
|
|
|
|
if (event->is_hint || (event->window != widget->window))
|
|
|
|
gdk_window_get_pointer (widget->window, &x, &y, &mods);
|
|
|
|
|
|
|
|
switch (dial->button)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
mask = GDK_BUTTON1_MASK;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
mask = GDK_BUTTON2_MASK;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
mask = GDK_BUTTON3_MASK;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
mask = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mods & mask)
|
|
|
|
gtk_dial_update_mouse (dial, x,y);
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
gtk_dial_timer (GtkDial *dial)
|
|
|
|
{
|
2002-02-25 01:47:44 +00:00
|
|
|
g_return_val_if_fail (dial != NULL, FALSE);
|
1998-03-23 06:36:09 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_DIAL (dial), FALSE);
|
|
|
|
|
|
|
|
if (dial->policy == GTK_UPDATE_DELAYED)
|
2002-02-25 01:47:44 +00:00
|
|
|
g_signal_emit_by_name (GTK_OBJECT (dial->adjustment), "value_changed");
|
1998-03-23 06:36:09 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_dial_update_mouse (GtkDial *dial, gint x, gint y)
|
|
|
|
{
|
|
|
|
gint xc, yc;
|
2002-02-25 01:47:44 +00:00
|
|
|
gfloat old_value;
|
1998-03-23 06:36:09 +00:00
|
|
|
|
2002-02-25 01:47:44 +00:00
|
|
|
g_return_if_fail (dial != NULL);
|
1998-03-23 06:36:09 +00:00
|
|
|
g_return_if_fail (GTK_IS_DIAL (dial));
|
|
|
|
|
|
|
|
xc = GTK_WIDGET(dial)->allocation.width / 2;
|
|
|
|
yc = GTK_WIDGET(dial)->allocation.height / 2;
|
|
|
|
|
|
|
|
old_value = dial->adjustment->value;
|
|
|
|
dial->angle = atan2(yc-y, x-xc);
|
|
|
|
|
2003-01-23 21:07:42 +00:00
|
|
|
if (dial->angle < -M_PI/2.)
|
|
|
|
dial->angle += 2*M_PI;
|
1998-03-23 06:36:09 +00:00
|
|
|
|
2003-01-23 21:07:42 +00:00
|
|
|
if (dial->angle < -M_PI/6)
|
|
|
|
dial->angle = -M_PI/6;
|
1998-03-23 06:36:09 +00:00
|
|
|
|
2003-01-23 21:07:42 +00:00
|
|
|
if (dial->angle > 7.*M_PI/6.)
|
|
|
|
dial->angle = 7.*M_PI/6.;
|
1998-03-23 06:36:09 +00:00
|
|
|
|
2003-01-23 21:07:42 +00:00
|
|
|
dial->adjustment->value = dial->adjustment->lower + (7.*M_PI/6 - dial->angle) *
|
|
|
|
(dial->adjustment->upper - dial->adjustment->lower) / (4.*M_PI/3.);
|
1998-03-23 06:36:09 +00:00
|
|
|
|
|
|
|
if (dial->adjustment->value != old_value)
|
|
|
|
{
|
|
|
|
if (dial->policy == GTK_UPDATE_CONTINUOUS)
|
|
|
|
{
|
2002-02-25 01:47:44 +00:00
|
|
|
g_signal_emit_by_name (GTK_OBJECT (dial->adjustment), "value_changed");
|
1998-03-23 06:36:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-02-16 23:52:30 +00:00
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (dial));
|
1998-03-23 06:36:09 +00:00
|
|
|
|
|
|
|
if (dial->policy == GTK_UPDATE_DELAYED)
|
|
|
|
{
|
|
|
|
if (dial->timer)
|
|
|
|
gtk_timeout_remove (dial->timer);
|
|
|
|
|
|
|
|
dial->timer = gtk_timeout_add (SCROLL_DELAY_LENGTH,
|
|
|
|
(GtkFunction) gtk_dial_timer,
|
|
|
|
(gpointer) dial);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_dial_update (GtkDial *dial)
|
|
|
|
{
|
2002-02-25 01:47:44 +00:00
|
|
|
gfloat new_value;
|
1998-03-23 06:36:09 +00:00
|
|
|
|
2002-02-25 01:47:44 +00:00
|
|
|
g_return_if_fail (dial != NULL);
|
1998-03-23 06:36:09 +00:00
|
|
|
g_return_if_fail (GTK_IS_DIAL (dial));
|
|
|
|
|
|
|
|
new_value = dial->adjustment->value;
|
|
|
|
|
|
|
|
if (new_value < dial->adjustment->lower)
|
|
|
|
new_value = dial->adjustment->lower;
|
|
|
|
|
|
|
|
if (new_value > dial->adjustment->upper)
|
|
|
|
new_value = dial->adjustment->upper;
|
|
|
|
|
|
|
|
if (new_value != dial->adjustment->value)
|
|
|
|
{
|
2002-02-25 01:47:44 +00:00
|
|
|
dial->adjustment->value = new_value;
|
|
|
|
g_signal_emit_by_name (GTK_OBJECT (dial->adjustment), "value_changed");
|
1998-03-23 06:36:09 +00:00
|
|
|
}
|
|
|
|
|
2003-01-23 21:07:42 +00:00
|
|
|
dial->angle = 7.*M_PI/6. - (new_value - dial->adjustment->lower) * 4.*M_PI/3. /
|
1998-03-23 06:36:09 +00:00
|
|
|
(dial->adjustment->upper - dial->adjustment->lower);
|
|
|
|
|
2002-02-16 23:52:30 +00:00
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (dial));
|
1998-03-23 06:36:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_dial_adjustment_changed (GtkAdjustment *adjustment,
|
2002-02-25 01:47:44 +00:00
|
|
|
gpointer data)
|
1998-03-23 06:36:09 +00:00
|
|
|
{
|
|
|
|
GtkDial *dial;
|
|
|
|
|
|
|
|
g_return_if_fail (adjustment != NULL);
|
2002-02-25 01:47:44 +00:00
|
|
|
g_return_if_fail (data != NULL);
|
1998-03-23 06:36:09 +00:00
|
|
|
|
|
|
|
dial = GTK_DIAL (data);
|
|
|
|
|
|
|
|
if ((dial->old_value != adjustment->value) ||
|
|
|
|
(dial->old_lower != adjustment->lower) ||
|
|
|
|
(dial->old_upper != adjustment->upper))
|
|
|
|
{
|
|
|
|
gtk_dial_update (dial);
|
|
|
|
|
|
|
|
dial->old_value = adjustment->value;
|
|
|
|
dial->old_lower = adjustment->lower;
|
|
|
|
dial->old_upper = adjustment->upper;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_dial_adjustment_value_changed (GtkAdjustment *adjustment,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkDial *dial;
|
|
|
|
|
|
|
|
g_return_if_fail (adjustment != NULL);
|
2002-02-25 01:47:44 +00:00
|
|
|
g_return_if_fail (data != NULL);
|
1998-03-23 06:36:09 +00:00
|
|
|
|
|
|
|
dial = GTK_DIAL (data);
|
|
|
|
|
|
|
|
if (dial->old_value != adjustment->value)
|
|
|
|
{
|
|
|
|
gtk_dial_update (dial);
|
|
|
|
|
|
|
|
dial->old_value = adjustment->value;
|
|
|
|
}
|
|
|
|
}
|