ReactOS  0.4.14-dev-317-g96040ec
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]
 
BOOL imageSaved
 

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
#define TRUE
Definition: types.h:120
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)
HDC hDrawingDC
Definition: history.h:16
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
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: history.h:24
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 213 of file history.cpp.

214 {
215  Rectangle(hDrawingDC, 0 - 1, 0 - 1, GetWidth() + 1, GetHeight() + 1);
217 }
BOOL WINAPI Rectangle(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int)
HDC hDrawingDC
Definition: history.h:16
int GetWidth()
Definition: history.cpp:195
int GetHeight()
Definition: history.cpp:200
void NotifyImageChanged()
Definition: history.cpp:20

Referenced by CMainWindow::OnCommand().

◆ 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 _tWinMain(), CMainWindow::OnCommand(), and CMainWindow::UpdateApplicationProperties().

◆ 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:1497
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
int undoSteps
Definition: history.h:21
BOOL imageSaved
Definition: history.h:24
#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:1497
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
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:410
#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:195
int GetHeight()
Definition: history.cpp:200
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

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

◆ FlipHorizontally()

void ImageModel::FlipHorizontally ( )

Definition at line 224 of file history.cpp.

225 {
226  CopyPrevious();
227  StretchBlt(hDrawingDC, GetWidth() - 1, 0, -GetWidth(), GetHeight(), GetDC(), 0, 0,
228  GetWidth(), GetHeight(), SRCCOPY);
230 }
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:219
int GetWidth()
Definition: history.cpp:195
int GetHeight()
Definition: history.cpp:200
void NotifyImageChanged()
Definition: history.cpp:20
#define SRCCOPY
Definition: wingdi.h:332

Referenced by CMainWindow::OnCommand().

◆ FlipVertically()

void ImageModel::FlipVertically ( )

Definition at line 232 of file history.cpp.

233 {
234  CopyPrevious();
235  StretchBlt(hDrawingDC, 0, GetHeight() - 1, GetWidth(), -GetHeight(), GetDC(), 0, 0,
236  GetWidth(), GetHeight(), SRCCOPY);
238 }
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:219
int GetWidth()
Definition: history.cpp:195
int GetHeight()
Definition: history.cpp:200
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 178 of file history.cpp.

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

Referenced by CMainWindow::OnInitMenuPopup().

◆ HasUndoSteps()

BOOL ImageModel::HasUndoSteps ( )

Definition at line 173 of file history.cpp.

174 {
175  return undoSteps > 0;
176 }
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:1497
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
int undoSteps
Definition: history.h:21
int GetWidth()
Definition: history.cpp:195
int GetHeight()
Definition: history.cpp:200
_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 _tWinMain(), CMainWindow::OnCommand(), StretchSkew(), and CMainWindow::UpdateApplicationProperties().

◆ InvertColors()

void ImageModel::InvertColors ( )

Definition at line 205 of file history.cpp.

206 {
207  RECT rect = {0, 0, GetWidth(), GetHeight()};
208  CopyPrevious();
211 }
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:195
int GetHeight()
Definition: history.cpp:200
void NotifyImageChanged()
Definition: history.cpp:20

Referenced by CMainWindow::OnCommand().

◆ IsImageSaved()

BOOL ImageModel::IsImageSaved ( )

Definition at line 168 of file history.cpp.

169 {
170  return imageSaved;
171 }
BOOL imageSaved
Definition: history.h:24

Referenced by CMainWindow::OnClose(), and CMainWindow::OnCommand().

◆ NotifyDimensionsChanged()

void ImageModel::NotifyDimensionsChanged ( )
private

Definition at line 15 of file history.cpp.

16 {
18 }
CImgAreaWindow imageArea
Definition: main.cpp:71
#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:71
#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:1497
int undoSteps
Definition: history.h:21
int GetWidth()
Definition: history.cpp:195
int GetHeight()
Definition: history.cpp:200
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:70

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:1497
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 240 of file history.cpp.

241 {
242  if (iN == 2)
243  {
244  CopyPrevious();
246  0, 0, GetWidth(), GetHeight(), SRCCOPY);
247  }
249 }
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:219
int GetWidth()
Definition: history.cpp:195
int GetHeight()
Definition: history.cpp:200
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  imageSaved = TRUE;
166 }
#define TRUE
Definition: types.h:120
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
HDC hDrawingDC
Definition: history.h:16
SYSTEMTIME fileTime
Definition: main.cpp:57
int fileHPPM
Definition: main.cpp:55
BOOL imageSaved
Definition: history.h:24
int fileVPPM
Definition: main.cpp:56
HBITMAP hBms[HISTORYSIZE]
Definition: history.h:18
_In_ LPCSTR lpFileName
Definition: winbase.h:3018

Referenced by CMainWindow::saveImage().

◆ StretchSkew()

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

Definition at line 183 of file history.cpp.

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 }
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:195
int GetHeight()
Definition: history.cpp:200
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:1497
int undoSteps
Definition: history.h:21
int GetWidth()
Definition: history.cpp:195
int GetHeight()
Definition: history.cpp:200
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:70

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

Member Data Documentation

◆ currInd

int ImageModel::currInd
private

◆ hBms

◆ hDrawingDC

◆ imageSaved

BOOL ImageModel::imageSaved

Definition at line 24 of file history.h.

Referenced by CopyPrevious(), ImageModel(), IsImageSaved(), CMainWindow::OnCommand(), and SaveImage().

◆ 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: