Did a proper migration of d2dscratch.c.

This commit is contained in:
Pietro Gagliardi 2016-04-23 11:50:47 -04:00
parent fbef804608
commit a8b6cab2ab
2 changed files with 18 additions and 12 deletions

View File

@ -1,5 +1,5 @@
// 17 april 2016
#include "uipriv_windows.h"
#include "uipriv_windows.hpp"
// The Direct2D scratch window is a utility for libui internal use to do quick things with Direct2D.
// To use, call newD2DScratch() passing in a subclass procedure. This subclass procedure should handle the msgD2DScratchPaint message, which has the following usage:
@ -18,7 +18,7 @@ static HRESULT d2dScratchDoPaint(HWND hwnd, ID2D1RenderTarget *rt)
COLORREF bgcolorref;
D2D1_COLOR_F bgcolor;
ID2D1RenderTarget_BeginDraw(rt);
rt->BeginDraw();
// TODO only clear the clip area
// TODO clear with actual background brush
@ -29,11 +29,11 @@ static HRESULT d2dScratchDoPaint(HWND hwnd, ID2D1RenderTarget *rt)
bgcolor.g = ((float) ((BYTE) ((bgcolorref & 0xFF00) >> 8))) / 255.0;
bgcolor.b = ((float) GetBValue(bgcolorref)) / 255.0;
bgcolor.a = 1.0;
ID2D1RenderTarget_Clear(rt, &bgcolor);
rt->Clear(&bgcolor);
SendMessageW(hwnd, msgD2DScratchPaint, 0, (LPARAM) rt);
return ID2D1RenderTarget_EndDraw(rt, NULL, NULL);
return rt->EndDraw(NULL, NULL);
}
static LRESULT CALLBACK d2dScratchWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
@ -57,26 +57,26 @@ static LRESULT CALLBACK d2dScratchWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, L
switch (uMsg) {
case WM_DESTROY:
ID2D1HwndRenderTarget_Release(rt);
rt->Release();
SetWindowLongPtrW(hwnd, 0, (LONG_PTR) FALSE);
break;
case WM_PAINT:
hr = d2dScratchDoPaint(hwnd, (ID2D1RenderTarget *) rt);
hr = d2dScratchDoPaint(hwnd, rt);
switch (hr) {
case S_OK:
if (ValidateRect(hwnd, NULL) == 0)
logLastError("error validating D2D scratch control rect in d2dScratchWndProc()");
logLastError(L"error validating D2D scratch control rect");
break;
case D2DERR_RECREATE_TARGET:
// DON'T validate the rect
// instead, simply drop the render target
// we'll get another WM_PAINT and make the render target again
// TODO would this require us to invalidate the entire client area?
ID2D1HwndRenderTarget_Release(rt);
rt->Release();
SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR) NULL);
break;
default:
logHRESULT("error drawing D2D scratch window in d2dScratchWndProc()", hr);
logHRESULT(L"error drawing D2D scratch window", hr);
}
return 0;
case WM_PRINTCLIENT:
@ -104,7 +104,7 @@ ATOM registerD2DScratchClass(HICON hDefaultIcon, HCURSOR hDefaultCursor)
void unregisterD2DScratchClass(void)
{
if (UnregisterClassW(d2dScratchClass, hInstance) == 0)
logLastError("error unregistering D2D scratch window class in unregisterD2DScratchClass()");
logLastError(L"error unregistering D2D scratch window class");
}
HWND newD2DScratch(HWND parent, RECT *rect, HMENU controlID, SUBCLASSPROC subclass, DWORD_PTR subclassData)
@ -118,8 +118,9 @@ HWND newD2DScratch(HWND parent, RECT *rect, HMENU controlID, SUBCLASSPROC subcla
rect->right - rect->left, rect->bottom - rect->top,
parent, controlID, hInstance, NULL);
if (hwnd == NULL)
logLastError("error creating D2D scratch window in newD2DScratch()");
// TODO return decoy window
logLastError(L"error creating D2D scratch window");
if (SetWindowSubclass(hwnd, subclass, 0, subclassData) == FALSE)
logLastError("error subclassing D2D scratch window in newD2DScratch()");
logLastError(L"error subclassing D2D scratch window");
return hwnd;
}

View File

@ -72,6 +72,11 @@ extern BOOL handleParentMessages(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa
// resize.cpp
extern void doResizes(void);
// d2dscratch.cpp
extern ATOM registerD2DScratchClass(HICON hDefaultIcon, HCURSOR hDefaultCursor);
extern void unregisterD2DScratchClass(void);
extern HWND newD2DScratch(HWND parent, RECT *rect, HMENU controlID, SUBCLASSPROC subclass, DWORD_PTR subclassData);
// TODO