about-dialog.c 41.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/* The GIMP -- an image manipulation program
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
18 19 20

#include "config.h"

Tor Lillqvist's avatar
Tor Lillqvist committed
21
#include <string.h>
Elliot Lee's avatar
Elliot Lee committed
22
#include <time.h>
Manish Singh's avatar
Manish Singh committed
23

24
#include <gtk/gtk.h>
Manish Singh's avatar
Manish Singh committed
25
#include <gdk/gdkkeysyms.h>
Manish Singh's avatar
Manish Singh committed
26

27
#include "libgimpmath/gimpmath.h"
28
#include "libgimpbase/gimpbase.h"
29
#include "libgimpwidgets/gimpwidgets.h"
30

31
#include "dialogs-types.h"
Sven Neumann's avatar
Sven Neumann committed
32

Michael Natterer's avatar
Michael Natterer committed
33
#include "core/gimptoolinfo.h"
34

35
#include "widgets/gimphelp-ids.h"
Michael Natterer's avatar
Michael Natterer committed
36 37
#include "widgets/gimpdnd.h"

38
#include "about-dialog.h"
Michael Natterer's avatar
Michael Natterer committed
39
#include "authors.h"
40

41
#include "gimp-intl.h"
42

43 44 45 46 47 48 49 50 51
static gchar *founders[] =
{
  N_("Version %s brought to you by"),
  "Spencer Kimball & Peter Mattis"
};

static gchar *translators[] =
{
  N_("Translation by"),
52
  /* Translators: insert your names here, separated by newline */
Sven Neumann's avatar
Sven Neumann committed
53
  /* we'd prefer just the names, please no email addresses.    */
54
  N_("translator-credits"),
55 56 57 58
};

static gchar *contri_intro[] =
{
59 60
  N_("Contributions by")
};
61

62 63
static gchar **translator_names = NULL;

64 65 66 67 68 69
typedef struct
{
  GtkWidget    *about_dialog;
  GtkWidget    *logo_area;
  GdkPixmap    *logo_pixmap;
  GdkRectangle  pixmaparea;
70

71 72 73 74
  GdkBitmap    *shape_bitmap;
  GdkGC        *trans_gc;
  GdkGC        *opaque_gc;

75 76 77 78 79 80 81 82
  GdkRectangle  textarea;
  gdouble       text_size;
  gdouble       min_text_size;
  PangoLayout  *layout;

  gint          timer;

  gint          index;
83
  gint          animstep;
84 85 86 87 88 89 90 91
  gboolean      visible;
  gint          textrange[2];
  gint          state;

} GimpAboutInfo;

PangoColor gradient[] =
{
92
  { 139 * 257, 137 * 257, 124 * 257 },
93
  { 65535, 65535, 65535 },
94
  { 5000, 5000, 5000 },
95 96
};

97 98
PangoColor foreground = { 5000, 5000, 5000 };
PangoColor background = { 139 * 257, 137 * 257, 124 * 257 };
99 100 101 102 103 104 105

/* backup values */

PangoColor grad1ent[] =
{
  { 0xff * 257, 0xba * 257, 0x00 * 257 },
  { 37522, 51914, 57568 },
106 107
};

108 109 110
PangoColor foregr0und = { 37522, 51914, 57568 };
PangoColor backgr0und = { 0, 0, 0 };

111
static GimpAboutInfo about_info = { 0, };
112
static gboolean pp = FALSE;
113

114 115 116 117 118
static gboolean  about_dialog_load_logo   (GtkWidget         *window);
static void      about_dialog_destroy     (GtkObject         *object,
                                           gpointer           data);
static void      about_dialog_unmap       (GtkWidget         *widget,
                                           gpointer           data);
119 120
static void      about_dialog_center      (GtkWindow         *window);
static gboolean  about_dialog_logo_expose (GtkWidget         *widget,
121 122 123 124 125 126 127 128
                                           GdkEventExpose    *event,
                                           gpointer           data);
static gint      about_dialog_button      (GtkWidget         *widget,
                                           GdkEventButton    *event,
                                           gpointer           data);
static gint      about_dialog_key         (GtkWidget         *widget,
                                           GdkEventKey       *event,
                                           gpointer           data);
129
static void      reshuffle_array          (void);
130
static gboolean  about_dialog_timer       (gpointer           data);
Elliot Lee's avatar
Elliot Lee committed
131 132


133
static PangoFontDescription  *font_desc     = NULL;
Sven Neumann's avatar
Sven Neumann committed
134
static const gchar          **scroll_text   = authors;
135 136
static gint                   nscroll_texts = G_N_ELEMENTS (authors);
static gint                   shuffle_array[G_N_ELEMENTS (authors)];
137

Michael Natterer's avatar
Michael Natterer committed
138

139
GtkWidget *
140
about_dialog_create (void)
Elliot Lee's avatar
Elliot Lee committed
141
{
142 143
  if (! about_info.about_dialog)
    {
144 145
      GtkWidget   *widget;
      GdkGCValues  shape_gcv;
146 147 148

      about_info.visible = FALSE;
      about_info.state = 0;
149
      about_info.animstep = -1;
150

151 152 153 154 155 156
      widget = g_object_new (GTK_TYPE_WINDOW,
                             "type",            GTK_WINDOW_POPUP,
                             "title",           _("About The GIMP"),
                             "window_position", GTK_WIN_POS_CENTER,
                             "resizable",       FALSE,
                             NULL);
157

158
      about_info.about_dialog = widget;
159

160
      gtk_window_set_role (GTK_WINDOW (widget), "about-dialog");
161 162 163 164 165 166 167

      g_signal_connect (widget, "destroy",
                        G_CALLBACK (about_dialog_destroy),
                        NULL);
      g_signal_connect (widget, "unmap",
                        G_CALLBACK (about_dialog_unmap),
                        NULL);
168
      g_signal_connect (widget, "button-press-event",
169 170
                        G_CALLBACK (about_dialog_button),
                        NULL);
171
      g_signal_connect (widget, "key-press-event",
172 173
                        G_CALLBACK (about_dialog_key),
                        NULL);
Michael Natterer's avatar
Michael Natterer committed
174

175 176 177 178
      gtk_widget_set_events (widget, GDK_BUTTON_PRESS_MASK);

      if (! about_dialog_load_logo (widget))
        {
179 180 181 182
          gtk_widget_destroy (widget);
          about_info.about_dialog = NULL;
          return NULL;
        }
Elliot Lee's avatar
Elliot Lee committed
183

184
      about_dialog_center (GTK_WINDOW (widget));
185

186 187
      /* place the scrolltext at the bottom of the image */
      about_info.textarea.width = about_info.pixmaparea.width;
188
      about_info.textarea.height = 32; /* gets changed in _expose () as well */
189 190 191 192
      about_info.textarea.x = 0;
      about_info.textarea.y = (about_info.pixmaparea.height -
                               about_info.textarea.height);

193 194
      widget = gtk_drawing_area_new ();
      about_info.logo_area = widget;
Elliot Lee's avatar
Elliot Lee committed
195

196 197 198 199 200 201 202
      gtk_widget_set_size_request (widget,
                                   about_info.pixmaparea.width,
                                   about_info.pixmaparea.height);
      gtk_widget_set_events (widget, GDK_EXPOSURE_MASK);
      gtk_container_add (GTK_CONTAINER (about_info.about_dialog),
                         widget);
      gtk_widget_show (widget);
Elliot Lee's avatar
Elliot Lee committed
203

204
      g_signal_connect (widget, "expose-event",
205 206
                        G_CALLBACK (about_dialog_logo_expose),
                        NULL);
207

208 209 210 211
      gtk_widget_realize (widget);
      gdk_window_set_background (widget->window,
                                 &(widget->style)->black);

212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
      /* setup shape bitmap */

      about_info.shape_bitmap = gdk_pixmap_new (widget->window,
                                                about_info.pixmaparea.width,
                                                about_info.pixmaparea.height,
                                                1);
      about_info.trans_gc = gdk_gc_new (about_info.shape_bitmap);

      about_info.opaque_gc = gdk_gc_new (about_info.shape_bitmap);
      gdk_gc_get_values (about_info.opaque_gc, &shape_gcv);
      gdk_gc_set_foreground (about_info.opaque_gc, &shape_gcv.background);

      gdk_draw_rectangle (about_info.shape_bitmap,
                          about_info.trans_gc,
                          TRUE,
                          0, 0,
                          about_info.pixmaparea.width,
                          about_info.pixmaparea.height);

      gdk_draw_line (about_info.shape_bitmap,
                     about_info.opaque_gc,
                     0, 0,
                     about_info.pixmaparea.width, 0);

      gtk_widget_shape_combine_mask (about_info.about_dialog,
                                     about_info.shape_bitmap,
                                     0, 0);
      about_info.layout = gtk_widget_create_pango_layout (about_info.logo_area,
                                                          NULL);
Michael Natterer's avatar
Michael Natterer committed
241
      g_object_weak_ref (G_OBJECT (about_info.logo_area),
242 243
                         (GWeakNotify) g_object_unref, about_info.layout);

244
      font_desc = pango_font_description_from_string ("Sans, 11");
245 246 247 248

      pango_layout_set_font_description (about_info.layout, font_desc);
      pango_layout_set_justify (about_info.layout, PANGO_ALIGN_CENTER);

Elliot Lee's avatar
Elliot Lee committed
249 250
    }

251
  if (! GTK_WIDGET_VISIBLE (about_info.about_dialog))
Elliot Lee's avatar
Elliot Lee committed
252
    {
253 254
      about_info.state = 0;
      about_info.index = 0;
255

256 257
      reshuffle_array ();
      pango_layout_set_text (about_info.layout, "", -1);
Elliot Lee's avatar
Elliot Lee committed
258
    }
259

260
  gtk_window_present (GTK_WINDOW (about_info.about_dialog));
261

262
  return about_info.about_dialog;
Elliot Lee's avatar
Elliot Lee committed
263 264 265
}

static void
266
about_dialog_destroy (GtkObject *object,
267
                      gpointer   data)
Elliot Lee's avatar
Elliot Lee committed
268
{
269
  about_info.about_dialog = NULL;
270
  about_dialog_unmap (NULL, NULL);
Elliot Lee's avatar
Elliot Lee committed
271 272 273
}

static void
274
about_dialog_unmap (GtkWidget *widget,
275
                    gpointer   data)
Elliot Lee's avatar
Elliot Lee committed
276
{
277
  if (about_info.timer)
Elliot Lee's avatar
Elliot Lee committed
278
    {
279 280
      g_source_remove (about_info.timer);
      about_info.timer = 0;
Elliot Lee's avatar
Elliot Lee committed
281
    }
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300

  if (about_info.about_dialog)
    {
      gdk_draw_rectangle (about_info.shape_bitmap,
                          about_info.trans_gc,
                          TRUE,
                          0, 0,
                          about_info.pixmaparea.width,
                          about_info.pixmaparea.height);

      gdk_draw_line (about_info.shape_bitmap,
                     about_info.opaque_gc,
                     0, 0,
                     about_info.pixmaparea.width, 0);

      gtk_widget_shape_combine_mask (about_info.about_dialog,
                                     about_info.shape_bitmap,
                                     0, 0);
    }
Elliot Lee's avatar
Elliot Lee committed
301 302
}

303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
static void
about_dialog_center (GtkWindow *window)
{
  GdkDisplay   *display = gtk_widget_get_display (GTK_WIDGET (window));
  GdkScreen    *screen;
  GdkRectangle  rect;
  gint          monitor;
  gint          x, y;

  gdk_display_get_pointer (display, &screen, &x, &y, NULL);

  monitor = gdk_screen_get_monitor_at_point (screen, x, y);
  gdk_screen_get_monitor_geometry (screen, monitor, &rect);

  gtk_window_set_screen (window, screen);
  gtk_window_move (window,
Sven Neumann's avatar
Sven Neumann committed
319 320
                   rect.x + (rect.width  - about_info.pixmaparea.width)  / 2,
                   rect.y + (rect.height - about_info.pixmaparea.height) / 2);
321 322 323
}

static gboolean
Elliot Lee's avatar
Elliot Lee committed
324
about_dialog_logo_expose (GtkWidget      *widget,
325 326
                          GdkEventExpose *event,
                          gpointer        data)
Elliot Lee's avatar
Elliot Lee committed
327
{
328 329 330
  gint width, height;

  if (!about_info.timer)
331
    {
332 333
      GdkModifierType mask;

334 335
      /* No timeout, we were unmapped earlier */
      about_info.state = 0;
336
      about_info.index = 1;
337 338 339
      about_info.animstep = -1;
      about_info.visible = FALSE;
      reshuffle_array ();
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
      gdk_draw_rectangle (about_info.shape_bitmap,
                          about_info.trans_gc,
                          TRUE,
                          0, 0,
                          about_info.pixmaparea.width,
                          about_info.pixmaparea.height);

      gdk_draw_line (about_info.shape_bitmap,
                     about_info.opaque_gc,
                     0, 0,
                     about_info.pixmaparea.width, 0);

      gtk_widget_shape_combine_mask (about_info.about_dialog,
                                     about_info.shape_bitmap,
                                     0, 0);
355
      about_info.timer = g_timeout_add (30, about_dialog_timer, NULL);
356 357 358 359 360

      gdk_window_get_pointer (NULL, NULL, NULL, &mask);

      /* weird magic to determine the way the logo should be shown */
      mask &= ~GDK_BUTTON3_MASK;
Michael Natterer's avatar
Michael Natterer committed
361
      pp = (mask &= (GDK_SHIFT_MASK | GDK_CONTROL_MASK) &
362 363 364 365 366
                    (GDK_CONTROL_MASK | GDK_MOD1_MASK) &
                    (GDK_MOD1_MASK | ~GDK_SHIFT_MASK),
      height = mask ? (about_info.pixmaparea.height > 0) &&
                      (about_info.pixmaparea.width > 0): 0);

367 368 369
      about_info.textarea.height = pp ? 50 : 32;
      about_info.textarea.y = (about_info.pixmaparea.height -
                               about_info.textarea.height);
370
    }
371 372 373 374 375 376 377 378 379 380 381 382

  /* only operate on the region covered by the pixmap */
  if (! gdk_rectangle_intersect (&(about_info.pixmaparea),
                                 &(event->area),
                                 &(event->area)))
    return FALSE;

  gdk_gc_set_clip_rectangle (widget->style->black_gc, &(event->area));

  gdk_draw_drawable (widget->window,
                     widget->style->white_gc,
                     about_info.logo_pixmap,
383 384
                     event->area.x, event->area.y +
                     (pp ? about_info.pixmaparea.height : 0),
385 386 387
                     event->area.x, event->area.y,
                     event->area.width, event->area.height);

Simon Budig's avatar
Simon Budig committed
388
  if (pp && about_info.state == 0 &&
389 390 391 392 393 394 395 396
      (about_info.index < about_info.pixmaparea.height / 12 ||
       about_info.index < g_random_int () %
                          (about_info.pixmaparea.height / 8 + 13)))
    {
      gdk_draw_rectangle (widget->window,
                          widget->style->black_gc,
                          TRUE,
                          0, 0, about_info.pixmaparea.width, 158);
Michael Natterer's avatar
Michael Natterer committed
397

398 399
    }

400
  if (about_info.visible == TRUE)
Elliot Lee's avatar
Elliot Lee committed
401
    {
402 403 404 405 406 407 408 409
      gint layout_x, layout_y;

      pango_layout_get_pixel_size (about_info.layout, &width, &height);

      layout_x = about_info.textarea.x +
                        (about_info.textarea.width - width) / 2;
      layout_y = about_info.textarea.y +
                        (about_info.textarea.height - height) / 2;
Michael Natterer's avatar
Michael Natterer committed
410

411 412 413 414 415 416
      if (about_info.textrange[1] > 0)
        {
          GdkRegion *covered_region = NULL;
          GdkRegion *rect_region;

          covered_region = gdk_pango_layout_get_clip_region
417 418 419
                                    (about_info.layout,
                                     layout_x, layout_y,
                                     about_info.textrange, 1);
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435

          rect_region = gdk_region_rectangle (&(event->area));

          gdk_region_intersect (covered_region, rect_region);
          gdk_region_destroy (rect_region);

          gdk_gc_set_clip_region (about_info.logo_area->style->text_gc[GTK_STATE_NORMAL],
                                  covered_region);
          gdk_region_destroy (covered_region);
        }

      gdk_draw_layout (widget->window,
                       widget->style->text_gc[GTK_STATE_NORMAL],
                       layout_x, layout_y,
                       about_info.layout);

Elliot Lee's avatar
Elliot Lee committed
436 437
    }

438 439
  gdk_gc_set_clip_rectangle (widget->style->black_gc, NULL);

Elliot Lee's avatar
Elliot Lee committed
440 441 442
  return FALSE;
}

443
static gint
Elliot Lee's avatar
Elliot Lee committed
444
about_dialog_button (GtkWidget      *widget,
445 446
                     GdkEventButton *event,
                     gpointer        data)
Elliot Lee's avatar
Elliot Lee committed
447
{
448
  gtk_widget_hide (about_info.about_dialog);
Elliot Lee's avatar
Elliot Lee committed
449 450 451 452

  return FALSE;
}

Manish Singh's avatar
Manish Singh committed
453 454
static gint
about_dialog_key (GtkWidget      *widget,
455 456
                  GdkEventKey    *event,
                  gpointer        data)
Manish Singh's avatar
Manish Singh committed
457
{
458
  /* placeholder */
Manish Singh's avatar
Manish Singh committed
459 460 461 462
  switch (event->keyval)
    {
    case GDK_a:
    case GDK_A:
463 464
    case GDK_b:
    case GDK_B:
Manish Singh's avatar
Manish Singh committed
465
    default:
466
        break;
Manish Singh's avatar
Manish Singh committed
467
    }
Michael Natterer's avatar
Michael Natterer committed
468

469 470 471 472 473 474 475 476 477 478 479
  return FALSE;
}

static gchar *
insert_spacers (const gchar *string)
{
  gchar *normalized, *ptr;
  gunichar unichr;
  GString *str;

  str = g_string_new (NULL);
Manish Singh's avatar
Manish Singh committed
480

481 482 483 484
  normalized = g_utf8_normalize (string, -1, G_NORMALIZE_DEFAULT_COMPOSE);
  ptr = normalized;

  while ((unichr = g_utf8_get_char (ptr)))
Manish Singh's avatar
Manish Singh committed
485
    {
486 487 488 489
      g_string_append_unichar (str, unichr);
      g_string_append_unichar (str, 0x200b);  /* ZERO WIDTH SPACE */
      ptr = g_utf8_next_char (ptr);
    }
490

491
  g_free (normalized);
492

493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512
  return g_string_free (str, FALSE);
}

static void
mix_gradient (PangoColor *gradient, guint ncolors,
              PangoColor *target, gdouble pos)
{
  gint index;

  g_return_if_fail (gradient != NULL);
  g_return_if_fail (ncolors > 1);
  g_return_if_fail (target != NULL);
  g_return_if_fail (pos >= 0.0  &&  pos <= 1.0);

  if (pos == 1.0)
    {
      target->red   = gradient[ncolors-1].red;
      target->green = gradient[ncolors-1].green;
      target->blue  = gradient[ncolors-1].blue;
      return;
Manish Singh's avatar
Manish Singh committed
513
    }
Michael Natterer's avatar
Michael Natterer committed
514

515 516 517 518 519 520
  index = (int) floor (pos * (ncolors-1));
  pos = pos * (ncolors - 1) - index;

  target->red   = gradient[index].red   * (1.0 - pos) + gradient[index+1].red   * pos;
  target->green = gradient[index].green * (1.0 - pos) + gradient[index+1].green * pos;
  target->blue  = gradient[index].blue  * (1.0 - pos) + gradient[index+1].blue  * pos;
521

Manish Singh's avatar
Manish Singh committed
522 523
}

524
static void
525 526 527
mix_colors (PangoColor *start, PangoColor *end,
            PangoColor *target,
            gdouble pos)
528
{
529 530 531 532 533 534 535 536 537
  g_return_if_fail (start != NULL);
  g_return_if_fail (end != NULL);
  g_return_if_fail (target != NULL);
  g_return_if_fail (pos >= 0.0  &&  pos <= 1.0);

  target->red   = start->red   * (1.0 - pos) + end->red   * pos;
  target->green = start->green * (1.0 - pos) + end->green * pos;
  target->blue  = start->blue  * (1.0 - pos) + end->blue  * pos;
}
538

539 540 541 542 543 544
static void
reshuffle_array (void)
{
  GRand *gr = g_rand_new ();
  gint i;

Michael Natterer's avatar
Michael Natterer committed
545
  for (i = 0; i < nscroll_texts; i++)
546 547 548 549
    {
      shuffle_array[i] = i;
    }

Michael Natterer's avatar
Michael Natterer committed
550
  for (i = 0; i < nscroll_texts; i++)
551 552 553 554
    {
      gint j;

      j = g_rand_int_range (gr, 0, nscroll_texts);
Michael Natterer's avatar
Michael Natterer committed
555
      if (i != j)
556 557 558 559 560 561 562 563 564 565 566 567
        {
          gint t;

          t = shuffle_array[j];
          shuffle_array[j] = shuffle_array[i];
          shuffle_array[i] = t;
        }
    }

  g_rand_free (gr);
}

568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583
static void
decorate_text (PangoLayout *layout, gint anim_type, gdouble time)
{
  gint letter_count = 0;
  gint text_length = 0;
  gint text_bytelen = 0;
  gint cluster_start, cluster_end;
  const gchar *text;
  const gchar *ptr;
  gunichar unichr;
  PangoAttrList *attrlist = NULL;
  PangoAttribute *attr;
  PangoRectangle irect = {0, 0, 0, 0};
  PangoRectangle lrect = {0, 0, 0, 0};
  PangoColor mix;

Tor Lillqvist's avatar
Tor Lillqvist committed
584 585
  mix_colors ((pp ? &backgr0und : &background),
              (pp ? &foregr0und : &foreground),
586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630
              &mix, time);

  text = pango_layout_get_text (layout);
  text_length = g_utf8_strlen (text, -1);
  text_bytelen = strlen (text);

  attrlist = pango_attr_list_new ();

  about_info.textrange[0] = 0;
  about_info.textrange[1] = text_bytelen;

  switch (anim_type)
  {
    case 0: /* Fade in */
      attr = pango_attr_foreground_new (mix.red, mix.green, mix.blue);
      attr->start_index = 0;
      attr->end_index = text_bytelen;
      pango_attr_list_insert (attrlist, attr);
      break;

    case 1: /* Fade in, spread */
      attr = pango_attr_foreground_new (mix.red, mix.green, mix.blue);
      attr->start_index = 0;
      attr->end_index = text_bytelen;
      pango_attr_list_change (attrlist, attr);

      ptr = text;

      cluster_start = 0;
      while ((unichr = g_utf8_get_char (ptr)))
        {
          ptr = g_utf8_next_char (ptr);
          cluster_end = (ptr - text);

          if (unichr == 0x200b)
            {
              lrect.width = (1.0 - time) * 15.0 * PANGO_SCALE + 0.5;
              attr = pango_attr_shape_new (&irect, &lrect);
              attr->start_index = cluster_start;
              attr->end_index = cluster_end;
              pango_attr_list_change (attrlist, attr);
            }
          cluster_start = cluster_end;
        }
      break;
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
    case 2: /* Fade in, sinewave */
      attr = pango_attr_foreground_new (mix.red, mix.green, mix.blue);
      attr->start_index = 0;
      attr->end_index = text_bytelen;
      pango_attr_list_change (attrlist, attr);

      ptr = text;

      cluster_start = 0;
      while ((unichr = g_utf8_get_char (ptr)))
        {
          if (unichr == 0x200b)
            {
              cluster_end = ptr - text;
              attr = pango_attr_rise_new ((1.0 -time) * 18000 *
                                          sin (4.0 * time +
                                               (float) letter_count * 0.7));
              attr->start_index = cluster_start;
              attr->end_index = cluster_end;
              pango_attr_list_change (attrlist, attr);

              letter_count++;
              cluster_start = cluster_end;
            }

          ptr = g_utf8_next_char (ptr);
        }
      break;
660

661 662
    case 3: /* letterwise Fade in */
      ptr = text;
663

664 665 666 667 668 669
      letter_count = 0;
      cluster_start = 0;
      while ((unichr = g_utf8_get_char (ptr)))
        {
          gint border;
          gdouble pos;
670

671
          border = (text_length + 15) * time - 15;
672

673 674 675 676 677 678
          if (letter_count < border)
            pos = 0;
          else if (letter_count > border + 15)
            pos = 1;
          else
            pos = ((gdouble) (letter_count - border)) / 15;
679

Tor Lillqvist's avatar
Tor Lillqvist committed
680 681
          mix_colors ((pp ? &foregr0und : &foreground),
                      (pp ? &backgr0und : &background),
682
                      &mix, pos);
683

684
          ptr = g_utf8_next_char (ptr);
685

686
          cluster_end = ptr - text;
687

688 689 690 691
          attr = pango_attr_foreground_new (mix.red, mix.green, mix.blue);
          attr->start_index = cluster_start;
          attr->end_index = cluster_end;
          pango_attr_list_change (attrlist, attr);
692

693 694
          if (pos < 1.0)
            about_info.textrange[1] = cluster_end;
695

696 697 698
          letter_count++;
          cluster_start = cluster_end;
        }
699

700
      break;
701

702 703
    case 4: /* letterwise Fade in, triangular */
      ptr = text;
704

705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720
      letter_count = 0;
      cluster_start = 0;
      while ((unichr = g_utf8_get_char (ptr)))
        {
          gint border;
          gdouble pos;

          border = (text_length + 15) * time - 15;

          if (letter_count < border)
            pos = 1.0;
          else if (letter_count > border + 15)
            pos = 0.0;
          else
            pos = 1.0 - ((gdouble) (letter_count - border)) / 15;

721 722 723
          mix_gradient (pp ? grad1ent : gradient,
                        pp ? G_N_ELEMENTS (grad1ent) : G_N_ELEMENTS (gradient),
                        &mix, pos);
724 725 726 727 728 729 730 731 732 733 734 735

          ptr = g_utf8_next_char (ptr);

          cluster_end = ptr - text;

          attr = pango_attr_foreground_new (mix.red, mix.green, mix.blue);
          attr->start_index = cluster_start;
          attr->end_index = cluster_end;
          pango_attr_list_change (attrlist, attr);

          if (pos > 0.0)
            about_info.textrange[1] = cluster_end;
736

737 738 739 740 741 742 743 744 745
          letter_count++;
          cluster_start = cluster_end;
        }
      break;

    default:
      g_printerr ("Unknown animation type %d\n", anim_type);
  }

Michael Natterer's avatar
Michael Natterer committed
746

747 748
  pango_layout_set_attributes (layout, attrlist);
  pango_attr_list_unref (attrlist);
749

750 751
}

752
static gboolean
Elliot Lee's avatar
Elliot Lee committed
753 754
about_dialog_timer (gpointer data)
{
755 756 757 758
  gboolean return_val;
  gint width, height;
  gdouble size;
  gchar *text;
Elliot Lee's avatar
Elliot Lee committed
759 760
  return_val = TRUE;

761
  if (about_info.animstep == 0)
Elliot Lee's avatar
Elliot Lee committed
762
    {
763
      size = 11.0;
764
      text = NULL;
765 766
      about_info.visible = TRUE;

767 768
      if (about_info.state == 0)
        {
769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810
          if (about_info.index > (about_info.pixmaparea.height /
                                  (pp ? 8 : 16)) + 16)
            {
              about_info.index = 0;
              about_info.state ++;
            }
          else
            {
              height = about_info.index * 16;

              if (height < about_info.pixmaparea.height)
                gdk_draw_line (about_info.shape_bitmap,
                               about_info.opaque_gc,
                               0, height,
                               about_info.pixmaparea.width, height);

              height -= 15;
              while (height > 0)
                {
                  if (height < about_info.pixmaparea.height)
                    gdk_draw_line (about_info.shape_bitmap,
                                   about_info.opaque_gc,
                                   0, height,
                                   about_info.pixmaparea.width, height);
                  height -= 15;
                }

              gtk_widget_shape_combine_mask (about_info.about_dialog,
                                             about_info.shape_bitmap,
                                             0, 0);
              about_info.index++;
              about_info.visible = FALSE;
              gtk_widget_queue_draw_area (about_info.logo_area,
                                          0, 0,
                                          about_info.pixmaparea.width,
                                          about_info.pixmaparea.height);
              return TRUE;
            }
        }

      if (about_info.state == 1)
        {
811 812 813
          if (about_info.index >= G_N_ELEMENTS (founders))
            {
              about_info.index = 0;
Michael Natterer's avatar
Michael Natterer committed
814

815 816 817 818
              /* skip the translators section when the translator
               * did not provide a translation with his name
               */
              if (gettext (translators[1]) == translators[1])
819
                about_info.state = 4;
820
              else
821
                about_info.state = 2;
822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838
            }
          else
            {
              if (about_info.index == 0)
                {
                  gchar *tmp;
                  tmp = g_strdup_printf (gettext (founders[0]), GIMP_VERSION);
                  text = insert_spacers (tmp);
                  g_free (tmp);
                }
              else
                {
                  text = insert_spacers (gettext (founders[about_info.index]));
                }
              about_info.index++;
            }
        }
839

840
      if (about_info.state == 2)
841
        {
842
          if (about_info.index >= G_N_ELEMENTS (translators) - 1)
843 844 845 846 847 848 849 850 851 852
            {
              about_info.index = 0;
              about_info.state++;
            }
          else
            {
              text = insert_spacers (gettext (translators[about_info.index]));
              about_info.index++;
            }
        }
853

854
      if (about_info.state == 3)
855 856 857 858 859 860 861 862 863 864 865 866 867 868 869
        {
          if (!translator_names)
            translator_names = g_strsplit (gettext (translators[1]), "\n", 0);

          if (translator_names[about_info.index] == NULL)
            {
              about_info.index = 0;
              about_info.state++;
            }
          else
            {
              text = insert_spacers (translator_names[about_info.index]);
              about_info.index++;
            }
        }
Michael Natterer's avatar
Michael Natterer committed
870

871
      if (about_info.state == 4)
872 873 874 875 876 877 878 879 880 881 882 883 884 885
        {
          if (about_info.index >= G_N_ELEMENTS (contri_intro))
            {
              about_info.index = 0;
              about_info.state++;
            }
          else
            {
              text = insert_spacers (gettext (contri_intro[about_info.index]));
              about_info.index++;
            }

        }

886
      if (about_info.state == 5)
887
        {
Michael Natterer's avatar
Michael Natterer committed
888

889 890 891
          about_info.index += 1;
          if (about_info.index == nscroll_texts)
            about_info.index = 0;
Michael Natterer's avatar
Michael Natterer committed
892

893 894
          text = insert_spacers (scroll_text[shuffle_array[about_info.index]]);
        }
895

896 897 898 899 900 901 902
      if (text == NULL)
        {
          g_printerr ("TEXT == NULL\n");
          return TRUE;
        }
      pango_layout_set_text (about_info.layout, text, -1);
      pango_layout_set_attributes (about_info.layout, NULL);
Elliot Lee's avatar
Elliot Lee committed
903

904 905
      pango_font_description_set_size (font_desc, size * PANGO_SCALE);
      pango_layout_set_font_description (about_info.layout, font_desc);
Elliot Lee's avatar
Elliot Lee committed
906

907
      pango_layout_get_pixel_size (about_info.layout, &width, &height);
Elliot Lee's avatar
Elliot Lee committed
908

909 910 911 912 913
      while (width >= about_info.textarea.width && size >= 6.0)
        {
          size -= 0.5;
          pango_font_description_set_size (font_desc, size * PANGO_SCALE);
          pango_layout_set_font_description (about_info.layout, font_desc);
914

915 916 917
          pango_layout_get_pixel_size (about_info.layout, &width, &height);
        }
    }
Elliot Lee's avatar
Elliot Lee committed
918

919
  about_info.animstep++;
Elliot Lee's avatar
Elliot Lee committed
920

921
  if (about_info.animstep < 16)
922
    {
923 924
      decorate_text (about_info.layout, 4,
                     ((float) about_info.animstep) / 15.0);
925
    }
926
  else if (about_info.animstep == 16)
927 928 929
    {
      about_info.timer = g_timeout_add (800, about_dialog_timer, NULL);
      return_val = FALSE;
Elliot Lee's avatar
Elliot Lee committed
930
    }
931
  else if (about_info.animstep == 17)
932 933 934 935
    {
      about_info.timer = g_timeout_add (30, about_dialog_timer, NULL);
      return_val = FALSE;
    }
936
  else if (about_info.animstep < 33)
937
    {
938 939
      decorate_text (about_info.layout, 1,
                     1.0 - ((float) (about_info.animstep-17)) / 15.0);
940
    }
941
  else if (about_info.animstep == 33)
942 943 944 945 946 947 948
    {
      about_info.timer = g_timeout_add (300, about_dialog_timer, NULL);
      return_val = FALSE;
      about_info.visible = FALSE;
    }
  else
    {
949
      about_info.animstep = 0;
950 951 952 953 954 955 956 957 958 959
      about_info.timer = g_timeout_add (30, about_dialog_timer, NULL);
      return_val = FALSE;
      about_info.visible = FALSE;
    }

  gtk_widget_queue_draw_area (about_info.logo_area,
                              about_info.textarea.x,
                              about_info.textarea.y,
                              about_info.textarea.width,
                              about_info.textarea.height);
Elliot Lee's avatar
Elliot Lee committed
960 961 962

  return return_val;
}
963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988


/* some handy shortcuts */

#define random() gdk_pixbuf_loader_new_with_type ("\160\x6e\147", NULL)
#define pink(a) gdk_pixbuf_loader_close ((a), NULL)
#define line gdk_pixbuf_loader_write
#define white gdk_pixbuf_loader_get_pixbuf
#define level(a) gdk_pixbuf_get_width ((a))
#define variance(a) gdk_pixbuf_get_height ((a))
#define GPL GdkPixbufLoader

static gboolean
about_dialog_load_logo (GtkWidget *window)
{
  gchar       *filename;
  GdkPixbuf   *pixbuf;
  GdkGC       *gc;
  PangoLayout *layout;
  PangoFontDescription *desc;
  GPL         *noise;

  if (about_info.logo_pixmap)
    return TRUE;

  filename = g_build_filename (gimp_data_directory (), "images",
989
                               "gimp-logo.png", NULL);
990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013

  pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
  g_free (filename);

  if (! pixbuf)
    return FALSE;

  about_info.pixmaparea.x = 0;
  about_info.pixmaparea.y = 0;
  about_info.pixmaparea.width = gdk_pixbuf_get_width (pixbuf);
  about_info.pixmaparea.height = gdk_pixbuf_get_height (pixbuf);

  gtk_widget_realize (window);

  about_info.logo_pixmap = gdk_pixmap_new (window->window,
                                about_info.pixmaparea.width,
                                about_info.pixmaparea.height * 2,
                                gtk_widget_get_visual (window)->depth);

  layout = gtk_widget_create_pango_layout (window, NULL);
  desc = pango_font_description_from_string ("Sans, Italic 9");
  pango_layout_set_font_description (layout, desc);
  pango_layout_set_justify (layout, PANGO_ALIGN_CENTER);
  pango_layout_set_text (layout, GIMP_VERSION, -1);
Michael Natterer's avatar
Michael Natterer committed
1014

1015 1016 1017 1018 1019 1020 1021 1022
  gc = gdk_gc_new (about_info.logo_pixmap);

  /* draw a defined content to the Pixmap */
  gdk_draw_rectangle (GDK_DRAWABLE (about_info.logo_pixmap),
                      gc, TRUE,
                      0, 0,
                      about_info.pixmaparea.width,
                      about_info.pixmaparea.height * 2);
Michael Natterer's avatar
Michael Natterer committed
1023

1024 1025 1026 1027 1028 1029 1030 1031
  gdk_draw_pixbuf (GDK_DRAWABLE (about_info.logo_pixmap),
                   gc, pixbuf,
                   0, 0, 0, 0,
                   about_info.pixmaparea.width,
                   about_info.pixmaparea.height,
                   GDK_RGB_DITHER_NORMAL, 0, 0);

  gdk_draw_layout (GDK_DRAWABLE (about_info.logo_pixmap),
1032
                   gc, 8, 39, layout);
1033 1034 1035 1036

  g_object_unref (pixbuf);
  g_object_unref (layout);

Sven Neumann's avatar
Sven Neumann committed
1037
  if ((noise = random ()) && line (noise, (const guchar *)
Simon Budig's avatar
Simon Budig committed
1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123