wined3d: Support writemasks on texkill in ARB.
[wine.git] / dlls / winex11.drv / pen.c
blob49fe74ca076a804893cf7bec2d2dd7b17416f3ea
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 CDECL X11DRV_SelectPen( X11DRV_PDEVICE *physDev, 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 LOGPEN logpen;
43 int i;
45 if (!GetObjectW( hpen, sizeof(logpen), &logpen ))
47 /* must be an extended pen */
48 EXTLOGPEN *elp;
49 INT size = GetObjectW( hpen, 0, NULL );
51 if (!size) return 0;
53 physDev->pen.ext = 1;
54 elp = HeapAlloc( GetProcessHeap(), 0, size );
56 GetObjectW( hpen, size, elp );
57 /* FIXME: add support for user style pens */
58 logpen.lopnStyle = elp->elpPenStyle;
59 logpen.lopnWidth.x = elp->elpWidth;
60 logpen.lopnWidth.y = 0;
61 logpen.lopnColor = elp->elpColor;
63 HeapFree( GetProcessHeap(), 0, elp );
65 else
66 physDev->pen.ext = 0;
68 physDev->pen.style = logpen.lopnStyle & PS_STYLE_MASK;
69 physDev->pen.type = logpen.lopnStyle & PS_TYPE_MASK;
70 physDev->pen.endcap = logpen.lopnStyle & PS_ENDCAP_MASK;
71 physDev->pen.linejoin = logpen.lopnStyle & PS_JOIN_MASK;
73 physDev->pen.width = logpen.lopnWidth.x;
74 if ((logpen.lopnStyle & PS_GEOMETRIC) || (physDev->pen.width >= 1))
76 physDev->pen.width = X11DRV_XWStoDS( physDev, physDev->pen.width );
77 if (physDev->pen.width < 0) physDev->pen.width = -physDev->pen.width;
80 if (physDev->pen.width == 1) physDev->pen.width = 0; /* Faster */
81 if (hpen == GetStockObject( DC_PEN ))
82 logpen.lopnColor = GetDCPenColor( physDev->hdc );
83 physDev->pen.pixel = X11DRV_PALETTE_ToPhysical( physDev, logpen.lopnColor );
84 switch(logpen.lopnStyle & PS_STYLE_MASK)
86 case PS_DASH:
87 physDev->pen.dash_len = sizeof(PEN_dash)/sizeof(*PEN_dash);
88 memcpy(physDev->pen.dashes, physDev->pen.ext ? EXTPEN_dash : PEN_dash,
89 physDev->pen.dash_len);
90 break;
91 case PS_DOT:
92 physDev->pen.dash_len = sizeof(PEN_dot)/sizeof(*PEN_dot);
93 memcpy(physDev->pen.dashes, physDev->pen.ext ? EXTPEN_dot : PEN_dot,
94 physDev->pen.dash_len);
95 break;
96 case PS_DASHDOT:
97 physDev->pen.dash_len = sizeof(PEN_dashdot)/sizeof(*PEN_dashdot);
98 memcpy(physDev->pen.dashes, physDev->pen.ext ? EXTPEN_dashdot : PEN_dashdot,
99 physDev->pen.dash_len);
100 break;
101 case PS_DASHDOTDOT:
102 physDev->pen.dash_len = sizeof(PEN_dashdotdot)/sizeof(*PEN_dashdotdot);
103 memcpy(physDev->pen.dashes, physDev->pen.ext ? EXTPEN_dashdotdot : PEN_dashdotdot,
104 physDev->pen.dash_len);
105 break;
106 case PS_ALTERNATE:
107 physDev->pen.dash_len = sizeof(PEN_alternate)/sizeof(*PEN_alternate);
108 memcpy(physDev->pen.dashes, PEN_alternate, physDev->pen.dash_len);
109 break;
110 case PS_USERSTYLE:
111 FIXME("PS_USERSTYLE is not supported\n");
112 /* fall through */
113 default:
114 physDev->pen.dash_len = 0;
115 break;
117 if(physDev->pen.ext && physDev->pen.dash_len &&
118 (logpen.lopnStyle & PS_STYLE_MASK) != PS_ALTERNATE)
119 for(i = 0; i < physDev->pen.dash_len; i++)
120 physDev->pen.dashes[i] *= (physDev->pen.width ? physDev->pen.width : 1);
122 return hpen;
126 /***********************************************************************
127 * SetDCPenColor (X11DRV.@)
129 COLORREF CDECL X11DRV_SetDCPenColor( X11DRV_PDEVICE *physDev, COLORREF crColor )
131 if (GetCurrentObject(physDev->hdc, OBJ_PEN) == GetStockObject( DC_PEN ))
132 physDev->pen.pixel = X11DRV_PALETTE_ToPhysical( physDev, crColor );
134 return crColor;