Changeset 2092 for trunk/src/gdi32/line.cpp
- Timestamp:
- Dec 16, 1999, 5:52:33 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gdi32/line.cpp
r1961 r2092 1 /* $Id: line.cpp,v 1. 1 1999-12-03 17:31:51cbratschi Exp $ */1 /* $Id: line.cpp,v 1.2 1999-12-16 16:52:32 cbratschi Exp $ */ 2 2 /* 3 3 * Line API's … … 13 13 #include "misc.h" 14 14 #include "callback.h" 15 16 //CB: todo: rewrite them without using Open32 15 #include "oslibgpi.h" 17 16 18 17 #define ROUND_FLOAT(x) ((INT)((x < 0) ? x-0.5:x+0.5)) 19 #define sqr(x) (pow(x,2)) 20 21 POINT ToWin32LineEnd(POINT startPt,INT nXEnd,INT nYEnd) 22 { 23 POINT 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; 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; 35 31 } else 36 32 { 37 DOUBLE len = sqrt(sqr(nXEnd-startPt.x)+sqr(nYEnd-startPt.y));38 DOUBLE len Dif = (len-1)/len;39 INT w = nXEnd-startPt.x,h = nYEnd-startPt.y;40 41 pt .x = startPt.x+ROUND_FLOAT(w*lenDif);42 pt .y = startPt.y+ROUND_FLOAT(h*lenDif);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); 43 39 } 44 40 } else 45 41 { 46 pt.x = nXEnd; 47 pt.y = nYEnd; 48 } 49 50 return pt; 51 } 52 53 VOID DrawSingleLinePoint(HDC hdc,POINT pt) 42 pt->x = nXEnd; 43 pt->y = nYEnd; 44 } 45 } 46 47 BOOL drawSingleLinePoint(HDC hdc,PVOID pHps,PPOINTLOS2 pt) 54 48 { 55 49 LOGPEN penInfo; 56 50 57 if (!GetObjectA(GetCurrentObject(hdc,OBJ_PEN),sizeof(penInfo),(LPVOID)&penInfo)) return; 58 if (penInfo.lopnWidth.x <= 1 && penInfo.lopnWidth.y <= 1) SetPixel(hdc,pt.x,pt.y,penInfo.lopnColor); else 59 { 60 INT x = pt.x-penInfo.lopnWidth.x/2; 61 INT y = pt.y-penInfo.lopnWidth.y/2; 62 Ellipse(hdc,x,y,x+penInfo.lopnWidth.x,y+penInfo.lopnWidth.y); 63 } 64 } 65 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\n")); 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 //****************************************************************************** 66 102 BOOL WIN32API LineTo( HDC hdc, int nXEnd, int nYEnd) 67 103 { 68 POINT oldPt,pt; 104 PVOID pHps = OSLibGpiQueryDCData(hdc); 105 BOOL rc = TRUE; 69 106 70 107 dprintf(("GDI32: LineTo")); 71 108 72 //CB: Open32 draws a pixel too much! 73 GetCurrentPositionEx(hdc,&oldPt); 74 pt = ToWin32LineEnd(oldPt,nXEnd,nYEnd); 75 76 BOOL rc; 77 78 if (oldPt.x == pt.x && oldPt.y == pt.y) 79 { 80 DrawSingleLinePoint(hdc,pt); 81 82 rc = TRUE; 83 } else rc = O32_LineTo(hdc,pt.x,pt.y); 84 MoveToEx(hdc,nXEnd,nYEnd,NULL); 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 } 85 142 86 143 return rc; … … 90 147 BOOL WIN32API LineDDA( int nXStart, int nYStart, int nXEnd, int nYEnd, LINEDDAPROC lpLineFunc, LPARAM lpData) 91 148 { 92 BOOL rc;93 LineDDAProcCallback *callback = new LineDDAProcCallback(lpLineFunc, lpData);94 POINTstartPt,endPt;149 BOOL rc; 150 LineDDAProcCallback *callback = new LineDDAProcCallback(lpLineFunc, lpData); 151 POINTLOS2 startPt,endPt; 95 152 96 153 dprintf(("GDI32: LineDDA\n")); 97 154 98 //CB: don't know if Open32 reports the last pixel, but all other line functions do99 155 startPt.x = nXStart; 100 156 startPt.y = nYStart; 101 endPt = ToWin32LineEnd(startPt,nXEnd,nYEnd);157 toWin32LineEnd(&startPt,nXEnd,nYEnd,&endPt); 102 158 103 159 rc = O32_LineDDA(startPt.x,startPt.y,endPt.x,endPt.y,callback->GetOS2Callback(),(LPARAM)callback); … … 110 166 BOOL WIN32API Polyline( HDC hdc, const POINT *lppt, int cPoints) 111 167 { 112 dprintf(("GDI32: Polyline")); 113 114 if (cPoints == 0) return TRUE; 115 if (cPoints < 0) 116 { 117 SetLastError(ERROR_INVALID_PARAMETER); 118 119 return FALSE; 120 } 121 122 if (cPoints == 1) 123 { 124 DrawSingleLinePoint(hdc,*lppt); //CB: check metafile recording 125 126 return TRUE; 127 } 128 129 //CB: Open32 draw a pixel too much! 130 POINT *points = (POINT*)lppt; 131 POINT lastPt = lppt[cPoints-1]; 132 BOOL rc; 133 134 points[cPoints-1] = ToWin32LineEnd(lppt[cPoints-2],lastPt.x,lastPt.y); 135 rc = O32_Polyline(hdc,lppt,cPoints); 136 points[cPoints-1] = lastPt; 137 138 return rc; 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; 139 202 } 140 203 //****************************************************************************** … … 142 205 BOOL WIN32API PolylineTo( HDC hdc, const POINT * lppt, DWORD cCount) 143 206 { 144 dprintf(("GDI32: PolylineTo")); 145 146 if (cCount == 0) return TRUE; 147 148 if (cCount == 1) 149 { 150 DrawSingleLinePoint(hdc,*lppt); 151 152 return TRUE; //CB: check metafile recording 153 } 154 155 //CB: Open32 draw a pixel too much! 156 POINT *points = (POINT*)lppt; 157 POINT lastPt = lppt[cCount-1]; 158 BOOL rc; 159 160 points[cCount-1] = ToWin32LineEnd(lppt[cCount-2],lastPt.x,lastPt.y); 161 rc = O32_PolylineTo(hdc,lppt,cCount); 162 points[cCount-1] = lastPt; 163 MoveToEx(hdc,lastPt.x,lastPt.y,NULL); 164 165 return rc; 166 } 167 //****************************************************************************** 168 //****************************************************************************** 169 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
Note:
See TracChangeset
for help on using the changeset viewer.