1 | /* $Id: line.cpp,v 1.13 2002-11-26 10:53:10 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 |
|
---|
23 | VOID 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 |
|
---|
51 | BOOL 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 |
|
---|
73 | BOOL 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 | if (lpPoint)
|
---|
84 | {
|
---|
85 | POINTLOS2 lastPoint;
|
---|
86 |
|
---|
87 | OSLibGpiQueryCurrentPosition(pHps,&lastPoint);
|
---|
88 | lpPoint->x = lastPoint.x;
|
---|
89 | lpPoint->y = lastPoint.y;
|
---|
90 | }
|
---|
91 |
|
---|
92 | #ifndef INVERT
|
---|
93 | if(pHps->yInvert > 0) {
|
---|
94 | newPoint.y = pHps->yInvert - newPoint.y;
|
---|
95 | if (lpPoint) {
|
---|
96 | lpPoint->y = pHps->yInvert - lpPoint->y;
|
---|
97 | }
|
---|
98 | }
|
---|
99 | #endif
|
---|
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 | //******************************************************************************
|
---|
115 | BOOL 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 | //******************************************************************************
|
---|
166 | BOOL 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 | #if 0 //CB: the Open32 function is ok -> to check
|
---|
173 | startPt.x = nXStart;
|
---|
174 | startPt.y = nYStart;
|
---|
175 | toWin32LineEnd(&startPt,nXEnd,nYEnd,&endPt);
|
---|
176 |
|
---|
177 | rc = O32_LineDDA(startPt.x,startPt.y,endPt.x,endPt.y, lpLineFunc, lpData);
|
---|
178 | #else
|
---|
179 | rc = O32_LineDDA(nXStart,nYStart,nXEnd,nYEnd,callback->GetOS2Callback(),(LPARAM)callback);
|
---|
180 | if(callback)
|
---|
181 | delete callback;
|
---|
182 | #endif
|
---|
183 | return(rc);
|
---|
184 | }
|
---|
185 | //******************************************************************************
|
---|
186 | //******************************************************************************
|
---|
187 | BOOL WIN32API Polyline( HDC hdc, const POINT *lppt, int cPoints)
|
---|
188 | {
|
---|
189 | pDCData pHps = (pDCData)OSLibGpiQueryDCData(hdc);
|
---|
190 |
|
---|
191 | if (!pHps)
|
---|
192 | {
|
---|
193 | SetLastError(ERROR_INVALID_HANDLE);
|
---|
194 | return FALSE;
|
---|
195 | }
|
---|
196 |
|
---|
197 | if (cPoints == 0) return TRUE;
|
---|
198 | if (cPoints < 0)
|
---|
199 | {
|
---|
200 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
201 | return FALSE;
|
---|
202 | }
|
---|
203 |
|
---|
204 | if (cPoints == 1)
|
---|
205 | {
|
---|
206 | drawSingleLinePoint(hdc,pHps,(PPOINTLOS2)lppt); //CB: check metafile recording
|
---|
207 | return TRUE;
|
---|
208 | }
|
---|
209 |
|
---|
210 | POINT *points = (POINT*)lppt;
|
---|
211 | POINT lastPt = lppt[cPoints-1];
|
---|
212 | BOOL rc;
|
---|
213 |
|
---|
214 | toWin32LineEnd((PPOINTLOS2)&lppt[cPoints-2],lastPt.x,lastPt.y,(PPOINTLOS2)&points[cPoints-1]);
|
---|
215 | rc = O32_Polyline(hdc,lppt,cPoints);
|
---|
216 | points[cPoints-1] = lastPt;
|
---|
217 |
|
---|
218 | return rc;
|
---|
219 | }
|
---|
220 | //******************************************************************************
|
---|
221 | //******************************************************************************
|
---|
222 | BOOL WIN32API PolylineTo( HDC hdc, const POINT * lppt, DWORD cCount)
|
---|
223 | {
|
---|
224 | pDCData pHps = (pDCData)OSLibGpiQueryDCData(hdc);
|
---|
225 |
|
---|
226 | if (!pHps)
|
---|
227 | {
|
---|
228 | SetLastError(ERROR_INVALID_HANDLE);
|
---|
229 | return FALSE;
|
---|
230 | }
|
---|
231 |
|
---|
232 | if (cCount == 0) return TRUE;
|
---|
233 |
|
---|
234 | //CB: add metafile info
|
---|
235 |
|
---|
236 | if (cCount == 1)
|
---|
237 | {
|
---|
238 | drawSingleLinePoint(hdc,pHps,(PPOINTLOS2)lppt);
|
---|
239 | return TRUE;
|
---|
240 | }
|
---|
241 |
|
---|
242 | POINT *points = (POINT*)lppt;
|
---|
243 | POINT lastPt = lppt[cCount-1];
|
---|
244 | BOOL rc;
|
---|
245 |
|
---|
246 | toWin32LineEnd((PPOINTLOS2)&lppt[cCount-2],lastPt.x,lastPt.y,(PPOINTLOS2)&points[cCount-1]);
|
---|
247 | rc = O32_PolylineTo(hdc,lppt,cCount);
|
---|
248 | points[cCount-1] = lastPt;
|
---|
249 | OSLibGpiMove(pHps,(PPOINTLOS2)&lastPt);
|
---|
250 |
|
---|
251 | return rc;
|
---|
252 | }
|
---|
253 | //******************************************************************************
|
---|
254 | //******************************************************************************
|
---|
255 |
|
---|