gboolean
rcm_gray_motion_notify_event (GtkWidget      *widget,
			      GdkEventMotion *event,
			      RcmGray        *circle)
{
  gint        x, y;
  GdkGCValues values;

  values.function = GDK_INVERT;
  xor_gc = gdk_gc_new_with_values (Current.From->preview->window,
				   &values,
                                   GDK_GC_FUNCTION);

  if (circle->action_flag == DRAG_START)
    {
      GtkStyle *style = gtk_widget_get_style (circle->preview);

      gtk_widget_queue_draw (circle->preview);
      color_rotate_draw_large_circle (circle->preview->window,
                                      style->black_gc,
                                      circle->gray_sat);

      circle->action_flag = DRAGING;
    }
  else
    {
      color_rotate_draw_little_circle (widget->window, xor_gc,
                                       circle->hue, circle->satur); /* erase */
    }

  x = event->x - GRAY_CENTER - LITTLE_RADIUS;
  y = GRAY_CENTER - event->y + LITTLE_RADIUS;

  circle->hue   = angle_mod_2PI (arctg (y, x));
  circle->satur = sqrt (SQR (x) + SQR (y)) / GRAY_RADIUS;

  if (circle->satur > 1.0)
    circle->satur = 1;

  color_rotate_draw_little_circle (widget->window, xor_gc,
                                   circle->hue, circle->satur);

  gtk_spin_button_set_value (GTK_SPIN_BUTTON (circle->hue_entry),
                             circle->hue * rcm_units_factor(Current.Units));

  gtk_spin_button_set_value (GTK_SPIN_BUTTON (circle->satur_entry),
                             circle->satur);

  if (Current.RealTime)
    rcm_render_preview (Current.Bna->after);

  gdk_event_request_motions (event);

  return TRUE;
}
gboolean
rcm_gray_expose_event (GtkWidget      *widget,
		       GdkEventExpose *event,
		       RcmGray        *circle)
{
  cairo_t *cr = gdk_cairo_create (gtk_widget_get_window (widget));

  cairo_translate (cr, 0.5, 0.5);

  color_rotate_draw_little_circle (cr, circle->hue, circle->satur);
  color_rotate_draw_large_circle (cr, circle->gray_sat);

  cairo_destroy (cr);

  return TRUE;
}
gboolean
rcm_gray_expose_event (GtkWidget      *widget,
		       GdkEventExpose *event,
		       RcmGray        *circle)
{
  if (circle->action_flag == VIRGIN)
    {
      GtkStyle *style = gtk_widget_get_style (widget);

      color_rotate_draw_little_circle (widget->window,
                                       style->black_gc,
                                       circle->hue, circle->satur);

      color_rotate_draw_large_circle (widget->window,
                                      style->black_gc,
                                      circle->gray_sat);
    }

  return TRUE;
}
gboolean
rcm_gray_release_event (GtkWidget      *widget,
			GdkEventButton *event,
			RcmGray        *circle)
{
  if (circle->action_flag == DRAGING)
    {
      GtkStyle *style = gtk_widget_get_style (widget);

      color_rotate_draw_little_circle (widget->window,
                                       style->black_gc,
                                       circle->hue,
                                       circle->satur);
    }

  circle->action_flag = VIRGIN;

  rcm_render_preview (Current.Bna->after);

  return TRUE;
}
gboolean
rcm_gray_button_press_event (GtkWidget      *widget,
			     GdkEventButton *event,
			     RcmGray        *circle)
{
  GtkStyle *style = gtk_widget_get_style (widget);
  int       x, y;

  x = event->x - GRAY_CENTER - LITTLE_RADIUS;
  y = GRAY_CENTER - event->y + LITTLE_RADIUS;

  circle->action_flag = DRAG_START;
  circle->hue         = angle_mod_2PI(arctg(y, x));
  circle->satur       = sqrt (SQR (x) + SQR (y)) / GRAY_RADIUS;

  if (circle->satur > 1.0)
    circle->satur = 1;

  gtk_widget_queue_draw (circle->preview);
  color_rotate_draw_little_circle (widget->window,
                                   style->black_gc,
                                   circle->hue, circle->satur);

  color_rotate_draw_large_circle (circle->preview->window,
                                  gtk_widget_get_style (circle->preview)->black_gc,
                                  circle->gray_sat);

  gtk_spin_button_set_value (GTK_SPIN_BUTTON (circle->hue_entry),
                             circle->hue * rcm_units_factor (Current.Units));

  gtk_spin_button_set_value (GTK_SPIN_BUTTON (circle->satur_entry),
                             circle->satur);

  if (Current.RealTime)
    rcm_render_preview (Current.Bna->after);

  return TRUE;
}
void
rcm_set_satur (GtkWidget *entry,
               RcmGray   *circle)
{
  GtkStyle *style = gtk_widget_get_style (circle->preview);

  if (circle->action_flag != VIRGIN)
    return;

  circle->satur = gtk_spin_button_get_value (GTK_SPIN_BUTTON (entry));

  gtk_widget_queue_draw (circle->preview);

  color_rotate_draw_little_circle (circle->preview->window,
                                   style->black_gc,
                                   circle->hue, circle->satur);

  color_rotate_draw_large_circle (circle->preview->window,
                                  style->black_gc,
                                  circle->gray_sat);

  rcm_render_preview (Current.Bna->after);
}