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