Esempio n. 1
0
void GraphicsWindow::OnPaint()
{
    HRESULT hr = CreateGraphicsResources();
    if (SUCCEEDED(hr))
    {
        PAINTSTRUCT ps;
        BeginPaint(m_hwnd, &ps);

        pRenderTarget->BeginDraw();

        pRenderTarget->Clear( D2D1::ColorF(D2D1::ColorF::SkyBlue) ); // Clear the device to blue

		// Draw hands
		SYSTEMTIME time;
		GetLocalTime(&time);

		// 60 minutes = 30 degrees, 1 minute = 0.5 degree
		const float fHourAngle = (360.0f / 12) * (time.wHour) + (time.wMinute * 0.5f); 
		const float fMinuteAngle =(360.0f / 60) * (time.wMinute);
		const float fSecondAngle = (360.0f / 60) * (time.wSecond);

		// Draw all stored shapes
        for (auto i = ellipses.begin(); i != ellipses.end(); ++i)
        {
            (*i)->Draw(pRenderTarget, pBrush);

			// Outline the selected item inside the loop to ensure it is at the right depth
			if (Selection() == *i)
			{
				pBrush->SetColor(D2D1::ColorF(D2D1::ColorF::Red)); // SetColor is a non-expensive operation
				pRenderTarget->DrawEllipse(Selection()->ellipse, pBrush, 2.0f);
			}

			// Add clock hands to the ellipses, because.. why not
			pBrush->SetColor(D2D1::ColorF(D2D1::ColorF::Black));
			DrawClockHand(*i, 0.6f,  fHourAngle,   6);
			DrawClockHand(*i, 0.85f, fMinuteAngle, 4);
			DrawClockHand(*i, 0.85f, fSecondAngle, 2);
			
			// Restore the identity transformation for the next ellipse after rotating the clock hands
			pRenderTarget->SetTransform( D2D1::Matrix3x2F::Identity() );
        }

        hr = pRenderTarget->EndDraw(); // If an error occurs during any of the draw commands (begin, clear, fillellipse) it is returned here
        if (FAILED(hr) || hr == D2DERR_RECREATE_TARGET)
        {
			// If we failed for some reason, including if the device has become unavailable and we need to recreate then discard current resources
            DiscardGraphicsResources();
        }
        EndPaint(m_hwnd, &ps);
    }
}
Esempio n. 2
0
void Scene::RenderScene()
{
	m_pRenderTarget->Clear(D2D1::ColorF(D2D1::ColorF::CornflowerBlue));

	m_pRenderTarget->FillEllipse(m_ellipse, m_pFill);
	
	DrawClockHand(0.6f, 0, 6);
	m_pRenderTarget->SetTransform(D2D1::Matrix3x2F::Identity());
}