Author: bfreisen Date: Thu Apr 29 21:56:18 2010 New Revision: 47062
URL: http://svn.reactos.org/svn/reactos?rev=47062&view=rev Log: [PAINT] - angle rounding for lines and polygons when SHIFT key is pressed - equal width and height for (rounded) rectangles and ellipses when SHIFT key is pressed Based on a patch by Katayama Hirofumi, see #5285
Modified: trunk/reactos/base/applications/paint/main.c trunk/reactos/base/applications/paint/mouse.c
Modified: trunk/reactos/base/applications/paint/main.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/paint/mai... ============================================================================== --- trunk/reactos/base/applications/paint/main.c [iso-8859-1] (original) +++ trunk/reactos/base/applications/paint/main.c [iso-8859-1] Thu Apr 29 21:56:18 2010 @@ -143,6 +143,7 @@ HBITMAP tempBm; int i; TCHAR tooltips[16][30]; + HDC hDC;
TCHAR *c; TCHAR sfnFilename[1000]; @@ -152,7 +153,7 @@ TCHAR ofnFiletitle[256]; TCHAR ofnFilter[1000]; TCHAR miniaturetitle[100]; - int custColors[16] = { 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, + static int custColors[16] = { 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff };
@@ -371,8 +372,10 @@ CreateWindowEx(0, _T("Scrollbox"), _T(""), WS_CHILD | WS_VISIBLE, 3, 3, imgXRes, imgYRes, hScrlClient, NULL, hThisInstance, NULL);
- hDrawingDC = CreateCompatibleDC(GetDC(hImageArea)); - hSelDC = CreateCompatibleDC(GetDC(hImageArea)); + hDC = GetDC(hImageArea); + hDrawingDC = CreateCompatibleDC(hDC); + hSelDC = CreateCompatibleDC(hDC); + ReleaseDC(hImageArea, hDC); SelectObject(hDrawingDC, CreatePen(PS_SOLID, 0, fgColor)); SelectObject(hDrawingDC, CreateSolidBrush(bgColor));
Modified: trunk/reactos/base/applications/paint/mouse.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/paint/mou... ============================================================================== --- trunk/reactos/base/applications/paint/mouse.c [iso-8859-1] (original) +++ trunk/reactos/base/applications/paint/mouse.c [iso-8859-1] Thu Apr 29 21:56:18 2010 @@ -23,6 +23,34 @@ BringWindowToTop(hSelection); SendMessage(hImageArea, WM_PAINT, 0, 0); //SendMessage(hSelection, WM_PAINT, 0, 0); +} + +void +regularize(short x0, short y0, short *x1, short *y1) +{ + if (abs(*x1 - x0) >= abs(*y1 - y0)) + *y1 = y0 + (*y1 > y0 ? abs(*x1 - x0) : -abs(*x1 - x0)); + else + *x1 = x0 + (*x1 > x0 ? abs(*y1 - y0) : -abs(*y1 - y0)); +} + +void +roundTo8Directions(short x0, short y0, short *x1, short *y1) +{ + if (abs(*x1 - x0) >= abs(*y1 - y0)) + { + if (abs(*y1 - y0) * 5 < abs(*x1 - x0) * 2) + *y1 = y0; + else + *y1 = y0 + (*y1 > y0 ? abs(*x1 - x0) : -abs(*x1 - x0)); + } + else + { + if (abs(*x1 - x0) * 5 < abs(*y1 - y0) * 2) + *x1 = x0; + else + *x1 = x0 + (*x1 > x0 ? abs(*y1 - y0) : -abs(*y1 - y0)); + } }
POINT pointStack[256]; @@ -147,6 +175,8 @@ break; case 11: resetToU1(); + if (GetAsyncKeyState(VK_SHIFT) < 0) + roundTo8Directions(startX, startY, &x, &y); Line(hdc, startX, startY, x, y, fg, lineWidth); break; case 12: @@ -169,21 +199,30 @@ break; case 13: resetToU1(); + if (GetAsyncKeyState(VK_SHIFT) < 0) + regularize(startX, startY, &x, &y); Rect(hdc, startX, startY, x, y, fg, bg, lineWidth, shapeStyle); break; case 14: resetToU1(); pointStack[pointSP].x = x; pointStack[pointSP].y = y; + if ((pointSP > 0) && (GetAsyncKeyState(VK_SHIFT) < 0)) + roundTo8Directions(pointStack[pointSP - 1].x, pointStack[pointSP - 1].y, + (short *)&pointStack[pointSP].x, (short *)&pointStack[pointSP].y); if (pointSP + 1 >= 2) Poly(hdc, pointStack, pointSP + 1, fg, bg, lineWidth, shapeStyle, FALSE); break; case 15: resetToU1(); + if (GetAsyncKeyState(VK_SHIFT) < 0) + regularize(startX, startY, &x, &y); Ellp(hdc, startX, startY, x, y, fg, bg, lineWidth, shapeStyle); break; case 16: resetToU1(); + if (GetAsyncKeyState(VK_SHIFT) < 0) + regularize(startX, startY, &x, &y); RRect(hdc, startX, startY, x, y, fg, bg, lineWidth, shapeStyle); break; } @@ -276,6 +315,8 @@ break; case 11: resetToU1(); + if (GetAsyncKeyState(VK_SHIFT) < 0) + roundTo8Directions(startX, startY, &x, &y); Line(hdc, startX, startY, x, y, fg, lineWidth); break; case 12: @@ -285,12 +326,17 @@ break; case 13: resetToU1(); + if (GetAsyncKeyState(VK_SHIFT) < 0) + regularize(startX, startY, &x, &y); Rect(hdc, startX, startY, x, y, fg, bg, lineWidth, shapeStyle); break; case 14: resetToU1(); pointStack[pointSP].x = x; pointStack[pointSP].y = y; + if ((pointSP > 0) && (GetAsyncKeyState(VK_SHIFT) < 0)) + roundTo8Directions(pointStack[pointSP - 1].x, pointStack[pointSP - 1].y, + (short *)&pointStack[pointSP].x, (short *)&pointStack[pointSP].y); pointSP++; if (pointSP >= 2) { @@ -310,10 +356,14 @@ break; case 15: resetToU1(); + if (GetAsyncKeyState(VK_SHIFT) < 0) + regularize(startX, startY, &x, &y); Ellp(hdc, startX, startY, x, y, fg, bg, lineWidth, shapeStyle); break; case 16: resetToU1(); + if (GetAsyncKeyState(VK_SHIFT) < 0) + regularize(startX, startY, &x, &y); RRect(hdc, startX, startY, x, y, fg, bg, lineWidth, shapeStyle); break; } @@ -398,6 +448,8 @@ break; case 11: resetToU1(); + if (GetAsyncKeyState(VK_SHIFT) < 0) + roundTo8Directions(startX, startY, &x, &y); Line(hdc, startX, startY, x, y, bg, lineWidth); break; case 12: @@ -420,21 +472,30 @@ break; case 13: resetToU1(); + if (GetAsyncKeyState(VK_SHIFT) < 0) + regularize(startX, startY, &x, &y); Rect(hdc, startX, startY, x, y, bg, fg, lineWidth, shapeStyle); break; case 14: resetToU1(); pointStack[pointSP].x = x; pointStack[pointSP].y = y; + if ((pointSP > 0) && (GetAsyncKeyState(VK_SHIFT) < 0)) + roundTo8Directions(pointStack[pointSP - 1].x, pointStack[pointSP - 1].y, + (short *)&pointStack[pointSP].x, (short *)&pointStack[pointSP].y); if (pointSP + 1 >= 2) Poly(hdc, pointStack, pointSP + 1, bg, fg, lineWidth, shapeStyle, FALSE); break; case 15: resetToU1(); + if (GetAsyncKeyState(VK_SHIFT) < 0) + regularize(startX, startY, &x, &y); Ellp(hdc, startX, startY, x, y, bg, fg, lineWidth, shapeStyle); break; case 16: resetToU1(); + if (GetAsyncKeyState(VK_SHIFT) < 0) + regularize(startX, startY, &x, &y); RRect(hdc, startX, startY, x, y, bg, fg, lineWidth, shapeStyle); break; } @@ -457,6 +518,8 @@ break; case 11: resetToU1(); + if (GetAsyncKeyState(VK_SHIFT) < 0) + roundTo8Directions(startX, startY, &x, &y); Line(hdc, startX, startY, x, y, bg, lineWidth); break; case 12: @@ -466,12 +529,17 @@ break; case 13: resetToU1(); + if (GetAsyncKeyState(VK_SHIFT) < 0) + regularize(startX, startY, &x, &y); Rect(hdc, startX, startY, x, y, bg, fg, lineWidth, shapeStyle); break; case 14: resetToU1(); pointStack[pointSP].x = x; pointStack[pointSP].y = y; + if ((pointSP > 0) && (GetAsyncKeyState(VK_SHIFT) < 0)) + roundTo8Directions(pointStack[pointSP - 1].x, pointStack[pointSP - 1].y, + (short *)&pointStack[pointSP].x, (short *)&pointStack[pointSP].y); pointSP++; if (pointSP >= 2) { @@ -491,10 +559,14 @@ break; case 15: resetToU1(); + if (GetAsyncKeyState(VK_SHIFT) < 0) + regularize(startX, startY, &x, &y); Ellp(hdc, startX, startY, x, y, bg, fg, lineWidth, shapeStyle); break; case 16: resetToU1(); + if (GetAsyncKeyState(VK_SHIFT) < 0) + regularize(startX, startY, &x, &y); RRect(hdc, startX, startY, x, y, bg, fg, lineWidth, shapeStyle); break; }