Release 961222
[wine/gsoc-2012-control.git] / objects / pen.c
blob9bb51ee7e20ad6563c798db5d7c024dc198935ed
1 /*
2 * GDI pen objects
4 * Copyright 1993 Alexandre Julliard
5 */
7 #define NO_TRANSITION_TYPES /* This file is Win32-clean */
8 #include "pen.h"
9 #include "metafile.h"
10 #include "color.h"
11 #include "stddebug.h"
12 #include "debug.h"
15 static const char PEN_dash[] = { 5,3 }; /* ----- ----- ----- */
16 static const char PEN_dot[] = { 1,1 }; /* -- -- -- -- -- -- */
17 static const char PEN_dashdot[] = { 4,3,2,3 }; /* ---- -- ---- -- */
18 static const char PEN_dashdotdot[] = { 4,2,2,2,2,2 }; /* ---- -- -- ---- */
20 /***********************************************************************
21 * CreatePen16 (GDI.61)
23 HPEN16 CreatePen16( INT16 style, INT16 width, COLORREF color )
25 LOGPEN32 logpen = { style, { width, 0 }, color };
26 dprintf_gdi(stddeb, "CreatePen16: %d %d %06lx\n", style, width, color );
27 return CreatePenIndirect32( &logpen );
31 /***********************************************************************
32 * CreatePen32 (GDI32.55)
34 HPEN32 CreatePen32( INT32 style, INT32 width, COLORREF color )
36 LOGPEN32 logpen = { style, { width, 0 }, color };
37 dprintf_gdi(stddeb, "CreatePen32: %d %d %06lx\n", style, width, color );
38 return CreatePenIndirect32( &logpen );
42 /***********************************************************************
43 * CreatePenIndirect16 (GDI.62)
45 HPEN16 CreatePenIndirect16( const LOGPEN16 * pen )
47 PENOBJ * penPtr;
48 HPEN16 hpen;
50 if (pen->lopnStyle > PS_INSIDEFRAME) return 0;
51 hpen = GDI_AllocObject( sizeof(PENOBJ), PEN_MAGIC );
52 if (!hpen) return 0;
53 penPtr = (PENOBJ *)GDI_HEAP_LIN_ADDR( hpen );
54 penPtr->logpen.lopnStyle = pen->lopnStyle;
55 penPtr->logpen.lopnColor = pen->lopnColor;
56 CONV_POINT16TO32( &pen->lopnWidth, &penPtr->logpen.lopnWidth );
57 return hpen;
61 /***********************************************************************
62 * CreatePenIndirect32 (GDI32.56)
64 HPEN32 CreatePenIndirect32( const LOGPEN32 * pen )
66 PENOBJ * penPtr;
67 HPEN32 hpen;
69 if (pen->lopnStyle > PS_INSIDEFRAME) return 0;
70 hpen = GDI_AllocObject( sizeof(PENOBJ), PEN_MAGIC );
71 if (!hpen) return 0;
72 penPtr = (PENOBJ *)GDI_HEAP_LIN_ADDR( hpen );
73 penPtr->logpen.lopnStyle = pen->lopnStyle;
74 penPtr->logpen.lopnWidth = pen->lopnWidth;
75 penPtr->logpen.lopnColor = pen->lopnColor;
76 return hpen;
80 /***********************************************************************
81 * PEN_GetObject16
83 INT16 PEN_GetObject16( PENOBJ * pen, INT16 count, LPSTR buffer )
85 LOGPEN16 logpen;
86 logpen.lopnStyle = pen->logpen.lopnStyle;
87 logpen.lopnColor = pen->logpen.lopnColor;
88 CONV_POINT32TO16( &pen->logpen.lopnWidth, &logpen.lopnWidth );
89 if (count > sizeof(logpen)) count = sizeof(logpen);
90 memcpy( buffer, &logpen, count );
91 return count;
95 /***********************************************************************
96 * PEN_GetObject32
98 INT32 PEN_GetObject32( PENOBJ * pen, INT32 count, LPSTR buffer )
100 if (count > sizeof(pen->logpen)) count = sizeof(pen->logpen);
101 memcpy( buffer, &pen->logpen, count );
102 return count;
106 /***********************************************************************
107 * PEN_SelectObject
109 HPEN32 PEN_SelectObject( DC * dc, HPEN32 hpen, PENOBJ * pen )
111 HPEN32 prevHandle = dc->w.hPen;
113 if (dc->header.wMagic == METAFILE_DC_MAGIC)
115 LOGPEN16 logpen = { pen->logpen.lopnStyle,
116 { pen->logpen.lopnWidth.x,
117 pen->logpen.lopnWidth.y },
118 pen->logpen.lopnColor };
119 if (MF_CreatePenIndirect( dc, hpen, &logpen )) return prevHandle;
120 else return 0;
123 dc->w.hPen = hpen;
125 dc->u.x.pen.style = pen->logpen.lopnStyle;
126 dc->u.x.pen.width = pen->logpen.lopnWidth.x * dc->vportExtX / dc->wndExtX;
127 if (dc->u.x.pen.width < 0) dc->u.x.pen.width = -dc->u.x.pen.width;
128 if (dc->u.x.pen.width == 1) dc->u.x.pen.width = 0; /* Faster */
129 dc->u.x.pen.pixel = COLOR_ToPhysical( dc, pen->logpen.lopnColor );
130 switch(pen->logpen.lopnStyle)
132 case PS_DASH:
133 dc->u.x.pen.dashes = (char *)PEN_dash;
134 dc->u.x.pen.dash_len = 2;
135 break;
136 case PS_DOT:
137 dc->u.x.pen.dashes = (char *)PEN_dot;
138 dc->u.x.pen.dash_len = 2;
139 break;
140 case PS_DASHDOT:
141 dc->u.x.pen.dashes = (char *)PEN_dashdot;
142 dc->u.x.pen.dash_len = 4;
143 break;
144 case PS_DASHDOTDOT:
145 dc->u.x.pen.dashes = (char *)PEN_dashdotdot;
146 dc->u.x.pen.dash_len = 6;
147 break;
150 return prevHandle;