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

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

OffsetRgn fix + small changes

File size: 6.6 KB
Line 
1/* $Id: line.cpp,v 1.7 2000-11-04 16:29:24 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#ifndef STDCALL_ENUMPROCS
170 LineDDAProcCallback *callback = new LineDDAProcCallback(lpLineFunc, lpData);
171#endif
172 POINTLOS2 startPt,endPt;
173
174 dprintf(("GDI32: LineDDA\n"));
175#if 0 //CB: the Open32 function is ok -> to check
176 startPt.x = nXStart;
177 startPt.y = nYStart;
178 toWin32LineEnd(&startPt,nXEnd,nYEnd,&endPt);
179
180 rc = O32_LineDDA(startPt.x,startPt.y,endPt.x,endPt.y, lpLineFunc, lpData);
181#else
182#ifdef STDCALL_ENUMPROCS
183 //should change os2win.h
184 rc = O32_LineDDA(nXStart,nYStart,nXEnd,nYEnd, (LINEDDAPROC_O32)lpLineFunc, lpData);
185#else
186 rc = O32_LineDDA(nXStart,nYStart,nXEnd,nYEnd,callback->GetOS2Callback(),(LPARAM)callback);
187 if(callback)
188 delete callback;
189#endif
190
191#endif
192 return(rc);
193}
194//******************************************************************************
195//******************************************************************************
196BOOL WIN32API Polyline( HDC hdc, const POINT *lppt, int cPoints)
197{
198 pDCData pHps = (pDCData)OSLibGpiQueryDCData(hdc);
199
200 dprintf(("GDI32: Polyline"));
201
202 if (!pHps)
203 {
204 SetLastError(ERROR_INVALID_HANDLE);
205 return FALSE;
206 }
207
208 if (cPoints == 0) return TRUE;
209 if (cPoints < 0)
210 {
211 SetLastError(ERROR_INVALID_PARAMETER);
212 return FALSE;
213 }
214
215 if (cPoints == 1)
216 {
217 drawSingleLinePoint(hdc,pHps,(PPOINTLOS2)lppt); //CB: check metafile recording
218 return TRUE;
219 }
220
221 POINT *points = (POINT*)lppt;
222 POINT lastPt = lppt[cPoints-1];
223 BOOL rc;
224
225 toWin32LineEnd((PPOINTLOS2)&lppt[cPoints-2],lastPt.x,lastPt.y,(PPOINTLOS2)&points[cPoints-1]);
226 rc = O32_Polyline(hdc,lppt,cPoints);
227 points[cPoints-1] = lastPt;
228
229 return rc;
230}
231//******************************************************************************
232//******************************************************************************
233BOOL WIN32API PolylineTo( HDC hdc, const POINT * lppt, DWORD cCount)
234{
235 pDCData pHps = (pDCData)OSLibGpiQueryDCData(hdc);
236
237 dprintf(("GDI32: PolylineTo"));
238
239 if (!pHps)
240 {
241 SetLastError(ERROR_INVALID_HANDLE);
242 return FALSE;
243 }
244
245 if (cCount == 0) return TRUE;
246
247 //CB: add metafile info
248
249 if (cCount == 1)
250 {
251 drawSingleLinePoint(hdc,pHps,(PPOINTLOS2)lppt);
252 return TRUE;
253 }
254
255 POINT *points = (POINT*)lppt;
256 POINT lastPt = lppt[cCount-1];
257 BOOL rc;
258
259 toWin32LineEnd((PPOINTLOS2)&lppt[cCount-2],lastPt.x,lastPt.y,(PPOINTLOS2)&points[cCount-1]);
260 rc = O32_PolylineTo(hdc,lppt,cCount);
261 points[cCount-1] = lastPt;
262 OSLibGpiMove(pHps,(PPOINTLOS2)&lastPt);
263
264 return rc;
265}
266//******************************************************************************
267//******************************************************************************
268
Note: See TracBrowser for help on using the repository browser.