void Sample2DSceneRenderer::Render()
{
	ID2D1DeviceContext* context = m_deviceResources->GetD2DDeviceContext();

	// Dash array for dashStyle D2D1_DASH_STYLE_CUSTOM
	float dashes[] = { 1.0f, 2.0f, 2.0f, 3.0f, 2.0f, 2.0f };
	ID2D1StrokeStyle* m_stroke;
	m_deviceResources->GetD2DFactory()->CreateStrokeStyle(
		D2D1::StrokeStyleProperties(
		D2D1_CAP_STYLE_FLAT,
		D2D1_CAP_STYLE_FLAT,
		D2D1_CAP_STYLE_ROUND,
		D2D1_LINE_JOIN_MITER,
		10.0f,
		D2D1_DASH_STYLE_CUSTOM,
		0.0f),
		dashes,
		ARRAYSIZE(dashes),
		&m_stroke
		);

	context->BeginDraw();
	//context->Clear(D2D1::ColorF(D2D1::ColorF::CornflowerBlue));

	auto m_bitmapSize = m_pBitmap->GetSize();

	context->DrawBitmap(
		m_pBitmap.Get(),
		D2D1::RectF(200.0f, padding, m_bitmapSize.width + 200.0f, m_bitmapSize.height + padding)
		);

	context->DrawRectangle(
		D2D1::RectF(100.0f, 100.0f, 500.0f, 500.0f),
		m_pBlueBrush.Get(),
		4.0f,
		m_stroke
		);

	context->FillRectangle(
		D2D1::RectF(600.0f, 400.0f, 900.0f, 700.0f),
		m_pLinearGradientBrush.Get()
		);

	context->DrawLine(
		D2D1::Point2F(200, 300),
		D2D1::Point2F(800, 500),
		m_pBlueBrush.Get(),
		10.0f,
		m_stroke
		);

	DX::ThrowIfFailed(
		context->EndDraw()
		);
}
コード例 #2
0
void QWindowsDirect2DWindow::flush(QWindowsDirect2DBitmap *bitmap, const QRegion &region, const QPoint &offset)
{
    QSize size;
    if (m_directRendering) {
        DXGI_SWAP_CHAIN_DESC1 desc;
        HRESULT hr = m_swapChain->GetDesc1(&desc);
        QRect geom = geometry();

        if ((FAILED(hr) || (desc.Width != geom.width()) || (desc.Height != geom.height()))) {
            resizeSwapChain(geom.size());
            m_swapChain->GetDesc1(&desc);
        }
        size.setWidth(desc.Width);
        size.setHeight(desc.Height);
    } else {
        size = geometry().size();
    }

    setupBitmap();
    if (!m_bitmap)
        return;

    if (bitmap != m_bitmap.data()) {
        m_bitmap->deviceContext()->begin();

        ID2D1DeviceContext *dc = m_bitmap->deviceContext()->get();
        if (!m_needsFullFlush) {
            QRegion clipped = region;
            clipped &= QRect(QPoint(), size);

            foreach (const QRect &rect, clipped.rects()) {
                QRectF rectF(rect);
                dc->DrawBitmap(bitmap->bitmap(),
                               to_d2d_rect_f(rectF),
                               1.0,
                               D2D1_INTERPOLATION_MODE_LINEAR,
                               to_d2d_rect_f(rectF.translated(offset.x(), offset.y())));
            }
        } else {