1 /*
2  * PROJECT:    PAINT for ReactOS
3  * LICENSE:    LGPL-2.0-or-later (https://spdx.org/licenses/LGPL-2.0-or-later)
4  * PURPOSE:    Keep track of selection parameters, notify listeners
5  * COPYRIGHT:  Copyright 2015 Benedikt Freisen <b.freisen@gmx.net>
6  *             Copyright 2019-2023 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
7  */
8 
9 #pragma once
10 
11 class SelectionModel
12 {
13 private:
14     HBITMAP m_hbmColor;
15     HBITMAP m_hbmMask;
16     POINT *m_ptStack;
17     int m_iPtSP;
18 
19 public:
20     COLORREF m_rgbBack;
21     BOOL m_bShow;
22     BOOL m_bContentChanged;
23     CRect m_rc;    // in image pixel coordinates
24     POINT m_ptHit; // in image pixel coordinates
25     CRect m_rcOld; // in image pixel coordinates
26 
27     SelectionModel();
28     ~SelectionModel();
29 
30     void ResetPtStack();
31     void PushToPtStack(POINT pt);
32     int PtStackSize() const;
33     void SetRectFromPoints(const POINT& ptFrom, const POINT& ptTo);
34     void BuildMaskFromPtStack();
35 
36     BOOL TakeOff();
37     void Landing();
38     BOOL IsLanded() const;
39     void HideSelection();
40     void DeleteSelection();
41 
42     HBITMAP CopyBitmap();
43     void GetSelectionContents(HDC hDCImage);
44     void DrawFramePoly(HDC hDCImage);
45     void DrawBackground(HDC hDCImage);
46     void DrawBackgroundPoly(HDC hDCImage, COLORREF crBg);
47     void DrawBackgroundRect(HDC hDCImage, COLORREF crBg);
48     void DrawSelection(HDC hDCImage, COLORREF crBg = 0, BOOL bBgTransparent = FALSE);
49     void InsertFromHBITMAP(HBITMAP hbmColor, INT x = 0, INT y = 0, HBITMAP hbmMask = NULL);
50 
51     // operation
52     void FlipHorizontally();
53     void FlipVertically();
54     void RotateNTimes90Degrees(int iN);
55     void StretchSkew(int nStretchPercentX, int nStretchPercentY, int nSkewDegX, int nSkewDegY);
56     void InvertSelection();
57 
58     void Dragging(HITTEST hit, POINT pt);
59     void ClearMask();
60     void ClearColor();
61     void NotifyContentChanged();
62 
63 private:
64     SelectionModel(const SelectionModel&);
65     SelectionModel& operator=(const SelectionModel&);
66 
67     void ShiftPtStack(INT dx, INT dy);
68     void SwapWidthAndHeight();
69 };
70