Release 940405
[wine/gsoc-2012-control.git] / objects / pen.c
blob48da2526a73dd2265c2fed04156bf60432954a9a
1 /*
2 * GDI pen objects
4 * Copyright 1993 Alexandre Julliard
5 */
7 static char Copyright[] = "Copyright Alexandre Julliard, 1993";
9 #include "gdi.h"
11 extern WORD COLOR_ToPhysical( DC *dc, COLORREF color );
13 /***********************************************************************
14 * CreatePen (GDI.61)
16 HPEN CreatePen( short style, short width, COLORREF color )
18 LOGPEN logpen = { style, { width, 0 }, color };
19 #ifdef DEBUG_GDI
20 printf( "CreatePen: %d %d %06x\n", style, width, color );
21 #endif
22 return CreatePenIndirect( &logpen );
26 /***********************************************************************
27 * CreatePenIndirect (GDI.62)
29 HPEN CreatePenIndirect( LOGPEN * pen )
31 PENOBJ * penPtr;
32 HPEN hpen;
34 if (pen->lopnStyle > PS_INSIDEFRAME) return 0;
35 hpen = GDI_AllocObject( sizeof(PENOBJ), PEN_MAGIC );
36 if (!hpen) return 0;
37 penPtr = (PENOBJ *) GDI_HEAP_ADDR( hpen );
38 memcpy( &penPtr->logpen, pen, sizeof(LOGPEN) );
39 return hpen;
43 /***********************************************************************
44 * PEN_GetObject
46 int PEN_GetObject( PENOBJ * pen, int count, LPSTR buffer )
48 if (count > sizeof(LOGPEN)) count = sizeof(LOGPEN);
49 memcpy( buffer, &pen->logpen, count );
50 return count;
54 /***********************************************************************
55 * PEN_SelectObject
57 HPEN PEN_SelectObject( DC * dc, HPEN hpen, PENOBJ * pen )
59 static char dash_dash[] = { 5, 3 }; /* ----- ----- ----- */
60 static char dash_dot[] = { 2, 2 }; /* -- -- -- -- -- -- */
61 static char dash_dashdot[] = { 4,3,2,3 }; /* ---- -- ---- -- */
62 static char dash_dashdotdot[] = { 4,2,2,2,2,2 }; /* ---- -- -- ---- */
64 HPEN prevHandle = dc->w.hPen;
65 dc->w.hPen = hpen;
67 dc->u.x.pen.style = pen->logpen.lopnStyle;
68 dc->u.x.pen.width = pen->logpen.lopnWidth.x * dc->w.VportExtX
69 / dc->w.WndExtX;
70 if (dc->u.x.pen.width < 0) dc->u.x.pen.width = -dc->u.x.pen.width;
71 if (dc->u.x.pen.width == 1) dc->u.x.pen.width = 0; /* Faster */
72 dc->u.x.pen.pixel = COLOR_ToPhysical( dc, pen->logpen.lopnColor );
73 switch(pen->logpen.lopnStyle)
75 case PS_DASH:
76 dc->u.x.pen.dashes = dash_dash;
77 dc->u.x.pen.dash_len = 2;
78 break;
79 case PS_DOT:
80 dc->u.x.pen.dashes = dash_dot;
81 dc->u.x.pen.dash_len = 2;
82 break;
83 case PS_DASHDOT:
84 dc->u.x.pen.dashes = dash_dashdot;
85 dc->u.x.pen.dash_len = 4;
86 break;
87 case PS_DASHDOTDOT:
88 dc->u.x.pen.dashes = dash_dashdotdot;
89 dc->u.x.pen.dash_len = 6;
90 break;
93 return prevHandle;