ReactOS  0.4.15-dev-1152-g6c94e4f
ImageModel Class Reference

#include <history.h>

Collaboration diagram for ImageModel:

Public Member Functions

 ImageModel ()
 
void CopyPrevious (void)
 
void Undo (void)
 
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 ()
 
BOOL HasUndoSteps ()
 
BOOL HasRedoSteps ()
 
void StretchSkew (int nStretchPercentX, int nStretchPercentY, int nSkewDegX=0, int nSkewDegY=0)
 
int GetWidth ()
 
int GetHeight ()
 
void InvertColors ()
 
void Clear (COLORREF color=0x00ffffff)
 
HDC GetDC ()
 
void FlipHorizontally ()
 
void FlipVertically ()
 
void RotateNTimes90Degrees (int iN)
 

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 11 of file history.h.

Constructor & Destructor Documentation

◆ ImageModel()

ImageModel::ImageModel ( )

Definition at line 25 of file history.cpp.

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 }
int redoSteps
Definition: history.h:22
HPEN WINAPI CreatePen(_In_ int, _In_ int, _In_ COLORREF)
int currInd
Definition: history.h:20
BOOL WINAPI Rectangle(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int)
#define TRUE
Definition: types.h:120
HDC hDrawingDC
Definition: history.h:16
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1499
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
#define PS_SOLID
Definition: wingdi.h:585
smooth NULL
Definition: ftsmooth.c:416
HBITMAP CreateDIBWithProperties(int width, int height)
Definition: dib.cpp:16
int undoSteps
Definition: history.h:21
BOOL imageSaved
Definition: main.cpp:54
PaletteModel paletteModel
Definition: main.cpp:28
HBRUSH WINAPI CreateSolidBrush(_In_ COLORREF)
HBITMAP hBms[HISTORYSIZE]
Definition: history.h:18

Member Function Documentation

◆ Clear()

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

Definition at line 212 of file history.cpp.

213 {
214  Rectangle(hDrawingDC, 0 - 1, 0 - 1, GetWidth() + 1, GetHeight() + 1);
216 }
BOOL WINAPI Rectangle(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int)
HDC hDrawingDC
Definition: history.h:16
int GetWidth()
Definition: history.cpp:194
int GetHeight()
Definition: history.cpp:199
void NotifyImageChanged()
Definition: history.cpp:20

◆ ClearHistory()

void ImageModel::ClearHistory ( void  )

Definition at line 102 of file history.cpp.

103 {
104  undoSteps = 0;
105  redoSteps = 0;
106 }
int redoSteps
Definition: history.h:22
int undoSteps
Definition: history.h:21

Referenced by SetBitmapAndInfo().

◆ CopyPrevious()

void ImageModel::CopyPrevious ( void  )

Definition at line 45 of file history.cpp.

46 {
49  currInd = (currInd + 1) % HISTORYSIZE;
50  if (undoSteps < HISTORYSIZE - 1)
51  undoSteps++;
52  redoSteps = 0;
54  imageSaved = FALSE;
55 }
int redoSteps
Definition: history.h:22
int currInd
Definition: history.h:20
HDC hDrawingDC
Definition: history.h:16
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1499
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
#define LR_COPYRETURNORG
Definition: winuser.h:1080
#define FALSE
Definition: types.h:117
HANDLE WINAPI CopyImage(_In_ HANDLE, _In_ UINT, _In_ int, _In_ int, _In_ UINT)
Definition: cursoricon.c:1956
int undoSteps
Definition: history.h:21
BOOL imageSaved
Definition: main.cpp:54
#define IMAGE_BITMAP
Definition: winuser.h:211
static HBITMAP
Definition: button.c:44
#define HISTORYSIZE
Definition: definitions.h:13
HBITMAP hBms[HISTORYSIZE]
Definition: history.h:18

Referenced by endPaintingL(), FlipHorizontally(), FlipVertically(), CMainWindow::InsertSelectionFromHBITMAP(), InvertColors(), CMainWindow::OnCommand(), RotateNTimes90Degrees(), startPaintingL(), startPaintingR(), and whilePaintingL().

◆ Crop()

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

Definition at line 124 of file history.cpp.

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 
139  hBms[(currInd + 1) % HISTORYSIZE] = CreateDIBWithProperties(nWidth, nHeight);
140  currInd = (currInd + 1) % HISTORYSIZE;
141  if (undoSteps < HISTORYSIZE - 1)
142  undoSteps++;
143  redoSteps = 0;
144 
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);
156 
157  if (GetWidth() != oldWidth || GetHeight() != oldHeight)
160 }
int redoSteps
Definition: history.h:22
HPEN WINAPI CreatePen(_In_ int, _In_ int, _In_ COLORREF)
int currInd
Definition: history.h:20
BOOL WINAPI Rectangle(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int)
static HDC
Definition: imagelist.c:92
HDC hDrawingDC
Definition: history.h:16
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1499
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
#define PS_SOLID
Definition: wingdi.h:585
HBITMAP CreateDIBWithProperties(int width, int height)
Definition: dib.cpp:16
int undoSteps
Definition: history.h:21
int GetWidth()
Definition: history.cpp:194
int GetHeight()
Definition: history.cpp:199
HDC hdc
Definition: main.c:9
PaletteModel paletteModel
Definition: main.cpp:28
BOOL WINAPI DeleteDC(_In_ HDC)
void NotifyDimensionsChanged()
Definition: history.cpp:15
HBRUSH WINAPI CreateSolidBrush(_In_ COLORREF)
void NotifyImageChanged()
Definition: history.cpp:20
#define HISTORYSIZE
Definition: definitions.h:13
#define SRCCOPY
Definition: wingdi.h:332
HBITMAP hBms[HISTORYSIZE]
Definition: history.h:18
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

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

◆ FlipHorizontally()

void ImageModel::FlipHorizontally ( )

Definition at line 223 of file history.cpp.

224 {
225  CopyPrevious();
226  StretchBlt(hDrawingDC, GetWidth() - 1, 0, -GetWidth(), GetHeight(), GetDC(), 0, 0,
227  GetWidth(), GetHeight(), SRCCOPY);
229 }
void CopyPrevious(void)
Definition: history.cpp:45
HDC hDrawingDC
Definition: history.h:16
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)
HDC GetDC()
Definition: history.cpp:218
int GetWidth()
Definition: history.cpp:194
int GetHeight()
Definition: history.cpp:199
void NotifyImageChanged()
Definition: history.cpp:20
#define SRCCOPY
Definition: wingdi.h:332

Referenced by CMainWindow::OnCommand().

◆ FlipVertically()

void ImageModel::FlipVertically ( )

Definition at line 231 of file history.cpp.

232 {
233  CopyPrevious();
234  StretchBlt(hDrawingDC, 0, GetHeight() - 1, GetWidth(), -GetHeight(), GetDC(), 0, 0,
235  GetWidth(), GetHeight(), SRCCOPY);
237 }
void CopyPrevious(void)
Definition: history.cpp:45
HDC hDrawingDC
Definition: history.h:16
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)
HDC GetDC()
Definition: history.cpp:218
int GetWidth()
Definition: history.cpp:194
int GetHeight()
Definition: history.cpp:199
void NotifyImageChanged()
Definition: history.cpp:20
#define SRCCOPY
Definition: wingdi.h:332

Referenced by CMainWindow::OnCommand().

◆ GetDC()

◆ GetHeight()

◆ GetWidth()

◆ HasRedoSteps()

BOOL ImageModel::HasRedoSteps ( )

Definition at line 177 of file history.cpp.

178 {
179  return redoSteps > 0;
180 }
int redoSteps
Definition: history.h:22

Referenced by CMainWindow::OnInitMenuPopup().

◆ HasUndoSteps()

BOOL ImageModel::HasUndoSteps ( )

Definition at line 172 of file history.cpp.

173 {
174  return undoSteps > 0;
175 }
int undoSteps
Definition: history.h:21

Referenced by CMainWindow::OnInitMenuPopup().

◆ Insert()

void ImageModel::Insert ( HBITMAP  hbm)

Definition at line 108 of file history.cpp.

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;
119  if (GetWidth() != oldWidth || GetHeight() != oldHeight)
122 }
int redoSteps
Definition: history.h:22
int currInd
Definition: history.h:20
HDC hDrawingDC
Definition: history.h:16
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1499
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
int undoSteps
Definition: history.h:21
int GetWidth()
Definition: history.cpp:194
int GetHeight()
Definition: history.cpp:199
_In_ HBITMAP hbm
Definition: ntgdi.h:2776
void NotifyDimensionsChanged()
Definition: history.cpp:15
void NotifyImageChanged()
Definition: history.cpp:20
#define HISTORYSIZE
Definition: definitions.h:13
HBITMAP hBms[HISTORYSIZE]
Definition: history.h:18

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

◆ InvertColors()

void ImageModel::InvertColors ( )

Definition at line 204 of file history.cpp.

205 {
206  RECT rect = {0, 0, GetWidth(), GetHeight()};
207  CopyPrevious();
210 }
void CopyPrevious(void)
Definition: history.cpp:45
HDC hDrawingDC
Definition: history.h:16
BOOL WINAPI InvertRect(_In_ HDC, _In_ LPCRECT)
& rect
Definition: startmenu.cpp:1413
int GetWidth()
Definition: history.cpp:194
int GetHeight()
Definition: history.cpp:199
void NotifyImageChanged()
Definition: history.cpp:20

Referenced by CMainWindow::OnCommand().

◆ IsImageSaved()

BOOL ImageModel::IsImageSaved ( )

Definition at line 167 of file history.cpp.

168 {
169  return imageSaved;
170 }
BOOL imageSaved
Definition: main.cpp:54

Referenced by CMainWindow::ConfirmSave().

◆ NotifyDimensionsChanged()

void ImageModel::NotifyDimensionsChanged ( )
private

Definition at line 15 of file history.cpp.

16 {
18 }
CImgAreaWindow imageArea
Definition: main.cpp:72
#define WM_IMAGEMODELDIMENSIONSCHANGED
Definition: definitions.h:246
LRESULT SendMessage(UINT message, WPARAM wParam=0, LPARAM lParam=0)
Definition: atlwin.h:1048

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

◆ NotifyImageChanged()

void ImageModel::NotifyImageChanged ( )
private

Definition at line 20 of file history.cpp.

21 {
23 }
CImgAreaWindow imageArea
Definition: main.cpp:72
#define WM_IMAGEMODELIMAGECHANGED
Definition: definitions.h:247
LRESULT SendMessage(UINT message, WPARAM wParam=0, LPARAM lParam=0)
Definition: atlwin.h:1048

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

◆ Redo()

void ImageModel::Redo ( void  )

Definition at line 75 of file history.cpp.

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 }
int redoSteps
Definition: history.h:22
int currInd
Definition: history.h:20
#define SW_HIDE
Definition: winuser.h:762
HDC hDrawingDC
Definition: history.h:16
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1499
int undoSteps
Definition: history.h:21
int GetWidth()
Definition: history.cpp:194
int GetHeight()
Definition: history.cpp:199
void NotifyDimensionsChanged()
Definition: history.cpp:15
void NotifyImageChanged()
Definition: history.cpp:20
#define HISTORYSIZE
Definition: definitions.h:13
HBITMAP hBms[HISTORYSIZE]
Definition: history.h:18
CSelectionWindow selectionWindow
Definition: main.cpp:71

Referenced by CMainWindow::OnCommand().

◆ ResetToPrevious()

void ImageModel::ResetToPrevious ( void  )

Definition at line 93 of file history.cpp.

94 {
96  hBms[currInd] =
100 }
int currInd
Definition: history.h:20
HDC hDrawingDC
Definition: history.h:16
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1499
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
#define LR_COPYRETURNORG
Definition: winuser.h:1080
HANDLE WINAPI CopyImage(_In_ HANDLE, _In_ UINT, _In_ int, _In_ int, _In_ UINT)
Definition: cursoricon.c:1956
#define IMAGE_BITMAP
Definition: winuser.h:211
void NotifyImageChanged()
Definition: history.cpp:20
static HBITMAP
Definition: button.c:44
#define HISTORYSIZE
Definition: definitions.h:13
HBITMAP hBms[HISTORYSIZE]
Definition: history.h:18

Referenced by SelectionModel::CalculateBoundingBoxAndContents(), CImgAreaWindow::cancelDrawing(), endPaintingL(), endPaintingR(), CSelectionWindow::OnMouseMove(), whilePaintingL(), and whilePaintingR().

◆ RotateNTimes90Degrees()

void ImageModel::RotateNTimes90Degrees ( int  iN)

Definition at line 239 of file history.cpp.

240 {
241  if (iN == 2)
242  {
243  CopyPrevious();
245  0, 0, GetWidth(), GetHeight(), SRCCOPY);
246  }
248 }
void CopyPrevious(void)
Definition: history.cpp:45
HDC hDrawingDC
Definition: history.h:16
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)
HDC GetDC()
Definition: history.cpp:218
int GetWidth()
Definition: history.cpp:194
int GetHeight()
Definition: history.cpp:199
void NotifyImageChanged()
Definition: history.cpp:20
#define SRCCOPY
Definition: wingdi.h:332

Referenced by CMainWindow::OnCommand().

◆ SaveImage()

void ImageModel::SaveImage ( LPTSTR  lpFileName)

Definition at line 162 of file history.cpp.

163 {
165 }
int currInd
Definition: history.h:20
HDC hDrawingDC
Definition: history.h:16
BOOL SaveDIBToFile(HBITMAP hBitmap, LPTSTR FileName, HDC hDC)
Definition: dib.cpp:68
HBITMAP hBms[HISTORYSIZE]
Definition: history.h:18
_In_ LPCSTR lpFileName
Definition: winbase.h:3034

Referenced by CMainWindow::saveImage().

◆ StretchSkew()

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

Definition at line 182 of file history.cpp.

183 {
184  int oldWidth = GetWidth();
185  int oldHeight = GetHeight();
187  GetWidth() * nStretchPercentX / 100,
188  GetHeight() * nStretchPercentY / 100, 0));
189  if (GetWidth() != oldWidth || GetHeight() != oldHeight)
192 }
int currInd
Definition: history.h:20
HANDLE WINAPI CopyImage(_In_ HANDLE, _In_ UINT, _In_ int, _In_ int, _In_ UINT)
Definition: cursoricon.c:1956
void Insert(HBITMAP hbm)
Definition: history.cpp:108
int GetWidth()
Definition: history.cpp:194
int GetHeight()
Definition: history.cpp:199
void NotifyDimensionsChanged()
Definition: history.cpp:15
#define IMAGE_BITMAP
Definition: winuser.h:211
void NotifyImageChanged()
Definition: history.cpp:20
static HBITMAP
Definition: button.c:44
HBITMAP hBms[HISTORYSIZE]
Definition: history.h:18

Referenced by CMainWindow::OnCommand().

◆ Undo()

void ImageModel::Undo ( void  )

Definition at line 57 of file history.cpp.

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 }
int redoSteps
Definition: history.h:22
int currInd
Definition: history.h:20
#define SW_HIDE
Definition: winuser.h:762
HDC hDrawingDC
Definition: history.h:16
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1499
int undoSteps
Definition: history.h:21
int GetWidth()
Definition: history.cpp:194
int GetHeight()
Definition: history.cpp:199
void NotifyDimensionsChanged()
Definition: history.cpp:15
void NotifyImageChanged()
Definition: history.cpp:20
#define HISTORYSIZE
Definition: definitions.h:13
HBITMAP hBms[HISTORYSIZE]
Definition: history.h:18
CSelectionWindow selectionWindow
Definition: main.cpp:71

Referenced by CImgAreaWindow::cancelDrawing(), CSelectionWindow::OnCaptureChanged(), CMainWindow::OnCommand(), CImgAreaWindow::OnLButtonDown(), and CImgAreaWindow::OnRButtonDown().

Member Data Documentation

◆ currInd

int ImageModel::currInd
private

◆ hBms

◆ hDrawingDC

◆ redoSteps

int ImageModel::redoSteps
private

Definition at line 22 of file history.h.

Referenced by ClearHistory(), CopyPrevious(), Crop(), HasRedoSteps(), ImageModel(), Insert(), Redo(), and Undo().

◆ undoSteps

int ImageModel::undoSteps
private

Definition at line 21 of file history.h.

Referenced by ClearHistory(), CopyPrevious(), Crop(), HasUndoSteps(), ImageModel(), Insert(), Redo(), and Undo().


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