ddraw: Add a test for DDSD_ZBUFFERBITDEPTH and DDSD_PIXELFORMAT.
[wine/wine-gecko.git] / dlls / winex11.drv / pen.c
blob54883b208d74b438d2213a0a23524559858c383b
1 /*
2 * X11DRV pen objects
4 * Copyright 1993 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
23 #include "x11drv.h"
24 #include "wine/debug.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
28 /***********************************************************************
29 * SelectPen (X11DRV.@)
31 HPEN X11DRV_SelectPen( PHYSDEV dev, HPEN hpen )
33 static const char PEN_dash[] = { 16,8 };
34 static const char PEN_dot[] = { 4,4 };
35 static const char PEN_dashdot[] = { 12,8,4,8 };
36 static const char PEN_dashdotdot[] = { 12,4,4,4,4,4 };
37 static const char PEN_alternate[] = { 1,1 };
38 static const char EXTPEN_dash[] = { 3,1 };
39 static const char EXTPEN_dot[] = { 1,1 };
40 static const char EXTPEN_dashdot[] = { 3,1,1,1 };
41 static const char EXTPEN_dashdotdot[] = { 3,1,1,1,1,1 };
42 X11DRV_PDEVICE *physDev = get_x11drv_dev( dev );
43 LOGPEN logpen;
44 int i;
46 if (!GetObjectW( hpen, sizeof(logpen), &logpen ))
48 /* must be an extended pen */
49 EXTLOGPEN *elp;
50 INT size = GetObjectW( hpen, 0, NULL );
52 if (!size) return 0;
54 physDev->pen.ext = 1;
55 elp = HeapAlloc( GetProcessHeap(), 0, size );
57 GetObjectW( hpen, size, elp );
58 /* FIXME: add support for user style pens */
59 logpen.lopnStyle = elp->elpPenStyle;
60 logpen.lopnWidth.x = elp->elpWidth;
61 logpen.lopnWidth.y = 0;
62 logpen.lopnColor = elp->elpColor;
64 HeapFree( GetProcessHeap(), 0, elp );
66 else
67 physDev->pen.ext = 0;
69 physDev->pen.style = logpen.lopnStyle & PS_STYLE_MASK;
70 physDev->pen.type = logpen.lopnStyle & PS_TYPE_MASK;
71 physDev->pen.endcap = logpen.lopnStyle & PS_ENDCAP_MASK;
72 physDev->pen.linejoin = logpen.lopnStyle & PS_JOIN_MASK;
74 physDev->pen.width = logpen.lopnWidth.x;
75 if ((logpen.lopnStyle & PS_GEOMETRIC) || (physDev->pen.width >= 1))
77 physDev->pen.width = X11DRV_XWStoDS( physDev, physDev->pen.width );
78 if (physDev->pen.width < 0) physDev->pen.width = -physDev->pen.width;
81 if (physDev->pen.width == 1) physDev->pen.width = 0; /* Faster */
82 if (hpen == GetStockObject( DC_PEN ))
83 logpen.lopnColor = GetDCPenColor( dev->hdc );
84 physDev->pen.pixel = X11DRV_PALETTE_ToPhysical( physDev, logpen.lopnColor );
85 switch(logpen.lopnStyle & PS_STYLE_MASK)
87 case PS_DASH:
88 physDev->pen.dash_len = sizeof(PEN_dash)/sizeof(*PEN_dash);
89 memcpy(physDev->pen.dashes, physDev->pen.ext ? EXTPEN_dash : PEN_dash,
90 physDev->pen.dash_len);
91 break;
92 case PS_DOT:
93 physDev->pen.dash_len = sizeof(PEN_dot)/sizeof(*PEN_dot);
94 memcpy(physDev->pen.dashes, physDev->pen.ext ? EXTPEN_dot : PEN_dot,
95 physDev->pen.dash_len);
96 break;
97 case PS_DASHDOT:
98 physDev->pen.dash_len = sizeof(PEN_dashdot)/sizeof(*PEN_dashdot);
99 memcpy(physDev->pen.dashes, physDev->pen.ext ? EXTPEN_dashdot : PEN_dashdot,
100 physDev->pen.dash_len);
101 break;
102 case PS_DASHDOTDOT:
103 physDev->pen.dash_len = sizeof(PEN_dashdotdot)/sizeof(*PEN_dashdotdot);
104 memcpy(physDev->pen.dashes, physDev->pen.ext ? EXTPEN_dashdotdot : PEN_dashdotdot,
105 physDev->pen.dash_len);
106 break;
107 case PS_ALTERNATE:
108 physDev->pen.dash_len = sizeof(PEN_alternate)/sizeof(*PEN_alternate);
109 memcpy(physDev->pen.dashes, PEN_alternate, physDev->pen.dash_len);
110 break;
111 case PS_USERSTYLE:
112 FIXME("PS_USERSTYLE is not supported\n");
113 /* fall through */
114 default:
115 physDev->pen.dash_len = 0;
116 break;
118 if(physDev->pen.ext && physDev->pen.dash_len &&
119 (logpen.lopnStyle & PS_STYLE_MASK) != PS_ALTERNATE)
120 for(i = 0; i < physDev->pen.dash_len; i++)
121 physDev->pen.dashes[i] *= (physDev->pen.width ? physDev->pen.width : 1);
123 return hpen;
127 /***********************************************************************
128 * SetDCPenColor (X11DRV.@)
130 COLORREF X11DRV_SetDCPenColor( PHYSDEV dev, COLORREF crColor )
132 X11DRV_PDEVICE *physDev = get_x11drv_dev( dev );
134 if (GetCurrentObject(dev->hdc, OBJ_PEN) == GetStockObject( DC_PEN ))
135 physDev->pen.pixel = X11DRV_PALETTE_ToPhysical( physDev, crColor );
137 return crColor;