gradient_editor.c 150 KB
Newer Older
Elliot Lee's avatar
Elliot Lee committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/* The GIMP -- an image manipulation program
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
 * Gradient editor module copyight (C) 1996-1997 Federico Mena Quintero
 * federico@nuclecu.unam.mx
 *
 * 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 PURIGHTE.  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
19
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Elliot Lee's avatar
Elliot Lee committed
20 21
 */

22 23 24
/* alt: Added previews and some other buttons to gradient dialog. 
 *
 * hof: Hofer Wolfgang, 1998.01.27   avoid resize bug by keeping 
25 26 27 28
 *                                   preview widgetsize constant.
 * hof: Hofer Wolfgang, 1997.10.17   Added "Load From FG color"
 */

Elliot Lee's avatar
Elliot Lee committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
/* Release date: 1997/06/02
 *
 * - Added the following procedural_db calls:
 *     gimp_gradients_get_list
 *     gimp_gradients_get_active
 *     gimp_gradients_set_active
 *     gimp_gradients_sample_uniform
 *     gimp_gradients_sample_custom
 *   Many thanks to Eiichi and Marcelo for their suggestions!
 */

/* Release date: 1997/05/07
 *
 * - Added accelerator keys for the popup functions.  This allows for
 * very fast operation of the editor.
 *
 * - Added Replicate Selection function.
 *
 * - Re-arranged the pop-up menu a bit; it was getting too big.  I am
 * still not entirely happy with it.
 *
 * - Added grad_dump_gradient(); it is useful for debugging.
 */

/* Release date: 1997/04/30
 *
 * - All `dangerous' dialogs now de-sensitize the main editor window.
 * This fixes a lot of potential bugs when the dialogs are active.
 *
 * - Fixed two bugs due to uninitialized variables, one in
 * prev_events() (thanks to Marcelo for pointing it out) and another
 * in cpopup_render_color_box() (me), and removed all warnings due to
 * those.
 *
 * - Removed the printf()'s in the pop-up menu (they were only used
 * for debugging).
 */

/* Release date: 1997/04/22
 *
 * - Added GtkRadioMenuItems to the blending and coloring pop-up
 * menus.  You no longer have to remember the dang type for each
 * segment.
 *
 * - Added midpoint capabilities to sinuosidal and spherical sigments.
 * Many thanks to Marcelo for the patches!
 *
 * - Added a *real* Cancel function to the color pickers.  I don't
 * know why nobody killed me for not having done it before.
 */

/* Release date: 1997/04/21
 *
 * - Re-wrote the old pop-up menu code, which was *horrible*.  The
 * memory leaks *should* go away once I write
 * grad_free_gradient_editor().  I'll do it once I'm finished adding
 * crap to gradient_editor_t.
 *
 * - Added "fetch from" color buttons.  Yeah, we all missed them.  You
 * should shed happiness tears when you see it.
 *
 * - Added an eyedropper function to the preview widget.  You can now
 * click on the preview widget and the foreground color will be set to
 * the gradient's color under the cursor.  This is still missing the
 * eyedropper cursor shape.
 *
 * - You can now invoke the pop-up menu from the preview widget.  Even
 * my hand gets unsteady at times.
 *
 * - Cool functions: Flip selection, Blend colors.  Can't live without
 * them.
 */

/* Special thanks to:
 *
 * Luis Albarran (luis4@mindspring.com) - Nice UI suggestions
 *
 * Miguel de Icaza (miguel@nuclecu.unam.mx) - Pop-up menu suggestion
 *
 * Marcelo Malheiros (malheiro@dca.fee.unicamp.br) - many, many
 * suggestions, nice gradient files
 *
 * Adam Moss (adam@uunet.pipex.com) - idea for the hint bar
 *
 * Everyone on #gimp - many suggestions
 */

/* TODO:
 *
 * - Fix memory leaks: grad_free_gradient_editor() and any others
 * which I may have missed.
 *
 * - Add all of Marcelo's neat suggestions:
 *   - Hue rotate, saturation, brightness, contrast.
 *
 * - Add Save Dirty Gradients function.
 *
 * - Add Reload function.
 *
 * - See that the default-gradient really gets selected on startup.
 *
 * - Provide a way of renaming a gradient (instead of having to do
 *   copy/delete).
 *
 * - Fix the flicker in the hint bar.
 *
 * - Maybe add a little preview of each gradient to the listbox?
 *
 * - Better handling of bogus gradient files and inconsistent
 *   segments.  Do not loop indefinitely in seg_get_segment_at() if
 *   there is a missing segment between two others.
 *
 * - Add a Gradient brush mode (color changes as you move it).
 */

144
#include "config.h"
Elliot Lee's avatar
Elliot Lee committed
145 146 147 148 149

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
150
#ifdef HAVE_UNISTD_H
Elliot Lee's avatar
Elliot Lee committed
151
#include <unistd.h>
152
#endif
Elliot Lee's avatar
Elliot Lee committed
153

154
#include "actionarea.h"
Elliot Lee's avatar
Elliot Lee committed
155 156 157 158 159 160 161 162 163 164
#include "appenv.h"
#include "colormaps.h"
#include "cursorutil.h"
#include "datafiles.h"
#include "errors.h"
#include "general.h"
#include "gimprc.h"
#include "gradient.h"
#include "interface.h"
#include "palette.h"
165
#include "session.h"
166
#include "gradient_header.h"
Elliot Lee's avatar
Elliot Lee committed
167

168 169
#include "libgimp/gimpintl.h"

170 171 172
#include "pixmaps/zoom_in.xpm"
#include "pixmaps/zoom_out.xpm"

Elliot Lee's avatar
Elliot Lee committed
173 174
/***** Magic numbers *****/

Manish Singh's avatar
Manish Singh committed
175 176 177 178
#ifndef M_PI
#define M_PI    3.14159265358979323846
#endif /* M_PI */

Elliot Lee's avatar
Elliot Lee committed
179 180 181 182 183 184
#define EPSILON 1e-10


/***** Local functions *****/

/* Gradient editor functions */
185 186 187 188 189 190 191
static GtkWidget *ed_create_button (gchar *label,
				    double xalign, double yalign,
				    GtkSignalFunc signal_func,
				    gpointer user_data);

static void  ed_fetch_foreground (double *fg_r, double *fg_g, double *fg_b,
				  double *fg_a);
192
static void  ed_update_editor    (int flags);
193

194
static void  ed_set_hint         (gchar *str);
195 196 197 198 199 200 201 202 203 204


static void  ed_list_item_update (GtkWidget *widget, 
				  gint row,
				  gint column,
				  GdkEventButton *event,
				  gpointer data);

static void  ed_initialize_saved_colors (void);

205
/* Main dialog button callbacks & functions */
206

207 208
static void  ed_new_gradient_callback       (GtkWidget *, gpointer);
static void  ed_do_new_gradient_callback    (GtkWidget *, gpointer , gpointer);
209

210 211
static void  ed_copy_gradient_callback      (GtkWidget *, gpointer);
static void  ed_do_copy_gradient_callback   (GtkWidget *, gpointer , gpointer);
212 213 214 215 216 217 218 219 220 221

static void  ed_delete_gradient_callback        (GtkWidget *, gpointer);
static void  ed_do_delete_gradient_callback     (GtkWidget *, gpointer);
static void  ed_cancel_delete_gradient_callback (GtkWidget *, gpointer);
static gint  ed_delete_delete_gradient_callback (GtkWidget *, GdkEvent *,
						 gpointer);

static void  ed_rename_gradient_callback    (GtkWidget *, gpointer);
static void  ed_do_rename_gradient_callback (GtkWidget *, gpointer, gpointer);

222 223 224 225
static void  ed_save_pov_callback           (GtkWidget *, gpointer);
static void  ed_do_save_pov_callback        (GtkWidget *, gpointer);
static void  ed_cancel_save_pov_callback    (GtkWidget *, gpointer);
static gint  ed_delete_save_pov_callback    (GtkWidget *, GdkEvent *, gpointer);
226

227 228 229 230 231 232 233
static void  ed_save_grads_callback         (GtkWidget *, gpointer);
static void  ed_refresh_grads_callback      (GtkWidget *, gpointer);

static gint  ed_delete_callback             (GtkWidget *, GdkEvent *, gpointer);
static void  ed_close_callback              (GtkWidget *, gpointer);

/* Zoom, scrollbar & instant update callbacks */
234 235 236 237 238 239

static void  ed_scrollbar_update      (GtkAdjustment *, gpointer);
static void  ed_zoom_all_callback     (GtkWidget *, gpointer);
static void  ed_zoom_out_callback     (GtkWidget *, gpointer);
static void  ed_zoom_in_callback      (GtkWidget *, gpointer);
static void  ed_instant_update_update (GtkWidget *, gpointer);
Elliot Lee's avatar
Elliot Lee committed
240 241 242

/* Gradient preview functions */

243 244
static gint prev_events         (GtkWidget *, GdkEvent *, gpointer);
static void prev_set_hint       (gint x);
245 246 247 248

static void prev_set_foreground (gint x);
static void prev_set_background (gint x);

249 250 251
static void prev_update         (gboolean recalculate);
static void prev_fill_image     (int width, int height,
				 double left, double right);
Elliot Lee's avatar
Elliot Lee committed
252 253 254

/* Gradient control functions */

255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
static gint   control_events                (GtkWidget *, GdkEvent *, gpointer);
static void   control_do_hint               (gint x, gint y);
static void   control_button_press          (gint x, gint y,
					     guint button, guint state);
static int    control_point_in_handle       (gint x, gint y, grad_segment_t *seg,
					     control_drag_mode_t handle);
static void   control_select_single_segment (grad_segment_t *seg);
static void   control_extend_selection      (grad_segment_t *seg, double pos);
static void   control_motion                (gint x);

static void   control_compress_left         (grad_segment_t *range_l,
					     grad_segment_t *range_r,
					     grad_segment_t *drag_seg,
					     double pos);
static void   control_compress_range        (grad_segment_t *range_l,
					     grad_segment_t *range_r,
					     double new_l, double new_r);

static double control_move                  (grad_segment_t *range_l,
					     grad_segment_t *range_r,
					     double delta);

/* Control update/redraw functions */

static void   control_update             (gboolean recalculate);
static void   control_draw               (GdkPixmap *pixmap,
					  int width, int height,
					  double left, double right);
static void   control_draw_normal_handle (GdkPixmap *pixmap,
					  double pos, int height);
static void   control_draw_middle_handle (GdkPixmap *pixmap,
					  double pos, int height);
static void   control_draw_handle        (GdkPixmap *pixmap,
					  GdkGC *border_gc, GdkGC *fill_gc,
					  int xpos, int height);

static int    control_calc_p_pos         (double pos);
static double control_calc_g_pos         (int pos);
Elliot Lee's avatar
Elliot Lee committed
293 294 295

/* Control popup functions */

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 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 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 408 409 410 411 412 413 414 415
static void       cpopup_create_main_menu  (void);
static void       cpopup_do_popup          (void);

static GtkWidget *cpopup_create_color_item           (GtkWidget **color_box,
						      GtkWidget **label);
static GtkWidget *cpopup_create_menu_item_with_label (gchar      *str,
						      GtkWidget **label);

static void  cpopup_adjust_menus           (void);
static void  cpopup_adjust_blending_menu   (void);
static void  cpopup_adjust_coloring_menu   (void);
static void  cpopup_check_selection_params (gint *equal_blending,
					    gint *equal_coloring);

static void  cpopup_render_color_box (GtkPreview *preview,
				      double r, double g, double b, double a);

static GtkWidget *cpopup_create_load_menu (GtkWidget **color_boxes,
					   GtkWidget **labels,
					   gchar *label1, gchar *label2,
					   GtkSignalFunc callback,
					   gchar accel_key_0,
					   guint8 accel_mods_0,
					   gchar accel_key_1,
					   guint8 accel_mods_1,
					   gchar accel_key_2,
					   guint8 accel_mods_2);
static GtkWidget *cpopup_create_save_menu (GtkWidget **color_boxes,
					   GtkWidget **labels,
					   GtkSignalFunc callback);

static void  cpopup_update_saved_color  (int n,
					 double r, double g, double b, double a);

static void  cpopup_load_left_callback  (GtkWidget *, gpointer);
static void  cpopup_save_left_callback  (GtkWidget *, gpointer);
static void  cpopup_load_right_callback (GtkWidget *, gpointer);
static void  cpopup_save_right_callback (GtkWidget *, gpointer);

static void  cpopup_set_color_selection_color (GtkColorSelection *cs,
					       double r, double g,
					       double b, double a);
static void  cpopup_get_color_selection_color (GtkColorSelection *cs,
					       double *r, double *g,
					       double *b, double *a);

static grad_segment_t *cpopup_save_selection    (void);
static void            cpopup_free_selection    (grad_segment_t *seg);
static void            cpopup_replace_selection (grad_segment_t *replace_seg);

/* ----- */

static void  cpopup_create_color_dialog (gchar *title,
					 double r, double g, double b, double a,
					 GtkSignalFunc color_changed_callback,
					 GtkSignalFunc ok_callback,
					 GtkSignalFunc cancel_callback,
					 GtkSignalFunc delete_callback);

static void  cpopup_set_left_color_callback  (GtkWidget *, gpointer);
static void  cpopup_left_color_changed       (GtkWidget *, gpointer);
static void  cpopup_left_color_dialog_ok     (GtkWidget *, gpointer);
static void  cpopup_left_color_dialog_cancel (GtkWidget *, gpointer);
static int   cpopup_left_color_dialog_delete (GtkWidget *, GdkEvent *,
					      gpointer);

static void  cpopup_set_right_color_callback  (GtkWidget *, gpointer);
static void  cpopup_right_color_changed       (GtkWidget *, gpointer);
static void  cpopup_right_color_dialog_ok     (GtkWidget *, gpointer);
static void  cpopup_right_color_dialog_cancel (GtkWidget *, gpointer);
static int   cpopup_right_color_dialog_delete (GtkWidget *, GdkEvent *,
					       gpointer);

/* ----- */

static GtkWidget *cpopup_create_blending_menu (void);
static void       cpopup_blending_callback    (GtkWidget *, gpointer);
static GtkWidget *cpopup_create_coloring_menu (void);
static void       cpopup_coloring_callback    (GtkWidget *, gpointer);

/* ----- */

static void  cpopup_split_midpoint_callback (GtkWidget *, gpointer);
static void  cpopup_split_midpoint (grad_segment_t *lseg, grad_segment_t **newl,
				    grad_segment_t **newr);

static void  cpopup_split_uniform_callback        (GtkWidget *, gpointer);
static void  cpopup_split_uniform_scale_update    (GtkAdjustment *, gpointer);
static void  cpopup_split_uniform_split_callback  (GtkWidget *, gpointer);
static void  cpopup_split_uniform_cancel_callback (GtkWidget *, gpointer);
static gint  cpopup_split_uniform_delete_callback (GtkWidget *, GdkEvent *,
						   gpointer);
static void  cpopup_split_uniform (grad_segment_t *lseg, int parts,
				   grad_segment_t **newl, grad_segment_t **newr);

static void  cpopup_delete_callback       (GtkWidget *, gpointer);
static void  cpopup_recenter_callback     (GtkWidget *, gpointer);
static void  cpopup_redistribute_callback (GtkWidget *, gpointer);

/* Control popup -> Selection operations functions */

static GtkWidget * cpopup_create_sel_ops_menu (void);

static void  cpopup_flip_callback             (GtkWidget *, gpointer);

static void  cpopup_replicate_callback        (GtkWidget *, gpointer);
static void  cpopup_replicate_scale_update    (GtkAdjustment *, gpointer);
static void  cpopup_do_replicate_callback     (GtkWidget *, gpointer);
static void  cpopup_replicate_cancel_callback (GtkWidget *, gpointer);
static gint  cpopup_replicate_delete_callback (GtkWidget *, GdkEvent *,
					       gpointer);

static void  cpopup_blend_colors              (GtkWidget *, gpointer);
static void  cpopup_blend_opacity             (GtkWidget *, gpointer);

/* Blend function */

static void  cpopup_blend_endpoints (double r0, double g0, double b0, double a0,
				     double r1, double g1, double b1, double a1,
				     int blend_colors, int blend_opacity);
Elliot Lee's avatar
Elliot Lee committed
416 417 418

/* Gradient functions */

419 420 421 422 423 424 425
static gradient_t *grad_new_gradient             (void);
static void        grad_free_gradient            (gradient_t *grad);
static void        grad_free_gradients           (void);
static void        grad_load_gradient            (char *filename);
static void        grad_save_gradient            (gradient_t *grad,
						  char *filename);
static void        grad_save_all                 (int need_free);
Elliot Lee's avatar
Elliot Lee committed
426

427
static gradient_t *grad_create_default_gradient  (void);
Elliot Lee's avatar
Elliot Lee committed
428

429
static int         grad_insert_in_gradients_list (gradient_t *grad);
Elliot Lee's avatar
Elliot Lee committed
430

431
static void        grad_dump_gradient            (gradient_t *grad, FILE *file);
432

Elliot Lee's avatar
Elliot Lee committed
433 434 435

/* Segment functions */

436 437 438
static grad_segment_t *seg_new_segment        (void);
static void            seg_free_segment       (grad_segment_t *seg);
static void            seg_free_segments      (grad_segment_t *seg);
Elliot Lee's avatar
Elliot Lee committed
439

440 441 442 443 444
static grad_segment_t *seg_get_segment_at     (gradient_t *grad, double pos);
static grad_segment_t *seg_get_last_segment   (grad_segment_t *seg);
static void            seg_get_closest_handle (gradient_t *grad, double pos,
					       grad_segment_t **seg,
					       control_drag_mode_t *handle);
Elliot Lee's avatar
Elliot Lee committed
445 446 447

/* Calculation functions */

448 449 450 451 452
static double calc_linear_factor            (double middle, double pos);
static double calc_curved_factor            (double middle, double pos);
static double calc_sine_factor              (double middle, double pos);
static double calc_sphere_increasing_factor (double middle, double pos);
static double calc_sphere_decreasing_factor (double middle, double pos);
Elliot Lee's avatar
Elliot Lee committed
453

454 455
static void   calc_rgb_to_hsv               (double *r, double *g, double *b);
static void   calc_hsv_to_rgb               (double *h, double *s, double *v);
Elliot Lee's avatar
Elliot Lee committed
456 457 458

/* Files and paths functions */

459
static gchar *build_user_filename (char *name, char *path_str);
Elliot Lee's avatar
Elliot Lee committed
460 461 462

/***** Local variables *****/

463 464 465 466 467 468
GdkColor            black;
gint                num_gradients         = 0;
gradient_t        * curr_gradient         = NULL; /* The active gradient */
GSList            * gradients_list        = NULL; /* The list of gradients */
gradient_t        * grad_default_gradient = NULL;
gradient_editor_t * g_editor              = NULL; /* The gradient editor */
Elliot Lee's avatar
Elliot Lee committed
469

470 471 472 473 474 475 476 477
static const gchar *blending_types[] =
{
  N_("Linear"),
  N_("Curved"),
  N_("Sinusoidal"),
  N_("Spherical (increasing)"),
  N_("Spherical (decreasing)")
};
Elliot Lee's avatar
Elliot Lee committed
478

479 480 481 482 483 484
static const gchar *coloring_types[] =
{
  N_("Plain RGB"),
  N_("HSV (counter-clockwise hue)"),
  N_("HSV (clockwise hue)")
};
Elliot Lee's avatar
Elliot Lee committed
485 486 487 488 489 490

/***** Public functions *****/

/*****/

void
491
gradients_init (int no_data)
Elliot Lee's avatar
Elliot Lee committed
492
{
493 494
  if (!no_data)
    datafiles_read_directories (gradient_path, grad_load_gradient, 0);
Elliot Lee's avatar
Elliot Lee committed
495

496 497 498 499 500

  if (grad_default_gradient != NULL)
    curr_gradient = grad_default_gradient;
  else if (gradients_list != NULL)
    curr_gradient = (gradient_t *) gradients_list->data;
501 502 503 504 505 506 507
  else
    {
      curr_gradient = grad_create_default_gradient ();
      curr_gradient->name     = g_strdup (_("Default"));
      curr_gradient->filename =
	build_user_filename (curr_gradient->name, gradient_path);
      curr_gradient->dirty    = FALSE;
Elliot Lee's avatar
Elliot Lee committed
508

509 510 511
      grad_insert_in_gradients_list (curr_gradient);
    }
}
Elliot Lee's avatar
Elliot Lee committed
512 513 514 515

/*****/

void
516
gradients_free (void)
Elliot Lee's avatar
Elliot Lee committed
517
{
518 519
  grad_free_gradients ();
}
Elliot Lee's avatar
Elliot Lee committed
520 521 522 523

/*****/

void
524 525
grad_get_color_at (double pos,
		   double *r, double *g, double *b, double *a)
Elliot Lee's avatar
Elliot Lee committed
526
{
527 528 529 530 531
  double          factor = 0.0;
  grad_segment_t *seg;
  double          seg_len, middle;
  double          h0, s0, v0;
  double          h1, s1, v1;
Elliot Lee's avatar
Elliot Lee committed
532

533 534 535 536 537 538
  /* if there is no gradient return a totally transparent black */
  if (curr_gradient == NULL) 
    {
      r = 0; g = 0; b = 0; a = 0;
      return;
    }
Elliot Lee's avatar
Elliot Lee committed
539

540 541 542 543
  if (pos < 0.0)
    pos = 0.0;
  else if (pos > 1.0)
    pos = 1.0;
Elliot Lee's avatar
Elliot Lee committed
544

545
  seg = seg_get_segment_at (curr_gradient, pos);
Elliot Lee's avatar
Elliot Lee committed
546

547
  seg_len = seg->right - seg->left;
Elliot Lee's avatar
Elliot Lee committed
548

549 550 551 552 553 554 555 556 557 558
  if (seg_len < EPSILON)
    {
      middle = 0.5;
      pos    = 0.5;
    }
  else
    {
      middle = (seg->middle - seg->left) / seg_len;
      pos    = (pos - seg->left) / seg_len;
    }
Elliot Lee's avatar
Elliot Lee committed
559

560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587
  switch (seg->type)
    {
    case GRAD_LINEAR:
      factor = calc_linear_factor (middle, pos);
      break;

    case GRAD_CURVED:
      factor = calc_curved_factor (middle, pos);
      break;

    case GRAD_SINE:
      factor = calc_sine_factor (middle, pos);
      break;

    case GRAD_SPHERE_INCREASING:
      factor = calc_sphere_increasing_factor (middle, pos);
      break;

    case GRAD_SPHERE_DECREASING:
      factor = calc_sphere_decreasing_factor (middle, pos);
      break;

    default:
      grad_dump_gradient (curr_gradient, stderr);
      gimp_fatal_error (_("grad_get_color_at(): Unknown gradient type %d"),
			(int) seg->type);
      break;
    }
Elliot Lee's avatar
Elliot Lee committed
588

589
  /* Calculate color components */
Elliot Lee's avatar
Elliot Lee committed
590

591
  *a = seg->a0 + (seg->a1 - seg->a0) * factor;
Elliot Lee's avatar
Elliot Lee committed
592

593 594 595 596 597 598 599 600 601 602 603
  if (seg->color == GRAD_RGB)
    {
      *r = seg->r0 + (seg->r1 - seg->r0) * factor;
      *g = seg->g0 + (seg->g1 - seg->g0) * factor;
      *b = seg->b0 + (seg->b1 - seg->b0) * factor;
    }
  else
    {
      h0 = seg->r0;
      s0 = seg->g0;
      v0 = seg->b0;
Elliot Lee's avatar
Elliot Lee committed
604

605 606 607
      h1 = seg->r1;
      s1 = seg->g1;
      v1 = seg->b1;
Elliot Lee's avatar
Elliot Lee committed
608

609 610
      calc_rgb_to_hsv(&h0, &s0, &v0);
      calc_rgb_to_hsv(&h1, &s1, &v1);
Elliot Lee's avatar
Elliot Lee committed
611

612 613
      s0 = s0 + (s1 - s0) * factor;
      v0 = v0 + (v1 - v0) * factor;
Elliot Lee's avatar
Elliot Lee committed
614

615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644
      switch (seg->color)
	{
	case GRAD_HSV_CCW:
	  if (h0 < h1)
	    h0 = h0 + (h1 - h0) * factor;
	  else
	    {
	      h0 = h0 + (1.0 - (h0 - h1)) * factor;
	      if (h0 > 1.0)
		h0 -= 1.0;
	    }
	  break;

	case GRAD_HSV_CW:
	  if (h1 < h0)
	    h0 = h0 - (h0 - h1) * factor;
	  else
	    {
	      h0 = h0 - (1.0 - (h1 - h0)) * factor;
	      if (h0 < 0.0)
		h0 += 1.0;
	    }
	  break;

	default:
	  grad_dump_gradient (curr_gradient, stderr);
	  gimp_fatal_error (_("grad_get_color_at(): Unknown coloring mode %d"),
			    (int) seg->color);
	  break;
	}
Elliot Lee's avatar
Elliot Lee committed
645

646 647 648
      *r = h0;
      *g = s0;
      *b = v0;
Elliot Lee's avatar
Elliot Lee committed
649

650 651 652
      calc_hsv_to_rgb (r, g, b);
    }
}
Elliot Lee's avatar
Elliot Lee committed
653

654
/***** The main gradient editor dialog *****/
Elliot Lee's avatar
Elliot Lee committed
655 656 657

/*****/

658
void 
659
grad_create_gradient_editor_init (gint need_show)
Elliot Lee's avatar
Elliot Lee committed
660
{
661 662 663 664 665 666 667
  GtkWidget *vbox;
  GtkWidget *hbox;
  GtkWidget *gvbox;
  GtkWidget *button;
  GtkWidget *frame;
  GtkWidget *scrolled_win;
  GdkColormap *colormap;
668 669 670 671
  GtkWidget* pixmapwid;
  GdkPixmap* pixmap;
  GdkBitmap* mask;
  GtkStyle* style;
672 673 674
  gint i;
  gint select_pos;

675 676 677 678 679 680
  static ActionAreaItem action_items[] =
  {
    { N_("Save"), ed_save_grads_callback, NULL, NULL },
    { N_("Refresh"), ed_refresh_grads_callback, NULL, NULL },
    { N_("Close"), ed_close_callback, NULL, NULL }
  };
681

682
  /* If the editor already exists, just show it */
683 684
  if (g_editor)
    {
685
      if (!GTK_WIDGET_VISIBLE (g_editor->shell))
686 687 688 689 690
	{
	  gtk_widget_show (g_editor->shell);
	  /* Do this because os a proble with scrolling
	   * clists when not visible on screen.
	   */
691
	  grad_set_grad_to_name (curr_gradient->name);
692 693 694
	}
      else
	gdk_window_raise (g_editor->shell->window);
Elliot Lee's avatar
Elliot Lee committed
695

696 697
      return;
    }
Elliot Lee's avatar
Elliot Lee committed
698

699 700 701
  /* Create editor */
  if (no_data)
    gradients_init (FALSE);
702
  g_editor = g_new (gradient_editor_t, 1);
Elliot Lee's avatar
Elliot Lee committed
703

704
  /* Shell and main vbox */
705
  g_editor->shell = gtk_dialog_new ();
706 707
  gtk_window_set_wmclass (GTK_WINDOW (g_editor->shell),
			  "gradient_editor", "Gimp");
708
  gtk_window_set_title (GTK_WINDOW (g_editor->shell), _("Gradient Editor"));
709

710
  /* Handle the wm delete event */
711
  gtk_signal_connect (GTK_OBJECT (g_editor->shell), "delete_event",
712
		      GTK_SIGNAL_FUNC (ed_delete_callback),
713
		      NULL);
Elliot Lee's avatar
Elliot Lee committed
714

715 716 717
  vbox = gtk_vbox_new (FALSE, 4);
  gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
  gtk_container_add (GTK_CONTAINER (GTK_DIALOG (g_editor->shell)->vbox), vbox);
718
  gtk_widget_show (vbox);
Elliot Lee's avatar
Elliot Lee committed
719

720
  /* Gradients list box */
721
  hbox = gtk_hbox_new (FALSE, 4);
722 723
  gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
  gtk_widget_show (hbox);
Elliot Lee's avatar
Elliot Lee committed
724

725 726
  /* clist preview of gradients */
  scrolled_win = gtk_scrolled_window_new (NULL, NULL);
727

728 729
  g_editor->clist = gtk_clist_new (2);
  gtk_clist_set_shadow_type (GTK_CLIST (g_editor->clist), GTK_SHADOW_IN);
730

731
  gtk_clist_set_row_height (GTK_CLIST (g_editor->clist), 18);
732

733 734 735 736
  gtk_clist_set_column_width (GTK_CLIST (g_editor->clist), 0, 52);
  gtk_clist_set_column_title (GTK_CLIST (g_editor->clist), 0, _("Gradient"));
  gtk_clist_set_column_title (GTK_CLIST (g_editor->clist), 1, _("Name"));
  gtk_clist_column_titles_show (GTK_CLIST (g_editor->clist));
737

738 739 740 741 742
  gtk_box_pack_start (GTK_BOX (hbox), scrolled_win, TRUE, TRUE, 0); 
  gtk_container_add (GTK_CONTAINER (scrolled_win), g_editor->clist);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
				  GTK_POLICY_AUTOMATIC,
				  GTK_POLICY_ALWAYS);
743

744 745
  gtk_widget_show (scrolled_win);
  gtk_widget_show (g_editor->clist);
746

747 748 749
  colormap = gtk_widget_get_colormap (g_editor->clist);
  gdk_color_parse ("black", &black);
  gdk_color_alloc (colormap, &black);
750
	
751 752 753 754
  gtk_signal_connect (GTK_OBJECT (g_editor->clist), "select_row",
		      GTK_SIGNAL_FUNC (ed_list_item_update),
		      (gpointer) NULL);

755 756 757
  /* Frame & vbox for gradient functions */
  frame = gtk_frame_new (_("Gradient Ops"));
  gtk_box_pack_end (GTK_BOX (hbox), frame, FALSE, FALSE, 0);
758

759 760 761
  gvbox = gtk_vbox_new (FALSE, 2);
  gtk_container_set_border_width (GTK_CONTAINER (gvbox), 4);
  gtk_container_add (GTK_CONTAINER (frame), gvbox);
762 763

  /* Buttons for gradient functions */
764
  button = ed_create_button (_("New Gradient"), 0.5, 0.5,
765
			     (GtkSignalFunc) ed_new_gradient_callback, NULL);
766
  GTK_WIDGET_UNSET_FLAGS (button, GTK_RECEIVES_DEFAULT);
767
  gtk_box_pack_start (GTK_BOX (gvbox), button, FALSE, FALSE, 0);
768 769
  gtk_widget_show (button);

770
  button = ed_create_button (_("Copy Gradient"), 0.5, 0.5,
771
			     (GtkSignalFunc) ed_copy_gradient_callback, NULL);
772
  GTK_WIDGET_UNSET_FLAGS (button, GTK_RECEIVES_DEFAULT);
773
  gtk_box_pack_start (GTK_BOX (gvbox), button, FALSE, FALSE, 0);
774 775
  gtk_widget_show (button);

776
  button = ed_create_button (_("Delete Gradient"), 0.5, 0.5,
777
			     (GtkSignalFunc) ed_delete_gradient_callback, NULL);
778
  GTK_WIDGET_UNSET_FLAGS (button, GTK_RECEIVES_DEFAULT);
779
  gtk_box_pack_start (GTK_BOX (gvbox), button, FALSE, FALSE, 0);
780 781
  gtk_widget_show (button);

782 783
  button = ed_create_button (_("Rename Gradient"), 0.5, 0.5,
			     (GtkSignalFunc) ed_rename_gradient_callback, NULL);
784
  GTK_WIDGET_UNSET_FLAGS (button, GTK_RECEIVES_DEFAULT);
785
  gtk_box_pack_start (GTK_BOX (gvbox), button, FALSE, FALSE, 0);
786 787
  gtk_widget_show (button);

788 789
  button = ed_create_button (_("Save as POV-Ray"), 0.5, 0.5,
			     (GtkSignalFunc) ed_save_pov_callback, NULL);
790
  GTK_WIDGET_UNSET_FLAGS (button, GTK_RECEIVES_DEFAULT);
791
  gtk_box_pack_start (GTK_BOX (gvbox), button, FALSE, FALSE, 0);
792 793
  gtk_widget_show (button);

794 795
  gtk_widget_show (gvbox);
  gtk_widget_show (frame);
796

797
  /*  Horizontal box for zoom controls, scrollbar and instant update toggle  */
798
  hbox = gtk_hbox_new (FALSE, 4);
799
  gtk_container_set_border_width (GTK_CONTAINER (hbox), 0);
800
  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
801 802
  gtk_widget_show (hbox);

803
  /*  Zoom all button */
804 805
  button = ed_create_button (_("Zoom all"), 0.5, 0.5,
			     (GtkSignalFunc) ed_zoom_all_callback, g_editor);
806
  GTK_WIDGET_UNSET_FLAGS (button, GTK_RECEIVES_DEFAULT);
807 808 809
  gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
  gtk_widget_show (button);

810 811 812 813 814 815 816 817 818
  /*  + and - buttons  */
  gtk_widget_realize (g_editor->shell);
  style = gtk_widget_get_style (g_editor->shell);

  button = gtk_button_new ();
  GTK_WIDGET_UNSET_FLAGS (button, GTK_RECEIVES_DEFAULT);
  gtk_signal_connect (GTK_OBJECT (button), "clicked",
		      GTK_SIGNAL_FUNC (ed_zoom_in_callback),
		      (gpointer) g_editor);
819 820
  gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);

821 822 823 824 825 826 827 828 829 830 831 832 833
  pixmap = gdk_pixmap_create_from_xpm_d (g_editor->shell->window, &mask,
					 &style->bg[GTK_STATE_NORMAL], 
					 zoom_in_xpm);
  pixmapwid = gtk_pixmap_new (pixmap, mask);
  gtk_container_add (GTK_CONTAINER (button), pixmapwid);
  gtk_widget_show (pixmapwid);
  gtk_widget_show (button);

  button = gtk_button_new ();
  GTK_WIDGET_UNSET_FLAGS (button, GTK_RECEIVES_DEFAULT);
  gtk_signal_connect (GTK_OBJECT (button), "clicked",
		      GTK_SIGNAL_FUNC (ed_zoom_out_callback),
		      (gpointer) g_editor);
834
  gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
835 836 837 838 839 840 841

  pixmap = gdk_pixmap_create_from_xpm_d (g_editor->shell->window, &mask,
					 &style->bg[GTK_STATE_NORMAL], 
					 zoom_out_xpm);
  pixmapwid = gtk_pixmap_new (pixmap, mask);
  gtk_container_add (GTK_CONTAINER (button), pixmapwid);
  gtk_widget_show (pixmapwid);
842 843
  gtk_widget_show (button);

844
  /*  Scrollbar  */
845 846 847 848 849 850 851 852 853 854 855 856 857 858
  g_editor->zoom_factor = 1;

  g_editor->scroll_data = gtk_adjustment_new (0.0, 0.0, 1.0,
					      1.0 * GRAD_SCROLLBAR_STEP_SIZE,
					      1.0 * GRAD_SCROLLBAR_PAGE_SIZE,
					      1.0);

  gtk_signal_connect (g_editor->scroll_data, "value_changed",
		      (GtkSignalFunc) ed_scrollbar_update,
		      g_editor);
  gtk_signal_connect (g_editor->scroll_data, "changed",
		      (GtkSignalFunc) ed_scrollbar_update,
		      g_editor);

859 860 861 862 863
  g_editor->scrollbar =
    gtk_hscrollbar_new (GTK_ADJUSTMENT (g_editor->scroll_data));
  gtk_range_set_update_policy (GTK_RANGE (g_editor->scrollbar),
			       GTK_UPDATE_CONTINUOUS);
  gtk_box_pack_start (GTK_BOX (hbox), g_editor->scrollbar, TRUE, TRUE, 0);
864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879
  gtk_widget_show (g_editor->scrollbar);

  /* Instant update toggle */
  g_editor->instant_update = 1;

  button = gtk_check_button_new_with_label (_("Instant update"));
  gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
  gtk_signal_connect (GTK_OBJECT (button), "toggled",
		      (GtkSignalFunc) ed_instant_update_update,
		      g_editor);
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
  gtk_widget_show (button);

  /* Frame for gradient preview and gradient control */
  frame = gtk_frame_new (NULL);
  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
880
  gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
881 882 883 884 885 886 887 888 889 890 891 892 893 894
  gtk_widget_show (frame);

  gvbox = gtk_vbox_new (FALSE, 0);
  gtk_container_add (GTK_CONTAINER (frame), gvbox); 
  gtk_widget_show (gvbox);

  /* Gradient preview */

  g_editor->preview_rows[0]     = NULL;
  g_editor->preview_rows[1]     = NULL;
  g_editor->preview_last_x      = 0;
  g_editor->preview_button_down = 0;

  g_editor->preview = gtk_preview_new (GTK_PREVIEW_COLOR);
895
  gtk_preview_set_dither (GTK_PREVIEW (g_editor->preview), GDK_RGB_DITHER_MAX);
896 897
  gtk_preview_size (GTK_PREVIEW (g_editor->preview),
		    GRAD_PREVIEW_WIDTH, GRAD_PREVIEW_HEIGHT);
898 899 900 901 902 903

  /*  Enable auto-resizing of the preview but ensure a minimal size  */
  gtk_widget_set_usize (g_editor->preview,
			GRAD_PREVIEW_WIDTH, GRAD_PREVIEW_HEIGHT);
  gtk_preview_set_expand (GTK_PREVIEW (g_editor->preview), TRUE);

904 905
  gtk_widget_set_events (g_editor->preview, GRAD_PREVIEW_EVENT_MASK);
  gtk_signal_connect (GTK_OBJECT(g_editor->preview), "event",
906
		      (GdkEventFunc) prev_events,
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 938 939 940 941 942 943 944 945 946
		      g_editor);
  gtk_box_pack_start (GTK_BOX (gvbox), g_editor->preview, TRUE, TRUE, 0);
  gtk_widget_show (g_editor->preview);

  /* Gradient control */

  g_editor->control_pixmap                  = NULL;
  g_editor->control_drag_segment            = NULL;
  g_editor->control_sel_l                   = NULL;
  g_editor->control_sel_r                   = NULL;
  g_editor->control_drag_mode               = GRAD_DRAG_NONE;
  g_editor->control_click_time              = 0;
  g_editor->control_compress                = 0;
  g_editor->control_last_x                  = 0;
  g_editor->control_last_gx                 = 0.0;
  g_editor->control_orig_pos                = 0.0;
  g_editor->control_main_popup              = NULL;
  g_editor->control_blending_label          = NULL;
  g_editor->control_coloring_label          = NULL;
  g_editor->control_splitm_label            = NULL;
  g_editor->control_splitu_label            = NULL;
  g_editor->control_delete_menu_item        = NULL;
  g_editor->control_delete_label            = NULL;
  g_editor->control_recenter_label          = NULL;
  g_editor->control_redistribute_label      = NULL;
  g_editor->control_flip_label              = NULL;
  g_editor->control_replicate_label         = NULL;
  g_editor->control_blend_colors_menu_item  = NULL;
  g_editor->control_blend_opacity_menu_item = NULL;
  g_editor->control_left_load_popup         = NULL;
  g_editor->control_left_save_popup         = NULL;
  g_editor->control_right_load_popup        = NULL;
  g_editor->control_right_save_popup        = NULL;
  g_editor->control_blending_popup          = NULL;
  g_editor->control_coloring_popup          = NULL;
  g_editor->control_sel_ops_popup           = NULL;

  g_editor->accel_group = NULL;

  for (i = 0;
947 948
       i < (sizeof (g_editor->control_blending_items) /
	    sizeof (g_editor->control_blending_items[0]));
949 950 951 952
       i++)
    g_editor->control_blending_items[i] = NULL;

  for (i = 0;
953 954
       i < (sizeof (g_editor->control_coloring_items) /
	    sizeof (g_editor->control_coloring_items[0]));
955 956 957 958 959 960 961 962
       i++)
    g_editor->control_coloring_items[i] = NULL;

  g_editor->control = gtk_drawing_area_new ();
  gtk_drawing_area_size (GTK_DRAWING_AREA (g_editor->control),
			 GRAD_PREVIEW_WIDTH, GRAD_CONTROL_HEIGHT);
  gtk_widget_set_events (g_editor->control, GRAD_CONTROL_EVENT_MASK);
  gtk_signal_connect (GTK_OBJECT (g_editor->control), "event",
963
		      (GdkEventFunc) control_events,
964
		      g_editor);
965
  gtk_box_pack_start (GTK_BOX (gvbox), g_editor->control, TRUE, TRUE, 0);
966 967
  gtk_widget_show (g_editor->control);

968 969 970 971 972 973 974 975
  /* Hint bar and close button */
  g_editor->hint_label = gtk_label_new ("");
  gtk_misc_set_alignment (GTK_MISC (g_editor->hint_label), 0.0, 0.5);
  gtk_box_pack_start (GTK_BOX (vbox), g_editor->hint_label, FALSE, FALSE, 0);
  gtk_widget_show (g_editor->hint_label);

  /* The action area */
  build_action_area (GTK_DIALOG (g_editor->shell), action_items, 3, 2);
976

977
  /* Initialize other data */
978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999
  g_editor->left_color_preview            = NULL;
  g_editor->left_saved_segments           = NULL;
  g_editor->left_saved_dirty              = 0;

  g_editor->right_color_preview           = NULL;
  g_editor->right_saved_segments          = NULL;
  g_editor->right_saved_dirty             = 0;

  ed_initialize_saved_colors();
  cpopup_create_main_menu();

  /* Show everything */
  g_editor->gc = gdk_gc_new (g_editor->shell->window);
  select_pos = ed_set_list_of_gradients (g_editor->gc,
					 g_editor->clist,
					 curr_gradient);

  if (need_show)
    gtk_widget_show (g_editor->shell);

  if (select_pos != -1)
    gtk_clist_moveto (GTK_CLIST (g_editor->clist), select_pos, 0, 0.0, 0.0);
1000
}
Elliot Lee's avatar
Elliot Lee committed
1001 1002 1003 1004


/***** Gradient editor functions *****/

1005 1006
/*****/

1007
static void
1008
ed_fetch_foreground (double *fg_r, double *fg_g, double *fg_b, double *fg_a)
1009
{
1010
  guchar r, g, b;
1011
	
1012
  palette_get_foreground (&r, &g, &b);
1013
 	
1014 1015 1016 1017 1018
  *fg_r = (double) r / 255.0;
  *fg_g = (double) g / 255.0;
  *fg_b = (double) b / 255.0;
  *fg_a = 1.0;                 /* opacity 100 % */
}
1019

Elliot Lee's avatar
Elliot Lee committed
1020 1021 1022
/*****/

static void
1023
ed_update_editor (int flags)
Elliot Lee's avatar
Elliot Lee committed
1024
{
1025 1026
  if (flags & GRAD_UPDATE_PREVIEW)
    prev_update (TRUE);
Elliot Lee's avatar
Elliot Lee committed
1027

1028 1029
  if (flags & GRAD_UPDATE_CONTROL)
    control_update(FALSE);
Elliot Lee's avatar
Elliot Lee committed
1030

1031 1032 1033
  if (flags & GRAD_RESET_CONTROL)
    control_update (TRUE);
}
Elliot Lee's avatar
Elliot Lee committed
1034 1035 1036 1037

/*****/

static GtkWidget *
1038 1039 1040 1041 1042
ed_create_button (gchar         *label,
		  double         xalign,
		  double         yalign,
		  GtkSignalFunc  signal_func,
		  gpointer       user_data)
Elliot Lee's avatar
Elliot Lee committed
1043
{
1044 1045
  GtkWidget *button;
  GtkWidget *text;
Elliot Lee's avatar
Elliot Lee committed
1046

1047 1048
  button = gtk_button_new ();
  text   = gtk_label_new (label);
Elliot Lee's avatar
Elliot Lee committed
1049

1050 1051 1052 1053
  gtk_misc_set_alignment (GTK_MISC (text), xalign, yalign);
  gtk_misc_set_padding (GTK_MISC (text), 4, 0);
  gtk_container_add (GTK_CONTAINER (button), text);
  gtk_widget_show (text);
Elliot Lee's avatar
Elliot Lee committed
1054

1055 1056 1057 1058
  if (signal_func != NULL)
    gtk_signal_connect (GTK_OBJECT (button), "clicked",
			(GtkSignalFunc) signal_func,
			user_data);
Elliot Lee's avatar
Elliot Lee committed
1059

1060 1061
  return button;
}
Elliot Lee's avatar
Elliot Lee committed
1062 1063 1064 1065

/*****/

static void
1066
ed_set_hint (gchar *str)
Elliot Lee's avatar
Elliot Lee committed
1067
{
1068 1069 1070
  gtk_label_set_text (GTK_LABEL (g_editor->hint_label), str);
  gdk_flush();
}
Elliot Lee's avatar
Elliot Lee committed
1071 1072 1073

/*****/

1074
gint
1075 1076 1077
ed_set_list_of_gradients (GdkGC      *gc,
			  GtkWidget  *clist,
			  gradient_t *sel_gradient)
Elliot Lee's avatar
Elliot Lee committed
1078
{
1079 1080 1081 1082
  GSList     *list;
  gradient_t *grad;
  gint n;
  gint select_pos = -1;
Elliot Lee's avatar
Elliot Lee committed
1083

1084 1085
  list = gradients_list;
  n    = 0;
1086

1087 1088
  if (sel_gradient == NULL)
    sel_gradient = curr_gradient;
1089

1090
  gtk_clist_freeze (GTK_CLIST (clist));
Elliot Lee's avatar
Elliot Lee committed
1091

1092 1093 1094
  while (list)
    {
      grad = list->data;
Elliot Lee's avatar
Elliot Lee committed
1095

1096 1097 1098 1099 1100 1101 1102 1103 1104
      if (grad == sel_gradient)
	{
	  ed_insert_in_gradients_listbox (gc, clist, grad, n, 1);
	  select_pos = n;
	}
      else
	{
	  ed_insert_in_gradients_listbox (gc, clist, grad, n, 0);
	}
1105

1106 1107 1108
      list = g_slist_next (list);
      n++;
    }
1109

1110
  gtk_clist_thaw (GTK_CLIST (clist));
Elliot Lee's avatar
Elliot Lee committed
1111

1112 1113
  return select_pos;
}
Elliot Lee's avatar
Elliot Lee committed
1114

1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 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