Fixed error handling in DGA_IDirectDraw2Impl_GetCaps().
[wine] / graphics / psdrv / brush.c
1 /*
2  *      PostScript brush handling
3  *
4  * Copyright 1998  Huw D M Davies
5  *
6  */
7
8 #include "psdrv.h"
9 #include "brush.h"
10 #include "debug.h"
11 #include "gdi.h"
12
13 DEFAULT_DEBUG_CHANNEL(psdrv)
14
15 /***********************************************************************
16  *           PSDRV_BRUSH_SelectObject
17  */
18 HBRUSH PSDRV_BRUSH_SelectObject( DC * dc, HBRUSH hbrush, BRUSHOBJ * brush )
19 {
20     HBRUSH prevbrush = dc->w.hBrush;
21     PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
22
23     TRACE(psdrv, "hbrush = %08x\n", hbrush);
24     dc->w.hBrush = hbrush;
25
26     switch(brush->logbrush.lbStyle) {
27
28     case BS_SOLID:
29         PSDRV_CreateColor(physDev, &physDev->brush.color, 
30                           brush->logbrush.lbColor);
31         break;
32
33     case BS_NULL:
34         break;
35
36     case BS_HATCHED:
37         PSDRV_CreateColor(physDev, &physDev->brush.color, 
38                           brush->logbrush.lbColor);
39         break;
40
41     case BS_PATTERN:
42         FIXME(psdrv, "Unsupported brush style %d\n", brush->logbrush.lbStyle);
43         break;
44
45     default:
46         FIXME(psdrv, "Unrecognized brush style %d\n", brush->logbrush.lbStyle);
47         break;
48     }
49
50     physDev->brush.set = FALSE;
51     return prevbrush;
52 }
53
54
55 /**********************************************************************
56  *
57  *      PSDRV_SetBrush
58  *
59  */
60 static BOOL PSDRV_SetBrush(DC *dc)
61 {
62     PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
63     BRUSHOBJ *brush = (BRUSHOBJ *)GDI_GetObjPtr( dc->w.hBrush, BRUSH_MAGIC );
64
65     if(!brush) {
66         ERR(psdrv, "Can't get BRUSHOBJ\n");
67         return FALSE;
68     }
69     
70     switch (brush->logbrush.lbStyle) {
71     case BS_SOLID:
72     case BS_HATCHED:
73         PSDRV_WriteSetColor(dc, &physDev->brush.color);
74         break;
75
76     case BS_NULL:
77         break;
78
79     default:
80         return FALSE;
81         break;
82
83     }
84     physDev->brush.set = TRUE;
85     return TRUE;
86 }
87
88
89 /**********************************************************************
90  *
91  *      PSDRV_Fill
92  *
93  */
94 static BOOL PSDRV_Fill(DC *dc, BOOL EO)
95 {
96     if(!EO)
97         return PSDRV_WriteFill(dc);
98     else
99       return PSDRV_WriteEOFill(dc);
100 }
101
102
103 /**********************************************************************
104  *
105  *      PSDRV_Clip
106  *
107  */
108 static BOOL PSDRV_Clip(DC *dc, BOOL EO)
109 {
110     if(!EO)
111         return PSDRV_WriteClip(dc);
112     else
113         return PSDRV_WriteEOClip(dc);
114 }
115
116 /**********************************************************************
117  *
118  *      PSDRV_Brush
119  *
120  */
121 BOOL PSDRV_Brush(DC *dc, BOOL EO)
122 {
123     BRUSHOBJ *brush = (BRUSHOBJ *)GDI_GetObjPtr( dc->w.hBrush, BRUSH_MAGIC );
124
125     if(!brush) {
126         ERR(psdrv, "Can't get BRUSHOBJ\n");
127         return FALSE;
128     }
129
130     switch (brush->logbrush.lbStyle) {
131     case BS_SOLID:
132         PSDRV_SetBrush(dc);
133         PSDRV_WriteGSave(dc);
134         PSDRV_Fill(dc, EO);
135         PSDRV_WriteGRestore(dc);
136         return TRUE;
137         break;
138
139     case BS_HATCHED:
140         PSDRV_SetBrush(dc);
141
142         switch(brush->logbrush.lbHatch) {
143         case HS_VERTICAL:
144         case HS_CROSS:
145             PSDRV_WriteGSave(dc);
146             PSDRV_Clip(dc, EO);
147             PSDRV_WriteHatch(dc);
148             PSDRV_WriteStroke(dc);
149             PSDRV_WriteGRestore(dc);
150             if(brush->logbrush.lbHatch == HS_VERTICAL)
151                 break;
152             /* else fallthrough for HS_CROSS */
153
154         case HS_HORIZONTAL:
155             PSDRV_WriteGSave(dc);
156             PSDRV_Clip(dc, EO);
157             PSDRV_WriteRotate(dc, 90.0);
158             PSDRV_WriteHatch(dc);
159             PSDRV_WriteStroke(dc);
160             PSDRV_WriteGRestore(dc);
161             break;
162
163         case HS_FDIAGONAL:
164         case HS_DIAGCROSS:
165             PSDRV_WriteGSave(dc);
166             PSDRV_Clip(dc, EO);
167             PSDRV_WriteRotate(dc, -45.0);
168             PSDRV_WriteHatch(dc);
169             PSDRV_WriteStroke(dc);
170             PSDRV_WriteGRestore(dc);
171             if(brush->logbrush.lbHatch == HS_FDIAGONAL)
172                 break;
173             /* else fallthrough for HS_DIAGCROSS */
174             
175         case HS_BDIAGONAL:
176             PSDRV_WriteGSave(dc);
177             PSDRV_Clip(dc, EO);
178             PSDRV_WriteRotate(dc, 45.0);
179             PSDRV_WriteHatch(dc);
180             PSDRV_WriteStroke(dc);
181             PSDRV_WriteGRestore(dc);
182             break;
183
184         default:
185             ERR(psdrv, "Unknown hatch style\n");
186             return FALSE;
187         }
188         return TRUE;
189         break;
190
191     case BS_NULL:
192         return TRUE;
193         break;
194
195     default:
196         return FALSE;
197         break;
198     }
199 }
200
201
202
203