Initial revision
[wine] / graphics / win16drv / graphics.c
1 /*
2  * Windows 16 bit device driver graphics functions
3  *
4  * Copyright 1997 John Harvey
5  */
6
7 #include <stdio.h>
8 #include "heap.h"
9 #include "win16drv.h"
10 #include "debug.h"
11
12 /**********************************************************************
13  *           WIN16DRV_MoveToEx
14  */
15 BOOL32
16 WIN16DRV_MoveToEx(DC *dc,INT32 x,INT32 y,LPPOINT32 pt) 
17 {
18     if (pt)
19     {
20         pt->x = dc->w.CursPosX;
21         pt->y = dc->w.CursPosY;
22     }
23     dc->w.CursPosX = x;
24     dc->w.CursPosY = y;
25     return TRUE;
26 }
27
28 /***********************************************************************
29  *           WIN16DRV_LineTo
30  */
31 BOOL32
32 WIN16DRV_LineTo( DC *dc, INT32 x, INT32 y )
33 {
34     BOOL32 bRet ;
35     WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dc->physDev;
36     POINT16 points[2];
37     points[0].x = dc->w.DCOrgX + XLPTODP( dc, dc->w.CursPosX );
38     points[0].y = dc->w.DCOrgY + YLPTODP( dc, dc->w.CursPosY );
39     points[1].x = dc->w.DCOrgX + XLPTODP( dc, x );
40     points[1].y = dc->w.DCOrgY + YLPTODP( dc, y );
41     bRet = PRTDRV_Output(physDev->segptrPDEVICE,
42                          OS_POLYLINE, 2, points, 
43                          physDev->PenInfo,
44                          NULL,
45                          win16drv_SegPtr_DrawMode, dc->w.hClipRgn);
46
47     dc->w.CursPosX = x;
48     dc->w.CursPosY = y;
49     return TRUE;
50 }
51
52
53 /***********************************************************************
54  *           WIN16DRV_Rectangle
55  */
56 BOOL32
57 WIN16DRV_Rectangle(DC *dc, INT32 left, INT32 top, INT32 right, INT32 bottom)
58 {
59     WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dc->physDev;
60     BOOL32 bRet = 0;
61     POINT16 points[2];
62
63     TRACE(win16drv, "In WIN16DRV_Rectangle, x %d y %d DCOrgX %d y %d\n",
64            left, top, dc->w.DCOrgX, dc->w.DCOrgY);
65     TRACE(win16drv, "In WIN16DRV_Rectangle, VPortOrgX %d y %d\n",
66            dc->vportOrgX, dc->vportOrgY);
67     points[0].x = XLPTODP(dc, left);
68     points[0].y = YLPTODP(dc, top);
69
70     points[1].x = XLPTODP(dc, right);
71     points[1].y = YLPTODP(dc, bottom);
72     bRet = PRTDRV_Output(physDev->segptrPDEVICE,
73                            OS_RECTANGLE, 2, points, 
74                            physDev->PenInfo,
75                            physDev->BrushInfo,
76                            win16drv_SegPtr_DrawMode, dc->w.hClipRgn);
77     return bRet;
78 }
79
80
81
82
83 /***********************************************************************
84  *           WIN16DRV_Polygon
85  */
86 BOOL32
87 WIN16DRV_Polygon(DC *dc, LPPOINT32 pt, INT32 count )
88 {
89     WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dc->physDev;
90     BOOL32 bRet = 0;
91     LPPOINT16 points;
92     int i;
93
94     if(count < 2) return TRUE;
95     if(pt[0].x != pt[count-1].x || pt[0].y != pt[count-1].y)
96         count++; /* Ensure polygon is closed */
97
98     points = HEAP_xalloc( GetProcessHeap(), 0, count * sizeof(POINT16) );
99     for (i = 0; i < count - 1; i++)
100     {
101       points[i].x = XLPTODP( dc, pt[i].x );
102       points[i].y = YLPTODP( dc, pt[i].y );
103     }
104     points[count-1].x = points[0].x;
105     points[count-1].y = points[0].y;
106     bRet = PRTDRV_Output(physDev->segptrPDEVICE,
107                          OS_WINDPOLYGON, count, points, 
108                          physDev->PenInfo,
109                          physDev->BrushInfo,
110                          win16drv_SegPtr_DrawMode, dc->w.hClipRgn);
111     HeapFree( GetProcessHeap(), 0, points );
112     return bRet;
113 }
114
115
116 /***********************************************************************
117  *           WIN16DRV_Polyline
118  */
119 BOOL32
120 WIN16DRV_Polyline(DC *dc, LPPOINT32 pt, INT32 count )
121 {
122     WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dc->physDev;
123     BOOL32 bRet = 0;
124     LPPOINT16 points;
125     int i;
126
127     if(count < 2) return TRUE;
128
129     points = HEAP_xalloc( GetProcessHeap(), 0, count * sizeof(POINT16) );
130     for (i = 0; i < count; i++)
131     {
132       points[i].x = XLPTODP( dc, pt[i].x );
133       points[i].y = YLPTODP( dc, pt[i].y );
134     }
135     bRet = PRTDRV_Output(physDev->segptrPDEVICE,
136                          OS_POLYLINE, count, points, 
137                          physDev->PenInfo,
138                          NULL,
139                          win16drv_SegPtr_DrawMode, dc->w.hClipRgn);
140     HeapFree( GetProcessHeap(), 0, points );
141     return bRet;
142 }
143
144
145
146 /***********************************************************************
147  *           WIN16DRV_Ellipse
148  */
149 BOOL32
150 WIN16DRV_Ellipse(DC *dc, INT32 left, INT32 top, INT32 right, INT32 bottom)
151 {
152     WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dc->physDev;
153     BOOL32 bRet = 0;
154     POINT16 points[2];
155     TRACE(win16drv, "In WIN16DRV_Ellipse, x %d y %d DCOrgX %d y %d\n",
156            left, top, dc->w.DCOrgX, dc->w.DCOrgY);
157     TRACE(win16drv, "In WIN16DRV_Ellipse, VPortOrgX %d y %d\n",
158            dc->vportOrgX, dc->vportOrgY);
159     points[0].x = XLPTODP(dc, left);
160     points[0].y = YLPTODP(dc, top);
161
162     points[1].x = XLPTODP(dc, right);
163     points[1].y = YLPTODP(dc, bottom);
164
165     bRet = PRTDRV_Output(physDev->segptrPDEVICE,
166                          OS_ELLIPSE, 2, points, 
167                          physDev->PenInfo,
168                          physDev->BrushInfo,
169                          win16drv_SegPtr_DrawMode, dc->w.hClipRgn);
170     return bRet;
171 }
172
173
174
175
176
177
178
179