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 TOOLTYPE m_tool; 44ee132a05SKatayama Hirofumi MZ HDC m_hdc; 45ee132a05SKatayama Hirofumi MZ COLORREF m_fg, m_bg; 46ec53d422SKatayama Hirofumi MZ static INT s_pointSP; 47ec53d422SKatayama Hirofumi MZ static POINT s_pointStack[256]; 48ee132a05SKatayama Hirofumi MZ 49e8c7e300SKatayama Hirofumi MZ ToolBase(TOOLTYPE tool) : m_tool(tool), m_hdc(NULL) { } 50e8c7e300SKatayama Hirofumi MZ virtual ~ToolBase() { } 51ee132a05SKatayama Hirofumi MZ 52e8c7e300SKatayama Hirofumi MZ virtual void OnButtonDown(BOOL bLeftButton, LONG x, LONG y, BOOL bDoubleClick) { } 53389d0465SKatayama Hirofumi MZ virtual BOOL OnMouseMove(BOOL bLeftButton, LONG& x, LONG& y) { return TRUE; } 54389d0465SKatayama Hirofumi MZ virtual BOOL OnButtonUp(BOOL bLeftButton, LONG& x, LONG& y) { return TRUE; } 55ee132a05SKatayama Hirofumi MZ 56ee132a05SKatayama Hirofumi MZ virtual void OnCancelDraw(); 5708397115SKatayama Hirofumi MZ virtual void OnFinishDraw(); 58ee132a05SKatayama Hirofumi MZ 59e8c7e300SKatayama Hirofumi MZ virtual void OnDrawOverlayOnImage(HDC hdc) { } 60e8c7e300SKatayama Hirofumi MZ virtual void OnDrawOverlayOnCanvas(HDC hdc) { } 61e8c7e300SKatayama Hirofumi MZ 62ed9973f8SKatayama Hirofumi MZ virtual void OnSpecialTweak(BOOL bMinus) { } 63ed9973f8SKatayama Hirofumi MZ 64ee132a05SKatayama Hirofumi MZ void beginEvent(); 65ee132a05SKatayama Hirofumi MZ void endEvent(); 66ee132a05SKatayama Hirofumi MZ void reset(); 67ee132a05SKatayama Hirofumi MZ 68ee132a05SKatayama Hirofumi MZ static ToolBase* createToolObject(TOOLTYPE type); 69e8c7e300SKatayama Hirofumi MZ 70e8c7e300SKatayama Hirofumi MZ protected: 71e8c7e300SKatayama Hirofumi MZ void OnDrawSelectionOnCanvas(HDC hdc); 72ee132a05SKatayama Hirofumi MZ }; 73ee132a05SKatayama Hirofumi MZ 74c2c66affSColin Finck class ToolsModel 75c2c66affSColin Finck { 76c2c66affSColin Finck private: 77c2c66affSColin Finck int m_lineWidth; 78f2a01224SKatayama Hirofumi MZ INT m_penWidth; 798a4787b3SKatayama Hirofumi MZ INT m_brushWidth; 80c2c66affSColin Finck int m_shapeStyle; 818a4787b3SKatayama Hirofumi MZ BrushStyle m_brushStyle; 82e9330371SKatayama Hirofumi MZ TOOLTYPE m_activeTool; 83ee132a05SKatayama Hirofumi MZ TOOLTYPE m_oldActiveTool; 84c2c66affSColin Finck int m_airBrushWidth; 85c2c66affSColin Finck int m_rubberRadius; 86c2c66affSColin Finck BOOL m_transpBg; 87c2c66affSColin Finck int m_zoom; 88ee132a05SKatayama Hirofumi MZ ToolBase* m_tools[TOOL_MAX + 1]; 89ee132a05SKatayama Hirofumi MZ ToolBase *m_pToolObject; 90ee132a05SKatayama Hirofumi MZ 91ee132a05SKatayama Hirofumi MZ ToolBase *GetOrCreateTool(TOOLTYPE nTool); 92c2c66affSColin Finck 93c2c66affSColin Finck public: 94c2c66affSColin Finck ToolsModel(); 95ee132a05SKatayama Hirofumi MZ ~ToolsModel(); 969afcbea2SKatayama Hirofumi MZ 979afcbea2SKatayama Hirofumi MZ BOOL IsSelection() const; 98f2a01224SKatayama Hirofumi MZ 9910289819SKatayama Hirofumi MZ int GetLineWidth() const; 100c2c66affSColin Finck void SetLineWidth(int nLineWidth); 101f2a01224SKatayama Hirofumi MZ void MakeLineThickerOrThinner(BOOL bThinner); 102f2a01224SKatayama Hirofumi MZ 103f2a01224SKatayama Hirofumi MZ INT GetPenWidth() const; 104f2a01224SKatayama Hirofumi MZ void SetPenWidth(INT nPenWidth); 105f2a01224SKatayama Hirofumi MZ void MakePenThickerOrThinner(BOOL bThinner); 106f2a01224SKatayama Hirofumi MZ 10710289819SKatayama Hirofumi MZ int GetShapeStyle() const; 108c2c66affSColin Finck void SetShapeStyle(int nShapeStyle); 1098a4787b3SKatayama Hirofumi MZ 1108a4787b3SKatayama Hirofumi MZ INT GetBrushWidth() const; 1118a4787b3SKatayama Hirofumi MZ void SetBrushWidth(INT nBrushWidth); 1128a4787b3SKatayama Hirofumi MZ void MakeBrushThickerOrThinner(BOOL bThinner); 1138a4787b3SKatayama Hirofumi MZ 1148a4787b3SKatayama Hirofumi MZ BrushStyle GetBrushStyle() const; 1158a4787b3SKatayama Hirofumi MZ void SetBrushStyle(BrushStyle nBrushStyle); 1168a4787b3SKatayama Hirofumi MZ 117e9330371SKatayama Hirofumi MZ TOOLTYPE GetActiveTool() const; 118ee132a05SKatayama Hirofumi MZ TOOLTYPE GetOldActiveTool() const; 119e9330371SKatayama Hirofumi MZ void SetActiveTool(TOOLTYPE nActiveTool); 1208a4787b3SKatayama Hirofumi MZ 12110289819SKatayama Hirofumi MZ int GetAirBrushWidth() const; 122c2c66affSColin Finck void SetAirBrushWidth(int nAirBrushWidth); 123*945ee4b2SKatayama Hirofumi MZ void MakeAirBrushThickerOrThinner(BOOL bThinner); 1248a4787b3SKatayama Hirofumi MZ 12510289819SKatayama Hirofumi MZ int GetRubberRadius() const; 126c2c66affSColin Finck void SetRubberRadius(int nRubberRadius); 127*945ee4b2SKatayama Hirofumi MZ void MakeRubberThickerOrThinner(BOOL bThinner); 1288a4787b3SKatayama Hirofumi MZ 12910289819SKatayama Hirofumi MZ BOOL IsBackgroundTransparent() const; 130c2c66affSColin Finck void SetBackgroundTransparent(BOOL bTransparent); 1318a4787b3SKatayama Hirofumi MZ 1329e1386dbSKatayama Hirofumi MZ int GetZoom() const; 133c2c66affSColin Finck void SetZoom(int nZoom); 134ee132a05SKatayama Hirofumi MZ 135ee132a05SKatayama Hirofumi MZ void OnButtonDown(BOOL bLeftButton, LONG x, LONG y, BOOL bDoubleClick); 136ee132a05SKatayama Hirofumi MZ void OnMouseMove(BOOL bLeftButton, LONG x, LONG y); 137ee132a05SKatayama Hirofumi MZ void OnButtonUp(BOOL bLeftButton, LONG x, LONG y); 138ee132a05SKatayama Hirofumi MZ void OnCancelDraw(); 13908397115SKatayama Hirofumi MZ void OnFinishDraw(); 140e8c7e300SKatayama Hirofumi MZ void OnDrawOverlayOnImage(HDC hdc); 141e8c7e300SKatayama Hirofumi MZ void OnDrawOverlayOnCanvas(HDC hdc); 142ee132a05SKatayama Hirofumi MZ 143ee132a05SKatayama Hirofumi MZ void resetTool(); 144ee132a05SKatayama Hirofumi MZ void selectAll(); 145361a2ce4SKatayama Hirofumi MZ 146361a2ce4SKatayama Hirofumi MZ void NotifyToolChanged(); 147361a2ce4SKatayama Hirofumi MZ void NotifyToolSettingsChanged(); 148361a2ce4SKatayama Hirofumi MZ void NotifyZoomChanged(); 149ed9973f8SKatayama Hirofumi MZ 150ed9973f8SKatayama Hirofumi MZ void SpecialTweak(BOOL bMinus); 151c2c66affSColin Finck }; 15229e147beSKatayama Hirofumi MZ 15329e147beSKatayama Hirofumi MZ extern ToolsModel toolsModel; 15429e147beSKatayama Hirofumi MZ 15529e147beSKatayama Hirofumi MZ static inline int Zoomed(int xy) 15629e147beSKatayama Hirofumi MZ { 15729e147beSKatayama Hirofumi MZ return xy * toolsModel.GetZoom() / 1000; 15829e147beSKatayama Hirofumi MZ } 15929e147beSKatayama Hirofumi MZ 16029e147beSKatayama Hirofumi MZ static inline int UnZoomed(int xy) 16129e147beSKatayama Hirofumi MZ { 16229e147beSKatayama Hirofumi MZ return xy * 1000 / toolsModel.GetZoom(); 16329e147beSKatayama Hirofumi MZ } 164aac89519SKatayama Hirofumi MZ 165aac89519SKatayama Hirofumi MZ static inline void Zoomed(POINT& pt) 166aac89519SKatayama Hirofumi MZ { 167aac89519SKatayama Hirofumi MZ pt.x = Zoomed(pt.x); 168aac89519SKatayama Hirofumi MZ pt.y = Zoomed(pt.y); 169aac89519SKatayama Hirofumi MZ } 170aac89519SKatayama Hirofumi MZ 171aac89519SKatayama Hirofumi MZ static inline void Zoomed(RECT& rc) 172aac89519SKatayama Hirofumi MZ { 173aac89519SKatayama Hirofumi MZ rc.left = Zoomed(rc.left); 174aac89519SKatayama Hirofumi MZ rc.top = Zoomed(rc.top); 175aac89519SKatayama Hirofumi MZ rc.right = Zoomed(rc.right); 176aac89519SKatayama Hirofumi MZ rc.bottom = Zoomed(rc.bottom); 177aac89519SKatayama Hirofumi MZ } 178aac89519SKatayama Hirofumi MZ 179aac89519SKatayama Hirofumi MZ static inline void UnZoomed(POINT& pt) 180aac89519SKatayama Hirofumi MZ { 181aac89519SKatayama Hirofumi MZ pt.x = UnZoomed(pt.x); 182aac89519SKatayama Hirofumi MZ pt.y = UnZoomed(pt.y); 183aac89519SKatayama Hirofumi MZ } 184aac89519SKatayama Hirofumi MZ 185aac89519SKatayama Hirofumi MZ static inline void UnZoomed(RECT& rc) 186aac89519SKatayama Hirofumi MZ { 187aac89519SKatayama Hirofumi MZ rc.left = UnZoomed(rc.left); 188aac89519SKatayama Hirofumi MZ rc.top = UnZoomed(rc.top); 189aac89519SKatayama Hirofumi MZ rc.right = UnZoomed(rc.right); 190aac89519SKatayama Hirofumi MZ rc.bottom = UnZoomed(rc.bottom); 191aac89519SKatayama Hirofumi MZ } 192