Implemented mouse control of the SV area; updated the color button immediately after a change.

This commit is contained in:
Pietro Gagliardi 2016-05-17 14:44:57 -04:00
parent 9654ca793d
commit 571faf9582
4 changed files with 44 additions and 2 deletions

View File

@ -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);
}

View File

@ -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");

View File

@ -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);
}

View File

@ -13,8 +13,8 @@ enum {
msgNOTIFY,
msgHSCROLL,
msgQueued,
// TODO convert to a function like with container?
msgD2DScratchPaint,
msgD2DScratchLButtonDown,
};
// alloc.cpp