home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3406 / misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-24  |  2.6 KB  |  133 lines

  1.  
  2. /* This module contains some miscellaneous routines, like
  3.  * allocating/freeing fonts, allocating cursors, writing text.
  4.  
  5.  * int AllocFonts(Display *display, GC gc);
  6.  * int WriteText(Display *display, Window window, GC gc,
  7.             char *text, int x, int y);
  8.  * void FreeFonts(Display *display);
  9.  * void AllocCursors(Display *display);
  10.  * void WaitCursor(Display *display, Window window);
  11.  * void NormalCursor(Display *display, Window window);
  12.  * void ZoomCursor(Display *display, Window window);
  13.  * void SlideCursor(Display *display, Window window);
  14.  * void VertCursor(Display *display, Window window);
  15.  
  16.  */
  17. #include <X11/Xlib.h>
  18. #include <X11/cursorfont.h>
  19.  
  20. #define FONT1 "-*-times-bold-r-*-*-12-*"
  21. #define FONT2 "-*-helvetica-bold-r-*-*-12-*"
  22. #define FONT3 "-*-courier-bold-r-*-*-12-*"
  23.  
  24. Cursor arrow, waitc, cross, updown, vert;
  25. XFontStruct *font= 0;
  26.  
  27.  
  28. int AllocFonts(display, gc)
  29. Display *display;
  30. GC gc;
  31. {
  32. if ( !(font= XLoadQueryFont(display, FONT1)) &&
  33.     !(font= XLoadQueryFont(display, FONT2)) &&
  34.      !(font= XLoadQueryFont(display, FONT3)))
  35.   return 0;
  36. XSetFont(display, gc, font->fid);
  37. return 1;
  38. }
  39.  
  40.  
  41. int WriteText(display, win, gc, text, x, y)
  42. Display *display;
  43. Window win;
  44. GC gc;
  45. char *text;
  46. int x, y;
  47. {
  48. int len;
  49. if (!font) 
  50.   /* Some plausible default */
  51.   return(8 * strlen(text));
  52.  
  53. len= XTextWidth(font, text, strlen(text));
  54. XDrawImageString(display, win, gc, x, y+ font->ascent,
  55.             text, strlen(text));
  56. return(len);
  57. }
  58.  
  59.  
  60. void FreeFonts(display)
  61. Display *display;
  62. {
  63. if (font) XFreeFont(display, font);
  64. }
  65.  
  66.  
  67. void AllocCursors(display)
  68. Display *display;
  69. {
  70. /* Good cursor choices:
  71.  * XC_crosshair, XC_diamond_cross, XC_fleur, XC_heart,
  72.  * XC_pencil, XC_plus, XC_spider
  73.  */
  74.  
  75. arrow= XCreateFontCursor(display, XC_top_left_arrow);
  76. waitc= XCreateFontCursor(display, XC_watch);
  77. cross= XCreateFontCursor(display, XC_crosshair);
  78. updown= XCreateFontCursor(display, XC_sb_v_double_arrow);
  79. vert= XCreateFontCursor(display, XC_xterm);
  80. }
  81.  
  82.  
  83. void WaitCursor(display, win)
  84. Display *display;
  85. Window win;
  86. {
  87. if (!arrow || !waitc)
  88.   return;
  89. XDefineCursor(display, win, waitc);
  90. }
  91.  
  92.  
  93. void NormalCursor(display, win)
  94. Display *display;
  95. Window win;
  96. {
  97. if (!arrow)
  98.   return;
  99. XDefineCursor(display, win, arrow);
  100. }
  101.  
  102.  
  103. void ZoomCursor(display, win)
  104. Display *display;
  105. Window win;
  106. {
  107. if (!cross || !arrow)
  108.   return;
  109. XDefineCursor(display, win, cross);
  110. }
  111.  
  112.  
  113. void SlideCursor(display, win)
  114. Display *display;
  115. Window win;
  116. {
  117. if (!updown || !arrow)
  118.   return;
  119. XDefineCursor(display, win, updown);
  120. }
  121.  
  122.  
  123. void VertCursor(display, win)
  124. Display *display;
  125. Window win;
  126. {
  127. if (!vert || !arrow)
  128.   return;
  129. XDefineCursor(display, win, vert);
  130. }
  131.  
  132.  
  133.