| 1 |
# Copyright (c) 1994 The Regents of the University of California. |
| 2 |
# Copyright (c) 1994-1997 Sun Microsystems, Inc. |
| 3 |
# See the file "license.terms" for information on usage and redistribution |
| 4 |
# of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 5 |
# |
| 6 |
# |
| 7 |
|
| 8 |
=head1 NAME |
| 9 |
|
| 10 |
Tk_CreateImageType, Tk_GetImageMasterData - define new kind of image |
| 11 |
|
| 12 |
=for category C Programming |
| 13 |
|
| 14 |
=head1 SYNOPSIS |
| 15 |
|
| 16 |
B<#include E<lt>tk.hE<gt>> |
| 17 |
|
| 18 |
B<Tk_CreateImageType>(I<typePtr>) |
| 19 |
ClientData |
| 20 |
|
| 21 |
B<Tk_GetImageMasterData>(I<interp, name, typePtrPtr>) |
| 22 |
|
| 23 |
=head1 ARGUMENTS |
| 24 |
|
| 25 |
=over 4 |
| 26 |
|
| 27 |
=item Tk_ImageType *typePtr (in) |
| 28 |
|
| 29 |
Structure that defines the new type of image. |
| 30 |
Must be static: a |
| 31 |
pointer to this structure is retained by the image code. |
| 32 |
|
| 33 |
=item Tcl_Interp *interp (in) |
| 34 |
|
| 35 |
Interpreter in which image was created. |
| 36 |
|
| 37 |
=item char *name (in) |
| 38 |
|
| 39 |
Name of existing image. |
| 40 |
|
| 41 |
=item Tk_ImageType **typePtrPtr (out) |
| 42 |
|
| 43 |
Points to word in which to store a pointer to type information for |
| 44 |
the given image, if it exists. |
| 45 |
|
| 46 |
=back |
| 47 |
|
| 48 |
=head1 DESCRIPTION |
| 49 |
|
| 50 |
B<Tk_CreateImageType> is invoked to define a new kind of image. |
| 51 |
An image type corresponds to a particular value of the I<type> |
| 52 |
argument for the B<image create> command. There may exist |
| 53 |
any number of different image types, and new types may be defined |
| 54 |
dynamically by calling B<Tk_CreateImageType>. |
| 55 |
For example, there might be one type for 2-color bitmaps, |
| 56 |
another for multi-color images, another for dithered images, |
| 57 |
another for video, and so on. |
| 58 |
|
| 59 |
The code that implements a new image type is called an |
| 60 |
I<image manager>. |
| 61 |
It consists of a collection of procedures plus three different |
| 62 |
kinds of data structures. |
| 63 |
The first data structure is a Tk_ImageType structure, which contains |
| 64 |
the name of the image type and pointers to five procedures provided |
| 65 |
by the image manager to deal with images of this type: |
| 66 |
|
| 67 |
typedef struct Tk_ImageType { |
| 68 |
char *name; |
| 69 |
Tk_ImageCreateProc *createProc; |
| 70 |
Tk_ImageGetProc *getProc; |
| 71 |
Tk_ImageDisplayProc *displayProc; |
| 72 |
Tk_ImageFreeProc *freeProc; |
| 73 |
Tk_ImageDeleteProc *deleteProc; |
| 74 |
} Tk_ImageType; |
| 75 |
|
| 76 |
The fields of this structure will be described in later subsections |
| 77 |
of this entry. |
| 78 |
|
| 79 |
The second major data structure manipulated by an image manager |
| 80 |
is called an I<image master>; it contains overall information |
| 81 |
about a particular image, such as the values of the configuration |
| 82 |
options specified in an B<image create> command. |
| 83 |
There will usually be one of these structures for each |
| 84 |
invocation of the B<image create> command. |
| 85 |
|
| 86 |
The third data structure related to images is an I<image instance>. |
| 87 |
There will usually be one of these structures for each usage of an |
| 88 |
image in a particular widget. |
| 89 |
It is possible for a single image to appear simultaneously |
| 90 |
in multiple widgets, or even multiple times in the same widget. |
| 91 |
Furthermore, different instances may be on different screens |
| 92 |
or displays. |
| 93 |
The image instance data structure describes things that may |
| 94 |
vary from instance to instance, such as colors and graphics |
| 95 |
contexts for redisplay. |
| 96 |
There is usually one instance structure for each B<-image> |
| 97 |
option specified for a widget or canvas item. |
| 98 |
|
| 99 |
The following subsections describe the fields of a Tk_ImageType |
| 100 |
in more detail. |
| 101 |
|
| 102 |
=head1 B<name> |
| 103 |
|
| 104 |
I<typePtr-E<gt>name> provides a name for the image type. |
| 105 |
Once B<Tk_CreateImageType> returns, this name may be used |
| 106 |
in B<image create> commands to create images of the new |
| 107 |
type. |
| 108 |
If there already existed an image type by this name then |
| 109 |
the new image type replaces the old one. |
| 110 |
|
| 111 |
=for category Tk Library Procedures |
| 112 |
|
| 113 |
=head1 CREATEPROC |
| 114 |
|
| 115 |
I<typePtr-E<gt>createProc> provides the address of a procedure for |
| 116 |
Tk to call whenever B<image create> is invoked to create |
| 117 |
an image of the new type. |
| 118 |
I<typePtr-E<gt>createProc> must match the following prototype: |
| 119 |
|
| 120 |
typedef int Tk_ImageCreateProc( |
| 121 |
Tcl_Interp *interp, |
| 122 |
char *name, |
| 123 |
int argc, |
| 124 |
char **argv, |
| 125 |
Tk_ImageType *typePtr, |
| 126 |
Tk_ImageMaster master, |
| 127 |
ClientData *masterDataPtr); |
| 128 |
|
| 129 |
The I<interp> argument is the interpreter in which the B<image> |
| 130 |
command was invoked, and I<name> is the name for the new image, |
| 131 |
which was either specified explicitly in the B<image> command |
| 132 |
or generated automatically by the B<image> command. |
| 133 |
The I<argc> and I<argv> arguments describe all the configuration |
| 134 |
options for the new image (everything after the name argument to |
| 135 |
B<image>). |
| 136 |
The I<master> argument is a token that refers to Tk's information |
| 137 |
about this image; the image manager must return this token to |
| 138 |
Tk when invoking the B<Tk_ImageChanged> procedure. |
| 139 |
Typically I<createProc> will parse I<argc> and I<argv> |
| 140 |
and create an image master data structure for the new image. |
| 141 |
I<createProc> may store an arbitrary one-word value at |
| 142 |
*I<masterDataPtr>, which will be passed back to the |
| 143 |
image manager when other callbacks are invoked. |
| 144 |
Typically the value is a pointer to the master data |
| 145 |
structure for the image. |
| 146 |
|
| 147 |
If I<createProc> encounters an error, it should leave an error |
| 148 |
message in I<interp-E<gt>result> and return B<TCL_ERROR>; otherwise |
| 149 |
it should return B<TCL_OK>. |
| 150 |
|
| 151 |
I<createProc> should call B<Tk_ImageChanged> in order to set the |
| 152 |
size of the image and request an initial redisplay. |
| 153 |
|
| 154 |
=head1 GETPROC |
| 155 |
|
| 156 |
I<typePtr-E<gt>getProc> is invoked by Tk whenever a widget |
| 157 |
calls B<Tk_GetImage> to use a particular image. |
| 158 |
This procedure must match the following prototype: |
| 159 |
|
| 160 |
typedef ClientData Tk_ImageGetProc( |
| 161 |
Tk_Window tkwin, |
| 162 |
ClientData masterData); |
| 163 |
|
| 164 |
The I<tkwin> argument identifies the window in which the |
| 165 |
image will be used and I<masterData> is the value |
| 166 |
returned by I<createProc> when the image master was created. |
| 167 |
I<getProc> will usually create a data structure for the new |
| 168 |
instance, including such things as the resources needed to |
| 169 |
display the image in the given window. |
| 170 |
I<getProc> returns a one-word token for the instance, which |
| 171 |
is typically the address of the instance data structure. |
| 172 |
Tk will pass this value back to the image manager when invoking |
| 173 |
its I<displayProc> and I<freeProc> procedures. |
| 174 |
|
| 175 |
=head1 DISPLAYPROC |
| 176 |
|
| 177 |
I<typePtr-E<gt>displayProc> is invoked by Tk whenever an image needs |
| 178 |
to be displayed (i.e., whenever a widget calls B<Tk_RedrawImage>). |
| 179 |
I<displayProc> must match the following prototype: |
| 180 |
|
| 181 |
typedef void Tk_ImageDisplayProc( |
| 182 |
ClientData instanceData, |
| 183 |
Display *display, |
| 184 |
Drawable drawable, |
| 185 |
int imageX, |
| 186 |
int imageY, |
| 187 |
int width, |
| 188 |
int height, |
| 189 |
int drawableX, |
| 190 |
int drawableY); |
| 191 |
|
| 192 |
The I<instanceData> will be the same as the value returned by |
| 193 |
I<getProc> when the instance was created. |
| 194 |
I<display> and I<drawable> indicate where to display the |
| 195 |
image; I<drawable> may be a pixmap rather than |
| 196 |
the window specified to I<getProc> (this is usually the case, |
| 197 |
since most widgets double-buffer their redisplay to get smoother |
| 198 |
visual effects). |
| 199 |
I<imageX>, I<imageY>, I<width>, and I<height> |
| 200 |
identify the region of the image that must be redisplayed. |
| 201 |
This region will always be within the size of the image |
| 202 |
as specified in the most recent call to B<Tk_ImageChanged>. |
| 203 |
I<drawableX> and I<drawableY> indicate where in I<drawable> |
| 204 |
the image should be displayed; I<displayProc> should display |
| 205 |
the given region of the image so that point (I<imageX>, I<imageY>) |
| 206 |
in the image appears at (I<drawableX>, I<drawableY>) in I<drawable>. |
| 207 |
|
| 208 |
=head1 FREEPROC |
| 209 |
|
| 210 |
I<typePtr-E<gt>freeProc> contains the address of a procedure that |
| 211 |
Tk will invoke when an image instance is released (i.e., when |
| 212 |
B<Tk_FreeImage> is invoked). |
| 213 |
This can happen, for example, when a widget is deleted or a image item |
| 214 |
in a canvas is deleted, or when the image displayed in a widget or |
| 215 |
canvas item is changed. |
| 216 |
I<freeProc> must match the following prototype: |
| 217 |
|
| 218 |
typedef void Tk_ImageFreeProc( |
| 219 |
ClientData instanceData, |
| 220 |
Display *display); |
| 221 |
|
| 222 |
The I<instanceData> will be the same as the value returned by |
| 223 |
I<getProc> when the instance was created, and I<display> |
| 224 |
is the display containing the window for the instance. |
| 225 |
I<freeProc> should release any resources associated with the |
| 226 |
image instance, since the instance will never be used again. |
| 227 |
|
| 228 |
=head1 DELETEPROC |
| 229 |
|
| 230 |
I<typePtr-E<gt>deleteProc> is a procedure that Tk invokes when an |
| 231 |
image is being deleted (i.e. when the B<image delete> command |
| 232 |
is invoked). |
| 233 |
Before invoking I<deleteProc> Tk will invoke I<freeProc> for |
| 234 |
each of the image's instances. |
| 235 |
I<deleteProc> must match the following prototype: |
| 236 |
|
| 237 |
typedef void Tk_ImageDeleteProc( |
| 238 |
ClientData masterData); |
| 239 |
|
| 240 |
The I<masterData> argument will be the same as the value |
| 241 |
stored in I<*masterDataPtr> by I<createProc> when the |
| 242 |
image was created. |
| 243 |
I<deleteProc> should release any resources associated with |
| 244 |
the image. |
| 245 |
|
| 246 |
=head1 TK_GETIMAGEMASTERDATA |
| 247 |
|
| 248 |
The procedure B<Tk_GetImageMasterData> may be invoked to retrieve |
| 249 |
information about an image. For example, an image manager can use this |
| 250 |
procedure to locate its image master data for an image. |
| 251 |
If there exists an image named I<name> |
| 252 |
in the interpreter given by I<interp>, then I<*typePtrPtr> is |
| 253 |
filled in with type information for the image (the I<typePtr> value |
| 254 |
passed to B<Tk_CreateImageType> when the image type was registered) |
| 255 |
and the return value is the ClientData value returned by the |
| 256 |
I<createProc> when the image was created (this is typically a |
| 257 |
pointer to the image master data structure). If no such image exists |
| 258 |
then NULL is returned and NULL is stored at I<*typePtrPtr>. |
| 259 |
|
| 260 |
=head1 SEE ALSO |
| 261 |
|
| 262 |
L<Tk::ImgChanged>, L<Tk::GetImage>, L<Tk::GetImage>, L<Tk::GetImage>, L<Tk::GetImage> |
| 263 |
|
| 264 |
=head1 KEYWORDS |
| 265 |
|
| 266 |
image manager, image type, instance, master |