source: trunk/src/gdi32/line.cpp@ 2775

Last change on this file since 2775 was 2767, checked in by cbratschi, 26 years ago

LineDDA fix

File size: 6.0 KB
Line 
1/* $Id: line.cpp,v 1.5 2000-02-12 18:08:57 cbratschi Exp $ */
2/*
3 * Line API's
4 *
5 * Copyright 1999 Christoph Bratschi (cbratschi@datacomm.ch)
6 *
7 * Project Odin Software License can be found in LICENSE.TXT
8 *
9 */
10
11#include <os2win.h>
12#include <math.h>
13#include "misc.h"
14#include "callback.h"
15#include "oslibgpi.h"
16
17#define ROUND_FLOAT(x) ((INT)((x < 0) ? x-0.5:x+0.5))
18
19VOID toWin32LineEnd(PPOINTLOS2 startPt,INT nXEnd,INT nYEnd,PPOINTLOS2 pt)
20{
21 if ((startPt->x != nXEnd) || (startPt->y != nYEnd))
22 {
23 if (nXEnd == startPt->x)
24 {
25 pt->x = nXEnd;
26 pt->y = (nYEnd > startPt->y) ? nYEnd-1:nYEnd+1;
27 } else if (nYEnd == startPt->y)
28 {
29 pt->x = (nXEnd > startPt->x) ? nXEnd-1:nXEnd+1;
30 pt->y = nYEnd;
31 } else
32 {
33 INT w = nXEnd-startPt->x,h = nYEnd-startPt->y;
34 DOUBLE len = hypot(w,h);
35 DOUBLE lenQuot = (len-1)/len;
36
37 pt->x = startPt->x+ROUND_FLOAT(w*lenQuot);
38 pt->y = startPt->y+ROUND_FLOAT(h*lenQuot);
39 }
40 } else
41 {
42 pt->x = nXEnd;
43 pt->y = nYEnd;
44 }
45}
46
47BOOL drawSingleLinePoint(HDC hdc,PVOID pHps,PPOINTLOS2 pt)
48{
49 LOGPEN penInfo;
50
51 if (!GetObjectA(GetCurrentObject(hdc,OBJ_PEN),sizeof(penInfo),(LPVOID)&penInfo)) return FALSE;
52
53 if ((penInfo.lopnWidth.x > 1) || (penInfo.lopnWidth.y > 1))
54 {
55 if ((penInfo.lopnStyle != PS_INSIDEFRAME) && (penInfo.lopnStyle != PS_SOLID))
56 return FALSE;
57
58 LONG color = GetBValue(penInfo.lopnColor) | (GetGValue(penInfo.lopnColor)<<8) | (GetRValue(penInfo.lopnColor)<<16);
59
60 return drawLinePointCircle(pHps,penInfo.lopnWidth.x,penInfo.lopnWidth.y,color);
61 } else
62 {
63 LONG color = GetBValue(penInfo.lopnColor) | (GetGValue(penInfo.lopnColor)<<8) | (GetRValue(penInfo.lopnColor)<<16);
64
65 return drawLinePoint(pHps,pt,color);
66 }
67}
68
69BOOL WIN32API MoveToEx( HDC hdc, int X, int Y, LPPOINT lpPoint)
70{
71 PVOID pHps = OSLibGpiQueryDCData(hdc);
72
73 dprintf(("GDI32: MoveToEx %x (%d,%d)", hdc, X, Y));
74
75 if (pHps)
76 {
77 POINTLOS2 newPoint = {X,Y};
78
79 if (lpPoint)
80 {
81 POINTLOS2 lastPoint;
82
83 OSLibGpiQueryCurrentPosition(pHps,&lastPoint);
84 lpPoint->x = lastPoint.x;
85 lpPoint->y = lastPoint.y;
86 }
87
88 if (OSLibGpiMove(pHps,&newPoint))
89 {
90 //CB: add metafile info
91 return TRUE;
92 }
93
94 return FALSE;
95 }
96
97 SetLastError(ERROR_INVALID_HANDLE);
98 return FALSE;
99}
100//******************************************************************************
101//******************************************************************************
102BOOL WIN32API LineTo( HDC hdc, int nXEnd, int nYEnd)
103{
104 PVOID pHps = OSLibGpiQueryDCData(hdc);
105 BOOL rc = TRUE;
106
107 dprintf(("GDI32: LineTo %x (%d,%d)", hdc, nXEnd, nYEnd));
108
109 if (pHps)
110 {
111 POINTLOS2 oldPoint,newPoint;
112 BOOL bWideLine;
113
114 //CB: add metafile info
115
116 OSLibGpiQueryCurrentPosition(pHps,&oldPoint);
117 toWin32LineEnd(&oldPoint,nXEnd,nYEnd,&newPoint);
118
119 if ((oldPoint.x == newPoint.x) && (oldPoint.y == newPoint.y))
120 {
121 rc = drawSingleLinePoint(hdc,pHps,&newPoint);
122 } else
123 {
124 if (getIsWideLine(pHps))
125 {
126 rc = O32_LineTo(hdc,newPoint.x,newPoint.y); //CB: wide line not supported
127 } else
128 {
129 if (OSLibGpiLine(pHps,&newPoint) == 0)
130 rc = FALSE;
131 }
132 }
133
134 newPoint.x = nXEnd;
135 newPoint.y = nYEnd;
136 OSLibGpiMove(pHps,&newPoint);
137 } else
138 {
139 SetLastError(ERROR_INVALID_HANDLE);
140 rc = FALSE;
141 }
142
143 return rc;
144}
145//******************************************************************************
146//******************************************************************************
147BOOL WIN32API LineDDA( int nXStart, int nYStart, int nXEnd, int nYEnd, LINEDDAPROC lpLineFunc, LPARAM lpData)
148{
149 BOOL rc;
150 LineDDAProcCallback *callback = new LineDDAProcCallback(lpLineFunc, lpData);
151 POINTLOS2 startPt,endPt;
152
153 dprintf(("GDI32: LineDDA\n"));
154#if 0 //CB: the Open32 function is ok -> to check
155 startPt.x = nXStart;
156 startPt.y = nYStart;
157 toWin32LineEnd(&startPt,nXEnd,nYEnd,&endPt);
158
159 rc = O32_LineDDA(startPt.x,startPt.y,endPt.x,endPt.y,callback->GetOS2Callback(),(LPARAM)callback);
160#else
161 rc = O32_LineDDA(nXStart,nYStart,nXEnd,nYEnd,callback->GetOS2Callback(),(LPARAM)callback);
162#endif
163 if(callback)
164 delete callback;
165 return(rc);
166}
167//******************************************************************************
168//******************************************************************************
169BOOL WIN32API Polyline( HDC hdc, const POINT *lppt, int cPoints)
170{
171 PVOID pHps = OSLibGpiQueryDCData(hdc);
172
173 dprintf(("GDI32: Polyline"));
174
175 if (!pHps)
176 {
177 SetLastError(ERROR_INVALID_HANDLE);
178 return FALSE;
179 }
180
181 if (cPoints == 0) return TRUE;
182 if (cPoints < 0)
183 {
184 SetLastError(ERROR_INVALID_PARAMETER);
185
186 return FALSE;
187 }
188
189 if (cPoints == 1)
190 {
191 drawSingleLinePoint(hdc,pHps,(PPOINTLOS2)lppt); //CB: check metafile recording
192
193 return TRUE;
194 }
195
196 POINT *points = (POINT*)lppt;
197 POINT lastPt = lppt[cPoints-1];
198 BOOL rc;
199
200 toWin32LineEnd((PPOINTLOS2)&lppt[cPoints-2],lastPt.x,lastPt.y,(PPOINTLOS2)&points[cPoints-1]);
201 rc = O32_Polyline(hdc,lppt,cPoints);
202 points[cPoints-1] = lastPt;
203
204 return rc;
205}
206//******************************************************************************
207//******************************************************************************
208BOOL WIN32API PolylineTo( HDC hdc, const POINT * lppt, DWORD cCount)
209{
210 PVOID pHps = OSLibGpiQueryDCData(hdc);
211
212 dprintf(("GDI32: PolylineTo"));
213
214 if (!pHps)
215 {
216 SetLastError(ERROR_INVALID_HANDLE);
217 return FALSE;
218 }
219
220 if (cCount == 0) return TRUE;
221
222 //CB: add metafile info
223
224 if (cCount == 1)
225 {
226 drawSingleLinePoint(hdc,pHps,(PPOINTLOS2)lppt);
227
228 return TRUE;
229 }
230
231 POINT *points = (POINT*)lppt;
232 POINT lastPt = lppt[cCount-1];
233 BOOL rc;
234
235 toWin32LineEnd((PPOINTLOS2)&lppt[cCount-2],lastPt.x,lastPt.y,(PPOINTLOS2)&points[cCount-1]);
236 rc = O32_PolylineTo(hdc,lppt,cCount);
237 points[cCount-1] = lastPt;
238 OSLibGpiMove(pHps,(PPOINTLOS2)&lastPt);
239
240 return rc;
241}
242//******************************************************************************
243//******************************************************************************
244
Note: See TracBrowser for help on using the repository browser.