2 * PROJECT: PAINT for ReactOS
4 * FILE: base/applications/paint/history.c
5 * PURPOSE: Undo and redo functionality
6 * PROGRAMMERS: Benedikt Freisen
9 /* INCLUDES *********************************************************/
12 #include "globalvar.h"
14 #include "definitions.h"
16 /* FUNCTIONS ********************************************************/
18 extern void updateCanvasAndScrollbars(void);
21 setImgXYRes(int x
, int y
)
23 if ((imgXRes
!= x
) || (imgYRes
!= y
))
27 updateCanvasAndScrollbars();
34 DeleteObject(hBms
[(currInd
+ 1) % HISTORYSIZE
]);
35 hBms
[(currInd
+ 1) % HISTORYSIZE
] = CopyImage(hBms
[currInd
], IMAGE_BITMAP
, 0, 0, LR_COPYRETURNORG
);
36 currInd
= (currInd
+ 1) % HISTORYSIZE
;
37 if (undoSteps
< HISTORYSIZE
- 1)
40 SelectObject(hDrawingDC
, hBms
[currInd
]);
41 imgXRes
= GetDIBWidth(hBms
[currInd
]);
42 imgYRes
= GetDIBHeight(hBms
[currInd
]);
51 ShowWindow(hSelection
, SW_HIDE
);
52 currInd
= (currInd
+ HISTORYSIZE
- 1) % HISTORYSIZE
;
53 SelectObject(hDrawingDC
, hBms
[currInd
]);
55 if (redoSteps
< HISTORYSIZE
- 1)
57 setImgXYRes(GetDIBWidth(hBms
[currInd
]), GetDIBHeight(hBms
[currInd
]));
66 ShowWindow(hSelection
, SW_HIDE
);
67 currInd
= (currInd
+ 1) % HISTORYSIZE
;
68 SelectObject(hDrawingDC
, hBms
[currInd
]);
70 if (undoSteps
< HISTORYSIZE
- 1)
72 setImgXYRes(GetDIBWidth(hBms
[currInd
]), GetDIBHeight(hBms
[currInd
]));
79 DeleteObject(hBms
[currInd
]);
81 CopyImage(hBms
[(currInd
+ HISTORYSIZE
- 1) % HISTORYSIZE
], IMAGE_BITMAP
, 0, 0, LR_COPYRETURNORG
);
82 SelectObject(hDrawingDC
, hBms
[currInd
]);
83 imgXRes
= GetDIBWidth(hBms
[currInd
]);
84 imgYRes
= GetDIBHeight(hBms
[currInd
]);
95 insertReversible(HBITMAP hbm
)
97 DeleteObject(hBms
[(currInd
+ 1) % HISTORYSIZE
]);
98 hBms
[(currInd
+ 1) % HISTORYSIZE
] = hbm
;
99 currInd
= (currInd
+ 1) % HISTORYSIZE
;
100 if (undoSteps
< HISTORYSIZE
- 1)
103 SelectObject(hDrawingDC
, hBms
[currInd
]);
104 setImgXYRes(GetDIBWidth(hBms
[currInd
]), GetDIBHeight(hBms
[currInd
]));
108 cropReversible(int width
, int height
, int xOffset
, int yOffset
)
114 SelectObject(hDrawingDC
, hBms
[currInd
]);
115 DeleteObject(hBms
[(currInd
+ 1) % HISTORYSIZE
]);
116 hBms
[(currInd
+ 1) % HISTORYSIZE
] = CreateDIBWithProperties(width
, height
);
117 currInd
= (currInd
+ 1) % HISTORYSIZE
;
118 if (undoSteps
< HISTORYSIZE
- 1)
122 hdc
= CreateCompatibleDC(hDrawingDC
);
123 SelectObject(hdc
, hBms
[currInd
]);
125 oldPen
= SelectObject(hdc
, CreatePen(PS_SOLID
, 1, bgColor
));
126 oldBrush
= SelectObject(hdc
, CreateSolidBrush(bgColor
));
127 Rectangle(hdc
, 0, 0, width
, height
);
128 BitBlt(hdc
, -xOffset
, -yOffset
, imgXRes
, imgYRes
, hDrawingDC
, 0, 0, SRCCOPY
);
129 DeleteObject(SelectObject(hdc
, oldBrush
));
130 DeleteObject(SelectObject(hdc
, oldPen
));
132 SelectObject(hDrawingDC
, hBms
[currInd
]);
134 setImgXYRes(width
, height
);