Bugfix: create DDB in X11DRV_DIB_GetDIBits if necessary.
[wine] / graphics / x11drv / pen.c
1 /*
2  * X11DRV pen objects
3  *
4  * Copyright 1993 Alexandre Julliard
5  */
6
7 #include "config.h"
8
9 #ifndef X_DISPLAY_MISSING
10
11 #include "pen.h"
12 #include "color.h"
13 #include "x11drv.h"
14 #include "debugtools.h"
15
16 static const char PEN_dash[]       = { 5,3 };      /* -----   -----   -----  */
17 static const char PEN_dot[]        = { 1,1 };      /* --  --  --  --  --  -- */
18 static const char PEN_dashdot[]    = { 4,3,2,3 };  /* ----   --   ----   --  */
19 static const char PEN_dashdotdot[] = { 4,2,2,2,2,2 }; /* ----  --  --  ----  */
20 static const char PEN_alternate[]  = { 1,1 };      /* FIXME */
21
22 /***********************************************************************
23  *           PEN_SelectObject
24  */
25 HPEN X11DRV_PEN_SelectObject( DC * dc, HPEN hpen, PENOBJ * pen )
26 {
27     HPEN prevHandle = dc->w.hPen;
28     X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
29
30     dc->w.hPen = hpen;
31     physDev->pen.style = pen->logpen.lopnStyle & PS_STYLE_MASK;
32     physDev->pen.type = pen->logpen.lopnStyle & PS_TYPE_MASK;
33     physDev->pen.endcap = pen->logpen.lopnStyle & PS_ENDCAP_MASK;
34     physDev->pen.linejoin = pen->logpen.lopnStyle & PS_JOIN_MASK;
35
36     physDev->pen.width = (pen->logpen.lopnWidth.x * dc->vportExtX +
37                     dc->wndExtX / 2) / dc->wndExtX;
38     if (physDev->pen.width < 0) physDev->pen.width = -physDev->pen.width;
39     if (physDev->pen.width == 1) physDev->pen.width = 0;  /* Faster */
40     physDev->pen.pixel = X11DRV_PALETTE_ToPhysical( dc, pen->logpen.lopnColor );    
41     switch(pen->logpen.lopnStyle & PS_STYLE_MASK)
42     {
43       case PS_DASH:
44         physDev->pen.dashes = (char *)PEN_dash;
45         physDev->pen.dash_len = 2;
46         break;
47       case PS_DOT:
48         physDev->pen.dashes = (char *)PEN_dot;
49         physDev->pen.dash_len = 2;
50         break;
51       case PS_DASHDOT:
52         physDev->pen.dashes = (char *)PEN_dashdot;
53         physDev->pen.dash_len = 4;
54         break;
55       case PS_DASHDOTDOT:
56         physDev->pen.dashes = (char *)PEN_dashdotdot;
57         physDev->pen.dash_len = 6;
58         break;
59       case PS_ALTERNATE:
60         /* FIXME: should be alternating _pixels_ that are set */
61         physDev->pen.dashes = (char *)PEN_alternate;
62         physDev->pen.dash_len = 2;
63         break;
64       case PS_USERSTYLE:
65         /* FIXME */
66         break;
67     }
68     
69     return prevHandle;
70 }
71
72 #endif /* !defined(X_DISPLAY_MISSING) */