home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / opengl / utilities / isfast / libtk / cursor.c next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  2.1 KB  |  78 lines

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