Exemplo n.º 1
1
HRESULT Application::OnRender()
{
	HRESULT hr = S_OK;
	hr = CreateDeviceResources();

	if(SUCCEEDED(hr))
	{
		_pRenderTarget->BeginDraw();
		_pRenderTarget->SetTransform(D2D1::Matrix3x2F::Identity());
		_pRenderTarget->Clear(D2D1::ColorF(D2D1::ColorF::White));

		D2D1_SIZE_F rtSize = _pRenderTarget->GetSize();

		// Draw a grid background.
		int width = static_cast<int>(rtSize.width);
		int height = static_cast<int>(rtSize.height);

		for (int x = 0; x < width; x += 10) {
			_pRenderTarget->DrawLine(D2D1::Point2F(static_cast<FLOAT>(x), 0.0f), D2D1::Point2F(static_cast<FLOAT>(x), rtSize.height), _pLightSlateGrayBrush, 0.5f);
		}

		for (int y = 0; y < height; y += 10) {
			_pRenderTarget->DrawLine(D2D1::Point2F(0.0f, static_cast<FLOAT>(y)), D2D1::Point2F(rtSize.width, static_cast<FLOAT>(y)), _pLightSlateGrayBrush, 0.5f);
		}

		// Try to draw bitmap.
		if(_buffer != 0) {
			// Why? http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/17e9e6bd-aa91-40a3-afc9-3241a24afe00
			IWICBitmap *pEmbeddedBitmap;
			ID2D1Bitmap *pBitmap;
			IWICImagingFactory *pFactory = NULL;
			HDC screen = GetDC(0);
			float dpiScaleX = GetDeviceCaps(screen, LOGPIXELSX) / 96.0f;
			float dpiScaleY = GetDeviceCaps(screen, LOGPIXELSY) / 96.0f;
			ReleaseDC(0, screen);

			CoCreateInstance(CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_IWICImagingFactory, (LPVOID*) &pFactory);

			HDC memDC = CreateCompatibleDC(screen);
			hr = pFactory->CreateBitmapFromMemory(_width, _height, GUID_WICPixelFormat32bppPBGRA, _width * 4, _numBytes, _buffer, &pEmbeddedBitmap);

			if(SUCCEEDED(hr)) {
				hr = _pRenderTarget->CreateBitmapFromWicBitmap(pEmbeddedBitmap, &pBitmap);
				_pRenderTarget->DrawBitmap(pBitmap);
			}
		}

		hr = _pRenderTarget->EndDraw();
	}

	if(hr == D2DERR_RECREATE_TARGET)
	{
		hr = S_OK;
		DiscardDeviceResources();
	}

	return hr;
}
Exemplo n.º 2
0
int ContextD3D11::HandleDeviceLost() {
  SafeRelease(&swap_chain_);

  CreateDeviceResources();
  OnWindowSizeChange(width_,height_);
  return S_OK;
}
Exemplo n.º 3
0
    bool DisplayerImpl::SetupBackend() {
        if (mHasBackend)
            return false;

        if (mHwnd == NULL && (mWidth == 0 || mHeight == 0))
            return false;

        HRESULT hr = CreateDeviceIndependentResources();
        if (FAILED(hr))
            return false;

        hr = CreateDeviceResources();
        if (FAILED(hr))
            return false;

        hr = CreateTargetDependentResources();
        if (FAILED(hr))
            return false;

        if (mHwnd) {
            hr = CreateDCompResources();
            if (FAILED(hr))
                return false;
        }

        mHasBackend = true;
        return true;
    }
HRESULT SimpleText::DrawD2DContent()
{
    HRESULT hr;


    hr = CreateDeviceResources();

    if (!(pRT_->CheckWindowState() & D2D1_WINDOW_STATE_OCCLUDED))
    {
        pRT_->BeginDraw();

        pRT_->SetTransform(D2D1::IdentityMatrix());

        pRT_->Clear(D2D1::ColorF(D2D1::ColorF::White));

        // Call the DrawText method of this class.
        hr = DrawText();

        if (SUCCEEDED(hr))
        {
            hr = pRT_->EndDraw(
                );
        }
    }

    if (FAILED(hr))
    {
        DiscardDeviceResources();
    }


    return hr;
}
Exemplo n.º 5
0
HRESULT CMainWindow::DrawClientArea()
{
    // Begin drawing the client area

    HRESULT hr = CreateDeviceResources();
    if (SUCCEEDED(hr))
    {
        hr = FindImages();
        if (SUCCEEDED(hr))
        {
            m_pRenderTarget->BeginDraw();

            // Retrieve the size of the render target

            D2D1_SIZE_F sizeRenderTarget = m_pRenderTarget->GetSize();
            
            // Paint the background

            m_pRenderTarget->FillRectangle(
                D2D1::RectF(
                    0.0f,
                    0.0f,
                    sizeRenderTarget.width,
                    sizeRenderTarget.height
                    ),
                m_pBackgroundBrush
                );

            // Paint all the thumbnails

            for (UINT i = 0; i < m_uThumbCount; i++)
            {
                hr = m_thumbs[i].Render(
                    m_pRenderTarget,
                    m_pOutlineBrush
                    );
                if (FAILED(hr))
                {
                    break;
                }
            }

            // Can only return one failure HRESULT
            HRESULT hrEndDraw = m_pRenderTarget->EndDraw();
            if (SUCCEEDED(hr))
            {
                hr = hrEndDraw;
            }
        }

        if (hr == D2DERR_RECREATE_TARGET)
        {
            DiscardDeviceResources();
        }
    }
    
    return hr;
}
Exemplo n.º 6
0
void Sandbox::Renderer::Initialize()
{
	PrintToDebugWindowOnly8("Sandbox. Initializing renderer.");
	EnterCriticalSection(&m_lock);

	DirectXBaseDesktop::Initialize();

	CreateDeviceIndependentResources();
	CreateDeviceResources();
	CreateWindowSizeDependentResources();

	m_glassRenderer->WICFactory(m_wicFactory.Get());
	m_sceneRenderer->WICFactory(m_wicFactory.Get());
	m_glassRenderer->Context3(m_d3dContext.Get());
	m_sceneRenderer->Context3(m_d3dContext.Get());
	m_glassRenderer->Device3(m_d3dDevice.Get());
	m_sceneRenderer->Device3(m_d3dDevice.Get());
	m_sceneRenderTarget.Context3(m_d3dContext.Get());
	m_sceneRenderTarget.Device3(m_d3dDevice.Get());

	m_sceneRenderTarget.Height(m_d3dRenderTargetSize.height);
	m_sceneRenderTarget.Width(m_d3dRenderTargetSize.width);
	m_sceneRenderTarget.Initialize();

	(*m_sceneRenderTarget.EditViewport()) = m_viewport;
	m_sceneRenderTarget.EditClear()->x = 0.4f;
	m_sceneRenderTarget.EditClear()->y = 0.4f;
	m_sceneRenderTarget.EditClear()->z = 0.4f;
	m_sceneRenderTarget.EditClear()->w = 1.0f;
	m_clear = m_sceneRenderTarget.GetClearCpy();

	m_camera.Aspect(m_d3dRenderTargetSize.width / m_d3dRenderTargetSize.height);
	m_camera.Fov(Reign::XM_PIDIV4);
	m_camera.Near(100.0f);
	m_camera.Far(0.01f);
	(*m_camera.EditFocus()) = Reign::Vector3(0.0f, 0.0f, 10.0f);
	(*m_camera.EditEye()) = Reign::Vector3(0.0f, 0.0f, -15.0f);

	m_camera.UpdateProj();
	m_camera.UpdateView();

	m_glassRenderer->SceneRenderTarget(&m_sceneRenderTarget);
	m_glassRenderer->Initialize();
	m_sceneRenderer->Initialize();

	m_sceneRenderer->EditSceneSpatial()->World = Matrix::CreateTranslation(0.0f, 0.0f, 20.0f);
	m_sceneRenderer->EditSceneSpatial()->View = m_camera.GetViewCpy();
	m_sceneRenderer->EditSceneSpatial()->Proj = m_camera.GetProjCpy();

	m_glassRenderer->EditGlassSpatial()->World = Matrix::CreateTranslation(0.0f, 0.0f, 0.0f);
	//  * Matrix::CreateRotationY(Reign::XM_PIDIV4);
	m_glassRenderer->EditGlassSpatial()->View = m_camera.GetViewCpy();
	m_glassRenderer->EditGlassSpatial()->Proj = m_camera.GetProjCpy();
	m_glassRenderer->EditGlassPerturb()->RefractionPerturb = 0.01;

	LeaveCriticalSection(&m_lock);
}
LRESULT DemoApp::OnPaint(HWND hWnd)
{
    HRESULT hr = S_OK;
    PAINTSTRUCT ps;

    HDC hdc = BeginPaint(hWnd, &ps);

    if (hdc)
    {
        // Create render target if not yet created
        hr = CreateDeviceResources(hWnd);

        if (SUCCEEDED(hr) && !(m_pRT->CheckWindowState() & D2D1_WINDOW_STATE_OCCLUDED))
        {
            m_pRT->BeginDraw();

            m_pRT->SetTransform(D2D1::Matrix3x2F::Identity());

            // Clear the background
            m_pRT->Clear(D2D1::ColorF(D2D1::ColorF::White));

            D2D1_SIZE_F rtSize = m_pRT->GetSize();

            // Create a rectangle same size of current window
            D2D1_RECT_F rectangle = D2D1::RectF(0.0f, 0.0f, rtSize.width, rtSize.height);

            // D2DBitmap may have been released due to device loss. 
            // If so, re-create it from the source bitmap
            if (m_pConvertedSourceBitmap && !m_pD2DBitmap)
            {
                m_pRT->CreateBitmapFromWicBitmap(m_pConvertedSourceBitmap, NULL, &m_pD2DBitmap);
            }

            // Draws an image and scales it to the current window size
            if (m_pD2DBitmap)
            {
                m_pRT->DrawBitmap(m_pD2DBitmap, rectangle);
            }

            hr = m_pRT->EndDraw();

            // In case of device loss, discard D2D render target and D2DBitmap.
            // They will be re-create in the next rendering pass
            if (hr == D2DERR_RECREATE_TARGET)
            {
                SafeRelease(m_pD2DBitmap);
                SafeRelease(m_pRT);
                // Force a re-render
                hr = InvalidateRect(hWnd, NULL, TRUE)? S_OK : E_FAIL;
            }
        }

        EndPaint(hWnd, &ps);
    }

    return SUCCEEDED(hr) ? 0 : 1;
}  
Exemplo n.º 8
0
HRESULT BaseApp::Initialize()
{
	HRESULT hr;

	//get the dpi information
	HDC screen = GetDC(0);
	ReleaseDC(0, screen);

	// Initialize device-indpendent resources, such
	// as the Direct2D factory.
	hr = CreateDeviceIndependentResources();

	if (SUCCEEDED(hr))
	{

		// Register the window class.
		WNDCLASSEX wcex = { sizeof(WNDCLASSEX) };
		wcex.style = CS_HREDRAW | CS_VREDRAW;
		wcex.lpfnWndProc = BaseApp::WndProc;
		wcex.cbClsExtra = 0;
		wcex.cbWndExtra = sizeof(LONG_PTR);
		wcex.hInstance = HINST_THISCOMPONENT;
		wcex.hbrBackground = NULL;
		wcex.lpszMenuName = NULL;
		wcex.hCursor = LoadCursor(NULL, IDI_APPLICATION);
		wcex.lpszClassName = "Base App Window Class";

		RegisterClassEx(&wcex);


		// Create the window.
		m_hwnd = CreateWindow(
			"Base App Window Class",
			"DubboIT - D2D Base App",
			WS_OVERLAPPEDWINDOW,
			CW_USEDEFAULT,
			CW_USEDEFAULT,
			CW_USEDEFAULT,
			CW_USEDEFAULT,
			NULL,
			NULL,
			HINST_THISCOMPONENT,
			this
			);
		hr = m_hwnd ? S_OK : E_FAIL;
		if (SUCCEEDED(hr))
		{
			hr = CreateDeviceResources(m_hwnd);
			ShowWindow(m_hwnd, SW_SHOWNORMAL);
			UpdateWindow(m_hwnd);
		}

	}

	return hr;
}
Exemplo n.º 9
0
    void Begin(RECT rcWnd, int yPitch) {
        CopyRect(&rcWnd_, &rcWnd);
        yPitch_ = yPitch;
        hr = CreateDeviceResources();

        if (SUCCEEDED(hr))
        {
            pRT_->BeginDraw();
            pRT_->SetTransform(D2D1::IdentityMatrix());
            pRT_->Clear(D2D1::ColorF(D2D1::ColorF::White, 0.0f));
        }
    }
Exemplo n.º 10
0
Direct2DRenderer::Direct2DRenderer(HWND hWnd) : hWnd_{hWnd}
{
	 	HRESULT hr = CreateDeviceIndependentResources();
	 	if (SUCCEEDED(hr))
	 	{
	 		hr = CreateDeviceResources();
	 	}
		if (FAILED(hr))
		{
			throw - 1;//change this Artie for the love of God
		}
}
Exemplo n.º 11
0
int ContextD3D11::CreateDisplay(HWND window) {
  window_handle_ = window;
  int hr = S_OK;

  
  


/*
  DXGI_SWAP_CHAIN_DESC sd;
  ZeroMemory( &sd, sizeof( sd ) );
  sd.BufferCount = 2;
  sd.BufferDesc.Width = width_;
  sd.BufferDesc.Height = height_;
  sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
  sd.BufferDesc.RefreshRate.Numerator = 60;
  sd.BufferDesc.RefreshRate.Denominator = 1;
  sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
  sd.OutputWindow = window_handle_;
  sd.SampleDesc.Count = 1;
  sd.SampleDesc.Quality = 0;
  sd.Windowed = TRUE;

  
  hr = D3D11CreateDeviceAndSwapChain( NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, creationFlags, NULL, 0,
                                          D3D11_SDK_VERSION, &sd, &swap_chain_, &device_, &feature_level, &device_context_ );
  int inta = GetLastError();
  if( FAILED( hr ) )
      return hr;

  Resize(width_,height_);
  /*
  IDXGISurface *pBackBuffer = NULL;
  hr = swap_chain_->GetBuffer( 0, IID_PPV_ARGS(&pBackBuffer) );
  if( FAILED( hr ) )
      return hr;

  FLOAT dpiX;
  FLOAT dpiY;
  d2d_factory_->GetDesktopDpi(&dpiX, &dpiY);

  D2D1_RENDER_TARGET_PROPERTIES props = D2D1::RenderTargetProperties(D2D1_RENDER_TARGET_TYPE_DEFAULT,D2D1::PixelFormat(DXGI_FORMAT_UNKNOWN, D2D1_ALPHA_MODE_PREMULTIPLIED),0,0);

  // Create a Direct2D render target which can draw into the surface in the swap chain
  //SafeRelease(&m_pBackBufferRT);
  hr = d2d_factory_->CreateDxgiSurfaceRenderTarget(pBackBuffer,&props,&d2d_render_target_);
    
  SafeRelease(&pBackBuffer);*/
  return CreateDeviceResources();
  //return CreateWindowSizeDependentResources();

}
Exemplo n.º 12
0
HRESULT MainWindow::OnRender()
{
	auto hr = CreateDeviceResources();
	hr = DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED,
							 __uuidof(IDWriteFactory),
							 reinterpret_cast<IUnknown**>(&m_pWriteFactory));
	if (hr != S_OK) return hr;
	hr = m_pWriteFactory->CreateTextFormat(
		L"Segoe UI",
		NULL,
		DWRITE_FONT_WEIGHT_NORMAL,
		DWRITE_FONT_STYLE_NORMAL,
		DWRITE_FONT_STRETCH_NORMAL,
		12.0f * 96.0f / 72.0f,
		L"zh-CN",
		&m_pWriteTextFormat);
#pragma warning(disable:4244)
#pragma warning(disable:4267)
	if (SUCCEEDED(hr)) {
		RECT rect;
		GetClientRect(&rect);
		m_pHwndRenderTarget->BeginDraw();
		m_pHwndRenderTarget->SetTransform(D2D1::Matrix3x2F::Identity());
		m_pHwndRenderTarget->Clear(D2D1::ColorF(D2D1::ColorF::White, 1.0f));

		m_pHwndRenderTarget->DrawRectangle(D2D1::RectF(20, 10, rect.right - rect.left - 20, 150), m_AreaBorderBrush, 1.0);
		m_pHwndRenderTarget->DrawRectangle(D2D1::RectF(20, 150, rect.right - rect.left - 20, rect.bottom-rect.top-20), m_AreaBorderBrush, 1.0);

		for (auto &label : label_) {
			if (label.text.empty())
				continue;
			m_pHwndRenderTarget->DrawTextW(label.text.c_str(),
										   label.text.size(),
										   m_pWriteTextFormat,
										   D2D1::RectF(label.layout.left, label.layout.top, label.layout.right, label.layout.bottom),
										   m_pBasicTextBrush,
										   D2D1_DRAW_TEXT_OPTIONS_NONE, DWRITE_MEASURING_MODE_NATURAL);
		}
		m_pWriteTextFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER);
		hr = m_pHwndRenderTarget->EndDraw();
	}
#pragma warning(default:4244)
#pragma warning(default:4267)	
	if (hr == D2DERR_RECREATE_TARGET) {
		hr = S_OK;
		DiscardDeviceResources();
		::InvalidateRect(m_hWnd, nullptr, FALSE);
	}
	return hr;
}
Exemplo n.º 13
0
    HRESULT DisplayerImpl::HandleDeviceLost() {
        HRESULT hr = CreateDeviceResources();
        if (FAILED(hr))
            return hr;

        hr = CreateTargetDependentResources();
        if (FAILED(hr))
            return hr;

        if (mHwnd) {
            hr = CreateDCompResources();
            if (FAILED(hr))
                return hr;
        }

        mNeedRecreateBitmap = true;

        return hr;
    }
Exemplo n.º 14
0
HRESULT Direct2DRenderer::DrawClientArea(const std::vector<GIT_Commit_Local>*const commits)
{
	if (D2DERR_RECREATE_TARGET == hr_)
	{
		CreateDeviceResources();
	}

	HRESULT hr = S_OK;
	CRect rect;
	GetClientRect(hWnd_,rect);
	D2D1_RECT_F dx_rect;

	dx_rect.bottom = rect.bottom;
	dx_rect.left = rect.left;
	dx_rect.right = rect.right;
	dx_rect.top = rect.top;

	{
		//Drawing part
		m_renderTarget->BeginDraw();

		m_renderTarget->SetTransform(D2D1::Matrix3x2F::Identity());
		m_renderTarget->Clear(D2D1::ColorF(D2D1::ColorF::Aqua));
		//m_renderTarget->DrawBitmap(m_arrowBitmap, &dx_rect);
		draw_tail_();
		if (nullptr != commits)
		{
			draw_commits_(commits);
		}
		draw_head_();
		hr = m_renderTarget->EndDraw();
	}

	if (hr == D2DERR_RECREATE_TARGET)
	{
		hr_ = D2DERR_RECREATE_TARGET;
		hr = S_OK;
		DiscardDeviceResources();
	}

	return hr;
}
Exemplo n.º 15
0
HRESULT GameState::Render()
{
	HRESULT hr = S_OK;

	hr = CreateDeviceResources();

	if(SUCCEEDED(hr))
	{
		renderTarget->BeginDraw();
		OnRender(renderTarget);
		hr = renderTarget->EndDraw();
	}

	if (hr == D2DERR_RECREATE_TARGET)
    {
        hr = S_OK;
        DiscardDeviceResources();
    }

	return hr;
}
Exemplo n.º 16
0
void MainApp::OnRender()
{
	HRESULT hr = S_OK;

	hr = CreateDeviceResources();

	if (SUCCEEDED(hr))
	{
		pRenderTarget->BeginDraw();

		pRenderTarget->SetTransform(D2D1::Matrix3x2F::Identity());

		pRenderTarget->Clear(pBrush->GetColor());

		D2D1_SIZE_F rtSize = pRenderTarget->GetSize();

		int width = static_cast<int>(rtSize.width);
		int height = static_cast<int>(rtSize.height);

		D2D1_RECT_F r1 = D2D1::RectF(20, 20, 520, 520);
		D2D1_RECT_F r2 = D2D1::RectF(220, 220, 320, 320);

		//TestScreen
		pBrush->SetColor(D2D1::ColorF(D2D1::ColorF::Turquoise));
		pRenderTarget->FillRectangle(r1, pBrush);
		pBrush->SetColor(D2D1::ColorF(D2D1::ColorF::IndianRed));
		pRenderTarget->FillRectangle(r2, pBrush);
		pBrush->SetColor(D2D1::ColorF(D2D1::ColorF::Gold));
		//TestScreen

		hr = pRenderTarget->EndDraw();
	}

	if (hr == D2DERR_RECREATE_TARGET)
	{
		hr = S_OK;
		DiscardDeviceResources();
	}
}
Exemplo n.º 17
0
// This method discards device-specific
// resources if the Direct3D device dissapears during execution and
// recreates the resources the next time it's invoked.
HRESULT Direct2D_Miffy::OnRender()
{
    HRESULT hr = S_OK;

    hr = CreateDeviceResources();

    if (SUCCEEDED(hr))
    {
        m_pRenderTarget->BeginDraw();

        m_pRenderTarget->SetTransform(D2D1::Matrix3x2F::Identity());

		m_pRenderTarget->Clear(D2D1::ColorF(D2D1::ColorF::White));

        D2D1_SIZE_F rtSize = m_pRenderTarget->GetSize();

		// Draw Sky
		D2D1_RECT_F rectangle = D2D1::RectF(0.0f, 0.0f, rtSize.width, rtSize.height);
		m_pRenderTarget->FillRectangle(rectangle, m_pLinearGradientBrush);

		// Draw title
		D2D1_RECT_F layoutRect = D2D1::RectF(200.0, -30.0, 640.0, 48.0);
		const wchar_t* text = L"Miffy the bunny";
		m_pRenderTarget->DrawText(text, wcslen(text), m_pTextFormat, layoutRect, m_pSolidBlackBrush);

		// Draw Miffy
		m_pPathGeometryUnion->Open(&m_pGeometrySink);

		if(SUCCEEDED(hr)) {
			hr = m_pEllipseGeometry1->CombineWithGeometry(
				m_pEllipseGeometry3,
				D2D1_COMBINE_MODE_UNION,
				NULL,
				NULL,
				m_pGeometrySink
				);
		}

		m_pGeometrySink->Close();
		SafeRelease(&m_pGeometrySink);

		m_pPathGeometryUnion2->Open(&m_pGeometrySink);
		if(SUCCEEDED(hr)) {
			hr = m_pPathGeometryUnion->CombineWithGeometry(
				m_pEllipseGeometry2,
				D2D1_COMBINE_MODE_UNION,
				NULL,
				NULL,
				m_pGeometrySink
				);
		}
		m_pGeometrySink->Close();

		// draw the ears, face and eyes
		m_pRenderTarget->FillGeometry(m_pEllipseGeometry1, m_pSolidWhiteBrush);
		m_pRenderTarget->FillGeometry(m_pEllipseGeometry2, m_pSolidWhiteBrush);
		m_pRenderTarget->FillGeometry(m_pEllipseGeometry3, m_pSolidWhiteBrush);
		m_pRenderTarget->FillGeometry(m_pEllipseGeometry4, m_pSolidBlackBrush);
		m_pRenderTarget->FillGeometry(m_pEllipseGeometry5, m_pSolidBlackBrush);
		m_pRenderTarget->DrawGeometry(m_pPathGeometryUnion2, m_pSolidBlackBrush, 1.0f);
		m_pRenderTarget->DrawGeometry(m_pEllipseGeometry4, m_pSolidBlackBrush, 1.0f);
		m_pRenderTarget->DrawGeometry(m_pEllipseGeometry5, m_pSolidBlackBrush, 1.0f);

		// draw the mouth
		D2D1_POINT_2F point1 = D2D1::Point2F(310, 365);
		D2D1_POINT_2F point2 = D2D1::Point2F(330, 385);
		D2D1_POINT_2F point3 = D2D1::Point2F(330, 365);
		D2D1_POINT_2F point4 = D2D1::Point2F(310, 385);
		m_pRenderTarget->DrawLine(point1, point2, m_pSolidBlackBrush, 1.5f);
		m_pRenderTarget->DrawLine(point3, point4, m_pSolidBlackBrush, 1.5f);

		// Draw author name.
		layoutRect = D2D1::RectF(520.0, 400.0, 640.0, 460.0);
		text = L"Yanzheng Li";
		m_pRenderTarget->DrawText(text, wcslen(text), m_pTextFormat2, layoutRect, m_pSolidBlackBrush);

        hr = m_pRenderTarget->EndDraw();
    }

    if (hr == D2DERR_RECREATE_TARGET) {
        hr = S_OK;
        DiscardDeviceResources();
    }

    return hr;
}
/******************************************************************
*  Create a D2DBitmap at a specific progressive level             *
******************************************************************/
HRESULT DemoApp::CreateD2DBitmapFromProgressiveCtrl(HWND hWnd, UINT uLevel)
{
    HRESULT hr = E_FAIL;
    
    // Make sure source frame has been decoded successfully
    if (m_pSourceFrame)
    {
        // Query for Progressive Interface Control
        IWICProgressiveLevelControl *pProgressive = NULL;
        
        hr = m_pSourceFrame->QueryInterface(IID_PPV_ARGS(&pProgressive));

        // Set the progessive level before converting the format
        if (SUCCEEDED(hr))
        {
            hr = pProgressive->SetCurrentLevel(uLevel);
        }

        if (SUCCEEDED(hr))
        {
            SafeRelease(m_pConvertedSourceBitmap);
            hr = m_pIWICFactory->CreateFormatConverter(&m_pConvertedSourceBitmap);
        }

        if (SUCCEEDED(hr) && m_pConvertedSourceBitmap)
        {
            // Format convert the current progressive level frame to 32bppPBGRA 
            hr = m_pConvertedSourceBitmap->Initialize(
                m_pSourceFrame,                  // Source bitmap to convert
                GUID_WICPixelFormat32bppPBGRA,   // Destination pixel format
                WICBitmapDitherTypeNone,         // Specified dither pattern
                NULL,                            // Specify a particular palette 
                0.f,                             // Alpha threshold
                WICBitmapPaletteTypeCustom       // Palette translation type
                );
        }

        if (SUCCEEDED(hr))
        {
            // Create device render target
            hr = CreateDeviceResources(hWnd);
        }

        // Create D2D bitmap from the converted source bitmap.
        if (SUCCEEDED(hr))
        {
            // Need to release the previous D2DBitmap if there is one.
            // For every new progressive level, we need to create a new D2DBitmap
            SafeRelease(m_pD2DBitmap);
            hr = m_pRT->CreateBitmapFromWicBitmap(m_pConvertedSourceBitmap, NULL, &m_pD2DBitmap);
        }

        // Update status window display
        if (SUCCEEDED(hr) && IsWindow(m_hStatusWnd))
        {
            WCHAR szLevelName[MAX_PATH];
            swprintf_s(szLevelName, ARRAYSIZE(szLevelName), L"Current Progress Level: %d", uLevel);
            SetWindowText(m_hStatusWnd, szLevelName);
        }

        // Force re-render
        if (SUCCEEDED(hr))
        {
            hr = InvalidateRect(hWnd, NULL, FALSE) ? S_OK : E_FAIL;
        }

        SafeRelease(pProgressive);
    }

    return hr;
}
Exemplo n.º 19
0
HRESULT MetroWindow::OnRender()
{
	HRESULT hr = S_OK;
	//const wchar_t* szFont[2] = { L"Segeo UI", L"Microsoft Yahei"};
	
	hr = CreateDeviceResources();
	//IDWriteTextLayout 
	DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED,
		__uuidof(IDWriteFactory),
		reinterpret_cast<IUnknown**>(&m_pIDWriteFactory));
	m_pIDWriteFactory->CreateTextFormat(
		normalFont.c_str(),
		NULL,
		DWRITE_FONT_WEIGHT_NORMAL,
		DWRITE_FONT_STYLE_NORMAL,
		DWRITE_FONT_STRETCH_NORMAL,
		12.0f * 96.0f / 72.0f,
		localeinfo.localename.c_str(),
		&m_pITextFormatTitle
		);
	 //m_pITextFormatContent
	m_pIDWriteFactory->CreateTextFormat(
		normalFont.c_str(),
		NULL,
		DWRITE_FONT_WEIGHT_NORMAL,
		DWRITE_FONT_STYLE_NORMAL,
		DWRITE_FONT_STRETCH_NORMAL,
		11.0f * 96.0f / 72.0f,
		localeinfo.localename.c_str(),
		&m_pITextFormatContent
		);
	if (SUCCEEDED(hr))
	{
		m_pRenderTarget->BeginDraw();
		m_pRenderTarget->SetTransform(D2D1::Matrix3x2F::Identity());
		m_pRenderTarget->Clear(D2D1::ColorF(0xFFFFFF));
		////Draw Exit area
		POINT pt;
		GetCursorPos(&pt);
		ScreenToClient(&pt);
		/////// Area Draw
		

		D2D1_SIZE_F rtSize = m_pRenderTarget->GetSize();

		int width = static_cast<int>(rtSize.width);
		int height = static_cast<int>(rtSize.height);

#pragma warning(disable:4244)
#pragma warning(disable:4267)
		D2D1_SIZE_F size = m_pBitmap->GetSize();
		D2D1_POINT_2F upperLeftCorner = D2D1::Point2F(0.f, 0.f);
		m_pRenderTarget->DrawBitmap(m_pBitmapBkg, D2D1::RectF(
			0, 0, width, height
			));
		m_pRenderTarget->DrawBitmap(
			m_pBitmap,
			D2D1::RectF(
			upperLeftCorner.x,
			upperLeftCorner.y,
			upperLeftCorner.x + size.width-2,
			upperLeftCorner.y + size.height-2)
			);


		//// Text Draw
		m_pRenderTarget->DrawTextW(windowTitle.c_str(), windowTitle.length(), m_pITextFormatTitle, D2D1::RectF(35, 5, 600, 25), m_pControlTextBrush, D2D1_DRAW_TEXT_OPTIONS_NONE, DWRITE_MEASURING_MODE_NATURAL);

		//m_pITextFormatContent->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_TRAILING);
		m_pRenderTarget->DrawTextW(USBdrive.c_str(), USBdrive.size(), m_pITextFormatContent, D2D1::RectF(30, 60, 110, 85), m_pControlTextBrush, D2D1_DRAW_TEXT_OPTIONS_NONE, DWRITE_MEASURING_MODE_NATURAL);
		m_pRenderTarget->DrawTextW(ImageFile.c_str(), ImageFile.size(), m_pITextFormatContent, D2D1::RectF(30, 95, 110, 122), m_pControlTextBrush, D2D1_DRAW_TEXT_OPTIONS_NONE, DWRITE_MEASURING_MODE_NATURAL);
		m_pRenderTarget->DrawTextW(ImageSize.c_str(), ImageSize.size(), m_pITextFormatContent, D2D1::RectF(30, 130, 110, 157), m_pControlTextBrush, D2D1_DRAW_TEXT_OPTIONS_NONE, DWRITE_MEASURING_MODE_NATURAL);
		m_pRenderTarget->DrawTextW(Description.c_str(), Description.size(), m_pITextFormatContent, D2D1::RectF(30, 167, 110, 221), m_pControlTextBrush, D2D1_DRAW_TEXT_OPTIONS_NONE, DWRITE_MEASURING_MODE_NATURAL);
		m_pRenderTarget->DrawTextW(copyright.c_str(), copyright.size(), m_pITextFormatContent, D2D1::RectF(30, m_Operate.place.top+10, 400, m_Operate.place.bottom), m_pControlTextBrush, D2D1_DRAW_TEXT_OPTIONS_NONE, DWRITE_MEASURING_MODE_NATURAL);
		m_pITextFormatContent->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_JUSTIFIED);
		m_pRenderTarget->DrawTextW(ProcessInfo.c_str(), ProcessInfo.length(), m_pITextFormatContent, D2D1::RectF(320.0f, xArea.bottom + 30.0f, xArea.right, xArea.bottom + 200.0f), m_pControlTextBrush, D2D1_DRAW_TEXT_OPTIONS_NONE, DWRITE_MEASURING_MODE_NATURAL);
		m_pRenderTarget->DrawTextW(JobStatusRate.c_str(), JobStatusRate.length(), m_pITextFormatContent, D2D1::RectF(320.0f, xArea.bottom + 90.0f, xArea.right, xArea.bottom + 260.0f), m_pControlTextBrush, D2D1_DRAW_TEXT_OPTIONS_NONE, DWRITE_MEASURING_MODE_NATURAL);
		m_pRenderTarget->DrawTextW(MTNotices.c_str(), MTNotices.length(), m_pITextFormatContent, D2D1::RectF(xArea.left + 10.f, xArea.bottom + 20.0f, xArea.right / 2 - 60.f, xArea.bottom + 200.0f), m_pControlTextBrush, D2D1_DRAW_TEXT_OPTIONS_NONE, DWRITE_MEASURING_MODE_NATURAL);
		m_pRenderTarget->DrawTextW(Notes.c_str(), Notes.size(), m_pITextFormatContent, D2D1::RectF(120, 167, 690, 221), m_pControlTextBrush, D2D1_DRAW_TEXT_OPTIONS_NONE, DWRITE_MEASURING_MODE_NATURAL);
		m_pRenderTarget->DrawTextW(SizeStr, wcslen(SizeStr), m_pITextFormatContent, D2D1::RectF(120, 130, 680, 157), m_pControlTextBrush, D2D1_DRAW_TEXT_OPTIONS_NONE, DWRITE_MEASURING_MODE_NATURAL);
		/////////////////
		/// Button Draw
		m_pITextFormatContent->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER);
		m_pITextFormatTitle->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER);
		//Exit
		if (pt.x >= m_rexit.place.left&&pt.x <= m_rexit.place.right&&pt.y >= m_rexit.place.top&&pt.y <= m_rexit.place.bottom){
			m_pRenderTarget->FillRectangle(D2D1::RectF(m_rexit.place.left, m_rexit.place.top, m_rexit.place.right + 1, m_rexit.place.bottom), m_pCloseButtonClickBrush);
			m_pRenderTarget->DrawLine(D2D1::Point2F(m_rexit.place.left + 17.5f, m_rexit.place.top + 10.0f), D2D1::Point2F(m_rexit.place.right - 17.5f, m_rexit.place.bottom - 10.0f), m_pLightWhiteBrush, 0.7f);
			m_pRenderTarget->DrawLine(D2D1::Point2F(m_rexit.place.left + 17.5f, m_rexit.place.bottom - 10.0f), D2D1::Point2F(m_rexit.place.right - 17.5f, m_rexit.place.top + 10.0f), m_pLightWhiteBrush, 0.7f);
		}
		else{
			m_pRenderTarget->DrawLine(D2D1::Point2F(m_rexit.place.left + 17.5f, m_rexit.place.top + 10.0f), D2D1::Point2F(m_rexit.place.right - 17.5f, m_rexit.place.bottom - 10.0f), m_pControlTextBrush, 0.7f);
			m_pRenderTarget->DrawLine(D2D1::Point2F(m_rexit.place.left + 17.5f, m_rexit.place.bottom - 10.0f), D2D1::Point2F(m_rexit.place.right - 17.5f, m_rexit.place.top + 10.0f), m_pControlTextBrush, 0.7f);
		}
		//Min
		if (pt.x >= m_rmin.place.left&&pt.x < m_rmin.place.right&&pt.y >= m_rmin.place.top&&pt.y <= m_rmin.place.bottom)
		{
			m_pRenderTarget->FillRectangle(D2D1::RectF(m_rmin.place.left, m_rmin.place.top, m_rmin.place.right, m_rmin.place.bottom), m_pMinButtonActiveBrush);
			m_pRenderTarget->DrawLine(D2D1::Point2F(m_rmin.place.left + 17, m_rmin.place.top + 15), D2D1::Point2F(m_rmin.place.right - 17, m_rmin.place.top + 15), m_pControlTextBrush, 1.0f);
		}
		else{
			m_pRenderTarget->DrawLine(D2D1::Point2F(m_rmin.place.left + 17, m_rmin.place.top + 15), D2D1::Point2F(m_rmin.place.right - 17, m_rmin.place.top + 15), m_pControlTextBrush, 1.0f);
		}
		//find
		if (pt.x >= m_mbFind.place.left&&pt.x <= m_mbFind.place.right&&pt.y >= m_mbFind.place.top&&pt.y <= m_mbFind.place.bottom)
		{
			m_pRenderTarget->FillRectangle(D2D1::RectF(m_mbFind.place.left, m_mbFind.place.top, m_mbFind.place.right, m_mbFind.place.bottom), m_pMetroButtonLsBrush);
		}
		else{
			m_pRenderTarget->FillRectangle(D2D1::RectF(m_mbFind.place.left, m_mbFind.place.top, m_mbFind.place.right, m_mbFind.place.bottom), m_pMetroButtonNsBrush);
		}
		m_pRenderTarget->DrawTextW(m_mbFind.caption.c_str(), m_mbFind.caption.length(), m_pITextFormatContent, D2D1::RectF(m_mbFind.place.left, m_mbFind.place.top+3, m_mbFind.place.right, m_mbFind.place.bottom), m_pControlTextBrush, D2D1_DRAW_TEXT_OPTIONS_NONE, DWRITE_MEASURING_MODE_NATURAL);
		//FixBoot
		if (pt.x >= m_FixBoot.place.left&&pt.x <= m_FixBoot.place.right&&pt.y >= m_FixBoot.place.top&&pt.y <= m_FixBoot.place.bottom)
		{
			m_pRenderTarget->FillRectangle(D2D1::RectF(m_FixBoot.place.left, m_FixBoot.place.top, m_FixBoot.place.right, m_FixBoot.place.bottom), m_pMetroButtonLsBrush);
		}
		else{
			m_pRenderTarget->FillRectangle(D2D1::RectF(m_FixBoot.place.left, m_FixBoot.place.top, m_FixBoot.place.right, m_FixBoot.place.bottom), m_pMetroButtonNsBrush);
		}
		m_pRenderTarget->DrawTextW(m_FixBoot.caption.c_str(), m_FixBoot.caption.length(), m_pITextFormatContent, D2D1::RectF(m_FixBoot.place.left, m_FixBoot.place.top+4, m_FixBoot.place.right, m_FixBoot.place.bottom), m_pControlTextBrush, D2D1_DRAW_TEXT_OPTIONS_NONE, DWRITE_MEASURING_MODE_NATURAL);
		//Operate
		if (pt.x >= m_Operate.place.left&&pt.x <= m_Operate.place.right&&pt.y >= m_Operate.place.top&&pt.y <= m_Operate.place.bottom)
		{
			m_pRenderTarget->FillRectangle(D2D1::RectF(m_Operate.place.left, m_Operate.place.top, m_Operate.place.right, m_Operate.place.bottom), m_pMetroButtonLsBrush);
		}
		else{
			m_pRenderTarget->FillRectangle(D2D1::RectF(m_Operate.place.left, m_Operate.place.top, m_Operate.place.right, m_Operate.place.bottom), m_pMetroButtonNsBrush);
		}
		m_pRenderTarget->DrawTextW(m_Operate.caption.c_str(), m_Operate.caption.length(), m_pITextFormatContent, D2D1::RectF(m_Operate.place.left, m_Operate.place.top+4, m_Operate.place.right, m_Operate.place.bottom), m_pControlTextBrush, D2D1_DRAW_TEXT_OPTIONS_NONE, DWRITE_MEASURING_MODE_NATURAL);
		
		////
#pragma warning(default:4244)
#pragma warning(default:4267)	
		m_pRenderTarget->DrawRectangle(D2D1::RectF(0.f, 0.f, rtSize.width, rtSize.height), m_EdgeViewBrush, 1.0f, NULL);

		hr = m_pRenderTarget->EndDraw();
	}

	if (hr == D2DERR_RECREATE_TARGET)
	{
		hr = S_OK;
		DiscardDeviceResources();
	}

	return hr;
}
HRESULT DemoApp::OnRender()
{
    HRESULT hr;

    hr = CreateDeviceResources();
    if (SUCCEEDED(hr) && !(m_pRT->CheckWindowState() & D2D1_WINDOW_STATE_OCCLUDED))
    {
        D2D1_POINT_2F point;
        D2D1_POINT_2F tangent;
        D2D1_MATRIX_3X2_F triangleMatrix;
        D2D1_SIZE_F rtSize = m_pRT->GetSize();
        float minWidthHeightScale = min(rtSize.width, rtSize.height) / 512;

        D2D1::Matrix3x2F scale = D2D1::Matrix3x2F::Scale(
            minWidthHeightScale,
            minWidthHeightScale
            );

        D2D1::Matrix3x2F translation = D2D1::Matrix3x2F::Translation(
            rtSize.width / 2,
            rtSize.height / 2
            );

        // Prepare to draw.
        m_pRT->BeginDraw();

        // Reset to identity transform
        m_pRT->SetTransform(D2D1::Matrix3x2F::Identity());

        //clear the render target contents
        m_pRT->Clear(D2D1::ColorF(D2D1::ColorF::Black));

        //center the path
        m_pRT->SetTransform(scale * translation);

        //draw the path in red
        m_pRT->DrawGeometry(m_pPathGeometry, m_pRedBrush);

        static float float_time = 0.0f;

        float length = m_Animation.GetValue(float_time);

        // Ask the geometry to give us the point that corresponds with the
        // length at the current time.
        hr = m_pPathGeometry->ComputePointAtLength(length, NULL, &point, &tangent);

        Assert(SUCCEEDED(hr));

        // Reorient the triangle so that it follows the
        // direction of the path.
        triangleMatrix = D2D1::Matrix3x2F(
            tangent.x, tangent.y,
            -tangent.y, tangent.x,
            point.x, point.y
            );

        m_pRT->SetTransform(triangleMatrix * scale * translation);

        // Draw the yellow triangle.
        m_pRT->FillGeometry(m_pObjectGeometry, m_pYellowBrush);

        // Commit the drawing operations.
        hr = m_pRT->EndDraw();

        if (hr == D2DERR_RECREATE_TARGET)
        {
            hr = S_OK;
            DiscardDeviceResources();
        }

        // When we reach the end of the animation, loop back to the beginning.
        if (float_time >= m_Animation.GetDuration())
        {
            float_time = 0.0f;
        }
        else
        {
            float_time += static_cast<float>(m_DwmTimingInfo.rateCompose.uiDenominator) /
                          static_cast<float>(m_DwmTimingInfo.rateCompose.uiNumerator);
        }
    }

    InvalidateRect(m_hwnd, NULL, FALSE);

    return hr;
}
Exemplo n.º 21
0
// This method discards device-specific
// resources if the Direct3D device dissapears during execution and
// recreates the resources the next time it's invoked.
HRESULT DemoApp::OnRender()
{
    HRESULT hr = S_OK;

    hr = CreateDeviceResources();

    if (SUCCEEDED(hr))
    {
        m_pRenderTarget->BeginDraw();

        m_pRenderTarget->SetTransform(D2D1::Matrix3x2F::Identity());

        m_pRenderTarget->Clear(D2D1::ColorF(D2D1::ColorF::White));

        D2D1_SIZE_F rtSize = m_pRenderTarget->GetSize();

        // Draw a grid background.
        int width = static_cast<int>(rtSize.width);
        int height = static_cast<int>(rtSize.height);

        for (int x = 0; x < width; x += 10)
        {
            m_pRenderTarget->DrawLine(
                D2D1::Point2F(static_cast<FLOAT>(x), 0.0f),
                D2D1::Point2F(static_cast<FLOAT>(x), rtSize.height),
                m_pLightSlateGrayBrush,
                0.5f
                );
        }

        for (int y = 0; y < height; y += 10)
        {
            m_pRenderTarget->DrawLine(
                D2D1::Point2F(0.0f, static_cast<FLOAT>(y)),
                D2D1::Point2F(rtSize.width, static_cast<FLOAT>(y)),
                m_pLightSlateGrayBrush,
                0.5f
                );
        }

        // Draw two rectangles.
        D2D1_RECT_F rectangle1 = D2D1::RectF(
            rtSize.width/2 - 50.0f,
            rtSize.height/2 - 50.0f,
            rtSize.width/2 + 50.0f,
            rtSize.height/2 + 50.0f
            );

        D2D1_RECT_F rectangle2 = D2D1::RectF(
            rtSize.width/2 - 100.0f,
            rtSize.height/2 - 100.0f,
            rtSize.width/2 + 100.0f,
            rtSize.height/2 + 100.0f
            );


        // Draw a filled rectangle.
        m_pRenderTarget->FillRectangle(&rectangle1, m_pLightSlateGrayBrush);

        // Draw the outline of a rectangle.
        m_pRenderTarget->DrawRectangle(&rectangle2, m_pCornflowerBlueBrush);

        hr = m_pRenderTarget->EndDraw();
    }

    if (hr == D2DERR_RECREATE_TARGET)
    {
        hr = S_OK;
        DiscardDeviceResources();
    }

    return hr;
}
Exemplo n.º 22
0
 // Initialize all DirectX resources
 Renderer::Renderer(_In_ Rect windowBounds, _In_ float dpi)
     : windowBounds(windowBounds), dpi(dpi)
 {
     CreateDeviceIndependentResources();
     CreateDeviceResources();
 }
Exemplo n.º 23
0
 // Recreate all device resources and set them back to the current state.
 void Renderer::HandleDeviceLost()
 {
     CreateDeviceResources();
 }
/******************************************************************
*                                                                 *
*  DemoApp::OnRender                                              *
*                                                                 *
*  This method draws Direct2D content to a GDI HDC.               *
*                                                                 *
*  This method will automatically discard device-specific         *
*  resources if the D3D device disappears during function         *
*  invocation, and will recreate the resources the next time it's *
*  invoked.                                                       *
*                                                                 *
******************************************************************/
HRESULT DemoApp::OnRender(const PAINTSTRUCT &ps)
{

    HRESULT hr;
    RECT rc;

    // Get the dimensions of the client drawing area.
    GetClientRect(m_hwnd, &rc);

    //
    // Draw the pie chart with Direct2D.
    //

    // Create the DC render target.
    hr = CreateDeviceResources();

    if (SUCCEEDED(hr))
    {
        // Bind the DC to the DC render target.
        hr = m_pDCRT->BindDC(ps.hdc, &rc);

        m_pDCRT->BeginDraw();

        m_pDCRT->SetTransform(D2D1::Matrix3x2F::Identity());

        m_pDCRT->Clear(D2D1::ColorF(D2D1::ColorF::White));

        m_pDCRT->DrawEllipse(
            D2D1::Ellipse(
                D2D1::Point2F(150.0f, 150.0f),
                100.0f,
                100.0f),
            m_pBlackBrush,
            3.0
            );

        m_pDCRT->DrawLine(
            D2D1::Point2F(150.0f, 150.0f),
            D2D1::Point2F(
                (150.0f + 100.0f * 0.15425f),
                (150.0f - 100.0f * 0.988f)),
            m_pBlackBrush,
            3.0
            );

        m_pDCRT->DrawLine(
            D2D1::Point2F(150.0f, 150.0f),
            D2D1::Point2F(
                (150.0f + 100.0f * 0.525f),
                (150.0f + 100.0f * 0.8509f)),
            m_pBlackBrush,
            3.0
            );

        m_pDCRT->DrawLine(
            D2D1::Point2F(150.0f, 150.0f),
            D2D1::Point2F(
                (150.0f - 100.0f * 0.988f),
                (150.0f - 100.0f * 0.15425f)),
            m_pBlackBrush,
            3.0
            );

        hr = m_pDCRT->EndDraw();
        if (SUCCEEDED(hr))
        {
            //
            // Draw the pie chart with GDI.
            //

            // Save the original object.
            HGDIOBJ original = NULL;
            original = SelectObject(
                ps.hdc,
                GetStockObject(DC_PEN)
                );

            HPEN blackPen = CreatePen(PS_SOLID, 3, 0);
            SelectObject(ps.hdc, blackPen);

            Ellipse(ps.hdc, 300, 50, 500, 250);

            POINT pntArray1[2];
            pntArray1[0].x = 400;
            pntArray1[0].y = 150;
            pntArray1[1].x = static_cast<LONG>(400 + 100 * 0.15425);
            pntArray1[1].y = static_cast<LONG>(150 - 100 * 0.9885);

            POINT pntArray2[2];
            pntArray2[0].x = 400;
            pntArray2[0].y = 150;
            pntArray2[1].x = static_cast<LONG>(400 + 100 * 0.525);
            pntArray2[1].y = static_cast<LONG>(150 + 100 * 0.8509);


            POINT pntArray3[2];
            pntArray3[0].x = 400;
            pntArray3[0].y = 150;
            pntArray3[1].x = static_cast<LONG>(400 - 100 * 0.988);
            pntArray3[1].y = static_cast<LONG>(150 - 100 * 0.15425);

            Polyline(ps.hdc, pntArray1, 2);
            Polyline(ps.hdc, pntArray2, 2);
            Polyline(ps.hdc, pntArray3, 2);

            DeleteObject(blackPen);

            // Restore the original object.
            SelectObject(ps.hdc, original);
        }
    }

    if (hr == D2DERR_RECREATE_TARGET)
    {
        hr = S_OK;
        DiscardDeviceResources();
    }

    return hr;
}
// Called whenever the application needs to display the client window
HRESULT DemoApp::OnRender()
{
	HRESULT hr = CreateDeviceResources();
	if (SUCCEEDED(hr) && !(m_pRenderTarget->CheckWindowState()&D2D1_WINDOW_STATE_OCCLUDED))
	{
		static const WCHAR sc_helloWorld[] = L"Hello, World!";

		D2D1_SIZE_F renderTargetSize = m_pRenderTarget->GetSize();

		m_pRenderTarget->BeginDraw();
		m_pRenderTarget->SetTransform(D2D1::Matrix3x2F::Identity());
		m_pRenderTarget->Clear(D2D1::ColorF(D2D1::ColorF::White));

		// Paint a grid background
		m_pRenderTarget->FillRectangle(
			D2D1::RectF(0.0f, 0.0f, renderTargetSize.width, renderTargetSize.height),
			m_pGridPatternBitmapBrush);

		D2D1_SIZE_F size = m_pBitmap->GetSize();

		// Draw a bitmap in the upper-left corner of the window
		m_pRenderTarget->DrawBitmap(
			m_pBitmap,
			D2D1::RectF(0.0f, 0.0f, size.width, size.height));

		// Draw a bitmap at the lower-right corner of the window
		m_pRenderTarget->DrawBitmap(
			m_pAnotherBitmap,
			D2D1::RectF(
				renderTargetSize.width - size.width,
				renderTargetSize.height - size.height,
				renderTargetSize.width,
				renderTargetSize.height));

		// Set the world transform to a 45 degree rotation at the center of the render target
		m_pRenderTarget->SetTransform(
			D2D1::Matrix3x2F::Rotation(
				45,
				D2D1::Point2F(
					renderTargetSize.width / 2,
					renderTargetSize.height / 2)));
		m_pRenderTarget->DrawTextW(
			sc_helloWorld,
			ARRAYSIZE(sc_helloWorld) - 1,
			m_pTextFormat,
			D2D1::RectF(0, 0, renderTargetSize.width, renderTargetSize.height),
			m_pBlackBrush);

		// Reset back to the identity transform
		m_pRenderTarget->SetTransform(
			D2D1::Matrix3x2F::Translation(0, renderTargetSize.height - 200));

		// Fill the hour glass geometry with a gradient
		m_pRenderTarget->FillGeometry(m_pPathGeometry, m_pLinearGradientBrush);

		m_pRenderTarget->SetTransform(
			D2D1::Matrix3x2F::Translation(renderTargetSize.width - 200, 0));

		// Fill the hour glass geometry with a gradient
		m_pRenderTarget->FillGeometry(m_pPathGeometry, m_pLinearGradientBrush);

		hr = m_pRenderTarget->EndDraw();
		if (hr == D2DERR_RECREATE_TARGET)
		{
			hr = S_OK;
			DiscardDeviceResources();
		}
	}

	return hr;
}
Exemplo n.º 26
0
HRESULT FirstTry::OnRender()
{
	HRESULT hr = S_OK;
	hr = CreateDeviceResources();

	if (SUCCEEDED(hr))
	{
		m_pRenderTarget->BeginDraw();
		m_pRenderTarget->SetTransform(D2D1::Matrix3x2F::Identity());
		m_pRenderTarget->Clear(D2D1::ColorF(D2D1::ColorF::White));

		// Retrieve the size of the drawing area.
		D2D1_SIZE_F rtSize = m_pRenderTarget->GetSize();

		//// Draw a grid background by using a for loop and the render target's DrawLine method.
		//int width = static_cast<int>(rtSize.width);
		//int height = static_cast<int>(rtSize.height);

		//for (int x = 0; x < width; x+=10)
		//{
		//	m_pRenderTarget->DrawLine(
		//		D2D1::Point2F(static_cast<FLOAT>(x), 0.f),
		//		D2D1::Point2F(static_cast<FLOAT>(x), rtSize.height),
		//		m_pLightSlateGrayBrush,
		//		0.5f);
		//}
		//for (int y = 0; y < height; y+=10)
		//{
		//	m_pRenderTarget->DrawLine(
		//		D2D1::Point2F(0.f, static_cast<float>(y)),
		//		D2D1::Point2F(rtSize.width, static_cast<float>(y)),
		//		m_pLightSlateGrayBrush,
		//		0.5f);
		//}

		// Get the animation variable value
		DOUBLE angleNow;
		hr = m_pAnimationVarAngle->GetValue(&angleNow);
		//currentAngle += angleNow*(secondsCurrent - secondsPrev);
		//currentAngle += 720 - sqrt(720 * 720 - angleNow*angleNow);
		
		m_pRenderTarget->SetTransform(D2D1::Matrix3x2F::Rotation(angleNow, D2D1::Point2F(rtSize.width / 2, rtSize.height / 2)));

		// Draw a bitmap in the upper-left corner.
		D2D1_SIZE_F size = m_pBitmap->GetSize();
		m_pRenderTarget->DrawBitmap(m_pBitmap, D2D1::RectF(0.f, 0.f, size.width, size.height));

		// Draw a bitmap 10 pixels off right.
		size = m_pBitmap1->GetSize();
		m_pRenderTarget->DrawBitmap(m_pBitmap1, D2D1::RectF(10.f, 10.f, size.width + 10.f, size.height + 10.f));

		//// Draw two rectangles
		//D2D1_RECT_F rectangle1 = D2D1::RectF(
		//	rtSize.width / 2 - 50.f,
		//	rtSize.height / 2 - 50.f,
		//	rtSize.width / 2 + 50.f,
		//	rtSize.height / 2 + 50.f);
		//D2D1_RECT_F rectangle2 = D2D1::RectF(
		//	rtSize.width / 2 - 100.f,
		//	rtSize.height / 2 - 100.f,
		//	rtSize.width / 2 + 100.f,
		//	rtSize.height / 2 + 100.f);

		//m_pRenderTarget->FillRectangle(&rectangle1, m_pLightSlateGrayBrush);
		//m_pRenderTarget->DrawRectangle(&rectangle2, m_pCornflowerBlueBrush);

		hr = m_pRenderTarget->EndDraw();
	}

	if (hr == D2DERR_RECREATE_TARGET)
	{
		hr = S_OK;
		DiscardDeviceResources();
	}

	return hr;
}
Exemplo n.º 27
0
void Sandbox::FluidSimulator::Initialize( _No_args_ )
{
	CreateDeviceIndependentResources( );
	CreateDeviceResources( );
	CreateWindowSizeDependentResources( );
}
Exemplo n.º 28
0
HRESULT MetroWindow::OnRender()
{
    auto hr = CreateDeviceResources();
    hr = DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED,
                             __uuidof(IDWriteFactory),
                             reinterpret_cast<IUnknown**>(&m_pWriteFactory));
    if (hr != S_OK) return hr;
    hr = m_pWriteFactory->CreateTextFormat(
             L"Segoe UI",
             NULL,
             DWRITE_FONT_WEIGHT_NORMAL,
             DWRITE_FONT_STYLE_NORMAL,
             DWRITE_FONT_STRETCH_NORMAL,
             12.0f * 96.0f / 72.0f,
             L"zh-CN",
             &m_pWriteTextFormat);
#pragma warning(disable:4244)
#pragma warning(disable:4267)
    if (SUCCEEDED(hr)) {
        m_pHwndRenderTarget->BeginDraw();
        m_pHwndRenderTarget->SetTransform(D2D1::Matrix3x2F::Identity());
        m_pHwndRenderTarget->Clear(D2D1::ColorF(D2D1::ColorF::White, 1.0f));
        //m_pWriteTextFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER);
        for (auto &label : label_) {
            if (label.text.empty())
                continue;
            m_pHwndRenderTarget->DrawTextW(label.text.c_str(),
                                           label.text.size(),
                                           m_pWriteTextFormat,
                                           D2D1::RectF(label.layout.left, label.layout.top, label.layout.right, label.layout.bottom),
                                           m_pSolidColorBrush,
                                           D2D1_DRAW_TEXT_OPTIONS_NONE, DWRITE_MEASURING_MODE_NATURAL);
        }
        for (auto &it : item_) {
            if (it.name.empty() || it.value.empty())
                continue;
            m_pHwndRenderTarget->DrawTextW(it.name.c_str(),
                                           it.name.size(),
                                           m_pWriteTextFormat,
                                           D2D1::RectF(it.layout.left, it.layout.top, it.layout.left + 135.0f, it.layout.bottom),
                                           m_pSolidColorBrush,
                                           D2D1_DRAW_TEXT_OPTIONS_NONE, DWRITE_MEASURING_MODE_NATURAL);
            m_pHwndRenderTarget->DrawTextW(it.value.c_str(),
                                           it.value.size(),
                                           m_pWriteTextFormat,
                                           D2D1::RectF(it.layout.left + 140.0f, it.layout.top, it.layout.right, it.layout.bottom),
                                           m_pSolidColorBrush,
                                           D2D1_DRAW_TEXT_OPTIONS_NONE, DWRITE_MEASURING_MODE_NATURAL);
        }
        m_pWriteTextFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER);
        for (auto &b : button_) {
            m_pHwndRenderTarget->DrawRectangle(
                D2D1::RectF(b.layout.left, b.layout.top, b.layout.right, b.layout.bottom),
                m_pBakcgroundEdgeBrush,
                0.3f, 0);
            switch (b.status) {
            case MetroButton::kKeyDown:
                m_pHwndRenderTarget->FillRectangle(
                    D2D1::RectF(b.layout.left, b.layout.top, b.layout.right, b.layout.bottom),
                    m_PushButtonClickBrush);
                break;
            case MetroButton::kKeyActive:
                m_pHwndRenderTarget->FillRectangle(
                    D2D1::RectF(b.layout.left, b.layout.top, b.layout.right, b.layout.bottom),
                    m_PushButtonActiveBrush);
                break;
            case MetroButton::kKeyLeave:
            default:
                m_pHwndRenderTarget->FillRectangle(
                    D2D1::RectF(b.layout.left, b.layout.top, b.layout.right, b.layout.bottom),
                    m_PushButtonNActiveBrush);
                break;
            }
            if (!b.caption.empty()) {
                m_pHwndRenderTarget->DrawTextW(b.caption.c_str(),
                                               b.caption.size(),
                                               m_pWriteTextFormat,
                                               D2D1::RectF(b.layout.left, b.layout.top, b.layout.right, b.layout.bottom),
                                               m_pSolidColorBrush,
                                               D2D1_DRAW_TEXT_OPTIONS_NONE, DWRITE_MEASURING_MODE_NATURAL);
            }
        }
        hr = m_pHwndRenderTarget->EndDraw();
    }
#pragma warning(default:4244)
#pragma warning(default:4267)
    if (hr == D2DERR_RECREATE_TARGET) {
        hr = S_OK;
        DiscardDeviceResources();
        ::InvalidateRect(m_hWnd, nullptr, FALSE);
    }
    return hr;
}
Exemplo n.º 29
0
HRESULT DemoApp::OnRender()
{
    HRESULT hr;

    hr = CreateDeviceResources();
    if (SUCCEEDED(hr))
    {


        D2D1_POINT_2F point;
        D2D1_POINT_2F tangent;

		D2D1_MATRIX_3X2_F wheelMatrix;
		D2D1_MATRIX_3X2_F flyMatrix;
	
 

        D2D1_SIZE_F rtSize = m_pRT->GetSize();	//렌더타겟의 사이즈
        float minWidthHeightScale = min(rtSize.width, rtSize.height) / 600;
		
		char tmp[20];	//임시 텍스트를 담을 배열
		
		static float float_time = 0.0f;
		static float fly_time   = 0.0f;

        float length  = m_Animation.GetValue(float_time);
		float fLength = m_linearAnimation.GetValue(fly_time);
		
	
		::ZeroMemory(tmp, 20);	//경과시간을 문자열로 저장하기
		::sprintf(tmp, "경과시간 : %.1f", accumulatedTime);
		int sz1 = ::MultiByteToWideChar(CP_ACP,0,tmp,-1,NULL,0);
		LPWSTR buf1 = new WCHAR[sz1];
		::MultiByteToWideChar(CP_ACP,0,tmp,-1,buf1,sz1);
		
		
		
		::ZeroMemory(tmp, 20);	//이동한 누적거리를 문자열로 저장하기
		::sprintf(tmp, "음향볼륨 : %d", volumeShow);
		int sz2 = ::MultiByteToWideChar(CP_ACP,0,tmp,-1,NULL,0);
		LPWSTR buf2 = new WCHAR[sz2];
		::MultiByteToWideChar(CP_ACP,0,tmp,-1,buf2,sz2);
		

		::ZeroMemory(tmp, 20);	//양품달걀을 문자열로 저장하기
		::sprintf(tmp, "양품달걀 : %d", score);
		int sz3= ::MultiByteToWideChar(CP_ACP,0,tmp,-1,NULL,0);
		LPWSTR buf3 = new WCHAR[sz3];
		::MultiByteToWideChar(CP_ACP,0,tmp,-1,buf3,sz3);

		//바닥을 그릴 사각형
		D2D1_RECT_F Rect = D2D1::RectF(0,rtSize.height/1.4,rtSize.width,rtSize.height);

		//윈도우 창 사이즈에 따라 크기 변환
        D2D1::Matrix3x2F scale = D2D1::Matrix3x2F::Scale(
            minWidthHeightScale,
            minWidthHeightScale
            );
		//중앙으로 이동시킬 변환 매트릭스
        D2D1::Matrix3x2F translation = D2D1::Matrix3x2F::Translation(
            rtSize.width / 2,
            rtSize.height / 2
            );

        m_pRT->BeginDraw();

        // Reset to identity transform
        m_pRT->SetTransform(D2D1::Matrix3x2F::Identity());

        //배경 하늘색으로 클리어
		m_pRT->Clear(D2D1::ColorF(D2D1::ColorF::White));
	
		
        // 창그리기
		m_pRT->DrawBitmap(m_pBitmap, D2D1::RectF(0.0f, 0.0f, rtSize.width, rtSize.height/1.4));

	  

		//달걀 1
		hr = m_pD2DFactory->CreateEllipseGeometry(D2D1::Ellipse(D2D1::Point2F(rtSize.width,50),60,40),&m_pEgg1);
		m_pRT->SetTransform(D2D1::Matrix3x2F::Translation(cloudX,300 - jumpValue1 ));
		m_pBrush->SetColor(D2D1::ColorF(D2D1::ColorF::Beige,1));
		m_pRT->FillGeometry(m_pEgg1, m_pBrush );
		m_pRT->DrawGeometry(m_pEgg1, m_pBlackBrush, 2);

		//달걀 2
		hr = m_pD2DFactory->CreateEllipseGeometry(D2D1::Ellipse(D2D1::Point2F(rtSize.width,50),60,40),&m_pEgg2);
		m_pRT->SetTransform(D2D1::Matrix3x2F::Translation(cloudX2,300 - jumpValue2 ));
		m_pBrush->SetColor(D2D1::ColorF(D2D1::ColorF::DeepSkyBlue,1));
		m_pRT->FillGeometry(m_pEgg2, m_pBrush );
		m_pRT->DrawGeometry(m_pEgg2, m_pBlackBrush, 2);


		//달걀 3
		hr = m_pD2DFactory->CreateEllipseGeometry(D2D1::Ellipse(D2D1::Point2F(rtSize.width,50),60,40),&m_pEgg3);
		m_pRT->SetTransform(D2D1::Matrix3x2F::Translation(cloudX3,300 - jumpValue3 ));
		m_pBrush->SetColor(D2D1::ColorF(D2D1::ColorF::Green,1));
		m_pRT->FillGeometry(m_pEgg3, m_pBrush );
		m_pRT->DrawGeometry(m_pEgg3, m_pBlackBrush, 2);


		//달걀 4
		hr = m_pD2DFactory->CreateEllipseGeometry(D2D1::Ellipse(D2D1::Point2F(rtSize.width,50),60,40),&m_pEgg4);
		m_pRT->SetTransform(D2D1::Matrix3x2F::Translation(cloudX4,300 - jumpValue4 ));
		m_pBrush->SetColor(D2D1::ColorF(D2D1::ColorF::Yellow,1));
		m_pRT->FillGeometry(m_pEgg4, m_pBrush );
		m_pRT->DrawGeometry(m_pEgg4, m_pBlackBrush, 2);


		//달걀 5
		hr = m_pD2DFactory->CreateEllipseGeometry(D2D1::Ellipse(D2D1::Point2F(rtSize.width,50),60,40),&m_pEgg5);
		m_pRT->SetTransform(D2D1::Matrix3x2F::Translation(cloudX5,300 - jumpValue5 ));
		m_pBrush->SetColor(D2D1::ColorF(D2D1::ColorF::Red,1));
		m_pRT->FillGeometry(m_pEgg5, m_pBrush );
		m_pRT->DrawGeometry(m_pEgg5, m_pBlackBrush, 2);

		m_pRT->SetTransform(D2D1::Matrix3x2F::Identity());

	
		//////////////////////////////////////////////////////////////////////////////////
		// 달걀 뺏어가는 블랙홀


		
		
		if( score != 0 && (score % 20) == 0 )
		{
			bossTrigger = true;

			if( bossSound == true )
				soundManager->play(0,FALSE);

			tempX = 80 + rand() % 1000;
			tempY = 80 + rand() % 200;
		}

		
		if( bossTrigger == true )
		{
			
			blackHoleX = tempX;
			blackHoleY = tempY;
		
			hr = m_pD2DFactory->CreateEllipseGeometry(D2D1::Ellipse(D2D1::Point2F(80,80),80,80),&m_blackHole);
			
			m_pRT->SetTransform(D2D1::Matrix3x2F::Translation(blackHoleX - 80 , blackHoleY - 80) );
		
			m_pRT->FillGeometry(m_blackHole, m_pBlackHoleBrush);
			m_pRT->DrawGeometry(m_blackHole, m_pBlackBrush,1);

			m_pRT->SetTransform(D2D1::Matrix3x2F::Identity());

			int x = rtSize.width/2 + fanXpos;
			int y = 200 + fanYpos;

		
			if( blackHoleX - 60 < x && x < blackHoleX + 60 && blackHoleY - 60 < y && y < blackHoleY + 60 )
			{
				bossTrigger == false;
				
				if( bossSound == true )
					soundManager->play(1,FALSE);
			}
			
			else 
			{ 
				static int count;

				count++;

				if( score > 0 && ( count % 20 ) == 0 )
					score = score - 2;


			}

		}
		

		m_pRT->SetTransform(D2D1::Matrix3x2F::Identity());


		/////////////////////////////////////////////////////////////////////////

		// 내가 조종하는 달걀
		hr = m_pD2DFactory->CreateEllipseGeometry(D2D1::Ellipse(D2D1::Point2F(rtSize.width/2 + fanXpos ,200 + fanYpos),60,40),&m_pMovingEgg);
		
		m_pRT->SetTransform(D2D1::Matrix3x2F::Rotation( eggAngle, D2D1::Point2F( rtSize.width/2 + fanXpos, 200 + fanYpos ) ) ); 
		
		m_pBrush->SetColor(D2D1::ColorF(D2D1::ColorF::HotPink,1));
		m_pRT->FillGeometry(m_pMovingEgg, m_pBrush );
		m_pRT->DrawGeometry(m_pMovingEgg, m_pBlackBrush, 2);

		m_pRT->SetTransform(D2D1::Matrix3x2F::Identity());
		//////////////////////////////////////////////////////////////////////////////////////
		
	
	
		//칼날
		D2D1_MATRIX_3X2_F translateEllipse = D2D1::Matrix3x2F::Translation( 200 ,115 ); //200 115
		D2D1_MATRIX_3X2_F rotateEllipse = D2D1::Matrix3x2F::Rotation( angle, D2D1::Point2F( 300 , 100  ) );  //300 ,100

		m_pRT->SetTransform( rotateEllipse * translateEllipse );
	
        m_pRT->DrawGeometry(m_pPathGeometry, m_pBlackBrush, 5.f, 0);
		m_pRT->FillGeometry(m_pPathGeometry, m_pRedBrush, 0);

		//////////////////////////////////////////////////////
	


		if( start != 0 )
		{
			if( cloudX == 0 )
				score++;
	
			if( cloudX2 == 0 )
				score++;

			if( cloudX3 == 0 )
				score++;

			if( cloudX4 == 0 )
				score++;

			if( cloudX5 == 0 )
				score++;

			if( float_time == 0 )
			{
				if(score > 0)
					score -= 1;
			}
		}
			start = 1;

		//매트릭스 초기화
		m_pRT->SetTransform(D2D1::Matrix3x2F::Identity());

		


		//컨베이어벨트 그리기
		m_pRT->DrawRectangle(Rect, m_pBlackBrush,30);
		m_pBrush->SetColor(D2D1::ColorF(D2D1::ColorF::LightGray,1));
		m_pRT->FillRectangle(Rect,m_pBrush);

		m_pRT->SetTransform(D2D1::Matrix3x2F::Identity());

		
		//미니언
	    hr = m_pD2DFactory->CreateRectangleGeometry( D2D1::RectF(0,0,150,150), &m_pRectGeo );
		m_pRT->SetTransform(D2D1::Matrix3x2F::Translation(300 + characterMove,405) );
		m_pRT->FillGeometry(m_pRectGeo, m_pMinionBrush,m_pRadialGradientBrush);
		

		//엘사
	
		m_pRT->SetTransform(D2D1::Matrix3x2F::Translation(450 + characterMove,405) );
		m_pRT->FillGeometry(m_pRectGeo, m_pElsaBrush,m_pRadialGradientBrush);
		

		//주디 홉스

		m_pRT->SetTransform(D2D1::Matrix3x2F::Translation(600 + characterMove,405) );
		m_pRT->FillGeometry(m_pRectGeo, m_pJoodyBrush,m_pLinearGradientBrush);


		//베이 맥스
	
		m_pRT->SetTransform(D2D1::Matrix3x2F::Translation(750 + characterMove,405) );
		m_pRT->FillGeometry(m_pRectGeo, m_pMaxBrush,m_pLinearGradientBrush);
		
		m_pRT->SetTransform(D2D1::Matrix3x2F::Identity());
		
///////////////////////////////////////////////////////////////////////////////////////////////////

		//움직이는 바퀴벌레 그리기
		D2D1_MATRIX_3X2_F translateWheel = D2D1::Matrix3x2F::Translation(600,400);

		if(toggle){
		m_pBrush->SetColor(D2D1::ColorF(D2D1::ColorF::DarkOrange,1));
		m_pRT->SetTransform( translateWheel );
        m_pRT->DrawGeometry(m_wheelPath, m_pBrush);
		}

	
			hr = m_wheelPath->ComputePointAtLength(
				length, 
				NULL, 
				&point, 
				&tangent); 

			 Assert(SUCCEEDED(hr));

			wheelMatrix = D2D1::Matrix3x2F(
				tangent.x, tangent.y,
				-tangent.y, tangent.x,
				point.x, point.y
            );

				m_pRT->SetTransform(  wheelMatrix * translateWheel );

				//파리 날개 그리기
				m_pRT->DrawGeometry(m_pWingGeometry[WingX], m_pBlackBrush);
				m_pBrush->SetColor(D2D1::ColorF(D2D1::ColorF::LightBlue,1));
				m_pRT->FillGeometry(m_pWingGeometry[WingX], m_pBrush);
				//파리 몸통 그리기
				m_pRT->DrawGeometry(m_pFlyGeometry, m_pBlackBrush);
				m_pBrush->SetColor(D2D1::ColorF(D2D1::ColorF::DarkCyan,1));
				m_pRT->FillGeometry(m_pFlyGeometry, m_pBrush);
				//파리 눈알 그리기
				m_pBrush->SetColor(D2D1::ColorF(D2D1::ColorF::Black,1));
				m_pRT->FillGeometry(m_pRightEyeGeometry, m_pBrush);
				m_pRT->FillGeometry(m_pLeftEyeGeometry, m_pBrush);

				m_pRT->SetTransform(D2D1::Matrix3x2F::Identity());

///////////////////////////////////////////////////////////////////////////////////

				//움직이는 파리 그리기

		D2D1_MATRIX_3X2_F translateFly = D2D1::Matrix3x2F::Translation(600,200);

		if(toggle){
		m_pBrush->SetColor(D2D1::ColorF(D2D1::ColorF::DarkOrange,1));
		m_pRT->SetTransform( translateFly );
        m_pRT->DrawGeometry(m_flyPath, m_pBrush);
		}

	
			hr = m_flyPath->ComputePointAtLength(
				fLength, 
				NULL, 
				&point, 
				&tangent); 

			 Assert(SUCCEEDED(hr));

			flyMatrix = D2D1::Matrix3x2F(
				tangent.x, tangent.y,
				-tangent.y, tangent.x,
				point.x, point.y
            );

		m_pRT->SetTransform(  flyMatrix * translateFly );
				

		//파리 날개 그리기
		m_pRT->DrawGeometry(m_pWingGeometry[WingX], m_pBlackBrush);
		m_pBrush->SetColor(D2D1::ColorF(D2D1::ColorF::LightBlue,1));
		m_pRT->FillGeometry(m_pWingGeometry[WingX], m_pBrush);
		//파리 몸통 그리기
		m_pRT->DrawGeometry(m_pFlyGeometry, m_pBlackBrush);
		m_pBrush->SetColor(D2D1::ColorF(D2D1::ColorF::ForestGreen,1));
        m_pRT->FillGeometry(m_pFlyGeometry, m_pBrush);
		//파리 눈알 그리기
		m_pBrush->SetColor(D2D1::ColorF(D2D1::ColorF::Black,1));
		m_pRT->FillGeometry(m_pRightEyeGeometry, m_pBrush);
		m_pRT->FillGeometry(m_pLeftEyeGeometry, m_pBrush);


		m_pRT->SetTransform(D2D1::Matrix3x2F::Identity());


/////////////////////////////////////////////////////////////////////////////////////////////////



		//왼쪽 기계 체인 바깥쪽 타원
		hr = m_pD2DFactory->CreateEllipseGeometry(D2D1::Ellipse(D2D1::Point2F(rtSize.width,50),30,50),&m_pChain);
		D2D1_MATRIX_3X2_F translateChain3 = D2D1::Matrix3x2F::Translation(-1100, 400);
		D2D1_MATRIX_3X2_F rotateChain3 = D2D1::Matrix3x2F::Rotation( chainAngle1, D2D1::Point2F(rtSize.width-1100, 450 ) );
	
		m_pRT->SetTransform( translateChain3 * rotateChain3 );
		m_pRT->DrawGeometry(m_pChain, m_pBlackBrush, 2);

		//왼쪽 기계 체인 안쪽 타원
		hr = m_pD2DFactory->CreateEllipseGeometry(D2D1::Ellipse(D2D1::Point2F(rtSize.width, 50),10,20),&m_pChain2);
		D2D1_MATRIX_3X2_F translateChain4 = D2D1::Matrix3x2F::Translation(-1100, 400);
		D2D1_MATRIX_3X2_F rotateChain4 = D2D1::Matrix3x2F::Rotation( chainAngle2 , D2D1::Point2F(rtSize.width-1100, 450 ) );
	
		m_pRT->SetTransform( translateChain4 * rotateChain4 );
		m_pRT->DrawGeometry(m_pChain2, m_pBlackBrush, 2);



		//오른쪽 기계 체인 바깥쪽 타원
		hr = m_pD2DFactory->CreateEllipseGeometry(D2D1::Ellipse(D2D1::Point2F(rtSize.width,50),30,50),&m_pChain);
		D2D1_MATRIX_3X2_F translateChain = D2D1::Matrix3x2F::Translation(-100, 400);
		D2D1_MATRIX_3X2_F rotateChain = D2D1::Matrix3x2F::Rotation( chainAngle1  , D2D1::Point2F(rtSize.width-100, 450 ) );
	
		m_pRT->SetTransform( translateChain * rotateChain );
		m_pRT->DrawGeometry(m_pChain, m_pBlackBrush, 2);

		//오른쪽 기계 체인 안쪽 타원
		hr = m_pD2DFactory->CreateEllipseGeometry(D2D1::Ellipse(D2D1::Point2F(rtSize.width, 50),10,20),&m_pChain2);
		D2D1_MATRIX_3X2_F translateChain2 = D2D1::Matrix3x2F::Translation(-100, 400);
		D2D1_MATRIX_3X2_F rotateChain2 = D2D1::Matrix3x2F::Rotation( chainAngle2  , D2D1::Point2F(rtSize.width-100, 450 ) );
	
		m_pRT->SetTransform( translateChain2 * rotateChain2 );
		m_pRT->DrawGeometry(m_pChain2, m_pBlackBrush, 2);


		
			

		//텍스트를 그리기 위해 매트릭스 초기화
		m_pRT->SetTransform(D2D1::Matrix3x2F::Identity());

		if(score < 0)
		{
			score = 0;
		}

		//경과 시간 문자열 그리기
		m_pBrush->SetColor(D2D1::ColorF(D2D1::ColorF::White,1));;
		m_pRT->DrawText(buf1, sz1-1, m_pTextFormat,
									 D2D1::RectF(0, 0, rtSize.width, rtSize.height),
									 m_pBrush);


		//문자열 간격
		m_pRT->SetTransform(D2D1::Matrix3x2F::Translation(0,20));
		
		
		//볼륨 표시
		m_pRT->DrawText(buf2, sz2-1, m_pTextFormat,
									 D2D1::RectF(0, 0, rtSize.width, rtSize.height),
									  m_pBrush);
		
		
		
		//문자열 간격
		
		m_pRT->SetTransform(D2D1::Matrix3x2F::Translation(0,40));
		
		//양품달걀 문자열 그리기
		m_pRT->DrawText(buf3, sz3-1, m_pTextFormat,
									 D2D1::RectF(0, 0, rtSize.width, rtSize.height),
									  m_pBrush);
		
		


		hr = m_pRT->EndDraw();



		
			//임시 문자열 삭제
			delete[] buf1;
			delete[] buf2;
			delete[] buf3;



			if (hr == D2DERR_RECREATE_TARGET)
			{
				hr = S_OK;
				DiscardDeviceResources();
			}

			// 한바퀴를 돌면 시간 초기화
			if (float_time >= m_Animation.GetDuration())
			{
				float_time = 0.0f;
			}
			else
			{	//아니면 시간 증가
				float_time += static_cast<float>(m_DwmTimingInfo.rateCompose.uiDenominator) /
							  static_cast<float>(m_DwmTimingInfo.rateCompose.uiNumerator);
			}

			// 한바퀴를 돌면 시간 초기화
			if (fly_time >= m_linearAnimation.GetDuration())
			{
				fly_time = 0.0f;
			}
			else
			{	//아니면 시간 증가
				fly_time += static_cast<float>(m_DwmTimingInfo.rateCompose.uiDenominator) /
							  static_cast<float>(m_DwmTimingInfo.rateCompose.uiNumerator);
			}




		}
		//경과 시간 계산
			accumulatedTime += static_cast<float>(m_DwmTimingInfo.rateCompose.uiDenominator) /
								  static_cast<float>(m_DwmTimingInfo.rateCompose.uiNumerator);


         //컨베이어 벨트 위에 있는 달걀 
		cloudX  -=6.f;	  //달걀 움직임 속도
		cloudX2 -=10.f;
		cloudX3 -=12.f;
		cloudX4 -= 24.f;
		cloudX5 -= 8.f;

		t1 += tToggle1;
		t2 += tToggle2;
		t3 += tToggle3;
		t4 += tToggle4;
		t5 += tToggle5;

		if(cloudX == -1200 )
		{
			cloudX = 0;
			t1 = 0;
		}

		if(cloudX2 == -1200 )
		{
			cloudX2 = 0;
			t2 = 0;
		}

		if(cloudX3 == -1200 )
		{
			cloudX3 = 0;
			t3 = 0;
		}

		if(cloudX4 == -1200 )
		{
			cloudX4 = 0;
			t4 = 0;
		}

		if(cloudX5 == -1200 )
		{
			cloudX5 = 0;
			t5 = 0;
		}


		jumpValue1 = -5 * t1 + 0.5 * 9.8 * t1 * t1;
		jumpValue2 = -5 * t2 + 0.5 * 9.8 * t2 * t2;
		jumpValue3 = -5 * t3 + 0.5 * 9.8 * t3 * t3;
		jumpValue4 = -5 * t4 + 0.5 * 9.8 * t4 * t4;
		jumpValue5 = -5 * t5 + 0.5 * 9.8 * t5 * t5;
		
		if( jumpValue1 > 250 )
			tToggle1 *= -1;

		if( jumpValue2 > 100 )
			tToggle2 *= -1;

		if( jumpValue3 > 50 )
			tToggle3 *= -1;

		if( jumpValue4 > 25 )
			tToggle4 *= -1;

		if( jumpValue5 > 160 )
			tToggle5 *= -1;
		
		///////////////////////////////

		//컨베이어 벨트 돌아가는 장치 컨트롤
		angle += angleValue;

		if( angle == 360 )
		{
			angle = 0;
		}
	
		chainAngle1 -= 5;
		chainAngle2 -= 10;



		// 아래 디즈니 캐릭터 좌우 왔다갔다 컨트롤
		characterMove += characterMoveValue;
		if( characterMove == -100 )
		{
			characterMoveValue *= -1;

		}else if( characterMove == 100 )
		{
			characterMoveValue *= -1;
		}


		// 움직이는 달걀 컨트롤
		eggAngle += 20;

		if( eggAngle == 360 )
			eggAngle = 0;


		if( fanXpos < -530 || fanXpos > 530)
			fanXpos = 0;

		else if( fanYpos < -150 || fanYpos > 140)
			fanYpos = 0;
		

		//똥파리 날개 컨트롤
			WingX = (WingX+1)%4;	//날개 배열의 4개 중 하나 선택
			if(WingX== 12)			
				WingX=0;



		return hr;
}
HRESULT DemoApp::OnRender()
{
    HRESULT hr = S_OK;

    LARGE_INTEGER time;
    LARGE_INTEGER frequency;
    QueryPerformanceCounter(&time);
    QueryPerformanceFrequency(&frequency);

    float floatTime;

    hr = CreateDeviceResources();
    if (SUCCEEDED(hr))
    {
        if (!m_paused)
        {
            floatTime = static_cast<float>(time.QuadPart + m_timeDelta)/static_cast<float>(frequency.QuadPart);
        }
        else
        {
            floatTime = static_cast<float>(m_pausedTime + m_timeDelta)/static_cast<float>(frequency.QuadPart);
        }

        m_times.Add(time.QuadPart);

        if (m_currentZoomFactor < m_targetZoomFactor)
        {
            m_currentZoomFactor *= sc_zoomSubStep;

            if (m_currentZoomFactor > m_targetZoomFactor)
            {
                m_currentZoomFactor = m_targetZoomFactor;

                if (m_autoGeometryRegen)
                {
                    m_updateRealization = true;
                }
            }
        }
        else if (m_currentZoomFactor > m_targetZoomFactor)
        {
            m_currentZoomFactor /= sc_zoomSubStep;

            if (m_currentZoomFactor < m_targetZoomFactor)
            {
                m_currentZoomFactor = m_targetZoomFactor;

                if (m_autoGeometryRegen)
                {
                    m_updateRealization = true;
                }
            }
        }

        m_pRT->SetTransform(
            D2D1::Matrix3x2F::Scale(
                m_currentZoomFactor,
                m_currentZoomFactor,
                m_mousePos)
            );

        hr = CreateGeometries();

        if (SUCCEEDED(hr))
        {
            m_pRT->BeginDraw();

            hr = RenderMainContent(floatTime);
            if (SUCCEEDED(hr))
            {
                hr = RenderTextInfo();
                if (SUCCEEDED(hr))
                {
                    hr = m_pRT->EndDraw();
                    if (SUCCEEDED(hr))
                    {
                        if (hr == D2DERR_RECREATE_TARGET)
                        {
                            DiscardDeviceResources();
                        }
                    }
                }
            }
        }
    }

    return hr;
}