Exemple #1
0
LRESULT CALLBACK
TextEditWinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
        case WM_SIZE:
        {
            RECT clientRect;
            GetClientRect(hwnd, &clientRect);
            MoveWindow(hwndEditCtl, clientRect.left, clientRect.top, RECT_WIDTH(clientRect), RECT_HEIGHT(clientRect), TRUE);
            break;
        }
        case WM_CLOSE:
            ShowWindow(hwnd, SW_HIDE);
            break;
        case WM_COMMAND:
            switch(HIWORD(wParam))
            {
                case EN_UPDATE:
                {
                    HeapFree(GetProcessHeap(), 0, textToolText);
                    textToolTextMaxLen = GetWindowTextLength(hwndEditCtl) + 1;
                    textToolText = HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, sizeof(TCHAR) * textToolTextMaxLen);
                    GetWindowText(hwndEditCtl, textToolText, textToolTextMaxLen);
                    ForceRefreshSelectionContents();
                    break;
                }
            }
            break;
        default:
            return DefWindowProc(hwnd, message, wParam, lParam);
    }
    
    return 0;
}
Exemple #2
0
void CMainWindow::InsertSelectionFromHBITMAP(HBITMAP bitmap, HWND window)
{
    int width = GetDIBWidth(bitmap); 
    int height = GetDIBHeight(bitmap); 
    int curWidth = imageModel.GetWidth();
    int curHeight = imageModel.GetHeight();

    if (width > curWidth || height > curHeight)
    {
        BOOL shouldEnlarge = TRUE;

        if (askBeforeEnlarging)
        {
            TCHAR programname[20];
            TCHAR shouldEnlargePromptText[100];

            LoadString(hProgInstance, IDS_PROGRAMNAME, programname, SIZEOF(programname));
            LoadString(hProgInstance, IDS_ENLARGEPROMPTTEXT, shouldEnlargePromptText, SIZEOF(shouldEnlargePromptText));

            switch (MessageBox(shouldEnlargePromptText, programname, MB_YESNOCANCEL | MB_ICONQUESTION))
            {
                case IDYES:
                    break;
                case IDNO:
                    shouldEnlarge = FALSE;
                    break;
                case IDCANCEL:
                    return; 
            }
        }

        if (shouldEnlarge)
        {
            if (width > curWidth)
                curWidth = width;

            if (height > curHeight)
                curHeight = height;

            imageModel.Crop(curWidth, curHeight, 0, 0);
        }
    }

    HWND hToolbar = FindWindowEx(toolBoxContainer.m_hWnd, NULL, TOOLBARCLASSNAME, NULL);
    SendMessage(hToolbar, TB_CHECKBUTTON, ID_RECTSEL, MAKELPARAM(TRUE, 0));
    toolBoxContainer.SendMessage(WM_COMMAND, ID_RECTSEL);

    imageModel.CopyPrevious();
    selectionModel.InsertFromHBITMAP(bitmap);

    placeSelWin();
    selectionWindow.ShowWindow(SW_SHOW);
    ForceRefreshSelectionContents();
}
Exemple #3
0
void
endPaintingL(HDC hdc, LONG x, LONG y, COLORREF fg, COLORREF bg)
{
    switch (activeTool)
    {
        case TOOL_FREESEL:
        {
            POINT *ptStackCopy;
            int i;
            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.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(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.left;
                    ptStackCopy[i].y = ptStack[i].y - rectSel_src.top;
                }
                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, FALSE);
                newReversible();

                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();
                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);
            }
            HeapFree(GetProcessHeap(), 0, ptStack);
            ptStack = NULL;
            break;
        }
        case TOOL_RECTSEL:
            resetToU1();
            if ((RECT_WIDTH(rectSel_src) != 0) && (RECT_HEIGHT(rectSel_src) != 0))
            {
                DeleteObject(hSelMask);
                hSelMask = CreateBitmap(RECT_WIDTH(rectSel_src), RECT_HEIGHT(rectSel_src), 1, 1, NULL);
                DeleteObject(SelectObject(hSelDC, hSelMask));
                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, 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);
                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:
            Erase(hdc, last.x, last.y, x, y, bg, rubberRadius);
            break;
        case TOOL_PEN:
            Line(hdc, last.x, last.y, x, y, fg, 1);
            SetPixel(hdc, x, y, fg);
            break;
        case TOOL_LINE:
            resetToU1();
            if (GetAsyncKeyState(VK_SHIFT) < 0)
                roundTo8Directions(start.x, start.y, &x, &y);
            Line(hdc, start.x, start.y, x, y, fg, lineWidth);
            break;
        case TOOL_BEZIER:
            pointSP++;
            if (pointSP == 4)
                pointSP = 0;
            break;
        case TOOL_RECT:
            resetToU1();
            if (GetAsyncKeyState(VK_SHIFT) < 0)
                regularize(start.x, start.y, &x, &y);
            Rect(hdc, start.x, start.y, x, y, fg, bg, lineWidth, shapeStyle);
            break;
        case TOOL_SHAPE:
            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,
                                   &pointStack[pointSP].x, &pointStack[pointSP].y);
            pointSP++;
            if (pointSP >= 2)
            {
                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, FALSE);
                    pointSP = 0;
                }
                else
                {
                    Poly(hdc, pointStack, pointSP, fg, bg, lineWidth, shapeStyle, FALSE, FALSE);
                }
            }
            if (pointSP == 255)
                pointSP--;
            break;
        case TOOL_ELLIPSE:
            resetToU1();
            if (GetAsyncKeyState(VK_SHIFT) < 0)
                regularize(start.x, start.y, &x, &y);
            Ellp(hdc, start.x, start.y, x, y, fg, bg, lineWidth, shapeStyle);
            break;
        case TOOL_RRECT:
            resetToU1();
            if (GetAsyncKeyState(VK_SHIFT) < 0)
                regularize(start.x, start.y, &x, &y);
            RRect(hdc, start.x, start.y, x, y, fg, bg, lineWidth, shapeStyle);
            break;
    }
}
Exemple #4
0
LRESULT CALLBACK
SettingsWinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
        case WM_VSCROLL:
            zoomTo(125 << SendMessage(hTrackbarZoom, TBM_GETPOS, 0, 0), 0, 0);
            break;
        case WM_PAINT:
        {
            HDC hdc = GetDC(hwnd);
            RECT rect1 = { 0, 0, 42, 66 };
            RECT rect2 = { 0, 70, 42, 136 };

            DefWindowProc(hwnd, message, wParam, lParam);

            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 TOOL_FREESEL:
                case TOOL_RECTSEL:
                case TOOL_TEXT:
                {
                    HPEN oldPen = SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
                    SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT));
                    Rectangle(hdc, 2, transpBg * 31 + 2, 41, transpBg * 31 + 33);
                    DeleteObject(SelectObject(hdc, oldPen));
                    DrawIconEx(hdc, 1, 2, hNontranspIcon, 40, 30, 0, NULL, DI_NORMAL);
                    DrawIconEx(hdc, 1, 33, hTranspIcon, 40, 30, 0, NULL, DI_NORMAL);
                    break;
                }
                case TOOL_RUBBER:
                {
                    int i;
                    HPEN oldPen = SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
                    for(i = 0; i < 4; i++)
                    {
                        if (rubberRadius == i + 2)
                        {
                            SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT));
                            Rectangle(hdc, 14, i * 15 + 2, 29, i * 15 + 17);
                            SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHTTEXT));
                        }
                        else
                            SelectObject(hdc, GetSysColorBrush(COLOR_WINDOWTEXT));
                        Rectangle(hdc, 19 - i, i * 14 + 7, 24 + i, i * 16 + 12);
                    }
                    DeleteObject(SelectObject(hdc, oldPen));
                    break;
                }
                case TOOL_BRUSH:
                {
                    int i;
                    HPEN oldPen = SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
                    SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT));
                    Rectangle(hdc, brushStyle % 3 * 13 + 2, brushStyle / 3 * 15 + 2, brushStyle % 3 * 13 + 15,
                              brushStyle / 3 * 15 + 17);
                    DeleteObject(SelectObject(hdc, oldPen));
                    for(i = 0; i < 12; i++)
                        Brush(hdc, i % 3 * 13 + 7, i / 3 * 15 + 8, i % 3 * 13 + 7, i / 3 * 15 + 8,
                              GetSysColor((i == brushStyle) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT), i);
                    break;
                }
                case TOOL_AIRBRUSH:
                {
                    HPEN oldPen = SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
                    SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT));
                    switch (airBrushWidth)
                    {
                        case 5:
                            Rectangle(hdc, 2, 2, 21, 31);
                            break;
                        case 8:
                            Rectangle(hdc, 20, 2, 41, 31);
                            break;
                        case 3:
                            Rectangle(hdc, 2, 30, 16, 61);
                            break;
                        case 12:
                            Rectangle(hdc, 15, 30, 41, 61);
                            break;
                    }
                    Airbrush(hdc, 10, 15,
                             GetSysColor((airBrushWidth == 5) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT), 5);
                    Airbrush(hdc, 30, 15,
                             GetSysColor((airBrushWidth == 8) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT), 8);
                    Airbrush(hdc, 8, 45,
                             GetSysColor((airBrushWidth == 3) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT), 3);
                    Airbrush(hdc, 27, 45,
                             GetSysColor((airBrushWidth == 12) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT), 12);
                    DeleteObject(SelectObject(hdc, oldPen));
                    break;
                }
                case TOOL_LINE:
                case TOOL_BEZIER:
                {
                    int i;
                    HPEN oldPen = SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
                    for(i = 0; i < 5; i++)
                    {
                        if (lineWidth == i + 1)
                        {
                            SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT));
                            Rectangle(hdc, 2, i * 12 + 2, 41, i * 12 + 14);
                            SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHTTEXT));
                        }
                        else
                            SelectObject(hdc, GetSysColorBrush(COLOR_WINDOWTEXT));
                        Rectangle(hdc, 5, i * 12 + 6, 38, i * 12 + 8 + i);
                    }
                    DeleteObject(SelectObject(hdc, oldPen));
                    break;
                }
                case TOOL_RECT:
                case TOOL_SHAPE:
                case TOOL_ELLIPSE:
                case TOOL_RRECT:
                {
                    int i;
                    HPEN oldPen = SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
                    for(i = 0; i < 3; i++)
                    {
                        if (shapeStyle == i)
                        {
                            SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT));
                            Rectangle(hdc, 2, i * 20 + 2, 41, i * 20 + 22);
                        }
                    }
                    Rect(hdc, 5, 6, 37, 16,
                         GetSysColor((shapeStyle == 0) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT),
                         GetSysColor(COLOR_APPWORKSPACE), 1, 0);
                    Rect(hdc, 5, 26, 37, 36,
                         GetSysColor((shapeStyle == 1) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT),
                         GetSysColor(COLOR_APPWORKSPACE), 1, 1);
                    Rect(hdc, 5, 46, 37, 56, GetSysColor(COLOR_APPWORKSPACE), GetSysColor(COLOR_APPWORKSPACE),
                         1, 1);
                    for(i = 0; i < 5; i++)
                    {
                        if (lineWidth == i + 1)
                        {
                            SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT));
                            Rectangle(hdc, 2, i * 12 + 72, 41, i * 12 + 84);
                            SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHTTEXT));
                        }
                        else
                            SelectObject(hdc, GetSysColorBrush(COLOR_WINDOWTEXT));
                        Rectangle(hdc, 5, i * 12 + 76, 38, i * 12 + 78 + i);
                    }
                    DeleteObject(SelectObject(hdc, oldPen));
                    break;
                }
            }
            ReleaseDC(hwnd, hdc);
            break;
        }
        case WM_LBUTTONDOWN:
        {
            int x = GET_X_LPARAM(lParam);
            int y = GET_Y_LPARAM(lParam);
            switch (activeTool)
            {
                case TOOL_FREESEL:
                case TOOL_RECTSEL:
                case TOOL_TEXT:
                    if ((y > 1) && (y < 64))
                    {
                        transpBg = (y - 2) / 31;
                        InvalidateRect(hwnd, NULL, TRUE);

                        ForceRefreshSelectionContents();
                    }
                    break;
                case TOOL_RUBBER:
                    if ((y > 1) && (y < 62))
                    {
                        rubberRadius = (y - 2) / 15 + 2;
                        InvalidateRect(hwnd, NULL, TRUE);
                    }
                    break;
                case TOOL_BRUSH:
                    if ((x > 1) && (x < 40) && (y > 1)
                        && (y < 62))
                    {
                        brushStyle = (y - 2) / 15 * 3 + (x - 2) / 13;
                        InvalidateRect(hwnd, NULL, TRUE);
                    }
                    break;
                case TOOL_AIRBRUSH:
                    if (y < 62)
                    {
                        if (y < 30)
                        {
                            if (x < 20)
                                airBrushWidth = 5;
                            else
                                airBrushWidth = 8;
                        }
                        else
                        {
                            if (x < 15)
                                airBrushWidth = 3;
                            else
                                airBrushWidth = 12;
                        }
                        InvalidateRect(hwnd, NULL, TRUE);
                    }
                    break;
                case TOOL_LINE:
                case TOOL_BEZIER:
                    if (y <= 62)
                    {
                        lineWidth = (y - 2) / 12 + 1;
                        InvalidateRect(hwnd, NULL, TRUE);
                    }
                    break;
                case TOOL_RECT:
                case TOOL_SHAPE:
                case TOOL_ELLIPSE:
                case TOOL_RRECT:
                    if (y <= 60)
                    {
                        shapeStyle = (y - 2) / 20;
                        InvalidateRect(hwnd, NULL, TRUE);
                    }
                    if ((y >= 70) && (y <= 132))
                    {
                        lineWidth = (y - 72) / 12 + 1;
                        InvalidateRect(hwnd, NULL, TRUE);
                    }
                    break;
            }
            break;
        }

        default:
            return DefWindowProc(hwnd, message, wParam, lParam);
    }

    return 0;
}