예제 #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);
    }
}
예제 #2
0
파일: Scene.cpp 프로젝트: dsp56001/CPP2014
void Scene::Render(HWND hwnd)
{
	HRESULT hr = CreateGraphicsResources(hwnd);
	if (FAILED(hr))
	{
		return;
	}

	assert(m_pRenderTarget != NULL);

	m_pRenderTarget->BeginDraw();

	RenderScene();

	hr = m_pRenderTarget->EndDraw();
	if (hr == D2DERR_RECREATE_TARGET)
	{
		DiscardDeviceDependentResources();
	}
}
예제 #3
0
void MainWindow::OnPaint()
{
	HRESULT hr = CreateGraphicsResources();
	if (SUCCEEDED(hr))
	{
		PAINTSTRUCT ps;
		BeginPaint(m_hwnd, &ps);

		pRenderTarget->BeginDraw();

		pRenderTarget->Clear(D2D1::ColorF(D2D1::ColorF::SkyBlue));
		pRenderTarget->FillEllipse(ellipse, pBrush);

		hr = pRenderTarget->EndDraw();
		if (FAILED(hr) || hr == D2DERR_RECREATE_TARGET)
		{
			DiscardGraphicsResources();
		}
		EndPaint(m_hwnd, &ps);
	}
}
// CResonanceStudioDraw drawing
// Note the top left is origen
void ResonanceStudioDraw::Draw(HWND m_hWnd, RECT rc, CResonanceStudioDoc *pDoc )
{
    CWaitCursor wait;
    clientRectangle = rc;

    pTheCoordinator = pDoc->GetCoordinator();
    if ( pTheCoordinator == nullptr )
    {
        return;
    }
    ptheParameterPack = pTheCoordinator->GetParameterPack();
    ptheFrequencyScale = ptheParameterPack->GetFrequencyScale();

    CPropertiesWnd *pthePropertiesWnd = &(pTheMainFrame->m_wndProperties);
    pthePropertiesWnd->SetOutputStatus();

    SetPalette();

    HRESULT hr = CreateGraphicsResources(m_hWnd, rc);

    if (SUCCEEDED(hr))
    {

        pRenderTarget->BeginDraw();

        // set the background and force a paint while we do our procesing
        pRenderTarget->Clear(backgroundColor);

        if ( pTheCoordinator->ProcessAndGetWICBitmap( &pWICBitmap ) )
        {
            // nothing to do. need actual screen size in renderTarget to map
        }

        // Get display times and other information
        highFrequencyLimit = ptheParameterPack->GetFilterHigh();
        lowFrequencyLimit = ptheParameterPack->GetFilterLow();
        rectangleSize = pRenderTarget->GetSize();
        dataBottom = rectangleSize.height;
        dataTop = audioScreenFraction * rectangleSize.height;

        if (pWICBitmap != nullptr )
        {
            // Copy WIC bitmap to ID2D1 bitmap
            hr = pRenderTarget->CreateBitmapFromWicBitmap( pWICBitmap, NULL, &pbitmap );

            time0 = pTheCoordinator->GetCurrentDisplayStartTime();
            time1 = pTheCoordinator->GetCurrentDisplayEndTime();
            double rate = pTheCoordinator->GetSamplingRate();

            SetStatus( time0, time1 );
            SetPixelTimeGrid( time1-time0, rate );

            // Use top 20% of screen for audio
            //const double xAxis = 0.1 * rectangleSize.height;
            double vScale = 0.2 * rectangleSize.height ;

            DrawAudioLine( 0.0, vScale );

            // Display the bitmap. Collect rectangle data first. Display to bottom section, below audio
            UINT uiWidth = 0;
            UINT uiHeight = 0;
            pWICBitmap->GetSize( &uiWidth, &uiHeight );

            D2D1_RECT_F sourceRectangle;
            CPropertiesWnd *pthePropertiesWnd = &(pTheMainFrame->m_wndProperties);
            if ( pthePropertiesWnd->GetFullScreenOrPan() == "Pan" )
            {
                // Limit travel
                float x = (float) panViewCorner.x;
                float y = (float) panViewCorner.y;
                x = max( x, 0.0f );
                y = max( y, 0.0f );
                x = min( x, uiWidth - rectangleSize.width );
                y = min( y, uiHeight - rectangleSize.height );
                sourceRectangle = D2D1::RectF(x, y,  x + rectangleSize.width, y + rectangleSize.height);
            }
            else
            {
                sourceRectangle = D2D1::RectF(0.0f, 0.0, (float) uiWidth, (float) uiHeight);
            }

            D2D1_RECT_F destinationRectangle = D2D1::RectF( 0.0f, (float) vScale, rectangleSize.width, rectangleSize.height);
            pRenderTarget->DrawBitmap(pbitmap, destinationRectangle,1.0F,D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, sourceRectangle);

            ptheDrawTimeFrequencyGrid->Draw( pRenderTarget, D2D1::RectF(0.0, (float) dataTop, rectangleSize.height, (float) dataBottom ),
                                             ptheParameterPack, time0, time1 );
        }


        hr = pRenderTarget->EndDraw();
        wait.Restore();
        DiscardGraphicsResources();
    }
}