home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / doc / Xlib / CH05 < prev    next >
Encoding:
Text File  |  1991-07-30  |  15.2 KB  |  522 lines

  1. \&
  2. .sp 1
  3. .ce 3
  4. \s+1\fBChapter 5\fP\s-1
  5.  
  6. \s+1\fBPixmap and Cursor Functions\fP\s-1
  7. .sp 2
  8. .nr H1 5
  9. .nr H2 0
  10. .nr H3 0
  11. .nr H4 0
  12. .nr H5 0
  13. .na
  14. .LP
  15. .XS
  16. Chapter 5: Pixmap and Cursor Functions 
  17. .XE
  18. Once you have connected to an X server,
  19. you can use the Xlib functions to:
  20. .IP \(bu 5
  21. Create and free pixmaps
  22. .IP \(bu 5
  23. Create, recolor, and free cursors
  24. .RE
  25. .NH 2
  26. Creating and Freeing Pixmaps
  27. .XS
  28. \*(SN Creating and Freeing Pixmaps
  29. .XE
  30. .LP
  31. Pixmaps can only be used on the screen on which they were created.
  32. Pixmaps are off-screen resources that are used for various operations,
  33. for example, defining cursors as tiling patterns 
  34. or as the source for certain raster operations.
  35. Most graphics requests can operate either on a window or on a pixmap.
  36. A bitmap is a single bit-plane pixmap.
  37. .LP
  38. .sp
  39. To create a pixmap of a given size, use
  40. .PN XCreatePixmap .
  41. .IN "XCreatePixmap" "" "@DEF@"
  42. .\" Start marker code here
  43. .FD 0
  44. .\" $Header: XCrePmap.f,v 1.1 88/02/26 09:59:10 mento Exp $
  45. Pixmap XCreatePixmap\^(\^\fIdisplay\fP, \fId\fP\^, \fIwidth\fP\^, \fIheight\fP\^, \fIdepth\fP\^)
  46. .br
  47.       Display *\fIdisplay\fP\^;
  48. .br
  49.       Drawable \fId\fP\^;
  50. .br
  51.       unsigned int \fIwidth\fP\^, \fIheight\fP\^;
  52. .br
  53.       unsigned int \fIdepth\fP\^;
  54. .FN
  55. .\" $Header: display.a,v 1.1 88/02/26 10:26:29 mento Exp $
  56. .IP \fIdisplay\fP 1i
  57. Specifies the connection to the X server.
  58. .\" $Header: d_crepix.a,v 1.1 88/02/26 10:06:13 mento Exp $
  59. .IP \fId\fP 1i
  60. Specifies which screen the pixmap is created on. 
  61. .ds Wh , which define the dimensions of the pixmap
  62. .\" $Header: w+h_gen.a,v 1.2 88/08/04 11:21:28 mento Exp $
  63. .IP \fIwidth\fP 1i
  64. .br
  65. .ns
  66. .IP \fIheight\fP 1i
  67. Specify the width and height\*(Wh.
  68. .\" $Header: depth1.a,v 1.3 88/05/09 09:53:55 mento Exp $
  69. .IP \fIdepth\fP 1i
  70. Specifies the depth of the pixmap.
  71. .\" End marker code here
  72. .LP 
  73. .\" $Header: XCrePmap.d,v 1.5 88/08/18 07:41:46 mento Exp $
  74. The
  75. .PN XCreatePixmap
  76. function creates a pixmap of the width, height, and depth you specified
  77. and returns a pixmap ID that identifies it.
  78. It is valid to pass an 
  79. .PN InputOnly
  80. window to the drawable argument.
  81. The width and height arguments must be nonzero,
  82. or a 
  83. .PN BadValue
  84. error results.
  85. The depth argument must be one of the depths supported by the screen
  86. of the specified drawable,
  87. or a
  88. .PN BadValue
  89. error results.
  90. .LP
  91. The server uses the specified drawable to determine on which screen
  92. to create the pixmap.
  93. The pixmap can be used only on this screen
  94. and only with other drawables of the same depth (see
  95. .PN XCopyPlane
  96. for an exception to this rule).
  97. The initial contents of the pixmap are undefined.
  98. .LP
  99. .PN XCreatePixmap
  100. can generate
  101. .PN BadAlloc ,
  102. .PN BadDrawable ,
  103. and
  104. .PN BadValue 
  105. errors.
  106. .LP
  107. .sp
  108. To free all storage associated with a specified pixmap, use
  109. .PN XFreePixmap .
  110. .IN "XFreePixmap" "" "@DEF@"
  111. .\" Start marker code here
  112. .FD 0
  113. .\" $Header: XFreePixmap.f,v 1.1 88/02/26 10:00:19 mento Exp $
  114. XFreePixmap\^(\^\fIdisplay\fP, \fIpixmap\fP\^)
  115. .br
  116.       Display *\fIdisplay\fP\^;
  117. .br
  118.       Pixmap \fIpixmap\fP\^;
  119. .FN    
  120. .\" $Header: display.a,v 1.1 88/02/26 10:26:29 mento Exp $
  121. .IP \fIdisplay\fP 1i
  122. Specifies the connection to the X server.
  123. .IP \fIpixmap\fP 1i
  124. Specifies the pixmap.
  125. .\" End marker code here
  126. .LP 
  127. .\" $Header: XFreePixmap.d,v 1.2 88/05/09 09:56:57 mento Exp $
  128. The
  129. .PN XFreePixmap
  130. function first deletes the association between the pixmap ID and the pixmap.
  131. Then, the X server frees the pixmap storage when there are no references to it.
  132. The pixmap should never be referenced again.
  133. .LP
  134. .PN XFreePixmap
  135. can generate a
  136. .PN BadPixmap 
  137. error.
  138. .NH 2
  139. Creating, Recoloring, and Freeing Cursors
  140. .XS
  141. \*(SN Creating, Recoloring, and Freeing Cursors 
  142. .XE
  143. .LP
  144. Each window can have a different cursor defined for it.
  145. Whenever the pointer is in a visible window, 
  146. it is set to the cursor defined for that window.
  147. If no cursor was defined for that window, 
  148. the cursor is the one defined for the parent window.
  149. .LP
  150. From X's perspective, 
  151. a cursor consists of a cursor source, mask, colors, and a hotspot. 
  152. The mask pixmap determines the shape of the cursor and must be a depth
  153. of one.
  154. The source pixmap must have a depth of one,
  155. and the colors determine the colors of the source.
  156. The hotspot defines the point on the cursor that is reported
  157. when a pointer event occurs.
  158. There may be limitations imposed by the hardware on
  159. cursors as to size and whether a mask is implemented. 
  160. .IN "XQueryBestCursor"
  161. .PN XQueryBestCursor
  162. can be used to find out what sizes are possible.
  163. There is a standard font for creating cursors, but
  164. Xlib provides functions that you can use to create cursors
  165. from an arbitrary font, or from bitmaps.
  166. .LP
  167. .sp
  168. To create a cursor from the standard cursor font, use
  169. .PN XCreateFontCursor .
  170. .IN "XCreateFontCursor" "" "@DEF@"
  171. .\" Start marker code here
  172. .FD 0
  173. .\" $Header: XCursor.f,v 1.1 88/02/26 09:59:17 mento Exp $
  174. #include <X11/cursorfont.h>
  175. .sp 6p
  176. Cursor XCreateFontCursor\^(\^\fIdisplay\fP, \fIshape\fP\^)
  177. .br
  178.       Display *\fIdisplay\fP\^;
  179. .br
  180.       unsigned int \fIshape\fP\^;
  181. .FN
  182. .\" $Header: display.a,v 1.1 88/02/26 10:26:29 mento Exp $
  183. .IP \fIdisplay\fP 1i
  184. Specifies the connection to the X server.
  185. .IP \fIshape\fP 1i
  186. Specifies the shape of the cursor.
  187. .\" End marker code here
  188. .LP
  189. .\" $Header: XCursor.d,v 1.2 88/06/11 07:49:47 mento Exp $
  190. X provides a set of standard cursor shapes in a special font named
  191. cursor.
  192. Applications are encouraged to use this interface for their cursors
  193. because the font can be customized for the individual display type.
  194. The shape argument specifies which glyph of the standard fonts
  195. to use.
  196. .LP
  197. The hotspot comes from the information stored in the cursor font.
  198. The initial colors of a cursor are a black foreground and a white
  199. background (see
  200. .PN XRecolorCursor ).
  201. For further information about cursor shapes,
  202. see appendix B.
  203. .LP
  204. .PN XCreateFontCursor
  205. can generate
  206. .PN BadAlloc
  207. and
  208. .PN BadValue 
  209. errors.
  210. .LP
  211. .sp
  212. To create a cursor from font glyphs, use
  213. .PN XCreateGlyphCursor .
  214. .IN "XCreateGlyphCursor" "" "@DEF@"
  215. .\" Start marker code here
  216. .FD 0
  217. .\" $Header: XCreateGlCur.f,v 1.1 88/02/26 09:59:16 mento Exp $
  218. Cursor XCreateGlyphCursor\^(\^\fIdisplay\fP, \fIsource_font\fP\^, \fImask_font\fP\^, \fIsource_char\fP\^, \fImask_char\fP\^,
  219. .br
  220.                            \fIforeground_color\fP\^, \fIbackground_color\fP\^)
  221. .br
  222.       Display *\fIdisplay\fP\^;
  223. .br
  224.       Font \fIsource_font\fP\^, \fImask_font\fP\^;
  225. .br
  226.       unsigned int \fIsource_char\fP\^, \fImask_char\fP\^;
  227. .br
  228.       XColor *\fIforeground_color\fP\^;
  229. .br
  230.       XColor *\fIbackground_color\fP\^;
  231. .FN
  232. .\" $Header: display.a,v 1.1 88/02/26 10:26:29 mento Exp $
  233. .IP \fIdisplay\fP 1i
  234. Specifies the connection to the X server.
  235. .\" $Header: sfont.a,v 1.1 88/02/26 10:31:12 mento Exp $
  236. .IP \fIsource_font\fP 1i
  237. Specifies the font for the source glyph.
  238. .\" $Header: mfont.a,v 1.2 88/05/13 13:01:38 mento Exp $
  239. .IP \fImask_font\fP 1i
  240. Specifies the font for the mask glyph or
  241. .PN None .
  242. .\" $Header: schar.a,v 1.1 88/02/26 10:31:06 mento Exp $
  243. .IP \fIsource_char\fP 1i
  244. Specifies the character glyph for the source.
  245. .\" $Header: mchar.a,v 1.1 88/02/26 10:28:52 mento Exp $
  246. .IP \fImask_char\fP 1i
  247. Specifies the glyph character for the mask. 
  248. .\" $Header: scolor.a,v 1.2 88/05/13 12:51:29 mento Exp $
  249. .IP \fIforeground_color\fP 1i
  250. Specifies the RGB values for the foreground of the source. 
  251. .\" $Header: bcolor.a,v 1.2 88/05/13 12:53:45 mento Exp $
  252. .IP \fIbackground_color\fP 1i
  253. Specifies the RGB values for the background of the source.
  254. .\" End marker code here
  255. .LP
  256. .\" $Header: XCreateGlCur.d,v 1.4 88/06/11 07:49:41 mento Exp $
  257. The
  258. .PN XCreateGlyphCursor
  259. function is similar to
  260. .PN XCreatePixmapCursor
  261. except that the source and mask bitmaps are obtained from the specified 
  262. font glyphs.
  263. The source_char must be a defined glyph in source_font, 
  264. or a
  265. .PN BadValue
  266. error results.
  267. If mask_font is given, 
  268. mask_char must be a defined glyph in mask_font,
  269. or a
  270. .PN BadValue
  271. error results.
  272. The mask_font and character are optional.
  273. The origins of the source_char and mask_char (if defined) glyphs are
  274. positioned coincidently and define the hotspot. 
  275. The source_char and mask_char need not have the same bounding box metrics, 
  276. and there is no restriction on the placement of the hotspot relative to the bounding
  277. boxes. 
  278. If no mask_char is given, all pixels of the source are displayed.
  279. You can free the fonts immediately by calling
  280. .PN XFreeFont
  281. if no further explicit references to them are to be made. 
  282. .LP
  283. For 2-byte matrix fonts, 
  284. the 16-bit value should be formed with the byte1
  285. member in the most-significant byte and the byte2 member in the 
  286. least-significant byte.
  287. .LP
  288. .PN XCreateGlyphCursor
  289. can generate
  290. .PN BadAlloc ,
  291. .PN BadFont ,
  292. and
  293. .PN BadValue 
  294. errors.
  295. .LP
  296. .sp
  297. To create a cursor from two bitmaps,
  298. use
  299. .PN XCreatePixmapCursor .
  300. .IN "XCreatePixmapCursor" "" "@DEF@"
  301. .\" Start marker code here
  302. .FD 0
  303. .\" $Header: XCreCursor.f,v 1.1 88/02/26 09:59:09 mento Exp $
  304. Cursor XCreatePixmapCursor\^(\^\fIdisplay\fP, \fIsource\fP\^, \fImask\fP\^, \fIforeground_color\fP\^, \fIbackground_color\fP\^, \fIx\fP\^, \fIy\fP\^)
  305. .br
  306.       Display *\fIdisplay\fP\^;
  307. .br
  308.       Pixmap \fIsource\fP\^;
  309. .br
  310.       Pixmap \fImask\fP\^;
  311. .br
  312.       XColor *\fIforeground_color\fP\^;
  313. .br
  314.       XColor *\fIbackground_color\fP\^;
  315. .br
  316.       unsigned int \fIx\fP\^, \fIy\fP\^;
  317. .FN
  318. .\" $Header: display.a,v 1.1 88/02/26 10:26:29 mento Exp $
  319. .IP \fIdisplay\fP 1i
  320. Specifies the connection to the X server.
  321. .\" $Header: source.a,v 1.1 88/02/26 10:31:17 mento Exp $
  322. .IP \fIsource\fP 1i
  323. Specifies the shape of the source cursor.
  324. .\" *** JIM: NEED TO CHECK THIS. ***
  325. .IP \fImask\fP 1i
  326. Specifies the cursor's source bits to be displayed or
  327. .PN None .
  328. .\" $Header: scolor.a,v 1.2 88/05/13 12:51:29 mento Exp $
  329. .IP \fIforeground_color\fP 1i
  330. Specifies the RGB values for the foreground of the source. 
  331. .\" $Header: bcolor.a,v 1.2 88/05/13 12:53:45 mento Exp $
  332. .IP \fIbackground_color\fP 1i
  333. Specifies the RGB values for the background of the source.
  334. .ds Xy , which indicate the hotspot relative to the source's origin
  335. .\" $Header: xy_gen.a,v 1.2 88/08/04 11:22:37 mento Exp $
  336. .IP \fIx\fP 1i
  337. .br
  338. .ns
  339. .IP \fIy\fP 1i
  340. Specify the x and y coordinates\*(Xy.
  341. .\" End marker code here
  342. .LP
  343. .\" $Header: XCreCursor.d,v 1.2 88/06/11 07:49:29 mento Exp $
  344. The
  345. .PN XCreatePixmapCursor
  346. function creates a cursor and returns the cursor ID associated with it.
  347. The foreground and background RGB values must be specified using
  348. foreground_color and background_color,
  349. even if the X server only has a
  350. .PN StaticGray
  351. or
  352. .PN GrayScale
  353. screen.
  354. The foreground color is used for the pixels set to 1 in the
  355. source, and the background color is used for the pixels set to 0.
  356. Both source and mask, if specified, must have depth one (or a 
  357. .PN BadMatch
  358. error results) but can have any root.
  359. The mask argument defines the shape of the cursor.
  360. The pixels set to 1 in the mask define which source pixels are displayed,
  361. and the pixels set to 0 define which pixels are ignored.
  362. If no mask is given, 
  363. all pixels of the source are displayed.
  364. The mask, if present, must be the same size as the pixmap defined by the 
  365. source argument, or a
  366. .PN BadMatch
  367. error results.
  368. The hotspot must be a point within the source,
  369. or a
  370. .PN BadMatch
  371. error results.
  372. .LP
  373. The components of the cursor can be transformed arbitrarily to meet
  374. display limitations.
  375. The pixmaps can be freed immediately if no further explicit references
  376. to them are to be made.
  377. Subsequent drawing in the source or mask pixmap has an undefined effect on the
  378. cursor.
  379. The X server might or might not make a copy of the pixmap.
  380. .LP
  381. .PN XCreatePixmapCursor
  382. can generate
  383. .PN BadAlloc
  384. and
  385. .PN BadPixmap
  386. errors.
  387. .LP
  388. .sp
  389. To determine useful cursor sizes, use
  390. .PN XQueryBestCursor .
  391. .IN "XQueryBestCursor" "" "@DEF@"
  392. .\" Start marker code here
  393. .FD 0
  394. .\" $Header: XQryCrsrSh.f,v 1.1 88/02/26 10:02:06 mento Exp $
  395. Status XQueryBestCursor\^(\^\fIdisplay\fP, \fId\fP, \fIwidth\fP\^, \fIheight\fP\^, \fIwidth_return\fP\^, \fIheight_return\fP\^)
  396. .br
  397.       Display *\fIdisplay\fP\^;
  398. .br
  399.       Drawable \fId\fP\^;
  400. .br
  401.       unsigned int \fIwidth\fP\^, \fIheight\fP\^;
  402. .br
  403.       unsigned int *\fIwidth_return\fP\^, *\fIheight_return\fP\^;
  404. .FN
  405. .\" $Header: display.a,v 1.1 88/02/26 10:26:29 mento Exp $
  406. .IP \fIdisplay\fP 1i
  407. Specifies the connection to the X server.
  408. .ds Dr , which indicates the screen
  409. .\" $Header: d_gen.a,v 1.2 88/08/04 11:09:21 mento Exp $
  410. .IP \fId\fP 1i
  411. Specifies the drawable\*(Dr. 
  412. .ds Wh \ of the cursor that you want the size information for
  413. .\" $Header: w+h_gen.a,v 1.2 88/08/04 11:21:28 mento Exp $
  414. .IP \fIwidth\fP 1i
  415. .br
  416. .ns
  417. .IP \fIheight\fP 1i
  418. Specify the width and height\*(Wh.
  419. .\" $Header: rwidtheight2.a,v 1.3 88/05/13 13:09:44 mento Exp $
  420. .IP \fIwidth_return\fP 1i
  421. .br
  422. .ns
  423. .IP \fIheight_return\fP 1i
  424. Return the best width and height that is closest to the specified width 
  425. and height.
  426. .\" End marker code here
  427. .LP
  428. .\" $Header: XQryCrsrSh.d,v 1.2 88/06/11 07:52:32 mento Exp $
  429. Some displays allow larger cursors than other displays.
  430. The
  431. .PN XQueryBestCursor
  432. function provides a way to find out what size cursors are actually
  433. possible on the display.
  434. .IN "Cursor" "limitations" 
  435. It returns the largest size that can be displayed.
  436. Applications should be prepared to use smaller cursors on displays that
  437. cannot support large ones.
  438. .LP
  439. .PN XQueryBestCursor
  440. can generate a
  441. .PN BadDrawable 
  442. error.
  443. .LP
  444. .sp
  445. To change the color of a given cursor, use
  446. .PN XRecolorCursor .
  447. .IN "XRecolorCursor" "" "@DEF@"
  448. .\" Start marker code here
  449. .FD 0
  450. .\" $Header: XRecolorCurs.f,v 1.1 88/02/26 10:02:35 mento Exp $
  451. XRecolorCursor\^(\^\fIdisplay\fP, \fIcursor\fP\^, \fIforeground_color\fP\^, \fIbackground_color\fP\^)
  452. .br
  453.       Display *\fIdisplay\fP\^;
  454. .br
  455.       Cursor \fIcursor\fP\^;
  456. .br
  457.       XColor *\fIforeground_color\fP\^, *\fIbackground_color\fP\^;
  458. .FN
  459. .\" $Header: display.a,v 1.1 88/02/26 10:26:29 mento Exp $
  460. .IP \fIdisplay\fP 1i
  461. Specifies the connection to the X server.
  462. .\" $Header: cursor.a,v 1.1 88/02/26 10:06:06 mento Exp $
  463. .IP \fIcursor\fP 1i
  464. Specifies the cursor. 
  465. .\" $Header: scolor.a,v 1.2 88/05/13 12:51:29 mento Exp $
  466. .IP \fIforeground_color\fP 1i
  467. Specifies the RGB values for the foreground of the source. 
  468. .\" $Header: bcolor.a,v 1.2 88/05/13 12:53:45 mento Exp $
  469. .IP \fIbackground_color\fP 1i
  470. Specifies the RGB values for the background of the source.
  471. .\" End marker code here
  472. .LP
  473. .\" $Header: XRecolorCurs.d,v 1.3 88/05/19 05:25:50 mento Exp $
  474. The
  475. .PN XRecolorCursor
  476. function changes the color of the specified cursor, and
  477. if the cursor is being displayed on a screen,
  478. the change is visible immediately.
  479. Note that the pixel members of the
  480. .PN XColor
  481. structures are ignored, only the RGB values are used.
  482. .LP
  483. .PN XRecolorCursor
  484. can generate a
  485. .PN BadCursor 
  486. error.
  487. .LP
  488. .sp
  489. To free (destroy) a given cursor, use
  490. .PN XFreeCursor .
  491. .IN "XFreeCursor" "" "@DEF@"
  492. .\" Start marker code here
  493. .FD 0
  494. .\" $Header: XFreeCursor.f,v 1.1 88/02/26 10:00:17 mento Exp $
  495. XFreeCursor\^(\^\fIdisplay\fP, \fIcursor\fP\^)
  496. .br
  497.       Display *\fIdisplay\fP\^;
  498. .br
  499.       Cursor \fIcursor\fP\^;
  500. .FN
  501. .\" $Header: display.a,v 1.1 88/02/26 10:26:29 mento Exp $
  502. .IP \fIdisplay\fP 1i
  503. Specifies the connection to the X server.
  504. .\" $Header: cursor.a,v 1.1 88/02/26 10:06:06 mento Exp $
  505. .IP \fIcursor\fP 1i
  506. Specifies the cursor. 
  507. .\" End marker code here
  508. .LP 
  509. .\" $Header: XFreeCursor.d,v 1.2 88/06/11 07:50:46 mento Exp $
  510. The
  511. .PN XFreeCursor
  512. function deletes the association between the cursor resource ID 
  513. and the specified cursor.
  514. The cursor storage is freed when no other resource references it.
  515. The specified cursor ID should not be referred to again.
  516. .LP
  517. .PN XFreeCursor
  518. can generate a
  519. .PN BadCursor 
  520. error.
  521. .bp
  522.