[MSPAINT] partially apply patch by swyter (bugfixes only). See CORE-5644

svn path=/trunk/; revision=65938
This commit is contained in:
Benedikt Freisen 2015-01-02 13:58:25 +00:00
parent 741c7726db
commit afea95d6b8
5 changed files with 49 additions and 23 deletions

View file

@ -67,11 +67,16 @@ RRect(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2, COLORREF fg, COLORREF bg, in
}
void
Poly(HDC hdc, POINT * lpPoints, int nCount, COLORREF fg, COLORREF bg, int thickness, int style, BOOL closed)
Poly(HDC hdc, POINT * lpPoints, int nCount, COLORREF fg, COLORREF bg, int thickness, int style, BOOL closed, BOOL inverted)
{
LOGBRUSH logbrush;
HBRUSH oldBrush;
HPEN oldPen = SelectObject(hdc, CreatePen(PS_SOLID, thickness, fg));
UINT oldRop = GetROP2(hdc);
if (inverted)
SetROP2(hdc, R2_NOTXORPEN);
logbrush.lbStyle = (style == 0) ? BS_HOLLOW : BS_SOLID;
logbrush.lbColor = (style == 2) ? fg : bg;
logbrush.lbHatch = 0;
@ -82,6 +87,8 @@ Poly(HDC hdc, POINT * lpPoints, int nCount, COLORREF fg, COLORREF bg, int thic
Polyline(hdc, lpPoints, nCount);
DeleteObject(SelectObject(hdc, oldBrush));
DeleteObject(SelectObject(hdc, oldPen));
SetROP2(hdc, oldRop);
}
void
@ -223,6 +230,10 @@ RectSel(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2)
HBRUSH oldBrush;
LOGBRUSH logbrush;
HPEN oldPen = SelectObject(hdc, CreatePen(PS_DOT, 1, 0x00000000));
UINT oldRop = GetROP2(hdc);
SetROP2(hdc, R2_NOTXORPEN);
logbrush.lbStyle = BS_HOLLOW;
logbrush.lbColor = 0;
logbrush.lbHatch = 0;
@ -230,23 +241,26 @@ RectSel(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2)
Rectangle(hdc, x1, y1, x2, y2);
DeleteObject(SelectObject(hdc, oldBrush));
DeleteObject(SelectObject(hdc, oldPen));
SetROP2(hdc, oldRop);
}
void
SelectionFrame(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2)
SelectionFrame(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2, DWORD system_selection_color)
{
HBRUSH oldBrush;
LOGBRUSH logbrush;
HPEN oldPen = SelectObject(hdc, CreatePen(PS_DOT, 1, 0x00000000));
HPEN oldPen = SelectObject(hdc, CreatePen(PS_DOT, 1, system_selection_color));
logbrush.lbStyle = BS_HOLLOW;
logbrush.lbColor = 0;
logbrush.lbHatch = 0;
oldBrush = SelectObject(hdc, CreateBrushIndirect(&logbrush));
Rectangle(hdc, x1, y1, x2, y2);
Rectangle(hdc, x1, y1, x2, y2); /* SEL BOX FRAME */
DeleteObject(SelectObject(hdc, oldBrush));
DeleteObject(SelectObject(hdc, oldPen));
oldPen = SelectObject(hdc, CreatePen(PS_SOLID, 1, 0x00000000));
oldBrush = SelectObject(hdc, CreateSolidBrush(0x00000000));
oldPen = SelectObject(hdc, CreatePen(PS_SOLID, 1, system_selection_color));
oldBrush = SelectObject(hdc, CreateSolidBrush(system_selection_color));
Rectangle(hdc, x1 - 1, y1 - 1, x1 + 2, y1 + 2);
Rectangle(hdc, x2 - 2, y1 - 1, x2 + 2, y1 + 2);
Rectangle(hdc, x1 - 1, y2 - 2, x1 + 2, y2 + 1);

View file

@ -14,7 +14,7 @@ void Ellp(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2, COLORREF fg, COLORREF bg,
void RRect(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2, COLORREF fg, COLORREF bg, int thickness, int style);
void Poly(HDC hdc, POINT *lpPoints, int nCount, COLORREF fg, COLORREF bg, int thickness, int style, BOOL closed);
void Poly(HDC hdc, POINT *lpPoints, int nCount, COLORREF fg, COLORREF bg, int thickness, int style, BOOL closed, BOOL inverted);
void Bezier(HDC hdc, POINT p1, POINT p2, POINT p3, POINT p4, COLORREF color, int thickness);
@ -30,6 +30,6 @@ void Brush(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2, COLORREF color, LONG sty
void RectSel(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2);
void SelectionFrame(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2);
void SelectionFrame(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2, DWORD system_selection_color);
void Text(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2, COLORREF fg, COLORREF bg, LPCTSTR lpchText, HFONT font, LONG style);

View file

@ -118,7 +118,7 @@ startPaintingL(HDC hdc, LONG x, LONG y, COLORREF fg, COLORREF bg)
pointStack[pointSP].x = x;
pointStack[pointSP].y = y;
if (pointSP + 1 >= 2)
Poly(hdc, pointStack, pointSP + 1, fg, bg, lineWidth, shapeStyle, FALSE);
Poly(hdc, pointStack, pointSP + 1, fg, bg, lineWidth, shapeStyle, FALSE, FALSE);
if (pointSP == 0)
{
newReversible();
@ -142,7 +142,7 @@ whilePaintingL(HDC hdc, LONG x, LONG y, COLORREF fg, COLORREF bg)
ptStack[ptSP].x = max(0, min(x, imgXRes));
ptStack[ptSP].y = max(0, min(y, imgYRes));
resetToU1();
Poly(hdc, ptStack, ptSP + 1, 0, 0, 2, 0, FALSE);
Poly(hdc, ptStack, ptSP + 1, 0, 0, 2, 0, FALSE, TRUE); /* draw the freehand selection inverted/xored */
break;
case TOOL_RECTSEL:
case TOOL_TEXT:
@ -208,7 +208,7 @@ whilePaintingL(HDC hdc, LONG x, LONG y, COLORREF fg, COLORREF bg)
roundTo8Directions(pointStack[pointSP - 1].x, pointStack[pointSP - 1].y,
&pointStack[pointSP].x, &pointStack[pointSP].y);
if (pointSP + 1 >= 2)
Poly(hdc, pointStack, pointSP + 1, fg, bg, lineWidth, shapeStyle, FALSE);
Poly(hdc, pointStack, pointSP + 1, fg, bg, lineWidth, shapeStyle, FALSE, FALSE);
break;
case TOOL_ELLIPSE:
resetToU1();
@ -267,13 +267,13 @@ endPaintingL(HDC hdc, LONG x, LONG y, COLORREF fg, COLORREF bg)
ptStackCopy[i].x = ptStack[i].x - rectSel_src.left;
ptStackCopy[i].y = ptStack[i].y - rectSel_src.top;
}
Poly(hSelDC, ptStackCopy, ptSP + 1, 0x00ffffff, 0x00ffffff, 1, 2, TRUE);
Poly(hSelDC, ptStackCopy, ptSP + 1, 0x00ffffff, 0x00ffffff, 1, 2, TRUE, FALSE);
HeapFree(GetProcessHeap(), 0, ptStackCopy);
SelectObject(hSelDC, hSelBm = CreateDIBWithProperties(RECT_WIDTH(rectSel_src), RECT_HEIGHT(rectSel_src)));
resetToU1();
MaskBlt(hSelDC, 0, 0, RECT_WIDTH(rectSel_src), RECT_HEIGHT(rectSel_src), hDrawingDC, rectSel_src.left,
rectSel_src.top, hSelMask, 0, 0, MAKEROP4(SRCCOPY, WHITENESS));
Poly(hdc, ptStack, ptSP + 1, bg, bg, 1, 2, TRUE);
Poly(hdc, ptStack, ptSP + 1, bg, bg, 1, 2, TRUE, FALSE);
newReversible();
MaskBlt(hDrawingDC, rectSel_src.left, rectSel_src.top, RECT_WIDTH(rectSel_src), RECT_HEIGHT(rectSel_src), hSelDC, 0,
@ -362,12 +362,12 @@ endPaintingL(HDC hdc, LONG x, LONG y, COLORREF fg, COLORREF bg)
if ((pointStack[0].x - x) * (pointStack[0].x - x) +
(pointStack[0].y - y) * (pointStack[0].y - y) <= lineWidth * lineWidth + 1)
{
Poly(hdc, pointStack, pointSP, fg, bg, lineWidth, shapeStyle, TRUE);
Poly(hdc, pointStack, pointSP, fg, bg, lineWidth, shapeStyle, TRUE, FALSE);
pointSP = 0;
}
else
{
Poly(hdc, pointStack, pointSP, fg, bg, lineWidth, shapeStyle, FALSE);
Poly(hdc, pointStack, pointSP, fg, bg, lineWidth, shapeStyle, FALSE, FALSE);
}
}
if (pointSP == 255)
@ -438,7 +438,7 @@ startPaintingR(HDC hdc, LONG x, LONG y, COLORREF fg, COLORREF bg)
pointStack[pointSP].x = x;
pointStack[pointSP].y = y;
if (pointSP + 1 >= 2)
Poly(hdc, pointStack, pointSP + 1, bg, fg, lineWidth, shapeStyle, FALSE);
Poly(hdc, pointStack, pointSP + 1, bg, fg, lineWidth, shapeStyle, FALSE, FALSE);
if (pointSP == 0)
{
newReversible();
@ -503,7 +503,7 @@ whilePaintingR(HDC hdc, LONG x, LONG y, COLORREF fg, COLORREF bg)
roundTo8Directions(pointStack[pointSP - 1].x, pointStack[pointSP - 1].y,
&pointStack[pointSP].x, &pointStack[pointSP].y);
if (pointSP + 1 >= 2)
Poly(hdc, pointStack, pointSP + 1, bg, fg, lineWidth, shapeStyle, FALSE);
Poly(hdc, pointStack, pointSP + 1, bg, fg, lineWidth, shapeStyle, FALSE, FALSE);
break;
case TOOL_ELLIPSE:
resetToU1();
@ -565,12 +565,12 @@ endPaintingR(HDC hdc, LONG x, LONG y, COLORREF fg, COLORREF bg)
if ((pointStack[0].x - x) * (pointStack[0].x - x) +
(pointStack[0].y - y) * (pointStack[0].y - y) <= lineWidth * lineWidth + 1)
{
Poly(hdc, pointStack, pointSP, bg, fg, lineWidth, shapeStyle, TRUE);
Poly(hdc, pointStack, pointSP, bg, fg, lineWidth, shapeStyle, TRUE, FALSE);
pointSP = 0;
}
else
{
Poly(hdc, pointStack, pointSP, bg, fg, lineWidth, shapeStyle, FALSE);
Poly(hdc, pointStack, pointSP, bg, fg, lineWidth, shapeStyle, FALSE, FALSE);
}
}
if (pointSP == 255)

View file

@ -37,6 +37,7 @@ int action = ACTION_MOVE;
POINTS pos;
POINTS frac;
POINT delta;
DWORD system_selection_color;
void
RegisterWclSelection()
@ -95,8 +96,8 @@ ForceRefreshSelectionContents()
if (IsWindowVisible(hSelection))
{
SendMessage(hSelection, WM_LBUTTONDOWN, 0, MAKELPARAM(0, 0));
SendMessage(hSelection, WM_MOUSEMOVE, 0, MAKELPARAM(0, 0));
SendMessage(hSelection, WM_LBUTTONUP, 0, MAKELPARAM(0, 0));
SendMessage(hSelection, WM_MOUSEMOVE, 0, MAKELPARAM(0, 0));
SendMessage(hSelection, WM_LBUTTONUP, 0, MAKELPARAM(0, 0));
}
}
@ -143,12 +144,22 @@ SelectionWinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
HDC hDC = GetDC(hwnd);
DefWindowProc(hwnd, message, wParam, lParam);
SelectionFrame(hDC, 1, 1, RECT_WIDTH(rectSel_dest) * zoom / 1000 + 5,
RECT_HEIGHT(rectSel_dest) * zoom / 1000 + 5);
RECT_HEIGHT(rectSel_dest) * zoom / 1000 + 5,
system_selection_color);
ReleaseDC(hwnd, hDC);
}
break;
}
case WM_CREATE:
case WM_SYSCOLORCHANGE:
{
/* update the system selection color */
system_selection_color = GetSysColor(COLOR_HIGHLIGHT);
SendMessage(hwnd, WM_PAINT, 0, MAKELPARAM(0, 0));
break;
}
case WM_LBUTTONDOWN:
{
pos.x = GET_X_LPARAM(lParam);
pos.y = GET_Y_LPARAM(lParam);
delta.x = 0;
@ -159,6 +170,7 @@ SelectionWinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
moving = TRUE;
InvalidateRect(hScrlClient, NULL, TRUE);
break;
}
case WM_MOUSEMOVE:
if (moving)
{

View file

@ -806,7 +806,7 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
if (activeTool == TOOL_FREESEL)
{
newReversible();
Poly(hDrawingDC, ptStack, ptSP + 1, 0, 0, 2, 0, FALSE);
Poly(hDrawingDC, ptStack, ptSP + 1, 0, 0, 2, 0, FALSE, TRUE);
}
break;
}