1c2c66affSColin Finck /*
2c2c66affSColin Finck  * PROJECT:     PAINT for ReactOS
3c2c66affSColin Finck  * LICENSE:     LGPL
4c2c66affSColin Finck  * FILE:        base/applications/mspaint/toolsmodel.h
5c2c66affSColin Finck  * PURPOSE:     Keep track of tool parameters, notify listeners
6c2c66affSColin Finck  * PROGRAMMERS: Benedikt Freisen
7c2c66affSColin Finck  */
8c2c66affSColin Finck 
94db1f987SAmine Khaldi #pragma once
104db1f987SAmine Khaldi 
11e9330371SKatayama Hirofumi MZ enum TOOLTYPE
12e9330371SKatayama Hirofumi MZ {
13e9330371SKatayama Hirofumi MZ     TOOL_FREESEL  =  1,
14e9330371SKatayama Hirofumi MZ     TOOL_RECTSEL  =  2,
15e9330371SKatayama Hirofumi MZ     TOOL_RUBBER   =  3,
16e9330371SKatayama Hirofumi MZ     TOOL_FILL     =  4,
17e9330371SKatayama Hirofumi MZ     TOOL_COLOR    =  5,
18e9330371SKatayama Hirofumi MZ     TOOL_ZOOM     =  6,
19e9330371SKatayama Hirofumi MZ     TOOL_PEN      =  7,
20e9330371SKatayama Hirofumi MZ     TOOL_BRUSH    =  8,
21e9330371SKatayama Hirofumi MZ     TOOL_AIRBRUSH =  9,
22e9330371SKatayama Hirofumi MZ     TOOL_TEXT     = 10,
23e9330371SKatayama Hirofumi MZ     TOOL_LINE     = 11,
24e9330371SKatayama Hirofumi MZ     TOOL_BEZIER   = 12,
25e9330371SKatayama Hirofumi MZ     TOOL_RECT     = 13,
26e9330371SKatayama Hirofumi MZ     TOOL_SHAPE    = 14,
27e9330371SKatayama Hirofumi MZ     TOOL_ELLIPSE  = 15,
28e9330371SKatayama Hirofumi MZ     TOOL_RRECT    = 16,
29ee132a05SKatayama Hirofumi MZ     TOOL_MAX = TOOL_RRECT,
30e9330371SKatayama Hirofumi MZ };
31e9330371SKatayama Hirofumi MZ 
32c2c66affSColin Finck /* CLASSES **********************************************************/
33c2c66affSColin Finck 
34ee132a05SKatayama Hirofumi MZ struct ToolBase
35ee132a05SKatayama Hirofumi MZ {
36ee132a05SKatayama Hirofumi MZ     TOOLTYPE m_tool;
37ee132a05SKatayama Hirofumi MZ     HDC m_hdc;
38ee132a05SKatayama Hirofumi MZ     COLORREF m_fg, m_bg;
39*ec53d422SKatayama Hirofumi MZ     static INT s_pointSP;
40*ec53d422SKatayama Hirofumi MZ     static POINT s_pointStack[256];
41ee132a05SKatayama Hirofumi MZ 
42e8c7e300SKatayama Hirofumi MZ     ToolBase(TOOLTYPE tool) : m_tool(tool), m_hdc(NULL) { }
43e8c7e300SKatayama Hirofumi MZ     virtual ~ToolBase() { }
44ee132a05SKatayama Hirofumi MZ 
45e8c7e300SKatayama Hirofumi MZ     virtual void OnButtonDown(BOOL bLeftButton, LONG x, LONG y, BOOL bDoubleClick) { }
46e8c7e300SKatayama Hirofumi MZ     virtual void OnMouseMove(BOOL bLeftButton, LONG x, LONG y) { }
47e8c7e300SKatayama Hirofumi MZ     virtual void OnButtonUp(BOOL bLeftButton, LONG x, LONG y) { }
48ee132a05SKatayama Hirofumi MZ 
49ee132a05SKatayama Hirofumi MZ     virtual void OnCancelDraw();
5008397115SKatayama Hirofumi MZ     virtual void OnFinishDraw();
51ee132a05SKatayama Hirofumi MZ 
52e8c7e300SKatayama Hirofumi MZ     virtual void OnDrawOverlayOnImage(HDC hdc) { }
53e8c7e300SKatayama Hirofumi MZ     virtual void OnDrawOverlayOnCanvas(HDC hdc) { }
54e8c7e300SKatayama Hirofumi MZ 
55ee132a05SKatayama Hirofumi MZ     void beginEvent();
56ee132a05SKatayama Hirofumi MZ     void endEvent();
57ee132a05SKatayama Hirofumi MZ     void reset();
58ee132a05SKatayama Hirofumi MZ 
59ee132a05SKatayama Hirofumi MZ     static ToolBase* createToolObject(TOOLTYPE type);
60e8c7e300SKatayama Hirofumi MZ 
61e8c7e300SKatayama Hirofumi MZ protected:
62e8c7e300SKatayama Hirofumi MZ     void OnDrawSelectionOnCanvas(HDC hdc);
63ee132a05SKatayama Hirofumi MZ };
64ee132a05SKatayama Hirofumi MZ 
65c2c66affSColin Finck class ToolsModel
66c2c66affSColin Finck {
67c2c66affSColin Finck private:
68c2c66affSColin Finck     int m_lineWidth;
69c2c66affSColin Finck     int m_shapeStyle;
70c2c66affSColin Finck     int m_brushStyle;
71e9330371SKatayama Hirofumi MZ     TOOLTYPE m_activeTool;
72ee132a05SKatayama Hirofumi MZ     TOOLTYPE m_oldActiveTool;
73c2c66affSColin Finck     int m_airBrushWidth;
74c2c66affSColin Finck     int m_rubberRadius;
75c2c66affSColin Finck     BOOL m_transpBg;
76c2c66affSColin Finck     int m_zoom;
77ee132a05SKatayama Hirofumi MZ     ToolBase* m_tools[TOOL_MAX + 1];
78ee132a05SKatayama Hirofumi MZ     ToolBase *m_pToolObject;
79ee132a05SKatayama Hirofumi MZ 
80ee132a05SKatayama Hirofumi MZ     ToolBase *GetOrCreateTool(TOOLTYPE nTool);
81c2c66affSColin Finck 
82c2c66affSColin Finck public:
83c2c66affSColin Finck     ToolsModel();
84ee132a05SKatayama Hirofumi MZ     ~ToolsModel();
859afcbea2SKatayama Hirofumi MZ 
869afcbea2SKatayama Hirofumi MZ     BOOL IsSelection() const;
8710289819SKatayama Hirofumi MZ     int GetLineWidth() const;
88c2c66affSColin Finck     void SetLineWidth(int nLineWidth);
8910289819SKatayama Hirofumi MZ     int GetShapeStyle() const;
90c2c66affSColin Finck     void SetShapeStyle(int nShapeStyle);
9110289819SKatayama Hirofumi MZ     int GetBrushStyle() const;
92c2c66affSColin Finck     void SetBrushStyle(int nBrushStyle);
93e9330371SKatayama Hirofumi MZ     TOOLTYPE GetActiveTool() const;
94ee132a05SKatayama Hirofumi MZ     TOOLTYPE GetOldActiveTool() const;
95e9330371SKatayama Hirofumi MZ     void SetActiveTool(TOOLTYPE nActiveTool);
9610289819SKatayama Hirofumi MZ     int GetAirBrushWidth() const;
97c2c66affSColin Finck     void SetAirBrushWidth(int nAirBrushWidth);
9810289819SKatayama Hirofumi MZ     int GetRubberRadius() const;
99c2c66affSColin Finck     void SetRubberRadius(int nRubberRadius);
10010289819SKatayama Hirofumi MZ     BOOL IsBackgroundTransparent() const;
101c2c66affSColin Finck     void SetBackgroundTransparent(BOOL bTransparent);
1029e1386dbSKatayama Hirofumi MZ     int GetZoom() const;
103c2c66affSColin Finck     void SetZoom(int nZoom);
104ee132a05SKatayama Hirofumi MZ 
105ee132a05SKatayama Hirofumi MZ     void OnButtonDown(BOOL bLeftButton, LONG x, LONG y, BOOL bDoubleClick);
106ee132a05SKatayama Hirofumi MZ     void OnMouseMove(BOOL bLeftButton, LONG x, LONG y);
107ee132a05SKatayama Hirofumi MZ     void OnButtonUp(BOOL bLeftButton, LONG x, LONG y);
108ee132a05SKatayama Hirofumi MZ     void OnCancelDraw();
10908397115SKatayama Hirofumi MZ     void OnFinishDraw();
110e8c7e300SKatayama Hirofumi MZ     void OnDrawOverlayOnImage(HDC hdc);
111e8c7e300SKatayama Hirofumi MZ     void OnDrawOverlayOnCanvas(HDC hdc);
112ee132a05SKatayama Hirofumi MZ 
113ee132a05SKatayama Hirofumi MZ     void resetTool();
114ee132a05SKatayama Hirofumi MZ     void selectAll();
115361a2ce4SKatayama Hirofumi MZ 
116361a2ce4SKatayama Hirofumi MZ     void NotifyToolChanged();
117361a2ce4SKatayama Hirofumi MZ     void NotifyToolSettingsChanged();
118361a2ce4SKatayama Hirofumi MZ     void NotifyZoomChanged();
119c2c66affSColin Finck };
12029e147beSKatayama Hirofumi MZ 
12129e147beSKatayama Hirofumi MZ extern ToolsModel toolsModel;
12229e147beSKatayama Hirofumi MZ 
12329e147beSKatayama Hirofumi MZ static inline int Zoomed(int xy)
12429e147beSKatayama Hirofumi MZ {
12529e147beSKatayama Hirofumi MZ     return xy * toolsModel.GetZoom() / 1000;
12629e147beSKatayama Hirofumi MZ }
12729e147beSKatayama Hirofumi MZ 
12829e147beSKatayama Hirofumi MZ static inline int UnZoomed(int xy)
12929e147beSKatayama Hirofumi MZ {
13029e147beSKatayama Hirofumi MZ     return xy * 1000 / toolsModel.GetZoom();
13129e147beSKatayama Hirofumi MZ }
132aac89519SKatayama Hirofumi MZ 
133aac89519SKatayama Hirofumi MZ static inline void Zoomed(POINT& pt)
134aac89519SKatayama Hirofumi MZ {
135aac89519SKatayama Hirofumi MZ     pt.x = Zoomed(pt.x);
136aac89519SKatayama Hirofumi MZ     pt.y = Zoomed(pt.y);
137aac89519SKatayama Hirofumi MZ }
138aac89519SKatayama Hirofumi MZ 
139aac89519SKatayama Hirofumi MZ static inline void Zoomed(RECT& rc)
140aac89519SKatayama Hirofumi MZ {
141aac89519SKatayama Hirofumi MZ     rc.left = Zoomed(rc.left);
142aac89519SKatayama Hirofumi MZ     rc.top = Zoomed(rc.top);
143aac89519SKatayama Hirofumi MZ     rc.right = Zoomed(rc.right);
144aac89519SKatayama Hirofumi MZ     rc.bottom = Zoomed(rc.bottom);
145aac89519SKatayama Hirofumi MZ }
146aac89519SKatayama Hirofumi MZ 
147aac89519SKatayama Hirofumi MZ static inline void UnZoomed(POINT& pt)
148aac89519SKatayama Hirofumi MZ {
149aac89519SKatayama Hirofumi MZ     pt.x = UnZoomed(pt.x);
150aac89519SKatayama Hirofumi MZ     pt.y = UnZoomed(pt.y);
151aac89519SKatayama Hirofumi MZ }
152aac89519SKatayama Hirofumi MZ 
153aac89519SKatayama Hirofumi MZ static inline void UnZoomed(RECT& rc)
154aac89519SKatayama Hirofumi MZ {
155aac89519SKatayama Hirofumi MZ     rc.left = UnZoomed(rc.left);
156aac89519SKatayama Hirofumi MZ     rc.top = UnZoomed(rc.top);
157aac89519SKatayama Hirofumi MZ     rc.right = UnZoomed(rc.right);
158aac89519SKatayama Hirofumi MZ     rc.bottom = UnZoomed(rc.bottom);
159aac89519SKatayama Hirofumi MZ }
160