mirror of
https://github.com/reactos/reactos.git
synced 2024-11-04 05:43:30 +00:00
527f2f9057
* Create a branch for some evul shell experiments. svn path=/branches/shell-experiments/; revision=61927
132 lines
3.4 KiB
C
132 lines
3.4 KiB
C
/*
|
|
* PROJECT: PAINT for ReactOS
|
|
* LICENSE: LGPL
|
|
* FILE: base/applications/paint/history.c
|
|
* PURPOSE: Undo and redo functionality
|
|
* PROGRAMMERS: Benedikt Freisen
|
|
*/
|
|
|
|
/* INCLUDES *********************************************************/
|
|
|
|
#include "precomp.h"
|
|
|
|
/* FUNCTIONS ********************************************************/
|
|
|
|
extern void updateCanvasAndScrollbars(void);
|
|
|
|
void
|
|
setImgXYRes(int x, int y)
|
|
{
|
|
if ((imgXRes != x) || (imgYRes != y))
|
|
{
|
|
imgXRes = x;
|
|
imgYRes = y;
|
|
updateCanvasAndScrollbars();
|
|
}
|
|
}
|
|
|
|
void
|
|
newReversible()
|
|
{
|
|
DeleteObject(hBms[(currInd + 1) % HISTORYSIZE]);
|
|
hBms[(currInd + 1) % HISTORYSIZE] = CopyImage(hBms[currInd], IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG);
|
|
currInd = (currInd + 1) % HISTORYSIZE;
|
|
if (undoSteps < HISTORYSIZE - 1)
|
|
undoSteps++;
|
|
redoSteps = 0;
|
|
SelectObject(hDrawingDC, hBms[currInd]);
|
|
imgXRes = GetDIBWidth(hBms[currInd]);
|
|
imgYRes = GetDIBHeight(hBms[currInd]);
|
|
imageSaved = FALSE;
|
|
}
|
|
|
|
void
|
|
undo()
|
|
{
|
|
if (undoSteps > 0)
|
|
{
|
|
ShowWindow(hSelection, SW_HIDE);
|
|
currInd = (currInd + HISTORYSIZE - 1) % HISTORYSIZE;
|
|
SelectObject(hDrawingDC, hBms[currInd]);
|
|
undoSteps--;
|
|
if (redoSteps < HISTORYSIZE - 1)
|
|
redoSteps++;
|
|
setImgXYRes(GetDIBWidth(hBms[currInd]), GetDIBHeight(hBms[currInd]));
|
|
}
|
|
}
|
|
|
|
void
|
|
redo()
|
|
{
|
|
if (redoSteps > 0)
|
|
{
|
|
ShowWindow(hSelection, SW_HIDE);
|
|
currInd = (currInd + 1) % HISTORYSIZE;
|
|
SelectObject(hDrawingDC, hBms[currInd]);
|
|
redoSteps--;
|
|
if (undoSteps < HISTORYSIZE - 1)
|
|
undoSteps++;
|
|
setImgXYRes(GetDIBWidth(hBms[currInd]), GetDIBHeight(hBms[currInd]));
|
|
}
|
|
}
|
|
|
|
void
|
|
resetToU1()
|
|
{
|
|
DeleteObject(hBms[currInd]);
|
|
hBms[currInd] =
|
|
CopyImage(hBms[(currInd + HISTORYSIZE - 1) % HISTORYSIZE], IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG);
|
|
SelectObject(hDrawingDC, hBms[currInd]);
|
|
imgXRes = GetDIBWidth(hBms[currInd]);
|
|
imgYRes = GetDIBHeight(hBms[currInd]);
|
|
}
|
|
|
|
void
|
|
clearHistory()
|
|
{
|
|
undoSteps = 0;
|
|
redoSteps = 0;
|
|
}
|
|
|
|
void
|
|
insertReversible(HBITMAP hbm)
|
|
{
|
|
DeleteObject(hBms[(currInd + 1) % HISTORYSIZE]);
|
|
hBms[(currInd + 1) % HISTORYSIZE] = hbm;
|
|
currInd = (currInd + 1) % HISTORYSIZE;
|
|
if (undoSteps < HISTORYSIZE - 1)
|
|
undoSteps++;
|
|
redoSteps = 0;
|
|
SelectObject(hDrawingDC, hBms[currInd]);
|
|
setImgXYRes(GetDIBWidth(hBms[currInd]), GetDIBHeight(hBms[currInd]));
|
|
}
|
|
|
|
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);
|
|
}
|