Release 951003
[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 "stddebug.h"
10 #include "color.h"
11 #include "debug.h"
12
13 /***********************************************************************
14  *           CreatePen    (GDI.61)
15  */
16 HPEN CreatePen( short style, short width, COLORREF color )
17 {
18     LOGPEN logpen = { style, { width, 0 }, color };
19     dprintf_gdi(stddeb, "CreatePen: %d %d %06lx\n", style, width, color );
20     return CreatePenIndirect( &logpen );
21 }
22
23
24 /***********************************************************************
25  *           CreatePenIndirect    (GDI.62)
26  */
27 HPEN CreatePenIndirect( LOGPEN * pen )
28 {
29     PENOBJ * penPtr;
30     HPEN hpen;
31
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;
38 }
39
40
41 /***********************************************************************
42  *           PEN_GetObject
43  */
44 int PEN_GetObject( PENOBJ * pen, int count, LPSTR buffer )
45 {
46     if (count > sizeof(LOGPEN)) count = sizeof(LOGPEN);
47     memcpy( buffer, &pen->logpen, count );
48     return count;
49 }
50
51
52 /***********************************************************************
53  *           PEN_SelectObject
54  */
55 HPEN PEN_SelectObject( DC * dc, HPEN hpen, PENOBJ * pen )
56 {
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;
62
63     if (dc->header.wMagic == METAFILE_DC_MAGIC)
64       if (MF_CreatePenIndirect(dc, hpen, &(pen->logpen)))
65         return prevHandle;
66       else
67         return 0;
68
69     dc->w.hPen = hpen;
70
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)
78     {
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;
95     }
96     
97     return prevHandle;
98 }