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

Last change on this file since 5044 was 5044, checked in by sandervl, 25 years ago

callback fixes

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