home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / tcl / tk3.3b1 / doc / GetBitmap.3 < prev    next >
Encoding:
Text File  |  1993-04-01  |  8.2 KB  |  240 lines

  1. '\"
  2. '\" Copyright (c) 1990 The Regents of the University of California.
  3. '\" All rights reserved.
  4. '\"
  5. '\" Permission is hereby granted, without written agreement and without
  6. '\" license or royalty fees, to use, copy, modify, and distribute this
  7. '\" documentation for any purpose, provided that the above copyright
  8. '\" notice and the following two paragraphs appear in all copies.
  9. '\"
  10. '\" IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
  11. '\" FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
  12. '\" ARISING OUT OF THE USE OF THIS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  13. '\" CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14. '\"
  15. '\" THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  16. '\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  17. '\" AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  18. '\" ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  19. '\" PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  20. '\" 
  21. '\" $Header: /user6/ouster/wish/man/RCS/GetBitmap.3,v 1.11 93/04/01 09:41:24 ouster Exp $ SPRITE (Berkeley)
  22. '\" 
  23. .so man.macros
  24. .HS Tk_GetBitmap tkc
  25. .BS
  26. .SH NAME
  27. Tk_GetBitmap, Tk_DefineBitmap, Tk_NameOfBitmap, Tk_SizeOfBitmap, Tk_FreeBitmap, Tk_GetBitmapFromData \- maintain database of single-plane pixmaps
  28. .SH SYNOPSIS
  29. .nf
  30. \fB#include <tk.h>\fR
  31. .sp
  32. Pixmap
  33. \fBTk_GetBitmap(\fIinterp, tkwin, id\fB)\fR
  34. .sp
  35. .VS
  36. int
  37. \fBTk_DefineBitmap(\fIinterp, nameId, source, width, height\fR)\fR
  38. .VE
  39. .sp
  40. Tk_Uid
  41. .VS
  42. \fBTk_NameOfBitmap(\fIdisplay, bitmap\fB)\fR
  43. .sp
  44. \fBTk_SizeOfBitmap(\fIdisplay, bitmap, widthPtr, heightPtr\fB)\fR
  45. .sp
  46. \fBTk_FreeBitmap(\fIdisplay, bitmap\fB)\fR
  47. .VE
  48. .SH ARGUMENTS
  49. .AS "unsigned long" *pixelPtr
  50. .AP Tcl_Interp *interp in
  51. Interpreter to use for error reporting.
  52. .AP Tk_Window tkwin in
  53. Token for window in which the bitmap will be used.
  54. .AP Tk_Uid id in
  55. Description of bitmap;  see below for possible values.
  56. .AP Tk_Uid *nameId in
  57. Name for new bitmap to be defined.
  58. .AP char *source in
  59. Data for bitmap, in standard bitmap format.
  60. Must be stored in static memory whose value will never change.
  61. .AP "unsigned int" width in
  62. Width of bitmap.
  63. .AP "unsigned int" height in
  64. Height of bitmap.
  65. .AP "unsigned int" *widthPtr out
  66. Pointer to word to fill in with \fIbitmap\fR's width.
  67. .AP "unsigned int" *heightPtr out
  68. Pointer to word to fill in with \fIbitmap\fR's height.
  69. .AP Display *display in
  70. Display for which \fIbitmap\fR was allocated.
  71. .VS
  72. .VE
  73. .AP Pixmap bitmap in
  74. Identifier for a bitmap allocated by \fBTk_GetBitmap\fR.
  75. .BE
  76.  
  77. .SH DESCRIPTION
  78. .PP
  79. These procedures manage a collection of bitmaps (one-plane pixmaps)
  80. being used by an application.  The procedures allow bitmaps to be
  81. re-used efficiently, thereby avoiding server overhead, and also
  82. allow bitmaps to be named with character strings.
  83. .PP
  84. \fBTk_GetBitmap\fR takes as argument a Tk_Uid describing a bitmap.
  85. It returns a Pixmap identifier for a bitmap corresponding to the
  86. description.  It re-uses an existing bitmap, if possible, and
  87. creates a new one otherwise.  At present, \fIid\fR must have
  88. one of the following forms:
  89. .TP 20
  90. \fB@\fIfileName\fR
  91. \fIFileName\fR must be the name of a file containing a bitmap
  92. description in the standard X11 or X10 format.
  93. .TP 20
  94. \fIname\fR
  95. \fIName\fR must be the name of a bitmap defined previously with
  96. a call to \fBTk_DefineBitmap\fR.  The following names are pre-defined
  97. by Tk:
  98. .RS
  99. .TP 12
  100. \fBerror\fR
  101. .VS
  102. The international "don't" symbol:  a circle with a diagonal line
  103. across it.
  104. .VE
  105. .TP 12
  106. \fBgray50\fR
  107. 50% gray: a checkerboard pattern where every other bit is on.
  108. .TP 12
  109. \fBgray25\fR
  110. 25% gray: a pattern where 25% of the bits are on, consisting of all the
  111. bit positions that can be reached by a chess knight starting at (0,0).
  112. .TP 12
  113. \fBhourglass\fR
  114. .VS
  115. An hourglass symbol.
  116. .TP 12
  117. \fBinfo\fR
  118. A large letter ``i''.
  119. .TP 12
  120. \fBquesthead\fR
  121. The silhouette of a human head, with a question mark in it.
  122. .TP 12
  123. \fBquestion\fR
  124. A large question-mark.
  125. .TP 12
  126. \fBwarning\fR
  127. A large exclamation point.
  128. .VE
  129. \fB
  130. .RE
  131. .LP
  132. Under normal conditions, \fBTk_GetBitmap\fR
  133. returns an identifier for the requested bitmap.  If an error
  134. occurs in creating the bitmap, such as when \fIid\fR refers
  135. to a non-existent file, then \fBNone\fR is returned and an error
  136. message is left in \fIinterp->result\fR.
  137. .PP
  138. \fBTk_DefineBitmap\fR associates a name with
  139. .VS
  140. in-memory bitmap data so that the name can be used in later
  141. calls to \fBTk_GetBitmap\fR.  The \fInameId\fR
  142. argument gives a name for the bitmap;  it must not previously
  143. have been used in a call to \fBTk_DefineBitmap\fR.
  144. The arguments \fIsource\fR, \fIwidth\fR, and \fIheight\fR
  145. describe the bitmap.
  146. \fBTk_DefineBitmap\fR normally returns TCL_OK;  if an error occurs
  147. (e.g. a bitmap named \fInameId\fR has already been defined) then
  148. TCL_ERROR is returned and an error message is left in
  149. \fIinterp->result\fR.
  150. Note:  \fBTk_DefineBitmap\fR expects the memory pointed to by
  151. \fIsource\fR to be static:  \fBTk_DefineBitmap\fR doesn't make
  152. a private copy of this memory, but uses the bytes pointed to
  153. by \fIsource\fR later in calls to \fBTk_GetBitmap\fR.
  154. .VE
  155. .PP
  156. Typically \fBTk_DefineBitmap\fR is used by \fB#include\fR-ing a
  157. bitmap file directly into a C program and then referencing
  158. the variables defined by the file.
  159. For example, suppose there exists a file \fBstip.bitmap\fR,
  160. which was created by the \fBbitmap\fR program and contains
  161. a stipple pattern.
  162. The following code uses \fBTk_DefineBitmap\fR to define a
  163. new bitmap named \fBfoo\fR:
  164. .nf
  165. .RS
  166. \fCPixmap bitmap;
  167. #include "stip.bitmap"
  168. Tk_DefineBitmap(interp, Tk_GetUid("foo"), stip_bits,
  169.     stip_width, stip_height);
  170. \&...
  171. bitmap = Tk_GetBitmap(interp, tkwin, Tk_GetUid("foo"));\fR
  172. .RE
  173. .fi
  174. This code causes the bitmap file to be read
  175. at compile-time and incorporates the bitmap information into
  176. the program's executable image.  The same bitmap file could be
  177. read at run-time using \fBTk_GetBitmap\fR:
  178. .nf
  179. .RS
  180. \fCPixmap bitmap;
  181. bitmap = Tk_GetBitmap(interp, tkwin, Tk_GetUid("@stip.bitmap"));\fR
  182. .RE
  183. .fi
  184. The second form is a bit more flexible (the file could be modified
  185. after the program has been compiled, or a different string could be
  186. provided to read a different file), but it is a little slower and
  187. requires the bitmap file to exist separately from the program.
  188. .PP
  189. \fBTk_GetBitmap\fR maintains a
  190. database of all the bitmaps that have been created.
  191. Whenever possible, it will return an existing bitmap rather
  192. than creating a new one.
  193. This approach can substantially reduce server overhead, so
  194. \fBTk_GetBitmap\fR should generally be used in preference to Xlib
  195. procedures like \fBXReadBitmapFile\fR.
  196. .PP
  197. The bitmaps returned by \fBTk_GetBitmap\fR
  198. are shared, so callers should never modify them.
  199. If a bitmap must be modified dynamically, then it should be
  200. created by calling Xlib procedures such as \fBXReadBitmapFile\fR
  201. or \fBXCreatePixmap\fR directly.
  202. .PP
  203. The procedure \fBTk_NameOfBitmap\fR is roughly the inverse of
  204. \fBTk_GetBitmap\fR.
  205. Given an X Pixmap argument, it returns the \fIid\fR that was
  206. passed to \fBTk_GetBitmap\fR when the bitmap was created.
  207. .VS
  208. \fIBitmap\fR must have been the return value from a previous
  209. call to \fBTk_GetBitmap\fR.
  210. .VE
  211. .PP
  212. \fBTk_SizeOfBitmap\fR returns the dimensions of its \fIbitmap\fR
  213. .VS
  214. argument in the words pointed to by the \fIwidthPtr\fR and
  215. \fIheightPtr\fR arguments.  As with \fBTk_NameOfBitmap\fR,
  216. \fIbitmap\fR must have been created by \fBTk_GetBitmap\fR.
  217. .VE
  218. .PP
  219. When a bitmap returned by \fBTk_GetBitmap\fR
  220. is no longer needed, \fBTk_FreeBitmap\fR should be called to release it.
  221. There should be exactly one call to \fBTk_FreeBitmap\fR for
  222. each call to \fBTk_GetBitmap\fR.
  223. When a bitmap is no longer in use anywhere (i.e. it has been freed as
  224. many times as it has been gotten) \fBTk_FreeBitmap\fR will release
  225. it to the X server and delete it from the database.
  226.  
  227. .SH BUGS
  228. In determining whether an existing bitmap can be used to satisfy
  229. a new request, \fBTk_GetBitmap\fR
  230. considers only the immediate value of its \fIid\fR argument.  For
  231. example, when a file name is passed to \fBTk_GetBitmap\fR,
  232. \fBTk_GetBitmap\fR will assume it is safe to re-use an existing
  233. bitmap created from the same file name:  it will not check to
  234. see whether the file itself has changed, or whether the current
  235. directory has changed, thereby causing the name to refer to
  236. a different file.
  237.  
  238. .SH KEYWORDS
  239. bitmap, pixmap
  240.