ReactOS 0.4.15-dev-5836-g942b022
ImageModel Class Reference

#include <history.h>

Collaboration diagram for ImageModel:

Public Member Functions

 ImageModel ()
 
void CopyPrevious (void)
 
void Undo (BOOL bClearRedo=FALSE)
 
void Redo (void)
 
void ResetToPrevious (void)
 
void ClearHistory (void)
 
void Insert (HBITMAP hbm)
 
void Crop (int nWidth, int nHeight, int nOffsetX=0, int nOffsetY=0)
 
void SaveImage (LPTSTR lpFileName)
 
BOOL IsImageSaved () const
 
BOOL HasUndoSteps () const
 
BOOL HasRedoSteps () const
 
void StretchSkew (int nStretchPercentX, int nStretchPercentY, int nSkewDegX=0, int nSkewDegY=0)
 
int GetWidth () const
 
int GetHeight () const
 
void InvertColors ()
 
void Clear (COLORREF color=0x00ffffff)
 
HDC GetDC ()
 
void FlipHorizontally ()
 
void FlipVertically ()
 
void RotateNTimes90Degrees (int iN)
 
void DrawSelectionBackground (COLORREF rgbBG)
 
void DeleteSelection ()
 
void Bound (POINT &pt)
 

Public Attributes

HBITMAP hBms [HISTORYSIZE]
 

Private Member Functions

void NotifyDimensionsChanged ()
 
void NotifyImageChanged ()
 

Private Attributes

HDC hDrawingDC
 
int currInd
 
int undoSteps
 
int redoSteps
 

Detailed Description

Definition at line 14 of file history.h.

Constructor & Destructor Documentation

◆ ImageModel()

ImageModel::ImageModel ( )

Definition at line 27 of file history.cpp.

28{
29 currInd = 0;
30 undoSteps = 0;
31 redoSteps = 0;
33
34 // prepare a minimal usable bitmap
35 int imgXRes = 1;
36 int imgYRes = 1;
37
41
42 hBms[0] = CreateDIBWithProperties(imgXRes, imgYRes);
44 Rectangle(hDrawingDC, 0 - 1, 0 - 1, imgXRes + 1, imgYRes + 1);
45}
HDC hDrawingDC
Definition: history.h:19
int currInd
Definition: history.h:23
HBITMAP hBms[HISTORYSIZE]
Definition: history.h:21
int redoSteps
Definition: history.h:25
int undoSteps
Definition: history.h:24
COLORREF GetBgColor() const
COLORREF GetFgColor() const
HBITMAP CreateDIBWithProperties(int width, int height)
Definition: dib.cpp:17
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
BOOL imageSaved
Definition: main.cpp:42
PaletteModel paletteModel
Definition: main.cpp:24
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1539
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
BOOL WINAPI Rectangle(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int)
HBRUSH WINAPI CreateSolidBrush(_In_ COLORREF)
HPEN WINAPI CreatePen(_In_ int, _In_ int, _In_ COLORREF)
#define PS_SOLID
Definition: wingdi.h:586

Member Function Documentation

◆ Bound()

void ImageModel::Bound ( POINT pt)

Definition at line 305 of file history.cpp.

306{
307 pt.x = max(0, min(pt.x, GetWidth()));
308 pt.y = max(0, min(pt.y, GetHeight()));
309}
int GetWidth() const
Definition: history.cpp:215
int GetHeight() const
Definition: history.cpp:220
#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 FreeSelTool::OnMouseMove(), RectSelTool::OnMouseMove(), and TextTool::UpdatePoint().

◆ Clear()

void ImageModel::Clear ( COLORREF  color = 0x00ffffff)

Definition at line 233 of file history.cpp.

234{
235 Rectangle(hDrawingDC, 0 - 1, 0 - 1, GetWidth() + 1, GetHeight() + 1);
237}
void NotifyImageChanged()
Definition: history.cpp:21

◆ ClearHistory()

void ImageModel::ClearHistory ( void  )

Definition at line 109 of file history.cpp.

110{
111 undoSteps = 0;
112 redoSteps = 0;
113}

Referenced by _tWinMain(), and SetBitmapAndInfo().

◆ CopyPrevious()

◆ Crop()

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

Definition at line 131 of file history.cpp.

132{
133 HDC hdc;
134 HPEN oldPen;
135 HBRUSH oldBrush;
136 int oldWidth = GetWidth();
137 int oldHeight = GetHeight();
138
139 if (nWidth <= 0)
140 nWidth = 1;
141 if (nHeight <= 0)
142 nHeight = 1;
143
146 hBms[(currInd + 1) % HISTORYSIZE] = CreateDIBWithProperties(nWidth, nHeight);
147 currInd = (currInd + 1) % HISTORYSIZE;
148 if (undoSteps < HISTORYSIZE - 1)
149 undoSteps++;
150 redoSteps = 0;
151
154
155 oldPen = (HPEN) SelectObject(hdc, CreatePen(PS_SOLID, 1, paletteModel.GetBgColor()));
157 Rectangle(hdc, 0, 0, nWidth, nHeight);
158 BitBlt(hdc, -nOffsetX, -nOffsetY, GetWidth(), GetHeight(), hDrawingDC, 0, 0, SRCCOPY);
159 DeleteObject(SelectObject(hdc, oldBrush));
160 DeleteObject(SelectObject(hdc, oldPen));
161 DeleteDC(hdc);
163
164 if (GetWidth() != oldWidth || GetHeight() != oldHeight)
167}
void NotifyDimensionsChanged()
Definition: history.cpp:15
static VOID NTAPI BitBlt(_In_ ULONG Left, _In_ ULONG Top, _In_ ULONG Width, _In_ ULONG Height, _In_reads_bytes_(Delta *Height) PUCHAR Buffer, _In_ ULONG BitsPerPixel, _In_ ULONG Delta)
Definition: common.c:49
HDC hdc
Definition: main.c:9
static HDC
Definition: imagelist.c:92
#define SRCCOPY
Definition: wingdi.h:333
BOOL WINAPI DeleteDC(_In_ HDC)

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

◆ DeleteSelection()

void ImageModel::DeleteSelection ( )

Definition at line 293 of file history.cpp.

294{
295 if (selectionWindow.IsWindowVisible())
297 CopyPrevious();
298 if (selectionWindow.IsWindowVisible())
299 Undo(TRUE);
301 selectionWindow.ShowWindow(SW_HIDE);
303}
void ResetToPrevious(void)
Definition: history.cpp:100
void CopyPrevious(void)
Definition: history.cpp:47
void DrawSelectionBackground(COLORREF rgbBG)
Definition: history.cpp:285
CSelectionWindow selectionWindow
Definition: main.cpp:58
void Undo(void)
Definition: solundo.cpp:53
#define SW_HIDE
Definition: winuser.h:762

Referenced by CMainWindow::OnCommand(), SelectionModel::RotateNTimes90Degrees(), and SelectionModel::StretchSkew().

◆ DrawSelectionBackground()

void ImageModel::DrawSelectionBackground ( COLORREF  rgbBG)

Definition at line 285 of file history.cpp.

286{
289 else
291}
void DrawBackgroundPoly(HDC hDCImage, COLORREF crBg)
void DrawBackgroundRect(HDC hDCImage, COLORREF crBg)
TOOLTYPE GetActiveTool() const
Definition: toolsmodel.cpp:76
ToolsModel toolsModel
Definition: main.cpp:20
SelectionModel selectionModel
Definition: main.cpp:22
@ TOOL_FREESEL
Definition: toolsmodel.h:13

Referenced by DeleteSelection(), CSelectionWindow::ForceRefreshSelectionContents(), CSelectionWindow::OnLButtonUp(), and CSelectionWindow::OnMouseMove().

◆ FlipHorizontally()

void ImageModel::FlipHorizontally ( )

Definition at line 244 of file history.cpp.

245{
246 CopyPrevious();
247 StretchBlt(hDrawingDC, GetWidth() - 1, 0, -GetWidth(), GetHeight(), GetDC(), 0, 0,
250}
HDC GetDC()
Definition: history.cpp:239
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)

Referenced by CMainWindow::OnCommand().

◆ FlipVertically()

void ImageModel::FlipVertically ( )

Definition at line 252 of file history.cpp.

253{
254 CopyPrevious();
255 StretchBlt(hDrawingDC, 0, GetHeight() - 1, GetWidth(), -GetHeight(), GetDC(), 0, 0,
258}

Referenced by CMainWindow::OnCommand().

◆ GetDC()

◆ GetHeight()

◆ GetWidth()

◆ HasRedoSteps()

BOOL ImageModel::HasRedoSteps ( ) const

Definition at line 184 of file history.cpp.

185{
186 return redoSteps > 0;
187}

Referenced by CMainWindow::OnInitMenuPopup().

◆ HasUndoSteps()

BOOL ImageModel::HasUndoSteps ( ) const

Definition at line 179 of file history.cpp.

180{
181 return undoSteps > 0;
182}

Referenced by CMainWindow::OnInitMenuPopup().

◆ Insert()

void ImageModel::Insert ( HBITMAP  hbm)

Definition at line 115 of file history.cpp.

116{
117 int oldWidth = GetWidth();
118 int oldHeight = GetHeight();
120 hBms[(currInd + 1) % HISTORYSIZE] = hbm;
121 currInd = (currInd + 1) % HISTORYSIZE;
122 if (undoSteps < HISTORYSIZE - 1)
123 undoSteps++;
124 redoSteps = 0;
126 if (GetWidth() != oldWidth || GetHeight() != oldHeight)
129}
_In_ HBITMAP hbm
Definition: ntgdi.h:2776

Referenced by CMainWindow::OnCommand(), SetBitmapAndInfo(), and StretchSkew().

◆ InvertColors()

void ImageModel::InvertColors ( )

Definition at line 225 of file history.cpp.

226{
227 RECT rect = {0, 0, GetWidth(), GetHeight()};
228 CopyPrevious();
231}
& rect
Definition: startmenu.cpp:1413
BOOL WINAPI InvertRect(_In_ HDC, _In_ LPCRECT)

Referenced by CMainWindow::OnCommand().

◆ IsImageSaved()

BOOL ImageModel::IsImageSaved ( ) const

Definition at line 174 of file history.cpp.

175{
176 return imageSaved;
177}

Referenced by CMainWindow::ConfirmSave().

◆ NotifyDimensionsChanged()

void ImageModel::NotifyDimensionsChanged ( )
private

Definition at line 15 of file history.cpp.

16{
17 if (imageArea.IsWindow())
19}
#define WM_IMAGEMODELDIMENSIONSCHANGED
Definition: precomp.h:38
CImgAreaWindow imageArea
Definition: main.cpp:59

Referenced by Crop(), Insert(), Redo(), RotateNTimes90Degrees(), StretchSkew(), and Undo().

◆ NotifyImageChanged()

void ImageModel::NotifyImageChanged ( )
private

Definition at line 21 of file history.cpp.

22{
23 if (imageArea.IsWindow())
25}
#define WM_IMAGEMODELIMAGECHANGED
Definition: precomp.h:39

Referenced by Clear(), Crop(), DeleteSelection(), FlipHorizontally(), FlipVertically(), Insert(), InvertColors(), Redo(), ResetToPrevious(), RotateNTimes90Degrees(), StretchSkew(), and Undo().

◆ Redo()

void ImageModel::Redo ( void  )

Definition at line 81 of file history.cpp.

82{
83 ATLTRACE("%s: %d\n", __FUNCTION__, redoSteps);
84 if (redoSteps > 0)
85 {
86 int oldWidth = GetWidth();
87 int oldHeight = GetHeight();
88 selectionWindow.ShowWindow(SW_HIDE);
89 currInd = (currInd + 1) % HISTORYSIZE;
91 redoSteps--;
92 if (undoSteps < HISTORYSIZE - 1)
93 undoSteps++;
94 if (GetWidth() != oldWidth || GetHeight() != oldHeight)
97 }
98}

Referenced by CMainWindow::OnCommand().

◆ ResetToPrevious()

◆ RotateNTimes90Degrees()

void ImageModel::RotateNTimes90Degrees ( int  iN)

Definition at line 260 of file history.cpp.

261{
262 switch (iN)
263 {
264 case 1:
265 case 3:
268 currInd = (currInd + 1) % HISTORYSIZE;
269 if (undoSteps < HISTORYSIZE - 1)
270 undoSteps++;
271 redoSteps = 0;
275 break;
276 case 2:
277 CopyPrevious();
279 0, 0, GetWidth(), GetHeight(), SRCCOPY);
280 break;
281 }
283}
HBITMAP Rotate90DegreeBlt(HDC hDC1, INT cx, INT cy, BOOL bRight)
Definition: dib.cpp:212

Referenced by CMainWindow::OnCommand().

◆ SaveImage()

void ImageModel::SaveImage ( LPTSTR  lpFileName)

Definition at line 169 of file history.cpp.

170{
172}
BOOL SaveDIBToFile(HBITMAP hBitmap, LPTSTR FileName, HDC hDC)
Definition: dib.cpp:69
_In_ LPCSTR lpFileName
Definition: winbase.h:3058

Referenced by CMainWindow::saveImage().

◆ StretchSkew()

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

Definition at line 189 of file history.cpp.

190{
191 int oldWidth = GetWidth();
192 int oldHeight = GetHeight();
193 INT newWidth = oldWidth * nStretchPercentX / 100;
194 INT newHeight = oldHeight * nStretchPercentY / 100;
195 if (oldWidth != newWidth || oldHeight != newHeight)
196 {
197 HBITMAP hbm0 = CopyDIBImage(hBms[currInd], newWidth, newHeight);
198 Insert(hbm0);
199 }
200 if (nSkewDegX)
201 {
202 HBITMAP hbm1 = SkewDIB(hDrawingDC, hBms[currInd], nSkewDegX, FALSE);
203 Insert(hbm1);
204 }
205 if (nSkewDegY)
206 {
207 HBITMAP hbm2 = SkewDIB(hDrawingDC, hBms[currInd], nSkewDegY, TRUE);
208 Insert(hbm2);
209 }
210 if (GetWidth() != oldWidth || GetHeight() != oldHeight)
213}
void Insert(HBITMAP hbm)
Definition: history.cpp:115
HBITMAP SkewDIB(HDC hDC1, HBITMAP hbm, INT nDegree, BOOL bVertical)
Definition: dib.cpp:251
static HBITMAP
Definition: button.c:44
int32_t INT
Definition: typedefs.h:58

Referenced by CMainWindow::OnCommand().

◆ Undo()

void ImageModel::Undo ( BOOL  bClearRedo = FALSE)

Member Data Documentation

◆ currInd

int ImageModel::currInd
private

◆ hBms

◆ hDrawingDC

◆ redoSteps

int ImageModel::redoSteps
private

◆ undoSteps

int ImageModel::undoSteps
private

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