コード例 #1
0
ファイル: gimpcursorview.c プロジェクト: Amerekanets/gimp
void
gimp_cursor_view_clear_cursor (GimpCursorView *view)
{
  g_return_if_fail (GIMP_IS_CURSOR_VIEW (view));

  gtk_label_set_text (GTK_LABEL (view->pixel_x_label), _("n/a"));
  gtk_label_set_text (GTK_LABEL (view->pixel_y_label), _("n/a"));
  gtk_label_set_text (GTK_LABEL (view->unit_x_label),  _("n/a"));
  gtk_label_set_text (GTK_LABEL (view->unit_y_label),  _("n/a"));

  gimp_color_frame_set_invalid (GIMP_COLOR_FRAME (view->color_frame_1));
  gimp_color_frame_set_invalid (GIMP_COLOR_FRAME (view->color_frame_2));
}
コード例 #2
0
static void
gimp_sample_point_editor_points_changed (GimpSamplePointEditor *editor)
{
  GimpImageEditor *image_editor = GIMP_IMAGE_EDITOR (editor);
  GList           *sample_points;
  gint             n_points     = 0;
  gint             i;

  if (image_editor->image)
    {
      sample_points = gimp_image_get_sample_points (image_editor->image);
      n_points = MIN (4, g_list_length (sample_points));
    }

  for (i = 0; i < n_points; i++)
    {
      gtk_widget_set_sensitive (editor->color_frames[i], TRUE);
      editor->dirty[i] = TRUE;
    }

  for (i = n_points; i < 4; i++)
    {
      gtk_widget_set_sensitive (editor->color_frames[i], FALSE);
      gimp_color_frame_set_invalid (GIMP_COLOR_FRAME (editor->color_frames[i]));
      editor->dirty[i] = FALSE;
    }

  if (n_points > 0)
    gimp_sample_point_editor_dirty (editor, -1);
}
コード例 #3
0
static gboolean
gimp_sample_point_editor_update (GimpSamplePointEditor *editor)
{
  GimpImageEditor *image_editor = GIMP_IMAGE_EDITOR (editor);
  GList           *sample_points;
  gint             n_points     = 0;
  GList           *list;
  gint             i;

  editor->dirty_idle_id = 0;

  if (! image_editor->image)
    return FALSE;

  sample_points = gimp_image_get_sample_points (image_editor->image);

  n_points = MIN (4, g_list_length (sample_points));

  for (i = 0, list = sample_points;
       i < n_points;
       i++, list = g_list_next (list))
    {
      if (editor->dirty[i])
        {
          GimpSamplePoint *sample_point = list->data;
          GimpColorFrame  *color_frame;
          const Babl      *format;
          guchar           pixel[32];
          GimpRGB          color;
          gint             x;
          gint             y;

          editor->dirty[i] = FALSE;

          color_frame = GIMP_COLOR_FRAME (editor->color_frames[i]);

          gimp_sample_point_get_position (sample_point, &x, &y);

          if (gimp_image_pick_color (image_editor->image, NULL,
                                     x, y,
                                     editor->sample_merged,
                                     FALSE, 0.0,
                                     &format,
                                     pixel,
                                     &color))
            {
              gimp_color_frame_set_color (color_frame, FALSE,
                                          format, pixel, &color);
            }
          else
            {
              gimp_color_frame_set_invalid (color_frame);
            }
        }
    }

  return FALSE;
}
コード例 #4
0
ファイル: gimpcursorview.c プロジェクト: Amerekanets/gimp
void
gimp_cursor_view_update_cursor (GimpCursorView   *view,
                                GimpImage        *image,
                                GimpUnit          unit,
                                gdouble           x,
                                gdouble           y)
{
  gboolean      in_image;
  gdouble       unit_factor;
  gint          unit_digits;
  const gchar  *unit_str;
  gchar         format_buf[32];
  gchar         buf[32];
  GimpImageType sample_type;
  GimpRGB       color;
  gint          color_index;

  g_return_if_fail (GIMP_IS_CURSOR_VIEW (view));
  g_return_if_fail (GIMP_IS_IMAGE (image));

  if (unit == GIMP_UNIT_PIXEL)
    unit = gimp_image_get_unit (image);

  in_image = (x >= 0.0 && x < gimp_image_get_width  (image) &&
              y >= 0.0 && y < gimp_image_get_height (image));

  unit_factor = _gimp_unit_get_factor (image->gimp, unit);
  unit_digits = _gimp_unit_get_digits (image->gimp, unit);
  unit_str    = _gimp_unit_get_abbreviation (image->gimp, unit);

#define FORMAT_STRING(s) (in_image ? (s) : "("s")")

  g_snprintf (buf, sizeof (buf), FORMAT_STRING ("%d"), (gint) floor (x));
  gtk_label_set_text (GTK_LABEL (view->pixel_x_label), buf);

  g_snprintf (buf, sizeof (buf), FORMAT_STRING ("%d"), (gint) floor (y));
  gtk_label_set_text (GTK_LABEL (view->pixel_y_label), buf);

  g_snprintf (format_buf, sizeof (format_buf),
              FORMAT_STRING ("%%.%df %s"), unit_digits, unit_str);

  g_snprintf (buf, sizeof (buf), format_buf,
              x * unit_factor / image->xresolution);
  gtk_label_set_text (GTK_LABEL (view->unit_x_label), buf);

  g_snprintf (buf, sizeof (buf), format_buf,
              y * unit_factor / image->yresolution);
  gtk_label_set_text (GTK_LABEL (view->unit_y_label), buf);

  if (gimp_image_pick_color (image, NULL,
                             (gint) floor (x),
                             (gint) floor (y),
                             view->sample_merged,
                             FALSE, 0.0,
                             &sample_type, &color, &color_index))
    {
      gimp_color_frame_set_color (GIMP_COLOR_FRAME (view->color_frame_1),
                                  sample_type, &color, color_index);
      gimp_color_frame_set_color (GIMP_COLOR_FRAME (view->color_frame_2),
                                  sample_type, &color, color_index);
    }
  else
    {
      gimp_color_frame_set_invalid (GIMP_COLOR_FRAME (view->color_frame_1));
      gimp_color_frame_set_invalid (GIMP_COLOR_FRAME (view->color_frame_2));
    }
}