lastY = y;
switch (activeTool)
{
- case 1:
+ case TOOL_FREESEL:
ShowWindow(hSelection, SW_HIDE);
if (ptStack != NULL)
HeapFree(GetProcessHeap(), 0, ptStack);
ptStack[0].x = x;
ptStack[0].y = y;
break;
- case 10:
- case 11:
- case 13:
- case 15:
- case 16:
+ case TOOL_TEXT:
+ case TOOL_LINE:
+ case TOOL_RECT:
+ case TOOL_ELLIPSE:
+ case TOOL_RRECT:
newReversible();
break;
- case 2:
+ case TOOL_RECTSEL:
newReversible();
ShowWindow(hSelection, SW_HIDE);
rectSel_src[2] = rectSel_src[3] = 0;
break;
- case 3:
+ case TOOL_RUBBER:
newReversible();
Erase(hdc, x, y, x, y, bg, rubberRadius);
break;
- case 4:
+ case TOOL_FILL:
newReversible();
Fill(hdc, x, y, fg);
break;
- case 7:
+ case TOOL_PEN:
newReversible();
SetPixel(hdc, x, y, fg);
break;
- case 8:
+ case TOOL_BRUSH:
newReversible();
Brush(hdc, x, y, x, y, fg, brushStyle);
break;
- case 9:
+ case TOOL_AIRBRUSH:
newReversible();
Airbrush(hdc, x, y, fg, airBrushWidth);
break;
- case 12:
+ case TOOL_BEZIER:
pointStack[pointSP].x = x;
pointStack[pointSP].y = y;
if (pointSP == 0)
pointSP++;
}
break;
- case 14:
+ case TOOL_SHAPE:
pointStack[pointSP].x = x;
pointStack[pointSP].y = y;
if (pointSP + 1 >= 2)
{
switch (activeTool)
{
- case 1:
+ case TOOL_FREESEL:
if (ptSP == 0)
newReversible();
ptSP++;
resetToU1();
Poly(hdc, ptStack, ptSP + 1, 0, 0, 2, 0, FALSE);
break;
- case 2:
+ case TOOL_RECTSEL:
{
short tempX;
short tempY;
RectSel(hdc, startX, startY, tempX, tempY);
break;
}
- case 3:
+ case TOOL_RUBBER:
Erase(hdc, lastX, lastY, x, y, bg, rubberRadius);
break;
- case 7:
+ case TOOL_PEN:
Line(hdc, lastX, lastY, x, y, fg, 1);
break;
- case 8:
+ case TOOL_BRUSH:
Brush(hdc, lastX, lastY, x, y, fg, brushStyle);
break;
- case 9:
+ case TOOL_AIRBRUSH:
Airbrush(hdc, x, y, fg, airBrushWidth);
break;
- case 11:
+ case TOOL_LINE:
resetToU1();
if (GetAsyncKeyState(VK_SHIFT) < 0)
roundTo8Directions(startX, startY, &x, &y);
Line(hdc, startX, startY, x, y, fg, lineWidth);
break;
- case 12:
+ case TOOL_BEZIER:
resetToU1();
pointStack[pointSP].x = x;
pointStack[pointSP].y = y;
break;
}
break;
- case 13:
+ case TOOL_RECT:
resetToU1();
if (GetAsyncKeyState(VK_SHIFT) < 0)
regularize(startX, startY, &x, &y);
Rect(hdc, startX, startY, x, y, fg, bg, lineWidth, shapeStyle);
break;
- case 14:
+ case TOOL_SHAPE:
resetToU1();
pointStack[pointSP].x = x;
pointStack[pointSP].y = y;
if (pointSP + 1 >= 2)
Poly(hdc, pointStack, pointSP + 1, fg, bg, lineWidth, shapeStyle, FALSE);
break;
- case 15:
+ case TOOL_ELLIPSE:
resetToU1();
if (GetAsyncKeyState(VK_SHIFT) < 0)
regularize(startX, startY, &x, &y);
Ellp(hdc, startX, startY, x, y, fg, bg, lineWidth, shapeStyle);
break;
- case 16:
+ case TOOL_RRECT:
resetToU1();
if (GetAsyncKeyState(VK_SHIFT) < 0)
regularize(startX, startY, &x, &y);
{
switch (activeTool)
{
- case 1:
+ case TOOL_FREESEL:
{
POINT *ptStackCopy;
int i;
ptStack = NULL;
break;
}
- case 2:
+ case TOOL_RECTSEL:
resetToU1();
if ((rectSel_src[2] != 0) && (rectSel_src[3] != 0))
{
ShowWindow(hSelection, SW_SHOW);
}
break;
- case 3:
+ case TOOL_RUBBER:
Erase(hdc, lastX, lastY, x, y, bg, rubberRadius);
break;
- case 7:
+ case TOOL_PEN:
Line(hdc, lastX, lastY, x, y, fg, 1);
SetPixel(hdc, x, y, fg);
break;
- case 11:
+ case TOOL_LINE:
resetToU1();
if (GetAsyncKeyState(VK_SHIFT) < 0)
roundTo8Directions(startX, startY, &x, &y);
Line(hdc, startX, startY, x, y, fg, lineWidth);
break;
- case 12:
+ case TOOL_BEZIER:
pointSP++;
if (pointSP == 4)
pointSP = 0;
break;
- case 13:
+ case TOOL_RECT:
resetToU1();
if (GetAsyncKeyState(VK_SHIFT) < 0)
regularize(startX, startY, &x, &y);
Rect(hdc, startX, startY, x, y, fg, bg, lineWidth, shapeStyle);
break;
- case 14:
+ case TOOL_SHAPE:
resetToU1();
pointStack[pointSP].x = x;
pointStack[pointSP].y = y;
if (pointSP == 255)
pointSP--;
break;
- case 15:
+ case TOOL_ELLIPSE:
resetToU1();
if (GetAsyncKeyState(VK_SHIFT) < 0)
regularize(startX, startY, &x, &y);
Ellp(hdc, startX, startY, x, y, fg, bg, lineWidth, shapeStyle);
break;
- case 16:
+ case TOOL_RRECT:
resetToU1();
if (GetAsyncKeyState(VK_SHIFT) < 0)
regularize(startX, startY, &x, &y);
lastY = y;
switch (activeTool)
{
- case 1:
- case 10:
- case 11:
- case 13:
- case 15:
- case 16:
+ case TOOL_FREESEL:
+ case TOOL_TEXT:
+ case TOOL_LINE:
+ case TOOL_RECT:
+ case TOOL_ELLIPSE:
+ case TOOL_RRECT:
newReversible();
break;
- case 3:
+ case TOOL_RUBBER:
newReversible();
Replace(hdc, x, y, x, y, fg, bg, rubberRadius);
break;
- case 4:
+ case TOOL_FILL:
newReversible();
Fill(hdc, x, y, bg);
break;
- case 7:
+ case TOOL_PEN:
newReversible();
SetPixel(hdc, x, y, bg);
break;
- case 8:
+ case TOOL_BRUSH:
newReversible();
Brush(hdc, x, y, x, y, bg, brushStyle);
break;
- case 9:
+ case TOOL_AIRBRUSH:
newReversible();
Airbrush(hdc, x, y, bg, airBrushWidth);
break;
- case 12:
+ case TOOL_BEZIER:
pointStack[pointSP].x = x;
pointStack[pointSP].y = y;
if (pointSP == 0)
pointSP++;
}
break;
- case 14:
+ case TOOL_SHAPE:
pointStack[pointSP].x = x;
pointStack[pointSP].y = y;
if (pointSP + 1 >= 2)
{
switch (activeTool)
{
- case 3:
+ case TOOL_RUBBER:
Replace(hdc, lastX, lastY, x, y, fg, bg, rubberRadius);
break;
- case 7:
+ case TOOL_PEN:
Line(hdc, lastX, lastY, x, y, bg, 1);
break;
- case 8:
+ case TOOL_BRUSH:
Brush(hdc, lastX, lastY, x, y, bg, brushStyle);
break;
- case 9:
+ case TOOL_AIRBRUSH:
Airbrush(hdc, x, y, bg, airBrushWidth);
break;
- case 11:
+ case TOOL_LINE:
resetToU1();
if (GetAsyncKeyState(VK_SHIFT) < 0)
roundTo8Directions(startX, startY, &x, &y);
Line(hdc, startX, startY, x, y, bg, lineWidth);
break;
- case 12:
+ case TOOL_BEZIER:
resetToU1();
pointStack[pointSP].x = x;
pointStack[pointSP].y = y;
break;
}
break;
- case 13:
+ case TOOL_RECT:
resetToU1();
if (GetAsyncKeyState(VK_SHIFT) < 0)
regularize(startX, startY, &x, &y);
Rect(hdc, startX, startY, x, y, bg, fg, lineWidth, shapeStyle);
break;
- case 14:
+ case TOOL_SHAPE:
resetToU1();
pointStack[pointSP].x = x;
pointStack[pointSP].y = y;
if (pointSP + 1 >= 2)
Poly(hdc, pointStack, pointSP + 1, bg, fg, lineWidth, shapeStyle, FALSE);
break;
- case 15:
+ case TOOL_ELLIPSE:
resetToU1();
if (GetAsyncKeyState(VK_SHIFT) < 0)
regularize(startX, startY, &x, &y);
Ellp(hdc, startX, startY, x, y, bg, fg, lineWidth, shapeStyle);
break;
- case 16:
+ case TOOL_RRECT:
resetToU1();
if (GetAsyncKeyState(VK_SHIFT) < 0)
regularize(startX, startY, &x, &y);
{
switch (activeTool)
{
- case 3:
+ case TOOL_RUBBER:
Replace(hdc, lastX, lastY, x, y, fg, bg, rubberRadius);
break;
- case 7:
+ case TOOL_PEN:
Line(hdc, lastX, lastY, x, y, bg, 1);
SetPixel(hdc, x, y, bg);
break;
- case 11:
+ case TOOL_LINE:
resetToU1();
if (GetAsyncKeyState(VK_SHIFT) < 0)
roundTo8Directions(startX, startY, &x, &y);
Line(hdc, startX, startY, x, y, bg, lineWidth);
break;
- case 12:
+ case TOOL_BEZIER:
pointSP++;
if (pointSP == 4)
pointSP = 0;
break;
- case 13:
+ case TOOL_RECT:
resetToU1();
if (GetAsyncKeyState(VK_SHIFT) < 0)
regularize(startX, startY, &x, &y);
Rect(hdc, startX, startY, x, y, bg, fg, lineWidth, shapeStyle);
break;
- case 14:
+ case TOOL_SHAPE:
resetToU1();
pointStack[pointSP].x = x;
pointStack[pointSP].y = y;
if (pointSP == 255)
pointSP--;
break;
- case 15:
+ case TOOL_ELLIPSE:
resetToU1();
if (GetAsyncKeyState(VK_SHIFT) < 0)
regularize(startX, startY, &x, &y);
Ellp(hdc, startX, startY, x, y, bg, fg, lineWidth, shapeStyle);
break;
- case 16:
+ case TOOL_RRECT:
resetToU1();
if (GetAsyncKeyState(VK_SHIFT) < 0)
regularize(startX, startY, &x, &y);
DefWindowProc(hwnd, message, wParam, lParam);
- DrawEdge(hdc, &rect1, BDR_SUNKENOUTER, (activeTool == 6) ? BF_RECT : BF_RECT | BF_MIDDLE);
- DrawEdge(hdc, &rect2, (activeTool >= 13) ? BDR_SUNKENOUTER : 0, BF_RECT | BF_MIDDLE);
+ DrawEdge(hdc, &rect1, BDR_SUNKENOUTER, (activeTool == TOOL_ZOOM) ? BF_RECT : BF_RECT | BF_MIDDLE);
+ DrawEdge(hdc, &rect2, (activeTool >= TOOL_RECT) ? BDR_SUNKENOUTER : 0, BF_RECT | BF_MIDDLE);
switch (activeTool)
{
- case 1:
- case 2:
- case 10:
+ case TOOL_FREESEL:
+ case TOOL_RECTSEL:
+ case TOOL_TEXT:
{
HPEN oldPen = SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT));
DrawIconEx(hdc, 1, 33, hTranspIcon, 40, 30, 0, NULL, DI_NORMAL);
break;
}
- case 3:
+ case TOOL_RUBBER:
{
int i;
HPEN oldPen = SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
DeleteObject(SelectObject(hdc, oldPen));
break;
}
- case 8:
+ case TOOL_BRUSH:
{
int i;
HPEN oldPen = SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
GetSysColor((i == brushStyle) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT), i);
break;
}
- case 9:
+ case TOOL_AIRBRUSH:
{
HPEN oldPen = SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT));
DeleteObject(SelectObject(hdc, oldPen));
break;
}
- case 11:
- case 12:
+ case TOOL_LINE:
+ case TOOL_BEZIER:
{
int i;
HPEN oldPen = SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
DeleteObject(SelectObject(hdc, oldPen));
break;
}
- case 13:
- case 14:
- case 15:
- case 16:
+ case TOOL_RECT:
+ case TOOL_SHAPE:
+ case TOOL_ELLIPSE:
+ case TOOL_RRECT:
{
int i;
HPEN oldPen = SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
{
switch (activeTool)
{
- case 1:
- case 2:
- case 10:
+ case TOOL_FREESEL:
+ case TOOL_RECTSEL:
+ case TOOL_TEXT:
if ((HIWORD(lParam) > 1) && (HIWORD(lParam) < 64))
{
transpBg = (HIWORD(lParam) - 2) / 31;
SendMessage(hwnd, WM_PAINT, 0, 0);
}
break;
- case 3:
+ case TOOL_RUBBER:
if ((HIWORD(lParam) > 1) && (HIWORD(lParam) < 62))
{
rubberRadius = (HIWORD(lParam) - 2) / 15 + 2;
SendMessage(hwnd, WM_PAINT, 0, 0);
}
break;
- case 8:
+ case TOOL_BRUSH:
if ((LOWORD(lParam) > 1) && (LOWORD(lParam) < 40) && (HIWORD(lParam) > 1)
&& (HIWORD(lParam) < 62))
{
SendMessage(hwnd, WM_PAINT, 0, 0);
}
break;
- case 9:
+ case TOOL_AIRBRUSH:
if (HIWORD(lParam) < 62)
{
if (HIWORD(lParam) < 30)
SendMessage(hwnd, WM_PAINT, 0, 0);
}
break;
- case 11:
- case 12:
+ case TOOL_LINE:
+ case TOOL_BEZIER:
if (HIWORD(lParam) <= 62)
{
lineWidth = (HIWORD(lParam) - 2) / 12 + 1;
SendMessage(hwnd, WM_PAINT, 0, 0);
}
break;
- case 13:
- case 14:
- case 15:
- case 16:
+ case TOOL_RECT:
+ case TOOL_SHAPE:
+ case TOOL_ELLIPSE:
+ case TOOL_RRECT:
if (HIWORD(lParam) <= 60)
{
shapeStyle = (HIWORD(lParam) - 2) / 20;
{
switch (activeTool)
{
- case 4:
+ case TOOL_FILL:
SetCursor(hCurFill);
break;
- case 5:
+ case TOOL_COLOR:
SetCursor(hCurColor);
break;
- case 6:
+ case TOOL_ZOOM:
SetCursor(hCurZoom);
break;
- case 7:
+ case TOOL_PEN:
SetCursor(hCurPen);
break;
- case 9:
+ case TOOL_AIRBRUSH:
SetCursor(hCurAirbrush);
break;
default:
case WM_LBUTTONDOWN:
if (hwnd == hImageArea)
{
- if ((!drawing) || (activeTool == 5))
+ if ((!drawing) || (activeTool == TOOL_COLOR))
{
SetCapture(hImageArea);
drawing = TRUE;
undo();
}
SendMessage(hImageArea, WM_PAINT, 0, 0);
- if ((activeTool == 6) && (zoom < 8000))
+ if ((activeTool == TOOL_ZOOM) && (zoom < 8000))
zoomTo(zoom * 2, (short)LOWORD(lParam), (short)HIWORD(lParam));
}
break;
case WM_RBUTTONDOWN:
if (hwnd == hImageArea)
{
- if ((!drawing) || (activeTool == 5))
+ if ((!drawing) || (activeTool == TOOL_COLOR))
{
SetCapture(hImageArea);
drawing = TRUE;
undo();
}
SendMessage(hImageArea, WM_PAINT, 0, 0);
- if ((activeTool == 6) && (zoom > 125))
+ if ((activeTool == TOOL_ZOOM) && (zoom > 125))
zoomTo(zoom / 2, (short)LOWORD(lParam), (short)HIWORD(lParam));
}
break;
endPaintingL(hDrawingDC, LOWORD(lParam) * 1000 / zoom, HIWORD(lParam) * 1000 / zoom, fgColor,
bgColor);
SendMessage(hImageArea, WM_PAINT, 0, 0);
- if (activeTool == 5)
+ if (activeTool == TOOL_COLOR)
{
int tempColor =
GetPixel(hDrawingDC, LOWORD(lParam) * 1000 / zoom, HIWORD(lParam) * 1000 / zoom);
endPaintingR(hDrawingDC, LOWORD(lParam) * 1000 / zoom, HIWORD(lParam) * 1000 / zoom, fgColor,
bgColor);
SendMessage(hImageArea, WM_PAINT, 0, 0);
- if (activeTool == 5)
+ if (activeTool == TOOL_COLOR)
{
int tempColor =
GetPixel(hDrawingDC, LOWORD(lParam) * 1000 / zoom, HIWORD(lParam) * 1000 / zoom);
case WM_MOUSEMOVE:
if (hwnd == hImageArea)
{
- if ((!drawing) || (activeTool <= 9))
+ short xNow = (short)LOWORD(lParam) * 1000 / zoom;
+ short yNow = (short)HIWORD(lParam) * 1000 / zoom;
+ if ((!drawing) || (activeTool <= TOOL_AIRBRUSH))
{
TRACKMOUSEEVENT tme;
- TCHAR coordStr[100];
- _stprintf(coordStr, _T("%d, %d"), (short)LOWORD(lParam) * 1000 / zoom,
- (short)HIWORD(lParam) * 1000 / zoom);
- SendMessage(hStatusBar, SB_SETTEXT, 1, (LPARAM) coordStr);
-
- if (activeTool == 6)
+ if (activeTool == TOOL_ZOOM)
{
SendMessage(hImageArea, WM_PAINT, 0, 0);
drawZoomFrame((short)LOWORD(lParam), (short)HIWORD(lParam));
tme.hwndTrack = hImageArea;
tme.dwHoverTime = 0;
TrackMouseEvent(&tme);
+
+ if (!drawing)
+ {
+ TCHAR coordStr[100];
+ _stprintf(coordStr, _T("%d, %d"), xNow, yNow);
+ SendMessage(hStatusBar, SB_SETTEXT, 1, (LPARAM) coordStr);
+ }
}
if (drawing)
{
+ /* values displayed in statusbar */
+ short xRel = xNow - startX;
+ short yRel = yNow - startY;
+ /* freesel, rectsel and text tools always show numbers limited to fit into image area */
+ if ((activeTool == TOOL_FREESEL) || (activeTool == TOOL_RECTSEL) || (activeTool == TOOL_TEXT))
+ {
+ if (xRel < 0)
+ xRel = (xNow < 0) ? -startX : xRel;
+ else if (xNow > imgXRes)
+ xRel = imgXRes-startX;
+ if (yRel < 0)
+ yRel = (yNow < 0) ? -startY : yRel;
+ else if (yNow > imgYRes)
+ yRel = imgYRes-startY;
+ }
+ /* rectsel and shape tools always show non-negative numbers when drawing */
+ if ((activeTool == TOOL_RECTSEL) || (activeTool == TOOL_SHAPE))
+ {
+ if (xRel < 0)
+ xRel = -xRel;
+ if (yRel < 0)
+ yRel = -yRel;
+ }
+ /* while drawing, update cursor coordinates only for tools 3, 7, 8, 9, 14 */
+ switch(activeTool)
+ {
+ case TOOL_RUBBER:
+ case TOOL_PEN:
+ case TOOL_BRUSH:
+ case TOOL_AIRBRUSH:
+ case TOOL_SHAPE:
+ {
+ TCHAR coordStr[100];
+ _stprintf(coordStr, _T("%d, %d"), xNow, yNow);
+ SendMessage(hStatusBar, SB_SETTEXT, 1, (LPARAM) coordStr);
+ break;
+ }
+ }
if ((wParam & MK_LBUTTON) != 0)
{
- whilePaintingL(hDrawingDC, (short)LOWORD(lParam) * 1000 / zoom,
- (short)HIWORD(lParam) * 1000 / zoom, fgColor, bgColor);
+ whilePaintingL(hDrawingDC, xNow, yNow, fgColor, bgColor);
SendMessage(hImageArea, WM_PAINT, 0, 0);
- if ((activeTool >= 10) || (activeTool == 2))
+ if ((activeTool >= TOOL_TEXT) || (activeTool == TOOL_RECTSEL) || (activeTool == TOOL_FREESEL))
{
TCHAR sizeStr[100];
- _stprintf(sizeStr, _T("%d x %d"), (short)LOWORD(lParam) * 1000 / zoom - startX,
- (short)HIWORD(lParam) * 1000 / zoom - startY);
+ _stprintf(sizeStr, _T("%d x %d"), xRel, yRel);
SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) sizeStr);
}
}
if ((wParam & MK_RBUTTON) != 0)
{
- whilePaintingR(hDrawingDC, (short)LOWORD(lParam) * 1000 / zoom,
- (short)HIWORD(lParam) * 1000 / zoom, fgColor, bgColor);
+ whilePaintingR(hDrawingDC, xNow, yNow, fgColor, bgColor);
SendMessage(hImageArea, WM_PAINT, 0, 0);
- if (activeTool >= 10)
+ if (activeTool >= TOOL_TEXT)
{
TCHAR sizeStr[100];
- _stprintf(sizeStr, _T("%d x %d"), (short)LOWORD(lParam) * 1000 / zoom - startX,
- (short)HIWORD(lParam) * 1000 / zoom - startY);
+ _stprintf(sizeStr, _T("%d x %d"), xRel, yRel);
SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) sizeStr);
}
}
case WM_MOUSELEAVE:
SendMessage(hStatusBar, SB_SETTEXT, 1, (LPARAM) _T(""));
- if (activeTool == 6)
+ if (activeTool == TOOL_ZOOM)
SendMessage(hImageArea, WM_PAINT, 0, 0);
break;
/* remove selection window and already painted content using undo(),
paint Rect for rectangular selections and nothing for freeform selections */
undo();
- if (activeTool == 2)
+ if (activeTool == TOOL_RECTSEL)
{
newReversible();
Rect(hDrawingDC, rectSel_dest[0], rectSel_dest[1], rectSel_dest[2] + rectSel_dest[0],
break;
}
case IDM_EDITSELECTALL:
- if (activeTool == 2)
+ if (activeTool == TOOL_RECTSEL)
{
startPaintingL(hDrawingDC, 0, 0, fgColor, bgColor);
whilePaintingL(hDrawingDC, imgXRes, imgYRes, fgColor, bgColor);