1 /* 2 * PROJECT: PAINT for ReactOS 3 * LICENSE: LGPL-2.0-or-later (https://spdx.org/licenses/LGPL-2.0-or-later) 4 * PURPOSE: Undo and redo functionality 5 * COPYRIGHT: Copyright 2015 Benedikt Freisen <b.freisen@gmx.net> 6 */ 7 8 #pragma once 9 10 /* HISTORYSIZE = number of possible undo-steps + 1 */ 11 #define HISTORYSIZE 11 12 13 struct IMAGE_PART 14 { 15 CRect m_rcPart; 16 HBITMAP m_hbmImage; 17 BOOL m_bPartial; 18 19 void clear(); 20 }; 21 22 class ImageModel 23 { 24 public: 25 ImageModel(); 26 virtual ~ImageModel(); 27 28 HDC GetDC(); 29 BOOL CanUndo() const { return m_undoSteps > 0; } 30 BOOL CanRedo() const { return m_redoSteps > 0; } 31 void PushImageForUndo(); 32 void PushImageForUndo(HBITMAP hbm); 33 void PushImageForUndo(const RECT& rcPartial); 34 void Undo(BOOL bClearRedo = FALSE); 35 void Redo(void); 36 void ClearHistory(void); 37 void Crop(int nWidth, int nHeight, int nOffsetX = 0, int nOffsetY = 0); 38 void SaveImage(LPCWSTR lpFileName); 39 BOOL IsImageSaved() const; 40 void StretchSkew(int nStretchPercentX, int nStretchPercentY, int nSkewDegX = 0, int nSkewDegY = 0); 41 int GetWidth() const; 42 int GetHeight() const; 43 HBITMAP CopyBitmap(); 44 HBITMAP LockBitmap(); 45 void UnlockBitmap(HBITMAP hbmLocked); 46 void InvertColors(); 47 void FlipHorizontally(); 48 void FlipVertically(); 49 void RotateNTimes90Degrees(int iN); 50 void Clamp(POINT& pt) const; 51 void NotifyImageChanged(); 52 BOOL IsBlackAndWhite(); 53 void PushBlackAndWhite(); 54 void SelectionClone(BOOL bUndoable = TRUE); 55 56 protected: 57 HDC m_hDrawingDC; // The device context for this class 58 HBITMAP m_hbmMaster; // The master bitmap 59 int m_currInd; // The current index in m_hBms 60 int m_undoSteps; // The undo-able count 61 int m_redoSteps; // The redo-able count 62 IMAGE_PART m_historyItems[HISTORYSIZE]; // A ring buffer of IMAGE_PARTs 63 HGDIOBJ m_hbmOld; 64 65 void SwapPart(); 66 void PushDone(); 67 }; 68