home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Graphics / Graphics.zip / xfitsvew.zip / XFITSview / cursor.c < prev    next >
C/C++ Source or Header  |  1996-01-11  |  2KB  |  63 lines

  1. /* creates cursor for XFITSview window */
  2. /* tries to use a 16x16 cursor; if this isn't appropriate then the standard */
  3. /* cursor is returned                                                       */
  4. /*-----------------------------------------------------------------------
  5. *  Copyright (C) 1996
  6. *  Associated Universities, Inc. Washington DC, USA.
  7. *  This program is free software; you can redistribute it and/or
  8. *  modify it under the terms of the GNU General Public License as
  9. *  published by the Free Software Foundation; either version 2 of
  10. *  the License, or (at your option) any later version.
  11. *
  12. *  This program is distributed in the hope that it will be useful,
  13. *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. *  GNU General Public License for more details.
  16. *-----------------------------------------------------------------------*/
  17. #include <X11/X.h> 
  18. #include <Xm/Xm.h> 
  19. #include <Xm/DrawingA.h> 
  20. #include <Xm/MainW.h> 
  21. #include "definecursor.h"
  22.  
  23. Cursor MakeImageCursor (Display *display, Drawable screen)
  24. /* make custom cursor for image display window if possible else return NULL */
  25. {
  26.   unsigned int width, height;
  27.   Pixmap csource, cmask;
  28.   int xhot = ImageCursor_x_hot, yhot = ImageCursor_y_hot;
  29.   XColor  cfore, cback;
  30.   Cursor  cursor;
  31.  
  32. /* see if this display wants a 16x16 cursor, if not return Null */
  33.   XQueryBestCursor (display, screen, ImageCursor_width, ImageCursor_height, 
  34.             &width, &height);
  35.   if ((width!=ImageCursor_width) || (height!=ImageCursor_height)) return 0;
  36.  
  37. /* set colors (should do this from resource file)*/
  38. /* foreground */
  39.   cfore.red=0; cfore.green=65535; cfore.blue = 65535;
  40.   cfore.flags = DoRed | DoGreen | DoBlue;
  41. /* background */
  42.   cback.red=65535; cback.green=65535; cback.blue = 0;
  43.   cback.flags = DoRed | DoGreen | DoBlue;
  44.  
  45. /* make pixmaps */
  46.   csource = XCreateBitmapFromData(display, screen, 
  47.                   (const char *)ImageCursor_bits,
  48.                   width, height);
  49.   if (!csource) return 0;
  50.   cmask = XCreateBitmapFromData(display, screen, 
  51.                 (const char *)ImageCursorMask_bits,
  52.                   width, height);
  53.   if (!cmask) return 0;
  54.  
  55. /* make cursor */
  56.   cursor = XCreatePixmapCursor (display, csource, cmask, &cfore, &cback, 
  57.                 xhot, yhot);
  58. /* delete pixmaps */
  59.   XFreePixmap(display, csource);
  60.   XFreePixmap(display, cmask);
  61.   return cursor;
  62. } /* end MakeImageCursor */
  63.