| 1 | /* $Id: line.cpp,v 1.18 2004-05-05 09:19: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 | #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 | //******************************************************************************
|
|---|
| 26 | VOID 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 | //******************************************************************************
|
|---|
| 69 | BOOL 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 | //******************************************************************************
|
|---|
| 106 | BOOL 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 | //******************************************************************************
|
|---|
| 148 | BOOL 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 (!pHps->inPath && (oldPoint.x == newPoint.x) && (oldPoint.y == newPoint.y))
|
|---|
| 171 | {
|
|---|
| 172 | rc = drawSingleLinePoint(hdc,pHps,&newPoint);
|
|---|
| 173 | }
|
|---|
| 174 | else
|
|---|
| 175 | {
|
|---|
| 176 | if (!pHps->inPath && getIsWideLine(pHps))
|
|---|
| 177 | {
|
|---|
| 178 | rc = O32_LineTo(hdc,newPoint.x,newPoint.y); //CB: wide line not supported
|
|---|
| 179 | }
|
|---|
| 180 | else
|
|---|
| 181 | {
|
|---|
| 182 | if (OSLibGpiLine(pHps,&newPoint) == FALSE)
|
|---|
| 183 | rc = FALSE;
|
|---|
| 184 | }
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 | newPoint.x = nXEnd;
|
|---|
| 188 | newPoint.y = nYEnd;
|
|---|
| 189 | // Do not change the current position when we're defining a path.
|
|---|
| 190 | // toWin32LineEnd can change the coordinates which would break up the path.
|
|---|
| 191 | if (!pHps->inPath)
|
|---|
| 192 | OSLibGpiMove(pHps,&newPoint);
|
|---|
| 193 | }
|
|---|
| 194 | else
|
|---|
| 195 | {
|
|---|
| 196 | SetLastError(ERROR_INVALID_HANDLE);
|
|---|
| 197 | rc = FALSE;
|
|---|
| 198 | }
|
|---|
| 199 |
|
|---|
| 200 | return rc;
|
|---|
| 201 | }
|
|---|
| 202 | //******************************************************************************
|
|---|
| 203 | //******************************************************************************
|
|---|
| 204 | BOOL WIN32API LineDDA( int nXStart, int nYStart, int nXEnd, int nYEnd, LINEDDAPROC lpLineFunc, LPARAM lpData)
|
|---|
| 205 | {
|
|---|
| 206 | BOOL rc;
|
|---|
| 207 | LineDDAProcCallback *callback = new LineDDAProcCallback(lpLineFunc, lpData);
|
|---|
| 208 | POINTLOS2 startPt,endPt;
|
|---|
| 209 |
|
|---|
| 210 | #if 0 //CB: the Open32 function is ok -> to check
|
|---|
| 211 | startPt.x = nXStart;
|
|---|
| 212 | startPt.y = nYStart;
|
|---|
| 213 | toWin32LineEnd(&startPt,nXEnd,nYEnd,&endPt);
|
|---|
| 214 |
|
|---|
| 215 | rc = O32_LineDDA(startPt.x,startPt.y,endPt.x,endPt.y, lpLineFunc, lpData);
|
|---|
| 216 | #else
|
|---|
| 217 | rc = O32_LineDDA(nXStart,nYStart,nXEnd,nYEnd,callback->GetOS2Callback(),(LPARAM)callback);
|
|---|
| 218 | if(callback)
|
|---|
| 219 | delete callback;
|
|---|
| 220 | #endif
|
|---|
| 221 | return(rc);
|
|---|
| 222 | }
|
|---|
| 223 | //******************************************************************************
|
|---|
| 224 | //******************************************************************************
|
|---|
| 225 | BOOL WIN32API Polyline( HDC hdc, const POINT *lppt, int cPoints)
|
|---|
| 226 | {
|
|---|
| 227 | pDCData pHps = (pDCData)OSLibGpiQueryDCData(hdc);
|
|---|
| 228 |
|
|---|
| 229 | if (!pHps)
|
|---|
| 230 | {
|
|---|
| 231 | SetLastError(ERROR_INVALID_HANDLE);
|
|---|
| 232 | return FALSE;
|
|---|
| 233 | }
|
|---|
| 234 |
|
|---|
| 235 | if (cPoints == 0) return TRUE;
|
|---|
| 236 | if (cPoints < 0)
|
|---|
| 237 | {
|
|---|
| 238 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 239 | return FALSE;
|
|---|
| 240 | }
|
|---|
| 241 |
|
|---|
| 242 | if (cPoints == 1)
|
|---|
| 243 | {
|
|---|
| 244 | drawSingleLinePoint(hdc,pHps,(PPOINTLOS2)lppt); //CB: check metafile recording
|
|---|
| 245 | return TRUE;
|
|---|
| 246 | }
|
|---|
| 247 |
|
|---|
| 248 | POINT *points = (POINT*)lppt;
|
|---|
| 249 | POINT lastPt = lppt[cPoints-1];
|
|---|
| 250 | BOOL rc;
|
|---|
| 251 |
|
|---|
| 252 | toWin32LineEnd(pHps, (PPOINTLOS2)&lppt[cPoints-2],lastPt.x,lastPt.y,(PPOINTLOS2)&points[cPoints-1]);
|
|---|
| 253 | rc = O32_Polyline(hdc,lppt,cPoints);
|
|---|
| 254 | points[cPoints-1] = lastPt;
|
|---|
| 255 |
|
|---|
| 256 | return rc;
|
|---|
| 257 | }
|
|---|
| 258 | //******************************************************************************
|
|---|
| 259 | //******************************************************************************
|
|---|
| 260 | BOOL WIN32API PolylineTo( HDC hdc, const POINT * lppt, DWORD cCount)
|
|---|
| 261 | {
|
|---|
| 262 | pDCData pHps = (pDCData)OSLibGpiQueryDCData(hdc);
|
|---|
| 263 |
|
|---|
| 264 | if (!pHps)
|
|---|
| 265 | {
|
|---|
| 266 | SetLastError(ERROR_INVALID_HANDLE);
|
|---|
| 267 | return FALSE;
|
|---|
| 268 | }
|
|---|
| 269 |
|
|---|
| 270 | if (cCount == 0) return TRUE;
|
|---|
| 271 |
|
|---|
| 272 | //CB: add metafile info
|
|---|
| 273 |
|
|---|
| 274 | if (cCount == 1)
|
|---|
| 275 | {
|
|---|
| 276 | drawSingleLinePoint(hdc,pHps,(PPOINTLOS2)lppt);
|
|---|
| 277 | return TRUE;
|
|---|
| 278 | }
|
|---|
| 279 |
|
|---|
| 280 | POINT *points = (POINT*)lppt;
|
|---|
| 281 | POINT lastPt = lppt[cCount-1];
|
|---|
| 282 | BOOL rc;
|
|---|
| 283 |
|
|---|
| 284 | toWin32LineEnd(pHps, (PPOINTLOS2)&lppt[cCount-2],lastPt.x,lastPt.y,(PPOINTLOS2)&points[cCount-1]);
|
|---|
| 285 | rc = O32_PolylineTo(hdc,lppt,cCount);
|
|---|
| 286 | points[cCount-1] = lastPt;
|
|---|
| 287 | OSLibGpiMove(pHps,(PPOINTLOS2)&lastPt);
|
|---|
| 288 |
|
|---|
| 289 | return rc;
|
|---|
| 290 | }
|
|---|
| 291 | //******************************************************************************
|
|---|
| 292 | //******************************************************************************
|
|---|
| 293 |
|
|---|