diff --git a/windows/colorbutton.cpp b/windows/colorbutton.cpp index edbba35d..b6c712c4 100644 --- a/windows/colorbutton.cpp +++ b/windows/colorbutton.cpp @@ -41,6 +41,7 @@ static BOOL onWM_COMMAND(uiControl *c, HWND hwnd, WORD code, LRESULT *lResult) b->g = rgba.g; b->b = rgba.b; b->a = rgba.a; + invalidateRect(b->hwnd, NULL, TRUE); (*(b->onChanged))(b, b->onChangedData); } diff --git a/windows/colordialog.cpp b/windows/colordialog.cpp index 096135dc..0c17dd28 100644 --- a/windows/colordialog.cpp +++ b/windows/colordialog.cpp @@ -363,13 +363,22 @@ static LRESULT CALLBACK svChooserSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LP { ID2D1RenderTarget *rt; struct colorDialog *c; + D2D1_POINT_2F *pos; + D2D1_SIZE_F *size; + c = (struct colorDialog *) dwRefData; switch (uMsg) { case msgD2DScratchPaint: rt = (ID2D1RenderTarget *) lParam; - c = (struct colorDialog *) dwRefData; drawSVChooser(c, rt); return 0; + case msgD2DScratchLButtonDown: + pos = (D2D1_POINT_2F *) wParam; + size = (D2D1_SIZE_F *) lParam; + c->s = pos->x / size->width; + c->v = 1 - (pos->y / size->height); + updateDialog(c, NULL); + return 0; case WM_NCDESTROY: if (RemoveWindowSubclass(hwnd, svChooserSubProc, uIdSubclass) == FALSE) logLastError(L"error removing color dialog SV chooser subclass"); diff --git a/windows/d2dscratch.cpp b/windows/d2dscratch.cpp index f9504317..146eea8b 100644 --- a/windows/d2dscratch.cpp +++ b/windows/d2dscratch.cpp @@ -6,6 +6,10 @@ // - wParam - 0 // - lParam - ID2D1RenderTarget * // - lResult - 0 +// You can optionally also handle msgD2DScratchLButtonDown, which is sent when the left mouse button is either pressed for the first time or held while the mouse is moving. +// - wParam - position in DIPs, as D2D1_POINT_2F * +// - lParam - size of render target in DIPs, as D2D1_SIZE_F * +// - lResult - 0 // Other messages can also be handled here. // TODO allow resize @@ -37,6 +41,26 @@ static HRESULT d2dScratchDoPaint(HWND hwnd, ID2D1RenderTarget *rt) return rt->EndDraw(NULL, NULL); } +static void d2dScratchDoLButtonDown(HWND hwnd, ID2D1RenderTarget *rt, LPARAM lParam) +{ + double xpix, ypix; + FLOAT dpix, dpiy; + D2D1_POINT_2F pos; + D2D1_SIZE_F size; + + xpix = (double) GET_X_LPARAM(lParam); + ypix = (double) GET_Y_LPARAM(lParam); + // these are in pixels; we need points + // TODO separate the function from areautil.cpp? + rt->GetDpi(&dpix, &dpiy); + pos.x = (xpix * 96) / dpix; + pos.y = (ypix * 96) / dpiy; + + size = rt->GetSize(); + + SendMessageW(hwnd, msgD2DScratchLButtonDown, (WPARAM) (&pos), (LPARAM) (&size)); +} + static LRESULT CALLBACK d2dScratchWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { LONG_PTR init; @@ -83,6 +107,14 @@ static LRESULT CALLBACK d2dScratchWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, L case WM_PRINTCLIENT: // TODO break; + case WM_LBUTTONDOWN: + d2dScratchDoLButtonDown(hwnd, rt, lParam); + return 0; + case WM_MOUSEMOVE: + // also send LButtonDowns when dragging + if ((wParam & MK_LBUTTON) != 0) + d2dScratchDoLButtonDown(hwnd, rt, lParam); + return 0; } return DefWindowProcW(hwnd, uMsg, wParam, lParam); } diff --git a/windows/uipriv_windows.hpp b/windows/uipriv_windows.hpp index d0b84a8c..d1380af3 100644 --- a/windows/uipriv_windows.hpp +++ b/windows/uipriv_windows.hpp @@ -13,8 +13,8 @@ enum { msgNOTIFY, msgHSCROLL, msgQueued, - // TODO convert to a function like with container? msgD2DScratchPaint, + msgD2DScratchLButtonDown, }; // alloc.cpp