Fixed bug in DIB_SetImageBits_RLE8 (because 'color' var was WORD, all
[wine] / objects / pen.c
1 /*
2  * GDI pen objects
3  *
4  * Copyright 1993 Alexandre Julliard
5  */
6
7 #include "pen.h"
8 #include "metafile.h"
9 #include "color.h"
10 #include "debug.h"
11
12
13
14 /***********************************************************************
15  *           CreatePen16    (GDI.61)
16  */
17 HPEN16 WINAPI CreatePen16( INT16 style, INT16 width, COLORREF color )
18 {
19     LOGPEN32 logpen = { style, { width, 0 }, color };
20     TRACE(gdi, "%d %d %06lx\n", style, width, color );
21     return CreatePenIndirect32( &logpen );
22 }
23
24
25 /***********************************************************************
26  *           CreatePen32    (GDI32.55)
27  */
28 HPEN32 WINAPI CreatePen32( INT32 style, INT32 width, COLORREF color )
29 {
30     LOGPEN32 logpen = { style, { width, 0 }, color };
31     TRACE(gdi, "%d %d %06lx\n", style, width, color );
32     return CreatePenIndirect32( &logpen );
33 }
34
35
36 /***********************************************************************
37  *           CreatePenIndirect16    (GDI.62)
38  */
39 HPEN16 WINAPI CreatePenIndirect16( const LOGPEN16 * pen )
40 {
41     PENOBJ * penPtr;
42     HPEN16 hpen;
43
44     if (pen->lopnStyle > PS_INSIDEFRAME) return 0;
45     hpen = GDI_AllocObject( sizeof(PENOBJ), PEN_MAGIC );
46     if (!hpen) return 0;
47     penPtr = (PENOBJ *)GDI_HEAP_LOCK( hpen );
48     penPtr->logpen.lopnStyle = pen->lopnStyle;
49     penPtr->logpen.lopnColor = pen->lopnColor;
50     CONV_POINT16TO32( &pen->lopnWidth, &penPtr->logpen.lopnWidth );
51     GDI_HEAP_UNLOCK( hpen );
52     return hpen;
53 }
54
55
56 /***********************************************************************
57  *           CreatePenIndirect32    (GDI32.56)
58  */
59 HPEN32 WINAPI CreatePenIndirect32( const LOGPEN32 * pen )
60 {
61     PENOBJ * penPtr;
62     HPEN32 hpen;
63
64     if (pen->lopnStyle > PS_INSIDEFRAME) return 0;
65     hpen = GDI_AllocObject( sizeof(PENOBJ), PEN_MAGIC );
66     if (!hpen) return 0;
67     penPtr = (PENOBJ *)GDI_HEAP_LOCK( hpen );
68     penPtr->logpen.lopnStyle = pen->lopnStyle;
69     penPtr->logpen.lopnWidth = pen->lopnWidth;
70     penPtr->logpen.lopnColor = pen->lopnColor;
71     GDI_HEAP_UNLOCK( hpen );
72     return hpen;
73 }
74
75 /***********************************************************************
76  *           ExtCreatePen32    (GDI32.93)
77  *
78  * FIXME: PS_USERSTYLE not handled
79  */
80
81 HPEN32 WINAPI ExtCreatePen32( DWORD style, DWORD width,
82                               const LOGBRUSH32 * brush, DWORD style_count,
83                               const DWORD *style_bits )
84 {
85     LOGPEN32 logpen;
86
87     if ((style & PS_STYLE_MASK) == PS_USERSTYLE)
88         FIXME(gdi, "PS_USERSTYLE not handled\n");
89     if ((style & PS_TYPE_MASK) == PS_GEOMETRIC)
90         if (brush->lbHatch)
91             FIXME(gdi, "Hatches not implemented\n");
92
93     logpen.lopnStyle = style & ~PS_TYPE_MASK;
94     logpen.lopnWidth.x = (style & PS_GEOMETRIC) ? width : 1;
95     logpen.lopnWidth.y = 0;
96     logpen.lopnColor = brush->lbColor;
97     return CreatePenIndirect32( &logpen );
98 }
99
100 /***********************************************************************
101  *           PEN_GetObject16
102  */
103 INT16 PEN_GetObject16( PENOBJ * pen, INT16 count, LPSTR buffer )
104 {
105     LOGPEN16 logpen;
106     logpen.lopnStyle = pen->logpen.lopnStyle;
107     logpen.lopnColor = pen->logpen.lopnColor;
108     CONV_POINT32TO16( &pen->logpen.lopnWidth, &logpen.lopnWidth );
109     if (count > sizeof(logpen)) count = sizeof(logpen);
110     memcpy( buffer, &logpen, count );
111     return count;
112 }
113
114
115 /***********************************************************************
116  *           PEN_GetObject32
117  */
118 INT32 PEN_GetObject32( PENOBJ * pen, INT32 count, LPSTR buffer )
119 {
120     if (count > sizeof(pen->logpen)) count = sizeof(pen->logpen);
121     memcpy( buffer, &pen->logpen, count );
122     return count;
123 }
124