1c2c66affSColin Finck /*
2c2c66affSColin Finck  * PROJECT:    PAINT for ReactOS
38f1f1c7aSStanislav Motylkov  * LICENSE:    LGPL-2.0-or-later (https://spdx.org/licenses/LGPL-2.0-or-later)
4c2c66affSColin Finck  * PURPOSE:    Keep track of tool parameters, notify listeners
5f5200e6cSStanislav Motylkov  * COPYRIGHT:  Copyright 2015 Benedikt Freisen <b.freisen@gmx.net>
6c2c66affSColin Finck  */
7c2c66affSColin Finck 
84db1f987SAmine Khaldi #pragma once
94db1f987SAmine Khaldi 
10e9330371SKatayama Hirofumi MZ enum TOOLTYPE
11e9330371SKatayama Hirofumi MZ {
12e9330371SKatayama Hirofumi MZ     TOOL_FREESEL  =  1,
13e9330371SKatayama Hirofumi MZ     TOOL_RECTSEL  =  2,
14e9330371SKatayama Hirofumi MZ     TOOL_RUBBER   =  3,
15e9330371SKatayama Hirofumi MZ     TOOL_FILL     =  4,
16e9330371SKatayama Hirofumi MZ     TOOL_COLOR    =  5,
17e9330371SKatayama Hirofumi MZ     TOOL_ZOOM     =  6,
18e9330371SKatayama Hirofumi MZ     TOOL_PEN      =  7,
19e9330371SKatayama Hirofumi MZ     TOOL_BRUSH    =  8,
20e9330371SKatayama Hirofumi MZ     TOOL_AIRBRUSH =  9,
21e9330371SKatayama Hirofumi MZ     TOOL_TEXT     = 10,
22e9330371SKatayama Hirofumi MZ     TOOL_LINE     = 11,
23e9330371SKatayama Hirofumi MZ     TOOL_BEZIER   = 12,
24e9330371SKatayama Hirofumi MZ     TOOL_RECT     = 13,
25e9330371SKatayama Hirofumi MZ     TOOL_SHAPE    = 14,
26e9330371SKatayama Hirofumi MZ     TOOL_ELLIPSE  = 15,
27e9330371SKatayama Hirofumi MZ     TOOL_RRECT    = 16,
28ee132a05SKatayama Hirofumi MZ     TOOL_MAX = TOOL_RRECT,
29e9330371SKatayama Hirofumi MZ };
30e9330371SKatayama Hirofumi MZ 
318a4787b3SKatayama Hirofumi MZ enum BrushStyle
328a4787b3SKatayama Hirofumi MZ {
338a4787b3SKatayama Hirofumi MZ     BrushStyleRound,
348a4787b3SKatayama Hirofumi MZ     BrushStyleSquare,
358a4787b3SKatayama Hirofumi MZ     BrushStyleForeSlash,
368a4787b3SKatayama Hirofumi MZ     BrushStyleBackSlash,
378a4787b3SKatayama Hirofumi MZ };
388a4787b3SKatayama Hirofumi MZ 
39c2c66affSColin Finck /* CLASSES **********************************************************/
40c2c66affSColin Finck 
41ee132a05SKatayama Hirofumi MZ struct ToolBase
42ee132a05SKatayama Hirofumi MZ {
43ee132a05SKatayama Hirofumi MZ     HDC m_hdc;
44ee132a05SKatayama Hirofumi MZ     COLORREF m_fg, m_bg;
45ee132a05SKatayama Hirofumi MZ 
ToolBaseToolBase46*96e48dcdSKatayama Hirofumi MZ     ToolBase() : m_hdc(NULL) { }
~ToolBaseToolBase47e8c7e300SKatayama Hirofumi MZ     virtual ~ToolBase() { }
48ee132a05SKatayama Hirofumi MZ 
OnButtonDownToolBase49e8c7e300SKatayama Hirofumi MZ     virtual void OnButtonDown(BOOL bLeftButton, LONG x, LONG y, BOOL bDoubleClick) { }
OnMouseMoveToolBase50389d0465SKatayama Hirofumi MZ     virtual BOOL OnMouseMove(BOOL bLeftButton, LONG& x, LONG& y) { return TRUE; }
OnButtonUpToolBase51389d0465SKatayama Hirofumi MZ     virtual BOOL OnButtonUp(BOOL bLeftButton, LONG& x, LONG& y) { return TRUE; }
52ee132a05SKatayama Hirofumi MZ 
OnDrawOverlayOnImageToolBase53e8c7e300SKatayama Hirofumi MZ     virtual void OnDrawOverlayOnImage(HDC hdc) { }
OnDrawOverlayOnCanvasToolBase54e8c7e300SKatayama Hirofumi MZ     virtual void OnDrawOverlayOnCanvas(HDC hdc) { }
55e8c7e300SKatayama Hirofumi MZ 
OnSpecialTweakToolBase56ed9973f8SKatayama Hirofumi MZ     virtual void OnSpecialTweak(BOOL bMinus) { }
57ed9973f8SKatayama Hirofumi MZ 
5837f56d24SKatayama Hirofumi MZ     virtual void OnEndDraw(BOOL bCancel);
5937f56d24SKatayama Hirofumi MZ 
60ee132a05SKatayama Hirofumi MZ     void beginEvent();
61ee132a05SKatayama Hirofumi MZ     void endEvent();
62ee132a05SKatayama Hirofumi MZ     void reset();
63ee132a05SKatayama Hirofumi MZ 
64ee132a05SKatayama Hirofumi MZ     static ToolBase* createToolObject(TOOLTYPE type);
65ee132a05SKatayama Hirofumi MZ };
66ee132a05SKatayama Hirofumi MZ 
67c2c66affSColin Finck class ToolsModel
68c2c66affSColin Finck {
69c2c66affSColin Finck private:
70c2c66affSColin Finck     int m_lineWidth;
71f2a01224SKatayama Hirofumi MZ     INT m_penWidth;
728a4787b3SKatayama Hirofumi MZ     INT m_brushWidth;
73c2c66affSColin Finck     int m_shapeStyle;
748a4787b3SKatayama Hirofumi MZ     BrushStyle m_brushStyle;
75e9330371SKatayama Hirofumi MZ     TOOLTYPE m_activeTool;
76ee132a05SKatayama Hirofumi MZ     TOOLTYPE m_oldActiveTool;
77157739a6SKatayama Hirofumi MZ     INT m_airBrushRadius;
78c2c66affSColin Finck     int m_rubberRadius;
79c2c66affSColin Finck     BOOL m_transpBg;
80c2c66affSColin Finck     int m_zoom;
81ee132a05SKatayama Hirofumi MZ     ToolBase *m_pToolObject;
82ee132a05SKatayama Hirofumi MZ 
83ee132a05SKatayama Hirofumi MZ     ToolBase *GetOrCreateTool(TOOLTYPE nTool);
84c2c66affSColin Finck 
85c2c66affSColin Finck public:
86c2c66affSColin Finck     ToolsModel();
87ee132a05SKatayama Hirofumi MZ     ~ToolsModel();
889afcbea2SKatayama Hirofumi MZ 
899afcbea2SKatayama Hirofumi MZ     BOOL IsSelection() const;
90f2a01224SKatayama Hirofumi MZ 
9110289819SKatayama Hirofumi MZ     int GetLineWidth() const;
92c2c66affSColin Finck     void SetLineWidth(int nLineWidth);
93f2a01224SKatayama Hirofumi MZ     void MakeLineThickerOrThinner(BOOL bThinner);
94f2a01224SKatayama Hirofumi MZ 
95f2a01224SKatayama Hirofumi MZ     INT GetPenWidth() const;
96f2a01224SKatayama Hirofumi MZ     void SetPenWidth(INT nPenWidth);
97f2a01224SKatayama Hirofumi MZ     void MakePenThickerOrThinner(BOOL bThinner);
98f2a01224SKatayama Hirofumi MZ 
9910289819SKatayama Hirofumi MZ     int GetShapeStyle() const;
100c2c66affSColin Finck     void SetShapeStyle(int nShapeStyle);
1018a4787b3SKatayama Hirofumi MZ 
1028a4787b3SKatayama Hirofumi MZ     INT GetBrushWidth() const;
1038a4787b3SKatayama Hirofumi MZ     void SetBrushWidth(INT nBrushWidth);
1048a4787b3SKatayama Hirofumi MZ     void MakeBrushThickerOrThinner(BOOL bThinner);
1058a4787b3SKatayama Hirofumi MZ 
1068a4787b3SKatayama Hirofumi MZ     BrushStyle GetBrushStyle() const;
1078a4787b3SKatayama Hirofumi MZ     void SetBrushStyle(BrushStyle nBrushStyle);
1088a4787b3SKatayama Hirofumi MZ 
109e9330371SKatayama Hirofumi MZ     TOOLTYPE GetActiveTool() const;
110ee132a05SKatayama Hirofumi MZ     TOOLTYPE GetOldActiveTool() const;
111e9330371SKatayama Hirofumi MZ     void SetActiveTool(TOOLTYPE nActiveTool);
1128a4787b3SKatayama Hirofumi MZ 
113157739a6SKatayama Hirofumi MZ     INT GetAirBrushRadius() const;
114157739a6SKatayama Hirofumi MZ     void SetAirBrushRadius(INT nAirBrushRadius);
115945ee4b2SKatayama Hirofumi MZ     void MakeAirBrushThickerOrThinner(BOOL bThinner);
1168a4787b3SKatayama Hirofumi MZ 
11710289819SKatayama Hirofumi MZ     int GetRubberRadius() const;
118c2c66affSColin Finck     void SetRubberRadius(int nRubberRadius);
119945ee4b2SKatayama Hirofumi MZ     void MakeRubberThickerOrThinner(BOOL bThinner);
1208a4787b3SKatayama Hirofumi MZ 
12172081168SKatayama Hirofumi MZ     SIZE GetToolSize() const;
12272081168SKatayama Hirofumi MZ 
12310289819SKatayama Hirofumi MZ     BOOL IsBackgroundTransparent() const;
124c2c66affSColin Finck     void SetBackgroundTransparent(BOOL bTransparent);
1258a4787b3SKatayama Hirofumi MZ 
1269e1386dbSKatayama Hirofumi MZ     int GetZoom() const;
127c2c66affSColin Finck     void SetZoom(int nZoom);
128ee132a05SKatayama Hirofumi MZ 
129ee132a05SKatayama Hirofumi MZ     void OnButtonDown(BOOL bLeftButton, LONG x, LONG y, BOOL bDoubleClick);
130ee132a05SKatayama Hirofumi MZ     void OnMouseMove(BOOL bLeftButton, LONG x, LONG y);
131ee132a05SKatayama Hirofumi MZ     void OnButtonUp(BOOL bLeftButton, LONG x, LONG y);
13237f56d24SKatayama Hirofumi MZ     void OnEndDraw(BOOL bCancel);
133e8c7e300SKatayama Hirofumi MZ     void OnDrawOverlayOnImage(HDC hdc);
134e8c7e300SKatayama Hirofumi MZ     void OnDrawOverlayOnCanvas(HDC hdc);
135ee132a05SKatayama Hirofumi MZ 
136ee132a05SKatayama Hirofumi MZ     void resetTool();
137ee132a05SKatayama Hirofumi MZ     void selectAll();
138361a2ce4SKatayama Hirofumi MZ 
139361a2ce4SKatayama Hirofumi MZ     void NotifyToolChanged();
140361a2ce4SKatayama Hirofumi MZ     void NotifyToolSettingsChanged();
141361a2ce4SKatayama Hirofumi MZ     void NotifyZoomChanged();
142ed9973f8SKatayama Hirofumi MZ 
143ed9973f8SKatayama Hirofumi MZ     void SpecialTweak(BOOL bMinus);
144a114169cSKatayama Hirofumi MZ 
145a114169cSKatayama Hirofumi MZ     void DrawWithMouseTool(POINT pt, WPARAM wParam);
146c2c66affSColin Finck };
14729e147beSKatayama Hirofumi MZ 
14829e147beSKatayama Hirofumi MZ extern ToolsModel toolsModel;
14929e147beSKatayama Hirofumi MZ 
Zoomed(int xy)15029e147beSKatayama Hirofumi MZ static inline int Zoomed(int xy)
15129e147beSKatayama Hirofumi MZ {
15229e147beSKatayama Hirofumi MZ     return xy * toolsModel.GetZoom() / 1000;
15329e147beSKatayama Hirofumi MZ }
15429e147beSKatayama Hirofumi MZ 
UnZoomed(int xy)15529e147beSKatayama Hirofumi MZ static inline int UnZoomed(int xy)
15629e147beSKatayama Hirofumi MZ {
15729e147beSKatayama Hirofumi MZ     return xy * 1000 / toolsModel.GetZoom();
15829e147beSKatayama Hirofumi MZ }
159aac89519SKatayama Hirofumi MZ 
Zoomed(POINT & pt)160aac89519SKatayama Hirofumi MZ static inline void Zoomed(POINT& pt)
161aac89519SKatayama Hirofumi MZ {
162e5792200SKatayama Hirofumi MZ     pt = { Zoomed(pt.x), Zoomed(pt.y) };
163aac89519SKatayama Hirofumi MZ }
164aac89519SKatayama Hirofumi MZ 
Zoomed(RECT & rc)165aac89519SKatayama Hirofumi MZ static inline void Zoomed(RECT& rc)
166aac89519SKatayama Hirofumi MZ {
167e5792200SKatayama Hirofumi MZ     rc = { Zoomed(rc.left), Zoomed(rc.top), Zoomed(rc.right), Zoomed(rc.bottom) };
168aac89519SKatayama Hirofumi MZ }
169aac89519SKatayama Hirofumi MZ 
UnZoomed(POINT & pt)170aac89519SKatayama Hirofumi MZ static inline void UnZoomed(POINT& pt)
171aac89519SKatayama Hirofumi MZ {
172e5792200SKatayama Hirofumi MZ     pt = { UnZoomed(pt.x), UnZoomed(pt.y) };
173aac89519SKatayama Hirofumi MZ }
174aac89519SKatayama Hirofumi MZ 
UnZoomed(RECT & rc)175aac89519SKatayama Hirofumi MZ static inline void UnZoomed(RECT& rc)
176aac89519SKatayama Hirofumi MZ {
177e5792200SKatayama Hirofumi MZ     rc = { UnZoomed(rc.left), UnZoomed(rc.top), UnZoomed(rc.right), UnZoomed(rc.bottom) };
178aac89519SKatayama Hirofumi MZ }
179