home *** CD-ROM | disk | FTP | other *** search
-
- /* Include file for turtle.c for Sun Microsystems workstation */
-
- /* modified for use with 2.0 SunWindows by Philippe Lacroute */
-
- /* must be loaded -lsuntool -lsunwindow -lpixrect */
-
- #include <suntool/tool_hs.h>
- #include <fcntl.h>
- #include <signal.h>
-
- /* Window system variables and functions */
-
- #define CLR PIX_CLR
- #define SET PIX_SET
- #define INVERT PIX_SRC ^ PIX_DST
- #define SPLIT_TEXT_SIZE 5 /* default # lines of text in split mode */
- #define BORDER 5 /* width of the window borders */
- #define SCREEN_DEPTH 1
- #define FIX_PICTURE 1
- #define FIX_SIZE 2
-
- #define ltos_xcor(c) c + scalex /* conversion: logo to window */
- #define ltos_ycor(c) scaley - c /* system coordinates */
-
- static short logocur_data[16] = {
- 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0000, 0x0000, 0xF83E,
- 0x0000, 0x0000, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0000
- };
-
- mpr_static(logocur_pr, 16, 16, 1, logocur_data);
-
- struct cursor logocur = { 7, 7, PIX_SRC ^ PIX_DST, &logocur_pr };
-
- static setwinchflag();
- extern char pr_reversesrc[];
- int screen_height, screen_width;/* size for retained pixrect */
- int gfx_windowfd = -1; /* window device (blanket) */
- int real_gfx_fd; /* gfx window parent */
- struct pixwin *gfx_pixwin; /* actual window */
- int gfx_flags = 0; /* used for SIGWINCH */
- int parentfd; /* toll window */
- int textfd; /* text window */
- int scalex, scaley;
- int font_height;
- int tlines = SPLIT_TEXT_SIZE;
- struct rect tool_rect;
- int sigwinch_ok = 0;
- int mouse_x = -1, mouse_y = -1; /* current location of mouse (screen coor.) */
- int mousein = 0;
-
- int sunpens[] = {SET, CLR, INVERT};
- char state; /* What state we are in (text, split, full) */
- NUMBER sunoldx,sunoldy;
-
- int sunturt(),sunfrom(),sunto(),suninit(),sunstate();
-
- struct display sun = {
- 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1, /* dims initialized later */
- "", "", "", "", sunturt, sunfrom, sunto, nullfn, suninit, nullfn,
- nullfn, nullfn, nullfn, sunstate
- };
-
- #define transline(op,fx,fy,tx,ty) pw_vector(gfx_pixwin, ltos_xcor(fx), ltos_ycor(fy), ltos_xcor(tx), ltos_ycor(ty), op, 1)
-
- sunturt(hide)
- int hide; /* 1 to erase */
- {
- NUMBER newx, newy, oldx, oldy, angle;
- static double scrunch = 1.0;
-
- if (!hide)
- scrunch = yscrunch;
- angle = (mydpy->turth-90.0)*3.141592654/180.0;
- oldx = mydpy->turtx + 15.0*sin(angle);
- oldy = mydpy->turty + 15.0*cos(angle);
- angle = mydpy->turth*3.141592654/180.0;
- newx = mydpy->turtx + 15.0*sin(angle);
- newy = mydpy->turty + 15.0*cos(angle);
- transline(INVERT,(int)oldx,(int)(scrunch*oldy),
- (int)newx,(int)(scrunch*newy));
- oldx = newx;
- oldy = newy;
- angle = (mydpy->turth+90.0)*3.141592654/180.0;
- newx = mydpy->turtx + 15.0*sin(angle);
- newy = mydpy->turty + 15.0*cos(angle);
- transline(INVERT,(int)oldx,(int)(scrunch*oldy),
- (int)newx,(int)(scrunch*newy));
- oldx = newx;
- oldy = newy;
- angle = (mydpy->turth-90.0)*3.141592654/180.0;
- newx = mydpy->turtx + 15.0*sin(angle);
- newy = mydpy->turty + 15.0*cos(angle);
- transline(INVERT,(int)oldx,(int)(scrunch*oldy),
- (int)newx,(int)(scrunch*newy));
- scrunch = yscrunch;
- }
-
- suninit()
- {
- if (gfx_windowfd < 0) {
- char *parent, *text, *gfx;
- struct pixfont *pf = pf_default();
- struct inputmask im;
- struct screen scr;
- int sig_mask;
-
- sig_mask = sigblock(1 << (SIGWINCH-1));
-
- /* Get window numbers from environment */
-
- if ((parent = getenv("LOGO_TOOL")) == NULL) {
- printf("No LOGO_TOOL environment variable\n");
- printf("Are you running logo instead of logotool?\n");
- errhand();
- }
- if ((text = getenv("LOGO_TEXT")) == NULL) {
- printf("No LOGO_TEXT environment variable\n");
- printf("Are you running logo instead of logotool?\n");
- errhand();
- }
- if ((gfx = getenv("LOGO_GFX")) == NULL) {
- printf("No LOGO_GFX environment variable\n");
- printf("Are you running logo instead of logotool?\n");
- errhand();
- }
-
- /* Open windows */
-
- if ((parentfd = open(parent, 0)) < 0) {
- printf("Couldn't open parent window %s\n", parent);
- printf("Sorry, cannot use the turtle!\n");
- errhand();
- }
- if ((textfd = open(text, 0)) < 0) {
- printf("Couldn't open ttysubwindow %s\n", text);
- printf("Sorry, cannot use the turtle!\n");
- errhand();
- }
- if ((real_gfx_fd = open(gfx, 0)) < 0) {
- printf("Couldn't open takeover window %s\n", gfx);
- printf("Sorry, cannot use the turtle!\n");
- errhand();
- }
-
- /* Find out how big we are */
-
- win_getrect(parentfd, &tool_rect);
-
- /* Create window */
-
- if ((gfx_windowfd = win_getnewwindow()) < 0) {
- printf("Couldn't get a new window\n");
- printf("Sorry, cannot use the turtle!\n");
- errhand();
- }
- if (win_insertblanket(gfx_windowfd, real_gfx_fd) != 0) {
- printf("Blanket window failed\n");
- printf("Sorry, cannot use the turtle!\n");
- errhand();
- }
- gfx_pixwin = pw_open(gfx_windowfd);
-
- /*
- * send input typed into gfxwindow to ttysubwindow;
- * save mouse movement and buttons for gfxsw;
- * want non-blocking read for gfxsw
- */
-
- input_imnull(&im);
- win_setinputcodebit(&im, LOC_MOVE);
- win_setinputcodebit(&im, MS_LEFT);
- win_setinputcodebit(&im, MS_MIDDLE);
- win_setinputcodebit(&im, LOC_WINEXIT);
- win_setinputmask(gfx_windowfd, &im, NULL, win_fdtonumber(textfd));
- if (fcntl(gfx_windowfd, F_SETFL, FNDELAY) == -1) {
- printf("Fcntl failed.\n");
- printf("Please don't use the mouse!\n");
- }
- win_setcursor(gfx_windowfd, &logocur);
-
- /* Create retained pixrect and set SIGWINCH catcher */
-
- win_screenget(gfx_windowfd, &scr); /* get screen dims */
- screen_height = scr.scr_rect.r_height;
- screen_width = scr.scr_rect.r_width;
- gfx_pixwin->pw_prretained =
- mem_create(screen_height, screen_width, SCREEN_DEPTH);
- font_height = pf->pf_defaultsize.y; /* Get the font height */
- signal(SIGWINCH, setwinchflag);
- sigsetmask(sig_mask);
-
- /* Initialize screen size and display */
-
- yscrunch = 1.0;
- gfx_setsize(0);
- } else
- sunstate('s'); /* Just redisplay */
- }
-
- sunfrom(x,y)
- NUMBER x,y;
- {
- sunoldx = x;
- sunoldy = y;
- }
-
- sunto(x,y)
- NUMBER x,y;
- {
- transline(sunpens[penerase], (int)sunoldx,(int)sunoldy,(int)x,(int)y);
- }
-
- sunstate(which)
- {
- struct rect r;
-
- win_getrect(parentfd, &r); /* get size of parent */
- fix_rect(&r);
- switch (which) {
- case 's': /* Split screen - leave lines for text */
- if (tlines > 0) {
- if (tlines * font_height <= r.r_height) {
- r.r_top += r.r_height - (tlines*font_height);
- r.r_height = tlines * font_height;
- }
- win_setrect(textfd, &r);
- putchar('\n');
- state = 's';
- break;
- } /* else fallthrough */
- case 'f': /* Full screen - size of parent */
- /* must get rid of text window */
- r.r_left = r.r_top = -2000;
- win_setrect(textfd, &r);
- putchar('\n');
- state = which; /* could be either s or f */
- break;
- case 't': /* Text - move graphics window off screen */
- win_setrect(textfd, &r);
- state = 't';
- break;
- case 'c':
- case 'w': /* Clear screen */
- win_getrect(gfx_windowfd, &r);
- pw_write(gfx_pixwin, 0, 0,
- r.r_width, r.r_height,
- PIX_CLR, NULL, 0, 0);
- pr_rop(gfx_pixwin->pw_prretained,
- 0, 0, screen_width, screen_height,
- PIX_CLR, NULL, 0, 0);
- break;
- }
- }
-
- checkwindow()
- {
- if (gfx_windowfd < 0)
- return;
- if (gfx_flags & FIX_PICTURE) {
- repaint();
- }
- if (gfx_flags & FIX_SIZE) {
- gfx_setsize(1);
- repaint();
- }
- gfx_flags = 0;
- }
-
- gfx_setsize(redraw)
- int redraw;
- {
- int newx, newy;
- struct rect r, p;
-
- win_getrect(parentfd, &r);
- p = r;
- fix_rect(&r);
- win_setrect(real_gfx_fd, &r);
-
- if (redraw) {
- sunstate(state);
- if (p.r_width != tool_rect.r_width)
- mydpy->xhigh += p.r_width - tool_rect.r_width;
- if (p.r_height != tool_rect.r_height)
- mydpy->ylow -= p.r_height - tool_rect.r_height;
-
- /* Move turtle inside window if it isn't */
-
- newx = mydpy->turtx;
- newy = mydpy->turty;
- if (mydpy->turtx > mydpy->xhigh)
- newx = mydpy->xhigh;
- if (mydpy->turtx < mydpy->xlow)
- newx = mydpy->xlow;
- if (mydpy->turty > mydpy->yhigh)
- newy = mydpy->yhigh;
- if (mydpy->turty < mydpy->ylow)
- newy = mydpy->ylow;
- if (newx != mydpy->turtx || newy != mydpy->turty) {
- if (shown)
- sunturt(1);
- mydpy->turtx = newx;
- mydpy->turty = newy;
- if (shown)
- sunturt(0);
- }
- tool_rect = p;
- } else {
- scalex = r.r_width / 2 - 1;
- scaley = r.r_height - r.r_height / 2 + 1;
- mydpy->xhigh = r.r_width / 2;
- mydpy->xlow = -(mydpy->xhigh) + 1;
- mydpy->yhigh = r.r_height / 2 + 3;
- mydpy->ylow = -(mydpy->yhigh) + 4;
- sunstate('s');
- }
- }
-
- static
- setwinchflag()
- {
- struct rect r;
-
- win_getrect(parentfd, &r);
- if (!rect_equal(&r, &tool_rect))
- gfx_flags |= FIX_SIZE;
- gfx_flags |= FIX_PICTURE;
- if (sigwinch_ok)
- checkwindow();
-
- }
-
- repaint()
- {
- struct rect r;
-
- win_getrect(gfx_windowfd, &r);
- pw_damaged(gfx_pixwin);
- pw_write(gfx_pixwin, 0, 0, r.r_width, r.r_height,
- PIX_SRC, gfx_pixwin->pw_prretained, 0, 0);
- pw_donedamaged(gfx_pixwin);
- }
-
- struct object *
- fill_region()
- {
- int x = ltos_xcor((int)mydpy->turtx), y = ltos_ycor((int)mydpy->turty);
- struct rect r;
-
- tcheck();
- if (shown)
- sunturt(1);
- win_getrect(gfx_windowfd, &r);
- fill(x, y, r.r_width, r.r_height);
- if (shown)
- sunturt(0);
- return((struct object *) 0);
- }
-
- #define getpixel ((*(mpr_d(buf)->md_image+(x>>4))>>(15-(x&15)))&1)
- #define getline pw_read(buf, 0, 0, gfx_width, 1, PIX_SRC, gfx_pixwin, 0, y); yinbuf = y
- #define putline pw_vector(gfx_pixwin, leftend, y, rightend, y, PIX_SRC, NEWVALUE)
- #define didabove (y == oldy+1 && leftend >= oldleft && rightend <= oldright)
- #define didbelow (y == oldy-1 && leftend >= oldleft && rightend <= oldright)
- #define savex savedx = x
- #define restorex x = savedx
- #define push stack[stackptr++] = x | (y << 16)
- #define pop x = stack[--stackptr] & 65535; y = stack[stackptr] >> 16
- #define stacknotempty (stackptr > 0)
- #define OLDVALUE 0
- #define NEWVALUE 1
- #define scanline \
- savex; \
- x = leftend; \
- while (x <= rightend) { \
- while(x <= rightend && getpixel != OLDVALUE) \
- x++; \
- if (x > rightend) \
- break; \
- push; \
- while (x <= rightend && getpixel == OLDVALUE) \
- x++; \
- } \
- restorex
-
- fill(startx, starty, gfx_width, gfx_height)
- int startx, starty, gfx_width, gfx_height;
- {
- register int x, y, stackptr = 0, savedx;
- int oldy, leftend, rightend, oldleft, oldright, yinbuf = -1;
- long stack[1000];
- struct pixrect *buf;
-
- x = startx;
- y = starty;
- if (pw_get(gfx_pixwin, x, y) == NEWVALUE) /* in case the pen */
- pw_put(gfx_pixwin, x, y, OLDVALUE); /* is down and this */
- buf = mem_create(gfx_width, 1, 1); /* point is written */
- oldy = y;
- push;
- while (stacknotempty) {
- pop;
- if (y != yinbuf)
- getline;
- if (getpixel == NEWVALUE)
- continue;
- savex;
- x--;
- while (x >= 0 && getpixel == OLDVALUE)
- x--;
- leftend = x + 1;
- restorex;
- savex;
- while (x < gfx_width && getpixel == OLDVALUE)
- x++;
- rightend = x - 1;
- restorex;
- putline;
- if (!didabove && y > 0) {
- y--;
- getline;
- scanline;
- y++;
- }
- if (!didbelow && y < gfx_height-1) {
- y++;
- getline;
- scanline;
- y--;
- }
- oldy = y;
- oldleft = leftend;
- oldright = rightend;
- }
- pr_destroy(buf);
- }
-
- struct object *
- text_size(arg)
- register struct object *arg;
- {
- int lines;
- NUMBER ncheck();
-
- lines = (int)ncheck(arg);
- if (lines < 0) {
- printf("textsize takes a positive input\n");
- errhand();
- } else {
- tlines = lines;
- }
- if (state == 's')
- sunstate('s');
- }
-
- fix_rect(r)
- struct rect *r;
- {
- r->r_width -= 2 * BORDER;
- r->r_height -= font_height + 1 + BORDER;
- r->r_top = font_height + 1;
- r->r_left = BORDER;
- }
-
- sigwinch_on()
- {
- checkwindow();
- sigwinch_ok = 1;
- }
-
- sigwinch_off()
- {
- sigwinch_ok = 0;
- }
-
-