~ubuntu-branches/ubuntu/dapper/xscreensaver/dapper-updates

« back to all changes in this revision

Viewing changes to hacks/bubbles.c

  • Committer: Bazaar Package Importer
  • Author(s): Ralf Hildebrandt
  • Date: 2005-04-09 00:06:43 UTC
  • mfrom: (1.1.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20050409000643-z0abtifbt9s20pcc
Tags: 4.21-3
Patch by Joachim Breitner to check more frequently if DPMS kicked in (closes: #303374, #286664).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* bubbles.c - frying pan / soft drink in a glass simulation */
2
2
 
3
 
/*$Id: bubbles.c,v 1.17 2000/07/19 06:38:42 jwz Exp $*/
 
3
/*$Id: bubbles.c,v 1.18 2002/01/17 02:16:04 jwz Exp $*/
4
4
 
5
5
/*
6
6
 *  Copyright (C) 1995-1996 James Macnicol
41
41
 
42
42
#include <math.h>
43
43
#include "screenhack.h"
44
 
#include "bubbles.h"
45
44
 
46
45
#include <limits.h>
47
46
 
60
59
# include <unistd.h>
61
60
#endif
62
61
#include "yarandom.h"
 
62
#include "bubbles.h"
 
63
#include "xpm-pixmap.h"
63
64
 
64
 
#ifdef HAVE_XPM
65
 
# include <X11/xpm.h>
 
65
#if defined(HAVE_GDK_PIXBUF) || defined(HAVE_XPM)
 
66
# define FANCY_BUBBLES
66
67
#endif
67
68
 
68
69
/* 
92
93
 
93
94
XrmOptionDescRec options [] = {
94
95
  { "-simple",          ".simple",      XrmoptionNoArg, "true" },
95
 
#ifdef HAVE_XPM
 
96
#ifdef FANCY_BUBBLES
96
97
  { "-broken",          ".broken",      XrmoptionNoArg, "true" },
97
 
#endif /* HAVE_XPM */
 
98
#endif
98
99
  { "-quiet",           ".quiet",       XrmoptionNoArg, "true" },
99
100
  { "-nodelay",         ".nodelay",     XrmoptionNoArg, "true" },
100
101
  { "-3D",          ".3D",      XrmoptionNoArg, "true" },
137
138
static int *bubble_droppages;
138
139
static GC draw_gc, erase_gc;
139
140
 
140
 
#ifdef HAVE_XPM
 
141
#ifdef FANCY_BUBBLES
141
142
static int num_bubble_pixmaps;
142
143
static Bubble_Step **step_pixmaps;
143
 
#endif /* HAVE_XPM */
 
144
#endif
144
145
 
145
146
/* Options stuff */
146
 
#ifdef HAVE_XPM
 
147
#ifdef FANCY_BUBBLES
147
148
static Bool simple = False;
148
149
#else
149
150
static Bool simple = True;
225
226
              bb->radius, bb->x, bb->y, bb->magic, bb->cell_index);
226
227
      die_bad_bubble(bb);  
227
228
    }
228
 
#ifdef HAVE_XPM
 
229
#ifdef FANCY_BUBBLES
229
230
  } else {
230
231
    if ((bb->x < 0) || (bb->x > screen_width) ||
231
232
        (bb->y < 0) || (bb->y > screen_height) ||
236
237
              bb->radius, bb->x, bb->y, bb->magic, bb->cell_index);
237
238
      die_bad_bubble(bb);  
238
239
    }
239
 
#endif /* HAVE_XPM */
 
240
#endif
240
241
  }
241
242
#endif /* DEBUG */
242
243
  return 0;
438
439
  long factor;
439
440
  int i;
440
441
 
441
 
#ifdef HAVE_XPM
 
442
#ifdef FANCY_BUBBLES
442
443
  if (simple)
443
444
    maxarea = bubble_areas[bubble_max_radius+1];
444
445
  else
445
446
    maxarea = step_pixmaps[num_bubble_pixmaps]->area;
446
 
#else
 
447
#else /* !FANCY_BUBBLES */
447
448
  maxarea = bubble_areas[bubble_max_radius+1];
448
 
#endif /* HAVE_XPM */
 
449
#endif /* !FANCY_BUBBLES */
449
450
  maxvalue = (double)screen_width * 2.0 * (double)maxarea;
450
451
  factor = (long)ceil(maxvalue / (double)LONG_MAX);
451
452
  if (factor > 1) {
452
453
    /* Overflow will occur in weighted_mean().  We must divide areas
453
454
       each by factor so it will never do so. */
454
 
#ifdef HAVE_XPM
 
455
#ifdef FANCY_BUBBLES
455
456
    if (simple) {
456
457
      for (i = bubble_min_radius; i <= bubble_max_radius+1; i++) {
457
458
        bubble_areas[i] /= factor;
471
472
#endif /* DEBUG */
472
473
      }
473
474
    }
474
 
#else
 
475
#else /* !FANCY_BUBBLES */
475
476
    for (i = bubble_min_radius; i <= bubble_max_radius+1; i++) {
476
477
      bubble_areas[i] /= factor;
477
478
      if (bubble_areas[i] == 0)
478
479
        bubble_areas[i] = 1;
479
480
    }
480
 
#endif /* HAVE_XPM */
 
481
#endif /* !FANCY_BUBBLES */
481
482
  }
482
483
#ifdef DEBUG
483
484
  printf("maxarea = %ld\n", maxarea);
507
508
  if (simple) {
508
509
    rv->radius = bubble_min_radius;
509
510
    rv->area = bubble_areas[bubble_min_radius];
510
 
#ifdef HAVE_XPM
 
511
#ifdef FANCY_BUBBLES
511
512
  } else {
512
513
    rv->step = 0;
513
514
    rv->radius = step_pixmaps[0]->radius;
514
515
    rv->area = step_pixmaps[0]->area;
515
 
#endif /* HAVE_XPM */
 
516
#endif /* FANCY_BUBBLES */
516
517
  }
517
518
  rv->visible = 0;
518
519
  rv->magic = BUBBLE_MAGIC;
540
541
               (bb->y - bb->radius), bb->radius*2, bb->radius*2, 0,
541
542
               360*64);  
542
543
    } else {
543
 
#ifdef HAVE_XPM
 
544
#ifdef FANCY_BUBBLES
544
545
      XSetClipOrigin(defdsp, step_pixmaps[bb->step]->draw_gc, 
545
546
                     (bb->x - bb->radius),
546
547
                     (bb->y - bb->radius));
551
552
                (bb->radius * 2),  
552
553
                (bb->x - bb->radius),
553
554
                (bb->y - bb->radius));
554
 
#endif /* HAVE_XPM */
 
555
#endif /* FANCY_BUBBLES */
555
556
    }
556
557
  }
557
558
}
573
574
               (bb->y - bb->radius), bb->radius*2, bb->radius*2, 0,
574
575
               360*64);
575
576
    } else {
576
 
#ifdef HAVE_XPM
 
577
#ifdef FANCY_BUBBLES
577
578
      if (! broken) {
578
579
        XSetClipOrigin(defdsp, step_pixmaps[bb->step]->erase_gc, 
579
580
                       (bb->x - bb->radius), (bb->y - bb->radius));
584
585
                       (bb->radius * 2),
585
586
                       (bb->radius * 2));
586
587
      }
587
 
#endif /* HAVE_XPM */
 
588
#endif /* FANCY_BUBBLES */
588
589
    }
589
590
  }
590
591
}
761
762
        if ((simple) && (diner->area > bubble_areas[bubble_max_radius])) {
762
763
          diner->area = bubble_areas[bubble_max_radius];
763
764
        }
764
 
#ifdef HAVE_XPM
 
765
#ifdef FANCY_BUBBLES
765
766
        if ((! simple) && (diner->area > step_pixmaps[num_bubble_pixmaps]->area)) {
766
767
          diner->area = step_pixmaps[num_bubble_pixmaps]->area;
767
768
        }
768
 
#endif /* HAVE_XPM */
 
769
#endif /* FANCY_BUBBLES */
769
770
  }
770
771
  else {
771
772
        if ((simple) && (diner->area > bubble_areas[bubble_max_radius])) {
772
773
          delete_bubble_in_mesh(diner, DELETE_BUBBLE);
773
774
          return 0;
774
775
        }
775
 
#ifdef HAVE_XPM
 
776
#ifdef FANCY_BUBBLES
776
777
        if ((! simple) && (diner->area > 
777
778
                                           step_pixmaps[num_bubble_pixmaps]->area)) {
778
779
          delete_bubble_in_mesh(diner, DELETE_BUBBLE);
779
780
          return 0;
780
781
        }
781
 
#endif /* HAVE_XPM */
 
782
#endif /* FANCY_BUBBLES */
782
783
  }
783
784
 
784
785
  if (simple) {
790
791
      diner->radius = i;
791
792
    }
792
793
    show_bubble(diner);
793
 
#ifdef HAVE_XPM
 
794
#ifdef FANCY_BUBBLES
794
795
  } else {
795
796
    if (diner->area > step_pixmaps[diner->step+1]->area) {
796
797
      i = diner->step;
800
801
      diner->radius = step_pixmaps[diner->step]->radius;
801
802
    }
802
803
    show_bubble(diner);
803
 
#endif /* HAVE_XPM */
 
804
#endif /* FANCY_BUBBLES */
804
805
  }
805
806
 
806
807
  /* Now adjust locations and cells if need be */
958
959
                  if ((nextbub->area >= bubble_areas[bubble_max_radius - 1]) && (random() % 2 == 0))
959
960
                        continue;
960
961
                }
961
 
#ifdef HAVE_XPM
 
962
#ifdef FANCY_BUBBLES
962
963
                else {
963
964
                  if ((nextbub->step >= num_bubble_pixmaps - 1) && (random() % 2 == 0))
964
965
                        continue;
965
966
                }
966
 
#endif /* HAVE_XPM */
 
967
#endif /* FANCY_BUBBLES */
967
968
      }
968
969
          break;
969
970
        }
996
997
 
997
998
  if (simple)
998
999
        (bb->y) += (bubble_droppages[bb->radius] * drop_dir);
999
 
#ifdef HAVE_XPM
 
1000
#ifdef FANCY_BUBBLES
1000
1001
  else
1001
1002
        (bb->y) += (step_pixmaps[bb->step]->droppage * drop_dir);
1002
 
#endif /* HAVE_XPM */
 
1003
#endif /* FANCY_BUBBLES */
1003
1004
  if ((bb->y < 0) || (bb->y > screen_height)) {
1004
1005
        delete_bubble_in_mesh( bb, DELETE_BUBBLE );
1005
1006
        return -1;
1020
1021
          if ((bb->area >= bubble_areas[bubble_max_radius - 1]) && (random() % 2 == 0)) 
1021
1022
                leave_trail( bb );
1022
1023
        }
1023
 
#ifdef HAVE_XPM
 
1024
#ifdef FANCY_BUBBLES
1024
1025
        else { 
1025
1026
          if ((bb->step >= num_bubble_pixmaps - 1) && (random() % 2 == 0))
1026
1027
                leave_trail( bb );
1027
1028
        }
1028
 
#endif /* HAVE_XPM */
 
1029
#endif /* FANCY_BUBBLES */
1029
1030
  }
1030
1031
 
1031
1032
  return 0;
1053
1054
 * still check for XPM, though!
1054
1055
 */
1055
1056
 
1056
 
#ifdef HAVE_XPM
 
1057
#ifdef FANCY_BUBBLES
1057
1058
 
1058
1059
/*
1059
1060
 * Pixmaps without file I/O (but do have XPM)
1178
1179
 This is virtually copied verbatim from make_pixmap_from_file() above and
1179
1180
changes made to either should be propagated onwards! */
1180
1181
{
1181
 
  int result;
1182
1182
  XGCValues gcv;
1183
1183
 
1184
1184
#ifdef DEBUG
1193
1193
    exit(1);
1194
1194
  }
1195
1195
 
1196
 
  bl->xpmattrs.valuemask = 0;
1197
 
 
1198
 
#ifdef XpmCloseness
1199
 
  bl->xpmattrs.valuemask |= XpmCloseness;
1200
 
  bl->xpmattrs.closeness = 40000;
1201
 
#endif
1202
 
#ifdef XpmVisual
1203
 
  bl->xpmattrs.valuemask |= XpmVisual;
1204
 
  bl->xpmattrs.visual = defvisual;
1205
 
#endif
1206
 
#ifdef XpmDepth
1207
 
  bl->xpmattrs.valuemask |= XpmDepth;
1208
 
  bl->xpmattrs.depth = screen_depth;
1209
 
#endif
1210
 
#ifdef XpmColormap
1211
 
  bl->xpmattrs.valuemask |= XpmColormap;
1212
 
  bl->xpmattrs.colormap = defcmap;
1213
 
#endif
1214
 
 
1215
 
 
1216
 
  /* This is the only line which is different from make_pixmap_from_file() */
1217
 
  result = XpmCreatePixmapFromData(defdsp, defwin, pixmap_data, &bl->ball, 
1218
 
                                   &bl->shape_mask, &bl->xpmattrs);
1219
 
 
1220
 
  switch(result) {
1221
 
  case XpmColorError:
1222
 
    fprintf(stderr, "xpm: color substitution performed\n");
1223
 
    /* fall through */
1224
 
  case XpmSuccess:
1225
 
    bl->radius = MAX(bl->xpmattrs.width, bl->xpmattrs.height) / 2;
 
1196
#ifdef FANCY_BUBBLES
 
1197
  {
 
1198
    int w, h;
 
1199
    bl->ball = xpm_data_to_pixmap (defdsp, defwin, (char **) pixmap_data,
 
1200
                                   &w, &h, &bl->shape_mask);
 
1201
    bl->radius = MAX(w, h) / 2;
1226
1202
    bl->area = calc_bubble_area(bl->radius);
1227
 
    break;
1228
 
  case XpmColorFailed:
1229
 
    fprintf(stderr, "xpm: color allocation failed\n");
1230
 
    exit(1);
1231
 
  case XpmNoMemory:
1232
 
    fprintf(stderr, "xpm: out of memory\n");
1233
 
    exit(1);
1234
 
  default:
1235
 
    fprintf(stderr, "xpm: unknown error code %d\n", result);
1236
 
    exit(1);
1237
1203
  }
1238
 
  
 
1204
#endif /* FANCY_BUBBLES */
 
1205
 
1239
1206
  gcv.plane_mask = AllPlanes;
1240
1207
  gcv.foreground = default_fg_pixel;
1241
1208
  gcv.function = GXcopy;
1279
1246
  make_pixmap_array(pixmap_list);
1280
1247
}
1281
1248
 
1282
 
#endif /* HAVE_XPM */
 
1249
#endif /* FANCY_BUBBLES */
1283
1250
 
1284
1251
 
1285
1252
/* 
1337
1304
      if (! quiet)
1338
1305
        fprintf(stderr, "-broken not available in simple mode\n");
1339
1306
  } else {
1340
 
#ifndef HAVE_XPM
 
1307
#ifndef FANCY_BUBBLES
1341
1308
    simple = 1;
1342
 
#else
 
1309
#else  /* FANCY_BUBBLES */
1343
1310
    broken = get_boolean_resource("broken", "Boolean");
1344
 
#endif /* HAVE_XPM */
 
1311
#endif /* FANCY_BUBBLES */
1345
1312
  }
1346
1313
}
1347
1314
 
1401
1368
 
1402
1369
    mesh_length = (2 * bubble_max_radius) + 3;
1403
1370
  } else {
1404
 
#ifndef HAVE_XPM
 
1371
#ifndef FANCY_BUBBLES
1405
1372
    fprintf(stderr,
1406
 
            "Bug: simple mode code not set but HAVE_XPM not defined\n");
 
1373
            "Bug: simple mode code not set but FANCY_BUBBLES not defined\n");
1407
1374
    exit(1);
1408
 
#else
 
1375
#else  /* FANCY_BUBBLES */
1409
1376
    /* Make sure all #ifdef sort of things have been taken care of in
1410
1377
       get_resources(). */
1411
1378
    default_to_pixmaps();
1412
1379
 
1413
1380
    /* Set mesh length */
1414
1381
    mesh_length = (2 * step_pixmaps[num_bubble_pixmaps-1]->radius) + 3;
1415
 
#endif /* HAVE_XPM */
 
1382
#endif /* FANCY_BUBBLES */
1416
1383
 
1417
1384
    /* Am I missing something in here??? */
1418
1385
  }