Release 950319
[wine.git] / objects / pen.c
blob131667a40217edccb9098a5370fefc4dfbe245ca
1 /*
2 * GDI pen objects
4 * Copyright 1993 Alexandre Julliard
5 */
7 #include "pen.h"
8 #include "metafile.h"
9 #include "stddebug.h"
10 #include "color.h"
11 #include "debug.h"
13 /***********************************************************************
14 * CreatePen (GDI.61)
16 HPEN CreatePen( short style, short width, COLORREF color )
18 LOGPEN logpen = { style, { width, 0 }, color };
19 dprintf_gdi(stddeb, "CreatePen: %d %d %06lx\n", style, width, color );
20 return CreatePenIndirect( &logpen );
24 /***********************************************************************
25 * CreatePenIndirect (GDI.62)
27 HPEN CreatePenIndirect( LOGPEN * pen )
29 PENOBJ * penPtr;
30 HPEN hpen;
32 if (pen->lopnStyle > PS_INSIDEFRAME) return 0;
33 hpen = GDI_AllocObject( sizeof(PENOBJ), PEN_MAGIC );
34 if (!hpen) return 0;
35 penPtr = (PENOBJ *) GDI_HEAP_LIN_ADDR( hpen );
36 memcpy( &penPtr->logpen, pen, sizeof(LOGPEN) );
37 return hpen;
41 /***********************************************************************
42 * PEN_GetObject
44 int PEN_GetObject( PENOBJ * pen, int count, LPSTR buffer )
46 if (count > sizeof(LOGPEN)) count = sizeof(LOGPEN);
47 memcpy( buffer, &pen->logpen, count );
48 return count;
52 /***********************************************************************
53 * PEN_SelectObject
55 HPEN PEN_SelectObject( DC * dc, HPEN hpen, PENOBJ * pen )
57 static char dash_dash[] = { 5, 3 }; /* ----- ----- ----- */
58 static char dash_dot[] = { 2, 2 }; /* -- -- -- -- -- -- */
59 static char dash_dashdot[] = { 4,3,2,3 }; /* ---- -- ---- -- */
60 static char dash_dashdotdot[] = { 4,2,2,2,2,2 }; /* ---- -- -- ---- */
61 HPEN prevHandle = dc->w.hPen;
63 if (dc->header.wMagic == METAFILE_DC_MAGIC)
64 return MF_CreatePenIndirect(dc, hpen, &(pen->logpen));
66 dc->w.hPen = hpen;
68 dc->u.x.pen.style = pen->logpen.lopnStyle;
69 dc->u.x.pen.width = pen->logpen.lopnWidth.x * dc->w.VportExtX
70 / dc->w.WndExtX;
71 if (dc->u.x.pen.width < 0) dc->u.x.pen.width = -dc->u.x.pen.width;
72 if (dc->u.x.pen.width == 1) dc->u.x.pen.width = 0; /* Faster */
73 dc->u.x.pen.pixel = COLOR_ToPhysical( dc, pen->logpen.lopnColor );
74 switch(pen->logpen.lopnStyle)
76 case PS_DASH:
77 dc->u.x.pen.dashes = dash_dash;
78 dc->u.x.pen.dash_len = 2;
79 break;
80 case PS_DOT:
81 dc->u.x.pen.dashes = dash_dot;
82 dc->u.x.pen.dash_len = 2;
83 break;
84 case PS_DASHDOT:
85 dc->u.x.pen.dashes = dash_dashdot;
86 dc->u.x.pen.dash_len = 4;
87 break;
88 case PS_DASHDOTDOT:
89 dc->u.x.pen.dashes = dash_dashdotdot;
90 dc->u.x.pen.dash_len = 6;
91 break;
94 return prevHandle;