Some broken games do not put the TEXTURE flags in the surface caps.
[wine/multimedia.git] / objects / pen.c
blobd117964c6b5b648e9f478e144a1aa58090065d7b
1 /*
2 * GDI pen objects
4 * Copyright 1993 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
23 #include <string.h>
25 #include "windef.h"
26 #include "wingdi.h"
27 #include "wine/wingdi16.h"
28 #include "gdi.h"
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(gdi);
33 /* GDI logical pen object */
34 typedef struct
36 GDIOBJHDR header;
37 LOGPEN logpen;
38 } PENOBJ;
41 static HGDIOBJ PEN_SelectObject( HGDIOBJ handle, void *obj, HDC hdc );
42 static INT PEN_GetObject16( HGDIOBJ handle, void *obj, INT count, LPVOID buffer );
43 static INT PEN_GetObject( HGDIOBJ handle, void *obj, INT count, LPVOID buffer );
45 static const struct gdi_obj_funcs pen_funcs =
47 PEN_SelectObject, /* pSelectObject */
48 PEN_GetObject16, /* pGetObject16 */
49 PEN_GetObject, /* pGetObjectA */
50 PEN_GetObject, /* pGetObjectW */
51 NULL, /* pUnrealizeObject */
52 GDI_FreeObject /* pDeleteObject */
56 /***********************************************************************
57 * CreatePen (GDI32.@)
59 HPEN WINAPI CreatePen( INT style, INT width, COLORREF color )
61 LOGPEN logpen;
63 TRACE("%d %d %06lx\n", style, width, color );
65 logpen.lopnStyle = style;
66 logpen.lopnWidth.x = width;
67 logpen.lopnWidth.y = 0;
68 logpen.lopnColor = color;
70 return CreatePenIndirect( &logpen );
74 /***********************************************************************
75 * CreatePenIndirect (GDI32.@)
77 HPEN WINAPI CreatePenIndirect( const LOGPEN * pen )
79 PENOBJ * penPtr;
80 HPEN hpen;
82 if (!(penPtr = GDI_AllocObject( sizeof(PENOBJ), PEN_MAGIC, (HGDIOBJ *)&hpen,
83 &pen_funcs ))) return 0;
84 penPtr->logpen.lopnStyle = pen->lopnStyle;
85 penPtr->logpen.lopnWidth = pen->lopnWidth;
86 penPtr->logpen.lopnColor = pen->lopnColor;
87 GDI_ReleaseObj( hpen );
88 return hpen;
91 /***********************************************************************
92 * ExtCreatePen (GDI32.@)
94 * FIXME: PS_USERSTYLE not handled
97 HPEN WINAPI ExtCreatePen( DWORD style, DWORD width,
98 const LOGBRUSH * brush, DWORD style_count,
99 const DWORD *style_bits )
101 PENOBJ * penPtr;
102 HPEN hpen;
104 if ((style & PS_STYLE_MASK) == PS_USERSTYLE)
105 FIXME("PS_USERSTYLE not handled\n");
106 if ((style & PS_TYPE_MASK) == PS_GEOMETRIC)
107 if (brush->lbHatch)
108 FIXME("Hatches not implemented\n");
110 if (!(penPtr = GDI_AllocObject( sizeof(PENOBJ), PEN_MAGIC, (HGDIOBJ *)&hpen,
111 &pen_funcs ))) return 0;
112 penPtr->logpen.lopnStyle = style & ~PS_TYPE_MASK;
114 /* PS_USERSTYLE workaround */
115 if((penPtr->logpen.lopnStyle & PS_STYLE_MASK) == PS_USERSTYLE)
116 penPtr->logpen.lopnStyle =
117 (penPtr->logpen.lopnStyle & ~PS_STYLE_MASK) | PS_SOLID;
119 penPtr->logpen.lopnWidth.x = (style & PS_GEOMETRIC) ? width : 1;
120 penPtr->logpen.lopnWidth.y = 0;
121 penPtr->logpen.lopnColor = brush->lbColor;
122 GDI_ReleaseObj( hpen );
124 return hpen;
128 /***********************************************************************
129 * PEN_SelectObject
131 static HGDIOBJ PEN_SelectObject( HGDIOBJ handle, void *obj, HDC hdc )
133 HGDIOBJ ret;
134 DC *dc = DC_GetDCPtr( hdc );
136 if (!dc) return 0;
137 ret = dc->hPen;
138 if (dc->funcs->pSelectPen) handle = dc->funcs->pSelectPen( dc->physDev, handle );
139 if (handle) dc->hPen = handle;
140 else ret = 0;
141 GDI_ReleaseObj( hdc );
142 return ret;
146 /***********************************************************************
147 * PEN_GetObject16
149 static INT PEN_GetObject16( HGDIOBJ handle, void *obj, INT count, LPVOID buffer )
151 PENOBJ *pen = obj;
152 LOGPEN16 logpen;
154 logpen.lopnStyle = pen->logpen.lopnStyle;
155 logpen.lopnColor = pen->logpen.lopnColor;
156 CONV_POINT32TO16( &pen->logpen.lopnWidth, &logpen.lopnWidth );
157 if (count > sizeof(logpen)) count = sizeof(logpen);
158 memcpy( buffer, &logpen, count );
159 return count;
163 /***********************************************************************
164 * PEN_GetObject
166 static INT PEN_GetObject( HGDIOBJ handle, void *obj, INT count, LPVOID buffer )
168 PENOBJ *pen = obj;
170 if (count > sizeof(pen->logpen)) count = sizeof(pen->logpen);
171 memcpy( buffer, &pen->logpen, count );
172 return count;