home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 5 / MA_Cover_5.iso / ppc / mesa / src-tk / cursor.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-01-31  |  2.1 KB  |  83 lines

  1. #if !defined(FX)
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include "gltk.h"
  7. #include "private.h"
  8.  
  9. /******************************************************************************/
  10.  
  11. #define MAX_CURSOR 32
  12.  
  13. typedef struct _cursorRec {
  14.     GLint id;
  15.     Cursor cursor;
  16. } cursorRec;
  17.  
  18. int cursorNum = 0;
  19. cursorRec cursors[MAX_CURSOR];
  20.  
  21. /******************************************************************************/
  22.  
  23. void tkNewCursor(GLint id, GLubyte *shapeBuf, GLubyte *maskBuf, GLenum fgColor,
  24.          GLenum bgColor, GLint hotX, GLint hotY)
  25. {
  26.     GLubyte buf[32];
  27.     Pixmap shapeMap, maskMap;
  28.     XColor c1, c2;
  29.     int i;
  30.  
  31.     if (cursorNum == MAX_CURSOR-1) {
  32.     return;
  33.     }
  34.  
  35.     for (i = 0; i < 32; i += 2) {
  36.     buf[i] = shapeBuf[i+1];
  37.     buf[i+1] = shapeBuf[i];
  38.     }
  39.     shapeMap = XCreatePixmapFromBitmapData(xDisplay, wRoot, (char*) buf,
  40.                        16, 16, 1, 0, 1);
  41.     for (i = 0; i < 32; i += 2) {
  42.     buf[i] = maskBuf[i+1];
  43.     buf[i+1] = maskBuf[i];
  44.     }
  45.     maskMap = XCreatePixmapFromBitmapData(xDisplay, wRoot, (char*) buf,
  46.                       16, 16, 1, 0, 1);
  47.     c1.red = (unsigned short)(tkRGBMap[fgColor][0] * 65535.0 + 0.5);
  48.     c1.green = (unsigned short)(tkRGBMap[fgColor][1] * 65535.0 + 0.5);
  49.     c1.blue = (unsigned short)(tkRGBMap[fgColor][2] * 65535.0 + 0.5);
  50.     c1.flags = DoRed | DoGreen | DoBlue;
  51.     c2.red = (unsigned short)(tkRGBMap[bgColor][0] * 65535.0 + 0.5);
  52.     c2.green = (unsigned short)(tkRGBMap[bgColor][1] * 65535.0 + 0.5);
  53.     c2.blue = (unsigned short)(tkRGBMap[bgColor][2] * 65535.0 + 0.5);
  54.     c2.flags = DoRed | DoGreen | DoBlue;
  55.  
  56.     cursors[cursorNum].id = id;
  57.     cursors[cursorNum].cursor = XCreatePixmapCursor(xDisplay, shapeMap, maskMap,
  58.                                 &c1, &c2, hotX, hotY);
  59.     cursorNum++;
  60. }
  61.  
  62. /******************************************************************************/
  63.  
  64. void tkSetCursor(GLint id)
  65. {
  66.     int i;
  67.  
  68.     for (i = 0; i < cursorNum; i++) {
  69.     if (cursors[i].id == id) {
  70.         XDefineCursor(xDisplay, w.wMain, cursors[i].cursor);
  71.     }
  72.     }
  73. }
  74.  
  75. /******************************************************************************/
  76.  
  77. #else
  78.  
  79. /* This is here to avoid ANSI C "empty source file" warnings */
  80. static void no_op () {}
  81.  
  82. #endif    /* !FX */
  83.