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; }
static void gimp_color_picker_tool_info_update (GimpColorPickerTool *picker_tool, GimpImageType sample_type, const GimpRGB *color, gint color_index) { gimp_color_area_set_color (GIMP_COLOR_AREA (picker_tool->color_area), color); gimp_color_frame_set_color (GIMP_COLOR_FRAME (picker_tool->color_frame1), sample_type, color, color_index); gimp_color_frame_set_color (GIMP_COLOR_FRAME (picker_tool->color_frame2), sample_type, color, color_index); /* don't use gtk_window_present() because it would focus the dialog */ if (gtk_widget_get_visible (picker_tool->dialog)) gdk_window_show (gtk_widget_get_window (picker_tool->dialog)); else gtk_widget_show (picker_tool->dialog); }
static void gimp_color_picker_tool_info_update (GimpColorPickerTool *picker_tool, const Babl *sample_format, const GimpRGB *color, gint color_index) { GimpTool *tool = GIMP_TOOL (picker_tool); gimp_tool_gui_set_shell (picker_tool->gui, gimp_display_get_shell (tool->display)); gimp_tool_gui_set_viewable (picker_tool->gui, GIMP_VIEWABLE (tool->drawable)); gimp_color_area_set_color (GIMP_COLOR_AREA (picker_tool->color_area), color); gimp_color_frame_set_color (GIMP_COLOR_FRAME (picker_tool->color_frame1), sample_format, color, color_index); gimp_color_frame_set_color (GIMP_COLOR_FRAME (picker_tool->color_frame2), sample_format, color, color_index); gimp_tool_gui_show (picker_tool->gui); }
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)); } }