Release 980201
[wine/multimedia.git] / windows / graphics.c
blobe3e1d2579ddad012b6227808534e56e7cd26e4ea
1 /*
2 * X-specific shortcuts to speed up WM code.
3 * No coordinate transformations except origin translation.
5 * Copyright 1993, 1994 Alexandre Julliard
6 */
8 #include <assert.h>
9 #include <stdlib.h>
10 #include "ts_xlib.h"
11 #include "ts_xutil.h"
12 #include <X11/Intrinsic.h>
13 #include "graphics.h"
14 #include "color.h"
15 #include "bitmap.h"
16 #include "gdi.h"
17 #include "dc.h"
19 #define MAX_DRAWLINES 8
22 /**********************************************************************
23 * GRAPH_DrawLines
25 * Draw multiple unconnected lines (limited by MAX_DRAWLINES).
27 BOOL32 GRAPH_DrawLines( HDC32 hdc, LPPOINT32 pXY, INT32 N, HPEN32 hPen )
29 BOOL32 bRet = FALSE;
30 DC* dc;
32 assert( N <= MAX_DRAWLINES );
33 if( (dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC )) )
35 HPEN32 hPrevPen = 0;
37 if( hPen ) hPrevPen = SelectObject32( hdc, hPen );
38 if( DC_SetupGCForPen( dc ) )
40 XSegment l[MAX_DRAWLINES];
41 INT32 i, j;
43 for( i = 0; i < N; i++ )
45 j = 2 * i;
46 l[i].x1 = pXY[j].x + dc->w.DCOrgX;
47 l[i].x2 = pXY[j + 1].x + dc->w.DCOrgX;
48 l[i].y1 = pXY[j].y + dc->w.DCOrgY;
49 l[i].y2 = pXY[j + 1].y + dc->w.DCOrgY;
51 TSXDrawSegments( display, dc->u.x.drawable, dc->u.x.gc, l, N );
52 bRet = TRUE;
54 if( hPrevPen ) SelectObject32( hdc, hPrevPen );
56 return bRet;
59 /**********************************************************************
61 * GRAPH_DrawBitmap
63 * Short-cut function to blit a bitmap into a device.
64 * Faster than CreateCompatibleDC() + SelectBitmap() + BitBlt() + DeleteDC().
66 BOOL32 GRAPH_DrawBitmap( HDC32 hdc, HBITMAP32 hbitmap,
67 INT32 xdest, INT32 ydest, INT32 xsrc, INT32 ysrc,
68 INT32 width, INT32 height, BOOL32 bMono )
70 BITMAPOBJ *bmp;
71 DC *dc;
73 if (!(dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ))) return FALSE;
74 if (!(bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC )))
75 return FALSE;
77 xdest += dc->w.DCOrgX; ydest += dc->w.DCOrgY;
79 TSXSetFunction( display, dc->u.x.gc, GXcopy );
80 if (bmp->bitmap.bmBitsPixel == 1)
82 TSXSetForeground( display, dc->u.x.gc, dc->w.backgroundPixel );
83 TSXSetBackground( display, dc->u.x.gc, dc->w.textPixel );
84 TSXCopyPlane( display, bmp->pixmap, dc->u.x.drawable, dc->u.x.gc,
85 xsrc, ysrc, width, height, xdest, ydest, 1 );
87 else if (bmp->bitmap.bmBitsPixel == dc->w.bitsPerPixel)
89 if( bMono )
91 INT32 plane;
93 if( COLOR_GetMonoPlane(&plane) )
95 TSXSetForeground( display, dc->u.x.gc, dc->w.backgroundPixel );
96 TSXSetBackground( display, dc->u.x.gc, dc->w.textPixel );
98 else
100 TSXSetForeground( display, dc->u.x.gc, dc->w.textPixel );
101 TSXSetBackground( display, dc->u.x.gc, dc->w.backgroundPixel );
103 TSXCopyPlane( display, bmp->pixmap, dc->u.x.drawable, dc->u.x.gc,
104 xsrc, ysrc, width, height, xdest, ydest, plane );
106 else
107 TSXCopyArea( display, bmp->pixmap, dc->u.x.drawable,
108 dc->u.x.gc, xsrc, ysrc, width, height, xdest, ydest );
110 else
112 GDI_HEAP_UNLOCK( hbitmap );
113 return FALSE;
116 GDI_HEAP_UNLOCK( hbitmap );
117 return TRUE;
121 /**********************************************************************
122 * GRAPH_DrawReliefRect
124 * Used in the standard control code for button edge drawing.
126 void GRAPH_DrawReliefRect( HDC32 hdc, const RECT32 *rect, INT32 highlight_size,
127 INT32 shadow_size, BOOL32 pressed )
129 if(pressed)
130 GRAPH_DrawGenericReliefRect(hdc, rect, highlight_size, shadow_size,
131 GetSysColorBrush32(COLOR_BTNSHADOW),
132 GetSysColorBrush32(COLOR_BTNHIGHLIGHT));
133 else
134 GRAPH_DrawGenericReliefRect(hdc, rect, highlight_size, shadow_size,
135 GetSysColorBrush32(COLOR_BTNHIGHLIGHT),
136 GetSysColorBrush32(COLOR_BTNSHADOW));
138 return;
142 /******************************************************************************
143 * GRAPH_DrawGenericReliefRect
145 * Creates a rectangle with the specified highlight and shadow colors.
146 * Adapted from DrawReliefRect (which is somewhat misnamed).
148 void GRAPH_DrawGenericReliefRect(
149 HDC32 hdc,
150 const RECT32 *rect,
151 INT32 highlight_size,
152 INT32 shadow_size,
153 HBRUSH32 highlight,
154 HBRUSH32 shadow )
156 DC* dc;
157 HBRUSH32 hPrevBrush;
158 INT32 w, h;
159 RECT32 r = *rect;
161 if (!(dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ))) return;
163 OffsetRect32( &r, dc->w.DCOrgX, dc->w.DCOrgY);
164 h = rect->bottom - rect->top; w = rect->right - rect->left;
166 hPrevBrush = SelectObject32(hdc, highlight);
168 if ( DC_SetupGCForBrush( dc ) )
170 INT32 i;
172 TSXSetFunction( display, dc->u.x.gc, GXcopy );
173 for (i = 0; i < highlight_size; i++)
175 TSXFillRectangle( display, dc->u.x.drawable, dc->u.x.gc,
176 r.left + i, r.top, 1, h - i );
177 TSXFillRectangle( display, dc->u.x.drawable, dc->u.x.gc,
178 r.left, r.top + i, w - i, 1 );
182 SelectObject32( hdc, shadow );
183 if ( DC_SetupGCForBrush( dc ) )
185 INT32 i;
187 TSXSetFunction( display, dc->u.x.gc, GXcopy );
188 for (i = 0; i < shadow_size; i++)
190 TSXFillRectangle( display, dc->u.x.drawable, dc->u.x.gc,
191 r.right - i - 1, r.top + i, 1, h - i );
192 TSXFillRectangle( display, dc->u.x.drawable, dc->u.x.gc,
193 r.left + i, r.bottom - i - 1, w - i, 1 );
197 SelectObject32( hdc, hPrevBrush );
202 /**********************************************************************
203 * GRAPH_DrawRectangle
205 void GRAPH_DrawRectangle( HDC32 hdc, INT32 x, INT32 y,
206 INT32 w, INT32 h, HPEN32 hPen )
208 DC* dc;
210 if( (dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC )) )
212 HPEN32 hPrevPen = 0;
214 if( hPen ) hPrevPen = SelectObject32( hdc, hPen );
215 if( DC_SetupGCForPen( dc ) )
216 TSXDrawRectangle( display, dc->u.x.drawable, dc->u.x.gc,
217 x + dc->w.DCOrgX, y + dc->w.DCOrgY, w - 1, h - 1);
218 if( hPrevPen ) SelectObject32( hdc, hPrevPen );
222 /**********************************************************************
223 * GRAPH_SelectClipMask
225 BOOL32 GRAPH_SelectClipMask( HDC32 hdc, HBITMAP32 hMonoBitmap, INT32 x, INT32 y)
227 BITMAPOBJ *bmp = NULL;
228 DC *dc;
230 if (!(dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ))) return FALSE;
231 if ( hMonoBitmap )
233 if ( !(bmp = (BITMAPOBJ *) GDI_GetObjPtr( hMonoBitmap, BITMAP_MAGIC))
234 || bmp->bitmap.bmBitsPixel != 1 ) return FALSE;
236 TSXSetClipOrigin( display, dc->u.x.gc, dc->w.DCOrgX + x, dc->w.DCOrgY + y);
239 TSXSetClipMask( display, dc->u.x.gc, (bmp) ? bmp->pixmap : None );
241 GDI_HEAP_UNLOCK( hMonoBitmap );
242 return TRUE;