Release 960114
[wine/gsoc-2012-control.git] / objects / pen.c
blobadf02e62f5e4b288e4d9573263d8465e4b2e18b1
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 if (MF_CreatePenIndirect(dc, hpen, &(pen->logpen)))
65 return prevHandle;
66 else
67 return 0;
69 dc->w.hPen = hpen;
71 dc->u.x.pen.style = pen->logpen.lopnStyle;
72 dc->u.x.pen.width = pen->logpen.lopnWidth.x * dc->w.VportExtX
73 / dc->w.WndExtX;
74 if (dc->u.x.pen.width < 0) dc->u.x.pen.width = -dc->u.x.pen.width;
75 if (dc->u.x.pen.width == 1) dc->u.x.pen.width = 0; /* Faster */
76 dc->u.x.pen.pixel = COLOR_ToPhysical( dc, pen->logpen.lopnColor );
77 switch(pen->logpen.lopnStyle)
79 case PS_DASH:
80 dc->u.x.pen.dashes = dash_dash;
81 dc->u.x.pen.dash_len = 2;
82 break;
83 case PS_DOT:
84 dc->u.x.pen.dashes = dash_dot;
85 dc->u.x.pen.dash_len = 2;
86 break;
87 case PS_DASHDOT:
88 dc->u.x.pen.dashes = dash_dashdot;
89 dc->u.x.pen.dash_len = 4;
90 break;
91 case PS_DASHDOTDOT:
92 dc->u.x.pen.dashes = dash_dashdotdot;
93 dc->u.x.pen.dash_len = 6;
94 break;
97 return prevHandle;