OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tix/] [win/] [tixWinXpm.c] - Blame information for rev 1780

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/*
2
 * tixWinImgXpm.c --
3
 *
4
 *      Implement the Windows specific function calls for the pixmap
5
 *      image type.
6
 *
7
 * Copyright (c) 1996, Expert Interface Technologies
8
 *
9
 * See the file "license.terms" for information on usage and redistribution
10
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11
 *
12
 */
13
 
14
#include <tkInt.h>
15
#include <tkWinInt.h>
16
#include <tix.h>
17
#include <tixImgXpm.h>
18
 
19
typedef struct PixmapData {
20
    HDC bitmapDC;               /* Bitmap used on Windows platforms */
21
    HDC maskDC;                 /* Mask used on Windows platforms */
22
    HBITMAP bitmap, bitmapOld;
23
    HBITMAP maskBm, maskBmOld;
24
} PixmapData;
25
 
26
static void             CopyTransparent _ANSI_ARGS_((Display* display,
27
                            HDC srcDC, Drawable dest,
28
                            int src_x, int src_y, int width,
29
                            int height, int dest_x, int dest_y,
30
                            HDC maskDC));
31
 
32
 
33
/*----------------------------------------------------------------------
34
 * TixpInitPixmapInstance --
35
 *
36
 *      Initializes the platform-specific data of a pixmap instance
37
 *
38
 *----------------------------------------------------------------------
39
 */
40
 
41
void
42
TixpInitPixmapInstance(masterPtr, instancePtr)
43
    PixmapMaster *masterPtr;    /* Pointer to master for image. */
44
    PixmapInstance *instancePtr;/* The pixmap instance. */
45
{
46
    PixmapData * dataPtr;
47
 
48
    dataPtr = (PixmapData *)ckalloc(sizeof(PixmapData));
49
    dataPtr->maskDC = NULL;
50
    dataPtr->bitmapDC = NULL;
51
 
52
    instancePtr->clientData = (ClientData)dataPtr;
53
}
54
 
55
 
56
/*----------------------------------------------------------------------
57
 * TixpXpmAllocTmpBuffer --
58
 *
59
 *      Allocate a temporary space to draw the image.
60
 *
61
 *----------------------------------------------------------------------
62
 */
63
void
64
TixpXpmAllocTmpBuffer(masterPtr, instancePtr, imagePtr, maskPtr)
65
    PixmapMaster * masterPtr;
66
    PixmapInstance * instancePtr;
67
    XImage ** imagePtr;
68
    XImage ** maskPtr;
69
{
70
    XImage * image = NULL;              /* Unused. Always return NULL. */
71
    XImage * mask;
72
    Display *display = Tk_Display(instancePtr->tkwin);
73
    int depth;
74
    int maskSize;
75
    int i;
76
    int wordBits  = sizeof(WORD)*8;             /* # of bits in WORD */
77
    int wordBytes = sizeof(WORD)/sizeof(char);  /* # of bytes in WORD */
78
    int words_per_line;
79
 
80
    depth = Tk_Depth(instancePtr->tkwin);
81
 
82
    instancePtr->pixmap = Tk_GetPixmap(display,
83
        Tk_WindowId(instancePtr->tkwin),
84
        masterPtr->size[0], masterPtr->size[1], depth);
85
 
86
    mask = (XImage*)ckalloc(sizeof(XImage));
87
 
88
    mask->width = masterPtr->size[0];
89
    mask->height = masterPtr->size[1];
90
 
91
    /*
92
     * In Windows, each scan line in the the mask data must be aligned
93
     * to words. The padding bits must be zero'ed.
94
     */
95
    words_per_line = (mask->width + (wordBits-1))/wordBits;
96
    mask->bytes_per_line = words_per_line * wordBytes;
97
 
98
    maskSize = mask->bytes_per_line  * mask->height;
99
    mask->data = (char *)ckalloc(maskSize);
100
    for (i=0; i<maskSize; i++) {
101
        mask->data[i] = 0;
102
    }
103
 
104
    *imagePtr = image;
105
    *maskPtr = mask;
106
}
107
 
108
 
109
void
110
TixpXpmFreeTmpBuffer(masterPtr, instancePtr, image, mask)
111
    PixmapMaster * masterPtr;
112
    PixmapInstance * instancePtr;
113
    XImage * image;
114
    XImage * mask;
115
{
116
    if (image) {
117
        ckfree((char*)image->data);
118
        image->data = NULL;
119
        XDestroyImage(image);
120
    }
121
    if (mask) {
122
        ckfree((char*)mask->data);
123
        mask->data = NULL;
124
        ckfree((char*)mask);
125
    }
126
}
127
 
128
 
129
/*----------------------------------------------------------------------
130
 * TixpXpmSetPixel --
131
 *
132
 *      Sets the pixel at the given (x,y) coordinate to be the given
133
 *      color.
134
 *----------------------------------------------------------------------
135
 */
136
void
137
TixpXpmSetPixel(instancePtr, image, mask, x, y, colorPtr, isTranspPtr)
138
    PixmapInstance * instancePtr;
139
    XImage * image;
140
    XImage * mask;
141
    int x;
142
    int y;
143
    XColor * colorPtr;
144
    int * isTranspPtr;
145
{
146
    char * p;
147
    int n;
148
    GC gc;
149
    XGCValues gcValues;
150
    Display *display = Tk_Display(instancePtr->tkwin);
151
 
152
    if (colorPtr != NULL) {
153
        gcValues.foreground = colorPtr->pixel;
154
        gc = Tk_GetGC(instancePtr->tkwin, GCForeground, &gcValues);
155
        XDrawRectangle(display, instancePtr->pixmap, gc, x, y, 1, 1);
156
        Tk_FreeGC(display, gc);
157
    }
158
 
159
    p = mask->data;
160
    p+= y*(mask->bytes_per_line);
161
    p+= x/8;
162
    n = x%8;
163
 
164
    if (colorPtr != NULL) {
165
        *p |=  (1 << (7-n));
166
    } else {
167
        *p &= ~(1 << (7-n));
168
        *isTranspPtr = 1;
169
    }
170
}
171
 
172
/*----------------------------------------------------------------------
173
 * TixpXpmRealizePixmap --
174
 *
175
 *      On Unix:        Create the pixmap from the buffer.
176
 *      On Windows:     Free the mask if there are no transparent pixels.
177
 *----------------------------------------------------------------------
178
 */
179
void
180
TixpXpmRealizePixmap(masterPtr, instancePtr, image, mask, isTransp)
181
    PixmapMaster * masterPtr;
182
    PixmapInstance * instancePtr;
183
    XImage * image;
184
    XImage * mask;
185
{
186
    Display *display = Tk_Display(instancePtr->tkwin);
187
    PixmapData *dataPtr = (PixmapData*)instancePtr->clientData;
188
    HDC dc, bitmapDC;
189
    TkWinDCState dcState;
190
    HBITMAP bitmap, bitmapOld;
191
    int w, h;
192
 
193
    w = masterPtr->size[0];
194
    h = masterPtr->size[1];
195
 
196
    dc = TkWinGetDrawableDC(display, instancePtr->pixmap, &dcState);
197
    bitmapDC = CreateCompatibleDC(dc);
198
 
199
    bitmap = CreateCompatibleBitmap(dc, w, h);
200
    bitmapOld = SelectObject(bitmapDC, bitmap);
201
 
202
    BitBlt(bitmapDC, 0, 0, w, h, dc, 0, 0, SRCCOPY);
203
 
204
    if (isTransp) {
205
        HDC maskDC;
206
        HBITMAP maskBm, maskBmOld;
207
 
208
        /*
209
         * There are transparent pixels. We need a mask.
210
         */
211
        maskDC = CreateCompatibleDC(dc);
212
        maskBm = CreateBitmap(w, h, 1, 1, (CONST VOID*)mask->data);
213
        maskBmOld = SelectObject(maskDC, maskBm);
214
 
215
        BitBlt(bitmapDC, 0, 0, w, h, maskDC, 0, 0, SRCAND);
216
        BitBlt(maskDC,   0, 0, w, h, maskDC, 0, 0, NOTSRCCOPY);
217
 
218
        TkWinReleaseDrawableDC(instancePtr->pixmap, dc, &dcState);
219
        dataPtr->maskDC = maskDC;
220
        dataPtr->maskBm = maskBm;
221
        dataPtr->maskBmOld = maskBmOld;
222
    } else {
223
        dataPtr->maskDC = NULL;
224
    }
225
    dataPtr->bitmapDC = bitmapDC;
226
    dataPtr->bitmap = bitmap;
227
    dataPtr->bitmapOld = bitmapOld;
228
}
229
 
230
void
231
TixpXpmFreeInstanceData(instancePtr, delete, display)
232
    PixmapInstance *instancePtr;        /* Pixmap instance. */
233
    int delete;                         /* Should the instance data structure
234
                                         * be deleted as well? */
235
    Display * display;                  /* Unused on Windows. */
236
{
237
    PixmapData *dataPtr = (PixmapData*)instancePtr->clientData;
238
 
239
    if (dataPtr->maskDC != NULL) {
240
        DeleteObject(SelectObject(dataPtr->maskDC,
241
            dataPtr->maskBmOld));
242
        DeleteDC(dataPtr->maskDC);
243
        dataPtr->maskDC = NULL;
244
    }
245
    if (dataPtr->bitmapDC != NULL) {
246
        DeleteObject(SelectObject(dataPtr->bitmapDC,
247
            dataPtr->bitmapOld));
248
        DeleteDC(dataPtr->bitmapDC);
249
        dataPtr->bitmapDC = NULL;
250
    }
251
    if (delete) {
252
        ckfree((char*)dataPtr);
253
        instancePtr->clientData = NULL;
254
    }
255
}
256
 
257
void
258
TixpXpmDisplay(clientData, display, drawable, imageX, imageY, width,
259
        height, drawableX, drawableY)
260
    ClientData clientData;      /* Pointer to PixmapInstance structure for
261
                                 * for instance to be displayed. */
262
    Display *display;           /* Display on which to draw image. */
263
    Drawable drawable;          /* Pixmap or window in which to draw image. */
264
    int imageX, imageY;         /* Upper-left corner of region within image
265
                                 * to draw. */
266
    int width, height;          /* Dimensions of region within image to draw.*/
267
    int drawableX, drawableY;   /* Coordinates within drawable that
268
                                 * correspond to imageX and imageY. */
269
{
270
    PixmapInstance *instancePtr = (PixmapInstance *) clientData;
271
    PixmapData *dataPtr = (PixmapData*)instancePtr->clientData;
272
 
273
    CopyTransparent(display, dataPtr->bitmapDC, drawable,
274
        imageX, imageY, width, height,
275
        drawableX, drawableY, dataPtr->maskDC);
276
}
277
 
278
static void
279
CopyTransparent(display, srcDC, dest, src_x, src_y, width, height, dest_x,
280
        dest_y, maskDC)
281
    Display* display;
282
    HDC srcDC;
283
    Drawable dest;
284
    int src_x;
285
    int src_y;
286
    int width;
287
    int height;
288
    int dest_x;
289
    int dest_y;
290
    HDC maskDC;
291
{
292
    HDC destDC;
293
    TkWinDCState destState;
294
 
295
    destDC = TkWinGetDrawableDC(display, dest, &destState);
296
 
297
    if (maskDC) {
298
        BitBlt(destDC, dest_x, dest_y, width, height, maskDC, src_x, src_y,
299
            SRCAND);
300
        BitBlt(destDC, dest_x, dest_y, width, height, srcDC, src_x, src_y,
301
            SRCPAINT);
302
    } else {
303
        BitBlt(destDC, dest_x, dest_y, width, height, srcDC, src_x, src_y,
304
            SRCCOPY);
305
    }
306
 
307
    TkWinReleaseDrawableDC(dest, destDC, &destState);
308
}
309
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.