ReactOS  0.4.12-dev-43-g63b00d8
history.cpp
Go to the documentation of this file.
1 /*
2  * PROJECT: PAINT for ReactOS
3  * LICENSE: LGPL
4  * FILE: base/applications/mspaint/history.cpp
5  * PURPOSE: Undo and redo functionality
6  * PROGRAMMERS: Benedikt Freisen
7  */
8 
9 /* INCLUDES *********************************************************/
10 
11 #include "precomp.h"
12 
13 /* FUNCTIONS ********************************************************/
14 
16 {
18 }
19 
21 {
23 }
24 
26 {
27  currInd = 0;
28  undoSteps = 0;
29  redoSteps = 0;
30  imageSaved = TRUE;
31 
32  // prepare a minimal usable bitmap
33  int imgXRes = 1;
34  int imgYRes = 1;
35 
39 
40  hBms[0] = CreateDIBWithProperties(imgXRes, imgYRes);
42  Rectangle(hDrawingDC, 0 - 1, 0 - 1, imgXRes + 1, imgYRes + 1);
43 }
44 
46 {
49  currInd = (currInd + 1) % HISTORYSIZE;
50  if (undoSteps < HISTORYSIZE - 1)
51  undoSteps++;
52  redoSteps = 0;
53  SelectObject(hDrawingDC, hBms[currInd]);
54  imageSaved = FALSE;
55 }
56 
58 {
59  if (undoSteps > 0)
60  {
61  int oldWidth = GetWidth();
62  int oldHeight = GetHeight();
63  selectionWindow.ShowWindow(SW_HIDE);
66  undoSteps--;
67  if (redoSteps < HISTORYSIZE - 1)
68  redoSteps++;
69  if (GetWidth() != oldWidth || GetHeight() != oldHeight)
72  }
73 }
74 
76 {
77  if (redoSteps > 0)
78  {
79  int oldWidth = GetWidth();
80  int oldHeight = GetHeight();
81  selectionWindow.ShowWindow(SW_HIDE);
82  currInd = (currInd + 1) % HISTORYSIZE;
84  redoSteps--;
85  if (undoSteps < HISTORYSIZE - 1)
86  undoSteps++;
87  if (GetWidth() != oldWidth || GetHeight() != oldHeight)
90  }
91 }
92 
94 {
96  hBms[currInd] =
98  SelectObject(hDrawingDC, hBms[currInd]);
100 }
101 
103 {
104  undoSteps = 0;
105  redoSteps = 0;
106 }
107 
109 {
110  int oldWidth = GetWidth();
111  int oldHeight = GetHeight();
113  hBms[(currInd + 1) % HISTORYSIZE] = hbm;
114  currInd = (currInd + 1) % HISTORYSIZE;
115  if (undoSteps < HISTORYSIZE - 1)
116  undoSteps++;
117  redoSteps = 0;
118  SelectObject(hDrawingDC, hBms[currInd]);
119  if (GetWidth() != oldWidth || GetHeight() != oldHeight)
122 }
123 
124 void ImageModel::Crop(int nWidth, int nHeight, int nOffsetX, int nOffsetY)
125 {
126  HDC hdc;
127  HPEN oldPen;
128  HBRUSH oldBrush;
129  int oldWidth = GetWidth();
130  int oldHeight = GetHeight();
131 
132  if (nWidth <= 0)
133  nWidth = 1;
134  if (nHeight <= 0)
135  nHeight = 1;
136 
138  DeleteObject(hBms[(currInd + 1) % HISTORYSIZE]);
139  hBms[(currInd + 1) % HISTORYSIZE] = CreateDIBWithProperties(nWidth, nHeight);
140  currInd = (currInd + 1) % HISTORYSIZE;
141  if (undoSteps < HISTORYSIZE - 1)
142  undoSteps++;
143  redoSteps = 0;
144 
146  SelectObject(hdc, hBms[currInd]);
147 
148  oldPen = (HPEN) SelectObject(hdc, CreatePen(PS_SOLID, 1, paletteModel.GetBgColor()));
149  oldBrush = (HBRUSH) SelectObject(hdc, CreateSolidBrush(paletteModel.GetBgColor()));
150  Rectangle(hdc, 0, 0, nWidth, nHeight);
151  BitBlt(hdc, -nOffsetX, -nOffsetY, GetWidth(), GetHeight(), hDrawingDC, 0, 0, SRCCOPY);
152  DeleteObject(SelectObject(hdc, oldBrush));
153  DeleteObject(SelectObject(hdc, oldPen));
154  DeleteDC(hdc);
155  SelectObject(hDrawingDC, hBms[currInd]);
156 
157  if (GetWidth() != oldWidth || GetHeight() != oldHeight)
160 }
161 
163 {
165  imageSaved = TRUE;
166 }
167 
169 {
170  return imageSaved;
171 }
172 
174 {
175  return undoSteps > 0;
176 }
177 
179 {
180  return redoSteps > 0;
181 }
182 
183 void ImageModel::StretchSkew(int nStretchPercentX, int nStretchPercentY, int nSkewDegX, int nSkewDegY)
184 {
185  int oldWidth = GetWidth();
186  int oldHeight = GetHeight();
188  GetWidth() * nStretchPercentX / 100,
189  GetHeight() * nStretchPercentY / 100, 0));
190  if (GetWidth() != oldWidth || GetHeight() != oldHeight)
193 }
194 
196 {
197  return GetDIBWidth(hBms[currInd]);
198 }
199 
201 {
202  return GetDIBHeight(hBms[currInd]);
203 }
204 
206 {
207  RECT rect = {0, 0, GetWidth(), GetHeight()};
208  CopyPrevious();
209  InvertRect(hDrawingDC, &rect);
211 }
212 
214 {
215  Rectangle(hDrawingDC, 0 - 1, 0 - 1, GetWidth() + 1, GetHeight() + 1);
217 }
218 
220 {
221  return hDrawingDC;
222 }
223 
225 {
226  CopyPrevious();
227  StretchBlt(hDrawingDC, GetWidth() - 1, 0, -GetWidth(), GetHeight(), GetDC(), 0, 0,
228  GetWidth(), GetHeight(), SRCCOPY);
230 }
231 
233 {
234  CopyPrevious();
235  StretchBlt(hDrawingDC, 0, GetHeight() - 1, GetWidth(), -GetHeight(), GetDC(), 0, 0,
236  GetWidth(), GetHeight(), SRCCOPY);
238 }
239 
241 {
242  if (iN == 2)
243  {
244  CopyPrevious();
246  0, 0, GetWidth(), GetHeight(), SRCCOPY);
247  }
249 }
int redoSteps
Definition: history.h:22
#define HDC
Definition: msvc.h:22
void FlipHorizontally()
Definition: history.cpp:224
void SaveImage(LPTSTR lpFileName)
Definition: history.cpp:162
ImageModel()
Definition: history.cpp:25
void CopyPrevious(void)
Definition: history.cpp:45
#define TRUE
Definition: types.h:120
HPEN WINAPI CreatePen(_In_ int, _In_ int, _In_ COLORREF)
#define HBITMAP
Definition: msvc.h:28
int fileSize
Definition: main.cpp:54
int currInd
Definition: history.h:20
void SaveDIBToFile(HBITMAP hBitmap, LPTSTR FileName, HDC hDC, LPSYSTEMTIME time, int *size, int hRes, int vRes)
Definition: dib.cpp:46
BOOL WINAPI Rectangle(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int)
#define SW_HIDE
Definition: winuser.h:762
HDC hDrawingDC
Definition: history.h:16
void InvertColors()
Definition: history.cpp:205
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
int GetDIBHeight(HBITMAP hBitmap)
Definition: dib.cpp:38
BOOL IsImageSaved()
Definition: history.cpp:168
BOOL WINAPI InvertRect(_In_ HDC, _In_ LPCRECT)
BOOL HasRedoSteps()
Definition: history.cpp:178
void Redo(void)
Definition: history.cpp:75
static VOID NTAPI BitBlt(IN ULONG Left, IN ULONG Top, IN ULONG Width, IN ULONG Height, IN PUCHAR Buffer, IN ULONG BitsPerPixel, IN ULONG Delta)
Definition: vga.c:416
BOOL WINAPI StretchBlt(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int, _In_opt_ HDC, _In_ int, _In_ int, _In_ int, _In_ int, _In_ DWORD)
& rect
Definition: startmenu.cpp:1413
CHAR * LPTSTR
Definition: xmlstorage.h:192
void Crop(int nWidth, int nHeight, int nOffsetX=0, int nOffsetY=0)
Definition: history.cpp:124
CImgAreaWindow imageArea
Definition: main.cpp:71
int GetDIBWidth(HBITMAP hBitmap)
Definition: dib.cpp:30
#define PS_SOLID
Definition: wingdi.h:584
#define LR_COPYRETURNORG
Definition: winuser.h:1080
SYSTEMTIME fileTime
Definition: main.cpp:57
void ClearHistory(void)
Definition: history.cpp:102
GLuint color
Definition: glext.h:6243
HDC GetDC()
Definition: history.cpp:219
HANDLE WINAPI CopyImage(_In_ HANDLE, _In_ UINT, _In_ int, _In_ int, _In_ UINT)
Definition: cursoricon.c:1956
HDC hdc
Definition: msvc.h:53
smooth NULL
Definition: ftsmooth.c:416
HBITMAP CreateDIBWithProperties(int width, int height)
Definition: dib.cpp:16
int fileHPPM
Definition: main.cpp:55
void Insert(HBITMAP hbm)
Definition: history.cpp:108
void Clear(COLORREF color=0x00ffffff)
Definition: history.cpp:213
unsigned int BOOL
Definition: ntddk_ex.h:94
int undoSteps
Definition: history.h:21
#define WM_IMAGEMODELDIMENSIONSCHANGED
Definition: definitions.h:246
void StretchSkew(int nStretchPercentX, int nStretchPercentY, int nSkewDegX=0, int nSkewDegY=0)
Definition: history.cpp:183
void RotateNTimes90Degrees(int iN)
Definition: history.cpp:240
BOOL imageSaved
Definition: history.h:24
int GetWidth()
Definition: history.cpp:195
int GetHeight()
Definition: history.cpp:200
#define WM_IMAGEMODELIMAGECHANGED
Definition: definitions.h:247
BOOL HasUndoSteps()
Definition: history.cpp:173
PaletteModel paletteModel
Definition: main.cpp:28
BOOL WINAPI DeleteDC(_In_ HDC)
_In_ HBITMAP hbm
Definition: ntgdi.h:2776
void NotifyDimensionsChanged()
Definition: history.cpp:15
HBRUSH WINAPI CreateSolidBrush(_In_ COLORREF)
#define IMAGE_BITMAP
Definition: winuser.h:211
void Undo(void)
Definition: history.cpp:57
void FlipVertically()
Definition: history.cpp:232
LRESULT SendMessage(UINT message, WPARAM wParam=0, LPARAM lParam=0)
Definition: atlwin.h:1039
void NotifyImageChanged()
Definition: history.cpp:20
#define HISTORYSIZE
Definition: definitions.h:13
DWORD COLORREF
Definition: windef.h:290
void ResetToPrevious(void)
Definition: history.cpp:93
#define SRCCOPY
Definition: wingdi.h:331
int fileVPPM
Definition: main.cpp:56
HBITMAP hBms[HISTORYSIZE]
Definition: history.h:18
_In_ LPCSTR lpFileName
Definition: winbase.h:3011
CSelectionWindow selectionWindow
Definition: main.cpp:70