1c2c66affSColin Finck /* 2c2c66affSColin Finck * PROJECT: PAINT for ReactOS 3*8f1f1c7aSStanislav 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 5*8f1f1c7aSStanislav Motylkov * COPYRIGHT: Copyright 2009 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 31c2c66affSColin Finck /* CLASSES **********************************************************/ 32c2c66affSColin Finck 33ee132a05SKatayama Hirofumi MZ struct ToolBase 34ee132a05SKatayama Hirofumi MZ { 35ee132a05SKatayama Hirofumi MZ TOOLTYPE m_tool; 36ee132a05SKatayama Hirofumi MZ HDC m_hdc; 37ee132a05SKatayama Hirofumi MZ COLORREF m_fg, m_bg; 38ec53d422SKatayama Hirofumi MZ static INT s_pointSP; 39ec53d422SKatayama Hirofumi MZ static POINT s_pointStack[256]; 40ee132a05SKatayama Hirofumi MZ 41e8c7e300SKatayama Hirofumi MZ ToolBase(TOOLTYPE tool) : m_tool(tool), m_hdc(NULL) { } 42e8c7e300SKatayama Hirofumi MZ virtual ~ToolBase() { } 43ee132a05SKatayama Hirofumi MZ 44e8c7e300SKatayama Hirofumi MZ virtual void OnButtonDown(BOOL bLeftButton, LONG x, LONG y, BOOL bDoubleClick) { } 45e8c7e300SKatayama Hirofumi MZ virtual void OnMouseMove(BOOL bLeftButton, LONG x, LONG y) { } 46e8c7e300SKatayama Hirofumi MZ virtual void OnButtonUp(BOOL bLeftButton, LONG x, LONG y) { } 47ee132a05SKatayama Hirofumi MZ 48ee132a05SKatayama Hirofumi MZ virtual void OnCancelDraw(); 4908397115SKatayama Hirofumi MZ virtual void OnFinishDraw(); 50ee132a05SKatayama Hirofumi MZ 51e8c7e300SKatayama Hirofumi MZ virtual void OnDrawOverlayOnImage(HDC hdc) { } 52e8c7e300SKatayama Hirofumi MZ virtual void OnDrawOverlayOnCanvas(HDC hdc) { } 53e8c7e300SKatayama Hirofumi MZ 54ee132a05SKatayama Hirofumi MZ void beginEvent(); 55ee132a05SKatayama Hirofumi MZ void endEvent(); 56ee132a05SKatayama Hirofumi MZ void reset(); 57ee132a05SKatayama Hirofumi MZ 58ee132a05SKatayama Hirofumi MZ static ToolBase* createToolObject(TOOLTYPE type); 59e8c7e300SKatayama Hirofumi MZ 60e8c7e300SKatayama Hirofumi MZ protected: 61e8c7e300SKatayama Hirofumi MZ void OnDrawSelectionOnCanvas(HDC hdc); 62ee132a05SKatayama Hirofumi MZ }; 63ee132a05SKatayama Hirofumi MZ 64c2c66affSColin Finck class ToolsModel 65c2c66affSColin Finck { 66c2c66affSColin Finck private: 67c2c66affSColin Finck int m_lineWidth; 68c2c66affSColin Finck int m_shapeStyle; 69c2c66affSColin Finck int m_brushStyle; 70e9330371SKatayama Hirofumi MZ TOOLTYPE m_activeTool; 71ee132a05SKatayama Hirofumi MZ TOOLTYPE m_oldActiveTool; 72c2c66affSColin Finck int m_airBrushWidth; 73c2c66affSColin Finck int m_rubberRadius; 74c2c66affSColin Finck BOOL m_transpBg; 75c2c66affSColin Finck int m_zoom; 76ee132a05SKatayama Hirofumi MZ ToolBase* m_tools[TOOL_MAX + 1]; 77ee132a05SKatayama Hirofumi MZ ToolBase *m_pToolObject; 78ee132a05SKatayama Hirofumi MZ 79ee132a05SKatayama Hirofumi MZ ToolBase *GetOrCreateTool(TOOLTYPE nTool); 80c2c66affSColin Finck 81c2c66affSColin Finck public: 82c2c66affSColin Finck ToolsModel(); 83ee132a05SKatayama Hirofumi MZ ~ToolsModel(); 849afcbea2SKatayama Hirofumi MZ 859afcbea2SKatayama Hirofumi MZ BOOL IsSelection() const; 8610289819SKatayama Hirofumi MZ int GetLineWidth() const; 87c2c66affSColin Finck void SetLineWidth(int nLineWidth); 8810289819SKatayama Hirofumi MZ int GetShapeStyle() const; 89c2c66affSColin Finck void SetShapeStyle(int nShapeStyle); 9010289819SKatayama Hirofumi MZ int GetBrushStyle() const; 91c2c66affSColin Finck void SetBrushStyle(int nBrushStyle); 92e9330371SKatayama Hirofumi MZ TOOLTYPE GetActiveTool() const; 93ee132a05SKatayama Hirofumi MZ TOOLTYPE GetOldActiveTool() const; 94e9330371SKatayama Hirofumi MZ void SetActiveTool(TOOLTYPE nActiveTool); 9510289819SKatayama Hirofumi MZ int GetAirBrushWidth() const; 96c2c66affSColin Finck void SetAirBrushWidth(int nAirBrushWidth); 9710289819SKatayama Hirofumi MZ int GetRubberRadius() const; 98c2c66affSColin Finck void SetRubberRadius(int nRubberRadius); 9910289819SKatayama Hirofumi MZ BOOL IsBackgroundTransparent() const; 100c2c66affSColin Finck void SetBackgroundTransparent(BOOL bTransparent); 1019e1386dbSKatayama Hirofumi MZ int GetZoom() const; 102c2c66affSColin Finck void SetZoom(int nZoom); 103ee132a05SKatayama Hirofumi MZ 104ee132a05SKatayama Hirofumi MZ void OnButtonDown(BOOL bLeftButton, LONG x, LONG y, BOOL bDoubleClick); 105ee132a05SKatayama Hirofumi MZ void OnMouseMove(BOOL bLeftButton, LONG x, LONG y); 106ee132a05SKatayama Hirofumi MZ void OnButtonUp(BOOL bLeftButton, LONG x, LONG y); 107ee132a05SKatayama Hirofumi MZ void OnCancelDraw(); 10808397115SKatayama Hirofumi MZ void OnFinishDraw(); 109e8c7e300SKatayama Hirofumi MZ void OnDrawOverlayOnImage(HDC hdc); 110e8c7e300SKatayama Hirofumi MZ void OnDrawOverlayOnCanvas(HDC hdc); 111ee132a05SKatayama Hirofumi MZ 112ee132a05SKatayama Hirofumi MZ void resetTool(); 113ee132a05SKatayama Hirofumi MZ void selectAll(); 114361a2ce4SKatayama Hirofumi MZ 115361a2ce4SKatayama Hirofumi MZ void NotifyToolChanged(); 116361a2ce4SKatayama Hirofumi MZ void NotifyToolSettingsChanged(); 117361a2ce4SKatayama Hirofumi MZ void NotifyZoomChanged(); 118c2c66affSColin Finck }; 11929e147beSKatayama Hirofumi MZ 12029e147beSKatayama Hirofumi MZ extern ToolsModel toolsModel; 12129e147beSKatayama Hirofumi MZ 12229e147beSKatayama Hirofumi MZ static inline int Zoomed(int xy) 12329e147beSKatayama Hirofumi MZ { 12429e147beSKatayama Hirofumi MZ return xy * toolsModel.GetZoom() / 1000; 12529e147beSKatayama Hirofumi MZ } 12629e147beSKatayama Hirofumi MZ 12729e147beSKatayama Hirofumi MZ static inline int UnZoomed(int xy) 12829e147beSKatayama Hirofumi MZ { 12929e147beSKatayama Hirofumi MZ return xy * 1000 / toolsModel.GetZoom(); 13029e147beSKatayama Hirofumi MZ } 131aac89519SKatayama Hirofumi MZ 132aac89519SKatayama Hirofumi MZ static inline void Zoomed(POINT& pt) 133aac89519SKatayama Hirofumi MZ { 134aac89519SKatayama Hirofumi MZ pt.x = Zoomed(pt.x); 135aac89519SKatayama Hirofumi MZ pt.y = Zoomed(pt.y); 136aac89519SKatayama Hirofumi MZ } 137aac89519SKatayama Hirofumi MZ 138aac89519SKatayama Hirofumi MZ static inline void Zoomed(RECT& rc) 139aac89519SKatayama Hirofumi MZ { 140aac89519SKatayama Hirofumi MZ rc.left = Zoomed(rc.left); 141aac89519SKatayama Hirofumi MZ rc.top = Zoomed(rc.top); 142aac89519SKatayama Hirofumi MZ rc.right = Zoomed(rc.right); 143aac89519SKatayama Hirofumi MZ rc.bottom = Zoomed(rc.bottom); 144aac89519SKatayama Hirofumi MZ } 145aac89519SKatayama Hirofumi MZ 146aac89519SKatayama Hirofumi MZ static inline void UnZoomed(POINT& pt) 147aac89519SKatayama Hirofumi MZ { 148aac89519SKatayama Hirofumi MZ pt.x = UnZoomed(pt.x); 149aac89519SKatayama Hirofumi MZ pt.y = UnZoomed(pt.y); 150aac89519SKatayama Hirofumi MZ } 151aac89519SKatayama Hirofumi MZ 152aac89519SKatayama Hirofumi MZ static inline void UnZoomed(RECT& rc) 153aac89519SKatayama Hirofumi MZ { 154aac89519SKatayama Hirofumi MZ rc.left = UnZoomed(rc.left); 155aac89519SKatayama Hirofumi MZ rc.top = UnZoomed(rc.top); 156aac89519SKatayama Hirofumi MZ rc.right = UnZoomed(rc.right); 157aac89519SKatayama Hirofumi MZ rc.bottom = UnZoomed(rc.bottom); 158aac89519SKatayama Hirofumi MZ } 159