From a8b6cab2ab66d9e86e5b69ac14c62c55ab903f00 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sat, 23 Apr 2016 11:50:47 -0400 Subject: [PATCH] Did a proper migration of d2dscratch.c. --- windows/{d2dscratch.c => d2dscratch.cpp} | 25 ++++++++++++------------ windows/uipriv_windows_new.hpp | 5 +++++ 2 files changed, 18 insertions(+), 12 deletions(-) rename windows/{d2dscratch.c => d2dscratch.cpp} (82%) diff --git a/windows/d2dscratch.c b/windows/d2dscratch.cpp similarity index 82% rename from windows/d2dscratch.c rename to windows/d2dscratch.cpp index 19635071..06f49a41 100644 --- a/windows/d2dscratch.c +++ b/windows/d2dscratch.cpp @@ -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; } diff --git a/windows/uipriv_windows_new.hpp b/windows/uipriv_windows_new.hpp index a88d4e62..a8947c62 100644 --- a/windows/uipriv_windows_new.hpp +++ b/windows/uipriv_windows_new.hpp @@ -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