projects
/
xscreensaver
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
From http://www.jwz.org/xscreensaver/xscreensaver-5.38.tar.gz
[xscreensaver]
/
hacks
/
forest.c
diff --git
a/hacks/forest.c
b/hacks/forest.c
index 5882bb3448c51be74294c5e2b80429c73a465325..38a480d9351fcbf76b7ea34baeff94bcedafa90b 100644
(file)
--- a/
hacks/forest.c
+++ b/
hacks/forest.c
@@
-14,7
+14,9
@@
* implied warranty.
*/
* implied warranty.
*/
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
/* ****************************** NOTE ******************************
/* ****************************** NOTE ******************************
@@
-25,21
+27,20
@@
*/
#ifdef STANDALONE
*/
#ifdef STANDALONE
-# define PROGCLASS "Forest" /*"XTree"*/
-# define HACK_INIT init_trees
-# define HACK_DRAW draw_trees
-# define trees_opts xlockmore_opts
# define DEFAULTS "*delay: 500000 \n" \
# define DEFAULTS "*delay: 500000 \n" \
- "*ncolors: 20 \n" \
- "*eraseSpeed: 400 \n" \
- "*eraseMode: -1 \n" \
- "*installColormap False"
+ "*ncolors: 20 \n" \
+ "*fpsSolid: true \n" \
+
# include "xlockmore.h" /* from the xscreensaver distribution */
# include "xlockmore.h" /* from the xscreensaver distribution */
+# define free_trees 0
+# define release_trees 0
+# define reshape_trees 0
+# define trees_handle_event 0
#else /* !STANDALONE */
# include "xlock.h" /* from the xlockmore distribution */
#endif /* !STANDALONE */
#else /* !STANDALONE */
# include "xlock.h" /* from the xlockmore distribution */
#endif /* !STANDALONE */
-ModeSpecOpt trees_opts = {0, NULL, 0, NULL, NULL};
+
ENTRYPOINT
ModeSpecOpt trees_opts = {0, NULL, 0, NULL, NULL};
typedef struct {
int x;
typedef struct {
int x;
@@
-48,13
+49,14
@@
typedef struct {
double size;
long color;
int toDo;
double size;
long color;
int toDo;
+ int pause;
int season;
} treestruct;
static treestruct *trees = NULL;
int season;
} treestruct;
static treestruct *trees = NULL;
-XColor colors[20];
-int color;
+
static
XColor colors[20];
+
static
int color;
static long colorM[12] = {0xff0000, 0xff8000, 0xffff00, 0x80ff00,
0x00ff00, 0x00ff80, 0x00ffff, 0x0080ff,
static long colorM[12] = {0xff0000, 0xff8000, 0xffff00, 0x80ff00,
0x00ff00, 0x00ff80, 0x00ffff, 0x0080ff,
@@
-64,18
+66,15
@@
static long colorV[12] = {0x0a0000, 0x0a0500, 0x0a0a00, 0x050a00,
0x000a00, 0x000a05, 0x000a0a, 0x00050a,
0x00000a, 0x05000a, 0x0a000a, 0x0a0005};
0x000a00, 0x000a05, 0x000a0a, 0x00050a,
0x00000a, 0x05000a, 0x0a000a, 0x0a0005};
-void init_trees(ModeInfo * mi) {
- unsigned long pixels[20];
+ENTRYPOINT void
+init_trees(ModeInfo * mi)
+{
treestruct *tree;
Display *display = MI_DISPLAY(mi);
GC gc = MI_GC(mi);
int i;
if (trees == NULL) {
treestruct *tree;
Display *display = MI_DISPLAY(mi);
GC gc = MI_GC(mi);
int i;
if (trees == NULL) {
- trees = (treestruct *) calloc(MI_NUM_SCREENS(mi), sizeof (treestruct));
- if (trees == NULL) {
- return;
- }
if (mi->npixels > 20) {
printf("%d colors selected. Setting limit to 20...\n", mi->npixels);
if (mi->npixels > 20) {
printf("%d colors selected. Setting limit to 20...\n", mi->npixels);
@@
-114,6
+113,8
@@
void init_trees(ModeInfo * mi) {
XSetForeground(display, gc, colors[1].pixel);
}
XSetForeground(display, gc, colors[1].pixel);
}
+ MI_INIT (mi, trees);
+
XClearWindow(display, MI_WINDOW(mi));
XSetLineAttributes(display, gc, 2, LineSolid, CapButt, JoinMiter);
tree = &trees[MI_SCREEN(mi)];
XClearWindow(display, MI_WINDOW(mi));
XSetLineAttributes(display, gc, 2, LineSolid, CapButt, JoinMiter);
tree = &trees[MI_SCREEN(mi)];
@@
-129,24
+130,21
@@
void init_trees(ModeInfo * mi) {
colors[i].flags = DoRed | DoGreen | DoBlue;
}
colors[i].flags = DoRed | DoGreen | DoBlue;
}
- for (i = 0; i < color; i++)
- pixels[i] = colors[i].pixel;
-
- XFreeColors(display, mi->xgwa.colormap, pixels, mi->npixels, 0L);
-
- for (i = 0; i < mi->npixels; i++)
+ for (i = 0; i < mi->npixels; i++)
if (!XAllocColor(display, mi->xgwa.colormap, &colors[i])) break;
color = i;
}
if (!XAllocColor(display, mi->xgwa.colormap, &colors[i])) break;
color = i;
}
-double rRand(double a, double b) {
+static double rRand(double a, double b)
+{
return (a+(b-a)*NRAND(10001)/10000.0);
}
return (a+(b-a)*NRAND(10001)/10000.0);
}
-void draw_line(ModeInfo * mi,
- int x1, int y1, int x2, int y2,
- double angle, int widths, int widthe) {
+static void draw_line(ModeInfo * mi,
+ int x1, int y1, int x2, int y2,
+ double angle, int widths, int widthe)
+{
Display *display = MI_DISPLAY(mi);
GC gc = MI_GC(mi);
Display *display = MI_DISPLAY(mi);
GC gc = MI_GC(mi);
@@
-174,7
+172,8
@@
void draw_line(ModeInfo * mi,
}
}
}
}
-void draw_tree_rec(ModeInfo * mi, double thick, int x, int y, double angle) {
+static void draw_tree_rec(ModeInfo * mi, double thick, int x, int y, double angle)
+{
treestruct *tree = &trees[MI_SCREEN(mi)];
Display *display = MI_DISPLAY(mi);
GC gc = MI_GC(mi);
treestruct *tree = &trees[MI_SCREEN(mi)];
Display *display = MI_DISPLAY(mi);
GC gc = MI_GC(mi);
@@
-210,14
+209,22
@@
void draw_tree_rec(ModeInfo * mi, double thick, int x, int y, double angle) {
}
}
}
}
-void draw_trees(ModeInfo * mi) {
+ENTRYPOINT void
+draw_trees(ModeInfo * mi)
+{
treestruct *tree = &trees[MI_SCREEN(mi)];
int width = MI_WIN_WIDTH(mi);
int height = MI_WIN_HEIGHT(mi);
treestruct *tree = &trees[MI_SCREEN(mi)];
int width = MI_WIN_WIDTH(mi);
int height = MI_WIN_HEIGHT(mi);
- if (
--(tree->toDo) == 0
) {
-
usleep(3000000)
;
+ if (
tree->pause == 1
) {
+
tree->pause--
;
init_trees(mi);
init_trees(mi);
+ } else if (tree->pause > 1) {
+ tree->pause--;
+ return;
+ } else if (--(tree->toDo) == 0) {
+ tree->pause = 6;
+ return;
}
tree->x = NRAND(width);
}
tree->x = NRAND(width);
@@
-233,9
+240,5
@@
void draw_trees(ModeInfo * mi) {
draw_tree_rec(mi, tree->thick, tree->x, tree->y, rRand(-0.1, 0.1));
}
draw_tree_rec(mi, tree->thick, tree->x, tree->y, rRand(-0.1, 0.1));
}
-void release_trees(ModeInfo * mi) {
- if (trees != NULL) {
- (void) free((void *) trees);
- trees = NULL;
- }
-}
+
+XSCREENSAVER_MODULE_2 ("Forest", forest, trees)