mirror of
https://github.com/ApfelTeeSaft/reactos.git
synced 2026-08-26 19:33:31 +00:00
[MSPAINT] Fix Color Picker tool (#9179)
The behavior of Color Picker (dropper) tool was incompatible with Windows. JIRA issue: CORE-19466 - On TOOL_COLOR, when mouse was pressed or moved, send WM_TOOLSMODELCOLORPICKED message with color value to the tools settings window. - In the tools settings window, display the picked color. - Don't apply to the current color until mouse up. Co-authored-by: Hermès BÉLUSCA - MAÏTO <[email protected]>
This commit is contained in:
@@ -611,30 +611,34 @@ struct FillTool : ToolBase
|
||||
// TOOL_COLOR
|
||||
struct ColorTool : ToolBase
|
||||
{
|
||||
void fetchColor(BOOL bLeftButton, LONG x, LONG y)
|
||||
COLORREF fetchColor(LONG x, LONG y)
|
||||
{
|
||||
COLORREF rgbColor;
|
||||
|
||||
if (0 <= x && x < imageModel.GetWidth() && 0 <= y && y < imageModel.GetHeight())
|
||||
rgbColor = GetPixel(m_hdc, x, y);
|
||||
else
|
||||
rgbColor = RGB(255, 255, 255); // Outside is white
|
||||
return GetPixel(m_hdc, x, y);
|
||||
return RGB(255, 255, 255); // Outside is white
|
||||
}
|
||||
|
||||
if (bLeftButton)
|
||||
paletteModel.SetFgColor(rgbColor);
|
||||
else
|
||||
paletteModel.SetBgColor(rgbColor);
|
||||
void OnButtonDown(BOOL bLeftButton, LONG x, LONG y, BOOL bDoubleClick) override
|
||||
{
|
||||
COLORREF rgbColor = fetchColor(x, y);
|
||||
toolSettingsWindow.SendMessage(WM_TOOLSMODELCOLORPICKED, rgbColor, 0);
|
||||
}
|
||||
|
||||
BOOL OnMouseMove(BOOL bLeftButton, LONG& x, LONG& y) override
|
||||
{
|
||||
fetchColor(bLeftButton, x, y);
|
||||
COLORREF rgbColor = fetchColor(x, y);
|
||||
toolSettingsWindow.SendMessage(WM_TOOLSMODELCOLORPICKED, rgbColor, 0);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL OnButtonUp(BOOL bLeftButton, LONG& x, LONG& y) override
|
||||
{
|
||||
fetchColor(bLeftButton, x, y);
|
||||
COLORREF rgbColor = fetchColor(x, y);
|
||||
if (bLeftButton)
|
||||
paletteModel.SetFgColor(rgbColor);
|
||||
else
|
||||
paletteModel.SetBgColor(rgbColor);
|
||||
|
||||
toolsModel.SetActiveTool(toolsModel.GetOldActiveTool());
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -49,8 +49,9 @@
|
||||
|
||||
#define WM_TOOLSMODELTOOLCHANGED (WM_APP + 0)
|
||||
#define WM_TOOLSMODELSETTINGSCHANGED (WM_APP + 1)
|
||||
#define WM_TOOLSMODELZOOMCHANGED (WM_APP + 2)
|
||||
#define WM_PALETTEMODELCOLORCHANGED (WM_APP + 3)
|
||||
#define WM_TOOLSMODELCOLORPICKED (WM_APP + 2)
|
||||
#define WM_TOOLSMODELZOOMCHANGED (WM_APP + 3)
|
||||
#define WM_PALETTEMODELCOLORCHANGED (WM_APP + 4)
|
||||
|
||||
enum HITTEST // hit
|
||||
{
|
||||
|
||||
@@ -391,8 +391,15 @@ LRESULT CToolSettingsWindow::OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BO
|
||||
drawBox(hdc, &rect1);
|
||||
drawLine(hdc, &rect2);
|
||||
break;
|
||||
case TOOL_FILL:
|
||||
case TOOL_COLOR:
|
||||
if (m_rgbPickColor != CLR_INVALID)
|
||||
{
|
||||
HBRUSH hbr = CreateSolidBrush(m_rgbPickColor);
|
||||
FillRect(hdc, &rect1, hbr);
|
||||
DeleteObject(hbr);
|
||||
}
|
||||
break;
|
||||
case TOOL_FILL:
|
||||
case TOOL_ZOOM:
|
||||
case TOOL_PEN:
|
||||
break;
|
||||
@@ -469,6 +476,7 @@ LRESULT CToolSettingsWindow::OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lPar
|
||||
|
||||
LRESULT CToolSettingsWindow::OnToolsModelToolChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
||||
{
|
||||
m_rgbPickColor = CLR_INVALID;
|
||||
Invalidate();
|
||||
trackbarZoom.ShowWindow((wParam == TOOL_ZOOM) ? SW_SHOW : SW_HIDE);
|
||||
return 0;
|
||||
@@ -480,6 +488,13 @@ LRESULT CToolSettingsWindow::OnToolsModelSettingsChanged(UINT nMsg, WPARAM wPara
|
||||
return 0;
|
||||
}
|
||||
|
||||
LRESULT CToolSettingsWindow::OnToolsModelColorPicked(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
||||
{
|
||||
m_rgbPickColor = (COLORREF)wParam;
|
||||
Invalidate();
|
||||
return 0;
|
||||
}
|
||||
|
||||
LRESULT CToolSettingsWindow::OnToolsModelZoomChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
||||
{
|
||||
int tbPos = MIN_ZOOM_TRACK;
|
||||
|
||||
@@ -20,6 +20,7 @@ public:
|
||||
MESSAGE_HANDLER(WM_NOTIFY, OnNotify)
|
||||
MESSAGE_HANDLER(WM_TOOLSMODELTOOLCHANGED, OnToolsModelToolChanged)
|
||||
MESSAGE_HANDLER(WM_TOOLSMODELSETTINGSCHANGED, OnToolsModelSettingsChanged)
|
||||
MESSAGE_HANDLER(WM_TOOLSMODELCOLORPICKED, OnToolsModelColorPicked)
|
||||
MESSAGE_HANDLER(WM_TOOLSMODELZOOMCHANGED, OnToolsModelZoomChanged)
|
||||
MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
|
||||
END_MSG_MAP()
|
||||
@@ -30,6 +31,7 @@ private:
|
||||
CWindow trackbarZoom;
|
||||
HICON m_hNontranspIcon;
|
||||
HICON m_hTranspIcon;
|
||||
COLORREF m_rgbPickColor = CLR_INVALID;
|
||||
|
||||
VOID drawTrans(HDC hdc, LPCRECT prc);
|
||||
VOID drawRubber(HDC hdc, LPCRECT prc);
|
||||
@@ -47,5 +49,6 @@ private:
|
||||
LRESULT OnNotify(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
||||
LRESULT OnToolsModelToolChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
||||
LRESULT OnToolsModelSettingsChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
||||
LRESULT OnToolsModelColorPicked(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
||||
LRESULT OnToolsModelZoomChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user