2009-05-12 14:15:48 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: PAINT for ReactOS
|
|
|
|
* LICENSE: LGPL
|
2009-10-21 15:44:31 +00:00
|
|
|
* FILE: base/applications/paint/history.c
|
2009-05-12 14:15:48 +00:00
|
|
|
* PURPOSE: Undo and redo functionality
|
|
|
|
* PROGRAMMERS: Benedikt Freisen
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *********************************************************/
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include "globalvar.h"
|
|
|
|
#include "dib.h"
|
|
|
|
#include "definitions.h"
|
|
|
|
|
|
|
|
/* FUNCTIONS ********************************************************/
|
|
|
|
|
2009-05-27 12:03:18 +00:00
|
|
|
extern void updateCanvasAndScrollbars(void);
|
|
|
|
|
2009-10-21 15:44:31 +00:00
|
|
|
void
|
|
|
|
setImgXYRes(int x, int y)
|
2009-05-12 14:15:48 +00:00
|
|
|
{
|
2009-10-21 15:44:31 +00:00
|
|
|
if ((imgXRes != x) || (imgYRes != y))
|
2009-05-12 14:15:48 +00:00
|
|
|
{
|
|
|
|
imgXRes = x;
|
|
|
|
imgYRes = y;
|
|
|
|
updateCanvasAndScrollbars();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-21 15:44:31 +00:00
|
|
|
void
|
|
|
|
newReversible()
|
2009-05-12 14:15:48 +00:00
|
|
|
{
|
2009-10-21 15:44:31 +00:00
|
|
|
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++;
|
2009-05-12 14:15:48 +00:00
|
|
|
redoSteps = 0;
|
|
|
|
SelectObject(hDrawingDC, hBms[currInd]);
|
|
|
|
imgXRes = GetDIBWidth(hBms[currInd]);
|
|
|
|
imgYRes = GetDIBHeight(hBms[currInd]);
|
2009-10-03 16:33:41 +00:00
|
|
|
imageSaved = FALSE;
|
2009-05-12 14:15:48 +00:00
|
|
|
}
|
|
|
|
|
2009-10-21 15:44:31 +00:00
|
|
|
void
|
|
|
|
undo()
|
2009-05-12 14:15:48 +00:00
|
|
|
{
|
2009-10-21 15:44:31 +00:00
|
|
|
if (undoSteps > 0)
|
2009-05-12 14:15:48 +00:00
|
|
|
{
|
|
|
|
ShowWindow(hSelection, SW_HIDE);
|
2009-10-21 15:44:31 +00:00
|
|
|
currInd = (currInd + HISTORYSIZE - 1) % HISTORYSIZE;
|
2009-05-12 14:15:48 +00:00
|
|
|
SelectObject(hDrawingDC, hBms[currInd]);
|
|
|
|
undoSteps--;
|
2009-10-21 15:44:31 +00:00
|
|
|
if (redoSteps < HISTORYSIZE - 1)
|
|
|
|
redoSteps++;
|
2009-05-12 14:15:48 +00:00
|
|
|
setImgXYRes(GetDIBWidth(hBms[currInd]), GetDIBHeight(hBms[currInd]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-21 15:44:31 +00:00
|
|
|
void
|
|
|
|
redo()
|
2009-05-12 14:15:48 +00:00
|
|
|
{
|
2009-10-21 15:44:31 +00:00
|
|
|
if (redoSteps > 0)
|
2009-05-12 14:15:48 +00:00
|
|
|
{
|
|
|
|
ShowWindow(hSelection, SW_HIDE);
|
2009-10-21 15:44:31 +00:00
|
|
|
currInd = (currInd + 1) % HISTORYSIZE;
|
2009-05-12 14:15:48 +00:00
|
|
|
SelectObject(hDrawingDC, hBms[currInd]);
|
|
|
|
redoSteps--;
|
2009-10-21 15:44:31 +00:00
|
|
|
if (undoSteps < HISTORYSIZE - 1)
|
|
|
|
undoSteps++;
|
2009-05-12 14:15:48 +00:00
|
|
|
setImgXYRes(GetDIBWidth(hBms[currInd]), GetDIBHeight(hBms[currInd]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-21 15:44:31 +00:00
|
|
|
void
|
|
|
|
resetToU1()
|
2009-05-12 14:15:48 +00:00
|
|
|
{
|
|
|
|
DeleteObject(hBms[currInd]);
|
2009-10-21 15:44:31 +00:00
|
|
|
hBms[currInd] =
|
|
|
|
CopyImage(hBms[(currInd + HISTORYSIZE - 1) % HISTORYSIZE], IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG);
|
2009-05-12 14:15:48 +00:00
|
|
|
SelectObject(hDrawingDC, hBms[currInd]);
|
|
|
|
imgXRes = GetDIBWidth(hBms[currInd]);
|
|
|
|
imgYRes = GetDIBHeight(hBms[currInd]);
|
|
|
|
}
|
|
|
|
|
2009-10-21 15:44:31 +00:00
|
|
|
void
|
|
|
|
clearHistory()
|
2009-05-12 14:15:48 +00:00
|
|
|
{
|
|
|
|
undoSteps = 0;
|
|
|
|
redoSteps = 0;
|
|
|
|
}
|
|
|
|
|
2009-10-21 15:44:31 +00:00
|
|
|
void
|
|
|
|
insertReversible(HBITMAP hbm)
|
2009-05-12 14:15:48 +00:00
|
|
|
{
|
2009-10-21 15:44:31 +00:00
|
|
|
DeleteObject(hBms[(currInd + 1) % HISTORYSIZE]);
|
|
|
|
hBms[(currInd + 1) % HISTORYSIZE] = hbm;
|
|
|
|
currInd = (currInd + 1) % HISTORYSIZE;
|
|
|
|
if (undoSteps < HISTORYSIZE - 1)
|
|
|
|
undoSteps++;
|
2009-05-12 14:15:48 +00:00
|
|
|
redoSteps = 0;
|
|
|
|
SelectObject(hDrawingDC, hBms[currInd]);
|
|
|
|
setImgXYRes(GetDIBWidth(hBms[currInd]), GetDIBHeight(hBms[currInd]));
|
|
|
|
}
|
|
|
|
|
2009-10-21 15:44:31 +00:00
|
|
|
void
|
|
|
|
cropReversible(int width, int height, int xOffset, int yOffset)
|
2009-05-12 14:15:48 +00:00
|
|
|
{
|
2009-07-02 17:02:37 +00:00
|
|
|
HDC hdc;
|
2009-06-16 21:12:47 +00:00
|
|
|
HPEN oldPen;
|
|
|
|
HBRUSH oldBrush;
|
|
|
|
|
2009-05-12 14:15:48 +00:00
|
|
|
SelectObject(hDrawingDC, hBms[currInd]);
|
2009-10-21 15:44:31 +00:00
|
|
|
DeleteObject(hBms[(currInd + 1) % HISTORYSIZE]);
|
|
|
|
hBms[(currInd + 1) % HISTORYSIZE] = CreateDIBWithProperties(width, height);
|
|
|
|
currInd = (currInd + 1) % HISTORYSIZE;
|
|
|
|
if (undoSteps < HISTORYSIZE - 1)
|
|
|
|
undoSteps++;
|
2009-05-12 14:15:48 +00:00
|
|
|
redoSteps = 0;
|
2009-10-21 15:44:31 +00:00
|
|
|
|
2009-07-02 17:02:37 +00:00
|
|
|
hdc = CreateCompatibleDC(hDrawingDC);
|
|
|
|
SelectObject(hdc, hBms[currInd]);
|
2009-10-21 15:44:31 +00:00
|
|
|
|
2009-07-02 17:02:37 +00:00
|
|
|
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]);
|
2009-10-21 15:44:31 +00:00
|
|
|
|
2009-07-02 17:02:37 +00:00
|
|
|
setImgXYRes(width, height);
|
2009-05-12 14:15:48 +00:00
|
|
|
}
|