Commit f41e0590 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

More sample point stuff. Addresses bug #137776.

2005-03-09  Michael Natterer  <mitch@gimp.org>

	More sample point stuff. Addresses bug #137776.

	* app/core/gimpimage-sample-points.c
	* app/core/gimpimage-undo-push.c: append, not prepend the sample
	paints to the image's list because their index matters. Update
	sample points when their index changes.

	* app/display/gimpcanvas.[ch]: added own sytles for the sample
	points.  Added gimp_canvas_draw_text() which uses a PangoLayout
	which is cached in the canvas.

	* app/display/gimpdisplayshell-draw.c
	(gimp_display_shell_draw_sample_point): draw the sample points
	more distinct from guides using the new canvas APIs above.

	* app/display/gimpdisplayshell-callbacks.c
	(gimp_display_shell_[hv]ruler_button_press): factored out all
	code to

	(gimp_display_shell_ruler_burron_press): which takes a boolean
	"horizontal" variable and allows to add sample points with
	<control>+drag.

	* app/tools/gimpcolortool.[ch]: implement adding, moving and
	removing of samp...
parent bc7c2a13
2005-03-09 Michael Natterer <mitch@gimp.org>
More sample point stuff. Addresses bug #137776.
* app/core/gimpimage-sample-points.c
* app/core/gimpimage-undo-push.c: append, not prepend the sample
paints to the image's list because their index matters. Update
sample points when their index changes.
* app/display/gimpcanvas.[ch]: added own sytles for the sample
points. Added gimp_canvas_draw_text() which uses a PangoLayout
which is cached in the canvas.
* app/display/gimpdisplayshell-draw.c
(gimp_display_shell_draw_sample_point): draw the sample points
more distinct from guides using the new canvas APIs above.
* app/display/gimpdisplayshell-callbacks.c
(gimp_display_shell_[hv]ruler_button_press): factored out all
code to
(gimp_display_shell_ruler_burron_press): which takes a boolean
"horizontal" variable and allows to add sample points with
<control>+drag.
* app/tools/gimpcolortool.[ch]: implement adding, moving and
removing of sample points in the same way as the move tool moves
guides.
* app/tools/gimpcolorpickertool.c
(gimp_color_picker_tool_oper_update): chain up.
2005-03-08 Bill Skaggs <weskaggs@primate.ucdavis.edu>
* plug-ins/metadata/interface.c: fix spelling error
......
......@@ -46,10 +46,10 @@ gimp_image_add_sample_point_at_pos (GimpImage *gimage,
sample_point = g_new0 (GimpSamplePoint, 1);
sample_point->ref_count = 1;
sample_point->x = -1;
sample_point->y = -1;
sample_point->sample_point_ID = gimage->gimp->next_sample_point_ID++;
sample_point->ref_count = 1;
sample_point->x = -1;
sample_point->y = -1;
sample_point->sample_point_ID = gimage->gimp->next_sample_point_ID++;
if (push_undo)
gimp_image_undo_push_image_sample_point (gimage, _("Add Sample_Point"),
......@@ -95,7 +95,7 @@ gimp_image_add_sample_point (GimpImage *gimage,
g_return_if_fail (x <= gimage->width);
g_return_if_fail (y <= gimage->height);
gimage->sample_points = g_list_prepend (gimage->sample_points, sample_point);
gimage->sample_points = g_list_append (gimage->sample_points, sample_point);
sample_point->x = x;
sample_point->y = y;
......@@ -105,23 +105,36 @@ gimp_image_add_sample_point (GimpImage *gimage,
}
void
gimp_image_remove_sample_point (GimpImage *gimage,
GimpSamplePoint *sample_point,
gboolean push_undo)
gimp_image_remove_sample_point (GimpImage *gimage,
GimpSamplePoint *sample_point,
gboolean push_undo)
{
GList *list;
g_return_if_fail (GIMP_IS_IMAGE (gimage));
g_return_if_fail (sample_point != NULL);
gimp_image_update_sample_point (gimage, sample_point);
if (push_undo)
gimp_image_undo_push_image_sample_point (gimage, _("Remove Sample Point"), sample_point);
gimp_image_undo_push_image_sample_point (gimage, _("Remove Sample Point"),
sample_point);
list = g_list_find (gimage->sample_points, sample_point);
if (list)
list = g_list_next (list);
gimage->sample_points = g_list_remove (gimage->sample_points, sample_point);
sample_point->x = -1;
sample_point->y = -1;
gimp_image_sample_point_unref (sample_point);
while (list)
{
gimp_image_update_sample_point (gimage, list->data);
list = g_list_next (list);
}
}
void
......@@ -139,7 +152,8 @@ gimp_image_move_sample_point (GimpImage *gimage,
g_return_if_fail (y <= gimage->height);
if (push_undo)
gimp_image_undo_push_image_sample_point (gimage, _("Move Sample Point"), sample_point);
gimp_image_undo_push_image_sample_point (gimage, _("Move Sample Point"),
sample_point);
gimp_image_update_sample_point (gimage, sample_point);
sample_point->x = x;
......
......@@ -547,8 +547,8 @@ undo_pop_image_sample_point (GimpUndo *undo,
if (gu->sample_point->x == -1)
{
undo->gimage->sample_points = g_list_prepend (undo->gimage->sample_points,
gu->sample_point);
undo->gimage->sample_points = g_list_append (undo->gimage->sample_points,
gu->sample_point);
gu->sample_point->x = gu->x;
gu->sample_point->y = gu->y;
gimp_image_sample_point_ref (gu->sample_point);
......
......@@ -211,6 +211,12 @@ gimp_canvas_unrealize (GtkWidget *widget)
}
}
if (canvas->layout)
{
g_object_unref (canvas->layout);
canvas->layout = NULL;
}
GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
}
......@@ -231,6 +237,8 @@ gimp_canvas_gc_new (GimpCanvas *canvas,
{
case GIMP_CANVAS_STYLE_BLACK:
case GIMP_CANVAS_STYLE_WHITE:
case GIMP_CANVAS_STYLE_SAMPLE_POINT_NORMAL:
case GIMP_CANVAS_STYLE_SAMPLE_POINT_ACTIVE:
break;
case GIMP_CANVAS_STYLE_RENDER:
......@@ -333,6 +341,18 @@ gimp_canvas_gc_new (GimpCanvas *canvas,
bg.green = 0x0;
bg.blue = 0x0;
break;
case GIMP_CANVAS_STYLE_SAMPLE_POINT_NORMAL:
fg.red = 0x0;
fg.green = 0x7f7f;
fg.blue = 0xffff;
break;
case GIMP_CANVAS_STYLE_SAMPLE_POINT_ACTIVE:
fg.red = 0xffff;
fg.green = 0x0;
fg.blue = 0x0;
break;
}
gdk_gc_set_rgb_fg_color (gc, &fg);
......@@ -616,10 +636,52 @@ gimp_canvas_draw_segments (GimpCanvas *canvas,
num_segments -= 32000;
segments += 32000;
}
gdk_draw_segments (GTK_WIDGET (canvas)->window, canvas->gc[style],
segments, num_segments);
}
/**
* gimp_canvas_draw_text:
* @canvas: a #GimpCanvas widget
* @style: one of the enumerated #GimpCanvasStyle's.
* @x: X coordinate of the left edge of the layout.
* @y: Y coordinate of the top edge of the layout.
* @layout: a #PangoLayout object.
*
* Draws a layout, in the specified style.
**/
void
gimp_canvas_draw_text (GimpCanvas *canvas,
GimpCanvasStyle style,
gint x,
gint y,
const gchar *format,
...)
{
va_list args;
gchar *text;
if (! gimp_canvas_ensure_style (canvas, style))
return;
if (! canvas->layout)
{
canvas->layout = gtk_widget_create_pango_layout (GTK_WIDGET (canvas),
NULL);
}
va_start (args, format);
text = g_strdup_vprintf (format, args);
va_end (args);
pango_layout_set_text (canvas->layout, text, -1);
g_free (text);
gdk_draw_layout (GTK_WIDGET (canvas)->window, canvas->gc[style],
x, y, canvas->layout);
}
/**
* gimp_canvas_draw_rgb:
* @canvas: a #GimpCanvas widget
......
......@@ -35,6 +35,8 @@ typedef enum
GIMP_CANVAS_STYLE_LAYER_BOUNDARY,
GIMP_CANVAS_STYLE_GUIDE_NORMAL,
GIMP_CANVAS_STYLE_GUIDE_ACTIVE,
GIMP_CANVAS_STYLE_SAMPLE_POINT_NORMAL,
GIMP_CANVAS_STYLE_SAMPLE_POINT_ACTIVE,
GIMP_CANVAS_STYLE_CUSTOM,
GIMP_CANVAS_NUM_STYLES
} GimpCanvasStyle;
......@@ -59,6 +61,7 @@ struct _GimpCanvas
GdkGC *gc[GIMP_CANVAS_NUM_STYLES];
GdkBitmap *stipple[GIMP_CANVAS_NUM_STIPPLES];
PangoLayout *layout;
};
struct _GimpCanvasClass
......@@ -117,6 +120,12 @@ void gimp_canvas_draw_segments (GimpCanvas *canvas,
GimpCanvasStyle style,
GdkSegment *segments,
gint num_segments);
void gimp_canvas_draw_text (GimpCanvas *canvas,
GimpCanvasStyle style,
gint x,
gint y,
const gchar *format,
...);
void gimp_canvas_draw_rgb (GimpCanvas *canvas,
GimpCanvasStyle style,
gint x,
......
......@@ -41,6 +41,7 @@
#include "core/gimplayer.h"
#include "core/gimptoolinfo.h"
#include "tools/gimpcolortool.h"
#include "tools/gimpmovetool.h"
#include "tools/gimptoolcontrol.h"
#include "tools/tool_manager.h"
......@@ -1355,9 +1356,10 @@ gimp_display_shell_canvas_tool_events (GtkWidget *canvas,
}
gboolean
gimp_display_shell_hruler_button_press (GtkWidget *widget,
GdkEventButton *event,
GimpDisplayShell *shell)
gimp_display_shell_ruler_button_press (GtkWidget *widget,
GdkEventButton *event,
GimpDisplayShell *shell,
gboolean horizontal)
{
GimpDisplay *gdisp = shell->gdisp;
......@@ -1366,33 +1368,46 @@ gimp_display_shell_hruler_button_press (GtkWidget *widget,
if (event->type == GDK_BUTTON_PRESS && event->button == 1)
{
GimpToolInfo *tool_info;
GimpTool *active_tool;
gboolean sample_point;
tool_info = (GimpToolInfo *)
gimp_container_get_child_by_name (gdisp->gimage->gimp->tool_info_list,
"gimp-move-tool");
active_tool = tool_manager_get_active (gdisp->gimage->gimp);
sample_point = (event->state & GDK_CONTROL_MASK);
if (tool_info)
if (! ((sample_point && GIMP_IS_COLOR_TOOL (active_tool)) ||
(! sample_point && GIMP_IS_MOVE_TOOL (active_tool))))
{
GimpTool *active_tool;
GimpToolInfo *tool_info;
gimp_context_set_tool (gimp_get_user_context (gdisp->gimage->gimp),
tool_info);
tool_info = (GimpToolInfo *)
gimp_container_get_child_by_name (gdisp->gimage->gimp->tool_info_list,
sample_point ?
"gimp-color-picker-tool" :
"gimp-move-tool");
active_tool = tool_manager_get_active (gdisp->gimage->gimp);
if (active_tool)
{
gdk_pointer_grab (shell->canvas->window, FALSE,
GDK_POINTER_MOTION_HINT_MASK |
GDK_BUTTON1_MOTION_MASK |
GDK_BUTTON_RELEASE_MASK,
NULL, NULL, event->time);
if (tool_info)
gimp_context_set_tool (gimp_get_user_context (gdisp->gimage->gimp),
tool_info);
}
gdk_keyboard_grab (shell->canvas->window, FALSE, event->time);
active_tool = tool_manager_get_active (gdisp->gimage->gimp);
gimp_move_tool_start_hguide (active_tool, gdisp);
}
if (active_tool)
{
gdk_pointer_grab (shell->canvas->window, FALSE,
GDK_POINTER_MOTION_HINT_MASK |
GDK_BUTTON1_MOTION_MASK |
GDK_BUTTON_RELEASE_MASK,
NULL, NULL, event->time);
gdk_keyboard_grab (shell->canvas->window, FALSE, event->time);
if (sample_point)
gimp_color_tool_start_sample_point (active_tool, gdisp);
else if (horizontal)
gimp_move_tool_start_hguide (active_tool, gdisp);
else
gimp_move_tool_start_vguide (active_tool, gdisp);
}
}
......@@ -1400,48 +1415,19 @@ gimp_display_shell_hruler_button_press (GtkWidget *widget,
}
gboolean
gimp_display_shell_vruler_button_press (GtkWidget *widget,
gimp_display_shell_hruler_button_press (GtkWidget *widget,
GdkEventButton *event,
GimpDisplayShell *shell)
{
GimpDisplay *gdisp = shell->gdisp;
if (gdisp->gimage->gimp->busy)
return TRUE;
if (event->type == GDK_BUTTON_PRESS && event->button == 1)
{
GimpToolInfo *tool_info;
tool_info = (GimpToolInfo *)
gimp_container_get_child_by_name (gdisp->gimage->gimp->tool_info_list,
"gimp-move-tool");
if (tool_info)
{
GimpTool *active_tool;
gimp_context_set_tool (gimp_get_user_context (gdisp->gimage->gimp),
tool_info);
active_tool = tool_manager_get_active (gdisp->gimage->gimp);
if (active_tool)
{
gdk_pointer_grab (shell->canvas->window, FALSE,
GDK_POINTER_MOTION_HINT_MASK |
GDK_BUTTON1_MOTION_MASK |
GDK_BUTTON_RELEASE_MASK,
NULL, NULL, event->time);
gdk_keyboard_grab (shell->canvas->window, FALSE, event->time);
gimp_move_tool_start_vguide (active_tool, gdisp);
}
}
}
return gimp_display_shell_ruler_button_press (widget, event, shell, TRUE);
}
return FALSE;
gboolean
gimp_display_shell_vruler_button_press (GtkWidget *widget,
GdkEventButton *event,
GimpDisplayShell *shell)
{
return gimp_display_shell_ruler_button_press (widget, event, shell, FALSE);
}
gboolean
......
......@@ -297,10 +297,11 @@ gimp_display_shell_draw_sample_point (GimpDisplayShell *shell,
GimpSamplePoint *sample_point,
gboolean active)
{
gint x1, x2;
gint y1, y2;
gint x, y;
gint w, h;
GimpCanvasStyle style;
gint x1, x2;
gint y1, y2;
gint x, y;
gint w, h;
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
g_return_if_fail (sample_point != NULL);
......@@ -318,7 +319,6 @@ gimp_display_shell_draw_sample_point (GimpDisplayShell *shell,
y1 = y - GIMP_SAMPLE_POINT_DRAW_SIZE;
y2 = y + GIMP_SAMPLE_POINT_DRAW_SIZE;
gdk_drawable_get_size (shell->canvas->window, &w, &h);
if (x < 0 || y < 0 || x >= w || y >= h)
......@@ -329,14 +329,35 @@ gimp_display_shell_draw_sample_point (GimpDisplayShell *shell,
if (x2 > w) x2 = w;
if (y2 > h) y2 = h;
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas),
(active ?
GIMP_CANVAS_STYLE_GUIDE_ACTIVE :
GIMP_CANVAS_STYLE_GUIDE_NORMAL), x, y1, x, y2);
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas),
(active ?
GIMP_CANVAS_STYLE_GUIDE_ACTIVE :
GIMP_CANVAS_STYLE_GUIDE_NORMAL), x1, y, x2, y);
if (active)
style = GIMP_CANVAS_STYLE_SAMPLE_POINT_ACTIVE;
else
style = GIMP_CANVAS_STYLE_SAMPLE_POINT_NORMAL;
#define HALF_SIZE (GIMP_SAMPLE_POINT_DRAW_SIZE / 2)
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas), style,
x, y1, x, y1 + HALF_SIZE);
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas), style,
x, y2 - HALF_SIZE, x, y2);
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas), style,
x1, y, x1 + HALF_SIZE, y);
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas), style,
x2 - HALF_SIZE, y, x2, y);
gimp_canvas_draw_arc (GIMP_CANVAS (shell->canvas), style,
FALSE,
x - HALF_SIZE, y - HALF_SIZE,
GIMP_SAMPLE_POINT_DRAW_SIZE,
GIMP_SAMPLE_POINT_DRAW_SIZE,
0, 64 * 270);
gimp_canvas_draw_text (GIMP_CANVAS (shell->canvas), style,
x + 2, y + 2,
"%d",
g_list_index (shell->gdisp->gimage->sample_points,
sample_point) + 1);
}
void
......
......@@ -259,6 +259,8 @@ gimp_color_picker_tool_oper_update (GimpTool *tool,
options = GIMP_COLOR_PICKER_OPTIONS (tool->tool_info->tool_options);
GIMP_COLOR_TOOL (tool)->pick_mode = options->pick_mode;
GIMP_TOOL_CLASS (parent_class)->oper_update (tool, coords, state, gdisp);
}
static void
......
......@@ -25,17 +25,27 @@
#include "tools-types.h"
#include "core/gimp.h"
#include "core/gimpimage.h"
#include "core/gimpimage-pick-color.h"
#include "core/gimpimage-sample-points.h"
#include "core/gimpitem.h"
#include "core/gimpmarshal.h"
#include "config/gimpdisplayconfig.h"
#include "display/gimpdisplay.h"
#include "display/gimpdisplayshell.h"
#include "display/gimpdisplayshell-appearance.h"
#include "display/gimpdisplayshell-draw.h"
#include "display/gimpdisplayshell-transform.h"
#include "gimpcoloroptions.h"
#include "gimpcolortool.h"
#include "gimptoolcontrol.h"
#include "gimp-intl.h"
enum
{
......@@ -50,6 +60,9 @@ static void gimp_color_tool_class_init (GimpColorToolClass *klass);
static void gimp_color_tool_init (GimpColorTool *color_tool);
static void gimp_color_tool_finalize (GObject *object);
static void gimp_color_tool_control (GimpTool *tool,
GimpToolAction action,
GimpDisplay *gdisp);
static void gimp_color_tool_button_press (GimpTool *tool,
GimpCoords *coords,
guint32 time,
......@@ -65,6 +78,10 @@ static void gimp_color_tool_motion (GimpTool *tool,
guint32 time,
GdkModifierType state,
GimpDisplay *gdisp);
static void gimp_color_tool_oper_update (GimpTool *tool,
GimpCoords *coords,
GdkModifierType state,
GimpDisplay *gdisp);
static void gimp_color_tool_cursor_update (GimpTool *tool,
GimpCoords *coords,
GdkModifierType state,
......@@ -141,9 +158,11 @@ gimp_color_tool_class_init (GimpColorToolClass *klass)
object_class->finalize = gimp_color_tool_finalize;
tool_class->control = gimp_color_tool_control;
tool_class->button_press = gimp_color_tool_button_press;
tool_class->button_release = gimp_color_tool_button_release;
tool_class->motion = gimp_color_tool_motion;
tool_class->oper_update = gimp_color_tool_oper_update;
tool_class->cursor_update = gimp_color_tool_cursor_update;
draw_class->draw = gimp_color_tool_draw;
......@@ -152,6 +171,27 @@ gimp_color_tool_class_init (GimpColorToolClass *klass)
klass->picked = NULL;
}
static void
gimp_color_tool_init (GimpColorTool *color_tool)
{
GimpTool *tool = GIMP_TOOL (color_tool);
gimp_tool_control_set_action_value_1 (tool->control,
"tools/tools-color-average-radius-set");
color_tool->enabled = FALSE;
color_tool->center_x = 0;
color_tool->center_y = 0;
color_tool->pick_mode = GIMP_COLOR_PICK_MODE_NONE;
color_tool->options = NULL;
color_tool->sample_point = NULL;
color_tool->moving_sample_point = FALSE;
color_tool->sample_point_x = -1;
color_tool->sample_point_y = -1;
}
static void
gimp_color_tool_finalize (GObject *object)
{
......@@ -167,18 +207,37 @@ gimp_color_tool_finalize (GObject *object)
}
static void
gimp_color_tool_init (GimpColorTool *color_tool)
gimp_color_tool_control (GimpTool *tool,
GimpToolAction action,
GimpDisplay *gdisp)
{
GimpTool *tool = GIMP_TOOL (color_tool);
GimpColorTool *color_tool = GIMP_COLOR_TOOL (tool);
GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (gdisp->shell);
gimp_tool_control_set_action_value_1 (tool->control,
"tools/tools-color-average-radius-set");
switch (action)
{
case PAUSE:
break;
case RESUME:
if (color_tool->sample_point &&
gimp_display_shell_get_show_sample_points (GIMP_DISPLAY_SHELL (shell)))
gimp_display_shell_draw_sample_point (GIMP_DISPLAY_SHELL (shell),
color_tool->sample_point, TRUE);
break;
case HALT:
if (color_tool->sample_point &&
gimp_display_shell_get_show_sample_points (GIMP_DISPLAY_SHELL (shell)))
gimp_display_shell_draw_sample_point (GIMP_DISPLAY_SHELL (shell),
color_tool->sample_point, FALSE);
break;
default:
break;
}
color_tool->enabled = FALSE;
color_tool->center_x = 0;
color_tool->center_y = 0;
color_tool->pick_mode = GIMP_COLOR_PICK_MODE_NONE;
color_tool->options = NULL;
GIMP_TOOL_CLASS (parent_class)->control (tool, action, gdisp);
}
static void
......@@ -188,14 +247,33 @@ gimp_color_tool_button_press (GimpTool *tool,
GdkModifierType state,
GimpDisplay *gdisp)
{
GimpColorTool *color_tool = GIMP_COLOR_TOOL (tool);
GimpColorTool *color_tool = GIMP_COLOR_TOOL (tool);
GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (gdisp->shell);