From 93baff6f054a3c655dcb4405887d920e4627b7dc Mon Sep 17 00:00:00 2001 From: Benedikt Freisen Date: Thu, 29 Apr 2010 19:56:18 +0000 Subject: [PATCH] [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 svn path=/trunk/; revision=47062 --- reactos/base/applications/paint/main.c | 9 ++-- reactos/base/applications/paint/mouse.c | 72 +++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 3 deletions(-) diff --git a/reactos/base/applications/paint/main.c b/reactos/base/applications/paint/main.c index 98565f4b36c..904220567d1 100644 --- a/reactos/base/applications/paint/main.c +++ b/reactos/base/applications/paint/main.c @@ -143,6 +143,7 @@ _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR lpszArgument HBITMAP tempBm; int i; TCHAR tooltips[16][30]; + HDC hDC; TCHAR *c; TCHAR sfnFilename[1000]; @@ -152,7 +153,7 @@ _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR lpszArgument 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 @@ _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR lpszArgument 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)); diff --git a/reactos/base/applications/paint/mouse.c b/reactos/base/applications/paint/mouse.c index 4f5c13031fd..9165291594e 100644 --- a/reactos/base/applications/paint/mouse.c +++ b/reactos/base/applications/paint/mouse.c @@ -25,6 +25,34 @@ placeSelWin() //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]; short pointSP; POINT *ptStack = NULL; @@ -147,6 +175,8 @@ whilePaintingL(HDC hdc, short x, short y, int fg, int bg) 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 @@ whilePaintingL(HDC hdc, short x, short y, int fg, int bg) 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 @@ endPaintingL(HDC hdc, short x, short y, int fg, int bg) 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 @@ endPaintingL(HDC hdc, short x, short y, int fg, int bg) 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 @@ endPaintingL(HDC hdc, short x, short y, int fg, int bg) 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 @@ whilePaintingR(HDC hdc, short x, short y, int fg, int bg) 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 @@ whilePaintingR(HDC hdc, short x, short y, int fg, int bg) 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 @@ endPaintingR(HDC hdc, short x, short y, int fg, int bg) 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 @@ endPaintingR(HDC hdc, short x, short y, int fg, int bg) 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 @@ endPaintingR(HDC hdc, short x, short y, int fg, int bg) 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; } -- 2.17.1