~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to plug-ins/common/spheredesigner.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * The GIMP -- an image manipulation program
 
2
 * GIMP - The GNU Image Manipulation Program
3
3
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
18
 */
 
19
 
 
20
/*
5
21
 * SphereDesigner v0.4 - creates textured spheres
6
22
 * by Vidar Madsen <vidar@prosalg.no>
7
23
 *
20
36
 * - (Probably more. ;-)
21
37
 */
22
38
 
23
 
#define PLUG_IN_NAME "SphereDesigner"
24
 
 
25
39
#include "config.h"
26
40
 
27
 
#include <stdio.h>
28
 
#include <stdlib.h>
29
41
#include <string.h>
30
42
#include <errno.h>
31
43
 
32
 
#ifdef HAVE_UNISTD_H
33
 
#include <unistd.h>
34
 
#endif
35
 
 
36
 
#include <gtk/gtk.h>
 
44
#include <glib/gstdio.h>
37
45
 
38
46
#include <libgimp/gimp.h>
39
47
#include <libgimp/gimpui.h>
41
49
#include "libgimp/stdplugins-intl.h"
42
50
 
43
51
 
 
52
#define PLUG_IN_PROC   "plug-in-spheredesigner"
 
53
#define PLUG_IN_BINARY "spheredesigner"
 
54
 
44
55
#define RESPONSE_RESET 1
45
56
 
46
57
#define PREVIEWSIZE 150
62
73
                   gint             *nreturn_vals,
63
74
                   GimpParam       **return_vals);
64
75
 
65
 
GimpPlugInInfo PLUG_IN_INFO =
 
76
const GimpPlugInInfo PLUG_IN_INFO =
66
77
{
67
78
  NULL,   /* init_proc  */
68
79
  NULL,   /* quit_proc  */
264
275
 
265
276
static guchar img[PREVIEWSIZE * PREVIEWSIZE * 3];
266
277
 
267
 
static gint running = FALSE;
 
278
static guint  idle_id = 0;
268
279
 
269
280
static sphere s;
270
281
 
296
307
settings = { 1, 1, 1 };
297
308
 
298
309
 
299
 
static inline void vset      (GimpVector4          *v,
300
 
                              gdouble               a,
301
 
                              gdouble               b,
302
 
                              gdouble               c);
303
 
static void    restartrender (void);
304
 
static void    drawcolor1    (GtkWidget            *widget);
305
 
static void    drawcolor2    (GtkWidget            *widget);
306
 
static void    render        (void);
307
 
static void    realrender    (GimpDrawable         *drawable);
308
 
static void    fileselect    (GtkFileChooserAction  action,
309
 
                              GtkWidget            *parent);
310
 
static gint    traceray      (ray                  *r,
311
 
                              GimpVector4          *col,
312
 
                              gint                  level,
313
 
                              gdouble               imp);
314
 
static gdouble turbulence    (gdouble              *point,
315
 
                              gdouble               lofreq,
316
 
                              gdouble               hifreq);
 
310
static inline void vset        (GimpVector4          *v,
 
311
                                gdouble               a,
 
312
                                gdouble               b,
 
313
                                gdouble               c);
 
314
static void      restartrender (void);
 
315
static void      drawcolor1    (GtkWidget            *widget);
 
316
static void      drawcolor2    (GtkWidget            *widget);
 
317
static gboolean  render        (void);
 
318
static void      realrender    (GimpDrawable         *drawable);
 
319
static void      fileselect    (GtkFileChooserAction  action,
 
320
                                GtkWidget            *parent);
 
321
static gint      traceray      (ray                  *r,
 
322
                                GimpVector4          *col,
 
323
                                gint                  level,
 
324
                                gdouble               imp);
 
325
static gdouble   turbulence    (gdouble              *point,
 
326
                                gdouble               lofreq,
 
327
                                gdouble               hifreq);
317
328
 
318
329
 
319
330
#define COLORBUTTONWIDTH  30
958
969
          return;
959
970
        }
960
971
    }
961
 
  fprintf (stderr, "Error in gradient!\n");
 
972
  g_printerr ("Error in gradient!\n");
962
973
  vset (col, 0, 1, 0);
963
974
}
964
975
 
1167
1178
          continue;
1168
1179
          break;
1169
1180
        default:
1170
 
          fprintf (stderr, "Warning: unknown texture %d\n", t->type);
 
1181
          g_printerr ("Warning: unknown texture %d\n", t->type);
1171
1182
          break;
1172
1183
        }
1173
1184
      vmul (&tmpcol, t->amount);
1175
1186
    }
1176
1187
  if (!i)
1177
1188
    {
1178
 
      fprintf (stderr, "Warning: object %p has no textures\n", obj);
 
1189
      g_printerr ("Warning: object %p has no textures\n", obj);
1179
1190
    }
1180
1191
}
1181
1192
 
1203
1214
      vset (res, 1, 1, 1);      /* fixme */
1204
1215
      break;
1205
1216
    default:
1206
 
      fprintf (stderr, "objnormal(): Unsupported object type!?\n");
1207
 
      exit (0);
 
1217
      g_error ("objnormal(): Unsupported object type!?\n");
1208
1218
    }
1209
1219
  vnorm (res, 1.0);
1210
1220
 
1268
1278
          continue;
1269
1279
          break;
1270
1280
        default:
1271
 
          fprintf (stderr, "Warning: unknown texture %d\n", t->type);
 
1281
          g_printerr ("Warning: unknown texture %d\n", t->type);
1272
1282
          break;
1273
1283
        }
1274
1284
 
1468
1478
          t = checkcylinder (r, (cylinder *) & world.obj[i]);
1469
1479
          break;
1470
1480
        default:
1471
 
          fprintf (stderr, "Illegal object!!\n");
1472
 
          exit (0);
 
1481
          g_error ("Illegal object!!\n");
1473
1482
        }
1474
1483
      if (t <= 0.0)
1475
1484
        continue;
1807
1816
static gboolean noupdate = FALSE;
1808
1817
 
1809
1818
static void
1810
 
setvals (texture * t)
 
1819
setvals (texture *t)
1811
1820
{
1812
1821
  struct textures_t *l;
1813
1822
 
1885
1894
                                  &iter);
1886
1895
 
1887
1896
  s.com.numtexture++;
 
1897
 
1888
1898
  restartrender ();
1889
1899
}
1890
1900
 
1914
1924
                                  &iter);
1915
1925
 
1916
1926
  s.com.numtexture++;
 
1927
 
1917
1928
  restartrender ();
1918
1929
}
1919
1930
 
1920
1931
static void
1921
1932
rebuildlist (void)
1922
1933
{
1923
 
  GtkListStore *list_store;
1924
 
  GtkTreeIter   iter;
1925
 
  gint          n;
 
1934
  GtkListStore     *list_store;
 
1935
  GtkTreeSelection *sel;
 
1936
  GtkTreeIter       iter;
 
1937
  gint              n;
 
1938
 
 
1939
  sel = gtk_tree_view_get_selection (texturelist);
1926
1940
 
1927
1941
  for (n = 0; n < s.com.numtexture; n++)
1928
1942
    {
1948
1962
                          TEXTURE, &s.com.texture[n],
1949
1963
                          -1);
1950
1964
    }
 
1965
 
 
1966
  if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter))
 
1967
    gtk_tree_selection_select_iter (sel, &iter);
 
1968
 
1951
1969
  restartrender ();
1952
1970
}
1953
1971
 
1971
1989
      t->majtype = -1;
1972
1990
      gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
1973
1991
    }
 
1992
 
 
1993
  restartrender ();
1974
1994
}
1975
1995
 
1976
1996
static void
1981
2001
  gchar    line[1024];
1982
2002
  gint     i;
1983
2003
  texture *t;
 
2004
  gint     majtype, type;
 
2005
 
 
2006
  f = g_fopen (fn, "rt");
 
2007
  if (! f)
 
2008
    {
 
2009
      g_message (_("Could not open '%s' for reading: %s"),
 
2010
                 gimp_filename_to_utf8 (fn), g_strerror (errno));
 
2011
      return;
 
2012
    }
 
2013
 
 
2014
  if (2 != fscanf (f, "%d %d", &majtype, &type) || majtype < 0 || majtype > 2)
 
2015
    {
 
2016
      g_message (_("File '%s' is not a valid save file."),
 
2017
                 gimp_filename_to_utf8 (fn));
 
2018
      fclose (f);
 
2019
      return;
 
2020
    }
 
2021
 
 
2022
  rewind (f);
1984
2023
 
1985
2024
  s.com.numtexture = 0;
1986
2025
 
1987
 
  f = fopen (fn, "rt");
1988
 
  if (!f)
1989
 
    {
1990
 
      g_message (_("Could not open '%s' for reading: %s"),
1991
 
                 gimp_filename_to_utf8 (fn), g_strerror (errno));
1992
 
      return;
1993
 
    }
1994
 
 
1995
2026
  while (!feof (f))
1996
2027
    {
1997
2028
 
2082
2113
  FILE  *f;
2083
2114
  gchar  buf[G_ASCII_DTOSTR_BUF_SIZE];
2084
2115
 
2085
 
  f = fopen (fn, "wt");
 
2116
  f = g_fopen (fn, "wt");
2086
2117
  if (!f)
2087
2118
    {
2088
2119
      g_message (_("Could not open '%s' for writing: %s"),
2164
2195
  gchar *titles[]   = { N_("Open File"), N_("Save File") };
2165
2196
  void  *handlers[] = { loadpreset_response,   savepreset_response };
2166
2197
 
2167
 
  if (!windows[action])
 
2198
  if (! windows[action])
2168
2199
    {
2169
2200
      GtkWidget *dialog = windows[action] =
2170
2201
        gtk_file_chooser_dialog_new (gettext (titles[action]),
2179
2210
 
2180
2211
                                     NULL);
2181
2212
 
 
2213
      gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
 
2214
                                               GTK_RESPONSE_OK,
 
2215
                                               GTK_RESPONSE_CANCEL,
 
2216
                                               -1);
 
2217
 
2182
2218
      gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
2183
2219
 
 
2220
      if (action == GTK_FILE_CHOOSER_ACTION_SAVE)
 
2221
        gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
 
2222
                                                        TRUE);
 
2223
 
2184
2224
      g_signal_connect (dialog, "destroy",
2185
2225
                        G_CALLBACK (gtk_widget_destroyed),
2186
2226
                        &windows[action]);
2255
2295
  world.smartambient = 40.0;
2256
2296
}
2257
2297
 
2258
 
static void
2259
 
drawit (void)
2260
 
{
2261
 
  if (drawarea)
2262
 
    gtk_widget_queue_draw (drawarea);
2263
 
}
2264
 
 
2265
2298
static gboolean
2266
2299
expose_event (GtkWidget      *widget,
2267
2300
              GdkEventExpose *event)
2282
2315
static void
2283
2316
restartrender (void)
2284
2317
{
2285
 
  if (running)
2286
 
    {
2287
 
      running = 2;
2288
 
      return;
2289
 
    }
 
2318
  if (idle_id)
 
2319
    g_source_remove (idle_id);
2290
2320
 
2291
 
  render ();
 
2321
  idle_id = g_idle_add ((GSourceFunc) render, NULL);
2292
2322
}
2293
2323
 
2294
2324
static void
2338
2368
 
2339
2369
  if (noupdate)
2340
2370
    return;
 
2371
 
2341
2372
  t = currenttexture ();
2342
2373
  if (!t)
2343
2374
    return;
 
2375
 
2344
2376
  t->amount = GTK_ADJUSTMENT (amountscale)->value;
2345
2377
  t->exp = GTK_ADJUSTMENT (expscale)->value;
 
2378
 
2346
2379
  f = GTK_ADJUSTMENT (turbulencescale)->value;
2347
2380
  vset (&t->turbulence, f, f, f);
2348
2381
 
2349
2382
  t->oscale = GTK_ADJUSTMENT (scalescale)->value;
 
2383
 
2350
2384
  t->scale.x = GTK_ADJUSTMENT (scalexscale)->value;
2351
2385
  t->scale.y = GTK_ADJUSTMENT (scaleyscale)->value;
2352
2386
  t->scale.z = GTK_ADJUSTMENT (scalezscale)->value;
2358
2392
  t->translate.x = GTK_ADJUSTMENT (posxscale)->value;
2359
2393
  t->translate.y = GTK_ADJUSTMENT (posyscale)->value;
2360
2394
  t->translate.z = GTK_ADJUSTMENT (poszscale)->value;
 
2395
 
 
2396
  restartrender ();
2361
2397
}
2362
2398
 
2363
2399
 
2364
2400
static void
2365
 
color1_changed (GimpColorButton *button,
2366
 
                gpointer         data)
 
2401
color1_changed (GimpColorButton *button)
2367
2402
{
2368
2403
  texture *t = currenttexture ();
 
2404
 
2369
2405
  if (t)
2370
2406
    {
2371
 
      gimp_color_button_get_color (button, (GimpRGB *) &t->color1);
 
2407
      GimpRGB color;
 
2408
 
 
2409
      gimp_color_button_get_color (button, &color);
 
2410
 
 
2411
      t->color1.x = color.r;
 
2412
      t->color1.y = color.g;
 
2413
      t->color1.z = color.b;
 
2414
      t->color1.w = color.a;
 
2415
 
 
2416
      restartrender ();
2372
2417
    }
2373
2418
}
2374
2419
 
2375
2420
static void
2376
 
color2_changed (GimpColorButton *button,
2377
 
                gpointer         data)
 
2421
color2_changed (GimpColorButton *button)
2378
2422
{
2379
2423
  texture *t = currenttexture ();
 
2424
 
2380
2425
  if (t)
2381
2426
    {
2382
 
      gimp_color_button_get_color (button, (GimpRGB *) &t->color2);
 
2427
      GimpRGB color;
 
2428
 
 
2429
      gimp_color_button_get_color (button, &color);
 
2430
 
 
2431
      t->color2.x = color.r;
 
2432
      t->color2.y = color.g;
 
2433
      t->color2.z = color.b;
 
2434
      t->color2.w = color.a;
 
2435
 
 
2436
      restartrender ();
2383
2437
    }
2384
2438
}
2385
2439
 
2388
2442
{
2389
2443
  static GtkWidget *lastw = NULL;
2390
2444
 
 
2445
  GimpRGB  color;
2391
2446
  texture *t = currenttexture ();
2392
2447
 
2393
2448
  if (w)
2394
2449
    lastw = w;
2395
2450
  else
2396
2451
    w = lastw;
 
2452
 
2397
2453
  if (!w)
2398
2454
    return;
2399
2455
  if (!t)
2400
2456
    return;
2401
2457
 
2402
 
  gimp_color_button_set_color (GIMP_COLOR_BUTTON (w),
2403
 
                               (const GimpRGB *) &t->color1);
 
2458
  gimp_rgba_set (&color,
 
2459
                 t->color1.x, t->color1.y, t->color1.z, t->color1.w);
 
2460
 
 
2461
  gimp_color_button_set_color (GIMP_COLOR_BUTTON (w), &color);
2404
2462
}
2405
2463
 
2406
2464
static void
2408
2466
{
2409
2467
  static GtkWidget *lastw = NULL;
2410
2468
 
 
2469
  GimpRGB  color;
2411
2470
  texture *t = currenttexture ();
2412
2471
 
2413
2472
  if (w)
2414
2473
    lastw = w;
2415
2474
  else
2416
2475
    w = lastw;
 
2476
 
2417
2477
  if (!w)
2418
2478
    return;
2419
2479
  if (!t)
2420
2480
    return;
2421
2481
 
2422
 
  gimp_color_button_set_color (GIMP_COLOR_BUTTON (w),
2423
 
                               (const GimpRGB *) &t->color2);
 
2482
  gimp_rgba_set (&color,
 
2483
                 t->color2.x, t->color2.y, t->color2.z, t->color2.w);
 
2484
 
 
2485
  gimp_color_button_set_color (GIMP_COLOR_BUTTON (w), &color);
2424
2486
}
2425
2487
 
2426
2488
static gboolean do_run = FALSE;
2452
2514
      break;
2453
2515
 
2454
2516
    case GTK_RESPONSE_OK:
2455
 
      running = -1;
 
2517
      if (idle_id)
 
2518
        {
 
2519
          g_source_remove (idle_id);
 
2520
          idle_id = 0;
 
2521
        }
 
2522
 
2456
2523
      do_run = TRUE;
2457
2524
 
2458
2525
    default:
2462
2529
    }
2463
2530
}
2464
2531
 
2465
 
GtkWidget *
 
2532
static GtkWidget *
2466
2533
makewindow (void)
2467
2534
{
2468
2535
  GtkListStore      *store;
2469
2536
  GtkTreeViewColumn *col;
 
2537
  GtkTreeSelection  *selection;
2470
2538
  GtkWidget  *window;
2471
2539
  GtkWidget  *main_hbox;
 
2540
  GtkWidget  *main_vbox;
2472
2541
  GtkWidget  *table;
2473
2542
  GtkWidget  *frame;
2474
2543
  GtkWidget  *scrolled;
2476
2545
  GtkWidget  *vbox;
2477
2546
  GtkWidget  *button;
2478
2547
  GtkWidget  *list;
2479
 
  GimpRGB     rgb;
 
2548
  GimpRGB     rgb = { 0, 0, 0, 0 };
2480
2549
 
2481
 
  window = gimp_dialog_new (_("Sphere Designer"), "spheredesigner",
 
2550
  window = gimp_dialog_new (_("Sphere Designer"), PLUG_IN_BINARY,
2482
2551
                            NULL, 0,
2483
 
                            gimp_standard_help_func,
2484
 
                            "plug-in-spheredesigner",
 
2552
                            gimp_standard_help_func, PLUG_IN_PROC,
2485
2553
 
2486
2554
                            GIMP_STOCK_RESET, RESPONSE_RESET,
2487
2555
                            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
2489
2557
 
2490
2558
                            NULL);
2491
2559
 
 
2560
  gtk_dialog_set_alternative_button_order (GTK_DIALOG (window),
 
2561
                                           RESPONSE_RESET,
 
2562
                                           GTK_RESPONSE_OK,
 
2563
                                           GTK_RESPONSE_CANCEL,
 
2564
                                           -1);
 
2565
 
 
2566
  gimp_window_set_transient (GTK_WINDOW (window));
 
2567
 
2492
2568
  g_signal_connect (window, "response",
2493
2569
                    G_CALLBACK (sphere_response),
2494
2570
                    NULL);
2495
2571
 
 
2572
  main_vbox = gtk_vbox_new (FALSE, 12);
 
2573
  gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
 
2574
  gtk_container_add (GTK_CONTAINER (GTK_DIALOG (window)->vbox), main_vbox);
 
2575
  gtk_widget_show (main_vbox);
 
2576
 
2496
2577
  main_hbox = gtk_hbox_new (FALSE, 12);
2497
 
  gtk_container_set_border_width (GTK_CONTAINER (main_hbox), 12);
2498
 
  gtk_container_add (GTK_CONTAINER (GTK_DIALOG (window)->vbox), main_hbox);
 
2578
  gtk_box_pack_start (GTK_BOX (main_vbox), main_hbox, TRUE, TRUE, 0);
2499
2579
  gtk_widget_show (main_hbox);
2500
2580
 
2501
 
  vbox = gtk_vbox_new (FALSE, 6);
 
2581
  vbox = gtk_vbox_new (FALSE, 12);
2502
2582
  gtk_box_pack_start (GTK_BOX (main_hbox), vbox, FALSE, FALSE, 0);
2503
2583
  gtk_widget_show (vbox);
2504
2584
 
2512
2592
  gtk_widget_set_size_request (drawarea, PREVIEWSIZE, PREVIEWSIZE);
2513
2593
  gtk_widget_show (drawarea);
2514
2594
 
2515
 
  g_signal_connect (drawarea, "expose_event",
 
2595
  g_signal_connect (drawarea, "expose-event",
2516
2596
                    G_CALLBACK (expose_event), NULL);
2517
2597
 
2518
 
  button = gtk_button_new_with_mnemonic (_("Update _Preview"));
2519
 
  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
2520
 
  gtk_widget_show (button);
2521
 
 
2522
 
  g_signal_connect (button, "clicked",
2523
 
                    G_CALLBACK (restartrender), NULL);
2524
 
 
2525
2598
  hbox = gtk_hbox_new (TRUE, 0);
2526
2599
  gtk_box_pack_end (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
2527
2600
  gtk_widget_show (hbox);
2543
2616
                    window);
2544
2617
 
2545
2618
  vbox = gtk_vbox_new (FALSE, 6);
2546
 
  gtk_box_pack_start (GTK_BOX (main_hbox), vbox, FALSE, FALSE, 0);
 
2619
  gtk_box_pack_end (GTK_BOX (main_hbox), vbox, TRUE, TRUE, 0);
2547
2620
  gtk_widget_show (vbox);
2548
2621
 
2549
2622
  scrolled = gtk_scrolled_window_new (NULL, NULL);
2561
2634
 
2562
2635
  texturelist = GTK_TREE_VIEW (list);
2563
2636
 
2564
 
  g_signal_connect (gtk_tree_view_get_selection (texturelist), "changed",
 
2637
  selection = gtk_tree_view_get_selection (texturelist);
 
2638
 
 
2639
  gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
 
2640
 
 
2641
  g_signal_connect (selection, "changed",
2565
2642
                    G_CALLBACK (selectitem),
2566
2643
                    NULL);
2567
2644
 
2569
2646
  gtk_container_add (GTK_CONTAINER (scrolled), list);
2570
2647
  gtk_widget_show (list);
2571
2648
 
2572
 
  col = gtk_tree_view_column_new_with_attributes (_("Textures"),
 
2649
  col = gtk_tree_view_column_new_with_attributes (_("Layers"),
2573
2650
                                                  gtk_cell_renderer_text_new (),
2574
2651
                                                  "text", TYPE,
2575
2652
                                                  NULL);
2597
2674
                            G_CALLBACK (deltexture), NULL);
2598
2675
  gtk_widget_show (button);
2599
2676
 
2600
 
  frame = gimp_frame_new (_("Texture Properties"));
 
2677
  main_hbox = gtk_hbox_new (FALSE, 12);
 
2678
  gtk_box_pack_start (GTK_BOX (main_vbox), main_hbox, FALSE, FALSE, 0);
 
2679
  gtk_widget_show (main_hbox);
 
2680
 
 
2681
  frame = gimp_frame_new (_("Properties"));
2601
2682
  gtk_box_pack_start (GTK_BOX (main_hbox), frame, TRUE, TRUE, 0);
2602
2683
  gtk_widget_show (frame);
2603
2684
 
2624
2705
                             _("Type:"), 0.0, 0.5,
2625
2706
                             typemenu, 2, FALSE);
2626
2707
 
2627
 
  texturemenu = gimp_int_combo_box_new (NULL, 0);
2628
 
 
 
2708
  texturemenu = g_object_new (GIMP_TYPE_INT_COMBO_BOX, NULL);
2629
2709
  {
2630
2710
    struct textures_t *t;
2631
2711
 
2656
2736
  gtk_widget_show (button);
2657
2737
  drawcolor1 (button);
2658
2738
 
2659
 
  g_signal_connect (button, "color_changed",
 
2739
  g_signal_connect (button, "color-changed",
2660
2740
                    G_CALLBACK (color1_changed),
2661
2741
                    NULL);
2662
2742
 
2667
2747
  gtk_widget_show (button);
2668
2748
  drawcolor2 (button);
2669
2749
 
2670
 
  g_signal_connect (button, "color_changed",
 
2750
  g_signal_connect (button, "color-changed",
2671
2751
                    G_CALLBACK (color2_changed),
2672
2752
                    NULL);
2673
2753
 
2674
2754
  scalescale = gimp_scale_entry_new (GTK_TABLE (table), 0, 3, _("Scale:"),
2675
2755
                                     100, -1, 1.0, 0.0, 10.0, 0.1, 1.0, 1,
2676
2756
                                     TRUE, 0.0, 0.0, NULL, NULL);
2677
 
  g_signal_connect (scalescale, "value_changed",
 
2757
  g_signal_connect (scalescale, "value-changed",
2678
2758
                    G_CALLBACK (getscales),
2679
2759
                    NULL);
2680
2760
 
2682
2762
                                          _("Turbulence:"),
2683
2763
                                          100, -1, 1.0, 0.0, 10.0, 0.1, 1.0, 1,
2684
2764
                                          TRUE, 0.0, 0.0, NULL, NULL);
2685
 
  g_signal_connect (turbulencescale, "value_changed",
 
2765
  g_signal_connect (turbulencescale, "value-changed",
2686
2766
                    G_CALLBACK (getscales),
2687
2767
                    NULL);
2688
2768
 
2689
2769
  amountscale = gimp_scale_entry_new (GTK_TABLE (table), 0, 5, _("Amount:"),
2690
2770
                                       100, -1, 1.0, 0.0, 1.0, 0.01, 0.1, 2,
2691
2771
                                       TRUE, 0.0, 0.0, NULL, NULL);
2692
 
  g_signal_connect (amountscale, "value_changed",
 
2772
  g_signal_connect (amountscale, "value-changed",
2693
2773
                    G_CALLBACK (getscales),
2694
2774
                    NULL);
2695
2775
 
2696
2776
  expscale = gimp_scale_entry_new (GTK_TABLE (table), 0, 6, _("Exp.:"),
2697
2777
                                   100, -1, 1.0, 0.0, 1.0, 0.01, 0.1, 2,
2698
2778
                                   TRUE, 0.0, 0.0, NULL, NULL);
2699
 
  g_signal_connect (expscale, "value_changed",
 
2779
  g_signal_connect (expscale, "value-changed",
2700
2780
                    G_CALLBACK (getscales),
2701
2781
                    NULL);
2702
2782
 
2703
 
  frame = gimp_frame_new (_("Texture Transformations"));
 
2783
  frame = gimp_frame_new (_("Transformations"));
2704
2784
  gtk_box_pack_start (GTK_BOX (main_hbox), frame, TRUE, TRUE, 0);
2705
2785
  gtk_widget_show (frame);
2706
2786
 
2719
2799
  scalexscale = gimp_scale_entry_new (GTK_TABLE (table), 0, 0, _("Scale X:"),
2720
2800
                                      100, -1, 1.0, 0.0, 10.0, 0.1, 1.0, 2,
2721
2801
                                      TRUE, 0.0, 0.0, NULL, NULL);
2722
 
  g_signal_connect (scalexscale, "value_changed",
 
2802
  g_signal_connect (scalexscale, "value-changed",
2723
2803
                    G_CALLBACK (getscales),
2724
2804
                    NULL);
2725
2805
 
2726
2806
  scaleyscale = gimp_scale_entry_new (GTK_TABLE (table), 0, 1, _("Scale Y:"),
2727
2807
                                      100, -1, 1.0, 0.0, 10.0, 0.1, 1.0, 2,
2728
2808
                                      TRUE, 0.0, 0.0, NULL, NULL);
2729
 
  g_signal_connect (scaleyscale, "value_changed",
 
2809
  g_signal_connect (scaleyscale, "value-changed",
2730
2810
                    G_CALLBACK (getscales),
2731
2811
                    NULL);
2732
2812
  scalezscale = gimp_scale_entry_new (GTK_TABLE (table), 0, 2, _("Scale Z:"),
2733
2813
                                      100, -1, 1.0, 0.0, 10.0, 0.1, 1.0, 2,
2734
2814
                                      TRUE, 0.0, 0.0, NULL, NULL);
2735
 
  g_signal_connect (scalezscale, "value_changed",
 
2815
  g_signal_connect (scalezscale, "value-changed",
2736
2816
                    G_CALLBACK (getscales),
2737
2817
                    NULL);
2738
2818
 
2739
2819
  rotxscale = gimp_scale_entry_new (GTK_TABLE (table), 0, 3, _("Rotate X:"),
2740
2820
                                    100, -1, 0.0, 0.0, 360.0, 1.0, 10.0, 1,
2741
2821
                                    TRUE, 0.0, 0.0, NULL, NULL);
2742
 
  g_signal_connect (rotxscale, "value_changed",
 
2822
  g_signal_connect (rotxscale, "value-changed",
2743
2823
                    G_CALLBACK (getscales),
2744
2824
                    NULL);
2745
2825
 
2746
2826
  rotyscale = gimp_scale_entry_new (GTK_TABLE (table), 0, 4, _("Rotate Y:"),
2747
2827
                                    100, -1, 0.0, 0.0, 360.0, 1.0, 10.0, 1,
2748
2828
                                    TRUE, 0.0, 0.0, NULL, NULL);
2749
 
  g_signal_connect (rotyscale, "value_changed",
 
2829
  g_signal_connect (rotyscale, "value-changed",
2750
2830
                    G_CALLBACK (getscales),
2751
2831
                    NULL);
2752
2832
 
2753
2833
  rotzscale = gimp_scale_entry_new (GTK_TABLE (table), 0, 5, _("Rotate Z:"),
2754
2834
                                    100, -1, 0.0, 0.0, 360.0, 1.0, 10.0, 1,
2755
2835
                                    TRUE, 0.0, 0.0, NULL, NULL);
2756
 
  g_signal_connect (rotzscale, "value_changed",
 
2836
  g_signal_connect (rotzscale, "value-changed",
2757
2837
                    G_CALLBACK (getscales),
2758
2838
                    NULL);
2759
2839
 
2760
2840
  posxscale = gimp_scale_entry_new (GTK_TABLE (table), 0, 6, _("Position X:"),
2761
2841
                                    100, -1, 0.0, -20.0, 20.0, 0.1, 1.0, 1,
2762
2842
                                    TRUE, 0.0, 0.0, NULL, NULL);
2763
 
  g_signal_connect (rotxscale, "value_changed",
 
2843
  g_signal_connect (posxscale, "value-changed",
2764
2844
                    G_CALLBACK (getscales),
2765
2845
                    NULL);
2766
2846
 
2767
2847
  posyscale = gimp_scale_entry_new (GTK_TABLE (table), 0, 7, _("Position Y:"),
2768
2848
                                    100, -1, 0.0, -20.0, 20.0, 0.1, 1.0, 1,
2769
2849
                                    TRUE, 0.0, 0.0, NULL, NULL);
2770
 
  g_signal_connect (rotyscale, "value_changed",
 
2850
  g_signal_connect (posyscale, "value-changed",
2771
2851
                    G_CALLBACK (getscales),
2772
2852
                    NULL);
2773
2853
 
2774
2854
  poszscale = gimp_scale_entry_new (GTK_TABLE (table), 0, 8, _("Position Z:"),
2775
2855
                                    100, -1, 0.0, -20.0, 20.0, 0.1, 1.0, 1,
2776
2856
                                    TRUE, 0.0, 0.0, NULL, NULL);
2777
 
  g_signal_connect (rotzscale, "value_changed",
 
2857
  g_signal_connect (poszscale, "value-changed",
2778
2858
                    G_CALLBACK (getscales),
2779
2859
                    NULL);
2780
2860
 
2794
2874
  return v;
2795
2875
}
2796
2876
 
2797
 
static void
 
2877
static gboolean
2798
2878
render (void)
2799
2879
{
 
2880
  GimpVector4  col;
 
2881
  guchar *dest_row;
 
2882
  ray     r;
2800
2883
  gint    x, y, p;
2801
 
  ray     r;
2802
 
  GimpVector4  col;
2803
2884
  gint    hit;
2804
 
  gint    tx, ty;
2805
 
  guchar *dest_row;
2806
 
  gint    bpp;
 
2885
  gint    tx  = PREVIEWSIZE;
 
2886
  gint    ty  = PREVIEWSIZE;
 
2887
  gint    bpp = 3;
 
2888
 
 
2889
  idle_id = 0;
 
2890
 
 
2891
  initworld ();
2807
2892
 
2808
2893
  r.v1.z = -10.0;
2809
2894
  r.v2.z = 0.0;
2810
2895
 
2811
 
  running = 2;
2812
 
 
2813
 
  tx = PREVIEWSIZE;
2814
 
  ty = PREVIEWSIZE;
2815
 
  bpp = 3;
2816
 
 
2817
 
  while (running > 0)
 
2896
  if (world.obj[0].com.numtexture > 0)
2818
2897
    {
2819
 
 
2820
 
      if (running == 2)
2821
 
        {
2822
 
          running = 1;
2823
 
          initworld ();
2824
 
        }
2825
 
      if (world.obj[0].com.numtexture == 0)
2826
 
        break;
2827
 
 
2828
2898
      for (y = 0; y < ty; y++)
2829
2899
        {
2830
2900
          dest_row = img + y * PREVIEWSIZE * 3;
2853
2923
                pixelval (255 * col.y) * col.w + g * (1.0 - col.w);
2854
2924
              dest_row[p + 2] =
2855
2925
                pixelval (255 * col.z) * col.w + g * (1.0 - col.w);
2856
 
 
2857
 
              if (running != 1)
2858
 
                {
2859
 
                  break;
2860
 
                }
2861
 
            }
2862
 
 
2863
 
#if CONTINOUS_UPDATE
2864
 
          drawit ();
2865
 
 
2866
 
          while (gtk_events_pending ())
2867
 
            gtk_main_iteration ();
2868
 
#endif
2869
 
 
2870
 
          if (running != 1)
2871
 
            {
2872
 
              break;
2873
 
            }
 
2926
             }
2874
2927
        }
2875
 
      if (running == 1)
2876
 
        break;
2877
 
      if (running == -1)
2878
 
        break;
2879
2928
    }
2880
2929
 
2881
 
  running = 0;
2882
 
  drawit ();
 
2930
  gtk_widget_queue_draw (drawarea);
 
2931
 
 
2932
  return FALSE;
2883
2933
}
2884
2934
 
2885
2935
static void
2895
2945
  GimpPixelRgn  pr, dpr;
2896
2946
  guchar       *buffer, *ibuffer;
2897
2947
 
2898
 
  if (running > 0)
2899
 
    return;                     /* Fixme: abort preview-render instead! */
2900
 
 
2901
2948
  initworld ();
2902
2949
 
2903
2950
  r.v1.z = -10.0;
2919
2966
  tx = x2 - x1;
2920
2967
  ty = y2 - y1;
2921
2968
 
2922
 
  gimp_progress_init (_("Rendering Sphere..."));
 
2969
  gimp_progress_init (_("Rendering sphere"));
2923
2970
 
2924
2971
  for (y = 0; y < ty; y++)
2925
2972
    {
2961
3008
static void
2962
3009
query (void)
2963
3010
{
2964
 
  static GimpParamDef args[] =
 
3011
  static const GimpParamDef args[] =
2965
3012
  {
2966
 
    { GIMP_PDB_INT32,    "run_mode", "Interactive, non-interactive" },
 
3013
    { GIMP_PDB_INT32,    "run-mode", "Interactive, non-interactive" },
2967
3014
    { GIMP_PDB_IMAGE,    "image",    "Input image (unused)"         },
2968
3015
    { GIMP_PDB_DRAWABLE, "drawable", "Input drawable"               }
2969
3016
  };
2970
3017
 
2971
 
  gimp_install_procedure ("plug_in_spheredesigner",
2972
 
                          "Renders textures spheres",
 
3018
  gimp_install_procedure (PLUG_IN_PROC,
 
3019
                          N_("Create an image of a textured sphere"),
2973
3020
                          "This plugin can be used to create textured and/or "
2974
3021
                          "bumpmapped spheres, and uses a small lightweight "
2975
3022
                          "raytracer to perform the task with good quality",
2982
3029
                          G_N_ELEMENTS (args), 0,
2983
3030
                          args, NULL);
2984
3031
 
2985
 
  gimp_plugin_menu_register ("plug_in_spheredesigner",
2986
 
                             "<Image>/Filters/Render");
 
3032
  gimp_plugin_menu_register (PLUG_IN_PROC, "<Image>/Filters/Render");
2987
3033
}
2988
3034
 
2989
3035
static gboolean
2990
3036
sphere_main (GimpDrawable *drawable)
2991
3037
{
2992
 
  initworld ();
2993
 
 
2994
 
  gimp_ui_init ("spheredesigner", TRUE);
 
3038
  gimp_ui_init (PLUG_IN_BINARY, TRUE);
2995
3039
 
2996
3040
  memset (img, 0, PREVIEWSIZE * PREVIEWSIZE * 3);
2997
3041
  makewindow ();
3017
3061
  GimpDrawable      *drawable;
3018
3062
  GimpRunMode        run_mode;
3019
3063
  GimpPDBStatusType  status = GIMP_PDB_SUCCESS;
 
3064
  gint               x, y, w, h;
3020
3065
 
3021
3066
  run_mode = param[0].data.d_int32;
3022
3067
 
3030
3075
 
3031
3076
  drawable = gimp_drawable_get (param[2].data.d_drawable);
3032
3077
 
 
3078
  if (! gimp_drawable_mask_intersect (drawable->drawable_id, &x, &y, &w, &h))
 
3079
    {
 
3080
      g_message (_("Region selected for plug-in is empty"));
 
3081
      return;
 
3082
    }
 
3083
 
3033
3084
  switch (run_mode)
3034
3085
    {
3035
3086
    case GIMP_RUN_INTERACTIVE:
3036
3087
      s.com.numtexture = 0;
3037
 
      gimp_get_data (PLUG_IN_NAME, &s);
 
3088
      gimp_get_data (PLUG_IN_PROC, &s);
3038
3089
      if (!sphere_main (drawable))
3039
3090
        {
3040
3091
          gimp_drawable_detach (drawable);
3043
3094
      break;
3044
3095
    case GIMP_RUN_WITH_LAST_VALS:
3045
3096
      s.com.numtexture = 0;
3046
 
      gimp_get_data (PLUG_IN_NAME, &s);
 
3097
      gimp_get_data (PLUG_IN_PROC, &s);
3047
3098
      if (s.com.numtexture == 0)
3048
3099
        {
3049
3100
          gimp_drawable_detach (drawable);
3057
3108
      return;
3058
3109
    }
3059
3110
 
3060
 
  gimp_set_data (PLUG_IN_NAME, &s, sizeof (s));
 
3111
  gimp_set_data (PLUG_IN_PROC, &s, sizeof (s));
3061
3112
 
3062
3113
  realrender (drawable);
3063
3114
  gimp_displays_flush ();