Magic_Game/Easy2D/Win/winbase.cpp

69 lines
1.2 KiB
C++
Raw Normal View History

2017-10-10 01:14:03 +08:00
#include "winbase.h"
2017-10-13 11:42:36 +08:00
HWND hwnd = nullptr;
ID2D1Factory * pDirect2dFactory = nullptr;
ID2D1HwndRenderTarget * pRenderTarget = nullptr;
2017-10-14 18:43:32 +08:00
ID2D1SolidColorBrush * m_pSolidBrush = nullptr;
IWICImagingFactory * pIWICFactory = nullptr;
2017-10-10 01:14:03 +08:00
2017-10-12 02:44:44 +08:00
HWND &GetHWnd()
2017-10-10 01:14:03 +08:00
{
2017-10-13 11:42:36 +08:00
return hwnd;
2017-10-10 01:14:03 +08:00
}
2017-10-12 02:44:44 +08:00
ID2D1Factory * &GetFactory()
2017-10-10 01:14:03 +08:00
{
2017-10-13 11:42:36 +08:00
return pDirect2dFactory;
2017-10-11 11:15:17 +08:00
}
IWICImagingFactory * &GetImagingFactory()
{
if (!pIWICFactory)
{
CoCreateInstance(
CLSID_WICImagingFactory,
NULL,
CLSCTX_INPROC_SERVER,
IID_IWICImagingFactory,
reinterpret_cast<void **>(&pIWICFactory)
);
}
return pIWICFactory;
}
2017-10-12 02:44:44 +08:00
ID2D1HwndRenderTarget * &GetRenderTarget()
2017-10-11 11:15:17 +08:00
{
if (!pRenderTarget)
{
RECT rc;
GetClientRect(hwnd, &rc);
D2D1_SIZE_U size = D2D1::SizeU(
rc.right - rc.left,
rc.bottom - rc.top
);
// Create a Direct2D render target.
HRESULT hr;
hr = pDirect2dFactory->CreateHwndRenderTarget(
D2D1::RenderTargetProperties(),
D2D1::HwndRenderTargetProperties(hwnd, size),
&pRenderTarget
);
ASSERT(SUCCEEDED(hr), "Create Render Target Failed!");
}
2017-10-13 11:42:36 +08:00
return pRenderTarget;
2017-10-11 11:15:17 +08:00
}
ID2D1SolidColorBrush * &GetSolidColorBrush()
2017-10-14 18:43:32 +08:00
{
2017-10-15 02:46:24 +08:00
if (!m_pSolidBrush)
{
pRenderTarget->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::White), &m_pSolidBrush);
}
2017-10-14 18:43:32 +08:00
return m_pSolidBrush;
}