2 * PROJECT: PAINT for ReactOS
4 * FILE: base/applications/paint/history.c
5 * PURPOSE: Undo and redo functionality
6 * PROGRAMMERS: Benedikt Freisen
9 /* INCLUDES *********************************************************/
13 /* FUNCTIONS ********************************************************/
15 extern void updateCanvasAndScrollbars(void);
18 setImgXYRes(int x
, int y
)
20 if ((imgXRes
!= x
) || (imgYRes
!= y
))
24 updateCanvasAndScrollbars();
31 DeleteObject(hBms
[(currInd
+ 1) % HISTORYSIZE
]);
32 hBms
[(currInd
+ 1) % HISTORYSIZE
] = CopyImage(hBms
[currInd
], IMAGE_BITMAP
, 0, 0, LR_COPYRETURNORG
);
33 currInd
= (currInd
+ 1) % HISTORYSIZE
;
34 if (undoSteps
< HISTORYSIZE
- 1)
37 SelectObject(hDrawingDC
, hBms
[currInd
]);
38 imgXRes
= GetDIBWidth(hBms
[currInd
]);
39 imgYRes
= GetDIBHeight(hBms
[currInd
]);
48 ShowWindow(hSelection
, SW_HIDE
);
49 currInd
= (currInd
+ HISTORYSIZE
- 1) % HISTORYSIZE
;
50 SelectObject(hDrawingDC
, hBms
[currInd
]);
52 if (redoSteps
< HISTORYSIZE
- 1)
54 setImgXYRes(GetDIBWidth(hBms
[currInd
]), GetDIBHeight(hBms
[currInd
]));
63 ShowWindow(hSelection
, SW_HIDE
);
64 currInd
= (currInd
+ 1) % HISTORYSIZE
;
65 SelectObject(hDrawingDC
, hBms
[currInd
]);
67 if (undoSteps
< HISTORYSIZE
- 1)
69 setImgXYRes(GetDIBWidth(hBms
[currInd
]), GetDIBHeight(hBms
[currInd
]));
76 DeleteObject(hBms
[currInd
]);
78 CopyImage(hBms
[(currInd
+ HISTORYSIZE
- 1) % HISTORYSIZE
], IMAGE_BITMAP
, 0, 0, LR_COPYRETURNORG
);
79 SelectObject(hDrawingDC
, hBms
[currInd
]);
80 imgXRes
= GetDIBWidth(hBms
[currInd
]);
81 imgYRes
= GetDIBHeight(hBms
[currInd
]);
92 insertReversible(HBITMAP hbm
)
94 DeleteObject(hBms
[(currInd
+ 1) % HISTORYSIZE
]);
95 hBms
[(currInd
+ 1) % HISTORYSIZE
] = hbm
;
96 currInd
= (currInd
+ 1) % HISTORYSIZE
;
97 if (undoSteps
< HISTORYSIZE
- 1)
100 SelectObject(hDrawingDC
, hBms
[currInd
]);
101 setImgXYRes(GetDIBWidth(hBms
[currInd
]), GetDIBHeight(hBms
[currInd
]));
105 cropReversible(int width
, int height
, int xOffset
, int yOffset
)
111 SelectObject(hDrawingDC
, hBms
[currInd
]);
112 DeleteObject(hBms
[(currInd
+ 1) % HISTORYSIZE
]);
113 hBms
[(currInd
+ 1) % HISTORYSIZE
] = CreateDIBWithProperties(width
, height
);
114 currInd
= (currInd
+ 1) % HISTORYSIZE
;
115 if (undoSteps
< HISTORYSIZE
- 1)
119 hdc
= CreateCompatibleDC(hDrawingDC
);
120 SelectObject(hdc
, hBms
[currInd
]);
122 oldPen
= SelectObject(hdc
, CreatePen(PS_SOLID
, 1, bgColor
));
123 oldBrush
= SelectObject(hdc
, CreateSolidBrush(bgColor
));
124 Rectangle(hdc
, 0, 0, width
, height
);
125 BitBlt(hdc
, -xOffset
, -yOffset
, imgXRes
, imgYRes
, hDrawingDC
, 0, 0, SRCCOPY
);
126 DeleteObject(SelectObject(hdc
, oldBrush
));
127 DeleteObject(SelectObject(hdc
, oldPen
));
129 SelectObject(hDrawingDC
, hBms
[currInd
]);
131 setImgXYRes(width
, height
);