Author: bfreisen Date: Fri Feb 7 17:54:25 2014 New Revision: 62025
URL: http://svn.reactos.org/svn/reactos?rev=62025&view=rev Log: [MSPAINT] - Simplify menu initialization - Add proof-of-concept text drawing functionality (for now with hard-coded text and font) - use RECT instead of int[4] and POINT instead of int x,y - move some redundant code to new function ForceRefreshSelectionContents - rework transparent selection code using new function ColorKeyedMaskBlt
Modified: trunk/reactos/base/applications/mspaint/definitions.h trunk/reactos/base/applications/mspaint/drawing.c trunk/reactos/base/applications/mspaint/drawing.h trunk/reactos/base/applications/mspaint/globalvar.h trunk/reactos/base/applications/mspaint/main.c trunk/reactos/base/applications/mspaint/mouse.c trunk/reactos/base/applications/mspaint/palette.c trunk/reactos/base/applications/mspaint/precomp.h trunk/reactos/base/applications/mspaint/selection.c trunk/reactos/base/applications/mspaint/selection.h trunk/reactos/base/applications/mspaint/toolsettings.c trunk/reactos/base/applications/mspaint/winproc.c
Modified: trunk/reactos/base/applications/mspaint/definitions.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mspaint/d... ============================================================================== --- trunk/reactos/base/applications/mspaint/definitions.h [iso-8859-1] (original) +++ trunk/reactos/base/applications/mspaint/definitions.h [iso-8859-1] Fri Feb 7 17:54:25 2014 @@ -13,6 +13,17 @@
#define SIZEOF(a) (sizeof(a) / sizeof((a)[0])) /* sizeof for string constants; equals max. number of characters */ + +#define RECT_WIDTH(a) ((a).right - (a).left) +/* width of the rectangle defined by a RECT structure */ + +#define RECT_HEIGHT(a) ((a).bottom - (a).top) +/* height of the rectangle defined by a RECT structure */ + +#define CHECKED_IF(a) ((a) ? (MF_CHECKED | MF_BYCOMMAND) : (MF_UNCHECKED | MF_BYCOMMAND)) +/* simplifies checking and unchecking menu items */ +#define ENABLED_IF(a) ((a) ? (MF_ENABLED | MF_BYCOMMAND) : (MF_GRAYED | MF_BYCOMMAND)) +/* simplifies enabling or graying menu items */
#define IDI_APPICON 500
Modified: trunk/reactos/base/applications/mspaint/drawing.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mspaint/d... ============================================================================== --- trunk/reactos/base/applications/mspaint/drawing.c [iso-8859-1] (original) +++ trunk/reactos/base/applications/mspaint/drawing.c [iso-8859-1] Fri Feb 7 17:54:25 2014 @@ -258,3 +258,24 @@ DeleteObject(SelectObject(hdc, oldBrush)); DeleteObject(SelectObject(hdc, oldPen)); } + +void +Text(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2, COLORREF fg, COLORREF bg, LPCTSTR lpchText, HFONT font, LONG style) +{ + HFONT oldFont; + RECT rect = {x1, y1, x2, y2}; + COLORREF oldColor; + COLORREF oldBkColor; + int oldBkMode; + oldFont = SelectObject(hdc, font); + oldColor = SetTextColor(hdc, fg); + oldBkColor = SetBkColor(hdc, bg); + oldBkMode = SetBkMode(hdc, TRANSPARENT); + if (style == 0) + Rect(hdc, x1, y1, x2, y2, bg, bg, 1, 2); + DrawText(hdc, lpchText, -1, &rect, DT_EDITCONTROL); + SelectObject(hdc, oldFont); + SetTextColor(hdc, oldColor); + SetBkColor(hdc, oldBkColor); + SetBkMode(hdc, oldBkMode); +}
Modified: trunk/reactos/base/applications/mspaint/drawing.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mspaint/d... ============================================================================== --- trunk/reactos/base/applications/mspaint/drawing.h [iso-8859-1] (original) +++ trunk/reactos/base/applications/mspaint/drawing.h [iso-8859-1] Fri Feb 7 17:54:25 2014 @@ -31,3 +31,5 @@ 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 Text(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2, COLORREF fg, COLORREF bg, LPCTSTR lpchText, HFONT font, LONG style);
Modified: trunk/reactos/base/applications/mspaint/globalvar.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mspaint/g... ============================================================================== --- trunk/reactos/base/applications/mspaint/globalvar.h [iso-8859-1] (original) +++ trunk/reactos/base/applications/mspaint/globalvar.h [iso-8859-1] Fri Feb 7 17:54:25 2014 @@ -48,12 +48,16 @@ extern int rubberRadius; extern int transpBg; extern int zoom; -extern int rectSel_src[4]; -extern int rectSel_dest[4]; +extern RECT rectSel_src; +extern RECT rectSel_dest; extern HWND hSelection; extern HWND hImageArea; extern HBITMAP hSelBm; extern HBITMAP hSelMask; +extern LOGFONT lfTextFont; +extern HFONT hfontTextFont; +extern LPTSTR textToolText; +extern int textToolTextMaxLen;
extern int palColors[28]; extern int modernPalColors[28];
Modified: trunk/reactos/base/applications/mspaint/main.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mspaint/m... ============================================================================== --- trunk/reactos/base/applications/mspaint/main.c [iso-8859-1] (original) +++ trunk/reactos/base/applications/mspaint/main.c [iso-8859-1] Fri Feb 7 17:54:25 2014 @@ -46,12 +46,17 @@ int rubberRadius = 4; int transpBg = 0; int zoom = 1000; -int rectSel_src[4]; -int rectSel_dest[4]; +RECT rectSel_src; +RECT rectSel_dest; HWND hSelection; HWND hImageArea; HBITMAP hSelBm; HBITMAP hSelMask; +LOGFONT lfTextFont; +HFONT hfontTextFont; +/* TODO: add dialog to edit the currently hard-coded text */ +LPTSTR textToolText = _T("Abc\n1234567890"); +int textToolTextMaxLen = SIZEOF(textToolText);
/* array holding palette colors; may be changed by the user during execution */ int palColors[28]; @@ -161,6 +166,23 @@ 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff };
+ /* init font for text tool */ + lfTextFont.lfHeight = 0; + lfTextFont.lfWidth = 0; + lfTextFont.lfEscapement = 0; + lfTextFont.lfOrientation = 0; + lfTextFont.lfWeight = FW_NORMAL; + lfTextFont.lfItalic = FALSE; + lfTextFont.lfUnderline = FALSE; + lfTextFont.lfStrikeOut = FALSE; + lfTextFont.lfCharSet = DEFAULT_CHARSET; + lfTextFont.lfOutPrecision = OUT_DEFAULT_PRECIS; + lfTextFont.lfClipPrecision = CLIP_DEFAULT_PRECIS; + lfTextFont.lfQuality = DEFAULT_QUALITY; + lfTextFont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; + lstrcpy(lfTextFont.lfFaceName, _T("")); + hfontTextFont = CreateFontIndirect(&lfTextFont); + /* init palette */ selectedPalette = 1; CopyMemory(palColors, modernPalColors, sizeof(palColors));
Modified: trunk/reactos/base/applications/mspaint/mouse.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mspaint/m... ============================================================================== --- trunk/reactos/base/applications/mspaint/mouse.c [iso-8859-1] (original) +++ trunk/reactos/base/applications/mspaint/mouse.c [iso-8859-1] Fri Feb 7 17:54:25 2014 @@ -15,8 +15,8 @@ void placeSelWin() { - MoveWindow(hSelection, rectSel_dest[0] * zoom / 1000, rectSel_dest[1] * zoom / 1000, - rectSel_dest[2] * zoom / 1000 + 6, rectSel_dest[3] * zoom / 1000 + 6, TRUE); + MoveWindow(hSelection, rectSel_dest.left * zoom / 1000, rectSel_dest.top * zoom / 1000, + RECT_WIDTH(rectSel_dest) * zoom / 1000 + 6, RECT_HEIGHT(rectSel_dest) * zoom / 1000 + 6, TRUE); BringWindowToTop(hSelection); InvalidateRect(hImageArea, NULL, FALSE); } @@ -72,7 +72,6 @@ ptStack[0].x = x; ptStack[0].y = y; break; - case TOOL_TEXT: case TOOL_LINE: case TOOL_RECT: case TOOL_ELLIPSE: @@ -80,9 +79,11 @@ newReversible(); break; case TOOL_RECTSEL: + case TOOL_TEXT: newReversible(); ShowWindow(hSelection, SW_HIDE); - rectSel_src[2] = rectSel_src[3] = 0; + rectSel_src.right = rectSel_src.left; + rectSel_src.bottom = rectSel_src.top; break; case TOOL_RUBBER: newReversible(); @@ -144,15 +145,16 @@ Poly(hdc, ptStack, ptSP + 1, 0, 0, 2, 0, FALSE); break; case TOOL_RECTSEL: + case TOOL_TEXT: { POINT temp; resetToU1(); temp.x = max(0, min(x, imgXRes)); temp.y = max(0, min(y, imgYRes)); - rectSel_dest[0] = rectSel_src[0] = min(start.x, temp.x); - rectSel_dest[1] = rectSel_src[1] = min(start.y, temp.y); - rectSel_dest[2] = rectSel_src[2] = max(start.x, temp.x) - min(start.x, temp.x); - rectSel_dest[3] = rectSel_src[3] = max(start.y, temp.y) - min(start.y, temp.y); + rectSel_dest.left = rectSel_src.left = min(start.x, temp.x); + rectSel_dest.top = rectSel_src.top = min(start.y, temp.y); + rectSel_dest.right = rectSel_src.right = max(start.x, temp.x); + rectSel_dest.bottom = rectSel_src.bottom = max(start.y, temp.y); RectSel(hdc, start.x, start.y, temp.x, temp.y); break; } @@ -235,46 +237,46 @@ { POINT *ptStackCopy; int i; - rectSel_src[0] = rectSel_src[1] = 0x7fffffff; - rectSel_src[2] = rectSel_src[3] = 0; + rectSel_src.left = rectSel_src.top = MAXLONG; + rectSel_src.right = rectSel_src.bottom = 0; for (i = 0; i <= ptSP; i++) { - if (ptStack[i].x < rectSel_src[0]) - rectSel_src[0] = ptStack[i].x; - if (ptStack[i].y < rectSel_src[1]) - rectSel_src[1] = ptStack[i].y; - if (ptStack[i].x > rectSel_src[2]) - rectSel_src[2] = ptStack[i].x; - if (ptStack[i].y > rectSel_src[3]) - rectSel_src[3] = ptStack[i].y; - } - rectSel_src[2] += 1 - rectSel_src[0]; - rectSel_src[3] += 1 - rectSel_src[1]; - rectSel_dest[0] = rectSel_src[0]; - rectSel_dest[1] = rectSel_src[1]; - rectSel_dest[2] = rectSel_src[2]; - rectSel_dest[3] = rectSel_src[3]; + if (ptStack[i].x < rectSel_src.left) + rectSel_src.left = ptStack[i].x; + if (ptStack[i].y < rectSel_src.top) + rectSel_src.top = ptStack[i].y; + if (ptStack[i].x > rectSel_src.right) + rectSel_src.right = ptStack[i].x; + if (ptStack[i].y > rectSel_src.bottom) + rectSel_src.bottom = ptStack[i].y; + } + rectSel_src.right += 1; + rectSel_src.bottom += 1; + rectSel_dest.left = rectSel_src.left; + rectSel_dest.top = rectSel_src.top; + rectSel_dest.right = rectSel_src.right; + rectSel_dest.bottom = rectSel_src.bottom; if (ptSP != 0) { DeleteObject(hSelMask); - hSelMask = CreateBitmap(rectSel_src[2], rectSel_src[3], 1, 1, NULL); + hSelMask = CreateBitmap(RECT_WIDTH(rectSel_src), RECT_HEIGHT(rectSel_src), 1, 1, NULL); DeleteObject(SelectObject(hSelDC, hSelMask)); ptStackCopy = HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, sizeof(POINT) * (ptSP + 1)); for (i = 0; i <= ptSP; i++) { - ptStackCopy[i].x = ptStack[i].x - rectSel_src[0]; - ptStackCopy[i].y = ptStack[i].y - rectSel_src[1]; + 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); HeapFree(GetProcessHeap(), 0, ptStackCopy); - SelectObject(hSelDC, hSelBm = CreateDIBWithProperties(rectSel_src[2], rectSel_src[3])); + SelectObject(hSelDC, hSelBm = CreateDIBWithProperties(RECT_WIDTH(rectSel_src), RECT_HEIGHT(rectSel_src))); resetToU1(); - MaskBlt(hSelDC, 0, 0, rectSel_src[2], rectSel_src[3], hDrawingDC, rectSel_src[0], - rectSel_src[1], hSelMask, 0, 0, MAKEROP4(SRCCOPY, WHITENESS)); + 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); newReversible();
- MaskBlt(hDrawingDC, rectSel_src[0], rectSel_src[1], rectSel_src[2], rectSel_src[3], hSelDC, 0, + MaskBlt(hDrawingDC, rectSel_src.left, rectSel_src.top, RECT_WIDTH(rectSel_src), RECT_HEIGHT(rectSel_src), hSelDC, 0, 0, hSelMask, 0, 0, MAKEROP4(SRCCOPY, SRCAND));
placeSelWin(); @@ -290,29 +292,37 @@ } case TOOL_RECTSEL: resetToU1(); - if ((rectSel_src[2] != 0) && (rectSel_src[3] != 0)) + if ((RECT_WIDTH(rectSel_src) != 0) && (RECT_HEIGHT(rectSel_src) != 0)) { DeleteObject(hSelMask); - hSelMask = CreateBitmap(rectSel_src[2], rectSel_src[3], 1, 1, NULL); + hSelMask = CreateBitmap(RECT_WIDTH(rectSel_src), RECT_HEIGHT(rectSel_src), 1, 1, NULL); DeleteObject(SelectObject(hSelDC, hSelMask)); - Rect(hSelDC, 0, 0, rectSel_src[2], rectSel_src[3], 0x00ffffff, 0x00ffffff, 1, 2); - SelectObject(hSelDC, hSelBm = CreateDIBWithProperties(rectSel_src[2], rectSel_src[3])); + Rect(hSelDC, 0, 0, RECT_WIDTH(rectSel_src), RECT_HEIGHT(rectSel_src), 0x00ffffff, 0x00ffffff, 1, 2); + SelectObject(hSelDC, hSelBm = CreateDIBWithProperties(RECT_WIDTH(rectSel_src), RECT_HEIGHT(rectSel_src))); resetToU1(); - BitBlt(hSelDC, 0, 0, rectSel_src[2], rectSel_src[3], hDrawingDC, rectSel_src[0], - rectSel_src[1], SRCCOPY); - Rect(hdc, rectSel_src[0], rectSel_src[1], rectSel_src[0] + rectSel_src[2], - rectSel_src[1] + rectSel_src[3], bgColor, bgColor, 0, TRUE); - newReversible(); - - BitBlt(hDrawingDC, rectSel_src[0], rectSel_src[1], rectSel_src[2], rectSel_src[3], hSelDC, 0, + BitBlt(hSelDC, 0, 0, RECT_WIDTH(rectSel_src), RECT_HEIGHT(rectSel_src), hDrawingDC, rectSel_src.left, + rectSel_src.top, SRCCOPY); + Rect(hdc, rectSel_src.left, rectSel_src.top, rectSel_src.right, + rectSel_src.bottom, bgColor, bgColor, 0, TRUE); + newReversible(); + + BitBlt(hDrawingDC, rectSel_src.left, rectSel_src.top, RECT_WIDTH(rectSel_src), RECT_HEIGHT(rectSel_src), hSelDC, 0, 0, SRCCOPY);
placeSelWin(); ShowWindow(hSelection, SW_SHOW); - /* force refresh of selection contents */ - SendMessage(hSelection, WM_LBUTTONDOWN, 0, 0); - SendMessage(hSelection, WM_MOUSEMOVE, 0, 0); - SendMessage(hSelection, WM_LBUTTONUP, 0, 0); + ForceRefreshSelectionContents(); + } + break; + case TOOL_TEXT: + resetToU1(); + if ((RECT_WIDTH(rectSel_src) != 0) && (RECT_HEIGHT(rectSel_src) != 0)) + { + newReversible(); + + placeSelWin(); + ShowWindow(hSelection, SW_SHOW); + ForceRefreshSelectionContents(); } break; case TOOL_RUBBER:
Modified: trunk/reactos/base/applications/mspaint/palette.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mspaint/p... ============================================================================== --- trunk/reactos/base/applications/mspaint/palette.c [iso-8859-1] (original) +++ trunk/reactos/base/applications/mspaint/palette.c [iso-8859-1] Fri Feb 7 17:54:25 2014 @@ -67,6 +67,8 @@ { fgColor = palColors[(GET_X_LPARAM(lParam) - 31) / 16 + (GET_Y_LPARAM(lParam) / 16) * 14]; InvalidateRect(hwnd, NULL, FALSE); + if (activeTool == 10) + ForceRefreshSelectionContents(); } break; case WM_RBUTTONDOWN: @@ -74,6 +76,8 @@ { bgColor = palColors[(GET_X_LPARAM(lParam) - 31) / 16 + (GET_Y_LPARAM(lParam) / 16) * 14]; InvalidateRect(hwnd, NULL, FALSE); + if (activeTool == 10) + ForceRefreshSelectionContents(); } break; case WM_LBUTTONDBLCLK: @@ -84,6 +88,8 @@ choosecolor.rgbResult; fgColor = choosecolor.rgbResult; InvalidateRect(hwnd, NULL, FALSE); + if (activeTool == 10) + ForceRefreshSelectionContents(); } break; case WM_RBUTTONDBLCLK: @@ -94,6 +100,8 @@ choosecolor.rgbResult; bgColor = choosecolor.rgbResult; InvalidateRect(hwnd, NULL, FALSE); + if (activeTool == 10) + ForceRefreshSelectionContents(); } break;
Modified: trunk/reactos/base/applications/mspaint/precomp.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mspaint/p... ============================================================================== --- trunk/reactos/base/applications/mspaint/precomp.h [iso-8859-1] (original) +++ trunk/reactos/base/applications/mspaint/precomp.h [iso-8859-1] Fri Feb 7 17:54:25 2014 @@ -20,5 +20,6 @@ #include "globalvar.h" #include "history.h" #include "mouse.h" +#include "selection.h"
#endif /* _MSPAINT_H */
Modified: trunk/reactos/base/applications/mspaint/selection.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mspaint/s... ============================================================================== --- trunk/reactos/base/applications/mspaint/selection.c [iso-8859-1] (original) +++ trunk/reactos/base/applications/mspaint/selection.c [iso-8859-1] Fri Feb 7 17:54:25 2014 @@ -18,10 +18,50 @@
BOOL moving = FALSE; int action = 0; -short xPos; -short yPos; -short xFrac; -short yFrac; +POINTS pos; +POINTS frac; + +BOOL +ColorKeyedMaskBlt(HDC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HDC hdcSrc, int nXSrc, int nYSrc, HBITMAP hbmMask, int xMask, int yMask, DWORD dwRop, COLORREF keyColor) +{ + HDC hTempDC; + HDC hTempDC2; + HBITMAP hTempBm; + HBRUSH hTempBrush; + HBITMAP hTempMask; + + hTempDC = CreateCompatibleDC(hdcSrc); + hTempDC2 = CreateCompatibleDC(hdcSrc); + hTempBm = CreateCompatibleBitmap(hTempDC, nWidth, nHeight); + SelectObject(hTempDC, hTempBm); + hTempBrush = CreateSolidBrush(keyColor); + SelectObject(hTempDC, hTempBrush); + BitBlt(hTempDC, 0, 0, nWidth, nHeight, hdcSrc, nXSrc, nYSrc, SRCCOPY); + PatBlt(hTempDC, 0, 0, nWidth, nHeight, PATINVERT); + hTempMask = CreateBitmap(nWidth, nHeight, 1, 1, NULL); + SelectObject(hTempDC2, hTempMask); + BitBlt(hTempDC2, 0, 0, nWidth, nHeight, hTempDC, 0, 0, SRCCOPY); + SelectObject(hTempDC, hbmMask); + BitBlt(hTempDC2, 0, 0, nWidth, nHeight, hTempDC, xMask, yMask, SRCAND); + MaskBlt(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc, hTempMask, xMask, yMask, dwRop); + DeleteDC(hTempDC); + DeleteDC(hTempDC2); + DeleteObject(hTempBm); + DeleteObject(hTempBrush); + DeleteObject(hTempMask); + return TRUE; +} + +void +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)); + } +}
int identifyCorner(short x, short y, short w, short h) @@ -65,15 +105,15 @@ { HDC hDC = GetDC(hwnd); DefWindowProc(hwnd, message, wParam, lParam); - SelectionFrame(hDC, 1, 1, rectSel_dest[2] * zoom / 1000 + 5, - rectSel_dest[3] * zoom / 1000 + 5); + SelectionFrame(hDC, 1, 1, RECT_WIDTH(rectSel_dest) * zoom / 1000 + 5, + RECT_HEIGHT(rectSel_dest) * zoom / 1000 + 5); ReleaseDC(hwnd, hDC); } break; } case WM_LBUTTONDOWN: - xPos = GET_X_LPARAM(lParam); - yPos = GET_Y_LPARAM(lParam); + pos.x = GET_X_LPARAM(lParam); + pos.y = GET_Y_LPARAM(lParam); SetCapture(hwnd); if (action != 0) SetCursor(LoadCursor(NULL, cursors[action])); @@ -83,107 +123,94 @@ if (moving) { TCHAR sizeStr[100]; - int xDelta; - int yDelta; + POINT delta; resetToU1(); - xFrac += GET_X_LPARAM(lParam) - xPos; - yFrac += GET_Y_LPARAM(lParam) - yPos; + frac.x += GET_X_LPARAM(lParam) - pos.x; + frac.y += GET_Y_LPARAM(lParam) - pos.y; if (zoom < 1000) { - xDelta = xFrac * 1000 / zoom; - xFrac = 0; - yDelta = yFrac * 1000 / zoom; - yFrac = 0; + delta.x = frac.x * 1000 / zoom; + frac.x = 0; + delta.y = frac.y * 1000 / zoom; + frac.y = 0; } else { - xDelta = xFrac * 1000 / zoom; - xFrac -= (xFrac * 1000 / zoom) * zoom / 1000; - yDelta = yFrac * 1000 / zoom; - yFrac -= (yFrac * 1000 / zoom) * zoom / 1000; + delta.x = frac.x * 1000 / zoom; + frac.x -= (frac.x * 1000 / zoom) * zoom / 1000; + delta.y = frac.y * 1000 / zoom; + frac.y -= (frac.y * 1000 / zoom) * zoom / 1000; } switch (action) { - case 0: - rectSel_dest[0] += xDelta; - rectSel_dest[1] += yDelta; - break; - case 1: - rectSel_dest[0] += xDelta; - rectSel_dest[1] += yDelta; - rectSel_dest[2] -= xDelta; - rectSel_dest[3] -= yDelta; - break; - case 2: - rectSel_dest[1] += yDelta; - rectSel_dest[3] -= yDelta; - break; - case 3: - rectSel_dest[1] += yDelta; - rectSel_dest[2] += xDelta; - rectSel_dest[3] -= yDelta; - break; - case 4: - rectSel_dest[0] += xDelta; - rectSel_dest[2] -= xDelta; - break; - case 5: - rectSel_dest[2] += xDelta; - break; - case 6: - rectSel_dest[0] += xDelta; - rectSel_dest[2] -= xDelta; - rectSel_dest[3] += yDelta; - break; - case 7: - rectSel_dest[3] += yDelta; - break; - case 8: - rectSel_dest[2] += xDelta; - rectSel_dest[3] += yDelta; - break; - } - - _stprintf(sizeStr, _T("%d x %d"), rectSel_dest[2], rectSel_dest[3]); + /* TODO: make sure that the selection is at least 1 pixel wide and high */ + case 0: /* move selection */ + OffsetRect(&rectSel_dest, delta.x, delta.y); + break; + case 1: /* resize at upper left corner */ + rectSel_dest.left += delta.x; + rectSel_dest.top += delta.y; + break; + case 2: /* resize at top edge */ + rectSel_dest.top += delta.y; + break; + case 3: /* resize at upper right corner */ + rectSel_dest.top += delta.y; + rectSel_dest.right += delta.x; + break; + case 4: /* resize at left edge */ + rectSel_dest.left += delta.x; + break; + case 5: /* resize at right edge */ + rectSel_dest.right += delta.x; + break; + case 6: /* resize at lower left corner */ + rectSel_dest.left += delta.x; + rectSel_dest.bottom += delta.y; + break; + case 7: /* resize at bottom edge */ + rectSel_dest.bottom += delta.y; + break; + case 8: /* resize at lower right corner */ + rectSel_dest.right += delta.x; + rectSel_dest.bottom += delta.y; + break; + } + + _stprintf(sizeStr, _T("%d x %d"), RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest)); SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) sizeStr);
- if (action != 0) - StretchBlt(hDrawingDC, rectSel_dest[0], rectSel_dest[1], rectSel_dest[2], rectSel_dest[3], hSelDC, 0, 0, GetDIBWidth(hSelBm), GetDIBHeight(hSelBm), SRCCOPY); + if (activeTool == 10) /* text tool */ + { + Text(hDrawingDC, rectSel_dest.left, rectSel_dest.top, rectSel_dest.right, rectSel_dest.bottom, fgColor, bgColor, textToolText, hfontTextFont, transpBg); + } else - if (transpBg == 0) - MaskBlt(hDrawingDC, rectSel_dest[0], rectSel_dest[1], rectSel_dest[2], rectSel_dest[3], - hSelDC, 0, 0, hSelMask, 0, 0, MAKEROP4(SRCCOPY, SRCAND)); - else - { - HBITMAP tempMask; - HBRUSH oldBrush; - HDC tempDC; - tempMask = CreateBitmap(rectSel_dest[2], rectSel_dest[3], 1, 1, NULL); - oldBrush = SelectObject(hSelDC, CreateSolidBrush(bgColor)); - tempDC = CreateCompatibleDC(hSelDC); - SelectObject(tempDC, tempMask); - MaskBlt(tempDC, 0, 0, rectSel_dest[2], rectSel_dest[3], hSelDC, 0, 0, hSelMask, 0, 0, - MAKEROP4(NOTSRCCOPY, BLACKNESS)); - DeleteDC(tempDC); - DeleteObject(SelectObject(hSelDC, oldBrush)); - - MaskBlt(hDrawingDC, rectSel_dest[0], rectSel_dest[1], rectSel_dest[2], rectSel_dest[3], - hSelDC, 0, 0, tempMask, 0, 0, MAKEROP4(SRCCOPY, SRCAND)); - DeleteObject(tempMask); + { + if (action != 0) + StretchBlt(hDrawingDC, rectSel_dest.left, rectSel_dest.top, RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest), hSelDC, 0, 0, GetDIBWidth(hSelBm), GetDIBHeight(hSelBm), SRCCOPY); + else + if (transpBg == 0) + MaskBlt(hDrawingDC, rectSel_dest.left, rectSel_dest.top, RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest), + hSelDC, 0, 0, hSelMask, 0, 0, MAKEROP4(SRCCOPY, SRCAND)); + else + { + ColorKeyedMaskBlt(hDrawingDC, rectSel_dest.left, rectSel_dest.top, RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest), + hSelDC, 0, 0, hSelMask, 0, 0, MAKEROP4(SRCCOPY, SRCAND), bgColor); + } } InvalidateRect(hImageArea, NULL, FALSE); - xPos = GET_X_LPARAM(lParam); - yPos = GET_Y_LPARAM(lParam); + pos.x = GET_X_LPARAM(lParam); + pos.y = GET_Y_LPARAM(lParam); //SendMessage(hwnd, WM_PAINT, 0, 0); } else { - int w = rectSel_dest[2] * zoom / 1000 + 6; - int h = rectSel_dest[3] * zoom / 1000 + 6; - xPos = GET_X_LPARAM(lParam); - yPos = GET_Y_LPARAM(lParam); + int w = RECT_WIDTH(rectSel_dest) * zoom / 1000 + 6; + int h = RECT_HEIGHT(rectSel_dest) * zoom / 1000 + 6; + pos.x = GET_X_LPARAM(lParam); + pos.y = GET_Y_LPARAM(lParam); SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) NULL); - action = identifyCorner(xPos, yPos, w, h); + action = identifyCorner(pos.x, pos.y, w, h); if (action != 0) SetCursor(LoadCursor(NULL, cursors[action])); } @@ -195,25 +222,32 @@ ReleaseCapture(); if (action != 0) { - HDC hTempDC; - HBITMAP hTempBm; - hTempDC = CreateCompatibleDC(hSelDC); - hTempBm = CreateDIBWithProperties(rectSel_dest[2], rectSel_dest[3]); - SelectObject(hTempDC, hTempBm); - SelectObject(hSelDC, hSelBm); - StretchBlt(hTempDC, 0, 0, rectSel_dest[2], rectSel_dest[3], hSelDC, 0, 0, - GetDIBWidth(hSelBm), GetDIBHeight(hSelBm), SRCCOPY); - DeleteObject(hSelBm); - hSelBm = hTempBm; - hTempBm = CreateBitmap(rectSel_dest[2], rectSel_dest[3], 1, 1, NULL); - SelectObject(hTempDC, hTempBm); - SelectObject(hSelDC, hSelMask); - StretchBlt(hTempDC, 0, 0, rectSel_dest[2], rectSel_dest[3], hSelDC, 0, 0, - GetDIBWidth(hSelMask), GetDIBHeight(hSelMask), SRCCOPY); - DeleteObject(hSelMask); - hSelMask = hTempBm; - SelectObject(hSelDC, hSelBm); - DeleteDC(hTempDC); + if (activeTool == 10) /* text tool */ + { + + } + else + { + HDC hTempDC; + HBITMAP hTempBm; + hTempDC = CreateCompatibleDC(hSelDC); + hTempBm = CreateDIBWithProperties(RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest)); + SelectObject(hTempDC, hTempBm); + SelectObject(hSelDC, hSelBm); + StretchBlt(hTempDC, 0, 0, RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest), hSelDC, 0, 0, + GetDIBWidth(hSelBm), GetDIBHeight(hSelBm), SRCCOPY); + DeleteObject(hSelBm); + hSelBm = hTempBm; + hTempBm = CreateBitmap(RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest), 1, 1, NULL); + SelectObject(hTempDC, hTempBm); + SelectObject(hSelDC, hSelMask); + StretchBlt(hTempDC, 0, 0, RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest), hSelDC, 0, 0, + GetDIBWidth(hSelMask), GetDIBHeight(hSelMask), SRCCOPY); + DeleteObject(hSelMask); + hSelMask = hTempBm; + SelectObject(hSelDC, hSelBm); + DeleteDC(hTempDC); + } } placeSelWin(); ShowWindow(hSelection, SW_HIDE);
Modified: trunk/reactos/base/applications/mspaint/selection.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mspaint/s... ============================================================================== --- trunk/reactos/base/applications/mspaint/selection.h [iso-8859-1] (original) +++ trunk/reactos/base/applications/mspaint/selection.h [iso-8859-1] Fri Feb 7 17:54:25 2014 @@ -6,4 +6,6 @@ * PROGRAMMERS: Benedikt Freisen */
+void ForceRefreshSelectionContents(); + LRESULT CALLBACK SelectionWinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
Modified: trunk/reactos/base/applications/mspaint/toolsettings.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mspaint/t... ============================================================================== --- trunk/reactos/base/applications/mspaint/toolsettings.c [iso-8859-1] (original) +++ trunk/reactos/base/applications/mspaint/toolsettings.c [iso-8859-1] Fri Feb 7 17:54:25 2014 @@ -184,13 +184,7 @@ transpBg = (y - 2) / 31; InvalidateRect(hwnd, NULL, TRUE);
- if (IsWindowVisible(hSelection)) - { - /* force refresh of selection contents */ - SendMessage(hSelection, WM_LBUTTONDOWN, 0, MAKELPARAM(0, 0)); - SendMessage(hSelection, WM_MOUSEMOVE, 0, MAKELPARAM(0, 0)); - SendMessage(hSelection, WM_LBUTTONUP, 0, MAKELPARAM(0, 0)); - } + ForceRefreshSelectionContents(); } break; case TOOL_RUBBER:
Modified: trunk/reactos/base/applications/mspaint/winproc.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mspaint/w... ============================================================================== --- trunk/reactos/base/applications/mspaint/winproc.c [iso-8859-1] (original) +++ trunk/reactos/base/applications/mspaint/winproc.c [iso-8859-1] Fri Feb 7 17:54:25 2014 @@ -44,15 +44,15 @@ int tbPos = 0; int tempZoom = newZoom;
- long clientRectScrollbox[4]; - long clientRectImageArea[4]; + RECT clientRectScrollbox; + RECT clientRectImageArea; int x, y, w, h; - GetClientRect(hScrollbox, (LPRECT) &clientRectScrollbox); - GetClientRect(hImageArea, (LPRECT) &clientRectImageArea); - w = clientRectImageArea[2] * clientRectScrollbox[2] / (clientRectImageArea[2] * newZoom / zoom); - h = clientRectImageArea[3] * clientRectScrollbox[3] / (clientRectImageArea[3] * newZoom / zoom); - x = max(0, min(clientRectImageArea[2] - w, mouseX - w / 2)) * newZoom / zoom; - y = max(0, min(clientRectImageArea[3] - h, mouseY - h / 2)) * newZoom / zoom; + GetClientRect(hScrollbox, &clientRectScrollbox); + GetClientRect(hImageArea, &clientRectImageArea); + w = clientRectImageArea.right * clientRectScrollbox.right / (clientRectImageArea.right * newZoom / zoom); + h = clientRectImageArea.bottom * clientRectScrollbox.bottom / (clientRectImageArea.bottom * newZoom / zoom); + x = max(0, min(clientRectImageArea.right - w, mouseX - w / 2)) * newZoom / zoom; + y = max(0, min(clientRectImageArea.bottom - h, mouseY - h / 2)) * newZoom / zoom;
zoom = newZoom;
@@ -81,15 +81,15 @@ LOGBRUSH logbrush; int rop;
- long clientRectScrollbox[4]; - long clientRectImageArea[4]; + RECT clientRectScrollbox; + RECT clientRectImageArea; int x, y, w, h; - GetClientRect(hScrollbox, (LPRECT) &clientRectScrollbox); - GetClientRect(hImageArea, (LPRECT) &clientRectImageArea); - w = clientRectImageArea[2] * clientRectScrollbox[2] / (clientRectImageArea[2] * 2); - h = clientRectImageArea[3] * clientRectScrollbox[3] / (clientRectImageArea[3] * 2); - x = max(0, min(clientRectImageArea[2] - w, mouseX - w / 2)); - y = max(0, min(clientRectImageArea[3] - h, mouseY - h / 2)); + GetClientRect(hScrollbox, &clientRectScrollbox); + GetClientRect(hImageArea, &clientRectImageArea); + w = clientRectImageArea.right * clientRectScrollbox.right / (clientRectImageArea.right * 2); + h = clientRectImageArea.bottom * clientRectScrollbox.bottom / (clientRectImageArea.bottom * 2); + x = max(0, min(clientRectImageArea.right - w, mouseX - w / 2)); + y = max(0, min(clientRectImageArea.bottom - h, mouseY - h / 2));
hdc = GetDC(hImageArea); oldPen = SelectObject(hdc, CreatePen(PS_SOLID, 0, 0)); @@ -190,25 +190,22 @@ IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG))); newReversible(); - rectSel_src[0] = rectSel_src[1] = rectSel_src[2] = rectSel_src[3] = 0; - rectSel_dest[0] = rectSel_dest[1] = 0; - rectSel_dest[2] = GetDIBWidth(hSelBm); - rectSel_dest[3] = GetDIBHeight(hSelBm); + SetRectEmpty(&rectSel_src); + rectSel_dest.left = rectSel_dest.top = 0; + rectSel_dest.right = rectSel_dest.left + GetDIBWidth(hSelBm); + rectSel_dest.bottom = rectSel_dest.top + GetDIBHeight(hSelBm);
hTempDC = CreateCompatibleDC(hSelDC); - hTempMask = CreateBitmap(rectSel_dest[2], rectSel_dest[3], 1, 1, NULL); + hTempMask = CreateBitmap(RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest), 1, 1, NULL); SelectObject(hTempDC, hTempMask); - Rect(hTempDC, 0, 0, rectSel_dest[2], rectSel_dest[3], 0x00ffffff, 0x00ffffff, 1, 1); + Rect(hTempDC, rectSel_dest.left, rectSel_dest.top, rectSel_dest.right, rectSel_dest.bottom, 0x00ffffff, 0x00ffffff, 1, 1); DeleteObject(hSelMask); hSelMask = hTempMask; DeleteDC(hTempDC);
placeSelWin(); ShowWindow(hSelection, SW_SHOW); - /* force refresh of selection contents */ - SendMessage(hSelection, WM_LBUTTONDOWN, 0, MAKELPARAM(0, 0)); - SendMessage(hSelection, WM_MOUSEMOVE, 0, MAKELPARAM(0, 0)); - SendMessage(hSelection, WM_LBUTTONUP, 0, MAKELPARAM(0, 0)); + ForceRefreshSelectionContents(); }
BOOL drawing; @@ -280,100 +277,52 @@ break;
case WM_INITMENUPOPUP: + { + HMENU menu = GetMenu(hMainWnd); + BOOL trueSelection = (IsWindowVisible(hSelection) && ((activeTool == 1) || (activeTool == 2))); switch (lParam) { - case 0: - if (isAFile) - { - EnableMenuItem(GetMenu(hMainWnd), IDM_FILEASWALLPAPERPLANE, - MF_ENABLED | MF_BYCOMMAND); - EnableMenuItem(GetMenu(hMainWnd), IDM_FILEASWALLPAPERCENTERED, - MF_ENABLED | MF_BYCOMMAND); - EnableMenuItem(GetMenu(hMainWnd), IDM_FILEASWALLPAPERSTRETCHED, - MF_ENABLED | MF_BYCOMMAND); - } - else - { - EnableMenuItem(GetMenu(hMainWnd), IDM_FILEASWALLPAPERPLANE, - MF_GRAYED | MF_BYCOMMAND); - EnableMenuItem(GetMenu(hMainWnd), IDM_FILEASWALLPAPERCENTERED, - MF_GRAYED | MF_BYCOMMAND); - EnableMenuItem(GetMenu(hMainWnd), IDM_FILEASWALLPAPERSTRETCHED, - MF_GRAYED | MF_BYCOMMAND); - } - break; - case 1: - EnableMenuItem(GetMenu(hMainWnd), IDM_EDITUNDO, - (undoSteps > 0) ? (MF_ENABLED | MF_BYCOMMAND) : (MF_GRAYED | MF_BYCOMMAND)); - EnableMenuItem(GetMenu(hMainWnd), IDM_EDITREDO, - (redoSteps > 0) ? (MF_ENABLED | MF_BYCOMMAND) : (MF_GRAYED | MF_BYCOMMAND)); - if (IsWindowVisible(hSelection)) - { - EnableMenuItem(GetMenu(hMainWnd), IDM_EDITCUT, MF_ENABLED | MF_BYCOMMAND); - EnableMenuItem(GetMenu(hMainWnd), IDM_EDITCOPY, MF_ENABLED | MF_BYCOMMAND); - EnableMenuItem(GetMenu(hMainWnd), IDM_EDITDELETESELECTION, MF_ENABLED | MF_BYCOMMAND); - EnableMenuItem(GetMenu(hMainWnd), IDM_EDITINVERTSELECTION, MF_ENABLED | MF_BYCOMMAND); - EnableMenuItem(GetMenu(hMainWnd), IDM_EDITCOPYTO, MF_ENABLED | MF_BYCOMMAND); - } - else - { - EnableMenuItem(GetMenu(hMainWnd), IDM_EDITCUT, MF_GRAYED | MF_BYCOMMAND); - EnableMenuItem(GetMenu(hMainWnd), IDM_EDITCOPY, MF_GRAYED | MF_BYCOMMAND); - EnableMenuItem(GetMenu(hMainWnd), IDM_EDITDELETESELECTION, MF_GRAYED | MF_BYCOMMAND); - EnableMenuItem(GetMenu(hMainWnd), IDM_EDITINVERTSELECTION, MF_GRAYED | MF_BYCOMMAND); - EnableMenuItem(GetMenu(hMainWnd), IDM_EDITCOPYTO, MF_GRAYED | MF_BYCOMMAND); - } + case 0: /* File menu */ + EnableMenuItem(menu, IDM_FILEASWALLPAPERPLANE, ENABLED_IF(isAFile)); + EnableMenuItem(menu, IDM_FILEASWALLPAPERCENTERED, ENABLED_IF(isAFile)); + EnableMenuItem(menu, IDM_FILEASWALLPAPERSTRETCHED, ENABLED_IF(isAFile)); + break; + case 1: /* Edit menu */ + EnableMenuItem(menu, IDM_EDITUNDO, ENABLED_IF(undoSteps > 0)); + EnableMenuItem(menu, IDM_EDITREDO, ENABLED_IF(redoSteps > 0)); + EnableMenuItem(menu, IDM_EDITCUT, ENABLED_IF(trueSelection)); + EnableMenuItem(menu, IDM_EDITCOPY, ENABLED_IF(trueSelection)); + EnableMenuItem(menu, IDM_EDITDELETESELECTION, ENABLED_IF(trueSelection)); + EnableMenuItem(menu, IDM_EDITINVERTSELECTION, ENABLED_IF(trueSelection)); + EnableMenuItem(menu, IDM_EDITCOPYTO, ENABLED_IF(trueSelection)); OpenClipboard(hMainWnd); - if (GetClipboardData(CF_BITMAP) != NULL) - EnableMenuItem(GetMenu(hMainWnd), IDM_EDITPASTE, MF_ENABLED | MF_BYCOMMAND); - else - EnableMenuItem(GetMenu(hMainWnd), IDM_EDITPASTE, MF_GRAYED | MF_BYCOMMAND); + EnableMenuItem(menu, IDM_EDITPASTE, ENABLED_IF(GetClipboardData(CF_BITMAP) != NULL)); CloseClipboard(); break; - case 3: - if (IsWindowVisible(hSelection)) - EnableMenuItem(GetMenu(hMainWnd), IDM_IMAGECROP, MF_ENABLED | MF_BYCOMMAND); - else - EnableMenuItem(GetMenu(hMainWnd), IDM_IMAGECROP, MF_GRAYED | MF_BYCOMMAND); - CheckMenuItem(GetMenu(hMainWnd), IDM_IMAGEDRAWOPAQUE, (transpBg == 0) ? - (MF_CHECKED | MF_BYCOMMAND) : (MF_UNCHECKED | MF_BYCOMMAND)); - break; - } - CheckMenuItem(GetMenu(hMainWnd), IDM_VIEWTOOLBOX, - IsWindowVisible(hToolBoxContainer) ? - (MF_CHECKED | MF_BYCOMMAND) : (MF_UNCHECKED | MF_BYCOMMAND)); - CheckMenuItem(GetMenu(hMainWnd), IDM_VIEWCOLORPALETTE, - IsWindowVisible(hPalWin) ? - (MF_CHECKED | MF_BYCOMMAND) : (MF_UNCHECKED | MF_BYCOMMAND)); - CheckMenuItem(GetMenu(hMainWnd), IDM_VIEWSTATUSBAR, - IsWindowVisible(hStatusBar) ? - (MF_CHECKED | MF_BYCOMMAND) : (MF_UNCHECKED | MF_BYCOMMAND)); - - CheckMenuItem(GetMenu(hMainWnd), IDM_VIEWSHOWGRID, - showGrid ? (MF_CHECKED | MF_BYCOMMAND) : (MF_UNCHECKED | MF_BYCOMMAND)); - CheckMenuItem(GetMenu(hMainWnd), IDM_VIEWSHOWMINIATURE, - showMiniature ? (MF_CHECKED | MF_BYCOMMAND) : (MF_UNCHECKED | MF_BYCOMMAND)); - - CheckMenuItem(GetMenu(hMainWnd), IDM_VIEWZOOM125, - (zoom == 125) ? (MF_CHECKED | MF_BYCOMMAND) : (MF_UNCHECKED | MF_BYCOMMAND)); - CheckMenuItem(GetMenu(hMainWnd), IDM_VIEWZOOM25, - (zoom == 250) ? (MF_CHECKED | MF_BYCOMMAND) : (MF_UNCHECKED | MF_BYCOMMAND)); - CheckMenuItem(GetMenu(hMainWnd), IDM_VIEWZOOM50, - (zoom == 500) ? (MF_CHECKED | MF_BYCOMMAND) : (MF_UNCHECKED | MF_BYCOMMAND)); - CheckMenuItem(GetMenu(hMainWnd), IDM_VIEWZOOM100, - (zoom == 1000) ? (MF_CHECKED | MF_BYCOMMAND) : (MF_UNCHECKED | MF_BYCOMMAND)); - CheckMenuItem(GetMenu(hMainWnd), IDM_VIEWZOOM200, - (zoom == 2000) ? (MF_CHECKED | MF_BYCOMMAND) : (MF_UNCHECKED | MF_BYCOMMAND)); - CheckMenuItem(GetMenu(hMainWnd), IDM_VIEWZOOM400, - (zoom == 4000) ? (MF_CHECKED | MF_BYCOMMAND) : (MF_UNCHECKED | MF_BYCOMMAND)); - CheckMenuItem(GetMenu(hMainWnd), IDM_VIEWZOOM800, - (zoom == 8000) ? (MF_CHECKED | MF_BYCOMMAND) : (MF_UNCHECKED | MF_BYCOMMAND)); - - CheckMenuItem(GetMenu(hMainWnd), IDM_COLORSMODERNPALETTE, - (selectedPalette == 1) ? (MF_CHECKED | MF_BYCOMMAND) : (MF_UNCHECKED | MF_BYCOMMAND)); - CheckMenuItem(GetMenu(hMainWnd), IDM_COLORSOLDPALETTE, - (selectedPalette == 2) ? (MF_CHECKED | MF_BYCOMMAND) : (MF_UNCHECKED | MF_BYCOMMAND)); - break; + case 3: /* Image menu */ + EnableMenuItem(menu, IDM_IMAGECROP, ENABLED_IF(IsWindowVisible(hSelection))); + CheckMenuItem(menu, IDM_IMAGEDRAWOPAQUE, CHECKED_IF(transpBg == 0)); + break; + } + CheckMenuItem(menu, IDM_VIEWTOOLBOX, CHECKED_IF(IsWindowVisible(hToolBoxContainer))); + CheckMenuItem(menu, IDM_VIEWCOLORPALETTE, CHECKED_IF(IsWindowVisible(hPalWin))); + CheckMenuItem(menu, IDM_VIEWSTATUSBAR, CHECKED_IF(IsWindowVisible(hStatusBar))); + + CheckMenuItem(menu, IDM_VIEWSHOWGRID, CHECKED_IF(showGrid)); + CheckMenuItem(menu, IDM_VIEWSHOWMINIATURE, CHECKED_IF(showMiniature)); + + CheckMenuItem(menu, IDM_VIEWZOOM125, CHECKED_IF(zoom == 125)); + CheckMenuItem(menu, IDM_VIEWZOOM25, CHECKED_IF(zoom == 250)); + CheckMenuItem(menu, IDM_VIEWZOOM50, CHECKED_IF(zoom == 500)); + CheckMenuItem(menu, IDM_VIEWZOOM100, CHECKED_IF(zoom == 1000)); + CheckMenuItem(menu, IDM_VIEWZOOM200, CHECKED_IF(zoom == 2000)); + CheckMenuItem(menu, IDM_VIEWZOOM400, CHECKED_IF(zoom == 4000)); + CheckMenuItem(menu, IDM_VIEWZOOM800, CHECKED_IF(zoom == 8000)); + + CheckMenuItem(menu, IDM_COLORSMODERNPALETTE, CHECKED_IF(selectedPalette == 1)); + CheckMenuItem(menu, IDM_COLORSOLDPALETTE, CHECKED_IF(selectedPalette == 2)); + break; + }
case WM_SIZE: if (hwnd == hMainWnd) @@ -413,25 +362,25 @@ } if ((hwnd == hImageArea) || (hwnd == hScrollbox)) { - long clientRectScrollbox[4]; - long clientRectImageArea[4]; + RECT clientRectScrollbox; + RECT clientRectImageArea; SCROLLINFO si; - GetClientRect(hScrollbox, (LPRECT) &clientRectScrollbox); - GetClientRect(hImageArea, (LPRECT) &clientRectImageArea); + GetClientRect(hScrollbox, &clientRectScrollbox); + GetClientRect(hImageArea, &clientRectImageArea); si.cbSize = sizeof(SCROLLINFO); si.fMask = SIF_PAGE | SIF_RANGE; - si.nMax = clientRectImageArea[2] + 6 - 1; + si.nMax = clientRectImageArea.right + 6 - 1; si.nMin = 0; - si.nPage = clientRectScrollbox[2]; + si.nPage = clientRectScrollbox.right; SetScrollInfo(hScrollbox, SB_HORZ, &si, TRUE); - GetClientRect(hScrollbox, (LPRECT) clientRectScrollbox); - si.nMax = clientRectImageArea[3] + 6 - 1; - si.nPage = clientRectScrollbox[3]; + GetClientRect(hScrollbox, &clientRectScrollbox); + si.nMax = clientRectImageArea.bottom + 6 - 1; + si.nPage = clientRectScrollbox.bottom; SetScrollInfo(hScrollbox, SB_VERT, &si, TRUE); MoveWindow(hScrlClient, -GetScrollPos(hScrollbox, SB_HORZ), -GetScrollPos(hScrollbox, SB_VERT), - max(clientRectImageArea[2] + 6, clientRectScrollbox[2]), - max(clientRectImageArea[3] + 6, clientRectScrollbox[3]), TRUE); + max(clientRectImageArea.right + 6, clientRectScrollbox.right), + max(clientRectImageArea.bottom + 6, clientRectScrollbox.bottom), TRUE); } break;
@@ -908,8 +857,8 @@ if (activeTool == TOOL_RECTSEL) { newReversible(); - Rect(hDrawingDC, rectSel_dest[0], rectSel_dest[1], rectSel_dest[2] + rectSel_dest[0], - rectSel_dest[3] + rectSel_dest[1], bgColor, bgColor, 0, TRUE); + Rect(hDrawingDC, rectSel_dest.left, rectSel_dest.top, rectSel_dest.right, + rectSel_dest.bottom, bgColor, bgColor, 0, TRUE); } if (activeTool == TOOL_FREESEL) { @@ -982,15 +931,12 @@ if (IsWindowVisible(hSelection)) { SelectObject(hSelDC, hSelMask); - StretchBlt(hSelDC, rectSel_dest[2] - 1, 0, -rectSel_dest[2], rectSel_dest[3], hSelDC, - 0, 0, rectSel_dest[2], rectSel_dest[3], SRCCOPY); + StretchBlt(hSelDC, RECT_WIDTH(rectSel_dest) - 1, 0, -RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest), hSelDC, + 0, 0, RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest), SRCCOPY); SelectObject(hSelDC, hSelBm); - StretchBlt(hSelDC, rectSel_dest[2] - 1, 0, -rectSel_dest[2], rectSel_dest[3], hSelDC, - 0, 0, rectSel_dest[2], rectSel_dest[3], SRCCOPY); - /* force refresh of selection contents */ - SendMessage(hSelection, WM_LBUTTONDOWN, 0, MAKELPARAM(0, 0)); - SendMessage(hSelection, WM_MOUSEMOVE, 0, MAKELPARAM(0, 0)); - SendMessage(hSelection, WM_LBUTTONUP, 0, MAKELPARAM(0, 0)); + StretchBlt(hSelDC, RECT_WIDTH(rectSel_dest) - 1, 0, -RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest), hSelDC, + 0, 0, RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest), SRCCOPY); + ForceRefreshSelectionContents(); } else { @@ -1004,15 +950,12 @@ if (IsWindowVisible(hSelection)) { SelectObject(hSelDC, hSelMask); - StretchBlt(hSelDC, 0, rectSel_dest[3] - 1, rectSel_dest[2], -rectSel_dest[3], hSelDC, - 0, 0, rectSel_dest[2], rectSel_dest[3], SRCCOPY); + StretchBlt(hSelDC, 0, RECT_HEIGHT(rectSel_dest) - 1, RECT_WIDTH(rectSel_dest), -RECT_HEIGHT(rectSel_dest), hSelDC, + 0, 0, RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest), SRCCOPY); SelectObject(hSelDC, hSelBm); - StretchBlt(hSelDC, 0, rectSel_dest[3] - 1, rectSel_dest[2], -rectSel_dest[3], hSelDC, - 0, 0, rectSel_dest[2], rectSel_dest[3], SRCCOPY); - /* force refresh of selection contents */ - SendMessage(hSelection, WM_LBUTTONDOWN, 0, MAKELPARAM(0, 0)); - SendMessage(hSelection, WM_MOUSEMOVE, 0, MAKELPARAM(0, 0)); - SendMessage(hSelection, WM_LBUTTONUP, 0, MAKELPARAM(0, 0)); + StretchBlt(hSelDC, 0, RECT_HEIGHT(rectSel_dest) - 1, RECT_WIDTH(rectSel_dest), -RECT_HEIGHT(rectSel_dest), hSelDC, + 0, 0, RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest), SRCCOPY); + ForceRefreshSelectionContents(); } else { @@ -1028,15 +971,12 @@ if (IsWindowVisible(hSelection)) { SelectObject(hSelDC, hSelMask); - StretchBlt(hSelDC, rectSel_dest[2] - 1, rectSel_dest[3] - 1, -rectSel_dest[2], -rectSel_dest[3], hSelDC, - 0, 0, rectSel_dest[2], rectSel_dest[3], SRCCOPY); + StretchBlt(hSelDC, RECT_WIDTH(rectSel_dest) - 1, RECT_HEIGHT(rectSel_dest) - 1, -RECT_WIDTH(rectSel_dest), -RECT_HEIGHT(rectSel_dest), hSelDC, + 0, 0, RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest), SRCCOPY); SelectObject(hSelDC, hSelBm); - StretchBlt(hSelDC, rectSel_dest[2] - 1, rectSel_dest[3] - 1, -rectSel_dest[2], -rectSel_dest[3], hSelDC, - 0, 0, rectSel_dest[2], rectSel_dest[3], SRCCOPY); - /* force refresh of selection contents */ - SendMessage(hSelection, WM_LBUTTONDOWN, 0, MAKELPARAM(0, 0)); - SendMessage(hSelection, WM_MOUSEMOVE, 0, MAKELPARAM(0, 0)); - SendMessage(hSelection, WM_LBUTTONUP, 0, MAKELPARAM(0, 0)); + StretchBlt(hSelDC, RECT_WIDTH(rectSel_dest) - 1, RECT_HEIGHT(rectSel_dest) - 1, -RECT_WIDTH(rectSel_dest), -RECT_HEIGHT(rectSel_dest), hSelDC, + 0, 0, RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest), SRCCOPY); + ForceRefreshSelectionContents(); } else {