1Tk_CreateImageType(3)        Tk Library Procedures       Tk_CreateImageType(3)
2
3
4
5______________________________________________________________________________
6

NAME

8       Tk_CreateImageType,  Tk_GetImageMasterData,  Tk_InitImageArgs  - define
9       new kind of image
10

SYNOPSIS

12       #include <tk.h>
13
14       Tk_CreateImageType(typePtr)
15
16       ClientData                                                              │
17       Tk_GetImageMasterData(interp, name, typePtrPtr)                         │
18
19       Tk_InitImageArgs(interp, argc, argvPtr)                                 │
20

ARGUMENTS │

22       Tk_ImageType   *typePtr      (in)                                       │
23                                              Structure that defines  the  new │
24                                              type  of image.  Must be static: │
25                                              a pointer to this  structure  is │
26                                              retained by the image code.      │
27
28       Tcl_Interp     *interp       (in)                                       │
29                                              Interpreter  in  which image was │
30                                              created.                         │
31
32       CONST char     *name         (in)                                       │
33                                              Name of existing image.          │
34
35       Tk_ImageType   **typePtrPtr  (out)                                      │
36                                              Points to word in which to store │
37                                              a  pointer  to  type information │
38                                              for  the  given  image,  if   it │
39                                              exists.                          │
40
41       int            argc          (in)                                       │
42                                              Number of arguments              │
43
44       char           ***argvPtr    (in/out)                                   │
45                                              Pointer to argument list
46_________________________________________________________________
47
48

DESCRIPTION

50       Tk_CreateImageType  is invoked to define a new kind of image.  An image
51       type corresponds to a particular value of the  type  argument  for  the
52       image  create  command.   There may exist any number of different image
53       types, and new types may be defined dynamically by calling Tk_CreateIm‐
54       ageType.   For  example,  there  might be one type for 2-color bitmaps,
55       another for multi-color images, another for  dithered  images,  another
56       for video, and so on.
57
58       The  code  that implements a new image type is called an image manager.
59       It consists of a collection of procedures plus three different kinds of
60       data structures.  The first data structure is a Tk_ImageType structure,
61       which contains the name of the image type and pointers to  five  proce‐
62       dures provided by the image manager to deal with images of this type:
63              typedef struct Tk_ImageType {
64                char *name;
65                Tk_ImageCreateProc *createProc;
66                Tk_ImageGetProc *getProc;
67                Tk_ImageDisplayProc *displayProc;
68                Tk_ImageFreeProc *freeProc;
69                Tk_ImageDeleteProc *deleteProc;
70              } Tk_ImageType;
71       The  fields of this structure will be described in later subsections of
72       this entry.
73
74       The second major data structure manipulated  by  an  image  manager  is
75       called  an  image master;  it contains overall information about a par‐
76       ticular image, such as the values of the configuration  options  speci‐
77       fied  in  an  image create command.  There will usually be one of these
78       structures for each invocation of the image create command.
79
80       The third data structure related to images is an image instance.  There
81       will usually be one of these structures for each usage of an image in a
82       particular widget.  It is possible for a single image to appear  simul‐
83       taneously  in multiple widgets, or even multiple times in the same wid‐
84       get.  Furthermore, different instances may be on different  screens  or
85       displays.   The image instance data structure describes things that may
86       vary from instance to instance, such as colors  and  graphics  contexts
87       for redisplay.  There is usually one instance structure for each -image
88       option specified for a widget or canvas item.
89
90       The following subsections describe the fields of a Tk_ImageType in more
91       detail.
92
93

NAME

95       typePtr->name  provides  a  name for the image type.  Once Tk_CreateIm‐
96       ageType returns, this name may be used in image create commands to cre‐
97       ate  images of the new type.  If there already existed an image type by
98       this name then the new image type replaces the old one.
99
100

PORTABILITY

102       In Tk 8.2 and earlier, the createProc below had a different  signature.
103       If  you  want  to  compile  an image type using the old interface which
104       should still run on all Tcl/Tk  versions,  compile  it  with  the  flag
105       -DUSE_OLD_IMAGE.  Further  on, if you are using Stubs, you need to call
106       the function Tk_InitImageArgs(interp, argc, &argv) first in  your  cre‐
107       ateProc. See below for a description of this function.
108
109

CREATEPROC

111       typePtr->createProc  provides the address of a procedure for Tk to call
112       whenever image create is invoked to create an image of  the  new  type.
113       typePtr->createProc must match the following prototype:
114              typedef int Tk_ImageCreateProc(
115                Tcl_Interp *interp,
116                char *name,
117                int objc,
118                Tcl_Obj *CONST objv[],
119                Tk_ImageType *typePtr,
120                Tk_ImageMaster master,
121                ClientData *masterDataPtr);
122       The  interp  argument is the interpreter in which the image command was
123       invoked, and name is the name for the new image, which was either spec‐
124       ified explicitly in the image command or generated automatically by the
125       image command.  The objc and objv arguments describe all the configura‐
126       tion  options  for the new image (everything after the name argument to
127       image).  The master argument is a token that refers to Tk's information
128       about  this image;  the image manager must return this token to Tk when
129       invoking the  Tk_ImageChanged  procedure.   Typically  createProc  will
130       parse  objc  and objv and create an image master data structure for the
131       new image.  createProc may store an arbitrary one-word value  at  *mas‐
132       terDataPtr,  which  will be passed back to the image manager when other
133       callbacks are invoked.  Typically the value is a pointer to the  master
134       data structure for the image.
135
136       If  createProc encounters an error, it should leave an error message in
137       interp->result  and  return  TCL_ERROR;   otherwise  it  should  return
138       TCL_OK.
139
140       createProc  should call Tk_ImageChanged in order to set the size of the
141       image and request an initial redisplay.
142
143

GETPROC

145       typePtr->getProc is invoked by Tk whenever a widget  calls  Tk_GetImage
146       to  use  a  particular  image.  This procedure must match the following
147       prototype:
148              typedef ClientData Tk_ImageGetProc(
149                Tk_Window tkwin,
150                ClientData masterData);
151       The tkwin argument identifies the window in which  the  image  will  be
152       used  and masterData is the value returned by createProc when the image
153       master was created.  getProc will usually create a data  structure  for
154       the new instance, including such things as the resources needed to dis‐
155       play the image in the given window.  getProc returns a  one-word  token
156       for  the  instance, which is typically the address of the instance data
157       structure.  Tk will pass this value back  to  the  image  manager  when
158       invoking its displayProc and freeProc procedures.
159
160

DISPLAYPROC

162       typePtr->displayProc  is  invoked  by  Tk whenever an image needs to be
163       displayed (i.e., whenever a widget calls Tk_RedrawImage).   displayProc
164       must match the following prototype:
165              typedef void Tk_ImageDisplayProc(
166                ClientData instanceData,
167                Display *display,
168                Drawable drawable,
169                int imageX,
170                int imageY,
171                int width,
172                int height,
173                int drawableX,
174                int drawableY);
175       The instanceData will be the same as the value returned by getProc when
176       the instance was created.  display and drawable indicate where to  dis‐
177       play the image;  drawable may be a pixmap rather than the window speci‐
178       fied to getProc (this is usually the case, since most  widgets  double-
179       buffer  their  redisplay  to  get  smoother  visual  effects).  imageX,
180       imageY, width, and height identify the region of the image that must be
181       redisplayed.   This  region will always be within the size of the image
182       as specified in the most recent call to Tk_ImageChanged.  drawableX and
183       drawableY  indicate  where  in  drawable the image should be displayed;
184       displayProc should display the given region of the image so that  point
185       (imageX,  imageY)  in  the  image  appears at (drawableX, drawableY) in
186       drawable.
187
188

FREEPROC

190       typePtr->freeProc contains the address of  a  procedure  that  Tk  will
191       invoke  when  an image instance is released (i.e., when Tk_FreeImage is
192       invoked).  This can happen, for example, when a widget is deleted or  a
193       image  item  in  a  canvas is deleted, or when the image displayed in a
194       widget or canvas item is changed.  freeProc must  match  the  following
195       prototype:
196              typedef void Tk_ImageFreeProc(
197                ClientData instanceData,
198                Display *display);
199       The instanceData will be the same as the value returned by getProc when
200       the instance was created, and display is  the  display  containing  the
201       window for the instance.  freeProc should release any resources associ‐
202       ated with the image instance, since the instance  will  never  be  used
203       again.
204
205

DELETEPROC

207       typePtr->deleteProc  is  a  procedure  that Tk invokes when an image is
208       being deleted (i.e. when the image delete command is invoked).   Before
209       invoking  deleteProc  Tk  will  invoke freeProc for each of the image's
210       instances.  deleteProc must match the following prototype:
211              typedef void Tk_ImageDeleteProc(
212                ClientData masterData);
213       The masterData argument will be the same as the value stored  in  *mas‐
214       terDataPtr by createProc when the image was created.  deleteProc should
215       release any resources associated with the image.
216
217

TK_GETIMAGEMASTERDATA

219       The procedure Tk_GetImageMasterData may be invoked to retrieve informa‐ │
220       tion about an image.  For example, an image manager can use this proce‐ │
221       dure to locate its image master data for an image.  If there exists  an │
222       image  named  name in the interpreter given by interp, then *typePtrPtr
223       is filled in with type information for the  image  (the  typePtr  value │
224       passed  to  Tk_CreateImageType  when the image type was registered) and │
225       the return value is the ClientData value  returned  by  the  createProc
226       when  the  image  was created (this is typically a pointer to the image │
227       master data structure).  If no such image exists then NULL is  returned │
228       and NULL is stored at *typePtrPtr.
229
230

TK_INITIMAGEARGS

232       The  function Tk_InitImageArgs converts the arguments of the createProc 
233       from objects to strings when necessary. When not using stubs, not using │
234       the old interface, or running under an older (pre-8.3) Tk version, this │
235       function has no effect. This function makes porting  older  image  han‐ │
236       dlers  to  the new interface a lot easier: After running this function, │
237       the arguments are guaranteed to be in string format, no matter  how  Tk │
238       deliverd them.                                                          │
239
240

SEE ALSO │

242       Tk_ImageChanged,  Tk_GetImage,  Tk_FreeImage,  Tk_RedrawImage, Tk_Size‐ │
243       OfImage                                                                 │
244
245

KEYWORDS │

247       image manager, image type, instance, master                             │
248
249
250
251Tk                                    8.3                Tk_CreateImageType(3)
Impressum