ReactOS 0.4.16-dev-1025-gd3456f5
ImageModel Class Reference

#include <history.h>

Collaboration diagram for ImageModel:

Public Member Functions

 ImageModel ()
 
virtual ~ImageModel ()
 
HDC GetDC ()
 
BOOL CanUndo () const
 
BOOL CanRedo () const
 
void PushImageForUndo ()
 
void PushImageForUndo (HBITMAP hbm)
 
void PushImageForUndo (const RECT &rcPartial)
 
void Undo (BOOL bClearRedo=FALSE)
 
void Redo (void)
 
void ClearHistory (void)
 
void Crop (int nWidth, int nHeight, int nOffsetX=0, int nOffsetY=0)
 
void SaveImage (LPCWSTR lpFileName)
 
BOOL IsImageSaved () const
 
void StretchSkew (int nStretchPercentX, int nStretchPercentY, int nSkewDegX=0, int nSkewDegY=0)
 
int GetWidth () const
 
int GetHeight () const
 
HBITMAP CopyBitmap ()
 
HBITMAP LockBitmap ()
 
void UnlockBitmap (HBITMAP hbmLocked)
 
void InvertColors ()
 
void FlipHorizontally ()
 
void FlipVertically ()
 
void RotateNTimes90Degrees (int iN)
 
void Clamp (POINT &pt) const
 
void NotifyImageChanged ()
 
BOOL IsBlackAndWhite ()
 
void PushBlackAndWhite ()
 

Protected Member Functions

void SwapPart ()
 
void PushDone ()
 

Protected Attributes

HDC m_hDrawingDC
 
HBITMAP m_hbmMaster
 
int m_currInd
 
int m_undoSteps
 
int m_redoSteps
 
IMAGE_PART m_historyItems [HISTORYSIZE]
 
HGDIOBJ m_hbmOld
 

Detailed Description

Definition at line 22 of file history.h.

Constructor & Destructor Documentation

◆ ImageModel()

ImageModel::ImageModel ( )

Definition at line 35 of file history.cpp.

37 , m_currInd(0)
38 , m_undoSteps(0)
39 , m_redoSteps(0)
40{
42
43 m_hbmMaster = CreateColorDIB(1, 1, RGB(255, 255, 255));
45
47}
BOOL g_imageSaved
Definition: main.cpp:21
int m_undoSteps
Definition: history.h:59
HGDIOBJ m_hbmOld
Definition: history.h:62
int m_redoSteps
Definition: history.h:60
HBITMAP m_hbmMaster
Definition: history.h:57
int m_currInd
Definition: history.h:58
HDC m_hDrawingDC
Definition: history.h:56
IMAGE_PART m_historyItems[HISTORYSIZE]
Definition: history.h:61
HBITMAP CreateColorDIB(int width, int height, COLORREF rgb)
Definition: dib.cpp:65
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define RGB(r, g, b)
Definition: precomp.h:71
#define ZeroMemory
Definition: winbase.h:1743
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1546
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)

◆ ~ImageModel()

ImageModel::~ImageModel ( )
virtual

Definition at line 49 of file history.cpp.

50{
55}
void ClearHistory(void)
Definition: history.cpp:116
pKey DeleteObject()
BOOL WINAPI DeleteDC(_In_ HDC)

Member Function Documentation

◆ CanRedo()

BOOL ImageModel::CanRedo ( ) const
inline

Definition at line 30 of file history.h.

30{ return m_redoSteps > 0; }

Referenced by CMainWindow::CanRedo(), and Redo().

◆ CanUndo()

BOOL ImageModel::CanUndo ( ) const
inline

Definition at line 29 of file history.h.

29{ return m_undoSteps > 0; }

Referenced by CMainWindow::CanUndo(), and Undo().

◆ Clamp()

void ImageModel::Clamp ( POINT pt) const

Definition at line 317 of file history.cpp.

318{
319 pt.x = max(0, min(pt.x, GetWidth()));
320 pt.y = max(0, min(pt.y, GetHeight()));
321}
int GetWidth() const
Definition: history.cpp:256
int GetHeight() const
Definition: history.cpp:261
#define pt(x, y)
Definition: drawing.c:79
#define min(a, b)
Definition: monoChain.cc:55
#define max(a, b)
Definition: svc.c:63

Referenced by SelectionBaseTool::OnButtonDown(), SelectionBaseTool::OnButtonUp(), TextTool::OnButtonUp(), SelectionBaseTool::OnMouseMove(), and TextTool::UpdatePoint().

◆ ClearHistory()

void ImageModel::ClearHistory ( void  )

Definition at line 116 of file history.cpp.

117{
118 for (int i = 0; i < HISTORYSIZE; ++i)
119 {
121 }
122
123 m_undoSteps = 0;
124 m_redoSteps = 0;
125}
#define HISTORYSIZE
Definition: history.h:11
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
void clear()
Definition: history.cpp:15

Referenced by Crop(), DoLoadImageFile(), InitializeImage(), CMainWindow::OnCommand(), CCanvasWindow::OnPaint(), PushImageForUndo(), SetBitmapAndInfo(), and ~ImageModel().

◆ CopyBitmap()

HBITMAP ImageModel::CopyBitmap ( )

Definition at line 323 of file history.cpp.

324{
328 return ret;
329}
static HBITMAP CopyDIBImage(HBITMAP hbm, INT cx=0, INT cy=0)
Definition: dib.h:19
HBITMAP LockBitmap()
Definition: history.cpp:348
void UnlockBitmap(HBITMAP hbmLocked)
Definition: history.cpp:357
static HBITMAP hBitmap
Definition: timezone.c:26
static HBITMAP
Definition: button.c:44
int ret

Referenced by PushImageForUndo().

◆ Crop()

void ImageModel::Crop ( int  nWidth,
int  nHeight,
int  nOffsetX = 0,
int  nOffsetY = 0 
)

Definition at line 193 of file history.cpp.

194{
195 // We cannot create bitmaps of size zero
196 if (nWidth <= 0)
197 nWidth = 1;
198 if (nHeight <= 0)
199 nHeight = 1;
200
201 // Create a white HBITMAP
202 HBITMAP hbmNew = CreateColorDIB(nWidth, nHeight, RGB(255, 255, 255));
203 if (!hbmNew)
204 {
206 ClearHistory();
207 return;
208 }
209
210 // Put the master image as a sub-image
211 RECT rcPart = { -nOffsetX, -nOffsetY, GetWidth() - nOffsetX, GetHeight() - nOffsetY };
212 HBITMAP hbmOld = imageModel.LockBitmap();
213 putSubImage(hbmNew, rcPart, hbmOld);
214 imageModel.UnlockBitmap(hbmOld);
215
216 // Push it
217 PushImageForUndo(hbmNew);
218
220}
void ShowOutOfMemory(void)
Definition: main.cpp:34
void PushImageForUndo()
Definition: history.cpp:127
void NotifyImageChanged()
Definition: history.cpp:23
void putSubImage(HBITMAP hbmWhole, const RECT &rcPartial, HBITMAP hbmPart)
Definition: dib.cpp:429
ImageModel imageModel
Definition: history.cpp:11

Referenced by CMainWindow::InsertSelectionFromHBITMAP(), CCanvasWindow::OnButtonUp(), and CMainWindow::OnCommand().

◆ FlipHorizontally()

void ImageModel::FlipHorizontally ( )

Definition at line 279 of file history.cpp.

280{
282 StretchBlt(m_hDrawingDC, GetWidth() - 1, 0, -GetWidth(), GetHeight(), GetDC(), 0, 0,
285}
HDC GetDC()
Definition: history.cpp:274
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)
#define SRCCOPY
Definition: wingdi.h:333

Referenced by CMainWindow::OnCommand().

◆ FlipVertically()

void ImageModel::FlipVertically ( )

Definition at line 287 of file history.cpp.

288{
290 StretchBlt(m_hDrawingDC, 0, GetHeight() - 1, GetWidth(), -GetHeight(), GetDC(), 0, 0,
293}

Referenced by CMainWindow::OnCommand().

◆ GetDC()

◆ GetHeight()

◆ GetWidth()

◆ InvertColors()

void ImageModel::InvertColors ( )

Definition at line 266 of file history.cpp.

267{
268 RECT rect = {0, 0, GetWidth(), GetHeight()};
272}
& rect
Definition: startmenu.cpp:1413
BOOL WINAPI InvertRect(_In_ HDC, _In_ LPCRECT)

Referenced by CMainWindow::OnCommand().

◆ IsBlackAndWhite()

BOOL ImageModel::IsBlackAndWhite ( )

Definition at line 331 of file history.cpp.

332{
334 BOOL bBlackAndWhite = IsBitmapBlackAndWhite(hBitmap);
336 return bBlackAndWhite;
337}
BOOL IsBitmapBlackAndWhite(HBITMAP hbm)
Definition: dib.cpp:581
unsigned int BOOL
Definition: ntddk_ex.h:94

Referenced by CMainWindow::OnCommand(), and CAttributesDialog::OnInitDialog().

◆ IsImageSaved()

BOOL ImageModel::IsImageSaved ( ) const

Definition at line 227 of file history.cpp.

228{
229 return g_imageSaved;
230}

Referenced by CMainWindow::ConfirmSave(), and OpenMailer().

◆ LockBitmap()

HBITMAP ImageModel::LockBitmap ( )

Definition at line 348 of file history.cpp.

349{
350 // NOTE: An app cannot select a bitmap into more than one device context at a time.
351 ::SelectObject(m_hDrawingDC, m_hbmOld); // De-select
352 HBITMAP hbmLocked = m_hbmMaster;
354 return hbmLocked;
355}

Referenced by CopyBitmap(), Crop(), SelectionModel::GetSelectionContents(), IsBlackAndWhite(), OpenMailer(), PushBlackAndWhite(), PushImageForUndo(), RegistrySettings::SetWallpaper(), and SwapPart().

◆ NotifyImageChanged()

void ImageModel::NotifyImageChanged ( )

◆ PushBlackAndWhite()

void ImageModel::PushBlackAndWhite ( )

Definition at line 339 of file history.cpp.

340{
344
345 PushImageForUndo(hNewBitmap);
346}
HBITMAP ConvertToBlackAndWhite(HBITMAP hbm)
Definition: dib.cpp:632

Referenced by CMainWindow::OnCommand().

◆ PushDone()

void ImageModel::PushDone ( )
protected

Definition at line 181 of file history.cpp.

182{
183 m_currInd = (m_currInd + 1) % HISTORYSIZE; // Go next
184
185 if (m_undoSteps < HISTORYSIZE - 1)
186 m_undoSteps++;
187 m_redoSteps = 0;
188
191}
#define FALSE
Definition: types.h:117

Referenced by PushImageForUndo().

◆ PushImageForUndo() [1/3]

◆ PushImageForUndo() [2/3]

void ImageModel::PushImageForUndo ( const RECT rcPartial)

Definition at line 160 of file history.cpp.

161{
162 ATLTRACE("%s: %d\n", __FUNCTION__, m_currInd);
163
165 part.clear();
166 part.m_bPartial = TRUE;
167 part.m_rcPart = rcPartial;
168
169 CRect rcImage = { 0, 0, GetWidth(), GetHeight() };
170 CRect& rc = part.m_rcPart;
171 if (!rc.IntersectRect(rc, rcImage))
172 rc.SetRect(-1, -1, 0, 0);
173
174 HBITMAP hbmMaster = LockBitmap();
175 part.m_hbmImage = getSubImage(hbmMaster, rc);
176 UnlockBitmap(hbmMaster);
177
178 PushDone();
179}
#define ATLTRACE(format,...)
Definition: atltrace.h:269
BOOL IntersectRect(LPCRECT lpRect1, LPCRECT lpRect2) noexcept
Definition: atltypes.h:346
void SetRect(int x1, int y1, int x2, int y2) noexcept
Definition: atltypes.h:423
void PushDone()
Definition: history.cpp:181
HBITMAP getSubImage(HBITMAP hbmWhole, const RECT &rcPartial)
Definition: dib.cpp:410
#define __FUNCTION__
Definition: types.h:116
CRect m_rcPart
Definition: history.h:15
HBITMAP m_hbmImage
Definition: history.h:16
BOOL m_bPartial
Definition: history.h:17

◆ PushImageForUndo() [3/3]

void ImageModel::PushImageForUndo ( HBITMAP  hbm)

Definition at line 140 of file history.cpp.

141{
142 ATLTRACE("%s: %d\n", __FUNCTION__, m_currInd);
143
144 if (hbm == NULL)
145 {
147 ClearHistory();
148 return;
149 }
150
152 part.clear();
153 part.m_hbmImage = m_hbmMaster;
156
157 PushDone();
158}

◆ Redo()

void ImageModel::Redo ( void  )

Definition at line 96 of file history.cpp.

97{
98 ATLTRACE("%s: %d\n", __FUNCTION__, m_redoSteps);
99 if (!CanRedo())
100 return;
101
103
105 SwapPart();
106 m_currInd = (m_currInd + 1) % HISTORYSIZE; // Go next
108
109 m_redoSteps--;
110 if (m_undoSteps < HISTORYSIZE - 1)
111 m_undoSteps++;
112
114}
#define ATLASSERT(x)
Definition: CComVariant.cpp:10
SelectionModel selectionModel
void SwapPart()
Definition: history.cpp:57
BOOL CanRedo() const
Definition: history.h:30

Referenced by CMainWindow::OnCommand().

◆ RotateNTimes90Degrees()

void ImageModel::RotateNTimes90Degrees ( int  iN)

Definition at line 295 of file history.cpp.

296{
297 switch (iN)
298 {
299 case 1:
300 case 3:
301 {
304 break;
305 }
306 case 2:
307 {
311 break;
312 }
313 }
315}
HBITMAP Rotate90DegreeBlt(HDC hDC1, INT cx, INT cy, BOOL bRight, BOOL bMono)
Definition: dib.cpp:313

Referenced by CMainWindow::OnCommand().

◆ SaveImage()

void ImageModel::SaveImage ( LPCWSTR  lpFileName)

Definition at line 222 of file history.cpp.

223{
225}
BOOL SaveDIBToFile(HBITMAP hBitmap, LPCWSTR FileName, BOOL fIsMainFile, REFGUID guidFileType)
Definition: dib.cpp:151
_In_ LPCSTR lpFileName
Definition: winbase.h:3102

Referenced by CMainWindow::saveImage().

◆ StretchSkew()

void ImageModel::StretchSkew ( int  nStretchPercentX,
int  nStretchPercentY,
int  nSkewDegX = 0,
int  nSkewDegY = 0 
)

Definition at line 232 of file history.cpp.

233{
234 int oldWidth = GetWidth();
235 int oldHeight = GetHeight();
236 INT newWidth = oldWidth * nStretchPercentX / 100;
237 INT newHeight = oldHeight * nStretchPercentY / 100;
238 if (oldWidth != newWidth || oldHeight != newHeight)
239 {
240 HBITMAP hbm0 = CopyDIBImage(m_hbmMaster, newWidth, newHeight);
241 PushImageForUndo(hbm0);
242 }
243 if (nSkewDegX)
244 {
245 HBITMAP hbm1 = SkewDIB(m_hDrawingDC, m_hbmMaster, nSkewDegX, FALSE);
246 PushImageForUndo(hbm1);
247 }
248 if (nSkewDegY)
249 {
250 HBITMAP hbm2 = SkewDIB(m_hDrawingDC, m_hbmMaster, nSkewDegY, TRUE);
251 PushImageForUndo(hbm2);
252 }
254}
HBITMAP SkewDIB(HDC hDC1, HBITMAP hbm, INT nDegree, BOOL bVertical, BOOL bMono)
Definition: dib.cpp:352
int32_t INT
Definition: typedefs.h:58

Referenced by CMainWindow::OnCommand().

◆ SwapPart()

void ImageModel::SwapPart ( )
protected

Definition at line 57 of file history.cpp.

58{
60 if (!part.m_bPartial)
61 {
63 return;
64 }
65
66 HBITMAP hbmMaster = LockBitmap();
67 HBITMAP hbmPart = getSubImage(hbmMaster, part.m_rcPart);
68 putSubImage(hbmMaster, part.m_rcPart, part.m_hbmImage);
70 part.m_hbmImage = hbmPart;
71 UnlockBitmap(hbmMaster);
72}
#define Swap(a, b)
Definition: geom.c:201

Referenced by Redo(), and Undo().

◆ Undo()

void ImageModel::Undo ( BOOL  bClearRedo = FALSE)

Definition at line 74 of file history.cpp.

75{
76 ATLTRACE("%s: %d\n", __FUNCTION__, m_undoSteps);
77 if (!CanUndo())
78 return;
79
81
82 m_currInd = (m_currInd + HISTORYSIZE - 1) % HISTORYSIZE; // Go previous
84 SwapPart();
86
88 if (bClearRedo)
89 m_redoSteps = 0;
90 else if (m_redoSteps < HISTORYSIZE - 1)
92
94}
BOOL CanUndo() const
Definition: history.h:29

Referenced by CMainWindow::OnCommand().

◆ UnlockBitmap()

Member Data Documentation

◆ m_currInd

int ImageModel::m_currInd
protected

Definition at line 58 of file history.h.

Referenced by PushDone(), PushImageForUndo(), Redo(), SwapPart(), and Undo().

◆ m_hbmMaster

HBITMAP ImageModel::m_hbmMaster
protected

◆ m_hbmOld

HGDIOBJ ImageModel::m_hbmOld
protected

Definition at line 62 of file history.h.

Referenced by ImageModel(), LockBitmap(), UnlockBitmap(), and ~ImageModel().

◆ m_hDrawingDC

◆ m_historyItems

IMAGE_PART ImageModel::m_historyItems[HISTORYSIZE]
protected

Definition at line 61 of file history.h.

Referenced by ClearHistory(), ImageModel(), PushImageForUndo(), and SwapPart().

◆ m_redoSteps

int ImageModel::m_redoSteps
protected

Definition at line 60 of file history.h.

Referenced by CanRedo(), ClearHistory(), PushDone(), Redo(), and Undo().

◆ m_undoSteps

int ImageModel::m_undoSteps
protected

Definition at line 59 of file history.h.

Referenced by CanUndo(), ClearHistory(), PushDone(), Redo(), and Undo().


The documentation for this class was generated from the following files: