/* FUNCTIONS ********************************************************/
-void
-selectTool(int tool)
+void CMainWindow::selectTool(int tool)
{
selectionWindow.ShowWindow(SW_HIDE);
activeTool = tool;
pointSP = 0; // resets the point-buffer of the polygon and bezier functions
toolSettingsWindow.Invalidate(TRUE);
- ShowWindow(hTrackbarZoom, (tool == TOOL_ZOOM) ? SW_SHOW : SW_HIDE);
+ ::ShowWindow(hTrackbarZoom, (tool == TOOL_ZOOM) ? SW_SHOW : SW_HIDE);
textEditWindow.ShowWindow((tool == TOOL_TEXT) ? SW_SHOW : SW_HIDE);
}
SendMessage(hTrackbarZoom, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) tbPos);
}
-void
-drawZoomFrame(int mouseX, int mouseY)
-{
- HDC hdc;
- HPEN oldPen;
- HBRUSH oldBrush;
- LOGBRUSH logbrush;
- int rop;
-
- RECT clientRectScrollbox;
- RECT clientRectImageArea;
- int x, y, w, h;
- scrollboxWindow.GetClientRect(&clientRectScrollbox);
- imageArea.GetClientRect(&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 = imageArea.GetDC();
- oldPen = (HPEN) SelectObject(hdc, CreatePen(PS_SOLID, 0, 0));
- logbrush.lbStyle = BS_HOLLOW;
- oldBrush = (HBRUSH) SelectObject(hdc, CreateBrushIndirect(&logbrush));
- rop = SetROP2(hdc, R2_NOT);
- Rectangle(hdc, x, y, x + w, y + h);
- SetROP2(hdc, rop);
- DeleteObject(SelectObject(hdc, oldBrush));
- DeleteObject(SelectObject(hdc, oldPen));
- imageArea.ReleaseDC(hdc);
-}
-
-void
-alignChildrenToMainWindow()
+void CMainWindow::alignChildrenToMainWindow()
{
int x, y, w, h;
RECT clientRect;
h = clientRect.bottom - 3;
}
- scrollboxWindow.MoveWindow(x, y, w, IsWindowVisible(hStatusBar) ? h - 23 : h, TRUE);
+ scrollboxWindow.MoveWindow(x, y, w, ::IsWindowVisible(hStatusBar) ? h - 23 : h, TRUE);
paletteWindow.MoveWindow(x, 9, 255, 32, TRUE);
}
-void
-saveImage(BOOL overwrite)
+void CMainWindow::saveImage(BOOL overwrite)
{
if (isAFile && overwrite)
{
}
}
-void
-UpdateApplicationProperties(HBITMAP bitmap, LPTSTR newfilename, LPTSTR newfilepathname)
+void CMainWindow::UpdateApplicationProperties(HBITMAP bitmap, LPTSTR newfilename, LPTSTR newfilepathname)
{
TCHAR tempstr[1000];
TCHAR resstr[100];
CopyMemory(filepathname, newfilepathname, sizeof(filepathname));
LoadString(hProgInstance, IDS_WINDOWTITLE, resstr, SIZEOF(resstr));
_stprintf(tempstr, resstr, filename);
- mainWindow.SetWindowText(tempstr);
+ SetWindowText(tempstr);
clearHistory();
isAFile = TRUE;
}
-void
-InsertSelectionFromHBITMAP(HBITMAP bitmap, HWND window)
+void CMainWindow::InsertSelectionFromHBITMAP(HBITMAP bitmap, HWND window)
{
HDC hTempDC;
HBITMAP hTempMask;
ForceRefreshSelectionContents();
}
-BOOL drawing;
-
LRESULT CMainWindow::OnDropFiles(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
HDROP drophandle;
LRESULT CMainWindow::OnClose(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
- if (m_hWnd == miniature.m_hWnd)
- {
- miniature.ShowWindow(SW_HIDE);
- showMiniature = FALSE;
- return 0;
- }
if (!imageSaved)
{
TCHAR programname[20];
alignChildrenToMainWindow();
Invalidate(TRUE);
}
- if (m_hWnd == imageArea.m_hWnd)
- {
- sizeboxLeftTop.MoveWindow(
- 0,
- 0, 3, 3, TRUE);
- sizeboxCenterTop.MoveWindow(
- imgXRes * zoom / 2000 + 3 * 3 / 4,
- 0, 3, 3, TRUE);
- sizeboxRightTop.MoveWindow(
- imgXRes * zoom / 1000 + 3,
- 0, 3, 3, TRUE);
- sizeboxLeftCenter.MoveWindow(
- 0,
- imgYRes * zoom / 2000 + 3 * 3 / 4, 3, 3, TRUE);
- sizeboxRightCenter.MoveWindow(
- imgXRes * zoom / 1000 + 3,
- imgYRes * zoom / 2000 + 3 * 3 / 4, 3, 3, TRUE);
- sizeboxLeftBottom.MoveWindow(
- 0,
- imgYRes * zoom / 1000 + 3, 3, 3, TRUE);
- sizeboxCenterBottom.MoveWindow(
- imgXRes * zoom / 2000 + 3 * 3 / 4,
- imgYRes * zoom / 1000 + 3, 3, 3, TRUE);
- sizeboxRightBottom.MoveWindow(
- imgXRes * zoom / 1000 + 3,
- imgYRes * zoom / 1000 + 3, 3, 3, TRUE);
- }
- if (m_hWnd == imageArea.m_hWnd)
- {
- UpdateScrollbox();
- }
return 0;
}
return 0;
}
-LRESULT CMainWindow::OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
-{
- DefWindowProc(WM_PAINT, wParam, lParam);
- if (m_hWnd == imageArea.m_hWnd)
- {
- HDC hdc = imageArea.GetDC();
- StretchBlt(hdc, 0, 0, imgXRes * zoom / 1000, imgYRes * zoom / 1000, hDrawingDC, 0, 0, imgXRes,
- imgYRes, SRCCOPY);
- if (showGrid && (zoom >= 4000))
- {
- HPEN oldPen = (HPEN) SelectObject(hdc, CreatePen(PS_SOLID, 1, 0x00a0a0a0));
- int counter;
- for(counter = 0; counter <= imgYRes; counter++)
- {
- MoveToEx(hdc, 0, counter * zoom / 1000, NULL);
- LineTo(hdc, imgXRes * zoom / 1000, counter * zoom / 1000);
- }
- for(counter = 0; counter <= imgXRes; counter++)
- {
- MoveToEx(hdc, counter * zoom / 1000, 0, NULL);
- LineTo(hdc, counter * zoom / 1000, imgYRes * zoom / 1000);
- }
- DeleteObject(SelectObject(hdc, oldPen));
- }
- imageArea.ReleaseDC(hdc);
- selectionWindow.Invalidate(FALSE);
- miniature.Invalidate(FALSE);
- }
- else if (m_hWnd == miniature.m_hWnd)
- {
- RECT mclient;
- HDC hdc;
- miniature.GetClientRect(&mclient);
- hdc = miniature.GetDC();
- StretchBlt(hdc, 0, 0, mclient.right, mclient.bottom, hDrawingDC, 0, 0, imgXRes, imgYRes, SRCCOPY);
- miniature.ReleaseDC(hdc);
- }
- return 0;
-}
-
LRESULT CMainWindow::OnSetCursor(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
- if (m_hWnd == imageArea.m_hWnd)
- {
- switch (activeTool)
- {
- case TOOL_FILL:
- SetCursor(hCurFill);
- break;
- case TOOL_COLOR:
- SetCursor(hCurColor);
- break;
- case TOOL_ZOOM:
- SetCursor(hCurZoom);
- break;
- case TOOL_PEN:
- SetCursor(hCurPen);
- break;
- case TOOL_AIRBRUSH:
- SetCursor(hCurAirbrush);
- break;
- default:
- SetCursor(LoadCursor(NULL, IDC_CROSS));
- }
- }
- else
- SetCursor(LoadCursor(NULL, IDC_ARROW));
- return 0;
-}
-
-LRESULT CMainWindow::OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
-{
- if (m_hWnd == imageArea.m_hWnd)
- {
- if ((!drawing) || (activeTool == TOOL_COLOR))
- {
- SetCapture();
- drawing = TRUE;
- startPaintingL(hDrawingDC, GET_X_LPARAM(lParam) * 1000 / zoom, GET_Y_LPARAM(lParam) * 1000 / zoom,
- fgColor, bgColor);
- }
- else
- {
- SendMessage(WM_LBUTTONUP, wParam, lParam);
- undo();
- }
- Invalidate(FALSE);
- if ((activeTool == TOOL_ZOOM) && (zoom < 8000))
- zoomTo(zoom * 2, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
- }
- return 0;
-}
-
-LRESULT CMainWindow::OnRButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
-{
- if (m_hWnd == imageArea.m_hWnd)
- {
- if ((!drawing) || (activeTool == TOOL_COLOR))
- {
- SetCapture();
- drawing = TRUE;
- startPaintingR(hDrawingDC, GET_X_LPARAM(lParam) * 1000 / zoom, GET_Y_LPARAM(lParam) * 1000 / zoom,
- fgColor, bgColor);
- }
- else
- {
- SendMessage(WM_RBUTTONUP, wParam, lParam);
- undo();
- }
- Invalidate(FALSE);
- if ((activeTool == TOOL_ZOOM) && (zoom > 125))
- zoomTo(zoom / 2, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
- }
- return 0;
-}
-
-LRESULT CMainWindow::OnLButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
-{
- if ((m_hWnd == imageArea.m_hWnd) && drawing)
- {
- ReleaseCapture();
- drawing = FALSE;
- endPaintingL(hDrawingDC, GET_X_LPARAM(lParam) * 1000 / zoom, GET_Y_LPARAM(lParam) * 1000 / zoom, fgColor,
- bgColor);
- Invalidate(FALSE);
- if (activeTool == TOOL_COLOR)
- {
- COLORREF tempColor =
- GetPixel(hDrawingDC, GET_X_LPARAM(lParam) * 1000 / zoom, GET_Y_LPARAM(lParam) * 1000 / zoom);
- if (tempColor != CLR_INVALID)
- fgColor = tempColor;
- paletteWindow.Invalidate(FALSE);
- }
- SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) "");
- }
- return 0;
-}
-
-LRESULT CMainWindow::OnRButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
-{
- if ((m_hWnd == imageArea.m_hWnd) && drawing)
- {
- ReleaseCapture();
- drawing = FALSE;
- endPaintingR(hDrawingDC, GET_X_LPARAM(lParam) * 1000 / zoom, GET_Y_LPARAM(lParam) * 1000 / zoom, fgColor,
- bgColor);
- Invalidate(FALSE);
- if (activeTool == TOOL_COLOR)
- {
- COLORREF tempColor =
- GetPixel(hDrawingDC, GET_X_LPARAM(lParam) * 1000 / zoom, GET_Y_LPARAM(lParam) * 1000 / zoom);
- if (tempColor != CLR_INVALID)
- bgColor = tempColor;
- paletteWindow.Invalidate(FALSE);
- }
- SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) "");
- }
+ SetCursor(LoadCursor(NULL, IDC_ARROW));
return 0;
}
{
if (wParam == VK_ESCAPE)
{
- if (!drawing)
+ if (!imageArea.drawing)
{
/* Deselect */
if ((activeTool == TOOL_RECTSEL) || (activeTool == TOOL_FREESEL))
return 0;
}
-LRESULT CMainWindow::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
-{
- if (m_hWnd == imageArea.m_hWnd)
- {
- LONG xNow = GET_X_LPARAM(lParam) * 1000 / zoom;
- LONG yNow = GET_Y_LPARAM(lParam) * 1000 / zoom;
- if ((!drawing) || (activeTool <= TOOL_AIRBRUSH))
- {
- TRACKMOUSEEVENT tme;
-
- if (activeTool == TOOL_ZOOM)
- {
- Invalidate(FALSE);
- UpdateWindow();
- drawZoomFrame(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
- }
-
- tme.cbSize = sizeof(TRACKMOUSEEVENT);
- tme.dwFlags = TME_LEAVE;
- tme.hwndTrack = imageArea.m_hWnd;
- tme.dwHoverTime = 0;
- TrackMouseEvent(&tme);
-
- if (!drawing)
- {
- TCHAR coordStr[100];
- _stprintf(coordStr, _T("%ld, %ld"), xNow, yNow);
- SendMessage(hStatusBar, SB_SETTEXT, 1, (LPARAM) coordStr);
- }
- }
- if (drawing)
- {
- /* values displayed in statusbar */
- LONG xRel = xNow - start.x;
- LONG yRel = yNow - start.y;
- /* 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) ? -start.x : xRel;
- else if (xNow > imgXRes)
- xRel = imgXRes-start.x;
- if (yRel < 0)
- yRel = (yNow < 0) ? -start.y : yRel;
- else if (yNow > imgYRes)
- yRel = imgYRes-start.y;
- }
- /* 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("%ld, %ld"), xNow, yNow);
- SendMessage(hStatusBar, SB_SETTEXT, 1, (LPARAM) coordStr);
- break;
- }
- }
- if ((wParam & MK_LBUTTON) != 0)
- {
- whilePaintingL(hDrawingDC, xNow, yNow, fgColor, bgColor);
- Invalidate(FALSE);
- if ((activeTool >= TOOL_TEXT) || (activeTool == TOOL_RECTSEL) || (activeTool == TOOL_FREESEL))
- {
- TCHAR sizeStr[100];
- if ((activeTool >= TOOL_LINE) && (GetAsyncKeyState(VK_SHIFT) < 0))
- yRel = xRel;
- _stprintf(sizeStr, _T("%ld x %ld"), xRel, yRel);
- SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) sizeStr);
- }
- }
- if ((wParam & MK_RBUTTON) != 0)
- {
- whilePaintingR(hDrawingDC, xNow, yNow, fgColor, bgColor);
- Invalidate(FALSE);
- if (activeTool >= TOOL_TEXT)
- {
- TCHAR sizeStr[100];
- if ((activeTool >= TOOL_LINE) && (GetAsyncKeyState(VK_SHIFT) < 0))
- yRel = xRel;
- _stprintf(sizeStr, _T("%ld x %ld"), xRel, yRel);
- SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) sizeStr);
- }
- }
- }
- }
- return 0;
-}
-
-LRESULT CMainWindow::OnMouseLeave(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
-{
- SendMessage(hStatusBar, SB_SETTEXT, 1, (LPARAM) _T(""));
- if (activeTool == TOOL_ZOOM)
- imageArea.Invalidate(FALSE);
- return 0;
-}
-
LRESULT CMainWindow::OnSysColorChange(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
/* Redirect message to common controls */