Dialogs.c 56.2 KB
Newer Older
Sven Neumann's avatar
Sven Neumann committed
1
2
#include "config.h"

3
#include <errno.h>
4
#include <stdio.h>
5
6
7
#include <stdlib.h>
#include <string.h>

8
9
10
11
12
#ifdef __GNUC__
#warning GTK_DISABLE_DEPRECATED
#endif
#undef GTK_DISABLE_DEPRECATED

13
#include <libgimp/gimp.h>
14
15
16
17
18
19
#include <libgimp/gimpui.h>

#include "FractalExplorer.h"
#include "Dialogs.h"
#include "Events.h"

20
21
#include "logo.h"

Sven Neumann's avatar
Sven Neumann committed
22
23
24
#include "libgimp/stdplugins-intl.h"


25
26
27
28
29
30
31
32
33
34
35
36
37
#ifdef G_OS_WIN32
#  include <io.h>
#  ifndef W_OK
#    define W_OK 2
#  endif
#  ifndef S_ISDIR
#    define S_ISDIR(m) ((m) & _S_IFDIR)
#  endif
#  ifndef S_ISREG
#    define S_ISREG(m) ((m) & _S_IFREG)
#  endif
#endif

38
39
40
static gdouble *gradient_samples = NULL;
static gchar   *gradient_name    = NULL;

41
/**********************************************************************
42
 FORWARD DECLARATIONS
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
static void explorer_logo_dialog (void);

/**********************************************************************
 CALLBACKS
 *********************************************************************/

static void
dialog_ok_callback (GtkWidget *widget,
		    gpointer   data)
{
  wint.run = TRUE;

  gtk_widget_destroy (GTK_WIDGET (data));
}

static void
dialog_reset_callback (GtkWidget *widget,
		       gpointer   data)
{
  wvals.xmin = standardvals.xmin;
  wvals.xmax = standardvals.xmax;
  wvals.ymin = standardvals.ymin;
  wvals.ymax = standardvals.ymax;
  wvals.iter = standardvals.iter;
69
70
  wvals.cx   = standardvals.cx;
  wvals.cy   = standardvals.cy;
71
72
73
74
75
76
77
78
79
80
81
82
83

  dialog_change_scale ();
  set_cmap_preview ();
  dialog_update_preview ();
}

static void
dialog_redraw_callback (GtkWidget *widget,
			gpointer   data)
{
  gint alwaysprev = wvals.alwayspreview;

  wvals.alwayspreview = TRUE;
84
85
  set_cmap_preview ();
  dialog_update_preview ();
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
  wvals.alwayspreview = alwaysprev;
}

static void
dialog_undo_zoom_callback (GtkWidget *widget,
			   gpointer   data)
{
  if (zoomindex > 1)
    {
      zooms[zoomindex] = wvals;
      zoomindex--;
      wvals = zooms[zoomindex];
      dialog_change_scale ();
      set_cmap_preview ();
      dialog_update_preview ();
    }
}

static void
dialog_redo_zoom_callback (GtkWidget *widget,
			   gpointer   data)
{
  if (zoomindex < zoommax)
    {
      zoomindex++;
      wvals = zooms[zoomindex];
      dialog_change_scale ();
      set_cmap_preview ();
      dialog_update_preview ();
    }
}

static void
dialog_step_in_callback (GtkWidget *widget,
			 gpointer   data)
{
  double xdifferenz;
  double ydifferenz;

  if (zoomindex < zoommax)
    {
      zooms[zoomindex]=wvals;
      zoomindex++;
    }

131
132
133
134
135
136
  xdifferenz =  wvals.xmax - wvals.xmin;
  ydifferenz =  wvals.ymax - wvals.ymin;
  wvals.xmin += 1.0 / 6.0 * xdifferenz;
  wvals.ymin += 1.0 / 6.0 * ydifferenz;
  wvals.xmax -= 1.0 / 6.0 * xdifferenz;
  wvals.ymax -= 1.0 / 6.0 * ydifferenz;
137
138
139
140
141
  zooms[zoomindex] = wvals;

  dialog_change_scale ();
  set_cmap_preview ();
  dialog_update_preview ();
142
}
143
144
145
146
147

static void
dialog_step_out_callback (GtkWidget *widget,
			  gpointer   data)
{
148
149
  gdouble xdifferenz;
  gdouble ydifferenz;
150
151
152
153
154
155
156

  if (zoomindex < zoommax)
    {
      zooms[zoomindex]=wvals;
      zoomindex++;
    }

157
158
159
160
161
162
  xdifferenz =  wvals.xmax - wvals.xmin;
  ydifferenz =  wvals.ymax - wvals.ymin;
  wvals.xmin -= 1.0 / 4.0 * xdifferenz;
  wvals.ymin -= 1.0 / 4.0 * ydifferenz;
  wvals.xmax += 1.0 / 4.0 * xdifferenz;
  wvals.ymax += 1.0 / 4.0 * ydifferenz;
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
  zooms[zoomindex] = wvals;

  dialog_change_scale ();
  set_cmap_preview ();
  dialog_update_preview ();
}

static void
explorer_toggle_update (GtkWidget *widget,
			gpointer   data)
{
  gimp_toggle_button_update (widget, data);

  set_cmap_preview ();
  dialog_update_preview ();
}

static void
explorer_radio_update  (GtkWidget *widget,
			gpointer   data)
{
  gimp_radio_button_update (widget, data);

  set_cmap_preview ();
  dialog_update_preview ();
}

static void
explorer_double_adjustment_update (GtkAdjustment *adjustment,
				   gpointer       data)
{
  gimp_double_adjustment_update (adjustment, data);

  set_cmap_preview ();
  dialog_update_preview ();
}

static void
explorer_number_of_colors_callback (GtkAdjustment *adjustment,
				    gpointer       data)
{
  gint dummy;

  gimp_int_adjustment_update (adjustment, data);

  g_free (gradient_samples);

210
  if (! gradient_name)
211
    gradient_name = gimp_gradients_get_gradient ();
212

213
214
215
  gimp_gradients_get_gradient_data (gradient_name,
                                    wvals.ncolors,
                                    &dummy,
Michael Natterer's avatar
Michael Natterer committed
216
                                    &gradient_samples);
217
218
219
220
221
222

  set_cmap_preview ();
  dialog_update_preview ();
}

static void
223
224
225
226
227
explorer_gradient_select_callback (const gchar   *name,
				   gint           width,
				   const gdouble *gradient_data,
				   gboolean       dialog_closing,
				   gpointer       data)
228
229
230
231
232
233
234
235
{
  gint dummy;

  g_free (gradient_name);
  g_free (gradient_samples);

  gradient_name = g_strdup (name);

236
237
238
  gimp_gradients_get_gradient_data (gradient_name,
                                    wvals.ncolors,
                                    &dummy,
239
				    &gradient_samples);
240
241
242

  if (wvals.colormode == 1)
    {
243
244
      set_cmap_preview ();
      dialog_update_preview (); 
245
246
247
248
249
250
    }
}

/**********************************************************************
 FUNCTION: explorer_dialog
 *********************************************************************/
251
252

gint
253
explorer_dialog (void)
254
{
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
  GtkWidget *dialog;
  GtkWidget *top_hbox;
  GtkWidget *left_vbox;
  GtkWidget *abox;
  GtkWidget *vbox;
  GtkWidget *hbbox;
  GtkWidget *frame;
  GtkWidget *pframe;
  GtkWidget *toggle;
  GtkWidget *toggle_vbox;
  GtkWidget *toggle_vbox2;
  GtkWidget *toggle_vbox3;
  GtkWidget *notebook;
  GtkWidget *hbox;
  GtkWidget *table;
  GtkWidget *button;
  GtkWidget *gradient;
  GtkWidget *sep;
  gchar   *gradient_name;
  GSList  *group = NULL;
  gint     i;

277
  gimp_ui_init ("fractalexplorer", TRUE);
278
279
280
281
282
283
284
285
286

  plug_in_parse_fractalexplorer_path ();

  wint.wimage = g_new (guchar, preview_width * preview_height * 3);
  elements    = g_new (DialogElements, 1);

  dialog = maindlg =
    gimp_dialog_new ("Fractal Explorer <Daniel Cotting/cotting@multimania.com>",
		     "fractalexplorer",
287
		     gimp_standard_help_func, "filters/fractalexplorer.html",
288
289
290
		     GTK_WIN_POS_NONE,
		     FALSE, TRUE, FALSE,

291
292
293
		     GTK_STOCK_CANCEL, gtk_widget_destroy,
		     NULL, 1, NULL, FALSE, TRUE,

294
295
		     _("About"), explorer_logo_dialog,
		     NULL, NULL, NULL, FALSE, FALSE,
296

297
		     GTK_STOCK_OK, dialog_ok_callback,
298
299
300
301
		     NULL, NULL, NULL, TRUE, FALSE,

		     NULL);

302
  g_signal_connect (dialog, "destroy",
303
304
                    G_CALLBACK (gtk_main_quit),
                    NULL);
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

  top_hbox = gtk_hbox_new (FALSE, 6);
  gtk_container_set_border_width (GTK_CONTAINER (top_hbox), 6);
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), top_hbox,
		      FALSE, FALSE, 0);
  gtk_widget_show (top_hbox);

  left_vbox = gtk_vbox_new (FALSE, 6);
  gtk_box_pack_start (GTK_BOX (top_hbox), left_vbox, FALSE, FALSE, 0);
  gtk_widget_show (left_vbox);

  /*  Preview  */
  frame = gtk_frame_new (_("Preview"));
  gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_ETCHED_IN);
  gtk_box_pack_start (GTK_BOX (left_vbox), frame, FALSE, FALSE, 0);
  gtk_widget_show (frame);

  vbox = gtk_vbox_new (FALSE, 4);
  gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
  gtk_container_add (GTK_CONTAINER (frame), vbox);
  gtk_widget_show (vbox);

  abox = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
  gtk_box_pack_start (GTK_BOX (vbox), abox, FALSE, FALSE, 0);
  gtk_widget_show (abox);

  pframe = gtk_frame_new (NULL);
  gtk_frame_set_shadow_type (GTK_FRAME (pframe), GTK_SHADOW_IN);
  gtk_container_add (GTK_CONTAINER (abox), pframe);
  gtk_widget_show (pframe);

  wint.preview = gtk_preview_new (GTK_PREVIEW_COLOR);
  gtk_preview_size (GTK_PREVIEW (wint.preview), preview_width, preview_height);
  gtk_container_add (GTK_CONTAINER (pframe), wint.preview);
339

340
  g_signal_connect (wint.preview, "button_press_event",
341
342
                    G_CALLBACK (preview_button_press_event),
                    NULL);
343
  g_signal_connect (wint.preview, "button_release_event",
344
                    G_CALLBACK (preview_button_release_event),
345
346
		    NULL);
  g_signal_connect (wint.preview, "motion_notify_event",
347
348
                    G_CALLBACK (preview_motion_notify_event),
                    NULL);
349
  g_signal_connect (wint.preview, "leave_notify_event",
350
351
                    G_CALLBACK (preview_leave_notify_event),
                    NULL);
352
  g_signal_connect (wint.preview, "enter_notify_event",
353
354
355
                    G_CALLBACK (preview_enter_notify_event),
                    NULL);

356
357
358
359
360
361
362
363
364
  gtk_widget_set_events (wint.preview, (GDK_BUTTON_PRESS_MASK |
					GDK_BUTTON_RELEASE_MASK |
					GDK_POINTER_MOTION_MASK |
					GDK_LEAVE_NOTIFY_MASK |
					GDK_ENTER_NOTIFY_MASK));
  gtk_widget_show (wint.preview);

  toggle = gtk_check_button_new_with_label (_("Realtime Preview"));
  gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0);
365
  g_signal_connect (toggle, "toggled",
366
367
                    G_CALLBACK (explorer_toggle_update),
                    &wvals.alwayspreview);
368
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), wvals.alwayspreview);
369
370
371
372
373
374
  gtk_widget_show (toggle);
  gimp_help_set_help_data (toggle, _("If you enable this option the preview "
				     "will be redrawn automatically"), NULL);

  button = gtk_button_new_with_label (_("Redraw"));
  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
375
  g_signal_connect (button, "clicked",
376
377
                    G_CALLBACK (dialog_redraw_callback),
                    dialog);
378
379
380
381
382
383
384
385
386
387
388
389
390
391
  gtk_widget_show (button);
  gimp_help_set_help_data (button, _("Redraw preview"), NULL);

  /*  Zoom Options  */
  frame = gtk_frame_new (_("Zoom Options"));
  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
  gtk_box_pack_end (GTK_BOX (left_vbox), frame, FALSE, FALSE, 0);
  gtk_widget_show (frame);

  vbox = gtk_vbox_new(FALSE, 0);
  gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
  gtk_container_add (GTK_CONTAINER (frame), vbox);
  gtk_widget_show (vbox);

392
  button = gtk_button_new_from_stock (GTK_STOCK_UNDO);
393
  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
394
395
396
397
  gtk_widget_show (button);

  gimp_help_set_help_data (button, _("Undo last zoom"), NULL);

398
  g_signal_connect (button, "clicked",
399
400
                    G_CALLBACK (dialog_undo_zoom_callback),
                    dialog);
401

402
  button = gtk_button_new_from_stock (GTK_STOCK_REDO);
403
  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
404
405
406
407
  gtk_widget_show (button);

  gimp_help_set_help_data (button, _("Redo last zoom"), NULL);

408
  g_signal_connect (button, "clicked",
409
410
                    G_CALLBACK (dialog_redo_zoom_callback),
                    dialog);
411

412
  button = gtk_button_new_from_stock (GTK_STOCK_ZOOM_IN);
413
  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
414
415
  gtk_widget_show (button);

416
  g_signal_connect (button, "clicked",
417
418
                    G_CALLBACK (dialog_step_in_callback),
                    dialog);
419

420
  button = gtk_button_new_from_stock (GTK_STOCK_ZOOM_OUT);
421
  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
422
423
  gtk_widget_show (button);

424
  g_signal_connect (button, "clicked",
425
426
                    G_CALLBACK (dialog_step_out_callback),
                    dialog);
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


  /*  Create notebook  */
  notebook = gtk_notebook_new ();
  gtk_box_pack_start (GTK_BOX (top_hbox), notebook, FALSE, FALSE, 0);
  gtk_widget_show (notebook);

  /*  "Parameters" page  */
  vbox = gtk_vbox_new (FALSE, 4);
  gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
  gtk_notebook_append_page (GTK_NOTEBOOK (notebook), vbox,
			    gtk_label_new (_("Parameters")));
  gtk_widget_show (vbox);

  frame = gtk_frame_new (_("Fractal Parameters"));
  gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
  gtk_widget_show (frame);

  table = gtk_table_new (8, 3, FALSE);
  gtk_container_set_border_width (GTK_CONTAINER (table), 4);
  gtk_table_set_col_spacings (GTK_TABLE (table), 4);
  gtk_table_set_row_spacings (GTK_TABLE (table), 2);
  gtk_table_set_row_spacing (GTK_TABLE (table), 6, 4);
  gtk_container_add (GTK_CONTAINER (frame), table);
  gtk_widget_show (table);

  elements->xmin =
    gimp_scale_entry_new (GTK_TABLE (table), 0, 0,
455
			  _("XMIN:"), SCALE_WIDTH, 10,
456
			  wvals.xmin, -3, 3, 0.001, 0.01, 5,
457
			  TRUE, 0, 0,
458
459
			  _("Change the first (minimal) x-coordinate "
			    "delimitation"), NULL);
460
  g_signal_connect (elements->xmin, "value_changed",
461
462
                    G_CALLBACK (explorer_double_adjustment_update),
                    &wvals.xmin);
463
464
465

  elements->xmax =
    gimp_scale_entry_new (GTK_TABLE (table), 0, 1,
466
			  _("XMAX:"), SCALE_WIDTH, 10,
467
			  wvals.xmax, -3, 3, 0.001, 0.01, 5,
468
			  TRUE, 0, 0,
469
470
			  _("Change the second (maximal) x-coordinate "
			    "delimitation"), NULL);
471
  g_signal_connect (elements->xmax, "value_changed",
472
473
                    G_CALLBACK (explorer_double_adjustment_update),
                    &wvals.xmax);
474
475
476

  elements->ymin =
    gimp_scale_entry_new (GTK_TABLE (table), 0, 2,
477
			  _("YMIN:"), SCALE_WIDTH, 10,
478
			  wvals.ymin, -3, 3, 0.001, 0.01, 5,
479
			  TRUE, 0, 0,
480
481
			  _("Change the first (minimal) y-coordinate "
			    "delimitation"), NULL);
482
  g_signal_connect (elements->ymin, "value_changed",
483
484
                    G_CALLBACK (explorer_double_adjustment_update),
                    &wvals.ymin);
485
486
487

  elements->ymax =
    gimp_scale_entry_new (GTK_TABLE (table), 0, 3,
488
			  _("YMAX:"), SCALE_WIDTH, 10,
489
			  wvals.ymax, -3, 3, 0.001, 0.01, 5,
490
			  TRUE, 0, 0,
491
492
			  _("Change the second (maximal) y-coordinate "
			    "delimitation"), NULL);
493
  g_signal_connect (elements->ymax, "value_changed",
494
495
                    G_CALLBACK (explorer_double_adjustment_update),
                    &wvals.ymax);
496
497
498

  elements->iter =
    gimp_scale_entry_new (GTK_TABLE (table), 0, 4,
499
			  _("ITER:"), SCALE_WIDTH, 10,
500
			  wvals.iter, 0, 1000, 1, 10, 5,
501
			  TRUE, 0, 0,
502
503
504
			  _("Change the iteration value. The higher it "
			    "is, the more details will be calculated, "
			    "which will take more time"), NULL);
505
  g_signal_connect (elements->iter, "value_changed",
506
507
                    G_CALLBACK (explorer_double_adjustment_update),
                    &wvals.iter);
508
509
510

  elements->cx =
    gimp_scale_entry_new (GTK_TABLE (table), 0, 5,
511
			  _("CX:"), SCALE_WIDTH, 10,
512
			  wvals.cx, -2.5, 2.5, 0.001, 0.01, 5,
513
			  TRUE, 0, 0,
514
515
516
			  _("Change the CX value (changes aspect of "
			    "fractal, active with every fractal but "
			    "Mandelbrot and Sierpinski)"), NULL);
517
  g_signal_connect (elements->cx, "value_changed",
518
519
                    G_CALLBACK (explorer_double_adjustment_update),
                    &wvals.cx);
520
521
522

  elements->cy =
    gimp_scale_entry_new (GTK_TABLE (table), 0, 6,
523
			  _("CY:"), SCALE_WIDTH, 10,
524
			  wvals.cy, -2.5, 2.5, 0.001, 0.01, 5,
525
			  TRUE, 0, 0,
526
527
528
			  _("Change the CY value (changes aspect of "
			    "fractal, active with every fractal but "
			    "Mandelbrot and Sierpinski)"), NULL);
529
  g_signal_connect (elements->cy, "value_changed",
530
531
                    G_CALLBACK (explorer_double_adjustment_update),
                    &wvals.cy);
532
533
534
535
536

  hbbox = gtk_hbox_new (FALSE, 4);
  gtk_table_attach_defaults (GTK_TABLE (table), hbbox, 0, 3, 7, 8);
  gtk_widget_show (hbbox);

537
  button = gtk_button_new_from_stock (GTK_STOCK_OPEN);
538
  gtk_box_pack_start (GTK_BOX (hbbox), button, TRUE, TRUE, 0);
539
  g_signal_connect (button, "clicked",
540
541
                    G_CALLBACK (create_load_file_selection),
                    dialog);
542
543
544
  gtk_widget_show (button);
  gimp_help_set_help_data (button, _("Load a fractal from file"), NULL);

545
  button = gtk_button_new_from_stock (GIMP_STOCK_RESET);
546
  gtk_box_pack_start (GTK_BOX (hbbox), button, TRUE, TRUE, 0);
547
  g_signal_connect (button, "clicked",
548
549
                    G_CALLBACK (dialog_reset_callback),
                    dialog);
550
551
552
553
  gtk_widget_show (button);
  gimp_help_set_help_data (button, _("Reset parameters to default values"),
			   NULL);

554
  button = gtk_button_new_from_stock (GTK_STOCK_SAVE);
555
  gtk_box_pack_start (GTK_BOX (hbbox), button, TRUE, TRUE, 0);
556
  g_signal_connect (button, "clicked",
557
558
                    G_CALLBACK (create_file_selection),
                    dialog);
559
560
  gtk_widget_show (button);
  gimp_help_set_help_data (button, _("Save active fractal to file"), NULL);
561
    
562
563
564
565
566
567
568
569
570
571
  /*  Fractal type toggle box  */
  frame = gtk_frame_new (_("Fractal Type"));
  gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);

  hbox = gtk_hbox_new (FALSE, 6);
  gtk_container_set_border_width (GTK_CONTAINER (hbox), 4);
  gtk_container_add (GTK_CONTAINER (frame), hbox);

  toggle_vbox =
    gimp_radio_group_new2 (FALSE, NULL,
572
			   G_CALLBACK (explorer_radio_update),
573
			   &wvals.fractaltype,
574
			   (gpointer) wvals.fractaltype,
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599

			   _("Mandelbrot"), (gpointer) TYPE_MANDELBROT,
			   &(elements->type[TYPE_MANDELBROT]),
			   _("Julia"), (gpointer) TYPE_JULIA,
			   &(elements->type[TYPE_JULIA]),
			   _("Barnsley 1"), (gpointer) TYPE_BARNSLEY_1,
			   &(elements->type[TYPE_BARNSLEY_1]),
			   _("Barnsley 2"), (gpointer) TYPE_BARNSLEY_2,
			   &(elements->type[TYPE_BARNSLEY_2]),
			   _("Barnsley 3"), (gpointer) TYPE_BARNSLEY_3,
			   &(elements->type[TYPE_BARNSLEY_3]),
			   _("Spider"), (gpointer) TYPE_SPIDER,
			   &(elements->type[TYPE_SPIDER]),
			   _("Man'o'war"), (gpointer) TYPE_MAN_O_WAR,
			   &(elements->type[TYPE_MAN_O_WAR]),
			   _("Lambda"), (gpointer) TYPE_LAMBDA,
			   &(elements->type[TYPE_LAMBDA]),
			   _("Sierpinski"), (gpointer) TYPE_SIERPINSKI,
			   &(elements->type[TYPE_SIERPINSKI]),

			   NULL);

  toggle_vbox2 = gtk_vbox_new (FALSE, 1);
  for (i = TYPE_BARNSLEY_2; i <= TYPE_SPIDER; i++)
    {
600
      g_object_ref (elements->type[i]);
601

602
603
604
605
606
      gtk_widget_hide (elements->type[i]);
      gtk_container_remove (GTK_CONTAINER (toggle_vbox), elements->type[i]);
      gtk_box_pack_start (GTK_BOX (toggle_vbox2), elements->type[i],
			  FALSE, FALSE, 0);
      gtk_widget_show (elements->type[i]);
607

608
      g_object_unref (elements->type[i]);
609
    }
610

611
612
613
  toggle_vbox3 = gtk_vbox_new (FALSE, 1);
  for (i = TYPE_MAN_O_WAR; i <= TYPE_SIERPINSKI; i++)
    {
614
      g_object_ref (elements->type[i]);
615

616
617
618
619
620
      gtk_widget_hide (elements->type[i]);
      gtk_container_remove (GTK_CONTAINER (toggle_vbox), elements->type[i]);
      gtk_box_pack_start (GTK_BOX (toggle_vbox3), elements->type[i],
			  FALSE, FALSE, 0);
      gtk_widget_show (elements->type[i]);
621

622
      g_object_unref (elements->type[i]);
623
    }
624

625
626
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
655
656
657
658
659
660
  gtk_container_set_border_width (GTK_CONTAINER (toggle_vbox), 0);
  gtk_box_pack_start (GTK_BOX (hbox), toggle_vbox, FALSE, FALSE, 0);
  gtk_widget_show (toggle_vbox);

  gtk_box_pack_start (GTK_BOX (hbox), toggle_vbox2, FALSE, FALSE, 0);
  gtk_widget_show (toggle_vbox2);

  gtk_box_pack_start (GTK_BOX (hbox), toggle_vbox3, FALSE, FALSE, 0);
  gtk_widget_show (toggle_vbox3);

  gtk_widget_show (hbox);
  gtk_widget_show (frame);

  /*  Color page  */
  vbox = gtk_vbox_new (FALSE, 4);
  gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
  gtk_notebook_append_page (GTK_NOTEBOOK (notebook), vbox,
			    gtk_label_new (_("Colors")));
  gtk_widget_show (vbox);

  /*  Number of Colors frame  */
  frame = gtk_frame_new (_("Number of Colors"));
  gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
  gtk_widget_show (frame);

  table = gtk_table_new (2, 3, FALSE);
  gtk_table_set_col_spacings (GTK_TABLE (table), 4);
  gtk_table_set_row_spacings (GTK_TABLE (table), 2);
  gtk_container_set_border_width (GTK_CONTAINER (table), 4);
  gtk_container_add (GTK_CONTAINER (frame), table);
  gtk_widget_show (table);

  elements->ncol =
    gimp_scale_entry_new (GTK_TABLE (table), 0, 0,
			  _("Number of Colors:"), SCALE_WIDTH, 0,
			  wvals.ncolors, 2, MAXNCOLORS, 1, 10, 0,
661
			  TRUE, 0, 0,
662
663
			  _("Change the number of colors in the mapping"),
			  NULL);
664
  g_signal_connect (elements->ncol, "value_changed",
665
666
                    G_CALLBACK (explorer_number_of_colors_callback),
                    &wvals.ncolors);
667
668
669
670

  elements->useloglog = toggle =
    gtk_check_button_new_with_label (_("Use loglog Smoothing"));
  gtk_table_attach_defaults (GTK_TABLE (table), toggle, 0, 3, 1, 2);
671
  g_signal_connect (toggle, "toggled",
672
673
                    G_CALLBACK (explorer_toggle_update),
                    &wvals.useloglog);
674
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), wvals.useloglog);
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
  gtk_widget_show (toggle);
  gimp_help_set_help_data (toggle, _("Use log log smoothing to eliminate "
				     "\"banding\" in the result"), NULL);

  /*  Color Density frame  */
  frame = gtk_frame_new (_("Color Density"));
  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
  gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
  gtk_widget_show (frame);

  table = gtk_table_new (3, 3, FALSE);
  gtk_table_set_col_spacings (GTK_TABLE (table), 4);
  gtk_table_set_row_spacings (GTK_TABLE (table), 2);
  gtk_container_set_border_width (GTK_CONTAINER (table), 4);
  gtk_container_add (GTK_CONTAINER (frame), table);
  gtk_widget_show (table);

  elements->red =
    gimp_scale_entry_new (GTK_TABLE (table), 0, 0,
			  _("Red:"), SCALE_WIDTH, 0,
			  wvals.redstretch, 0, 1, 0.01, 0.1, 2,
696
			  TRUE, 0, 0,
697
			  _("Change the intensity of the red channel"), NULL);
698
  g_signal_connect (elements->red, "value_changed",
699
700
                    G_CALLBACK (explorer_double_adjustment_update),
                    &wvals.redstretch);
701
702
703
704
705

  elements->green =
    gimp_scale_entry_new (GTK_TABLE (table), 0, 1,
			  _("Green:"), SCALE_WIDTH, 0,
			  wvals.greenstretch, 0, 1, 0.01, 0.1, 2,
706
			  TRUE, 0, 0,
707
			  _("Change the intensity of the green channel"), NULL);
708
  g_signal_connect (elements->green, "value_changed",
709
710
                    G_CALLBACK (explorer_double_adjustment_update),
                    &wvals.greenstretch);
711
712
713
714
715

  elements->blue =
    gimp_scale_entry_new (GTK_TABLE (table), 0, 2,
			  _("Blue:"), SCALE_WIDTH, 0,
			  wvals.bluestretch, 0, 1, 0.01, 0.1, 2,
716
			  TRUE, 0, 0,
717
			  _("Change the intensity of the blue channel"), NULL);
718
  g_signal_connect (elements->blue, "value_changed",
719
720
                    G_CALLBACK (explorer_double_adjustment_update),
                    &wvals.bluestretch);
721
722
723
724
725
726
727
728
729
730
731
732
733
734

  /*  Color Function frame  */
  frame = gtk_frame_new (_("Color Function"));
  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
  gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
  gtk_widget_show (frame);

  hbox = gtk_hbox_new (FALSE, 6);
  gtk_container_set_border_width (GTK_CONTAINER (hbox), 4);
  gtk_container_add (GTK_CONTAINER (frame), hbox);
  gtk_widget_show (hbox);

  /*  Redmode radio frame  */
  frame = gimp_radio_group_new2 (TRUE, _("Red"),
735
				 G_CALLBACK (explorer_radio_update),
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
				 &wvals.redmode, (gpointer) wvals.redmode,

				 _("Sine"), (gpointer) SINUS,
				 &elements->redmode[SINUS],
				 _("Cosine"), (gpointer) COSINUS,
				 &elements->redmode[COSINUS],
				 _("None"), (gpointer) NONE,
				 &elements->redmode[NONE],

				 NULL);
  gimp_help_set_help_data (elements->redmode[SINUS],
			   _("Use sine-function for this color component"),
			   NULL);
  gimp_help_set_help_data (elements->redmode[COSINUS],
			   _("Use cosine-function for this color "
			     "component"), NULL);
  gimp_help_set_help_data (elements->redmode[NONE],
			   _("Use linear mapping instead of any "
			     "trigonometrical function for this color "
			     "channel"), NULL);
  gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
  gtk_widget_show (frame);

  toggle_vbox = GTK_BIN (frame)->child;

  elements->redinvert = toggle =
    gtk_check_button_new_with_label (_("Inversion"));
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), wvals.redinvert);
  gtk_box_pack_start (GTK_BOX (toggle_vbox), toggle, FALSE, FALSE, 0);
765
  g_signal_connect (toggle, "toggled",
766
767
                    G_CALLBACK (explorer_toggle_update),
                    &wvals.redinvert);
768
769
770
771
772
773
774
775
  gtk_widget_show (toggle);
  gimp_help_set_help_data (toggle,
			   _("If you enable this option higher color values "
			     "will be swapped with lower ones and vice "
			     "versa"), NULL);

  /*  Greenmode radio frame  */
  frame = gimp_radio_group_new2 (TRUE, _("Green"),
776
				 G_CALLBACK (explorer_radio_update),
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
				 &wvals.greenmode, (gpointer) wvals.greenmode,

				 _("Sine"), (gpointer) SINUS,
				 &elements->greenmode[SINUS],
				 _("Cosine"), (gpointer) COSINUS,
				 &elements->greenmode[COSINUS],
				 _("None"), (gpointer) NONE,
				 &elements->greenmode[NONE],

				 NULL);
  gimp_help_set_help_data (elements->greenmode[SINUS],
			   _("Use sine-function for this color component"),
			   NULL);
  gimp_help_set_help_data (elements->greenmode[COSINUS],
			   _("Use cosine-function for this color "
			     "component"), NULL);
  gimp_help_set_help_data (elements->greenmode[NONE],
			   _("Use linear mapping instead of any "
			     "trigonometrical function for this color "
			     "channel"), NULL);
  gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
  gtk_widget_show (frame);

  toggle_vbox = GTK_BIN (frame)->child;

  elements->greeninvert = toggle =
    gtk_check_button_new_with_label (_("Inversion"));
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), wvals.greeninvert);
  gtk_box_pack_start (GTK_BOX (toggle_vbox), toggle, FALSE, FALSE, 0);
806
  g_signal_connect (toggle, "toggled",
807
808
                    G_CALLBACK (explorer_toggle_update),
                    &wvals.greeninvert);
809
810
811
812
813
814
815
816
  gtk_widget_show (toggle);
  gimp_help_set_help_data (toggle,
			   _("If you enable this option higher color values "
			     "will be swapped with lower ones and vice "
			     "versa"), NULL);

  /*  Bluemode radio frame  */
  frame = gimp_radio_group_new2 (TRUE, _("Blue"),
817
				 G_CALLBACK (explorer_radio_update),
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
				 &wvals.bluemode, (gpointer) wvals.bluemode,

				 _("Sine"), (gpointer) SINUS,
				 &elements->bluemode[SINUS],
				 _("Cosine"), (gpointer) COSINUS,
				 &elements->bluemode[COSINUS],
				 _("None"), (gpointer) NONE,
				 &elements->bluemode[NONE],

				 NULL);
  gimp_help_set_help_data (elements->bluemode[SINUS],
			   _("Use sine-function for this color component"),
			   NULL);
  gimp_help_set_help_data (elements->bluemode[COSINUS],
			   _("Use cosine-function for this color "
			     "component"), NULL);
  gimp_help_set_help_data (elements->bluemode[NONE],
			   _("Use linear mapping instead of any "
			     "trigonometrical function for this color "
			     "channel"), NULL);
  gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
  gtk_widget_show (frame);

  toggle_vbox = GTK_BIN (frame)->child;

  elements->blueinvert = toggle =
    gtk_check_button_new_with_label (_("Inversion"));
845
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON( toggle), wvals.blueinvert);
846
  gtk_box_pack_start (GTK_BOX (toggle_vbox), toggle, FALSE, FALSE, 0);
847
  g_signal_connect (toggle, "toggled",
848
849
                    G_CALLBACK (explorer_toggle_update),
                    &wvals.blueinvert);
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
  gtk_widget_show (toggle);
  gimp_help_set_help_data (toggle,
			   _("If you enable this option higher color values "
			     "will be swapped with lower ones and vice "
			     "versa"), NULL);

  /*  Colormode toggle box  */
  frame = gtk_frame_new (_("Color Mode"));
  gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_ETCHED_IN);
  gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
  gtk_widget_show (frame);

  toggle_vbox = gtk_vbox_new (FALSE, 2);
  gtk_container_set_border_width (GTK_CONTAINER (toggle_vbox), 2);
  gtk_container_add (GTK_CONTAINER (frame), toggle_vbox);
  gtk_widget_show (toggle_vbox);

  toggle = elements->colormode[0] =
    gtk_radio_button_new_with_label (group, _("As Specified above"));
869
  group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (toggle));
870
  gtk_box_pack_start (GTK_BOX (toggle_vbox), toggle, FALSE, FALSE, 0);
871
872
  g_object_set_data (G_OBJECT (toggle), "gimp-item-data",
                     GINT_TO_POINTER (0));
873
  g_signal_connect (toggle, "toggled",
874
875
                    G_CALLBACK (explorer_radio_update),
                    &wvals.colormode);
876
877
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
				wvals.colormode == 0);
878
879
880
881
882
883
884
885
886
887
888
889
890
  gtk_widget_show (toggle);
  gimp_help_set_help_data (toggle,
			   _("Create a color-map with the options you "
			     "specified above (color density/function). The "
			     "result is visible in the preview image"), NULL);

  hbox = gtk_hbox_new (FALSE, 6);
  gtk_box_pack_start (GTK_BOX (toggle_vbox), hbox, FALSE, FALSE, 0);
  gtk_widget_show (hbox);

  toggle = elements->colormode[1] =
    gtk_radio_button_new_with_label (group,
				     _("Apply Active Gradient to Final Image"));
891
  group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (toggle));
892
  gtk_box_pack_start (GTK_BOX (hbox), toggle, TRUE, TRUE, 0);
893
894
  g_object_set_data (G_OBJECT (toggle), "gimp-item-data",
                     GINT_TO_POINTER (1));
895
  g_signal_connect (toggle, "toggled",
896
897
                    G_CALLBACK (explorer_radio_update),
                    &wvals.colormode);
898
899
900
901
902
903
904
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
				wvals.colormode == 1);
  gtk_widget_show (toggle);
  gimp_help_set_help_data (toggle,
			   _("Create a color-map using a gradient from "
			     "the gradient editor"), NULL);

905
  gradient_name = gimp_gradients_get_gradient ();
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
  gradient_samples = gimp_gradients_sample_uniform (wvals.ncolors);
  gradient = gimp_gradient_select_widget (_("FractalExplorer Gradient"),
					  gradient_name,
					  explorer_gradient_select_callback,
					  NULL);
  g_free (gradient_name);
  gtk_box_pack_start (GTK_BOX (hbox), gradient, FALSE, FALSE, 0);
  gtk_widget_show (gradient);

  sep = gtk_hseparator_new ();
  gtk_box_pack_start (GTK_BOX (toggle_vbox), sep, FALSE, FALSE, 1);
  gtk_widget_show (sep);

  abox = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
  {
    gint xsize, ysize;
922

923
    for (ysize = 1; ysize * ysize * ysize < 8192; ysize++) /**/;
924
    xsize = wvals.ncolors / ysize;
925
    while (xsize * ysize < 8192) xsize++;
926

927
    gtk_widget_set_size_request (abox, xsize, ysize * 4);
928
929
930
  }
  gtk_box_pack_start (GTK_BOX (toggle_vbox), abox, FALSE, FALSE, 0);
  gtk_widget_show (abox);
931

932
933
934
935
  cmap_preview = gtk_preview_new (GTK_PREVIEW_COLOR);
  gtk_preview_size (GTK_PREVIEW (cmap_preview), 32, 32);
  gtk_container_add (GTK_CONTAINER (abox), cmap_preview);
  gtk_widget_show (cmap_preview);
936

937
938
939
940
  frame = add_objects_list ();
  gtk_notebook_append_page (GTK_NOTEBOOK (notebook), frame, 
			    gtk_label_new (_("Fractals")));
  gtk_widget_show (frame);
941

942
  gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), 1);
943

944
  /* Done */
945

946
947
948
  /* Popup for list area: Not yet fully implemented
     fractalexplorer_op_menu_create(maindlg);
  */
949

950
951
  gtk_widget_show (dialog);
  ready_now = TRUE;
952

953
954
955
956
957
958
959
960
961
962
  set_cmap_preview ();
  dialog_update_preview ();

  gtk_main ();
  gdk_flush ();

  if (the_tile != NULL)
    {
      gimp_tile_unref (the_tile, FALSE);
      the_tile = NULL;
963
964
    }

965
966
967
968
  g_free (wint.wimage);

  return wint.run;
}
969
970
971
972
973
974

/**********************************************************************
 FUNCTION: dialog_update_preview
 *********************************************************************/

void
975
dialog_update_preview (void)
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
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
  gdouble  left;
  gdouble  right;
  gdouble  bottom;
  gdouble  top;
  gdouble  dx;
  gdouble  dy;
  gdouble  cx;
  gdouble  cy;
  gint     px;
  gint     py;
  gint     xcoord;
  gint     ycoord;
  gint     iteration;
  guchar  *p_ul;
  guchar  *p;
  gdouble  a;
  gdouble  b;
  gdouble  x;
  gdouble  y;
  gdouble  oldx;
  gdouble  oldy;
  gdouble  foldxinitx;
  gdouble  foldxinity;
  gdouble  tempsqrx;
  gdouble  tempsqry;
  gdouble  tmpx = 0;
  gdouble  tmpy = 0;
  gdouble  foldyinitx;
  gdouble  foldyinity;
  gdouble  adjust;
  gdouble  xx = 0;
  gint     zaehler;
  gint     color;
  gint     useloglog;
	
  if (NULL == wint.preview)
    return;

  if ((ready_now) && (wvals.alwayspreview))
    {
      left = sel_x1;
      right = sel_x2 - 1;
      bottom = sel_y2 - 1;
      top = sel_y1;
      dx = (right - left) / (preview_width - 1);
      dy = (bottom - top) / (preview_height - 1);

      xmin = wvals.xmin;
      xmax = wvals.xmax;
      ymin = wvals.ymin;
      ymax = wvals.ymax;
      cx = wvals.cx;
      cy = wvals.cy;
      xbild = preview_width;
      ybild = preview_height;
      xdiff = (xmax - xmin) / xbild;
      ydiff = (ymax - ymin) / ybild;

      py = 0;

      p_ul = wint.wimage;
      iteration = (int) wvals.iter;
      useloglog = wvals.useloglog;
      for (ycoord = 0; ycoord < preview_height; ycoord++)
	{
	  px = 0;

	  for (xcoord = 0; xcoord < preview_width; xcoord++)
	    {
	      a = (double) xmin + (double) xcoord *xdiff;
	      b = (double) ymin + (double) ycoord *ydiff;

	      if (wvals.fractaltype != TYPE_MANDELBROT)
		{
		  tmpx = x = a;
		  tmpy = y = b;
		}
	      else
		{
		  x = 0;
		  y = 0;
1058
		}
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
	      for (zaehler = 0;
		   (zaehler < iteration) && ((x * x + y * y) < 4);
		   zaehler++)
		{
		  oldx = x;
		  oldy = y;

		  switch (wvals.fractaltype)
		    {
		    case TYPE_MANDELBROT:
		      xx = x * x - y * y + a;
		      y = 2.0 * x * y + b;
		      break;

		    case TYPE_JULIA:
		      xx = x * x - y * y + cx;
		      y = 2.0 * x * y + cy; 
		      break;

		    case TYPE_BARNSLEY_1:
		      foldxinitx = oldx * cx;
		      foldyinity = oldy * cy;
		      foldxinity = oldx * cy;
		      foldyinitx = oldy * cx;
		      /* orbit calculation */
		      if (oldx >= 0)
			{
1086
		          xx = (foldxinitx - cx - foldyinity);
1087
1088
1089
1090
                          y  = (foldyinitx - cy + foldxinity);
			}
		      else
			{
1091
		          xx = (foldxinitx + cx - foldyinity);
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
		          y  = (foldyinitx + cy + foldxinity);
			}
		      break;

		    case TYPE_BARNSLEY_2:
		      foldxinitx = oldx * cx;
		      foldyinity = oldy * cy;
		      foldxinity = oldx * cy;
		      foldyinitx = oldy * cx;
		      /* orbit calculation */
		      if (foldxinity + foldyinitx >= 0)
1103
                        {
1104
1105
			  xx = foldxinitx - cx - foldyinity;
			  y  = foldyinitx - cy + foldxinity;
1106
                        }
1107
		      else
1108
		        {
1109
1110
			  xx = foldxinitx + cx - foldyinity;
			  y  = foldyinitx + cy + foldxinity;
1111
                        }
1112
1113
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
		      break;

		    case TYPE_BARNSLEY_3:
		      foldxinitx  = oldx * oldx;
		      foldyinity  = oldy * oldy;
		      foldxinity  = oldx * oldy;
		      /* orbit calculation */
		      if(oldx > 0)
			{
			  xx = foldxinitx - foldyinity - 1.0;
			  y  = foldxinity * 2;
			}
		      else
			{
			  xx = foldxinitx - foldyinity -1.0 + cx * oldx;
			  y  = foldxinity * 2;
			  y += cy * oldx;
			}
		      break;

		    case TYPE_SPIDER:
		      /* { c=z=pixel: z=z*z+c; c=c/2+z, |z|<=4 } */
		      xx = x*x - y*y + tmpx + cx;
		      y = 2 * oldx * oldy + tmpy +cy;
		      tmpx = tmpx/2 + xx;
		      tmpy = tmpy/2 + y;
		      break;

		    case TYPE_MAN_O_WAR:
		      xx = x*x - y*y + tmpx + cx;
		      y = 2.0 * x * y + tmpy + cy;
		      tmpx = oldx;
		      tmpy = oldy;
		      break;

		    case TYPE_LAMBDA:
		      tempsqrx = x * x;
		      tempsqry = y * y;
		      tempsqrx = oldx - tempsqrx + tempsqry;
		      tempsqry = -(oldy * oldx);
		      tempsqry += tempsqry + oldy;
		      xx = cx * tempsqrx - cy * tempsqry;
		      y = cx * tempsqry + cy * tempsqrx;
		      break;

		    case TYPE_SIERPINSKI:
		      xx = oldx + oldx;
		      y = oldy + oldy;
		      if (oldy > .5)
			y = y - 1;
		      else if (oldx > .5)
			xx = xx - 1;
		      break;

		    default:
		      break;
1168
		    }
1169
1170
1171
1172
1173
1174
1175

		  x = xx;
		}

	      if (useloglog)
		{
		  adjust = log (log (x * x + y * y) / 2) / log (2);
1176
		}
1177
1178
	      else
		{
1179
1180
		  adjust = 0.0;
		}
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
	      color = (int) (((zaehler - adjust) *
			      (wvals.ncolors - 1)) / iteration);
	      p_ul[0] = colormap[color][0];
	      p_ul[1] = colormap[color][1];
	      p_ul[2] = colormap[color][2];
	      p_ul += 3;
	      px += 1;
	    } /* for */
	  py += 1;
	} /* for */

      p = wint.wimage;

      for (y = 0; y < preview_height; y++)
	{
	  gtk_preview_draw_row (GTK_PREVIEW (wint.preview), p,
				0, y, preview_width);
	  p += preview_width * 3;
	}
1200

1201
      gtk_widget_queue_draw (wint.preview);
1202
1203
1204
      gdk_flush ();
    }
}
1205
1206
1207
1208
1209
1210

/**********************************************************************
 FUNCTION: set_cmap_preview()
 *********************************************************************/

void
1211
set_cmap_preview (void)
1212
{
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
  gint    i;
  gint    x;
  gint    y;
  gint    j;
  guchar *b;
  guchar  c[GR_WIDTH * 3];
  gint    xsize, ysize;

  if (NULL == cmap_preview)
    return;

  make_color_map ();

  for (ysize = 1; ysize * ysize * ysize < wvals.ncolors; ysize++) /**/;
  xsize = wvals.ncolors / ysize;
  while (xsize * ysize < wvals.ncolors) xsize++;
  b = g_new (guchar, xsize * 3);

1231
1232
  gtk_preview_size (GTK_PREVIEW (cmap_preview), xsize, ysize * 4);
  gtk_widget_set_size_request (GTK_WIDGET (cmap_preview), xsize, ysize * 4);
1233
    
1234
1235
1236
1237
1238
1239
1240
  for (y = 0; y < ysize*4; y += 4)
    {
      for (x = 0; x < xsize; x++)
	{
	  i = x + (y / 4) * xsize;
	  if (i > wvals.ncolors)
	    {
1241
1242
	      for (j = 0; j < 3; j++) 
		b[x * 3 + j] = 0;
1243
1244
1245
	    }
	  else
	    {
1246
	      for (j = 0; j < 3; j++)
1247
		b[x * 3 + j] = colormap[i][j];
1248
	    }
1249
	}
1250
1251
1252
1253
1254

      gtk_preview_draw_row (GTK_PREVIEW (cmap_preview), b, 0, y, xsize);
      gtk_preview_draw_row (GTK_PREVIEW (cmap_preview), b, 0, y + 1, xsize);
      gtk_preview_draw_row (GTK_PREVIEW (cmap_preview), b, 0, y + 2, xsize);
      gtk_preview_draw_row (GTK_PREVIEW (cmap_preview), b, 0, y + 3, xsize);
1255
1256
    }

1257
1258
1259
1260
1261
1262
  for (x = 0; x < GR_WIDTH; x++)
    {
      for (j = 0; j < 3; j++)
	c[x * 3 + j] = colormap[(int)((float)x/(float)GR_WIDTH*256.0)][j];
    }

1263
  gtk_widget_queue_draw (cmap_preview);
1264
1265

  g_free (b);
1266
1267
1268
1269
1270
1271
1272
}

/**********************************************************************
 FUNCTION: make_color_map()
 *********************************************************************/

void
1273
make_color_map (void)
1274
{
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
  gint     i;
  gint     j;
  gint     r;
  gint     gr;
  gint     bl;
  gdouble  redstretch;
  gdouble  greenstretch;
  gdouble  bluestretch;
  gdouble  pi = atan (1) * 4;

1285
1286
1287
1288
1289
1290
  /*  get gradient samples if they don't exist -- fixes gradient color
   *  mode for noninteractive use (bug #103470).
   */
  if (gradient_samples == NULL)
    gradient_samples = gimp_gradients_sample_uniform (wvals.ncolors);

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
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
  redstretch   = wvals.redstretch * 127.5;
  greenstretch = wvals.greenstretch * 127.5;
  bluestretch  = wvals.bluestretch * 127.5;

  for (i = 0; i < wvals.ncolors; i++)
    if (wvals.colormode == 1)
      {
	for (j = 0; j < 3; j++)
	  colormap[i][j] = (int) (gradient_samples[i * 4 + j] * 255.0);
      }
    else
      {
	double x = (i*2.0) / wvals.ncolors;
	r = gr = bl = 0;

	switch (wvals.redmode)
	  {
	  case SINUS:
	    r = (int) redstretch *(1.0 + sin((x - 1) * pi));
	    break;
	  case COSINUS:
	    r = (int) redstretch *(1.0 + cos((x - 1) * pi));
	    break;
	  case NONE:
	    r = (int)(redstretch *(x));
	    break;
	  default:
	    break;
	  }

	switch (wvals.greenmode)
	  {
	  case SINUS:
	    gr = (int) greenstretch *(1.0 + sin((x - 1) * pi));
	    break;
	  case COSINUS:
	    gr = (int) greenstretch *(1.0 + cos((x - 1) * pi));
	    break;
	  case NONE:
	    gr = (int)(greenstretch *(x));
	    break;
	  default:
	    break;
	  }

	switch (wvals.bluemode)
	  {
	  case SINUS:
	    bl = (int) bluestretch * (1.0 + sin ((x - 1) * pi));
	    break;
	  case COSINUS:
	    bl = (int) bluestretch * (1.0 + cos ((x - 1) * pi));
	    break;
	  case NONE:
	    bl = (int) (bluestretch * x);
	    break;
	  default:
	    break;
	  }

	r  = MIN (r,  255);
	gr = MIN (gr, 255);
	bl = MIN (bl, 255);

	if (wvals.redinvert)
	  r = 255 - r;

	if (wvals.greeninvert)
	  gr = 255 - gr;

	if (wvals.blueinvert)
	  bl = 255 - bl;

	colormap[i][0] = r;
	colormap[i][1] = gr;
	colormap[i][2] = bl;
      }
1368
1369
1370
1371
1372
1373
}

/**********************************************************************
 FUNCTION: explorer_logo_dialog
 *********************************************************************/

1374
1375
static void
explorer_logo_dialog (void)
1376
{
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
  GtkWidget *xdlg;
  GtkWidget *xlabel = NULL;
  GtkWidget *xlogo_box;
  GtkWidget *xpreview;
  GtkWidget *xframe;
  GtkWidget *xframe2;
  GtkWidget *xframe3;
  GtkWidget *xvbox;
  GtkWidget *xhbox;
  GtkWidget *vpaned;
1387
1388
1389
1390
1391
  guchar    *temp;
  guchar    *temp2;
  guchar    *datapointer;
  gint       y;
  gint       x;
1392
1393
1394

  if (logodlg)
    {
1395
      gtk_window_present (GTK_WINDOW (logodlg));
1396
      return;
1397
1398
    }

1399
1400
  xdlg = logodlg =
    gimp_dialog_new (_("About"), "fractalexplorer",
1401
		     gimp_standard_help_func, "filters/fractalexplorer.html",
1402
1403
		     GTK_WIN_POS_MOUSE,
		     FALSE, TRUE, FALSE,
1404

1405
		     GTK_STOCK_OK, gtk_widget_destroy,
1406
		     NULL, 1, NULL, TRUE, TRUE,
1407

1408
		     NULL);
1409

1410
  g_signal_connect (xdlg, "destroy",
1411
1412
                    G_CALLBACK (gtk_widget_destroyed),
                    &logodlg);