|
|
1.1 ! root 1: #include <X/mit-copyright.h> ! 2: ! 3: /* Copyright Massachusetts Institute of Technology 1986 */ ! 4: ! 5: #include <sys/types.h> ! 6: #include "../Xlib/Xlib.h" ! 7: #undef CURSOR ! 8: #include "../Xlib/Xkeyboard.h" ! 9: #include <stdio.h> ! 10: #include <errno.h> ! 11: #include "../X/vsinput.h" ! 12: #include "../X/Xdev.h" ! 13: ! 14: extern int errno, XFlush(); ! 15: char *Xalloc(), *Xrealloc(), *strcpy(); ! 16: ! 17: #define Xpixmap(p) ((Pixmap) p->data) ! 18: #define Xbitmap(b) ((Bitmap) b->data) ! 19: #define Xfinf(f) ((FontInfo *) f->data) ! 20: #define Xfont(f) (Xfinf(f)->id) ! 21: #define Xcursor(c) ((Cursor) c->data) ! 22: #define npix(p) (((p) << pixshift) | basepix) ! 23: #define opix(p) (((p) &~ basepix) >> pixshift) ! 24: #define nmask(m) ((m) << pixshift) ! 25: ! 26: static Window w, t, ot, tt; ! 27: static int extrapix; ! 28: static int pixplanes = 0; ! 29: static int pixshift = 0; ! 30: static int basepix = 0; ! 31: static int screen_height, screen_width; ! 32: static int tilex = 0; ! 33: static int tiley = 0; ! 34: static CLIP tileclip = {0, 0, 0, 0}; ! 35: static vsCursor mouse = {0, 0}; ! 36: static vsBox mbox = {0, 0, 0, 0}; ! 37: static int cursor_x, cursor_y; ! 38: static DEVICE *dev; ! 39: ! 40: /*ARGSUSED*/ ! 41: ProcessInput (ev) ! 42: vsEvent ev; ! 43: { ! 44: } ! 45: ! 46: /*ARGSUSED*/ ! 47: OpenDisplay (display) ! 48: char *display; /* display number */ ! 49: { ! 50: OpaqueFrame frame; ! 51: char def[32]; ! 52: char *option; ! 53: Color cdef; ! 54: ! 55: if (XOpenDisplay((char *) NULL) == NULL) { ! 56: errno = EINVAL; ! 57: return(-1); ! 58: } ! 59: if (option = XGetDefault("X", "BorderWidth")) ! 60: frame.bdrwidth = atoi(option); ! 61: else ! 62: frame.bdrwidth = 0; ! 63: if (frame.bdrwidth && DisplayCells() > 2 && ! 64: (option = XGetDefault("X", "Border")) && ! 65: XParseColor(option, &cdef) && ! 66: XGetHardwareColor(&cdef)) ! 67: frame.border = XMakeTile(cdef.pixel); ! 68: else ! 69: frame.border = BlackPixmap; ! 70: frame.background = NULL; ! 71: frame.x = 0; ! 72: frame.y = 0; ! 73: sprintf(def, "=%dx%d+0+0", ! 74: DisplayWidth() - (frame.bdrwidth << 1), ! 75: DisplayHeight() - (frame.bdrwidth << 1)); ! 76: w = XCreate("X", "X", "", def, &frame, 50, 50); ! 77: screen_height = frame.height; ! 78: screen_width = frame.width; ! 79: XMapWindow(w); ! 80: XSelectInput(w, KeyPressed|KeyReleased|ButtonPressed|ButtonReleased| ! 81: MouseMoved|EnterWindow|LeaveWindow); ! 82: t = XCreateTransparency(w, 0, 0, screen_width, screen_height); ! 83: ot = XCreateTransparency(w, 0, 0, screen_width, screen_height); ! 84: XTileAbsolute(ot); ! 85: tt = XCreateTransparency(ot, 0, 0, screen_width, screen_height); ! 86: XMapWindow(t); ! 87: XMapWindow(tt); ! 88: XMapWindow(ot); ! 89: return(dpyno()); ! 90: } ! 91: ! 92: InputReader () ! 93: { ! 94: XEvent xev; ! 95: vsEvent ev; ! 96: int nstate; ! 97: static int state = 0; ! 98: vsCursor ms; ! 99: ! 100: XPending(); ! 101: while (QLength()) { ! 102: XNextEvent(&xev); ! 103: switch (xev.type) { ! 104: case EnterWindow: ! 105: if (xev.subwindow) ! 106: continue; ! 107: case MouseMoved: ! 108: ms.x = ((XMouseMovedEvent *) (&xev))->x - cursor_x; ! 109: ms.y = ((XMouseMovedEvent *) (&xev))->y - cursor_y; ! 110: if ((ms.x != mouse.x || ms.y != mouse.y) && ! 111: ms.x >= 0 && ms.x < screen_width && ! 112: ms.y >= 0 && ms.y < screen_height) { ! 113: mouse = ms; ! 114: if (ms.y >= mbox.bottom || ms.y < mbox.top || ! 115: ms.x >= mbox.right || ms.x < mbox.left) { ! 116: mbox.bottom = 0; ! 117: Deal_with_movement(); ! 118: } ! 119: } ! 120: if (xev.type != EnterWindow) ! 121: continue; ! 122: ev.vse_time = ((XKeyOrButtonEvent *) (&xev))->time; ! 123: nstate = ((XEnterWindowEvent *) (&xev))->detail & ~ValueMask; ! 124: nstate ^= state; ! 125: ev.vse_direction = VSE_KBTUP; ! 126: ButtonTransition(&ev, nstate & state); ! 127: KeyTransition(&ev, nstate & state); ! 128: ev.vse_direction = VSE_KBTDOWN; ! 129: KeyTransition(&ev, nstate & ~state); ! 130: ButtonTransition(&ev, nstate & ~state); ! 131: continue; ! 132: case LeaveWindow: ! 133: state = ((XLeaveWindowEvent *) (&xev))->detail & ~ValueMask; ! 134: continue; ! 135: } ! 136: ev.vse_x = mouse.x; ! 137: ev.vse_y = mouse.y; ! 138: ev.vse_time = ((XKeyOrButtonEvent *) (&xev))->time; ! 139: ev.vse_key = ((XKeyOrButtonEvent *) (&xev))->detail & ValueMask; ! 140: switch (xev.type) { ! 141: case KeyPressed: ! 142: ev.vse_device = VSE_DKB; ! 143: ev.vse_direction = VSE_KBTDOWN; ! 144: break; ! 145: case KeyReleased: ! 146: ev.vse_device = VSE_DKB; ! 147: ev.vse_direction = VSE_KBTUP; ! 148: break; ! 149: case ButtonPressed: ! 150: ev.vse_device = VSE_MOUSE; ! 151: ev.vse_direction = VSE_KBTDOWN; ! 152: ev.vse_key = 2 - ev.vse_key; ! 153: break; ! 154: case ButtonReleased: ! 155: ev.vse_device = VSE_MOUSE; ! 156: ev.vse_direction = VSE_KBTUP; ! 157: ev.vse_key = 2 - ev.vse_key; ! 158: break; ! 159: } ! 160: Deal_with_input(&ev); ! 161: } ! 162: } ! 163: ! 164: KeyTransition (ev, bits) ! 165: register vsEvent *ev; ! 166: register int bits; ! 167: { ! 168: ev->vse_device = VSE_DKB; ! 169: if (bits & ControlMask) { ! 170: ev->vse_x = mouse.x; ! 171: ev->vse_y = mouse.y; ! 172: ev->vse_key = KC_CTRL; ! 173: Deal_with_input(ev); ! 174: } ! 175: if (bits & MetaMask) { ! 176: ev->vse_x = mouse.x; ! 177: ev->vse_y = mouse.y; ! 178: ev->vse_key = KC_META; ! 179: Deal_with_input(ev); ! 180: } ! 181: if (bits & ShiftMask) { ! 182: ev->vse_x = mouse.x; ! 183: ev->vse_y = mouse.y; ! 184: ev->vse_key = KC_SHIFT; ! 185: Deal_with_input(ev); ! 186: } ! 187: if (bits & ShiftLockMask) { ! 188: ev->vse_x = mouse.x; ! 189: ev->vse_y = mouse.y; ! 190: ev->vse_key = KC_LOCK; ! 191: Deal_with_input(ev); ! 192: } ! 193: } ! 194: ! 195: ButtonTransition (ev, bits) ! 196: register vsEvent *ev; ! 197: register int bits; ! 198: { ! 199: ev->vse_device = VSE_MOUSE; ! 200: if (bits & LeftMask) { ! 201: ev->vse_x = mouse.x; ! 202: ev->vse_y = mouse.y; ! 203: ev->vse_key = 2 - LeftButton; ! 204: Deal_with_input(ev); ! 205: } ! 206: if (bits & MiddleMask) { ! 207: ev->vse_x = mouse.x; ! 208: ev->vse_y = mouse.y; ! 209: ev->vse_key = 2 - MiddleButton; ! 210: Deal_with_input(ev); ! 211: } ! 212: if (bits & RightMask) { ! 213: ev->vse_x = mouse.x; ! 214: ev->vse_y = mouse.y; ! 215: ev->vse_key = 2 - RightButton; ! 216: Deal_with_input(ev); ! 217: } ! 218: } ! 219: ! 220: InitDisplay (info) ! 221: DEVICE *info; /* device data */ ! 222: { ! 223: char *option; ! 224: int planes; ! 225: static vsEventQueue queue = {NULL, 0, 0, 0}; ! 226: ! 227: dev = info; ! 228: info->id = XDEV_XNEST; ! 229: info->width = screen_width; ! 230: info->height = screen_height; ! 231: info->planes = DisplayPlanes(); ! 232: info->entries = 0; ! 233: pixplanes = 0; ! 234: if (DisplayCells() > 2 && ! 235: (option = XGetDefault("X", "CellExponent")) && ! 236: (pixplanes = atoi(option)) && ! 237: XGetColorCells(0, 1, 0, &planes, &extrapix)) { ! 238: while (pixplanes && ! 239: !XGetColorCells(1, 1, pixplanes, &planes, &basepix)) ! 240: pixplanes--; ! 241: if (pixplanes) { ! 242: info->entries = 1 << pixplanes; ! 243: while (!(planes & 1)) { ! 244: pixshift++; ! 245: planes >>= 1; ! 246: } ! 247: } else ! 248: XFreeColors(&extrapix, 1, 0); ! 249: } ! 250: info->mouse = &mouse; ! 251: info->mbox = &mbox; ! 252: info->queue = &queue; ! 253: Define_input_handler(InputReader); ! 254: Define_block_handler(XFlush); ! 255: return(0); ! 256: } ! 257: ! 258: DisplayDead () ! 259: { ! 260: return(0); ! 261: } ! 262: ! 263: InitMouse () ! 264: { ! 265: } ! 266: ! 267: caddr_t AllocateSpace (bytes) ! 268: int bytes; /* number of bytes to allocate */ ! 269: { ! 270: static char *buf = NULL; ! 271: static int buflen = 0; ! 272: ! 273: if (bytes > buflen) { ! 274: free(buf); ! 275: buf = Xalloc((bytes + 0xff) &~ 0xff); ! 276: } ! 277: return(buf); ! 278: } ! 279: ! 280: PixFill (srcpix, xymask, dstx, dsty, width, height, clips, clipcount, ! 281: func, zmask) ! 282: int srcpix; /* source pixel */ ! 283: BITMAP *xymask; /* source mask or NULL */ ! 284: int dstx, dsty; /* destination */ ! 285: int width, height; ! 286: register CLIP *clips; /* clipping rectangles */ ! 287: int clipcount; /* count of rectangles */ ! 288: int func; /* GX display function */ ! 289: int zmask; /* plane mask */ ! 290: { ! 291: srcpix = npix(srcpix); ! 292: zmask = nmask(zmask); ! 293: for (; --clipcount >= 0; clips++) { ! 294: SetClip(clips); ! 295: XPixFill(t, dstx - clips->left, dsty - clips->top, width, height, ! 296: srcpix, xymask ? Xbitmap(xymask) : NULL, func, zmask); ! 297: } ! 298: } ! 299: ! 300: TileFill (tile, xoff, yoff, xymask, dstx, dsty, width, height, ! 301: clips, clipcount, func, zmask) ! 302: PIXMAP *tile; /* source tile */ ! 303: int xoff, yoff; /* tile origin */ ! 304: BITMAP *xymask; /* source mask or NULL */ ! 305: int dstx, dsty; /* destination */ ! 306: int width, height; ! 307: register CLIP *clips; /* clipping rectangles */ ! 308: int clipcount; /* count of rectangles */ ! 309: int func; /* GX display function */ ! 310: int zmask; /* plane mask */ ! 311: { ! 312: zmask = nmask(zmask); ! 313: SetTileOrigin(tile, xoff, yoff); ! 314: for (; --clipcount >= 0; clips++) { ! 315: SetTileClip(clips); ! 316: XTileFill(tt, dstx - clips->left, dsty - clips->top, width, height, ! 317: Xpixmap(tile), xymask ? Xbitmap(xymask) : NULL, ! 318: func, zmask); ! 319: } ! 320: } ! 321: ! 322: int StippleFill (srcpix, xoff, yoff, stipmask, dstx, dsty, width, height, ! 323: clips, clipcount, func, zmask) ! 324: int srcpix; /* source pixel */ ! 325: int xoff, yoff; /* stipple origin */ ! 326: BITMAP *stipmask; /* stipple mask */ ! 327: int dstx, dsty; /* destination */ ! 328: int width, height; ! 329: CLIP *clips; /* clipping rectangles */ ! 330: int clipcount; ! 331: int func; /* GX display function */ ! 332: int zmask; /* plane mask */ ! 333: { ! 334: return (1); ! 335: } ! 336: PixmapPut (src, srcx, srcy, width, height, dstx, dsty, clips, clipcount, ! 337: func, zmask) ! 338: PIXMAP *src; /* source */ ! 339: int srcx, srcy; /* region of source */ ! 340: int width, height; ! 341: int dstx, dsty; /* destination */ ! 342: register CLIP *clips; /* clipping rectangles */ ! 343: int clipcount; /* count of rectangles */ ! 344: int func; /* GX display function */ ! 345: int zmask; /* plane mask */ ! 346: { ! 347: zmask = nmask(zmask); ! 348: for (; --clipcount >= 0; clips++) { ! 349: SetClip(clips); ! 350: XPixmapPut(t, srcx, srcy, dstx - clips->left, dsty - clips->top, ! 351: width, height, Xpixmap(src), func, zmask); ! 352: } ! 353: } ! 354: ! 355: PixmapBitsPut (width, height, format, data, xymask, dstx, dsty, ! 356: clips, clipcount, func, zmask) ! 357: int width; /* source width */ ! 358: int height; /* source height */ ! 359: int format; /* 0: XY-format, 1: Z-format */ ! 360: char *data; /* source data */ ! 361: BITMAP *xymask; /* source mask or NULL */ ! 362: int dstx, dsty; /* destination */ ! 363: register CLIP *clips; /* clipping rectangles */ ! 364: int clipcount; /* count of rectangles */ ! 365: int func; /* GX display function */ ! 366: int zmask; /* plane mask */ ! 367: { ! 368: ToPixmap(width, height, format, data); ! 369: zmask = nmask(zmask); ! 370: for (; --clipcount >= 0; clips++) { ! 371: SetClip(clips); ! 372: if (format == XYFormat) ! 373: XPixmapBitsPutXY(t, dstx - clips->left, dsty - clips->top, ! 374: width, height, data, ! 375: xymask ? Xbitmap(xymask) : NULL, func, zmask); ! 376: else { ! 377: XPixmapBitsPutZ(t, dstx - clips->left, dsty - clips->top, ! 378: width, height, data, ! 379: xymask ? Xbitmap(xymask) : NULL, func, zmask); ! 380: } ! 381: } ! 382: } ! 383: ! 384: BitmapBitsPut (width, height, data, fore, back, xymask, dstx, dsty, ! 385: clips, clipcount, func, zmask) ! 386: int width; /* source width */ ! 387: int height; /* source height */ ! 388: char *data; /* source data */ ! 389: int fore; /* foreground source pixel */ ! 390: int back; /* background source pixel */ ! 391: BITMAP *xymask; /* source mask or NULL */ ! 392: int dstx, dsty; /* destination */ ! 393: register CLIP *clips; /* clipping rectangles */ ! 394: int clipcount; /* count of rectangles */ ! 395: int func; /* GX display function */ ! 396: int zmask; /* plane mask */ ! 397: { ! 398: fore = npix(fore); ! 399: back = npix(back); ! 400: zmask = nmask(zmask); ! 401: for (; --clipcount >= 0; clips++) { ! 402: SetClip(clips); ! 403: XBitmapBitsPut(t, dstx - clips->left, dsty - clips->top, ! 404: width, height, data, fore, back, ! 405: xymask ? Xbitmap(xymask) : NULL, func, zmask); ! 406: } ! 407: } ! 408: ! 409: CopyArea (srcx, srcy, width, height, dstx, dsty, clips, clipcount, func, zmask) ! 410: int srcx, srcy; /* source */ ! 411: int width, height; ! 412: int dstx, dsty; /* destination */ ! 413: register CLIP *clips; /* clipping rectangles */ ! 414: int clipcount; /* count of rectangles */ ! 415: int func; /* GX display function */ ! 416: int zmask; /* plane mask */ ! 417: { ! 418: int dstr, dstb, left, top; ! 419: ! 420: dstr = dstx + width; ! 421: dstb = dsty + height; ! 422: srcx -= dstx; ! 423: srcy -= dsty; ! 424: for (; --clipcount >= 0; clips++) { ! 425: left = clips->left; ! 426: if (left < dstx) ! 427: left = dstx; ! 428: width = clips->left + clips->width; ! 429: if (width > dstr) ! 430: width = dstr; ! 431: width -= left; ! 432: top = clips->top; ! 433: if (top < dsty) ! 434: top = dsty; ! 435: height = clips->top + clips->height; ! 436: if (height > dstb) ! 437: height = dstb; ! 438: height -= top; ! 439: if (width > 0 && height > 0) ! 440: XCopyArea(w, srcx + left, srcy + top, left, top, ! 441: width, height, func, zmask); ! 442: } ! 443: } ! 444: ! 445: PrintText (string, strlen, font, fore, back, charpad, spacepad, dstx, dsty, ! 446: clips, clipcount, func, zmask) ! 447: char *string; /* character string */ ! 448: int strlen; /* string length */ ! 449: FONT *font; /* source font */ ! 450: int fore; /* foreground source pixel */ ! 451: int back; /* background source pixel */ ! 452: int charpad; /* inter-character pad */ ! 453: int spacepad; /* space-character pad */ ! 454: int dstx, dsty; /* destination */ ! 455: register CLIP *clips; /* clipping rectangles */ ! 456: int clipcount; /* count of rectangles */ ! 457: int func; /* GX display function */ ! 458: int zmask; /* plane mask */ ! 459: { ! 460: fore = npix(fore); ! 461: back = npix(back); ! 462: zmask = nmask(zmask); ! 463: for (; --clipcount >= 0; clips++) { ! 464: SetClip(clips); ! 465: XTextPad(t, dstx - clips->left, dsty - clips->top, string, strlen, ! 466: Xfont(font), charpad, spacepad, fore, back, func, zmask); ! 467: } ! 468: } ! 469: ! 470: PrintTextMask (string, strlen, font, srcpix, charpad, spacepad, dstx, dsty, ! 471: clips, clipcount, func, zmask) ! 472: char *string; /* character string */ ! 473: int strlen; /* string length */ ! 474: FONT *font; /* font mask */ ! 475: int srcpix; /* source pixel */ ! 476: int charpad; /* inter-character pad */ ! 477: int spacepad; /* space-character pad */ ! 478: int dstx, dsty; /* destination */ ! 479: register CLIP *clips; /* clipping rectangles */ ! 480: int clipcount; /* count of rectangles */ ! 481: int func; /* GX display function */ ! 482: int zmask; /* plane mask */ ! 483: { ! 484: srcpix = npix(srcpix); ! 485: zmask = nmask(zmask); ! 486: for (; --clipcount >= 0; clips++) { ! 487: SetClip(clips); ! 488: XTextMaskPad(t, dstx - clips->left, dsty - clips->top, string, ! 489: strlen, Xfont(font), charpad, spacepad, srcpix, ! 490: func, zmask); ! 491: } ! 492: } ! 493: ! 494: DrawCurve (verts, vertcount, xbase, ybase, srcpix, altpix, mode, ! 495: bwidth, bheight, pat, patlen, patmul, clips, clipcount, func, zmask) ! 496: Vertex *verts; /* vertexes */ ! 497: int vertcount; /* vertex count */ ! 498: int xbase, ybase; /* draw origin */ ! 499: int srcpix; /* source pixel * ! 500: int altpix; /* alternate source pixel */ ! 501: int mode; /* 0: solid, 1: dashed, 2: patterned */ ! 502: int bwidth; /* brush width */ ! 503: int bheight; /* brush height */ ! 504: int pat; /* pattern */ ! 505: int patlen; /* pattern length */ ! 506: int patmul; /* pattern repeat count */ ! 507: register CLIP *clips; /* clipping rectangles */ ! 508: int clipcount; /* count of rectangles */ ! 509: int func; /* GX display function */ ! 510: int zmask; /* plane mask */ ! 511: { ! 512: srcpix = npix(srcpix); ! 513: altpix = npix(altpix); ! 514: zmask = nmask(zmask); ! 515: for (; --clipcount >= 0; clips++) { ! 516: SetClip(clips); ! 517: PathOffsets(verts, vertcount, ! 518: xbase - clips->left, ybase - clips->top); ! 519: xbase = clips->left; ! 520: ybase = clips->top; ! 521: switch (mode) { ! 522: case DrawSolidLine: ! 523: XDraw(t, verts, vertcount, bwidth, bheight, srcpix, ! 524: func, zmask); ! 525: break; ! 526: case DrawDashedLine: ! 527: XDrawDashed(t, verts, vertcount, bwidth, bheight, srcpix, ! 528: XMakePattern(pat, patlen, patmul), func, zmask); ! 529: break; ! 530: case DrawPatternedLine: ! 531: XDrawPatterned(t, verts, vertcount, bwidth, bheight, srcpix, ! 532: altpix, XMakePattern(pat, patlen, patmul), ! 533: func, zmask); ! 534: break; ! 535: } ! 536: } ! 537: } ! 538: ! 539: DrawFilled (verts, vertcount, xbase, ybase, srcpix, tile, xoff, yoff, ! 540: clips, clipcount, func, zmask) ! 541: Vertex *verts; /* vertexes */ ! 542: int vertcount; /* vertex count */ ! 543: int xbase, ybase; /* draw origin */ ! 544: int srcpix; /* source pixel */ ! 545: PIXMAP *tile; /* optional tile or NULL */ ! 546: int xoff, yoff; /* tile origin */ ! 547: register CLIP *clips; /* clipping rectangles */ ! 548: int clipcount; /* count of rectangles */ ! 549: int func; /* GX display function */ ! 550: int zmask; /* plane mask */ ! 551: { ! 552: if (tile) ! 553: SetTileOrigin(tile, xoff, yoff); ! 554: else ! 555: srcpix = npix(srcpix); ! 556: zmask = nmask(zmask); ! 557: for (; --clipcount >= 0; clips++) { ! 558: PathOffsets(verts, vertcount, ! 559: xbase - clips->left, ybase - clips->top); ! 560: xbase = clips->left; ! 561: ybase = clips->top; ! 562: if (tile) { ! 563: SetTileClip(clips); ! 564: XDrawTiled(tt, verts, vertcount, Xpixmap(tile), func, zmask); ! 565: } else { ! 566: SetClip(clips); ! 567: XDrawFilled(t, verts, vertcount, srcpix, func, zmask); ! 568: } ! 569: } ! 570: } ! 571: ! 572: PathOffsets (verts, vertcount, xoff, yoff) ! 573: register Vertex *verts; ! 574: register int vertcount, xoff, yoff; ! 575: { ! 576: for (; --vertcount >= 0; verts++) { ! 577: if (!(verts->flags & VertexRelative)) { ! 578: verts->x += xoff; ! 579: verts->y += yoff; ! 580: } ! 581: } ! 582: } ! 583: ! 584: SetClip (clip) ! 585: register CLIP *clip; ! 586: { ! 587: static CLIP normclip = {0, 0, 0, 0}; ! 588: ! 589: if (clip->left != normclip.left || clip->top != normclip.top || ! 590: clip->width != normclip.width || clip->height != normclip.height) { ! 591: XConfigureWindow(t, clip->left, clip->top, ! 592: clip->width, clip->height); ! 593: normclip = *clip; ! 594: } ! 595: } ! 596: ! 597: SetTileClip (clip) ! 598: register CLIP *clip; ! 599: { ! 600: if (clip->left != tileclip.left || clip->top != tileclip.top || ! 601: clip->width != tileclip.width || clip->height != tileclip.height) { ! 602: XConfigureWindow(tt, clip->left - tilex, clip->top - tiley, ! 603: clip->width, clip->height); ! 604: tileclip = *clip; ! 605: } ! 606: } ! 607: ! 608: SetTileOrigin (tile, xoff, yoff) ! 609: register PIXMAP *tile; ! 610: register int xoff, yoff; ! 611: { ! 612: if (tile->width) { ! 613: xoff %= tile->width; ! 614: if (xoff) ! 615: xoff -= tile->width; ! 616: yoff %= tile->height; ! 617: if (yoff) ! 618: yoff -= tile->height; ! 619: if (xoff != tilex || yoff != tiley) { ! 620: XConfigureWindow(ot, xoff, yoff, ! 621: screen_width - xoff, screen_height - yoff); ! 622: tileclip.left += (xoff - tilex); ! 623: tileclip.top += (yoff - tiley); ! 624: tilex = xoff; ! 625: tiley = yoff; ! 626: } ! 627: } ! 628: } ! 629: ! 630: PIXMAP *PixmapSave (srcx, srcy, width, height) ! 631: int srcx, srcy; /* source */ ! 632: int width, height; ! 633: { ! 634: Pixmap pix; ! 635: PIXMAP *pm; ! 636: ! 637: pix = XPixmapSave(w, srcx, srcy, width, height); ! 638: if (pix == NULL) ! 639: return(NULL); ! 640: pm = (PIXMAP *) Xalloc (sizeof (PIXMAP)); ! 641: pm->width = width; ! 642: pm->height = height; ! 643: pm->refcnt = 1; ! 644: pm->data = (caddr_t) pix; ! 645: IsTile(pm); ! 646: return(pm); ! 647: } ! 648: ! 649: PixmapGet (srcx, srcy, width, height, client, format, swapit) ! 650: int srcx, srcy; /* source */ ! 651: int width, height; ! 652: int client; /* file desc to write to */ ! 653: int format; /* 0: XY-format, 1: Z-format */ ! 654: int swapit; /* 1: swap shorts */ ! 655: { ! 656: int count; ! 657: caddr_t data; ! 658: ! 659: if (format == XYFormat) { ! 660: count = (XYPixmapSize(width, height, dev->planes) + 3) & ~3; ! 661: data = Xalloc(count); ! 662: if (XPixmapGetXY(w, srcx, srcy, width, height, data) == NULL) ! 663: return; ! 664: } else { ! 665: if (dev->planes > 8) ! 666: count = WZPixmapSize(width, height); ! 667: else { ! 668: count = BZPixmapSize(width, height); ! 669: swapit = 0; ! 670: } ! 671: count = (count + 3) & ~3; ! 672: data = Xalloc(count); ! 673: if (XPixmapGetZ(w, srcx, srcy, width, height, data) == NULL) ! 674: return; ! 675: } ! 676: FromPixmap(width, height, format, data); ! 677: if (swapit) ! 678: Swap_shorts(data, count >> 1); ! 679: Write(client, data, count); ! 680: free(data); ! 681: } ! 682: ! 683: ResolveColor (red, green, blue) ! 684: unsigned short *red, *green, *blue; /* update in place */ ! 685: { ! 686: Color def; ! 687: ! 688: if (dev->entries) { ! 689: def.pixel = extrapix; ! 690: def.red = *red; ! 691: def.green = *green; ! 692: def.blue = *blue; ! 693: XStoreColor(&def); ! 694: XQueryColor(&def); ! 695: *red = def.red; ! 696: *green = def.green; ! 697: *blue = def.blue; ! 698: } ! 699: } ! 700: ! 701: StoreColors (count, entries) ! 702: int count; /* number of entries */ ! 703: register ColorDef *entries; ! 704: { ! 705: register Color *ptr; ! 706: register int n; ! 707: static Color *ents = NULL; ! 708: static entcnt = 0; ! 709: ! 710: if (count > entcnt) { ! 711: free ((caddr_t) ents); ! 712: ents = (Color *) Xalloc(count * sizeof(Color)); ! 713: entcnt = count; ! 714: } ! 715: for (ptr = ents, n = count; --n >= 0; entries++, ptr++) { ! 716: ptr->pixel = npix(entries->pixel); ! 717: ptr->red = entries->red; ! 718: ptr->green = entries->green; ! 719: ptr->blue = entries->blue; ! 720: } ! 721: XStoreColors(count, ents); ! 722: } ! 723: ! 724: FONT *GetFont (name) ! 725: char *name; /* font or file name */ ! 726: { ! 727: register FontInfo *info; ! 728: register FONT *fd; ! 729: char *fname; ! 730: ! 731: info = XOpenFont(name); ! 732: if (info == NULL) { ! 733: errno = EINVAL; ! 734: return(NULL); ! 735: } ! 736: fd = (FONT *) Xalloc(sizeof(FONT)); ! 737: fname = Xalloc(strlen(name) + 1); ! 738: strcpy(fname, name); ! 739: fd->name = fname; ! 740: fd->first = info->firstchar; ! 741: fd->last = info->lastchar; ! 742: fd->space = ' '; ! 743: fd->height = info->height; ! 744: fd->avg_width = info->width; ! 745: fd->fixed = info->fixedwidth; ! 746: fd->base = info->baseline; ! 747: fd->refcnt = 1; ! 748: fd->data = (caddr_t) info; ! 749: return(fd); ! 750: } ! 751: ! 752: FreeFont (font) ! 753: FONT *font; ! 754: { ! 755: XCloseFont(Xfinf(font)); ! 756: free(font->name); ! 757: free((caddr_t) font); ! 758: } ! 759: ! 760: CharWidth (c, font) ! 761: unsigned c; /* character */ ! 762: register FONT *font; /* font */ ! 763: { ! 764: if (c < font->first || c > font->last) ! 765: return(0); ! 766: else if (font->fixed) ! 767: return(font->avg_width); ! 768: else ! 769: return(Xfinf(font)->widths[c - font->first]); ! 770: } ! 771: ! 772: TextWidth (string, strlen, spacepad, font) ! 773: char *string; /* character string */ ! 774: int strlen; /* string length */ ! 775: int spacepad; /* space-character pad */ ! 776: register FONT *font; /* font */ ! 777: { ! 778: register u_char *strptr = (u_char *) string; ! 779: short c; ! 780: register short *widths; ! 781: int width = 0; ! 782: ! 783: if (font->fixed) { ! 784: width = strlen * font->avg_width; ! 785: if (spacepad) { ! 786: while (--strlen >= 0) ! 787: if (*strptr++ == font->space) ! 788: width += spacepad; ! 789: } ! 790: } else { ! 791: widths = Xfinf(font)->widths; ! 792: while (--strlen >= 0) { ! 793: c = *strptr++; ! 794: if (c >= font->first && c <= font->last) { ! 795: if (c == font->space) ! 796: width += spacepad; ! 797: width += widths[c - font->first]; ! 798: } ! 799: } ! 800: } ! 801: return (width); ! 802: } ! 803: ! 804: BITMAP *StoreBitmap (width, height, data) ! 805: int width; /* bitmap width */ ! 806: int height; /* bitmap height */ ! 807: char *data; /* bitmap data */ ! 808: { ! 809: Bitmap bitmap; ! 810: register BITMAP *bm; ! 811: ! 812: bitmap = XStoreBitmap(width, height, data); ! 813: if (bitmap == NULL) ! 814: return(NULL); ! 815: bm = (BITMAP *) Xalloc(sizeof(BITMAP)); ! 816: bm->width = width; ! 817: bm->height = height; ! 818: bm->refcnt = 1; ! 819: bm->data = (caddr_t) bitmap; ! 820: return(bm); ! 821: } ! 822: ! 823: FreeBitmap (bitmap) ! 824: BITMAP *bitmap; ! 825: { ! 826: XFreeBitmap(Xbitmap(bitmap)); ! 827: free((caddr_t) bitmap); ! 828: } ! 829: ! 830: BITMAP *CharBitmap (c, font) ! 831: unsigned c; /* character */ ! 832: register FONT *font; /* font */ ! 833: { ! 834: Bitmap bitmap; ! 835: register BITMAP *bm; ! 836: ! 837: bitmap = XCharBitmap(Xfont(font), (int) c); ! 838: if (bitmap == NULL) ! 839: return(NULL); ! 840: bm = (BITMAP *) Xalloc(sizeof(BITMAP)); ! 841: bm->width = CharWidth(c, font); ! 842: bm->height = Xfinf(font)->height; ! 843: bm->refcnt = 1; ! 844: bm->data = (caddr_t) bitmap; ! 845: return(bm); ! 846: } ! 847: ! 848: PIXMAP *StorePixmap (width, height, format, data) ! 849: int width; /* pixmap width */ ! 850: int height; /* pixmap height */ ! 851: int format; /* 0: XY-format, 1: Z-format */ ! 852: char *data; /* pixmap data */ ! 853: { ! 854: Pixmap pix; ! 855: register PIXMAP *pm; ! 856: ! 857: ToPixmap(width, height, format, data); ! 858: if (format == XYFormat) ! 859: pix = XStorePixmapXY(width, height, data); ! 860: else ! 861: pix = XStorePixmapZ(width, height, data); ! 862: if (pix == NULL) ! 863: return(NULL); ! 864: pm = (PIXMAP *) Xalloc (sizeof (PIXMAP)); ! 865: pm->width = width; ! 866: pm->height = height; ! 867: pm->refcnt = 1; ! 868: pm->data = (caddr_t) pix; ! 869: IsTile(pm); ! 870: return(pm); ! 871: } ! 872: ! 873: FreePixmap (pixmap) ! 874: PIXMAP *pixmap; ! 875: { ! 876: XFreePixmap(Xpixmap(pixmap)); ! 877: free((caddr_t) pixmap); ! 878: } ! 879: ! 880: ToPixmap (width, height, format, data) ! 881: int width, height, format; ! 882: char *data; ! 883: { ! 884: register int n; ! 885: int shift; ! 886: register u_short *sptr; ! 887: register u_char *cptr; ! 888: register char *ptr; ! 889: ! 890: if (dev->entries == 0) ! 891: return; ! 892: if (format == XYFormat) { ! 893: n = BitmapSize(width, height); ! 894: if (pixshift) { ! 895: ptr = data + XYPixmapSize(width, height, dev->planes); ! 896: shift = XYPixmapSize(width, height, pixplanes); ! 897: bcopy(ptr - shift, ! 898: ptr - (shift + XYPixmapSize(width, height, pixshift)), ! 899: shift); ! 900: for (shift = 0, ptr -= n; ! 901: shift < pixshift; ! 902: shift++, ptr -= n) { ! 903: if (basepix & (1 << shift)) ! 904: AllOnes(ptr, width, height); ! 905: else ! 906: bzero(ptr, n); ! 907: } ! 908: } ! 909: for (shift = dev->planes, ptr = data; ! 910: --shift >= pixshift + pixplanes; ! 911: ptr += n) { ! 912: if (basepix & (1 << shift)) ! 913: AllOnes(ptr, width, height); ! 914: } ! 915: } else if (dev->planes > 8) { ! 916: for (n = WZPixmapSize(width, height) >> 1, sptr = (u_short *) data; ! 917: --n >= 0; ! 918: sptr++) ! 919: *sptr = npix(*sptr); ! 920: } else { ! 921: for (n = BZPixmapSize(width, height), cptr = (u_char *) data; ! 922: --n >= 0; ! 923: cptr++) ! 924: *cptr = npix(*cptr); ! 925: } ! 926: } ! 927: ! 928: AllOnes (data, width, height) ! 929: register char *data; ! 930: int width, height; ! 931: { ! 932: register int n, cnt; ! 933: register char *ptr; ! 934: ! 935: n = BitmapSize(width, 1); ! 936: for (ptr = data, cnt = n; --cnt >= 0; ) ! 937: *ptr++ = ~0; ! 938: for (ptr = data + n, cnt = height; --cnt > 0; ptr += n) ! 939: bcopy(data, ptr, n); ! 940: } ! 941: ! 942: FromPixmap (width, height, format, data) ! 943: int width, height, format; ! 944: register char *data; ! 945: { ! 946: register int n; ! 947: register u_short *sptr; ! 948: register u_char *cptr; ! 949: register char *ptr; ! 950: int cnt, shift; ! 951: ! 952: if (dev->entries == 0) ! 953: return; ! 954: if (format == XYFormat) { ! 955: if (pixshift) { ! 956: cnt = BitmapSize(width, height); ! 957: shift = XYPixmapSize(width, height, pixshift); ! 958: for (ptr = data + XYPixmapSize(width, height, dev->planes) - cnt, ! 959: n = pixshift; ! 960: --n >= 0; ! 961: ptr -= cnt) ! 962: bcopy(ptr - shift, ptr, cnt); ! 963: } ! 964: bzero(data, XYPixmapSize(width, height, dev->planes - pixplanes)); ! 965: } else if (dev->planes > 8) { ! 966: for (n = WZPixmapSize(width, height) >> 1, sptr = (u_short *) data; ! 967: --n >= 0; ! 968: sptr++) ! 969: *sptr = opix(*sptr); ! 970: } else { ! 971: for (n = BZPixmapSize(width, height), cptr = (u_char *) data; ! 972: --n >= 0; ! 973: cptr++) ! 974: *cptr = opix(*cptr); ! 975: } ! 976: } ! 977: ! 978: PIXMAP *MakePixmap (xymask, fore, back) ! 979: BITMAP *xymask; /* mask or NULL */ ! 980: int fore; /* foreground pixel */ ! 981: int back; /* background pixel */ ! 982: { ! 983: Pixmap pix; ! 984: register PIXMAP *pm; ! 985: ! 986: pix = XMakePixmap(xymask ? Xbitmap(xymask) : NULL, ! 987: npix(fore), npix(back)); ! 988: if (pix == NULL) ! 989: return(NULL); ! 990: pm = (PIXMAP *) Xalloc (sizeof (PIXMAP)); ! 991: pm->refcnt = 1; ! 992: pm->data = (caddr_t) pix; ! 993: if (xymask) { ! 994: pm->width = xymask->width; ! 995: pm->height = xymask->height; ! 996: IsTile(pm); ! 997: } else { ! 998: pm->width = 0; ! 999: pm->height = 0; ! 1000: pm->tile = 1; ! 1001: } ! 1002: return(pm); ! 1003: } ! 1004: ! 1005: IsTile (pm) ! 1006: PIXMAP *pm; ! 1007: { ! 1008: int width, height; ! 1009: ! 1010: XQueryTileShape(pm->width, pm->height, &width, &height); ! 1011: if (pm->width == width && pm->height == height) ! 1012: pm->tile = 1; ! 1013: else ! 1014: pm->tile = 0; ! 1015: } ! 1016: ! 1017: QueryShape (shape, width, height) ! 1018: int shape; /* 0: cursor, 1: tile, 2: brush */ ! 1019: short *width, *height; /* update in place */ ! 1020: { ! 1021: int rwidth, rheight; ! 1022: ! 1023: switch (shape) { ! 1024: case CursorShape: ! 1025: XQueryCursorShape(*width, *height, &rwidth, &rheight); ! 1026: break; ! 1027: case TileShape: ! 1028: XQueryTileShape(*width, *height, &rwidth, &rheight); ! 1029: break; ! 1030: case BrushShape: ! 1031: XQueryBrushShape(*width, *height, &rwidth, &rheight); ! 1032: break; ! 1033: } ! 1034: *width = rwidth; ! 1035: *height = rheight; ! 1036: } ! 1037: ! 1038: CURSOR *StoreCursor (func, image, fore, back, mask, xoff, yoff) ! 1039: int func; /* GX display function */ ! 1040: BITMAP *image; /* cursor image */ ! 1041: int fore; /* foreground pixel */ ! 1042: int back; /* background pixel */ ! 1043: BITMAP *mask; /* cursor mask or NULL */ ! 1044: int xoff, yoff; /* tip */ ! 1045: { ! 1046: Cursor cursor; ! 1047: register CURSOR *cr; ! 1048: int width, height; ! 1049: ! 1050: cursor = XStoreCursor(Xbitmap(image), mask ? Xbitmap(mask) : NULL, ! 1051: xoff, yoff, npix(fore), npix(back), func); ! 1052: if (cursor == NULL) ! 1053: return(NULL); ! 1054: XQueryCursorShape(image->width, image->height, &width, &height); ! 1055: cr = (CURSOR *) Xalloc(sizeof(CURSOR)); ! 1056: cr->width = width; ! 1057: cr->height = height; ! 1058: cr->xoff = xoff; ! 1059: cr->yoff = yoff; ! 1060: cr->xmin = xoff; ! 1061: cr->ymin = yoff; ! 1062: cr->xmax = screen_width - (width - xoff); ! 1063: cr->ymax = screen_height - (height - yoff); ! 1064: cr->refcnt = 1; ! 1065: cr->data = (caddr_t) cursor; ! 1066: return(cr); ! 1067: } ! 1068: ! 1069: FreeCursor (cursor) ! 1070: CURSOR *cursor; ! 1071: { ! 1072: XFreeCursor(Xcursor(cursor)); ! 1073: free((caddr_t) cursor); ! 1074: } ! 1075: ! 1076: LoadCursor (cursor) ! 1077: CURSOR *cursor; ! 1078: { ! 1079: if (cursor->xoff != cursor_x || cursor->yoff != cursor_y) { ! 1080: XCondWarpMouse(w, mouse.x + cursor->xoff, mouse.y + cursor->yoff, ! 1081: w, mouse.x + cursor_x, mouse.y + cursor_y, 1, 1); ! 1082: cursor_x = cursor->xoff; ! 1083: cursor_y = cursor->yoff; ! 1084: } ! 1085: XDefineCursor(w, Xcursor(cursor)); ! 1086: } ! 1087: ! 1088: /*ARGSUSED*/ ! 1089: SetMouseCharacteristics (threshold, acceleration) ! 1090: int threshold, acceleration; ! 1091: { ! 1092: } ! 1093: ! 1094: SetCursorPosition (pos) ! 1095: vsCursor *pos; ! 1096: { ! 1097: XCondWarpMouse(w, pos->x + cursor_x, pos->y + cursor_y, w, 0, 0, 0, 0); ! 1098: mouse = *pos; ! 1099: } ! 1100: ! 1101: /*ARGSUSED*/ ! 1102: SetAutoRepeat (onoff) ! 1103: int onoff; /* 0: off, 1: on */ ! 1104: { ! 1105: } ! 1106: ! 1107: /*ARGSUSED*/ ! 1108: SetKeyClick (volume) ! 1109: int volume; /* 0: off, 1-8: on */ ! 1110: { ! 1111: } ! 1112: ! 1113: SoundBell (volume) ! 1114: int volume; /* 0-7 */ ! 1115: { ! 1116: XFeep(volume); ! 1117: } ! 1118: ! 1119: /*ARGSUSED*/ ! 1120: SetLockLED (onoff) ! 1121: int onoff; /* 0: off, 1: on */ ! 1122: { ! 1123: } ! 1124: ! 1125: SetVideo (onoff) ! 1126: int onoff; /* 0: off, 1: on */ ! 1127: { ! 1128: return(onoff - 1); ! 1129: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.