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