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

Last change on this file since 10594 was 10594, checked in by sandervl, 21 years ago

drawSingleLinePoint: wrong pen style checks; logging updates

File size: 8.1 KB
Line 
1/* $Id: line.cpp,v 1.17 2004-04-30 13:27:18 sandervl 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#include <dcdata.h>
17#include "region.h"
18
19#define DBG_LOCALLOG DBG_line
20#include "dbglocal.h"
21
22#define ROUND_FLOAT(x) ((INT)((x < 0) ? x-0.5:x+0.5))
23
24//******************************************************************************
25//******************************************************************************
26VOID toWin32LineEnd(pDCData pHps, PPOINTLOS2 startPt,INT nXEnd,INT nYEnd,PPOINTLOS2 pt)
27{
28// SvL: This breaks path creation when used as a clip region in a printer DC
29// (offset by one for x coordinates make the rectangle not so rectangular anymore)
30// Removing it alltogether causes nice drawing errors on the screen, so
31// we'll simply ignore it when we're inside a path definition.
32 if(pHps->inPath)
33 {
34 LONG vertRes = hdcHeight(pHps->hwnd, pHps);
35 LONG horzRes = hdcWidth(pHps->hwnd, pHps);
36
37 // LineTo will return an error if the coordinates are outside the DC
38 pt->x = (nXEnd >= horzRes) ? horzRes-1 : nXEnd;
39 pt->y = (nYEnd >= vertRes) ? vertRes-1 : nYEnd;
40 }
41 else
42 if ((startPt->x != nXEnd) || (startPt->y != nYEnd))
43 {
44 if (nXEnd == startPt->x)
45 {
46 pt->x = nXEnd;
47 pt->y = (nYEnd > startPt->y) ? nYEnd-1:nYEnd+1;
48 } else if (nYEnd == startPt->y)
49 {
50 pt->x = (nXEnd > startPt->x) ? nXEnd-1:nXEnd+1;
51 pt->y = nYEnd;
52 } else
53 {
54 INT w = nXEnd-startPt->x,h = nYEnd-startPt->y;
55 DOUBLE len = hypot(w,h);
56 DOUBLE lenQuot = (len-1)/len;
57
58 pt->x = startPt->x+ROUND_FLOAT(w*lenQuot);
59 pt->y = startPt->y+ROUND_FLOAT(h*lenQuot);
60 }
61 } else
62 {
63 pt->x = nXEnd;
64 pt->y = nYEnd;
65 }
66}
67//******************************************************************************
68//******************************************************************************
69BOOL drawSingleLinePoint(HDC hdc,pDCData pHps,PPOINTLOS2 pt)
70{
71 LOGPEN penInfo;
72 EXTLOGPEN extpenInfo;
73
74 if (!GetObjectA(GetCurrentObject(hdc,OBJ_PEN),sizeof(penInfo),(LPVOID)&penInfo))
75 {//try extlogpen
76 if (!GetObjectA(GetCurrentObject(hdc,OBJ_PEN),sizeof(extpenInfo),(LPVOID)&extpenInfo)) {
77 return FALSE;
78 }
79 penInfo.lopnStyle = extpenInfo.elpPenStyle;
80 penInfo.lopnWidth.x = extpenInfo.elpWidth;
81 penInfo.lopnWidth.y = 0; //??????
82 penInfo.lopnColor = extpenInfo.elpColor;
83 }
84
85 if ((penInfo.lopnWidth.x > 1) || (penInfo.lopnWidth.y > 1))
86 {
87 if (((penInfo.lopnStyle & PS_STYLE_MASK) != PS_INSIDEFRAME) && ((penInfo.lopnStyle & PS_STYLE_MASK) != PS_SOLID))
88 {
89 dprintf(("drawSingleLinePoint -> not PS_INSIDEFRAME nor PS_SOLID"));
90 return TRUE; //TODO: ??
91 }
92
93 LONG color = GetBValue(penInfo.lopnColor) | (GetGValue(penInfo.lopnColor)<<8) | (GetRValue(penInfo.lopnColor)<<16);
94
95 return drawLinePointCircle(pHps,penInfo.lopnWidth.x,penInfo.lopnWidth.y,color);
96 }
97 else
98 {
99 LONG color = GetBValue(penInfo.lopnColor) | (GetGValue(penInfo.lopnColor)<<8) | (GetRValue(penInfo.lopnColor)<<16);
100
101 return drawLinePoint(pHps,pt,color);
102 }
103}
104//******************************************************************************
105//******************************************************************************
106BOOL WIN32API MoveToEx( HDC hdc, int X, int Y, LPPOINT lpPoint)
107{
108 pDCData pHps = (pDCData)OSLibGpiQueryDCData(hdc);
109
110 dprintf(("GDI32: MoveToEx %x (%d,%d)", hdc, X, Y));
111
112 if (pHps)
113 {
114 POINTLOS2 newPoint = {X,Y};
115
116 if (lpPoint)
117 {
118 POINTLOS2 lastPoint;
119
120 OSLibGpiQueryCurrentPosition(pHps,&lastPoint);
121 lpPoint->x = lastPoint.x;
122 lpPoint->y = lastPoint.y;
123 }
124
125#ifndef INVERT
126 if(pHps->yInvert > 0) {
127 newPoint.y = pHps->yInvert - newPoint.y;
128 if (lpPoint) {
129 lpPoint->y = pHps->yInvert - lpPoint->y;
130 }
131 }
132#endif
133
134 if(OSLibGpiMove(pHps,&newPoint))
135 {
136 //CB: add metafile info
137 return TRUE;
138 }
139
140 return FALSE;
141 }
142
143 SetLastError(ERROR_INVALID_HANDLE);
144 return FALSE;
145}
146//******************************************************************************
147//******************************************************************************
148BOOL WIN32API LineTo( HDC hdc, int nXEnd, int nYEnd)
149{
150 pDCData pHps = (pDCData)OSLibGpiQueryDCData(hdc);
151 BOOL rc = TRUE;
152
153 dprintf(("GDI32: LineTo %x (%d,%d)", hdc, nXEnd, nYEnd));
154
155 if (pHps)
156 {
157 POINTLOS2 oldPoint,newPoint;
158 BOOL bWideLine;
159
160#ifndef INVERT
161 if (pHps->yInvert > 0) {
162 nYEnd = pHps->yInvert - nYEnd;
163 }
164#endif
165 //CB: add metafile info
166
167 OSLibGpiQueryCurrentPosition(pHps,&oldPoint);
168 toWin32LineEnd(pHps, &oldPoint,nXEnd,nYEnd,&newPoint);
169
170 if ((oldPoint.x == newPoint.x) && (oldPoint.y == newPoint.y))
171 {
172 rc = drawSingleLinePoint(hdc,pHps,&newPoint);
173 } else
174 {
175 if (getIsWideLine(pHps))
176 {
177 rc = O32_LineTo(hdc,newPoint.x,newPoint.y); //CB: wide line not supported
178 } else
179 {
180 if (OSLibGpiLine(pHps,&newPoint) == FALSE)
181 rc = FALSE;
182 }
183 }
184
185 newPoint.x = nXEnd;
186 newPoint.y = nYEnd;
187 // Do not change the current position when we're defining a path.
188 // toWin32LineEnd can change the coordinates which would break up the path.
189 if (!pHps->inPath)
190 OSLibGpiMove(pHps,&newPoint);
191 }
192 else
193 {
194 SetLastError(ERROR_INVALID_HANDLE);
195 rc = FALSE;
196 }
197
198 return rc;
199}
200//******************************************************************************
201//******************************************************************************
202BOOL WIN32API LineDDA( int nXStart, int nYStart, int nXEnd, int nYEnd, LINEDDAPROC lpLineFunc, LPARAM lpData)
203{
204 BOOL rc;
205 LineDDAProcCallback *callback = new LineDDAProcCallback(lpLineFunc, lpData);
206 POINTLOS2 startPt,endPt;
207
208#if 0 //CB: the Open32 function is ok -> to check
209 startPt.x = nXStart;
210 startPt.y = nYStart;
211 toWin32LineEnd(&startPt,nXEnd,nYEnd,&endPt);
212
213 rc = O32_LineDDA(startPt.x,startPt.y,endPt.x,endPt.y, lpLineFunc, lpData);
214#else
215 rc = O32_LineDDA(nXStart,nYStart,nXEnd,nYEnd,callback->GetOS2Callback(),(LPARAM)callback);
216 if(callback)
217 delete callback;
218#endif
219 return(rc);
220}
221//******************************************************************************
222//******************************************************************************
223BOOL WIN32API Polyline( HDC hdc, const POINT *lppt, int cPoints)
224{
225 pDCData pHps = (pDCData)OSLibGpiQueryDCData(hdc);
226
227 if (!pHps)
228 {
229 SetLastError(ERROR_INVALID_HANDLE);
230 return FALSE;
231 }
232
233 if (cPoints == 0) return TRUE;
234 if (cPoints < 0)
235 {
236 SetLastError(ERROR_INVALID_PARAMETER);
237 return FALSE;
238 }
239
240 if (cPoints == 1)
241 {
242 drawSingleLinePoint(hdc,pHps,(PPOINTLOS2)lppt); //CB: check metafile recording
243 return TRUE;
244 }
245
246 POINT *points = (POINT*)lppt;
247 POINT lastPt = lppt[cPoints-1];
248 BOOL rc;
249
250 toWin32LineEnd(pHps, (PPOINTLOS2)&lppt[cPoints-2],lastPt.x,lastPt.y,(PPOINTLOS2)&points[cPoints-1]);
251 rc = O32_Polyline(hdc,lppt,cPoints);
252 points[cPoints-1] = lastPt;
253
254 return rc;
255}
256//******************************************************************************
257//******************************************************************************
258BOOL WIN32API PolylineTo( HDC hdc, const POINT * lppt, DWORD cCount)
259{
260 pDCData pHps = (pDCData)OSLibGpiQueryDCData(hdc);
261
262 if (!pHps)
263 {
264 SetLastError(ERROR_INVALID_HANDLE);
265 return FALSE;
266 }
267
268 if (cCount == 0) return TRUE;
269
270 //CB: add metafile info
271
272 if (cCount == 1)
273 {
274 drawSingleLinePoint(hdc,pHps,(PPOINTLOS2)lppt);
275 return TRUE;
276 }
277
278 POINT *points = (POINT*)lppt;
279 POINT lastPt = lppt[cCount-1];
280 BOOL rc;
281
282 toWin32LineEnd(pHps, (PPOINTLOS2)&lppt[cCount-2],lastPt.x,lastPt.y,(PPOINTLOS2)&points[cCount-1]);
283 rc = O32_PolylineTo(hdc,lppt,cCount);
284 points[cCount-1] = lastPt;
285 OSLibGpiMove(pHps,(PPOINTLOS2)&lastPt);
286
287 return rc;
288}
289//******************************************************************************
290//******************************************************************************
291
Note: See TracBrowser for help on using the repository browser.