コード例 #1
0
ファイル: history.cpp プロジェクト: GYGit/reactos
void ImageModel::Crop(int nWidth, int nHeight, int nOffsetX, int nOffsetY)
{
    HDC hdc;
    HPEN oldPen;
    HBRUSH oldBrush;
    int oldWidth = GetWidth();
    int oldHeight = GetHeight();

    SelectObject(hDrawingDC, hBms[currInd]);
    DeleteObject(hBms[(currInd + 1) % HISTORYSIZE]);
    hBms[(currInd + 1) % HISTORYSIZE] = CreateDIBWithProperties(nWidth, nHeight);
    currInd = (currInd + 1) % HISTORYSIZE;
    if (undoSteps < HISTORYSIZE - 1)
        undoSteps++;
    redoSteps = 0;

    hdc = CreateCompatibleDC(hDrawingDC);
    SelectObject(hdc, hBms[currInd]);

    oldPen = (HPEN) SelectObject(hdc, CreatePen(PS_SOLID, 1, paletteModel.GetBgColor()));
    oldBrush = (HBRUSH) SelectObject(hdc, CreateSolidBrush(paletteModel.GetBgColor()));
    Rectangle(hdc, 0, 0, nWidth, nHeight);
    BitBlt(hdc, -nOffsetX, -nOffsetY, GetWidth(), GetHeight(), hDrawingDC, 0, 0, SRCCOPY);
    DeleteObject(SelectObject(hdc, oldBrush));
    DeleteObject(SelectObject(hdc, oldPen));
    DeleteDC(hdc);
    SelectObject(hDrawingDC, hBms[currInd]);

    if (GetWidth() != oldWidth || GetHeight() != oldHeight)
        NotifyDimensionsChanged();
    NotifyImageChanged();
}
コード例 #2
0
ファイル: history.c プロジェクト: hoangduit/reactos
void
cropReversible(int width, int height, int xOffset, int yOffset)
{
    HDC hdc;
    HPEN oldPen;
    HBRUSH oldBrush;

    SelectObject(hDrawingDC, hBms[currInd]);
    DeleteObject(hBms[(currInd + 1) % HISTORYSIZE]);
    hBms[(currInd + 1) % HISTORYSIZE] = CreateDIBWithProperties(width, height);
    currInd = (currInd + 1) % HISTORYSIZE;
    if (undoSteps < HISTORYSIZE - 1)
        undoSteps++;
    redoSteps = 0;

    hdc = CreateCompatibleDC(hDrawingDC);
    SelectObject(hdc, hBms[currInd]);

    oldPen = SelectObject(hdc, CreatePen(PS_SOLID, 1, bgColor));
    oldBrush = SelectObject(hdc, CreateSolidBrush(bgColor));
    Rectangle(hdc, 0, 0, width, height);
    BitBlt(hdc, -xOffset, -yOffset, imgXRes, imgYRes, hDrawingDC, 0, 0, SRCCOPY);
    DeleteObject(SelectObject(hdc, oldBrush));
    DeleteObject(SelectObject(hdc, oldPen));
    DeleteDC(hdc);
    SelectObject(hDrawingDC, hBms[currInd]);

    setImgXYRes(width, height);
}
コード例 #3
0
ファイル: history.cpp プロジェクト: GYGit/reactos
ImageModel::ImageModel()
{
    currInd = 0;
    undoSteps = 0;
    redoSteps = 0;
    imageSaved = TRUE;

    // prepare a minimal usable bitmap
    int imgXRes = 1;
    int imgYRes = 1;

    hDrawingDC = CreateCompatibleDC(NULL);
    SelectObject(hDrawingDC, CreatePen(PS_SOLID, 0, paletteModel.GetFgColor()));
    SelectObject(hDrawingDC, CreateSolidBrush(paletteModel.GetBgColor()));

    hBms[0] = CreateDIBWithProperties(imgXRes, imgYRes);
    SelectObject(hDrawingDC, hBms[0]);
    Rectangle(hDrawingDC, 0 - 1, 0 - 1, imgXRes + 1, imgYRes + 1);
}
コード例 #4
0
ファイル: main.c プロジェクト: RPG-7/reactos
int WINAPI
_tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR lpszArgument, int nFunsterStil)
{
    HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */

    TCHAR progtitle[1000];
    TCHAR resstr[100];
    HMENU menu;
    HWND hToolbar;
    HIMAGELIST hImageList;
    HANDLE haccel;
    HBITMAP tempBm;
    int i;
    TCHAR tooltips[16][30];
    HDC hDC;

    TCHAR *c;
    TCHAR sfnFilename[1000];
    TCHAR sfnFiletitle[256];
    TCHAR sfnFilter[1000];
    TCHAR ofnFilename[1000];
    TCHAR ofnFiletitle[256];
    TCHAR ofnFilter[1000];
    TCHAR miniaturetitle[100];
    static int custColors[16] = { 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
        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));

    hProgInstance = hThisInstance;

    /* initialize common controls library */
    InitCommonControls();

    /* register application defined window classes */
    RegisterWclMain();
    RegisterWclScrollbox();
    RegisterWclPal();
    RegisterWclSettings();
    RegisterWclSelection();
    RegisterWclSizebox();
    RegisterWclTextEdit();

    LoadString(hThisInstance, IDS_DEFAULTFILENAME, filename, SIZEOF(filename));
    LoadString(hThisInstance, IDS_WINDOWTITLE, resstr, SIZEOF(resstr));
    _stprintf(progtitle, resstr, filename);
    LoadString(hThisInstance, IDS_MINIATURETITLE, miniaturetitle, SIZEOF(miniaturetitle));

    /* create main window */
    hwnd =
        CreateWindowEx(0, _T("MainWindow"), progtitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 544,
                       375, HWND_DESKTOP, NULL, hThisInstance, NULL);
    hMainWnd = hwnd;

    hwndMiniature =
        CreateWindowEx(WS_EX_PALETTEWINDOW, _T("MainWindow"), miniaturetitle,
                       WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME, 180, 200, 120, 100, hwnd,
                       NULL, hThisInstance, NULL);

    /* loading and setting the window menu from resource */
    menu = LoadMenu(hThisInstance, MAKEINTRESOURCE(ID_MENU));
    SetMenu(hwnd, menu);
    haccel = LoadAccelerators(hThisInstance, MAKEINTRESOURCE(800));

    /* preloading the draw transparent/nontransparent icons for later use */
    hNontranspIcon =
        LoadImage(hThisInstance, MAKEINTRESOURCE(IDI_NONTRANSPARENT), IMAGE_ICON, 40, 30, LR_DEFAULTCOLOR);
    hTranspIcon =
        LoadImage(hThisInstance, MAKEINTRESOURCE(IDI_TRANSPARENT), IMAGE_ICON, 40, 30, LR_DEFAULTCOLOR);

    hCurFill     = LoadIcon(hThisInstance, MAKEINTRESOURCE(IDC_FILL));
    hCurColor    = LoadIcon(hThisInstance, MAKEINTRESOURCE(IDC_COLOR));
    hCurZoom     = LoadIcon(hThisInstance, MAKEINTRESOURCE(IDC_ZOOM));
    hCurPen      = LoadIcon(hThisInstance, MAKEINTRESOURCE(IDC_PEN));
    hCurAirbrush = LoadIcon(hThisInstance, MAKEINTRESOURCE(IDC_AIRBRUSH));

    CreateWindowEx(0, _T("STATIC"), _T(""), WS_CHILD | WS_VISIBLE | SS_ETCHEDHORZ, 0, 0, 5000, 2, hwnd, NULL,
                   hThisInstance, NULL);

    hToolBoxContainer =
        CreateWindowEx(0, _T("MainWindow"), _T(""), WS_CHILD | WS_VISIBLE, 2, 2, 52, 350, hwnd, NULL,
                       hThisInstance, NULL);
    /* creating the 16 bitmap radio buttons and setting the bitmap */


    /*
     * FIXME: Unintentionally there is a line above the tool bar (hidden by y-offset).
     * To prevent cropping of the buttons height has been increased from 200 to 205
     */
    hToolbar =
        CreateWindowEx(0, TOOLBARCLASSNAME, NULL,
                       WS_CHILD | WS_VISIBLE | CCS_NOPARENTALIGN | CCS_VERT | CCS_NORESIZE | TBSTYLE_TOOLTIPS,
                       1, -2, 50, 205, hToolBoxContainer, NULL, hThisInstance, NULL);
    hImageList = ImageList_Create(16, 16, ILC_COLOR24 | ILC_MASK, 16, 0);
    SendMessage(hToolbar, TB_SETIMAGELIST, 0, (LPARAM) hImageList);
    tempBm = LoadImage(hThisInstance, MAKEINTRESOURCE(IDB_TOOLBARICONS), IMAGE_BITMAP, 256, 16, 0);
    ImageList_AddMasked(hImageList, tempBm, 0xff00ff);
    DeleteObject(tempBm);
    SendMessage(hToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);

    for(i = 0; i < 16; i++)
    {
        TBBUTTON tbbutton;
        int wrapnow = 0;

        if (i % 2 == 1)
            wrapnow = TBSTATE_WRAP;

        LoadString(hThisInstance, IDS_TOOLTIP1 + i, tooltips[i], 30);
        ZeroMemory(&tbbutton, sizeof(TBBUTTON));
        tbbutton.iString   = (INT_PTR) tooltips[i];
        tbbutton.fsStyle   = TBSTYLE_CHECKGROUP;
        tbbutton.fsState   = TBSTATE_ENABLED | wrapnow;
        tbbutton.idCommand = ID_FREESEL + i;
        tbbutton.iBitmap   = i;
        SendMessage(hToolbar, TB_ADDBUTTONS, 1, (LPARAM) &tbbutton);
    }

    SendMessage(hToolbar, TB_CHECKBUTTON, ID_PEN, MAKELONG(TRUE, 0));
    SendMessage(hToolbar, TB_SETMAXTEXTROWS, 0, 0);
    SendMessage(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(25, 25));

    /* creating the tool settings child window */
    hToolSettings =
        CreateWindowEx(0, _T("ToolSettings"), _T(""), WS_CHILD | WS_VISIBLE, 5, 208, 42, 140,
                       hToolBoxContainer, NULL, hThisInstance, NULL);
    hTrackbarZoom =
        CreateWindowEx(0, TRACKBAR_CLASS, _T(""), WS_CHILD | TBS_VERT | TBS_AUTOTICKS, 1, 1, 40, 64,
                       hToolSettings, NULL, hThisInstance, NULL);
    SendMessage(hTrackbarZoom, TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG(0, 6));
    SendMessage(hTrackbarZoom, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) 3);

    /* creating the palette child window */
    hPalWin =
        CreateWindowEx(0, _T("Palette"), _T(""), WS_CHILD | WS_VISIBLE, 56, 9, 255, 32, hwnd, NULL,
                       hThisInstance, NULL);

    /* creating the scroll box */
    hScrollbox =
        CreateWindowEx(WS_EX_CLIENTEDGE, _T("Scrollbox"), _T(""),
                       WS_CHILD | WS_GROUP | WS_HSCROLL | WS_VSCROLL | WS_VISIBLE, 56, 49, 472, 248, hwnd,
                       NULL, hThisInstance, NULL);

    /* creating the status bar */
    hStatusBar =
        CreateWindowEx(0, STATUSCLASSNAME, _T(""), SBARS_SIZEGRIP | WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, hwnd,
                       NULL, hThisInstance, NULL);
    SendMessage(hStatusBar, SB_SETMINHEIGHT, 21, 0);

    hScrlClient =
        CreateWindowEx(0, _T("Scrollbox"), _T(""), WS_CHILD | WS_VISIBLE, 0, 0, 500, 500, hScrollbox, NULL,
                       hThisInstance, NULL);

    /* create selection window (initially hidden) */
    hSelection =
        CreateWindowEx(WS_EX_TRANSPARENT, _T("Selection"), _T(""), WS_CHILD | BS_OWNERDRAW, 350, 0, 100, 100,
                       hScrlClient, NULL, hThisInstance, NULL);

    /* creating the window inside the scroll box, on which the image in hDrawingDC's bitmap is drawn */
    hImageArea =
        CreateWindowEx(0, _T("MainWindow"), _T(""), WS_CHILD | WS_VISIBLE, 3, 3, imgXRes, imgYRes, hScrlClient,
                       NULL, hThisInstance, NULL);

    hDC = GetDC(hImageArea);
    hDrawingDC = CreateCompatibleDC(hDC);
    hSelDC     = CreateCompatibleDC(hDC);
    ReleaseDC(hImageArea, hDC);
    SelectObject(hDrawingDC, CreatePen(PS_SOLID, 0, fgColor));
    SelectObject(hDrawingDC, CreateSolidBrush(bgColor));

    hBms[0] = CreateDIBWithProperties(imgXRes, imgYRes);
    SelectObject(hDrawingDC, hBms[0]);
    Rectangle(hDrawingDC, 0 - 1, 0 - 1, imgXRes + 1, imgYRes + 1);

    if (lpszArgument[0] != 0)
    {
        HBITMAP bmNew = NULL;
        LoadDIBFromFile(&bmNew, lpszArgument, &fileTime, &fileSize, &fileHPPM, &fileVPPM);
        if (bmNew != NULL)
        {
            TCHAR tempstr[1000];
            TCHAR resstr[100];
            TCHAR *temp;
            insertReversible(bmNew);
            GetFullPathName(lpszArgument, SIZEOF(filepathname), filepathname, &temp);
            _tcscpy(filename, temp);
            LoadString(hProgInstance, IDS_WINDOWTITLE, resstr, SIZEOF(resstr));
            _stprintf(tempstr, resstr, filename);
            SetWindowText(hMainWnd, tempstr);
            clearHistory();
            isAFile = TRUE;
        }
        else
        {
            exit(0);
        }
    }

    /* initializing the CHOOSECOLOR structure for use with ChooseColor */
    choosecolor.lStructSize    = sizeof(CHOOSECOLOR);
    choosecolor.hwndOwner      = hwnd;
    choosecolor.hInstance      = NULL;
    choosecolor.rgbResult      = 0x00ffffff;
    choosecolor.lpCustColors   = (COLORREF*) &custColors;
    choosecolor.Flags          = 0;
    choosecolor.lCustData      = 0;
    choosecolor.lpfnHook       = NULL;
    choosecolor.lpTemplateName = NULL;

    /* initializing the OPENFILENAME structure for use with GetOpenFileName and GetSaveFileName */
    CopyMemory(ofnFilename, filename, sizeof(filename));
    LoadString(hThisInstance, IDS_OPENFILTER, ofnFilter, SIZEOF(ofnFilter));
    for(c = ofnFilter; *c; c++)
        if (*c == '\1')
            *c = '\0';
    ZeroMemory(&ofn, sizeof(OPENFILENAME));
    ofn.lStructSize    = sizeof(OPENFILENAME);
    ofn.hwndOwner      = hwnd;
    ofn.hInstance      = hThisInstance;
    ofn.lpstrFilter    = ofnFilter;
    ofn.lpstrFile      = ofnFilename;
    ofn.nMaxFile       = SIZEOF(ofnFilename);
    ofn.lpstrFileTitle = ofnFiletitle;
    ofn.nMaxFileTitle  = SIZEOF(ofnFiletitle);
    ofn.Flags          = OFN_HIDEREADONLY;

    CopyMemory(sfnFilename, filename, sizeof(filename));
    LoadString(hThisInstance, IDS_SAVEFILTER, sfnFilter, SIZEOF(sfnFilter));
    for(c = sfnFilter; *c; c++)
        if (*c == '\1')
            *c = '\0';
    ZeroMemory(&sfn, sizeof(OPENFILENAME));
    sfn.lStructSize    = sizeof(OPENFILENAME);
    sfn.hwndOwner      = hwnd;
    sfn.hInstance      = hThisInstance;
    sfn.lpstrFilter    = sfnFilter;
    sfn.lpstrFile      = sfnFilename;
    sfn.nMaxFile       = SIZEOF(sfnFilename);
    sfn.lpstrFileTitle = sfnFiletitle;
    sfn.nMaxFileTitle  = SIZEOF(sfnFiletitle);
    sfn.Flags          = OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY;

    /* creating the size boxes */
    hSizeboxLeftTop =
        CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD | WS_VISIBLE, 0, 0, 3, 3, hScrlClient, NULL,
                       hThisInstance, NULL);
    hSizeboxCenterTop =
        CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD | WS_VISIBLE, 0, 0, 3, 3, hScrlClient, NULL,
                       hThisInstance, NULL);
    hSizeboxRightTop =
        CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD | WS_VISIBLE, 0, 0, 3, 3, hScrlClient, NULL,
                       hThisInstance, NULL);
    hSizeboxLeftCenter =
        CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD | WS_VISIBLE, 0, 0, 3, 3, hScrlClient, NULL,
                       hThisInstance, NULL);
    hSizeboxRightCenter =
        CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD | WS_VISIBLE, 0, 0, 3, 3, hScrlClient, NULL,
                       hThisInstance, NULL);
    hSizeboxLeftBottom =
        CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD | WS_VISIBLE, 0, 0, 3, 3, hScrlClient, NULL,
                       hThisInstance, NULL);
    hSizeboxCenterBottom =
        CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD | WS_VISIBLE, 0, 0, 3, 3, hScrlClient, NULL,
                       hThisInstance, NULL);
    hSizeboxRightBottom =
        CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD | WS_VISIBLE, 0, 0, 3, 3, hScrlClient, NULL,
                       hThisInstance, NULL);
    /* placing the size boxes around the image */
    SendMessage(hImageArea, WM_SIZE, 0, 0);

    /* by moving the window, the things in WM_SIZE are done */
    MoveWindow(hwnd, 100, 100, 600, 450, TRUE);

    /* creating the text editor window for the text tool */
    hwndTextEdit =
        CreateWindowEx(0, _T("TextEdit"), _T(""), WS_OVERLAPPEDWINDOW, 300, 0, 300,
                       200, hwnd, NULL, hThisInstance, NULL);
    /* creating the edit control within the editor window */
    hwndEditCtl =
        CreateWindowEx(WS_EX_CLIENTEDGE, _T("EDIT"), _T(""),
                       WS_CHILD | WS_VISIBLE | WS_BORDER | WS_HSCROLL | WS_VSCROLL | ES_MULTILINE | ES_NOHIDESEL | ES_AUTOHSCROLL | ES_AUTOVSCROLL,
                       0, 0, 100, 100, hwndTextEdit, NULL, hThisInstance, NULL);

    /* Make the window visible on the screen */
    ShowWindow (hwnd, nFunsterStil);

    /* inform the system, that the main window accepts dropped files */
    DragAcceptFiles(hwnd, TRUE);

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage(&messages, NULL, 0, 0))
    {
        TranslateAccelerator(hwnd, haccel, &messages);

        /* Translate virtual-key messages into character messages */
        TranslateMessage(&messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&messages);
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}
コード例 #5
0
ファイル: mouse.c プロジェクト: rmallof/reactos
void
endPaintingL(HDC hdc, LONG x, LONG y, COLORREF fg, COLORREF bg)
{
    switch (activeTool)
    {
        case TOOL_FREESEL:
        {
            POINT *ptStackCopy;
            int i;
            rectSel_src[0] = rectSel_src[1] = 0x7fffffff;
            rectSel_src[2] = rectSel_src[3] = 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 (ptSP != 0)
            {
                DeleteObject(hSelMask);
                hSelMask = CreateBitmap(rectSel_src[2], rectSel_src[3], 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];
                }
                Poly(hSelDC, ptStackCopy, ptSP + 1, 0x00ffffff, 0x00ffffff, 1, 2, TRUE);
                HeapFree(GetProcessHeap(), 0, ptStackCopy);
                SelectObject(hSelDC, hSelBm = CreateDIBWithProperties(rectSel_src[2], rectSel_src[3]));
                resetToU1();
                MaskBlt(hSelDC, 0, 0, rectSel_src[2], rectSel_src[3], hDrawingDC, rectSel_src[0],
                        rectSel_src[1], 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,
                        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 ((rectSel_src[2] != 0) && (rectSel_src[3] != 0))
            {
                DeleteObject(hSelMask);
                hSelMask = CreateBitmap(rectSel_src[2], rectSel_src[3], 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]));
                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,
                       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);
            }
            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);
                    pointSP = 0;
                }
                else
                {
                    Poly(hdc, pointStack, pointSP, fg, bg, lineWidth, shapeStyle, 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;
    }
}
コード例 #6
0
ファイル: selection.c プロジェクト: HBelusca/NasuTek-Odyssey
LRESULT CALLBACK
SelectionWinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
        case WM_PAINT:
        {
            if (!moving)
            {
                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);
                ReleaseDC(hwnd, hDC);
            }
            break;
        }
        case WM_LBUTTONDOWN:
            xPos = LOWORD(lParam);
            yPos = HIWORD(lParam);
            SetCapture(hwnd);
            if (action != 0)
                SetCursor(LoadCursor(NULL, cursors[action]));
            moving = TRUE;
            break;
        case WM_MOUSEMOVE:
            if (moving)
            {
                TCHAR sizeStr[100];
                int xDelta;
                int yDelta;
                resetToU1();
                xFrac += (short)LOWORD(lParam) - xPos;
                yFrac += (short)HIWORD(lParam) - yPos;
                if (zoom < 1000)
                {
                    xDelta = xFrac * 1000 / zoom;
                    xFrac = 0;
                    yDelta = yFrac * 1000 / zoom;
                    yFrac = 0;
                }
                else
                {
                    xDelta = xFrac * 1000 / zoom;
                    xFrac -= (xFrac * 1000 / zoom) * zoom / 1000;
                    yDelta = yFrac * 1000 / zoom;
                    yFrac -= (yFrac * 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[2] += xDelta;
                        rectSel_dest[1] += 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]);
                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);
                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);
                }
                SendMessage(hImageArea, WM_PAINT, 0, 0);
                xPos = LOWORD(lParam);
                yPos = HIWORD(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 = LOWORD(lParam);
                yPos = HIWORD(lParam);
                SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) NULL);
                action = identifyCorner(xPos, yPos, w, h);
                if (action != 0)
                    SetCursor(LoadCursor(NULL, cursors[action]));
            }
            break;
        case WM_LBUTTONUP:
            if (moving)
            {
                moving = FALSE;
                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);
                }
                placeSelWin();
                ShowWindow(hSelection, SW_HIDE);
                ShowWindow(hSelection, SW_SHOW);
            }
            break;
        default:
            return DefWindowProc(hwnd, message, wParam, lParam);
    }

    return 0;
}