static unsigned long rorschach_draw (Display *dpy, Window window, void *closure) { struct state *st = (struct state *) closure; unsigned long delay = 20000; if (st->eraser) { st->eraser = erase_window (dpy, window, st->eraser); goto END; } if (st->remaining_iterations > 0) { rorschach_draw_step (dpy, window, st); if (st->remaining_iterations == 0) delay = st->sleep_time * 1000000; } else { if (st->remaining_iterations == 0) st->eraser = erase_window (dpy, window, st->eraser); rorschach_draw_start (dpy, window, st); } END: return delay; }
/* * z_erase_window, erase a window or the screen to background colour. * * zargs[0] = window (-3 current, -2 screen, -1 screen & unsplit) * */ void z_erase_window (void) { flush_buffer (); if ((short) zargs[0] == -1 || (short) zargs[0] == -2) erase_screen (zargs[0]); else erase_window (winarg0 ()); }/* z_erase_window */
void split_window (zword height) { zword stat_height = 0; flush_buffer (); /* Calculate height of status line and upper window */ if (h_version != V6) height *= hi (wp[1].font_size); if (h_version <= V3) stat_height = hi (wp[7].font_size); /* Cursor of upper window mustn't be swallowed by the lower window */ wp[1].y_cursor += wp[1].y_pos - 1 - stat_height; wp[1].y_pos = 1 + stat_height; wp[1].y_size = height; if ((short) wp[1].y_cursor > (short) wp[1].y_size) reset_cursor (1); /* Cursor of lower window mustn't be swallowed by the upper window */ wp[0].y_cursor += wp[0].y_pos - 1 - stat_height - height; wp[0].y_pos = 1 + stat_height + height; wp[0].y_size = h_screen_height - stat_height - height; if ((short) wp[0].y_cursor < 1) reset_cursor (0); /* Erase the upper window in V3 only */ if (h_version == V3 && height != 0) erase_window (1); os_window_height (0, wp[0].y_size); os_window_height (1, wp[1].y_size); }/* split_window */
/* * Since the XFillPolygon doesn't require that the last * point == first point, the number of points is the same * as the number of lines. We just let XFillPolygon supply * the line from the last point to the first point. * */ static unsigned long pedal_draw (Display *dpy, Window window, void *closure) { struct state *st = (struct state *) closure; int numpoints; int erase_delay = 10000; int long_delay = 1000000 * st->delay; if (st->erase_p || st->eraser) { st->eraser = erase_window (dpy, window, st->eraser); st->erase_p = 0; return (st->eraser ? erase_delay : 1000000); } numpoints = compute_pedal(st, st->points, st->maxlines); /* Pick a new foreground color (added by jwz) */ if (! mono_p) { XColor color; hsv_to_rgb (random()%360, 1.0, 1.0, &color.red, &color.green, &color.blue); if (XAllocColor (st->dpy, st->cmap, &color)) { XSetForeground (st->dpy, st->gc, color.pixel); XFreeColors (st->dpy, st->cmap, &st->foreground.pixel, 1, 0); st->foreground.red = color.red; st->foreground.green = color.green; st->foreground.blue = color.blue; st->foreground.pixel = color.pixel; } } XFillPolygon (st->dpy, st->window, st->gc, st->points, numpoints, Complex, CoordModeOrigin); st->erase_p = 1; return long_delay; }
ENTRYPOINT void draw_braid(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); int num_points = 500; float t_inc; float theta, psi; float t, r_diff; int i, s; float x_1, y_1, x_2, y_2, r1, r2; float color, color_use = 0.0, color_inc; braidtype *braid; if (braids == NULL) return; braid = &braids[MI_SCREEN(mi)]; #ifdef STANDALONE if (braid->eraser) { braid->eraser = erase_window (MI_DISPLAY(mi), MI_WINDOW(mi), braid->eraser); return; } #endif MI_IS_DRAWN(mi) = True; XSetLineAttributes(display, MI_GC(mi), braid->linewidth, LineSolid, (braid->linewidth <= 3 ? CapButt : CapRound), JoinMiter); theta = (2.0 * M_PI) / (float) (braid->braidlength); t_inc = (2.0 * M_PI) / (float) num_points; color_inc = (float) MI_NPIXELS(mi) * braid->color_direction / (float) num_points; braid->startcolor += SPINRATE * color_inc; if (((int) braid->startcolor) >= MI_NPIXELS(mi)) braid->startcolor = 0.0; r_diff = (braid->max_radius - braid->min_radius) / (float) (braid->nstrands); color = braid->startcolor; psi = 0.0; for (i = 0; i < braid->braidlength; i++) { psi += theta; for (t = 0.0; t < theta; t += t_inc) { #ifdef COLORROUND color += color_inc; if (((int) color) >= MI_NPIXELS(mi)) color = 0.0; color_use = color; #endif for (s = 0; s < braid->nstrands; s++) { if (ABS(braid->braidword[i]) == s) continue; if (ABS(braid->braidword[i]) - 1 == s) { /* crosSINFg */ #ifdef COLORCOMP if (MI_NPIXELS(mi) > 2) { color_use = color + SPINRATE * braid->components[applywordbackto(braid, s, i)] + (psi + t) / 2.0 / M_PI * (float) MI_NPIXELS(mi); while (((int) color_use) >= MI_NPIXELS(mi)) color_use -= (float) MI_NPIXELS(mi); while (((int) color_use) < 0) color_use += (float) MI_NPIXELS(mi); } #endif #ifdef COLORROUND if (MI_NPIXELS(mi) > 2) { color_use += SPINRATE * color_inc; while (((int) color_use) >= MI_NPIXELS(mi)) color_use -= (float) MI_NPIXELS(mi); } #endif r1 = braid->min_radius + r_diff * (float) (s); r2 = braid->min_radius + r_diff * (float) (s + 1); if (braid->braidword[i] > 0 || (FABSF(t - theta / 2.0) > theta / 7.0)) { x_1 = ((0.5 * (1.0 + SINF(t / theta * M_PI - M_PI_2)) * r2 + 0.5 * (1.0 + SINF((theta - t) / theta * M_PI - M_PI_2)) * r1)) * COSF(t + psi) + braid->center_x; y_1 = ((0.5 * (1.0 + SINF(t / theta * M_PI - M_PI_2)) * r2 + 0.5 * (1.0 + SINF((theta - t) / theta * M_PI - M_PI_2)) * r1)) * SINF(t + psi) + braid->center_y; x_2 = ((0.5 * (1.0 + SINF((t + t_inc) / theta * M_PI - M_PI_2)) * r2 + 0.5 * (1.0 + SINF((theta - t - t_inc) / theta * M_PI - M_PI_2)) * r1)) * COSF(t + t_inc + psi) + braid->center_x; y_2 = ((0.5 * (1.0 + SINF((t + t_inc) / theta * M_PI - M_PI_2)) * r2 + 0.5 * (1.0 + SINF((theta - t - t_inc) / theta * M_PI - M_PI_2)) * r1)) * SINF(t + t_inc + psi) + braid->center_y; if (MI_NPIXELS(mi) > 2) XSetForeground(display, MI_GC(mi), MI_PIXEL(mi, (int) color_use)); else XSetForeground(display, MI_GC(mi), MI_WHITE_PIXEL(mi)); XDrawLine(display, window, MI_GC(mi), (int) (x_1), (int) (y_1), (int) (x_2), (int) (y_2)); } #ifdef COLORCOMP if (MI_NPIXELS(mi) > 2) { color_use = color + SPINRATE * braid->components[applywordbackto(braid, s + 1, i)] + (psi + t) / 2.0 / M_PI * (float) MI_NPIXELS(mi); while (((int) color_use) >= MI_NPIXELS(mi)) color_use -= (float) MI_NPIXELS(mi); while (((int) color_use) < 0) color_use += (float) MI_NPIXELS(mi); } #endif if (braid->braidword[i] < 0 || (FABSF(t - theta / 2.0) > theta / 7.0)) { x_1 = ((0.5 * (1.0 + SINF(t / theta * M_PI - M_PI_2)) * r1 + 0.5 * (1.0 + SINF((theta - t) / theta * M_PI - M_PI_2)) * r2)) * COSF(t + psi) + braid->center_x; y_1 = ((0.5 * (1.0 + SINF(t / theta * M_PI - M_PI_2)) * r1 + 0.5 * (1.0 + SINF((theta - t) / theta * M_PI - M_PI_2)) * r2)) * SINF(t + psi) + braid->center_y; x_2 = ((0.5 * (1.0 + SINF((t + t_inc) / theta * M_PI - M_PI_2)) * r1 + 0.5 * (1.0 + SINF((theta - t - t_inc) / theta * M_PI - M_PI_2)) * r2)) * COSF(t + t_inc + psi) + braid->center_x; y_2 = ((0.5 * (1.0 + SINF((t + t_inc) / theta * M_PI - M_PI_2)) * r1 + 0.5 * (1.0 + SINF((theta - t - t_inc) / theta * M_PI - M_PI_2)) * r2)) * SINF(t + t_inc + psi) + braid->center_y; if (MI_NPIXELS(mi) > 2) XSetForeground(display, MI_GC(mi), MI_PIXEL(mi, (int) color_use)); else XSetForeground(display, MI_GC(mi), MI_WHITE_PIXEL(mi)); XDrawLine(display, window, MI_GC(mi), (int) (x_1), (int) (y_1), (int) (x_2), (int) (y_2)); } } else { /* no crosSINFg */ #ifdef COLORCOMP if (MI_NPIXELS(mi) > 2) { color_use = color + SPINRATE * braid->components[applywordbackto(braid, s, i)] + (psi + t) / 2.0 / M_PI * (float) MI_NPIXELS(mi); while (((int) color_use) >= MI_NPIXELS(mi)) color_use -= (float) MI_NPIXELS(mi); while (((int) color_use) < 0) color_use += (float) MI_NPIXELS(mi); } #endif #ifdef COLORROUND if (MI_NPIXELS(mi) > 2) { color_use += SPINRATE * color_inc; while (((int) color_use) >= MI_NPIXELS(mi)) color_use -= (float) MI_NPIXELS(mi); } #endif r1 = braid->min_radius + r_diff * (float) (s); x_1 = r1 * COSF(t + psi) + braid->center_x; y_1 = r1 * SINF(t + psi) + braid->center_y; x_2 = r1 * COSF(t + t_inc + psi) + braid->center_x; y_2 = r1 * SINF(t + t_inc + psi) + braid->center_y; if (MI_NPIXELS(mi) > 2) XSetForeground(display, MI_GC(mi), MI_PIXEL(mi, (int) color_use)); else XSetForeground(display, MI_GC(mi), MI_WHITE_PIXEL(mi)); XDrawLine(display, window, MI_GC(mi), (int) (x_1), (int) (y_1), (int) (x_2), (int) (y_2)); } } } } XSetLineAttributes(display, MI_GC(mi), 1, LineSolid, CapNotLast, JoinRound); if (++braid->age > MI_CYCLES(mi)) { #ifdef STANDALONE braid->eraser = erase_window (MI_DISPLAY(mi), MI_WINDOW(mi), braid->eraser); #endif init_braid(mi); } }
static unsigned long critical_draw (Display *dpy, Window window, void *closure) { struct state *st = (struct state *) closure; if (st->eraser) { st->eraser = erase_window (st->dpy, st->window, st->eraser); return st->delay_usecs; } /* for (d_i_batch = batchcount; d_i_batch; d_i_batch--) */ { /* Set color */ if ((st->d_i_batch % st->lines_per_color) == 0) { st->d_i_color = (st->d_i_color + 1) % st->d_n_colors; st->gcv.foreground = st->d_colors[st->d_i_color].pixel; XChangeGC (st->dpy, st->fgc, GCForeground, &st->gcv); } assert(st->d_pos >= 0 && st->d_pos < st->settings.trail); model_step (st->model, &st->history[st->d_pos]); draw_step (st, st->fgc, st->d_pos); /* we use the history as a ring buffer, but don't start erasing until we've d_wrapped around once. */ if (++st->d_pos >= st->settings.trail) { st->d_pos -= st->settings.trail; st->d_wrapped = 1; } if (st->d_wrapped) { draw_step (st, st->bgc, st->d_pos+1); } } st->d_i_batch--; if (st->d_i_batch < 0) st->d_i_batch = st->batchcount; else return st->delay_usecs; st->i_restart = (st->i_restart + 1) % st->n_restart; if (st->i_restart == 0) { /* Time to start a new simulation, this one has probably got to be a bit boring. */ free_colormap (st, &st->d_colors, st->d_n_colors); setup_colormap (st, &st->d_colors, &st->d_n_colors); st->eraser = erase_window (st->dpy, st->window, st->eraser); model_initialize (st->model); model_step (st->model, &st->history[0]); st->d_pos = 1; st->d_wrapped = 0; st->d_i_batch = st->batchcount; } return st->delay_usecs; }
void z_restore (void) { FILE *gfp; zword success = 0; if (zargc != 0) { /* Get the file name */ /* Open auxilary file */ if ((gfp = frotzopenprompt(FILE_LOAD_AUX)) == NULL) goto finished; /* Load auxilary file */ success = fread (zmp + zargs[0], 1, zargs[1], gfp); /* Close auxilary file */ fclose (gfp); } else { long pc; zword release; zword addr; int i; /* Open game file */ if ((gfp = frotzopenprompt(FILE_RESTORE)) == NULL) goto finished; if (f_setup.save_quetzal) { success = restore_quetzal (gfp, story_fp, blorb_ofs); } else { /* Load game file */ release = (unsigned) fgetc (gfp) << 8; release |= fgetc (gfp); (void) fgetc (gfp); (void) fgetc (gfp); /* Check the release number */ if (release == h_release) { pc = (long) fgetc (gfp) << 16; pc |= (unsigned) fgetc (gfp) << 8; pc |= fgetc (gfp); SET_PC (pc); sp = stack + (fgetc (gfp) << 8); sp += fgetc (gfp); fp = stack + (fgetc (gfp) << 8); fp += fgetc (gfp); for (i = (int) (sp - stack); i < STACK_SIZE; i++) { stack[i] = (unsigned) fgetc (gfp) << 8; stack[i] |= fgetc (gfp); } fseek (story_fp, blorb_ofs, SEEK_SET); for (addr = 0; addr < h_dynamic_size; addr++) { int skip = fgetc (gfp); for (i = 0; i < skip; i++) zmp[addr++] = fgetc (story_fp); zmp[addr] = fgetc (gfp); (void) fgetc (story_fp); } /* Check for errors */ if (ferror (gfp) || ferror (story_fp) || addr != h_dynamic_size) success = -1; else /* Success */ success = 2; } else print_string ("Invalid save file\n"); } if ((short) success >= 0) { /* Close game file */ fclose (gfp); if ((short) success > 0) { zbyte old_screen_rows; zbyte old_screen_cols; /* In V3, reset the upper window. */ if (h_version == V3) split_window (0); LOW_BYTE (H_SCREEN_ROWS, old_screen_rows); LOW_BYTE (H_SCREEN_COLS, old_screen_cols); /* Reload cached header fields. */ restart_header (); /* * Since QUETZAL files may be saved on many different machines, * the screen sizes may vary a lot. Erasing the status window * seems to cover up most of the resulting badness. */ if (h_version > V3 && h_version != V6 && (h_screen_rows != old_screen_rows || h_screen_cols != old_screen_cols)) erase_window (1); } } else os_fatal ("Error reading save file"); } finished: if (h_version <= V3) branch (success); else store (success); }/* z_restore */
static unsigned long xspirograph_draw (Display *dpy, Window window, void *closure) { struct state *st = (struct state *) closure; Bool free_color = False; Bool flip_p = (st->counter & 1); int i; switch (st->drawstate) { case ERASE1: /* 5 sec delay before starting the erase */ st->drawstate = ERASE2; /* shouldn't this use the configured long_delay value??? */ return (st->long_delay == 0 ? 0 : 5000000); case ERASE2: /* erase, delaying 1/50th sec between frames */ st->eraser = erase_window(st->dpy, st->window, st->eraser); if (st->eraser) /* shouldn't this be a configured pause??? */ return 20000; st->drawstate = NEW_LAYER; /* just finished erasing -- leave screen black for 1 sec */ return (st->long_delay == 0 ? 0 : 1000000); case DRAW: /* most common case put in front */ for (i = 0; i < 1000; i++) { if (go(st, st->radius1, (flip_p ? st->radius2 : -st->radius2), st->distance)) { st->drawstate = NEW_LAYER; break; } } /* Next draw is delayed sleep_time (initialized value)*/ return st->sub_sleep_time; case NEW_LAYER: /* Increment counter */ st->counter++; if (st->counter > (2 * st->num_layers)) { /* reset to zero, free, and erase next time through */ st->counter = 0; if (free_color) XFreeColors (st->dpy, st->xgwa.colormap, &st->color.pixel, 1, 0); st->drawstate = ERASE1; } else { /* first, third, fifth, ... time through */ if (!flip_p) pick_new (st); new_colors (st); st->drawstate = DRAW; } /* No delay to the next draw */ return 0; default: /* OOPS!! */ fprintf(stderr, "%s: invalid state\n", progname); exit(1); } return st->sub_sleep_time; /* notreached */ }
/* random_helix_or_trig */ static unsigned long helix_draw (Display *dpy, Window window, void *closure) { struct state *st = (struct state *) closure; Bool free_color = False; XColor color; int delay = st->subdelay; int erase_delay = 10000; int ii; if (st->eraser) { st->eraser = erase_window (dpy, window, st->eraser); if (st->eraser) delay = erase_delay; goto END; } switch (st->dstate) { case LINGER: delay = st->sleep_time * 1000000; st->dstate = ERASE; break; case ERASE: st->eraser = erase_window (dpy, window, st->eraser); delay = erase_delay; if (free_color) XFreeColors (dpy, st->cmap, &color.pixel, 1, 0); st->dstate = (random() & 1) ? HELIX : TRIG; break; case DRAW_HELIX: for (ii = 0; ii < 10; ii++) { helix (dpy, window, st); if (st->dstate != DRAW_HELIX) break; } break; case DRAW_TRIG: for (ii = 0; ii < 5; ii++) { trig (dpy, window, st); if (st->dstate != DRAW_TRIG) break; } break; case HELIX: random_helix (dpy, window, st, &color, &free_color); st->dstate = DRAW_HELIX; break; case TRIG: random_trig(dpy, window, st, &color, &free_color); st->dstate = DRAW_TRIG; break; default: abort(); } END: return delay; }
static unsigned long wander_draw (Display *dpy, Window window, void *closure) { struct state *st = (struct state *) closure; int i; if (st->eraser) { st->eraser = erase_window (st->dpy, st->window, st->eraser); goto END; } for (i = 0; i < 2000; i++) { if (NRAND (st->density)) { st->x = st->last_x; st->y = st->last_y; } else { st->last_x = st->x; st->last_y = st->y; st->x += st->width_1 + NRAND (3); while (st->x >= st->width) st->x -= st->width; st->y += st->height_1 + NRAND (3); while (st->y >= st->height) st->y -= st->height; } if (NRAND (st->length_limit) == 0) { if (st->advance == 0) { st->color_index = NRAND (st->color_count); } else { st->color_index = (st->color_index + st->advance) % st->color_count; } st->color = st->colors [st->color_index].pixel; XSetForeground (st->dpy, st->context, st->color); if (st->circles) { XFillArc (st->dpy, st->pixmap, st->context, 0, 0, st->size, st->size, 0, 360 * 64); } } if (st->reset_p || NRAND (st->reset_limit) == 0) { st->reset_p = 0; st->eraser = erase_window (st->dpy, st->window, st->eraser); st->color = st->colors [NRAND (st->color_count)].pixel; st->x = NRAND (st->width); st->y = NRAND (st->height); st->last_x = st->x; st->last_y = st->y; if (st->circles) { XFillArc (st->dpy, st->pixmap, st->context, 0, 0, st->size, st->size, 0, 360*64); } } if (st->size == 1) { XDrawPoint (st->dpy, st->window, st->context, st->x, st->y); } else { if (st->circles) { XCopyArea (st->dpy, st->pixmap, st->window, st->context, 0, 0, st->size, st->size, st->x * st->size, st->y * st->size); } else { XFillRectangle (st->dpy, st->window, st->context, st->x * st->size, st->y * st->size, st->size, st->size); } } } END: return st->delay; }
void GlkInterface::restart_screen() { erase_window(0); erase_window(1); split_window(0); }
ENTRYPOINT void draw_hop(ModeInfo * mi) { double oldj, oldi; XPoint *xp; int k; hopstruct *hp; if (hops == NULL) return; hp = &hops[MI_SCREEN(mi)]; #ifdef STANDALONE if (hp->eraser) { hp->eraser = erase_window (MI_DISPLAY(mi), MI_WINDOW(mi), hp->eraser); return; } #endif if (hp->pointBuffer == NULL) return; xp = hp->pointBuffer; k = hp->bufsize; MI_IS_DRAWN(mi) = True; hp->inc++; if (MI_NPIXELS(mi) > 2) { XSetForeground(MI_DISPLAY(mi), MI_GC(mi), MI_PIXEL(mi, hp->pix)); if (++hp->pix >= MI_NPIXELS(mi)) hp->pix = 0; } while (k--) { oldj = hp->j; switch (hp->op) { case MARTIN: /* SQRT, MARTIN1 */ oldi = hp->i + hp->inc; hp->j = hp->a - hp->i; hp->i = oldj + ((hp->i < 0) ? sqrt(fabs(hp->b * oldi - hp->c)) : -sqrt(fabs(hp->b * oldi - hp->c))); xp->x = hp->centerx + (int) (hp->i + hp->j); xp->y = hp->centery - (int) (hp->i - hp->j); break; case EJK1: oldi = hp->i + hp->inc; hp->j = hp->a - hp->i; hp->i = oldj - ((hp->i > 0) ? (hp->b * oldi - hp->c) : -(hp->b * oldi - hp->c)); xp->x = hp->centerx + (int) (hp->i + hp->j); xp->y = hp->centery - (int) (hp->i - hp->j); break; case EJK2: oldi = hp->i + hp->inc; hp->j = hp->a - hp->i; hp->i = oldj - ((hp->i < 0) ? log(fabs(hp->b * oldi - hp->c)) : -log(fabs(hp->b * oldi - hp->c))); xp->x = hp->centerx + (int) (hp->i + hp->j); xp->y = hp->centery - (int) (hp->i - hp->j); break; case EJK3: oldi = hp->i + hp->inc; hp->j = hp->a - hp->i; hp->i = oldj - ((hp->i > 0) ? sin(hp->b * oldi) - hp->c : -sin(hp->b * oldi) - hp->c); xp->x = hp->centerx + (int) (hp->i + hp->j); xp->y = hp->centery - (int) (hp->i - hp->j); break; case EJK4: oldi = hp->i + hp->inc; hp->j = hp->a - hp->i; hp->i = oldj - ((hp->i > 0) ? sin(hp->b * oldi) - hp->c : -sqrt(fabs(hp->b * oldi - hp->c))); xp->x = hp->centerx + (int) (hp->i + hp->j); xp->y = hp->centery - (int) (hp->i - hp->j); break; case EJK5: oldi = hp->i + hp->inc; hp->j = hp->a - hp->i; hp->i = oldj - ((hp->i > 0) ? sin(hp->b * oldi) - hp->c : -(hp->b * oldi - hp->c)); xp->x = hp->centerx + (int) (hp->i + hp->j); xp->y = hp->centery - (int) (hp->i - hp->j); break; case EJK6: oldi = hp->i + hp->inc; hp->j = hp->a - hp->i; hp->i = oldj - asin((hp->b * oldi) - (long) (hp->b * oldi)); xp->x = hp->centerx + (int) (hp->i + hp->j); xp->y = hp->centery - (int) (hp->i - hp->j); break; case RR: /* RR1 */ oldi = hp->i + hp->inc; hp->j = hp->a - hp->i; hp->i = oldj - ((hp->i < 0) ? -pow(fabs(hp->b * oldi - hp->c), hp->d) : pow(fabs(hp->b * oldi - hp->c), hp->d)); xp->x = hp->centerx + (int) (hp->i + hp->j); xp->y = hp->centery - (int) (hp->i - hp->j); break; case POPCORN: #define HVAL 0.05 #define INCVAL 50 { double tempi, tempj; if (hp->inc >= 100) hp->inc = 0; if (hp->inc == 0) { if (hp->a++ >= INCVAL) { hp->a = 0; if (hp->b++ >= INCVAL) hp->b = 0; } hp->i = (-hp->c * INCVAL / 2 + hp->c * hp->a) * M_PI / 180.0; hp->j = (-hp->c * INCVAL / 2 + hp->c * hp->b) * M_PI / 180.0; } tempi = hp->i - HVAL * sin(hp->j + tan(3.0 * hp->j)); tempj = hp->j - HVAL * sin(hp->i + tan(3.0 * hp->i)); xp->x = hp->centerx + (int) (MI_WIDTH(mi) / 40 * tempi); xp->y = hp->centery + (int) (MI_HEIGHT(mi) / 40 * tempj); hp->i = tempi; hp->j = tempj; } break; case JONG: if (hp->centerx > 0) oldi = hp->i + 4 * hp->inc / hp->centerx; else oldi = hp->i; hp->j = sin(hp->c * hp->i) - cos(hp->d * hp->j); hp->i = sin(hp->a * oldj) - cos(hp->b * oldi); xp->x = hp->centerx + (int) (hp->centerx * (hp->i + hp->j) / 4.0); xp->y = hp->centery - (int) (hp->centery * (hp->i - hp->j) / 4.0); break; case SINE: /* MARTIN2 */ oldi = hp->i + hp->inc; hp->j = hp->a - hp->i; hp->i = oldj - sin(oldi); xp->x = hp->centerx + (int) (hp->i + hp->j); xp->y = hp->centery - (int) (hp->i - hp->j); break; } xp++; } XDrawPoints(MI_DISPLAY(mi), MI_WINDOW(mi), MI_GC(mi), hp->pointBuffer, hp->bufsize, CoordModeOrigin); if (++hp->count > MI_CYCLES(mi)) { #ifdef STANDALONE hp->eraser = erase_window (MI_DISPLAY(mi), MI_WINDOW(mi), hp->eraser); #endif /* STANDALONE */ init_hop(mi); } }
// Group handler void __saveds backdrop_group_handler(void) { IPCData *ipc; GroupData *group=0; // Do group if (ipc=IPC_ProcStartup((ULONG *)&group,backdrop_group_init)) { // Read objects SetBusyPointer(group->window); backdrop_read_group_objects(group); ClearPointer(group->window); // Event loop FOREVER { IPCMessage *msg; BOOL quit_flag=0; // Got an AppWindow? if (group->appwindow) { DOpusAppMessage *amsg; BOOL beep=0; // AppMessages? while (amsg=(DOpusAppMessage *)GetMsg(group->appport)) { short arg; char path[256]; BackdropObject *drop_obj; // Lock backdrop list lock_listlock(&group->info->objects,1); // Set busy pointer if (group->window) SetBusyPointer(group->window); // Dropped on an object? if (drop_obj=backdrop_get_object(group->info,amsg->da_Msg.am_MouseX,amsg->da_Msg.am_MouseY,0)) { USHORT qual; // Get qualifiers qual=(InputBase)?PeekQualifier():0; // Is shift/alt down? if (qual&(IEQUALIFIER_LSHIFT|IEQUALIFIER_LALT)==(IEQUALIFIER_LSHIFT|IEQUALIFIER_LALT)) { // Get path of first file GetWBArgPath(&amsg->da_Msg.am_ArgList[0],path,256); // Replace the image backdrop_replace_icon_image(group->info,path,drop_obj); } // Run program with args else backdrop_object_open( group->info, drop_obj, 0, 0, amsg->da_Msg.am_NumArgs, amsg->da_Msg.am_ArgList); } // Otherwise, adding objects to the group else for (arg=0;arg<amsg->da_Msg.am_NumArgs;arg++) { // Valid name? if (*amsg->da_Msg.am_ArgList[arg].wa_Name) { short x,y; // Get full path name GetWBArgPath(&amsg->da_Msg.am_ArgList[arg],path,256); // Default to no position x=-1; y=-1; // Dopus app message? if (CheckAppMessage(amsg)) { // Get icon position x=amsg->da_DragOffset.x+amsg->da_Msg.am_MouseX+amsg->da_DropPos[arg].x; y=amsg->da_DragOffset.y+amsg->da_Msg.am_MouseY+amsg->da_DropPos[arg].y; } // Add group object backdrop_group_add_object(group->name,group->info,path,x,y); } // Otherwise, set beep flag for error else if (!beep) { beep=1; DisplayBeep(group->window->WScreen); } } // Clear busy pointer if (group->window) ClearPointer(group->window); // Unlock backdrop list unlock_listlock(&group->info->objects); // Reply to message ReplyMsg((struct Message *)amsg); } } // Icon notification if (group->info->notify_req) { DOpusNotify *notify; // Get notify message if (notify=(DOpusNotify *)GetMsg(group->info->notify_port)) backdrop_check_notify(group->info,notify,0); } // IPC messages? while (msg=(IPCMessage *)GetMsg(ipc->command_port)) { // Look at message switch (msg->command) { // Activate case IPC_ACTIVATE: // Bring window to front if (group->window) backdrop_show_group(group); break; // Quit case IPC_QUIT: quit_flag=1; group->got_quit=1; break; // Hide case IPC_HIDE: backdrop_hide_group(group); break; // Show case IPC_SHOW: group->screen=(struct Screen *)msg->data; backdrop_show_group(group); break; // Reset (menus) case IPC_RESET: // Gotta window? if (group->window) { // Reset menus? if (msg->flags) { display_free_menu(group->window); display_get_menu(group->window); } // Fix menus display_fix_menu(group->window,WINDOW_GROUP,0); } break; // New font case GROUP_NEW_FONT: // Get new font backdrop_get_font(group->info); // Redraw objects backdrop_show_objects(group->info,BDSF_CLEAR|BDSF_RESET); break; // New name case GROUP_NEW_NAME: // Copy name strcpy(group->name,msg->data_free); // Update window title if (group->window) SetWindowTitles(group->window,group->name,(char *)-1); break; // Add a new icon case GROUP_ADD_ICON: // Lock backdrop list lock_listlock(&group->info->objects,1); // Set busy pointer if (group->window) SetBusyPointer(group->window); // Add object backdrop_group_add_object(group->name,group->info,msg->data_free,-1,-1); // Clear busy pointer if (group->window) ClearPointer(group->window); // Unlock backdrop list unlock_listlock(&group->info->objects); break; // New backfill pattern case LISTER_BACKFILL_CHANGE: // Window open? if (group->window) { // Install appropriate hook InstallLayerHook( group->window->WLayer, (msg->flags)?&group->pattern.hook:LAYERS_BACKFILL); // Redraw window erase_window(group->window); // Redraw icons backdrop_show_objects(group->info,0); } break; // Delete from group case GROUP_DELETE: SetBusyPointer(group->window); backdrop_remove_group_objects(group,(BackdropObject *)msg->data); ClearPointer(group->window); break; // Help case IPC_HELP: // Show help for group help_show_help(HELP_PROGRAM_GROUP,0); break; // Do a function case LISTER_DO_FUNCTION: // Arrange icons? if (msg->data>=(APTR)MENU_LISTER_ARRANGE_NAME && msg->data<=(APTR)MENU_LISTER_ARRANGE_SIZE) { // Do cleanup backdrop_cleanup(group->info,BSORT_NAME+(((ULONG)msg->data)-MENU_LISTER_ARRANGE_NAME),0); } break; } // Reply to message IPC_Reply(msg); } // Is window open? if (group->window) { struct IntuiMessage *imsg; // Check timer if (CheckTimer(group->timer)) { // Dragging something? if (group->info->flags&BDIF_DRAGGING) { // Check for deadlocks if (group->info->last_tick==group->info->tick_count) { // Stop drag backdrop_stop_drag(group->info); } // Remember tick count group->info->last_tick=group->info->tick_count; } // Re-start timer StartTimer(group->timer,0,500000); } // Window messages while (imsg=(struct IntuiMessage *)GetMsg(group->window->UserPort)) { struct IntuiMessage msg_copy; struct MenuItem *item; // Copy message msg_copy=*imsg; // Menu verify? if (imsg->Class==IDCMP_MENUVERIFY) { // See if we want to swallow it if (!backdrop_test_rmb(group->info,imsg,&msg_copy,TRUE)) { // Did event happen over the window? if (imsg->MouseX>=0 && imsg->MouseY>=0 && imsg->MouseX<group->window->Width && imsg->MouseY<group->window->Height && imsg->Qualifier&IEQUALIFIER_RBUTTON) { // Cancel menu event imsg->Code=MENUCANCEL; // Change our copy to MOUSEBUTTONS msg_copy.Class=IDCMP_MOUSEBUTTONS; msg_copy.Code=MENUDOWN; // Kludge for MagicMenu if (msg_copy.Seconds==0) CurrentTime(&msg_copy.Seconds,&msg_copy.Micros); } } } // Resize/refresh? if (imsg->Class==IDCMP_NEWSIZE || imsg->Class==IDCMP_REFRESHWINDOW) { // Handle message backdrop_idcmp(group->info,imsg,0); // Reply to message ReplyMsg((struct Message *)imsg); continue; } // Reply to message ReplyMsg((struct Message *)imsg); // Is it a backdrop message? if (backdrop_idcmp(group->info,&msg_copy,0)) continue; // Look at message class switch (msg_copy.Class) { // Window closed case IDCMP_CLOSEWINDOW: quit_flag=1; break; // Window is inactive case IDCMP_INACTIVEWINDOW: // Abort timer if running StopTimer(group->timer); break; // Window is active case IDCMP_ACTIVEWINDOW: // Start timer if not running StartTimer(group->timer,1,0); break; // Key press case IDCMP_RAWKEY: // Help? if (msg_copy.Code==0x5f && !(msg_copy.Qualifier&VALID_QUALIFIERS)) { help_get_help( msg_copy.MouseX+group->window->LeftEdge, msg_copy.MouseY+group->window->TopEdge, msg_copy.Qualifier); } // Close? else if (msg_copy.Code==0x45 && msg_copy.Qualifier&IEQUAL_ANYSHIFT) quit_flag=1; break; // Button pressed case IDCMP_MOUSEBUTTONS: // Right button? if (msg_copy.Code==MENUDOWN) { USHORT res; // Do popup menu if (group->popup && (res=DoPopUpMenu(group->window,&group->popup->ph_Menu,NULL,MENUDOWN))!=(USHORT)-1) { // Help? if (res&POPUP_HELPFLAG) { // Get help ID res&=~POPUP_HELPFLAG; // Do help help_menu_help(res,0); break; } // Do the function quit_flag=backdrop_group_do_function(group,res,0); } } break; // Menu event case IDCMP_MENUPICK: case IDCMP_MENUHELP: { struct Menu *oldstrip=group->window->MenuStrip; USHORT nextselect; // Get item nextselect=msg_copy.Code; while (item=ItemAddress(group->window->MenuStrip,nextselect)) { // get next nextselect=item->NextSelect; // Help? if (msg_copy.Class==IDCMP_MENUHELP) { help_menu_help((long)GTMENUITEM_USERDATA(item),0); break; } // Do the function quit_flag=backdrop_group_do_function(group,(ULONG)GTMENUITEM_USERDATA(item),item); // Check valid next if (!nextselect || !group->window || oldstrip!=group->window->MenuStrip) break; } } break; } } } // Check quit flag if (quit_flag) break; // Wait for event Wait( 1<<ipc->command_port->mp_SigBit| 1<<group->timer->port->mp_SigBit| ((group->info->notify_req)?(1<<group->info->notify_port->mp_SigBit):0)| ((group->window)?(1<<group->window->UserPort->mp_SigBit):0)| ((group->appwindow)?(1<<group->appport->mp_SigBit):0)); } // Close window backdrop_free_group(group); // Send goodbye IPC_Goodbye(ipc,&main_ipc,0); }