gimpink.c 34.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/* The GIMP -- an image manipulation program
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
Tor Lillqvist's avatar
Tor Lillqvist committed
18 19 20

#include <string.h>

21 22 23 24
#include "appenv.h"
#include "drawable.h"
#include "draw_core.h"
#include "gimage_mask.h"
25
#include "gimpbrushlist.h"
26
#include "gimprc.h"
27 28 29 30
#include "ink.h"
#include "tools.h"
#include "undo.h"
#include "blob.h"
31
#include "gdisplay.h"
32

33 34
#include "libgimp/gimpintl.h"

scott's avatar
scott committed
35
#include "tile.h"			/* ick. */
36

37 38
#include <math.h>
#include <stdlib.h>
39
#include <string.h>
40

Raph Levien's avatar
Raph Levien committed
41 42 43 44
#ifndef M_PI
#define M_PI    3.14159265358979323846
#endif /* M_PI */

45 46 47 48
#define SUBSAMPLE 8

/*  the Ink structures  */

49 50
typedef Blob *(*BlobFunc) (double, double, double, double, double, double);

51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
typedef struct _InkTool InkTool;
struct _InkTool
{
  DrawCore *      core;         /*  Core select object          */
  
  Blob     *      last_blob;	/*  blob for last cursor position */

  int             x1, y1;       /*  image space coordinate      */
  int             x2, y2;       /*  image space coords          */

};

typedef struct _InkOptions InkOptions;
struct _InkOptions
{
  double       size;
  double       aspect;
  double       angle;
  double       sensitivity;
70
  double       tilt_sensitivity;
Raph Levien's avatar
Raph Levien committed
71
  double       tilt_angle;
72
  BlobFunc     function;
73 74 75 76 77
};

typedef struct _BrushWidget BrushWidget;
struct _BrushWidget
{
78
  GtkWidget   *widget;
79 80 81
  gboolean     state;
};

82 83 84
/* Global variable to store brush widget */
static BrushWidget *brush_widget;

85 86
/*  undo blocks variables  */
static TileManager *  undo_tiles = NULL;
87 88

/* Tiles used to render the stroke at 1 byte/pp */
89 90
static TileManager *  canvas_tiles = NULL;

91 92 93
/* Flat buffer that is used to used to render the dirty region
 * for composition onto the destination drawable
 */
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
static TempBuf *  canvas_buf = NULL;

/*  local variables  */
static InkOptions *ink_options = NULL;

/*  local function prototypes  */
static void   ink_button_press            (Tool *, GdkEventButton *, gpointer);
static void   ink_button_release          (Tool *, GdkEventButton *, gpointer);
static void   ink_motion                  (Tool *, GdkEventMotion *, gpointer);
static void   ink_cursor_update           (Tool *, GdkEventMotion *, gpointer);
static void   ink_control                 (Tool *, int, gpointer);

static InkOptions *create_ink_options   (void);
static Argument *ink_invoker              (Argument *);

static void ink_init   (InkTool      *ink_tool, 
			GimpDrawable *drawable, 
			double        x, 
			double        y);
static void ink_finish (InkTool      *ink_tool, 
			GimpDrawable *drawable, 
			int           tool_id);
static void ink_cleanup (void);

static void ink_scale_update              (GtkAdjustment  *adjustment, 
                                           gdouble        *value);
120 121 122 123 124 125 126 127 128
static void ink_type_update               (GtkWidget      *radio_button,
                                           BlobFunc        function);
static GdkPixmap *blob_pixmap (GdkColormap *colormap,
			       GdkVisual   *visual,
			       BlobFunc     function);
static void paint_blob (GdkDrawable  *drawable, 
			GdkGC        *gc,
			Blob         *blob);

129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
/* Rendering functions */

static void ink_set_paint_area  (InkTool      *ink_tool, 
				 GimpDrawable *drawable, 
				 Blob         *blob);
static void ink_paste           (InkTool      *ink_tool, 
				 GimpDrawable *drawable,
				 Blob         *blob);

static void ink_to_canvas_tiles (InkTool      *ink_tool,
				 Blob         *blob,
				 guchar       *color);

static void ink_set_undo_tiles  (GimpDrawable *drawable,
				 int           x, 
				 int           y,
				 int           w, 
				 int           h);
static void ink_set_canvas_tiles(int           x, 
				 int           y,
				 int           w, 
				 int           h);

/* Brush pseudo-widget callbacks */
static void brush_widget_active_rect      (BrushWidget    *brush_widget,
					   GtkWidget      *w, 
					   GdkRectangle   *rect);
static void brush_widget_realize          (GtkWidget      *w);
static void brush_widget_expose           (GtkWidget      *w, 
					   GdkEventExpose *event,
					   BrushWidget    *brush_widget);
static void brush_widget_button_press     (GtkWidget      *w, 
					   GdkEventButton *event,
					   BrushWidget    *brush_widget);
static void brush_widget_button_release   (GtkWidget      *w,  
					   GdkEventButton *event,
					   BrushWidget    *brush_widget);
static void brush_widget_motion_notify    (GtkWidget      *w, 
					   GdkEventMotion *event,
					   BrushWidget    *brush_widget);


static InkOptions *
create_ink_options ()
{
  GtkWidget *vbox;
175
  GtkWidget *util_vbox;
176 177
  GtkWidget *hbox;
  GtkWidget *label;
178 179
  GtkWidget *radio_button;
  GtkWidget *pixmap_widget;
180 181 182 183 184
  GtkWidget *slider;
  GtkWidget *aspect_frame;
  GtkWidget *darea;
  GtkAdjustment *adj;

185 186
  GdkPixmap *pixmap;

187 188 189
  InkOptions *options;

  /*  the new options structure  */
190
  options = g_new (InkOptions, 1);
191

192 193 194 195
  options->size = 3.0;
  options->sensitivity = 1.0;
  options->aspect = 1.0;
  options->angle = 0.0;
Raph Levien's avatar
Raph Levien committed
196 197
  options->tilt_sensitivity = 1.0;
  options->tilt_angle = 0.0;
198
  options->function = blob_ellipse;
199 200 201 202

  /*  the main vbox  */
  vbox = gtk_vbox_new (FALSE, 1);

203
  /*  the main label  */
204
  label = gtk_label_new (_("Ink Options"));
205 206 207
  gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
  gtk_widget_show (label);

208 209 210
  /* size slider */
  hbox = gtk_hbox_new (FALSE, 2);
  gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
211
  label = gtk_label_new (_("Size:"));
212 213
  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 2);
  
214
  adj = GTK_ADJUSTMENT (gtk_adjustment_new (3.0, 0.0, 20.0, 1.0, 5.0, 0.0));
215 216 217 218 219 220 221 222 223 224 225 226
  slider = gtk_hscale_new (adj);
  gtk_box_pack_start (GTK_BOX (hbox), slider, TRUE, TRUE, 0);
  gtk_scale_set_value_pos (GTK_SCALE (slider), GTK_POS_TOP);
  
  gtk_range_set_update_policy (GTK_RANGE (slider), GTK_UPDATE_DELAYED);
  gtk_signal_connect (GTK_OBJECT (adj), "value_changed",
		      (GtkSignalFunc) ink_scale_update,
		      &options->size);
  
  /* sens slider */
  hbox = gtk_hbox_new (FALSE, 2);
  gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
227
  label = gtk_label_new (_("Sensitivity:"));
228 229 230 231 232 233 234 235 236 237 238 239
  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 2);
  
  adj = GTK_ADJUSTMENT (gtk_adjustment_new (1.0, 0.0, 1.0, 0.01, 0.1, 0.0));
  slider = gtk_hscale_new (adj);
  gtk_box_pack_start (GTK_BOX (hbox), slider, TRUE, TRUE, 0);
  gtk_scale_set_value_pos (GTK_SCALE (slider), GTK_POS_TOP);
  
  gtk_range_set_update_policy (GTK_RANGE (slider), GTK_UPDATE_DELAYED);
  gtk_signal_connect (GTK_OBJECT (adj), "value_changed",
		      (GtkSignalFunc) ink_scale_update,
		      &options->sensitivity);

240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
  /* tilt sens slider */
  hbox = gtk_hbox_new (FALSE, 2);
  gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
  label = gtk_label_new (_("Tilt Sensitivity:"));
  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 2);
  
  adj = GTK_ADJUSTMENT (gtk_adjustment_new (1.0, 0.0, 1.0, 0.01, 0.1, 0.0));
  slider = gtk_hscale_new (adj);
  gtk_box_pack_start (GTK_BOX (hbox), slider, TRUE, TRUE, 0);
  gtk_scale_set_value_pos (GTK_SCALE (slider), GTK_POS_TOP);
  
  gtk_range_set_update_policy (GTK_RANGE (slider), GTK_UPDATE_DELAYED);
  gtk_signal_connect (GTK_OBJECT (adj), "value_changed",
		      (GtkSignalFunc) ink_scale_update,
		      &options->tilt_sensitivity);

Raph Levien's avatar
Raph Levien committed
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
  /* angle adjust slider */
  hbox = gtk_hbox_new (FALSE, 2);
  gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
  label = gtk_label_new (_("Angle adjust:"));
  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 2);
  
  adj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, -90.0, 90.0, 1, 10.0, 0.0));
  slider = gtk_hscale_new (adj);
  gtk_box_pack_start (GTK_BOX (hbox), slider, TRUE, TRUE, 0);
  gtk_scale_set_value_pos (GTK_SCALE (slider), GTK_POS_TOP);
  
  gtk_range_set_update_policy (GTK_RANGE (slider), GTK_UPDATE_DELAYED);
  gtk_signal_connect (GTK_OBJECT (adj), "value_changed",
		      (GtkSignalFunc) ink_scale_update,
		      &options->tilt_angle);

272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
  /* Brush type radiobuttons */

  hbox = gtk_hbox_new (FALSE, 2);
  gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 5);

  util_vbox = gtk_vbox_new (FALSE, 2);
  gtk_box_pack_start (GTK_BOX(hbox), util_vbox, FALSE, FALSE, 5);

  label = gtk_label_new (_("Type:"));
  gtk_box_pack_start (GTK_BOX (util_vbox), label, FALSE, FALSE, 0);
  
  pixmap = blob_pixmap (gtk_widget_get_colormap (util_vbox),
			gtk_widget_get_visual (util_vbox),
			blob_ellipse);

  pixmap_widget = gtk_pixmap_new (pixmap, NULL);
  gdk_pixmap_unref (pixmap);

  radio_button = gtk_radio_button_new (NULL);
  gtk_signal_connect (GTK_OBJECT (radio_button), "toggled",
		      GTK_SIGNAL_FUNC (ink_type_update), 
		      (gpointer)blob_ellipse);

  gtk_container_add (GTK_CONTAINER (radio_button), pixmap_widget);
  gtk_box_pack_start (GTK_BOX (util_vbox), radio_button, FALSE, FALSE, 0);

  pixmap = blob_pixmap (gtk_widget_get_colormap (util_vbox),
			gtk_widget_get_visual (util_vbox),
			blob_square);

  pixmap_widget = gtk_pixmap_new (pixmap, NULL);
  gdk_pixmap_unref (pixmap);

  radio_button = gtk_radio_button_new_from_widget (GTK_RADIO_BUTTON (radio_button));
  gtk_signal_connect (GTK_OBJECT (radio_button), "toggled",
		      GTK_SIGNAL_FUNC (ink_type_update), 
		      (gpointer)blob_square);
  
  gtk_container_add (GTK_CONTAINER (radio_button), pixmap_widget);
  gtk_box_pack_start (GTK_BOX (util_vbox), radio_button, FALSE, FALSE, 0);

  pixmap = blob_pixmap (gtk_widget_get_colormap (util_vbox),
			gtk_widget_get_visual (util_vbox),
			blob_diamond);

  pixmap_widget = gtk_pixmap_new (pixmap, NULL);
  gdk_pixmap_unref (pixmap);

  radio_button = gtk_radio_button_new_from_widget (GTK_RADIO_BUTTON (radio_button));
  gtk_signal_connect (GTK_OBJECT (radio_button), "toggled",
		      GTK_SIGNAL_FUNC (ink_type_update), 
		      (gpointer)blob_diamond);

  gtk_container_add (GTK_CONTAINER (radio_button), pixmap_widget);
  gtk_box_pack_start (GTK_BOX (util_vbox), radio_button, FALSE, FALSE, 0);

328 329 330 331 332
  /* Brush shape widget */

  brush_widget = g_new (BrushWidget, 1);
  brush_widget->state = FALSE;
  
333 334 335
  util_vbox = gtk_vbox_new (FALSE, 2);
  gtk_box_pack_start (GTK_BOX(hbox), util_vbox, FALSE, FALSE, 5);

336
  label = gtk_label_new (_("Shape:"));
337
  gtk_box_pack_start (GTK_BOX (util_vbox), label, FALSE, FALSE, 0);
338 339 340
  
  aspect_frame = gtk_aspect_frame_new (NULL, 0.5, 0.5, 1.0, FALSE);
  gtk_frame_set_shadow_type (GTK_FRAME(aspect_frame), GTK_SHADOW_IN);
341 342
  gtk_box_pack_start (GTK_BOX (util_vbox), aspect_frame, TRUE, TRUE, 2);

343
  darea = gtk_drawing_area_new();
344 345
  brush_widget->widget = darea;
  
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
  gtk_drawing_area_size (GTK_DRAWING_AREA(darea), 60, 60);
  gtk_container_add (GTK_CONTAINER(aspect_frame), darea);
  
  gtk_widget_set_events (darea, 
			 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
			 | GDK_POINTER_MOTION_MASK | GDK_EXPOSURE_MASK);
  gtk_signal_connect (GTK_OBJECT (darea), "button_press_event",
		      GTK_SIGNAL_FUNC (brush_widget_button_press),
		      brush_widget);
  gtk_signal_connect (GTK_OBJECT (darea), "button_release_event",
		      GTK_SIGNAL_FUNC (brush_widget_button_release),
		      brush_widget);
  gtk_signal_connect (GTK_OBJECT (darea), "motion_notify_event",
		      GTK_SIGNAL_FUNC (brush_widget_motion_notify),
		      brush_widget);
  gtk_signal_connect (GTK_OBJECT (darea), "expose_event",
		      GTK_SIGNAL_FUNC (brush_widget_expose), 
		      brush_widget);
  gtk_signal_connect (GTK_OBJECT (darea), "realize",
		      GTK_SIGNAL_FUNC (brush_widget_realize),
		      brush_widget);
  gtk_widget_show_all (vbox);
  gtk_widget_hide (vbox);
  
  /*  Register this selection options widget with the main tools options dialog  */
  tools_register_options (INK, vbox);

  return options;
}

static void
brush_widget_active_rect (BrushWidget *brush_widget, GtkWidget *w,
			  GdkRectangle *rect)
{
  int x,y;
  int r;

  r = MIN(w->allocation.width,w->allocation.height)/2;

  x = w->allocation.width/2 + 0.85*r*ink_options->aspect/10. *
    cos (ink_options->angle);
  y = w->allocation.height/2 + 0.85*r*ink_options->aspect/10. *
    sin (ink_options->angle);

  rect->x = x-5;
  rect->y = y-5;
  rect->width = 10;
  rect->height = 10;
}

static void
brush_widget_realize (GtkWidget *w)
{
  gtk_style_set_background (w->style, w->window, GTK_STATE_ACTIVE);
}

static void
brush_widget_draw_brush (BrushWidget *brush_widget, GtkWidget *w,
			 double xc, double yc, double radius)
{
  Blob *b;

408 409 410 411 412
  b = ink_options->function (xc,yc,
			     radius*cos(ink_options->angle),
			     radius*sin(ink_options->angle),
			     -(radius/ink_options->aspect)*sin(ink_options->angle),
			     (radius/ink_options->aspect)*cos(ink_options->angle));
413

414
  paint_blob (w->window, w->style->fg_gc[w->state],b);
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
  g_free (b);
}

static void
brush_widget_expose (GtkWidget *w, GdkEventExpose *event,
		     BrushWidget *brush_widget)
{
  GdkRectangle rect;
  int r0;
  
  r0 = MIN(w->allocation.width,w->allocation.height)/2;

  if (r0 < 2)
    return;

  gdk_window_clear_area(w->window,
			0,0,w->allocation.width,
			w->allocation.height);
  brush_widget_draw_brush (brush_widget, w,
			   w->allocation.width/2, w->allocation.height/2,
			   0.9*r0);

  brush_widget_active_rect (brush_widget, w, &rect);
  gdk_draw_rectangle (w->window, w->style->bg_gc[GTK_STATE_NORMAL],
		      TRUE,	/* filled */
		      rect.x, rect.y, 
		      rect.width, rect.height);
  gtk_draw_shadow (w->style, w->window, w->state, GTK_SHADOW_OUT,
		   rect.x, rect.y,
		   rect.width, rect.height);
}

static void
brush_widget_button_press (GtkWidget *w, GdkEventButton *event,
			   BrushWidget *brush_widget)
{
  GdkRectangle rect;

  brush_widget_active_rect (brush_widget, w, &rect);
  
  if ((event->x >= rect.x) && (event->x-rect.x < rect.width) &&
      (event->y >= rect.y) && (event->y-rect.y < rect.height))
    {
      brush_widget->state = TRUE;
    }
}

static void
brush_widget_button_release (GtkWidget *w, GdkEventButton *event,
			    BrushWidget *brush_widget)
{
  brush_widget->state = FALSE;
}

static void
brush_widget_motion_notify (GtkWidget *w, GdkEventMotion *event,
			    BrushWidget *brush_widget)
{
  int x;
  int y;
  int r0;
  int rsquare;

  if (brush_widget->state)
    {
      x = event->x - w->allocation.width/2;
      y = event->y - w->allocation.height/2;
      rsquare = x*x + y*y;

      if (rsquare != 0)
	{
	  ink_options->angle = atan2(y,x);

	  r0 = MIN(w->allocation.width,w->allocation.height)/2;
	  ink_options->aspect =
	    10. * sqrt((double)rsquare/(r0*r0)) / 0.85;

	  if (ink_options->aspect < 1.0)
	    ink_options->aspect = 1.0;
	  if (ink_options->aspect > 10.0)
	    ink_options->aspect = 10.0;

	  gtk_widget_draw(w, NULL);
	}
    }
}

static void
ink_scale_update (GtkAdjustment *adjustment, gdouble *value)
{
  *value = adjustment->value;
}

508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570
static void 
ink_type_update (GtkWidget      *radio_button,
		 BlobFunc        function)
{
  if (GTK_TOGGLE_BUTTON (radio_button)->active)
    ink_options->function = function;

  gtk_widget_queue_draw (brush_widget->widget);
}

/*
 * Return a black-on white pixmap in the given colormap and
 * visual that represents the BlobFunc 'function'
 */
static GdkPixmap *
blob_pixmap (GdkColormap *colormap,
	     GdkVisual *visual,
	     BlobFunc function)
{
  GdkPixmap *pixmap;
  GdkGC *black_gc, *white_gc;
  GdkColor tmp_color;
  Blob *blob;

  pixmap = gdk_pixmap_new (NULL, 22, 21, visual->depth);

  black_gc = gdk_gc_new (pixmap);
  gdk_color_black (colormap, &tmp_color);
  gdk_gc_set_foreground (black_gc, &tmp_color);

  white_gc = gdk_gc_new (pixmap);
  gdk_color_white (colormap, &tmp_color);
  gdk_gc_set_foreground (white_gc, &tmp_color);

  gdk_draw_rectangle (pixmap, white_gc, TRUE, 0, 0, 21, 20);
  gdk_draw_rectangle (pixmap, black_gc, FALSE, 0, 0, 21, 20);
  blob = (*function) (10, 10, 8, 0, 0, 8);
  paint_blob (pixmap, black_gc, blob);

  gdk_gc_unref (white_gc);
  gdk_gc_unref (black_gc);

  return pixmap;
}

/*
 * Draw a blob onto a drawable with the specified graphics context
 */
static void
paint_blob (GdkDrawable *drawable, GdkGC *gc,
	    Blob *blob)
{
  int i;

  for (i=0;i<blob->height;i++)
    {
      if (blob->data[i].left <= blob->data[i].right)
	gdk_draw_line (drawable, gc,
		       blob->data[i].left,i+blob->y,
		       blob->data[i].right+1,i+blob->y);
    }
}

571 572 573 574 575 576 577 578
static Blob *
ink_pen_ellipse (gdouble x_center, gdouble y_center,
		 gdouble pressure, gdouble xtilt, gdouble ytilt)
{
  double size;
  double tsin, tcos;
  double aspect, radmin;
  double x,y;
579
  double tscale;
Raph Levien's avatar
Raph Levien committed
580 581
  double tscale_c;
  double tscale_s;
582 583
  
  size = ink_options->size * (1 + ink_options->sensitivity * (2*pressure - 1));
584
  if (size*SUBSAMPLE < 1) size = 1/SUBSAMPLE;
585 586 587

  /* Add brush angle/aspect to title vectorially */

Raph Levien's avatar
Raph Levien committed
588 589 590 591
  /* I'm not happy with the way the brush widget info is combined with
     tilt info from the brush. My personal feeling is that representing
     both as affine transforms would make the most sense. -RLL */

592
  tscale = ink_options->tilt_sensitivity * 10.0;
Raph Levien's avatar
Raph Levien committed
593 594 595 596 597 598 599 600 601 602
  tscale_c = tscale * cos (ink_options->tilt_angle * M_PI / 180);
  tscale_s = tscale * sin (ink_options->tilt_angle * M_PI / 180);
  x = ink_options->aspect*cos(ink_options->angle) +
    xtilt * tscale_c - ytilt * tscale_s;
  y = ink_options->aspect*sin(ink_options->angle) +
    ytilt * tscale_c + xtilt * tscale_s;
#ifdef VERBOSE
  g_print ("angle %g aspect %g; %g %g; %g %g\n",
	   ink_options->angle, ink_options->aspect, tscale_c, tscale_s, x, y);
#endif
603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623
  aspect = sqrt(x*x+y*y);

  if (aspect != 0)
    {
      tcos = x/aspect;
      tsin = y/aspect;
    }
  else
    {
      tsin = sin(ink_options->angle);
      tcos = cos(ink_options->angle);
    }
  
  if (aspect < 1.0) 
    aspect = 1.0;
  else if (aspect > 10.0) 
    aspect = 10.0;

  radmin = SUBSAMPLE * size/aspect;
  if (radmin < 1.0) radmin = 1.0;
  
624 625 626
  return ink_options->function (x_center * SUBSAMPLE, y_center * SUBSAMPLE,
				radmin*aspect*tcos, radmin*aspect*tsin,  
				-radmin*tsin, radmin*tcos);
627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654
}

static void
ink_button_press (Tool           *tool,
		  GdkEventButton *bevent,
		  gpointer        gdisp_ptr)
{
  gdouble       x, y;
  GDisplay     *gdisp;
  InkTool      *ink_tool;
  GimpDrawable *drawable;
  Blob         *b;

  gdisp = (GDisplay *) gdisp_ptr;
  ink_tool = (InkTool *) tool->private;

  /*  Keep the coordinates of the target  */
  gdisplay_untransform_coords_f (gdisp, bevent->x, bevent->y,
				 &x, &y, TRUE);
  drawable = gimage_active_drawable (gdisp->gimage);

  ink_init (ink_tool, drawable, x, y);

  tool->state = ACTIVE;
  tool->gdisp_ptr = gdisp_ptr;
  tool->paused_count = 0;

  /*  pause the current selection and grab the pointer  */
655
  gdisplays_selection_visibility (gdisp->gimage, SelectionPause);
656

657 658
  /* add motion memory if you press mod1 first ^ perfectmouse */
  if (((bevent->state & GDK_MOD1_MASK) != 0) != (perfectmouse != 0))
659 660 661 662 663
    gdk_pointer_grab (gdisp->canvas->window, FALSE,
		      GDK_BUTTON1_MOTION_MASK | GDK_BUTTON_RELEASE_MASK,
		      NULL, NULL, bevent->time);
  else
    gdk_pointer_grab (gdisp->canvas->window, FALSE,
664 665
		      GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON1_MOTION_MASK |
		      GDK_BUTTON_RELEASE_MASK,
666 667 668 669 670 671 672 673 674 675 676
		      NULL, NULL, bevent->time);
  
  tool->gdisp_ptr = gdisp_ptr;
  tool->state = ACTIVE;

  b = ink_pen_ellipse (x, y, 
		       bevent->pressure, bevent->xtilt, bevent->ytilt);

  ink_paste (ink_tool, drawable, b);
  ink_tool->last_blob = b;

677
  gdisplay_flush_now (gdisp);
678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693
}

static void
ink_button_release (Tool           *tool,
		    GdkEventButton *bevent,
		    gpointer        gdisp_ptr)
{
  GDisplay * gdisp;
  GImage * gimage;
  InkTool * ink_tool;

  gdisp = (GDisplay *) gdisp_ptr;
  gimage = gdisp->gimage;
  ink_tool = (InkTool *) tool->private;

  /*  resume the current selection and ungrab the pointer  */
694
  gdisplays_selection_visibility (gdisp->gimage, SelectionResume);
695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732

  gdk_pointer_ungrab (bevent->time);
  gdk_flush ();

  /*  Set tool state to inactive -- no longer painting */
  tool->state = INACTIVE;

  ink_finish (ink_tool, gimage_active_drawable (gdisp->gimage), tool->ID);
  gdisplays_flush ();
}

static void
ink_motion (Tool           *tool,
	    GdkEventMotion *mevent,
	    gpointer        gdisp_ptr)
{
  GDisplay *gdisp;
  InkTool  *ink_tool;
  GimpDrawable *drawable;
  Blob *b, *blob_union;

  double x, y;

  gdisp = (GDisplay *) gdisp_ptr;
  ink_tool = (InkTool *) tool->private;

  gdisplay_untransform_coords_f (gdisp, mevent->x, mevent->y, &x, &y, TRUE);
  drawable = gimage_active_drawable (gdisp->gimage);

  b = ink_pen_ellipse (x, y, 
		       mevent->pressure, mevent->xtilt, mevent->ytilt);
  blob_union = blob_convex_union (ink_tool->last_blob, b);
  g_free (ink_tool->last_blob);
  ink_tool->last_blob = b;

  ink_paste (ink_tool, drawable, blob_union);  
  g_free (blob_union);
  
733
  gdisplay_flush_now (gdisp);
734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937
}

static void
ink_cursor_update (Tool           *tool,
		   GdkEventMotion *mevent,
		   gpointer        gdisp_ptr)
{
  GDisplay *gdisp;
  Layer *layer;
  GdkCursorType ctype = GDK_TOP_LEFT_ARROW;
  int x, y;

  gdisp = (GDisplay *) gdisp_ptr;

  gdisplay_untransform_coords (gdisp, mevent->x, mevent->y, &x, &y, FALSE, FALSE);
  if ((layer = gimage_get_active_layer (gdisp->gimage))) 
    {
      int off_x, off_y;
      drawable_offsets (GIMP_DRAWABLE(layer), &off_x, &off_y);
    if (x >= off_x && y >= off_y &&
	x < (off_x + drawable_width (GIMP_DRAWABLE(layer))) &&
	y < (off_y + drawable_height (GIMP_DRAWABLE(layer))))
      {
	/*  One more test--is there a selected region?
	 *  if so, is cursor inside?
	 */
	if (gimage_mask_is_empty (gdisp->gimage))
	  ctype = GDK_PENCIL;
	else if (gimage_mask_value (gdisp->gimage, x, y))
	  ctype = GDK_PENCIL;
      }
    }
  gdisplay_install_tool_cursor (gdisp, ctype);
}

static void
ink_control (Tool     *tool,
	     int       action,
	     gpointer  gdisp_ptr)
{
  GDisplay *gdisp;
  GimpDrawable *drawable;
  InkTool *ink_tool;

  gdisp = (GDisplay *) gdisp_ptr;
  ink_tool = (InkTool *) tool->private;
  drawable = gimage_active_drawable (gdisp->gimage);

  switch (action)
    {
    case PAUSE :
      draw_core_pause (ink_tool->core, tool);
      break;
    case RESUME :
      draw_core_resume (ink_tool->core, tool);
      break;
    case HALT :
      ink_cleanup ();
      break;
    }
}

static void
ink_init (InkTool *ink_tool, GimpDrawable *drawable, 
		 double x, double y)
{
  /*  free the block structures  */
  if (undo_tiles)
    tile_manager_destroy (undo_tiles);
  if (canvas_tiles)
    tile_manager_destroy (canvas_tiles);

  /*  Allocate the undo structure  */
  undo_tiles = tile_manager_new (drawable_width (drawable),
				 drawable_height (drawable),
				 drawable_bytes (drawable));

  /*  Allocate the canvas blocks structure  */
  canvas_tiles = tile_manager_new (drawable_width (drawable),
				   drawable_height (drawable), 1);

  /*  Get the initial undo extents  */
  ink_tool->x1 = ink_tool->x2 = x;
  ink_tool->y1 = ink_tool->y2 = y;
}

static void
ink_finish (InkTool *ink_tool, GimpDrawable *drawable, int tool_id)
{
  /*  push an undo  */
  drawable_apply_image (drawable, ink_tool->x1, ink_tool->y1,
			ink_tool->x2, ink_tool->y2, undo_tiles, TRUE);
  undo_tiles = NULL;

  /*  invalidate the drawable--have to do it here, because
   *  it is not done during the actual painting.
   */
  drawable_invalidate_preview (drawable);
}

static void
ink_cleanup (void)
{
  /*  CLEANUP  */
  /*  If the undo tiles exist, nuke them  */
  if (undo_tiles)
    {
      tile_manager_destroy (undo_tiles);
      undo_tiles = NULL;
    }

  /*  If the canvas blocks exist, nuke them  */
  if (canvas_tiles)
    {
      tile_manager_destroy (canvas_tiles);
      canvas_tiles = NULL;
    }

  /*  Free the temporary buffer if it exist  */
  if (canvas_buf)
    temp_buf_free (canvas_buf);
  canvas_buf = NULL;
}

/*********************************
 *  Rendering functions          *
 *********************************/

/* Some of this stuff should probably be combined with the 
 * code it was copied from in paint_core.c; but I wanted
 * to learn this stuff, so I've kept it simple.
 *
 * The following only supports CONSTANT mode. Incremental
 * would, I think, interact strangely with the way we
 * do things. But it wouldn't be hard to implement at all.
 */

static void
ink_set_paint_area (InkTool      *ink_tool, 
		    GimpDrawable *drawable, 
		    Blob         *blob)
{
  int x, y, width, height;
  int x1, y1, x2, y2;
  int bytes;
  
  blob_bounds (blob, &x, &y, &width, &height);

  bytes = drawable_has_alpha (drawable) ?
    drawable_bytes (drawable) : drawable_bytes (drawable) + 1;

  x1 = CLAMP (x/SUBSAMPLE - 1,            0, drawable_width (drawable));
  y1 = CLAMP (y/SUBSAMPLE - 1,            0, drawable_height (drawable));
  x2 = CLAMP ((x + width)/SUBSAMPLE + 2,  0, drawable_width (drawable));
  y2 = CLAMP ((y + height)/SUBSAMPLE + 2, 0, drawable_height (drawable));

  /*  configure the canvas buffer  */
  if ((x2 - x1) && (y2 - y1))
    canvas_buf = temp_buf_resize (canvas_buf, bytes, x1, y1,
				  (x2 - x1), (y2 - y1));
}

enum { ROW_START, ROW_STOP };

/* The insertion sort here, for SUBSAMPLE = 8, tends to beat out
 * qsort() by 4x with CFLAGS=-O2, 2x with CFLAGS=-g
 */
static void insert_sort (int *data, int n)
{
  int i, j, k;
  int tmp1, tmp2;

  for (i=2; i<2*n; i+=2)
    {
      tmp1 = data[i];
      tmp2 = data[i+1];
      j = 0;
      while (data[j] < tmp1)
	j += 2;

      for (k=i; k>j; k-=2)
	{
	  data[k] = data[k-2];
	  data[k+1] = data[k-1];
	}

      data[j] = tmp1;
      data[j+1] = tmp2;
    }
}

static void
fill_run (guchar *dest,
	  guchar  alpha,
	  int     w)
{
  if (alpha == 255)
    {
      memset (dest, 255, w);
    }
  else
    {
      while (w--)
	{
938
	  *dest = MAX(*dest, alpha);
939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036
	  dest++;
	}
    }
}

static void
render_blob_line (Blob *blob, guchar *dest,
		  int x, int y, int width)
{
  int buf[4*SUBSAMPLE];
  int *data = buf;
  int n = 0;
  int i, j;
  int current = 0;		/* number of filled rows at this point
				 * in the scan line */

  int last_x;

  /* Sort start and ends for all lines */
  
  j = y * SUBSAMPLE - blob->y;
  for (i=0; i<SUBSAMPLE; i++)
    {
      if (j >= blob->height)
	break;
      if ((j > 0) && (blob->data[j].left <= blob->data[j].right))
	{
	  data[2*n] = blob->data[j].left;
	  data[2*n+1] = ROW_START;
	  data[2*SUBSAMPLE+2*n] = blob->data[j].right;
	  data[2*SUBSAMPLE+2*n+1] = ROW_STOP;
	  n++;
	}
      j++;
    }

  /*   If we have less than SUBSAMPLE rows, compress */
  if (n < SUBSAMPLE)
    {
      for (i=0; i<2*n; i++)
	data[2*n+i] = data[2*SUBSAMPLE+i];
    }

  /*   Now count start and end separately */
  n *= 2;

  insert_sort (data, n);

  /* Discard portions outside of tile */

  while ((n > 0) && (data[0] < SUBSAMPLE*x))
    {
      if (data[1] == ROW_START)
	current++;
      else
	current--;
      data += 2;
      n--;
    }

  while ((n > 0) && (data[2*(n-1)] >= SUBSAMPLE*(x+width)))
    n--;
  
  /* Render the row */

  last_x = 0;
  for (i=0; i<n;)
    {
      int cur_x = data[2*i] / SUBSAMPLE - x;
      int pixel;

      /* Fill in portion leading up to this pixel */
      if (current && cur_x != last_x)
	fill_run (dest + last_x, (255*current)/SUBSAMPLE, cur_x - last_x);

      /* Compute the value for this pixel */
      pixel = current * SUBSAMPLE; 

      while (i<n)
	{
	  int tmp_x = data[2*i] / SUBSAMPLE;
	  if (tmp_x - x != cur_x)
	    break;

	  if (data[2*i+1] == ROW_START)
	    {
	      current++;
	      pixel += ((tmp_x + 1) * SUBSAMPLE) - data[2*i];
	    }
	  else
	    {
	      current--;
	      pixel -= ((tmp_x + 1) * SUBSAMPLE) - data[2*i];
	    }
	  
	  i++;
	}

1037
      dest[cur_x] = MAX(dest[cur_x], (pixel * 255) / (SUBSAMPLE * SUBSAMPLE));
1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081

      last_x = cur_x + 1;
    }

  if (current != 0)
    fill_run (dest + last_x, (255*current)/SUBSAMPLE, width - last_x);
}

static void
render_blob (PixelRegion *dest, Blob *blob)
{
  int i;
  int h;
  unsigned char * s;
  void * pr;

  for (pr = pixel_regions_register (1, dest); 
       pr != NULL; 
       pr = pixel_regions_process (pr))
    {
      h = dest->h;
      s = dest->data;

      for (i=0; i<h; i++)
	{
	  render_blob_line (blob, s,
			    dest->x, dest->y + i, dest->w);
	  s += dest->rowstride;
	}
    }
}

static void
ink_paste (InkTool      *ink_tool, 
	   GimpDrawable *drawable,
	   Blob         *blob)
{
  GImage *gimage;
  PixelRegion srcPR;
  int offx, offy;
  unsigned char col[MAX_CHANNELS];

  if (! (gimage = drawable_gimage (drawable)))
    return;
1082

1083 1084
  /* Get the the buffer */
  ink_set_paint_area (ink_tool, drawable, blob);
1085 1086 1087 1088
 
  /* check to make sure there is actually a canvas to draw on */
  if (!canvas_buf)
    return;
1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120

  gimage_get_foreground (gimage, drawable, col);

  /*  set the alpha channel  */
  col[canvas_buf->bytes - 1] = OPAQUE_OPACITY;

  /*  color the pixels  */
  color_pixels (temp_buf_data (canvas_buf), col,
		canvas_buf->width * canvas_buf->height, canvas_buf->bytes);

  /*  set undo blocks  */
  ink_set_undo_tiles (drawable,
		      canvas_buf->x, canvas_buf->y,
		      canvas_buf->width, canvas_buf->height);

  /*  initialize any invalid canvas tiles  */
  ink_set_canvas_tiles (canvas_buf->x, canvas_buf->y,
			canvas_buf->width, canvas_buf->height);

  ink_to_canvas_tiles (ink_tool, blob, col);

  /*  initialize canvas buf source pixel regions  */
  srcPR.bytes = canvas_buf->bytes;
  srcPR.x = 0; srcPR.y = 0;
  srcPR.w = canvas_buf->width;
  srcPR.h = canvas_buf->height;
  srcPR.rowstride = canvas_buf->width * canvas_buf->bytes;
  srcPR.data = temp_buf_data (canvas_buf);

  /*  apply the paint area to the gimage  */
  gimage_apply_image (gimage, drawable, &srcPR,
		      FALSE, 
1121 1122
		      (int) (gimp_brush_get_opacity () * 255),
		      gimp_brush_get_paint_mode(),
1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136
		      undo_tiles,  /*  specify an alternative src1  */
		      canvas_buf->x, canvas_buf->y);

  /*  Update the undo extents  */
  ink_tool->x1 = MIN (ink_tool->x1, canvas_buf->x);
  ink_tool->y1 = MIN (ink_tool->y1, canvas_buf->y);
  ink_tool->x2 = MAX (ink_tool->x2, (canvas_buf->x + canvas_buf->width));
  ink_tool->y2 = MAX (ink_tool->y2, (canvas_buf->y + canvas_buf->height));

  /*  Update the gimage--it is important to call gdisplays_update_area
   *  instead of drawable_update because we don't want the drawable
   *  preview to be constantly invalidated
   */
  drawable_offsets (drawable, &offx, &offy);
1137
  gdisplays_update_area (gimage, canvas_buf->x + offx, canvas_buf->y + offy,
1138 1139 1140
			 canvas_buf->width, canvas_buf->height);
}

1141 1142 1143 1144
/* This routine a) updates the representation of the stroke
 * in the canvas tiles, then renders the dirty bit of it
 * into canvas_buf.
 */
1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188
static void
ink_to_canvas_tiles (InkTool *ink_tool,
		     Blob    *blob,
		     guchar  *color)
{
  PixelRegion srcPR, maskPR;

  /*  draw the blob on the canvas tiles  */
  pixel_region_init (&srcPR, canvas_tiles,
		     canvas_buf->x, canvas_buf->y,
		     canvas_buf->width, canvas_buf->height, TRUE);

  render_blob (&srcPR, blob);

  /*  combine the canvas tiles and the canvas buf  */
  srcPR.bytes = canvas_buf->bytes;
  srcPR.x = 0; srcPR.y = 0;
  srcPR.w = canvas_buf->width;
  srcPR.h = canvas_buf->height;
  srcPR.rowstride = canvas_buf->width * canvas_buf->bytes;
  srcPR.data = temp_buf_data (canvas_buf);

  pixel_region_init (&maskPR, canvas_tiles,
		     canvas_buf->x, canvas_buf->y,
		     canvas_buf->width, canvas_buf->height, FALSE);

  /*  apply the canvas tiles to the canvas buf  */
  apply_mask_to_region (&srcPR, &maskPR, OPAQUE_OPACITY);
}

static void
ink_set_undo_tiles (drawable, x, y, w, h)
     GimpDrawable *drawable;
     int x, y;
     int w, h;
{
  int i, j;
  Tile *src_tile;
  Tile *dest_tile;

  for (i = y; i < (y + h); i += (TILE_HEIGHT - (i % TILE_HEIGHT)))
    {
      for (j = x; j < (x + w); j += (TILE_WIDTH - (j % TILE_WIDTH)))
	{
1189
	  dest_tile = tile_manager_get_tile (undo_tiles, j, i, FALSE, FALSE);
scott's avatar
scott committed
1190
	  if (tile_is_valid (dest_tile) == FALSE)
1191
	    {
1192 1193
	      src_tile = tile_manager_get_tile (drawable_data (drawable), j, i, TRUE, FALSE);
	      tile_manager_map_tile (undo_tiles, j, i, src_tile);
1194
	      tile_release (src_tile, FALSE);
1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212
	    }
	}
    }
}


static void
ink_set_canvas_tiles (x, y, w, h)
     int x, y;
     int w, h;
{
  int i, j;
  Tile *tile;

  for (i = y; i < (y + h); i += (TILE_HEIGHT - (i % TILE_HEIGHT)))
    {
      for (j = x; j < (x + w); j += (TILE_WIDTH - (j % TILE_WIDTH)))
	{
1213
	  tile = tile_manager_get_tile (canvas_tiles, j, i, FALSE, FALSE);
scott's avatar
scott committed
1214
	  if (tile_is_valid (tile) == FALSE)
1215
	    {
1216
	      tile = tile_manager_get_tile (canvas_tiles, j, i, TRUE, TRUE);
scott's avatar
scott committed
1217 1218 1219
	      memset (tile_data_pointer (tile, 0, 0), 
		      0, 
		      tile_size (tile));
1220
	      tile_release (tile, TRUE);
1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283
	    }
	}
    }
}

/****************************/
/*  Global ink functions  */
/****************************/

void
ink_no_draw (Tool *tool)
{
  return;
}

Tool *
tools_new_ink ()
{
  Tool * tool;
  InkTool * private;

  if (! ink_options)
    ink_options = create_ink_options ();

  tool = (Tool *) g_malloc (sizeof (Tool));
  private = (InkTool *) g_malloc (sizeof (InkTool));

  private->core = draw_core_new (ink_no_draw);
  private->last_blob = NULL;

  tool->type = INK;
  tool->state = INACTIVE;
  tool->scroll_lock = 0;  /*  Allow scrolling  */
  tool->auto_snap_to = TRUE;
  tool->gdisp_ptr = NULL;
  tool->private = private;
  tool->preserve = TRUE;

  tool->button_press_func = ink_button_press;
  tool->button_release_func = ink_button_release;
  tool->motion_func = ink_motion;
  tool->arrow_keys_func = standard_arrow_keys_func;
  tool->cursor_update_func = ink_cursor_update;
  tool->control_func = ink_control;

  return tool;
}

void
tools_free_ink (Tool *tool)
{
  InkTool * ink_tool;

  ink_tool = (InkTool *) tool->private;

  /*  Make sure the selection core is not visible  */
  if (tool->state == ACTIVE && ink_tool->core)
    draw_core_stop (ink_tool->core, tool);

  /*  Free the selection core  */
  if (ink_tool->core)
    draw_core_free (ink_tool->core);

1284 1285 1286 1287
  /*  Free the last blob, if any */
  if (ink_tool->last_blob)
    g_free (ink_tool->last_blob);
  
1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347
  /*  Cleanup memory  */
  ink_cleanup ();

  /*  Free the paint core  */
  g_free (ink_tool);
}


/*  The ink procedure definition  */
ProcArg ink_args[] =
{
  { PDB_IMAGE,
    "image",
    "the image"
  },
  { PDB_DRAWABLE,
    "drawable",
    "the drawable"
  },
  { PDB_INT32,
    "num_strokes",
    "number of stroke control points (count each coordinate as 2 points)"
  },
  { PDB_FLOATARRAY,
    "strokes",
    "array of stroke coordinates: {s1.x, s1.y, s2.x, s2.y, ..., sn.x, sn.y}"
  }
};


ProcRecord ink_proc =
{
  "gimp_ink",
  "Paint in the current brush without sub-pixel sampling",
  "fixme fixme",
  "Spencer Kimball & Peter Mattis",
  "Spencer Kimball & Peter Mattis",
  "1995-1996",
  PDB_INTERNAL,

  /*  Input arguments  */
  4,
  ink_args,

  /*  Output arguments  */
  0,
  NULL,

  /*  Exec method  */
  { { ink_invoker } },
};

static Argument *
ink_invoker (args)
     Argument *args;
{
  /* Fix me */
  return NULL;
}