📄 teksw_ui.c
字号:
voidtek_char(td, c) caddr_t td; register unsigned char c;{ register struct teksw *tsp; tsp = (struct teksw *) td; /* * turn off cursor while characters are being displayed */ if (tsp->uiflags & ACURSORON) { tsp->uiflags &= ~ACURSORON; removealphacursor(tsp); } c &= 0xff; if (tsp->type == VT_WRITETHRU) { pw_char(tsp->pwp, tsp->curpos.x, tsp->curpos.y, (PIX_SRC ^ PIX_DST), tsp->curfont, c); pw_show(tsp->pwp); pw_char(tsp->pwp, tsp->curpos.x, tsp->curpos.y, (PIX_SRC ^ PIX_DST), tsp->curfont, c); } else { pw_char(tsp->pwp, tsp->curpos.x, tsp->curpos.y, (tsp->straps & CRT_CHARS) ? PIX_SRC : (PIX_SRC | PIX_DST), tsp->curfont, c); }}voidtek_ttyoutput(td, c) caddr_t td; char c;{ register struct teksw *tsp; tsp = (struct teksw *) td; if (tsp->ptyorp == tsp->ptyowp) { notify_set_output_func(tsp, teksw_pty_output, tsp->pty); } *tsp->ptyowp++ = c; if (tsp->ptyowp >= &tsp->ptyobuf[sizeof (tsp->ptyobuf)]) { tsp->ptyowp--; }}voidtek_displaymode(td, style, type) caddr_t td; enum vstyle style; enum vtype type;{ register struct teksw *tsp; tsp = (struct teksw *) td; tsp->style = style; tsp->type = type;}voidtek_chfont(td, f) caddr_t td; int f;{ register struct teksw *tsp; tsp = (struct teksw *) td; tsp->curfont = tekfont[f]; (void) ioctl(tsp->tty, TIOCSSIZE, &tekttysize[f]); if (tsp->uiflags & ACURSORON) { tsp->uiflags &= ~ACURSORON; removealphacursor(tsp); }}voidtek_cursormode(td, cmode) caddr_t td; register enum cursormode cmode;{ register struct teksw *tsp; tsp = (struct teksw *) td; switch (cmode) { case NOCURSOR: if (tsp->uiflags & ACURSORON) { tsp->uiflags &= ~ACURSORON; removealphacursor(tsp); } if (tsp->uiflags & GCURSORON) { tsp->uiflags &= ~GCURSORON; if (tsp->uiflags & BADCURSOR) { goodcursor(tsp); } cursor_set(tsp->cursor, CURSOR_SHOW_CURSOR, TRUE, CURSOR_SHOW_CROSSHAIRS, FALSE, 0); window_set(tsp->canvas, WIN_CURSOR, tsp->cursor, WIN_IGNORE_PICK_EVENT, WIN_IN_TRANSIT_EVENTS, 0); } break; case ALPHACURSOR: if (tsp->uiflags & GCURSORON) { tsp->uiflags &= ~GCURSORON; if (tsp->uiflags & BADCURSOR) { goodcursor(tsp); } cursor_set(tsp->cursor, CURSOR_SHOW_CURSOR, TRUE, CURSOR_SHOW_CROSSHAIRS, FALSE, 0); window_set(tsp->canvas, WIN_CURSOR, tsp->cursor, WIN_IGNORE_PICK_EVENT, WIN_IN_TRANSIT_EVENTS, 0); } if (!(tsp->uiflags & ACURSORON)) { tsp->uiflags |= ACURSORON; drawalphacursor(tsp); } break; case GFXCURSOR: if (tsp->uiflags & ACURSORON) { tsp->uiflags &= ~ACURSORON; removealphacursor(tsp); } if (!(tsp->uiflags & GCURSORON)) { tsp->uiflags |= GCURSORON; cursor_set(tsp->cursor, CURSOR_SHOW_CURSOR, FALSE, CURSOR_SHOW_CROSSHAIRS, TRUE, 0); window_set(tsp->canvas, WIN_CURSOR, tsp->cursor, WIN_CONSUME_PICK_EVENT, WIN_IN_TRANSIT_EVENTS, 0); } break; } tsp->cursormode = cmode;}voidtek_clearscreen(td) caddr_t td;{ register struct teksw *tsp; tsp = (struct teksw *) td; pw_writebackground(tsp->pwp, 0, 0, tsp->imagesize.x, tsp->imagesize.y, PIX_CLR); if (tsp->uiflags & ACURSORON) drawalphacursor(tsp);}voidtek_bell(td) caddr_t td;{ register struct teksw *tsp; tsp = (struct teksw *) td; window_bell(tsp->canvas);}voidtek_makecopy(td) caddr_t td;{ register struct teksw *tsp; char *cmd; FILE *copy; void (*s)(); extern FILE *popen(); extern char *getenv(); tsp = (struct teksw *) td; if (tsp->props != NULL) cmd = (char *)panel_get_value(tsp->copy_item); else cmd = getenv("TEKCOPY"); if (cmd == NULL || *cmd == '\0') cmd = DEFAULTCOPY; if ((copy = popen(cmd, "w")) == NULL) { confirm(tsp, "cannot fork copy command"); return; } window_set(tsp->canvas, WIN_CURSOR, &waitcursor, 0); if (pr_dump(tsp->pwp->pw_prretained, copy, NULL, RT_BYTE_ENCODED, 1)) { confirm(tsp, "copy command failed"); } pclose(copy); if (tsp->uiflags & PAGEFULL) { window_set(tsp->canvas, WIN_CURSOR, &stop_cursor, 0); } else { window_set(tsp->canvas, WIN_CURSOR, tsp->cursor, 0); }}voidtek_pagefull_on(td) caddr_t td;{ register struct teksw *tsp; tsp = (struct teksw *) td; tsp->uiflags |= PAGEFULL; notify_set_input_func(tsp, NOTIFY_FUNC_NULL, tsp->pty); window_set(tsp->canvas, WIN_CURSOR, &stop_cursor, 0);}voidtek_pagefull_off(td) caddr_t td;{ register struct teksw *tsp; tsp = (struct teksw *) td; tsp->uiflags &= ~PAGEFULL; tsp->uiflags |= RESTARTPTY; notify_set_input_func(tsp, teksw_pty_input, tsp->pty); window_set(tsp->canvas, WIN_CURSOR, tsp->cursor, 0);}/* * support routines */static voiddrawalphacursor(tsp) register struct teksw *tsp;{ tsp->alphacursorpos = tsp->curpos; tsp->alphacursorsize = tsp->curfont->pf_defaultsize; tsp->alphacursorpos.y += tsp->curfont->pf_char['A'].pc_home.y; pw_writebackground(tsp->pwp, tsp->alphacursorpos.x, tsp->alphacursorpos.y, tsp->alphacursorsize.x, tsp->alphacursorsize.y, PIX_NOT(PIX_DST));}static voidremovealphacursor(tsp) register struct teksw *tsp;{ pw_writebackground(tsp->pwp, tsp->alphacursorpos.x, tsp->alphacursorpos.y, tsp->alphacursorsize.x, tsp->alphacursorsize.y, PIX_NOT(PIX_DST));}/* * Tek line drawing routine. * Calculations are done in fixed point arithmetic. */#define HALF (1 << 9) /* 1/2 in fixed point */#define FIX(X) ((long)((X) << 10)) /* int to fixed pt */#define UNFIX(X) ((int)(((X) + HALF) >> 10)) /* fixed pt to int *//* * vector styles (out of the 4014 hardware manual) */#define DOT 3 /* line style dot in tekpts (guess) *//* * One pixel is subtracted from the on pattern beacause vector drawing includes * the end pixel. The off pattern is incremented for the same reason. */#define ON(X) FIX(((X) * DOT) - 1)#define OFF(X) FIX(((X) * DOT) + 1)static long pattern[5][5] = { 0, 0, 0, 0, 0, /* solid */ ON(1), OFF(1), ON(1), OFF(1), FIX(4 * DOT), /* dotted */ ON(5), OFF(1), ON(1), OFF(1), FIX(8 * DOT), /* dash dot */ ON(3), OFF(1), ON(3), OFF(1), FIX(8 * DOT), /* short dash */ ON(6), OFF(2), ON(6), OFF(2), FIX(16 * DOT) /* long dash */};#undef DOT#undef ON#undef OFFstatic long psx[4], psy[4]; /* pattern length vector */static long lsx, lsy; /* last segement remainder x,y */static int lstyle = 0;static int lx, ly;static long patrem; /* pattern remainder */static char lps;static char cont; /* continuation vector flag */static char width;static int rop;static struct pixwin *destpwp;static void texturedline();static void plotline();static void dot();static int length();static int isqrt();tek_line(tsp, x0, y0, x1, y1, op, w, style) register struct teksw *tsp; register int x0, y0, x1, y1; /* window coords */ int op; int w; /* line width */ int style;{ register int dx, dy; /* vector components */ rop = op | PIX_COLOR(-1); destpwp = tsp->pwp; cont = (style && lstyle == style && lx == x0 && ly == y0 && patrem); width = w; dx = x1 - x0; dy = y1 - y0; lstyle = style; lx = x1; ly = y1; if ((dx == 0) && (dy == 0)) { /* * single point */ if (cont) { register long pl; /* piece length */ register long *pp; register long segrem; pp = &pattern[style][0]; segrem = patrem; for (lps = 0; lps < 4; lps++) { pl = pp[lps]; if (segrem < pl) { break; } segrem -= pl; } if ((lps & 1) == 0) dot(x0, y0); } else { dot(x0, y0); } return (0); } if (style) { register long vecl; /* vector length */ register long pl; /* piece length */ register long *pp; register int i; /* * textured line * compute the x and y projections of the texture pattern * placed on the line */ vecl = length(dx, dy); /* make four part pattern cycle */ pp = &pattern[style][0]; for (i = 0; i < 4; i++) { pl = pp[i]; psx[i] = (dx * pl) / vecl; psy[i] = (dy * pl) / vecl; } if (cont) { register long segrem; segrem = patrem; for (lps = 0; lps < 4; lps++) { pl = pp[lps]; if (segrem < pl) { segrem = pl - segrem; break; } segrem -= pl; } lsx = (dx * segrem) / vecl; lsy = (dy * segrem) / vecl; patrem = (FIX(vecl) + patrem) % pp[4]; } else { patrem = FIX(vecl) % pp[4]; } } else { /* * solid line */ psx[0] = FIX(dx); psy[0] = FIX(dy); patrem = 0; } texturedline(x0, y0, x1, y1); return (0);}static voidtexturedline(x0, y0, x1, y1) int x0, y0, x1, y1;{ register long dx, dy; /* line length counters */ register long sx, sy; /* x, y segment length */ register long xb, yb, xe, ye; /* begin and end pts */ register int ps; /* current segment number */ xb = xe = FIX(x0); yb = ye = FIX(y0); dx = FIX(abs(x1 - x0)); dy = FIX(abs(y1 - y0)); if (cont) { sx = lsx; sy = lsy; ps = lps; } else { ps = 0; sx = psx[0]; sy = psy[0]; } while (dx >= abs(sx) && dy >= abs(sy)) { xe += sx; ye += sy; dx -= abs(sx); dy -= abs(sy); if ((ps & 1) == 0) { plotline(UNFIX(xb), UNFIX(yb), UNFIX(xe), UNFIX(ye)); } ps = (ps + 1) & 03; /* four part pattern cycle */ sx = psx[ps]; sy = psy[ps]; xb = xe; yb = ye; } if (dx != 0 || dy != 0) { /* * finish off segment */ if ((ps & 1) == 0) { plotline(UNFIX(xe), UNFIX(ye), x1, y1); } }}/* * Fat line end pixrect. */static short fat_end[] = {0x4000, 0xe000, 0x4000};mpr_static(fat_end_mpr, 3, 3, 1, fat_end);static voidplotline(x0, y0, x1, y1) int x0, y0, x1, y1;{ if (width) { register struct pr_pos *plp; register int rx0, ry0, rx1, ry1; register int dx, dy; rx0 = x0; ry0 = y0; rx1 = x1; ry1 = y1; pw_vector(destpwp, rx0, ry0, rx1, ry1, rop, 1); dx = rx1 - rx0; dy = ry1 - ry0; if (abs(dx) < abs(dy)) { pw_vector(destpwp, rx0+1, ry0, rx1+1, ry1, rop, 1); pw_vector(destpwp, rx0-1, ry0, rx1-1, ry1, rop, 1); } else { pw_vector(destpwp, rx0, ry0+1, rx1, ry1+1, rop, 1); pw_vector(destpwp, rx0, ry0-1, rx1, ry1-1, rop, 1); } pw_stencil(destpwp, rx0-1, ry0-1, 3, 3, rop, &fat_end_mpr, 0, 0, NULL, 0, 0); pw_stencil(destpwp, rx1-1, ry1-1, 3, 3, rop, &fat_end_mpr, 0, 0, NULL, 0, 0); } else { pw_vector(destpwp, x0, y0, x1, y1, rop, 1); }}/* * Fat dot pixrect. */static short fat_dot[] = {0xe000, 0xe000, 0xe000};mpr_static(fat_dot_mpr, 3, 3, 1, fat_dot);static voiddot(x0, y0) register short x0, y0;{ if (width) { pw_stencil(destpwp, x0-1, y0-1, 3, 3, rop, &fat_dot_mpr, 0, 0, NULL, 0, 0); } else { pw_rop(destpwp, x0, y0, 1, 1, rop, NULL, 0, 0); }}/* * Length and integer square root. */static intlength(dx, dy){ if (dx == 0) return (abs(dy)); if (dy == 0) return (abs(dx)); return (isqrt((dx * dx) + (dy * dy)));}static intisqrt(n) register int n;{ register int q, r, x2, x; register int t; if (n < 0) abort(); if (n < 2) return (n); /* or this case */ t = x = n; while (t >>= 2) x >>= 1; x++; while (1) { q = n / x; r = n % x; if (x <= q) { x2 = x + 2; if (q < x2 || q == x2 && r == 0) break; } x = (x + q) >> 1; } return (x);}#undef HALF#undef FIX#undef UNFIX#define scale(pp, fs, ts) \ (pp)->x = \ ( ((long)(pp)->x * (long)ts.x) + ((long)fs.x / 2) ) / (long)fs.x; \ (pp)->y = \ ( ((long)(pp)->y * (long)ts.y) + ((long)fs.y / 2) ) / (long)fs.y;static intinimage(tsp, x, y) register struct teksw *tsp; register int x, y;{ return (x >= WXMIN(tsp) && x < WXMAX(tsp) && y >= WYMIN(tsp) && y < WYMAX(tsp));}static voidimagetotek(tsp, posp) register struct teksw *tsp; struct pr_pos *posp;{ posp->x -= WXMIN(tsp); posp->y -= WYMIN(tsp); scale(posp, tsp->scalesize, teksize); posp->y = teksize.y - posp->y;}static voidtektoimage(tsp, posp) register struct teksw *tsp; struct pr_pos *posp;{ posp->y = teksize.y - posp->y; scale(posp, teksize, tsp->scalesize); posp->x += WXMIN(tsp); posp->y += WYMIN(tsp);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -