2015-07-07 11:15:24 +00:00
|
|
|
/*
|
2023-06-23 11:04:32 +00:00
|
|
|
* PROJECT: PAINT for ReactOS
|
|
|
|
* LICENSE: LGPL-2.0-or-later (https://spdx.org/licenses/LGPL-2.0-or-later)
|
|
|
|
* PURPOSE: Keep track of tool parameters, notify listeners
|
2023-06-27 18:22:21 +00:00
|
|
|
* COPYRIGHT: Copyright 2015 Benedikt Freisen <b.freisen@gmx.net>
|
2015-07-07 11:15:24 +00:00
|
|
|
*/
|
|
|
|
|
2017-12-09 12:36:45 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-12-27 14:23:32 +00:00
|
|
|
enum TOOLTYPE
|
|
|
|
{
|
|
|
|
TOOL_FREESEL = 1,
|
|
|
|
TOOL_RECTSEL = 2,
|
|
|
|
TOOL_RUBBER = 3,
|
|
|
|
TOOL_FILL = 4,
|
|
|
|
TOOL_COLOR = 5,
|
|
|
|
TOOL_ZOOM = 6,
|
|
|
|
TOOL_PEN = 7,
|
|
|
|
TOOL_BRUSH = 8,
|
|
|
|
TOOL_AIRBRUSH = 9,
|
|
|
|
TOOL_TEXT = 10,
|
|
|
|
TOOL_LINE = 11,
|
|
|
|
TOOL_BEZIER = 12,
|
|
|
|
TOOL_RECT = 13,
|
|
|
|
TOOL_SHAPE = 14,
|
|
|
|
TOOL_ELLIPSE = 15,
|
|
|
|
TOOL_RRECT = 16,
|
2022-01-01 13:02:36 +00:00
|
|
|
TOOL_MAX = TOOL_RRECT,
|
2021-12-27 14:23:32 +00:00
|
|
|
};
|
|
|
|
|
2023-09-28 12:30:34 +00:00
|
|
|
enum BrushStyle
|
|
|
|
{
|
|
|
|
BrushStyleRound,
|
|
|
|
BrushStyleSquare,
|
|
|
|
BrushStyleForeSlash,
|
|
|
|
BrushStyleBackSlash,
|
|
|
|
};
|
|
|
|
|
2015-07-07 11:15:24 +00:00
|
|
|
/* CLASSES **********************************************************/
|
|
|
|
|
2022-01-01 13:02:36 +00:00
|
|
|
struct ToolBase
|
|
|
|
{
|
|
|
|
HDC m_hdc;
|
|
|
|
COLORREF m_fg, m_bg;
|
2023-11-22 22:14:57 +00:00
|
|
|
static SIZE_T s_pointSP;
|
2022-01-01 13:02:36 +00:00
|
|
|
|
2023-11-23 07:37:13 +00:00
|
|
|
ToolBase() : m_hdc(NULL) { }
|
2023-06-17 12:15:35 +00:00
|
|
|
virtual ~ToolBase() { }
|
2022-01-01 13:02:36 +00:00
|
|
|
|
2023-06-17 12:15:35 +00:00
|
|
|
virtual void OnButtonDown(BOOL bLeftButton, LONG x, LONG y, BOOL bDoubleClick) { }
|
2023-09-26 13:47:23 +00:00
|
|
|
virtual BOOL OnMouseMove(BOOL bLeftButton, LONG& x, LONG& y) { return TRUE; }
|
|
|
|
virtual BOOL OnButtonUp(BOOL bLeftButton, LONG& x, LONG& y) { return TRUE; }
|
2022-01-01 13:02:36 +00:00
|
|
|
|
2023-06-17 12:15:35 +00:00
|
|
|
virtual void OnDrawOverlayOnImage(HDC hdc) { }
|
|
|
|
virtual void OnDrawOverlayOnCanvas(HDC hdc) { }
|
|
|
|
|
2023-09-23 00:26:11 +00:00
|
|
|
virtual void OnSpecialTweak(BOOL bMinus) { }
|
|
|
|
|
2023-11-03 07:20:03 +00:00
|
|
|
virtual void OnEndDraw(BOOL bCancel);
|
|
|
|
|
2022-01-01 13:02:36 +00:00
|
|
|
void beginEvent();
|
|
|
|
void endEvent();
|
|
|
|
void reset();
|
2023-11-22 22:14:57 +00:00
|
|
|
void pushToPtStack(LONG x, LONG y);
|
2022-01-01 13:02:36 +00:00
|
|
|
|
|
|
|
static ToolBase* createToolObject(TOOLTYPE type);
|
|
|
|
};
|
|
|
|
|
2015-07-07 11:15:24 +00:00
|
|
|
class ToolsModel
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
int m_lineWidth;
|
2023-09-28 07:32:36 +00:00
|
|
|
INT m_penWidth;
|
2023-09-28 12:30:34 +00:00
|
|
|
INT m_brushWidth;
|
2015-07-07 11:15:24 +00:00
|
|
|
int m_shapeStyle;
|
2023-09-28 12:30:34 +00:00
|
|
|
BrushStyle m_brushStyle;
|
2021-12-27 14:23:32 +00:00
|
|
|
TOOLTYPE m_activeTool;
|
2022-01-01 13:02:36 +00:00
|
|
|
TOOLTYPE m_oldActiveTool;
|
2023-11-16 06:45:06 +00:00
|
|
|
INT m_airBrushRadius;
|
2015-07-07 11:15:24 +00:00
|
|
|
int m_rubberRadius;
|
|
|
|
BOOL m_transpBg;
|
|
|
|
int m_zoom;
|
2022-01-01 13:02:36 +00:00
|
|
|
ToolBase *m_pToolObject;
|
|
|
|
|
|
|
|
ToolBase *GetOrCreateTool(TOOLTYPE nTool);
|
2015-07-07 11:44:50 +00:00
|
|
|
|
2015-07-07 11:15:24 +00:00
|
|
|
public:
|
|
|
|
ToolsModel();
|
2022-01-01 13:02:36 +00:00
|
|
|
~ToolsModel();
|
2023-06-19 00:56:02 +00:00
|
|
|
|
|
|
|
BOOL IsSelection() const;
|
2023-09-28 07:32:36 +00:00
|
|
|
|
2021-12-27 11:08:07 +00:00
|
|
|
int GetLineWidth() const;
|
2015-07-07 11:15:24 +00:00
|
|
|
void SetLineWidth(int nLineWidth);
|
2023-09-28 07:32:36 +00:00
|
|
|
void MakeLineThickerOrThinner(BOOL bThinner);
|
|
|
|
|
|
|
|
INT GetPenWidth() const;
|
|
|
|
void SetPenWidth(INT nPenWidth);
|
|
|
|
void MakePenThickerOrThinner(BOOL bThinner);
|
|
|
|
|
2021-12-27 11:08:07 +00:00
|
|
|
int GetShapeStyle() const;
|
2015-07-07 11:15:24 +00:00
|
|
|
void SetShapeStyle(int nShapeStyle);
|
2023-09-28 12:30:34 +00:00
|
|
|
|
|
|
|
INT GetBrushWidth() const;
|
|
|
|
void SetBrushWidth(INT nBrushWidth);
|
|
|
|
void MakeBrushThickerOrThinner(BOOL bThinner);
|
|
|
|
|
|
|
|
BrushStyle GetBrushStyle() const;
|
|
|
|
void SetBrushStyle(BrushStyle nBrushStyle);
|
|
|
|
|
2021-12-27 14:23:32 +00:00
|
|
|
TOOLTYPE GetActiveTool() const;
|
2022-01-01 13:02:36 +00:00
|
|
|
TOOLTYPE GetOldActiveTool() const;
|
2021-12-27 14:23:32 +00:00
|
|
|
void SetActiveTool(TOOLTYPE nActiveTool);
|
2023-09-28 12:30:34 +00:00
|
|
|
|
2023-11-16 06:45:06 +00:00
|
|
|
INT GetAirBrushRadius() const;
|
|
|
|
void SetAirBrushRadius(INT nAirBrushRadius);
|
2023-09-28 12:54:32 +00:00
|
|
|
void MakeAirBrushThickerOrThinner(BOOL bThinner);
|
2023-09-28 12:30:34 +00:00
|
|
|
|
2021-12-27 11:08:07 +00:00
|
|
|
int GetRubberRadius() const;
|
2015-07-07 11:15:24 +00:00
|
|
|
void SetRubberRadius(int nRubberRadius);
|
2023-09-28 12:54:32 +00:00
|
|
|
void MakeRubberThickerOrThinner(BOOL bThinner);
|
2023-09-28 12:30:34 +00:00
|
|
|
|
2023-11-19 03:59:39 +00:00
|
|
|
SIZE GetToolSize() const;
|
|
|
|
|
2021-12-27 11:08:07 +00:00
|
|
|
BOOL IsBackgroundTransparent() const;
|
2015-07-07 11:15:24 +00:00
|
|
|
void SetBackgroundTransparent(BOOL bTransparent);
|
2023-09-28 12:30:34 +00:00
|
|
|
|
2021-12-26 10:49:56 +00:00
|
|
|
int GetZoom() const;
|
2015-07-07 11:15:24 +00:00
|
|
|
void SetZoom(int nZoom);
|
2022-01-01 13:02:36 +00:00
|
|
|
|
|
|
|
void OnButtonDown(BOOL bLeftButton, LONG x, LONG y, BOOL bDoubleClick);
|
|
|
|
void OnMouseMove(BOOL bLeftButton, LONG x, LONG y);
|
|
|
|
void OnButtonUp(BOOL bLeftButton, LONG x, LONG y);
|
2023-11-03 07:20:03 +00:00
|
|
|
void OnEndDraw(BOOL bCancel);
|
2023-06-17 12:15:35 +00:00
|
|
|
void OnDrawOverlayOnImage(HDC hdc);
|
|
|
|
void OnDrawOverlayOnCanvas(HDC hdc);
|
2022-01-01 13:02:36 +00:00
|
|
|
|
|
|
|
void resetTool();
|
|
|
|
void selectAll();
|
2022-01-05 07:26:05 +00:00
|
|
|
|
|
|
|
void NotifyToolChanged();
|
|
|
|
void NotifyToolSettingsChanged();
|
|
|
|
void NotifyZoomChanged();
|
2023-09-23 00:26:11 +00:00
|
|
|
|
|
|
|
void SpecialTweak(BOOL bMinus);
|
2023-11-03 13:41:06 +00:00
|
|
|
|
|
|
|
void DrawWithMouseTool(POINT pt, WPARAM wParam);
|
2015-07-07 11:15:24 +00:00
|
|
|
};
|
2023-03-28 13:31:26 +00:00
|
|
|
|
|
|
|
extern ToolsModel toolsModel;
|
|
|
|
|
|
|
|
static inline int Zoomed(int xy)
|
|
|
|
{
|
|
|
|
return xy * toolsModel.GetZoom() / 1000;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int UnZoomed(int xy)
|
|
|
|
{
|
|
|
|
return xy * 1000 / toolsModel.GetZoom();
|
|
|
|
}
|
2023-04-01 13:01:04 +00:00
|
|
|
|
|
|
|
static inline void Zoomed(POINT& pt)
|
|
|
|
{
|
2023-11-22 22:14:57 +00:00
|
|
|
pt = { Zoomed(pt.x), Zoomed(pt.y) };
|
2023-04-01 13:01:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void Zoomed(RECT& rc)
|
|
|
|
{
|
2023-11-22 22:14:57 +00:00
|
|
|
rc = { Zoomed(rc.left), Zoomed(rc.top), Zoomed(rc.right), Zoomed(rc.bottom) };
|
2023-04-01 13:01:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void UnZoomed(POINT& pt)
|
|
|
|
{
|
2023-11-22 22:14:57 +00:00
|
|
|
pt = { UnZoomed(pt.x), UnZoomed(pt.y) };
|
2023-04-01 13:01:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void UnZoomed(RECT& rc)
|
|
|
|
{
|
2023-11-22 22:14:57 +00:00
|
|
|
rc = { UnZoomed(rc.left), UnZoomed(rc.top), UnZoomed(rc.right), UnZoomed(rc.bottom) };
|
2023-04-01 13:01:04 +00:00
|
|
|
}
|