Beispiel #1
0
HRESULT MainWindow::CreateGraphicsResources()
{
	HRESULT hr = S_OK;
	if (pRenderTarget == NULL)
	{
		RECT rc;
		GetClientRect(m_hwnd, &rc);

		D2D1_SIZE_U size = D2D1::SizeU(rc.right, rc.bottom);

		hr = pFactory->CreateHwndRenderTarget(
			D2D1::RenderTargetProperties(),
			D2D1::HwndRenderTargetProperties(m_hwnd, size),
			&pRenderTarget);

		if (SUCCEEDED(hr))
		{
			const D2D1_COLOR_F color = D2D1::ColorF(1.0f, 1.0f, 0);
			hr = pRenderTarget->CreateSolidColorBrush(color, &pBrush);

			if (SUCCEEDED(hr))
			{
				CalculateLayout();
			}
		}
	}
	return hr;
}
void MWinDeviceImpl::SetBackColor(
	MColor				inColor)
{
	if (mBackBrush != nil)
		mBackBrush->Release();

	ID2D1SolidColorBrush* brush;
	THROW_IF_HRESULT_ERROR(
		mRenderTarget->CreateSolidColorBrush(D2D1::ColorF(inColor.red / 255.f, inColor.green / 255.f, inColor.blue / 255.f), &brush));

	mBackBrush = brush;
}
HRESULT D2DRenderer::InitializeDeviceDependentResources()
{
    HRESULT hr = S_OK;

    if (renderTarget_ != NULL)
        return hr;

    ID2D1HwndRenderTarget* renderTarget = NULL;
    ID2D1SolidColorBrush*  backBrush    = NULL;
    ID2D1SolidColorBrush*  textBrush    = NULL;
    ID2D1SolidColorBrush*  borderBrush  = NULL;

    D2D1_RENDER_TARGET_PROPERTIES renderTargetProperties = D2D1::RenderTargetProperties(
        D2D1_RENDER_TARGET_TYPE_DEFAULT,
        D2D1::PixelFormat(),
        static_cast<float>(g_dpiX),
        static_cast<float>(g_dpiY)
        );

    if (SUCCEEDED(hr))
    {
        hr = g_d2dFactory->CreateHwndRenderTarget(
                renderTargetProperties,
                D2D1::HwndRenderTargetProperties(hwnd_, D2D1::SizeU(width_, height_)),
                &renderTarget
                );
    }

    if (renderingParams_ != NULL)
    {
        renderTarget->SetTextRenderingParams(renderingParams_);
    }

    backColor_ = D2D1::ColorF(GetSysColor(COLOR_WINDOW));

    if (SUCCEEDED(hr))
    {
        hr = renderTarget->CreateSolidColorBrush(
                backColor_,
                &backBrush
                );
    }

    if (SUCCEEDED(hr))
    {
        hr = renderTarget->CreateSolidColorBrush(
                D2D1::ColorF(GetSysColor(COLOR_WINDOWTEXT)),
                &textBrush
                );
    }

    if (SUCCEEDED(hr))
    {
        hr = renderTarget->CreateSolidColorBrush(
                D2D1::ColorF(1.0f, 0, 0, 0.5f),
                &borderBrush
                );
    }

    // Commit changes.
    SafeAttach(&renderTarget_, SafeDetach(&renderTarget));
    SafeAttach(&backBrush_,    SafeDetach(&backBrush));
    SafeAttach(&textBrush_,    SafeDetach(&textBrush));
    SafeAttach(&borderBrush_,  SafeDetach(&borderBrush));

    return hr;
}