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 tool parameters, notify listeners 5 * COPYRIGHT: Copyright 2015 Benedikt Freisen <b.freisen@gmx.net> 6 */ 7 8 #pragma once 9 10 enum TOOLTYPE 11 { 12 TOOL_FREESEL = 1, 13 TOOL_RECTSEL = 2, 14 TOOL_RUBBER = 3, 15 TOOL_FILL = 4, 16 TOOL_COLOR = 5, 17 TOOL_ZOOM = 6, 18 TOOL_PEN = 7, 19 TOOL_BRUSH = 8, 20 TOOL_AIRBRUSH = 9, 21 TOOL_TEXT = 10, 22 TOOL_LINE = 11, 23 TOOL_BEZIER = 12, 24 TOOL_RECT = 13, 25 TOOL_SHAPE = 14, 26 TOOL_ELLIPSE = 15, 27 TOOL_RRECT = 16, 28 TOOL_MAX = TOOL_RRECT, 29 }; 30 31 enum BrushStyle 32 { 33 BrushStyleRound, 34 BrushStyleSquare, 35 BrushStyleForeSlash, 36 BrushStyleBackSlash, 37 }; 38 39 /* CLASSES **********************************************************/ 40 41 struct ToolBase 42 { 43 HDC m_hdc; 44 COLORREF m_fg, m_bg; 45 static SIZE_T s_pointSP; 46 47 ToolBase() : m_hdc(NULL) { } 48 virtual ~ToolBase() { } 49 50 virtual void OnButtonDown(BOOL bLeftButton, LONG x, LONG y, BOOL bDoubleClick) { } 51 virtual BOOL OnMouseMove(BOOL bLeftButton, LONG& x, LONG& y) { return TRUE; } 52 virtual BOOL OnButtonUp(BOOL bLeftButton, LONG& x, LONG& y) { return TRUE; } 53 54 virtual void OnDrawOverlayOnImage(HDC hdc) { } 55 virtual void OnDrawOverlayOnCanvas(HDC hdc) { } 56 57 virtual void OnSpecialTweak(BOOL bMinus) { } 58 59 virtual void OnEndDraw(BOOL bCancel); 60 61 void beginEvent(); 62 void endEvent(); 63 void reset(); 64 void pushToPtStack(LONG x, LONG y); 65 66 static ToolBase* createToolObject(TOOLTYPE type); 67 }; 68 69 class ToolsModel 70 { 71 private: 72 int m_lineWidth; 73 INT m_penWidth; 74 INT m_brushWidth; 75 int m_shapeStyle; 76 BrushStyle m_brushStyle; 77 TOOLTYPE m_activeTool; 78 TOOLTYPE m_oldActiveTool; 79 INT m_airBrushRadius; 80 int m_rubberRadius; 81 BOOL m_transpBg; 82 int m_zoom; 83 ToolBase *m_pToolObject; 84 85 ToolBase *GetOrCreateTool(TOOLTYPE nTool); 86 87 public: 88 ToolsModel(); 89 ~ToolsModel(); 90 91 BOOL IsSelection() const; 92 93 int GetLineWidth() const; 94 void SetLineWidth(int nLineWidth); 95 void MakeLineThickerOrThinner(BOOL bThinner); 96 97 INT GetPenWidth() const; 98 void SetPenWidth(INT nPenWidth); 99 void MakePenThickerOrThinner(BOOL bThinner); 100 101 int GetShapeStyle() const; 102 void SetShapeStyle(int nShapeStyle); 103 104 INT GetBrushWidth() const; 105 void SetBrushWidth(INT nBrushWidth); 106 void MakeBrushThickerOrThinner(BOOL bThinner); 107 108 BrushStyle GetBrushStyle() const; 109 void SetBrushStyle(BrushStyle nBrushStyle); 110 111 TOOLTYPE GetActiveTool() const; 112 TOOLTYPE GetOldActiveTool() const; 113 void SetActiveTool(TOOLTYPE nActiveTool); 114 115 INT GetAirBrushRadius() const; 116 void SetAirBrushRadius(INT nAirBrushRadius); 117 void MakeAirBrushThickerOrThinner(BOOL bThinner); 118 119 int GetRubberRadius() const; 120 void SetRubberRadius(int nRubberRadius); 121 void MakeRubberThickerOrThinner(BOOL bThinner); 122 123 SIZE GetToolSize() const; 124 125 BOOL IsBackgroundTransparent() const; 126 void SetBackgroundTransparent(BOOL bTransparent); 127 128 int GetZoom() const; 129 void SetZoom(int nZoom); 130 131 void OnButtonDown(BOOL bLeftButton, LONG x, LONG y, BOOL bDoubleClick); 132 void OnMouseMove(BOOL bLeftButton, LONG x, LONG y); 133 void OnButtonUp(BOOL bLeftButton, LONG x, LONG y); 134 void OnEndDraw(BOOL bCancel); 135 void OnDrawOverlayOnImage(HDC hdc); 136 void OnDrawOverlayOnCanvas(HDC hdc); 137 138 void resetTool(); 139 void selectAll(); 140 141 void NotifyToolChanged(); 142 void NotifyToolSettingsChanged(); 143 void NotifyZoomChanged(); 144 145 void SpecialTweak(BOOL bMinus); 146 147 void DrawWithMouseTool(POINT pt, WPARAM wParam); 148 }; 149 150 extern ToolsModel toolsModel; 151 152 static inline int Zoomed(int xy) 153 { 154 return xy * toolsModel.GetZoom() / 1000; 155 } 156 157 static inline int UnZoomed(int xy) 158 { 159 return xy * 1000 / toolsModel.GetZoom(); 160 } 161 162 static inline void Zoomed(POINT& pt) 163 { 164 pt = { Zoomed(pt.x), Zoomed(pt.y) }; 165 } 166 167 static inline void Zoomed(RECT& rc) 168 { 169 rc = { Zoomed(rc.left), Zoomed(rc.top), Zoomed(rc.right), Zoomed(rc.bottom) }; 170 } 171 172 static inline void UnZoomed(POINT& pt) 173 { 174 pt = { UnZoomed(pt.x), UnZoomed(pt.y) }; 175 } 176 177 static inline void UnZoomed(RECT& rc) 178 { 179 rc = { UnZoomed(rc.left), UnZoomed(rc.top), UnZoomed(rc.right), UnZoomed(rc.bottom) }; 180 } 181