Moved VGA-emulating DirectX code from dispdib.c to a separate
[wine/multimedia.git] / windows / graphics.c
blobc949f466acc9c67cffba3aecbe84336529e69948
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 );
55 GDI_HEAP_UNLOCK( hdc );
57 return bRet;
60 /**********************************************************************
62 * GRAPH_DrawBitmap
64 * Short-cut function to blit a bitmap into a device.
65 * Faster than CreateCompatibleDC() + SelectBitmap() + BitBlt() + DeleteDC().
67 BOOL32 GRAPH_DrawBitmap( HDC32 hdc, HBITMAP32 hbitmap,
68 INT32 xdest, INT32 ydest, INT32 xsrc, INT32 ysrc,
69 INT32 width, INT32 height, BOOL32 bMono )
71 BITMAPOBJ *bmp;
72 DC *dc;
73 BOOL32 ret = TRUE;
74 X11DRV_PHYSBITMAP *pbitmap;
76 if (!(dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ))) return FALSE;
77 if (!(bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC )))
79 GDI_HEAP_UNLOCK( hdc );
80 return FALSE;
83 pbitmap = bmp->DDBitmap->physBitmap;
85 xdest += dc->w.DCOrgX; ydest += dc->w.DCOrgY;
87 TSXSetFunction( display, dc->u.x.gc, GXcopy );
88 if (bmp->bitmap.bmBitsPixel == 1)
90 TSXSetForeground( display, dc->u.x.gc, dc->u.x.backgroundPixel );
91 TSXSetBackground( display, dc->u.x.gc, dc->u.x.textPixel );
92 TSXCopyPlane( display, pbitmap->pixmap, dc->u.x.drawable, dc->u.x.gc,
93 xsrc, ysrc, width, height, xdest, ydest, 1 );
95 else if (bmp->bitmap.bmBitsPixel == dc->w.bitsPerPixel)
97 if( bMono )
99 INT32 plane;
101 if( COLOR_GetMonoPlane(&plane) )
103 TSXSetForeground(display, dc->u.x.gc, dc->u.x.backgroundPixel);
104 TSXSetBackground(display, dc->u.x.gc, dc->u.x.textPixel);
106 else
108 TSXSetForeground(display, dc->u.x.gc, dc->u.x.textPixel);
109 TSXSetBackground(display, dc->u.x.gc, dc->u.x.backgroundPixel);
111 TSXCopyPlane( display, pbitmap->pixmap, dc->u.x.drawable, dc->u.x.gc,
112 xsrc, ysrc, width, height, xdest, ydest, plane );
114 else
116 TSXCopyArea( display, pbitmap->pixmap, dc->u.x.drawable,
117 dc->u.x.gc, xsrc, ysrc, width, height, xdest, ydest );
120 else
122 ret = FALSE;
125 GDI_HEAP_UNLOCK( hdc );
126 GDI_HEAP_UNLOCK( hbitmap );
127 return ret;
131 /**********************************************************************
132 * GRAPH_DrawReliefRect
134 * Used in the standard control code for button edge drawing.
136 void GRAPH_DrawReliefRect( HDC32 hdc, const RECT32 *rect, INT32 highlight_size,
137 INT32 shadow_size, BOOL32 pressed )
139 if(pressed)
140 GRAPH_DrawGenericReliefRect(hdc, rect, highlight_size, shadow_size,
141 GetSysColorBrush32(COLOR_BTNSHADOW),
142 GetSysColorBrush32(COLOR_BTNHIGHLIGHT));
143 else
144 GRAPH_DrawGenericReliefRect(hdc, rect, highlight_size, shadow_size,
145 GetSysColorBrush32(COLOR_BTNHIGHLIGHT),
146 GetSysColorBrush32(COLOR_BTNSHADOW));
148 return;
152 /******************************************************************************
153 * GRAPH_DrawGenericReliefRect
155 * Creates a rectangle with the specified highlight and shadow colors.
156 * Adapted from DrawReliefRect (which is somewhat misnamed).
158 void GRAPH_DrawGenericReliefRect(
159 HDC32 hdc,
160 const RECT32 *rect,
161 INT32 highlight_size,
162 INT32 shadow_size,
163 HBRUSH32 highlight,
164 HBRUSH32 shadow )
166 DC* dc;
167 HBRUSH32 hPrevBrush;
168 INT32 w, h;
169 RECT32 r = *rect;
171 if (!(dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ))) return;
173 OffsetRect32( &r, dc->w.DCOrgX, dc->w.DCOrgY);
174 h = rect->bottom - rect->top; w = rect->right - rect->left;
176 hPrevBrush = SelectObject32(hdc, highlight);
178 if ( DC_SetupGCForBrush( dc ) )
180 INT32 i;
182 TSXSetFunction( display, dc->u.x.gc, GXcopy );
183 for (i = 0; i < highlight_size; i++)
185 TSXFillRectangle( display, dc->u.x.drawable, dc->u.x.gc,
186 r.left + i, r.top, 1, h - i );
187 TSXFillRectangle( display, dc->u.x.drawable, dc->u.x.gc,
188 r.left, r.top + i, w - i, 1 );
192 SelectObject32( hdc, shadow );
193 if ( DC_SetupGCForBrush( dc ) )
195 INT32 i;
197 TSXSetFunction( display, dc->u.x.gc, GXcopy );
198 for (i = 0; i < shadow_size; i++)
200 TSXFillRectangle( display, dc->u.x.drawable, dc->u.x.gc,
201 r.right - i - 1, r.top + i, 1, h - i );
202 TSXFillRectangle( display, dc->u.x.drawable, dc->u.x.gc,
203 r.left + i, r.bottom - i - 1, w - i, 1 );
207 SelectObject32( hdc, hPrevBrush );
208 GDI_HEAP_UNLOCK( hdc );
213 /**********************************************************************
214 * GRAPH_DrawRectangle
216 void GRAPH_DrawRectangle( HDC32 hdc, INT32 x, INT32 y,
217 INT32 w, INT32 h, HPEN32 hPen )
219 DC* dc;
221 if( (dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC )) )
223 HPEN32 hPrevPen = 0;
225 if( hPen ) hPrevPen = SelectObject32( hdc, hPen );
226 if( DC_SetupGCForPen( dc ) )
227 TSXDrawRectangle( display, dc->u.x.drawable, dc->u.x.gc,
228 x + dc->w.DCOrgX, y + dc->w.DCOrgY, w - 1, h - 1);
229 if( hPrevPen ) SelectObject32( hdc, hPrevPen );
230 GDI_HEAP_UNLOCK( hdc );
234 /**********************************************************************
235 * GRAPH_SelectClipMask
237 BOOL32 GRAPH_SelectClipMask( HDC32 hdc, HBITMAP32 hMonoBitmap, INT32 x, INT32 y)
239 BITMAPOBJ *bmp = NULL;
240 DC *dc;
241 X11DRV_PHYSBITMAP *pbitmap = NULL;
243 if (!(dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ))) return FALSE;
244 if ( hMonoBitmap )
246 if ( !(bmp = (BITMAPOBJ *) GDI_GetObjPtr( hMonoBitmap, BITMAP_MAGIC))
247 || bmp->bitmap.bmBitsPixel != 1 )
249 GDI_HEAP_UNLOCK( hdc );
250 return FALSE;
252 pbitmap = bmp->DDBitmap->physBitmap;
253 TSXSetClipOrigin( display, dc->u.x.gc, dc->w.DCOrgX + x, dc->w.DCOrgY + y);
256 TSXSetClipMask( display, dc->u.x.gc, (bmp) ? pbitmap->pixmap : None );
258 GDI_HEAP_UNLOCK( hdc );
259 GDI_HEAP_UNLOCK( hMonoBitmap );
260 return TRUE;