/// <summary>
/// Create gauge (with position cloud) used to display sound source angle.
/// </summary>
/// <returns>S_OK on success, otherwise failure code.</returns>
HRESULT AudioPanel::CreateSourceGauge()
{
    HRESULT hr = m_pD2DFactory->CreatePathGeometry(&m_pSourceGauge);

    // Create gauge background shape
    if (SUCCEEDED(hr))
    {
        ID2D1GeometrySink *pGeometrySink = NULL;
        hr = m_pSourceGauge->Open(&pGeometrySink);

        if (SUCCEEDED(hr))
        {
            pGeometrySink->BeginFigure(D2D1::Point2F(0.1270f,0.3021f), D2D1_FIGURE_BEGIN_FILLED);
            pGeometrySink->AddLine(D2D1::Point2F(0.1503f,0.2832f));
            pGeometrySink->AddArc(D2D1::ArcSegment(D2D1::Point2F(0.8497f,0.2832f), D2D1::SizeF(0.45f,0.45f), 102, D2D1_SWEEP_DIRECTION_COUNTER_CLOCKWISE, D2D1_ARC_SIZE_SMALL));
            pGeometrySink->AddLine(D2D1::Point2F(0.8730f,0.3021f));
            pGeometrySink->AddArc(D2D1::ArcSegment(D2D1::Point2F(0.1270f,0.3021f), D2D1::SizeF(0.48f,0.48f), 102, D2D1_SWEEP_DIRECTION_CLOCKWISE, D2D1_ARC_SIZE_SMALL));
            pGeometrySink->EndFigure(D2D1_FIGURE_END_CLOSED);
            hr = pGeometrySink->Close();

            // Create gauge background brush
            if (SUCCEEDED(hr))
            {
                hr = CreateSourceGaugeFill(0.1f);
            }
        }

        SafeRelease(pGeometrySink);
    }

    return hr;
}
/// <summary>
/// Create gauge (with needle) used to display beam angle.
/// </summary>
/// <returns>S_OK on success, otherwise failure code.</returns>
HRESULT AudioPanel::CreateBeamGauge()
{
    HRESULT hr = m_pD2DFactory->CreatePathGeometry(&m_pBeamGauge);

    // Create gauge background shape
    if (SUCCEEDED(hr))
    {
        ID2D1GeometrySink *pGeometrySink = NULL;
        hr = m_pBeamGauge->Open(&pGeometrySink);

        if (SUCCEEDED(hr))
        {
            pGeometrySink->BeginFigure(D2D1::Point2F(0.1503f,0.2832f), D2D1_FIGURE_BEGIN_FILLED);
            pGeometrySink->AddLine(D2D1::Point2F(0.228f,0.2203f));
            pGeometrySink->AddArc(D2D1::ArcSegment(D2D1::Point2F(0.772f,0.2203f), D2D1::SizeF(0.35f,0.35f), 102, D2D1_SWEEP_DIRECTION_COUNTER_CLOCKWISE, D2D1_ARC_SIZE_SMALL));
            pGeometrySink->AddLine(D2D1::Point2F(0.8497f,0.2832f));
            pGeometrySink->AddArc(D2D1::ArcSegment(D2D1::Point2F(0.1503f,0.2832f), D2D1::SizeF(0.45f,0.45f), 102, D2D1_SWEEP_DIRECTION_CLOCKWISE, D2D1_ARC_SIZE_SMALL));
            pGeometrySink->EndFigure(D2D1_FIGURE_END_CLOSED);
            hr = pGeometrySink->Close();

            // Create gauge background brush
            if (SUCCEEDED(hr))
            {
                ID2D1GradientStopCollection *pGradientStops = NULL;
                D2D1_GRADIENT_STOP gradientStops[4];
                gradientStops[0].color = D2D1::ColorF(D2D1::ColorF::LightGray, 1);
                gradientStops[0].position = 0.0f;
                gradientStops[1].color = D2D1::ColorF(D2D1::ColorF::LightGray, 1);
                gradientStops[1].position = 0.34f;
                gradientStops[2].color = D2D1::ColorF(D2D1::ColorF::WhiteSmoke, 1);
                gradientStops[2].position = 0.37f;
                gradientStops[3].color = D2D1::ColorF(D2D1::ColorF::WhiteSmoke, 1);
                gradientStops[3].position = 1.0f;
                hr = m_pRenderTarget->CreateGradientStopCollection(
                    gradientStops,
                    4,
                    &pGradientStops
                    );

                if (SUCCEEDED(hr))
                {
                    hr = m_pRenderTarget->CreateRadialGradientBrush(D2D1::RadialGradientBrushProperties(D2D1::Point2F(0.5f,0.0f), D2D1::Point2F(0.0f,0.0f), 1.0f, 1.0f), pGradientStops, &m_pBeamGaugeFill);

                    if (SUCCEEDED(hr))
                    {
                        // Create gauge needle shape and fill brush
                        hr = CreateBeamGaugeNeedle();
                    }
                }

                SafeRelease(pGradientStops);
            }
        }

        SafeRelease(pGeometrySink);
    }

    return hr;
}
/// <summary>
/// Create outline that frames both gauges and energy display into a cohesive panel.
/// </summary>
/// <returns>S_OK on success, otherwise failure code.</returns>
HRESULT AudioPanel::CreatePanelOutline()
{
    HRESULT hr = m_pD2DFactory->CreatePathGeometry(&m_pPanelOutline);

    // Create panel outline path
    if (SUCCEEDED(hr))
    {
        ID2D1GeometrySink *pGeometrySink = NULL;
        hr = m_pPanelOutline->Open(&pGeometrySink);

        if (SUCCEEDED(hr))
        {
            /// Draw left wave display frame
            pGeometrySink->BeginFigure(D2D1::Point2F(0.15f,0.0353f), D2D1_FIGURE_BEGIN_FILLED);
            pGeometrySink->AddLine(D2D1::Point2F(0.13f,0.0353f));
            pGeometrySink->AddLine(D2D1::Point2F(0.13f,0.2203f));
            pGeometrySink->AddLine(D2D1::Point2F(0.2280f,0.2203f));

            // Draw gauge outline
            pGeometrySink->AddLine(D2D1::Point2F(0.1270f,0.3021f));
            pGeometrySink->AddArc(D2D1::ArcSegment(D2D1::Point2F(0.8730f,0.3021f), D2D1::SizeF(0.48f,0.48f), 102, D2D1_SWEEP_DIRECTION_COUNTER_CLOCKWISE, D2D1_ARC_SIZE_SMALL));
            pGeometrySink->AddLine(D2D1::Point2F(0.7720f,0.2203f));
            pGeometrySink->AddArc(D2D1::ArcSegment(D2D1::Point2F(0.2280f,0.2203f), D2D1::SizeF(0.35f,0.35f), 102, D2D1_SWEEP_DIRECTION_CLOCKWISE, D2D1_ARC_SIZE_SMALL));

            // Reposition geometry without drawing
            pGeometrySink->SetSegmentFlags(D2D1_PATH_SEGMENT_FORCE_UNSTROKED);
            pGeometrySink->AddLine(D2D1::Point2F(0.7720f,0.2203f));
            pGeometrySink->SetSegmentFlags(D2D1_PATH_SEGMENT_NONE);

            // Draw right wave display frame
            pGeometrySink->AddLine(D2D1::Point2F(0.87f,0.2203f));
            pGeometrySink->AddLine(D2D1::Point2F(0.87f,0.0353f));
            pGeometrySink->AddLine(D2D1::Point2F(0.85f,0.0353f));
            pGeometrySink->EndFigure(D2D1_FIGURE_END_OPEN);
            hr = pGeometrySink->Close();

            // Create panel outline brush
            if (SUCCEEDED(hr))
            {
                hr = m_pRenderTarget->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::LightGray), &m_pPanelOutlineStroke);
            }
        }

        SafeRelease(pGeometrySink);
    }

    return hr;
}
HRESULT DemoApp::CreateDeviceIndependentResources()
{
    HRESULT hr;
    ID2D1GeometrySink *pSink = NULL;

    // Create a Direct2D factory.
    hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &m_pD2DFactory);
    if (SUCCEEDED(hr))
    {
        // Create the path geometry.
        hr = m_pD2DFactory->CreatePathGeometry(&m_pPathGeometry);
    }
    if (SUCCEEDED(hr))
    {
        // Write to the path geometry using the geometry sink. We are going to create a
        // spiral
        hr = m_pPathGeometry->Open(&pSink);
    }
    if (SUCCEEDED(hr))
    {
        D2D1_POINT_2F currentLocation = {0, 0};

        pSink->BeginFigure(currentLocation, D2D1_FIGURE_BEGIN_FILLED);

        D2D1_POINT_2F locDelta = {2, 2};
        float radius = 3;

        for (UINT i = 0; i < 30; ++i)
        {
            currentLocation.x += radius * locDelta.x;
            currentLocation.y += radius * locDelta.y;

            pSink->AddArc(
                D2D1::ArcSegment(
                    currentLocation,
                    D2D1::SizeF(2*radius, 2*radius), // radiusx/y
                    0.0f, // rotation angle
                    D2D1_SWEEP_DIRECTION_CLOCKWISE,
                    D2D1_ARC_SIZE_SMALL
                    )
                );

            locDelta = D2D1::Point2F(-locDelta.y, locDelta.x);

            radius += 3;
        }

        pSink->EndFigure(D2D1_FIGURE_END_OPEN);

        hr = pSink->Close();
    }
    if (SUCCEEDED(hr))
    {
        // Create the path geometry.
        hr = m_pD2DFactory->CreatePathGeometry(&m_pObjectGeometry);
    }
    if (SUCCEEDED(hr))
    {
        // Write to the object geometry using the geometry sink.
        // We are going to create a simple triangle
        hr = m_pObjectGeometry->Open(&pSink);
    }
    if (SUCCEEDED(hr))
    {
        pSink->BeginFigure(
            D2D1::Point2F(0.0f, 0.0f),
            D2D1_FIGURE_BEGIN_FILLED
            );

        const D2D1_POINT_2F ptTriangle[] = {{-10.0f, -10.0f}, {-10.0f, 10.0f}, {0.0f, 0.0f}};
        pSink->AddLines(ptTriangle, 3);

        pSink->EndFigure(D2D1_FIGURE_END_OPEN);

        hr = pSink->Close();
    }

    SafeRelease(&pSink);

    return hr;
}
Example #5
0
//-----------------------------------------------------------------------------
ID2D1PathGeometry* D2DGraphicsPath::getPath (int32_t fillMode)
{
	if (path == 0 || fillMode != currentPathFillMode)
	{
		dirty ();
		if (!SUCCEEDED (getD2DFactory ()->CreatePathGeometry (&path)))
			return 0;
		if (fillMode == -1)
			fillMode = 0;
		currentPathFillMode = fillMode;
		
		ID2D1GeometrySink* sink = 0;
		if (!SUCCEEDED (path->Open (&sink)))
		{
			path->Release ();
			path = 0;
			return 0;
		}

		sink->SetFillMode ((D2D1_FILL_MODE)fillMode);

		bool figureOpen = false;
		CPoint lastPos;
		for (ElementList::const_iterator it = elements.begin (); it != elements.end (); it++)
		{
			Element e = (*it);
			switch (e.type)
			{
				case Element::kArc:
				{
					bool clockwise = e.instruction.arc.clockwise;
					double startAngle = e.instruction.arc.startAngle;
					double endAngle = e.instruction.arc.endAngle;
					CRect o_r (e.instruction.arc.rect.left, e.instruction.arc.rect.top, e.instruction.arc.rect.right, e.instruction.arc.rect.bottom);
					CRect r (o_r);
					o_r.originize ();
					CPoint center = o_r.getCenter ();
					CPoint start;
					start.x = r.left + center.x + center.x * cos (radians (startAngle));
					start.y = r.top + center.y + center.y * sin (radians (startAngle));
					if (!figureOpen)
					{
						sink->BeginFigure (makeD2DPoint (start), D2D1_FIGURE_BEGIN_FILLED);
						figureOpen = true;
					}
					else if (lastPos != start)
					{
						sink->AddLine (makeD2DPoint (start));
					}

					double sweepangle = endAngle - startAngle;
					if (clockwise) {
						// sweepangle positive
						while (sweepangle < 0.0)
							sweepangle += 360.0;
						while (sweepangle > 360.0)
							sweepangle -= 360.0;
					} else {
						// sweepangle negative
						while (sweepangle > 0.0)
							sweepangle -= 360.0;
						while (sweepangle < -360.0)
							sweepangle += 360.0;
					}

					CPoint endPoint;
					endPoint.x = r.left + center.x + center.x * cos (radians (endAngle));
					endPoint.y = r.top + center.y + center.y * sin (radians (endAngle));

					D2D1_ARC_SEGMENT arc;
					arc.size = makeD2DSize (r.getWidth ()/2., r.getHeight ()/2.);
					arc.rotationAngle = 0;
					arc.sweepDirection = clockwise ? D2D1_SWEEP_DIRECTION_CLOCKWISE : D2D1_SWEEP_DIRECTION_COUNTER_CLOCKWISE;
					arc.point = makeD2DPoint (endPoint);
					arc.arcSize = fabs(sweepangle) <= 180. ? D2D1_ARC_SIZE_SMALL : D2D1_ARC_SIZE_LARGE;
					sink->AddArc (arc);
					lastPos = endPoint;
					break;
				}
				case Element::kEllipse:
				{
					CRect r (e.instruction.rect.left, e.instruction.rect.top, e.instruction.rect.right, e.instruction.rect.bottom);
					CPoint top (r.getTopLeft ());
					top.x += r.getWidth () / 2.;
					CPoint bottom (r.getBottomLeft ());
					bottom.x += r.getWidth () / 2.;
					if (figureOpen && lastPos != CPoint (e.instruction.rect.left, e.instruction.rect.top))
					{
						sink->EndFigure (D2D1_FIGURE_END_OPEN);
						figureOpen = false;
					}
					if (!figureOpen)
					{
						sink->BeginFigure (makeD2DPoint (top), D2D1_FIGURE_BEGIN_FILLED);
						figureOpen = true;
					}
					D2D1_ARC_SEGMENT arc = D2D1::ArcSegment (makeD2DPoint (bottom), D2D1::SizeF ((FLOAT)r.getWidth ()/2.f, (FLOAT)r.getHeight ()/2.f), 180.f, D2D1_SWEEP_DIRECTION_CLOCKWISE, D2D1_ARC_SIZE_SMALL);
					sink->AddArc (arc);
					arc.point = makeD2DPoint (top);
					sink->AddArc (arc);
					lastPos = top;
					break;
				}
				case Element::kRect:
				{
					D2D1_POINT_2F points[4] = {
						{(FLOAT)e.instruction.rect.right, (FLOAT)e.instruction.rect.top},
						{(FLOAT)e.instruction.rect.right, (FLOAT)e.instruction.rect.bottom},
						{(FLOAT)e.instruction.rect.left, (FLOAT)e.instruction.rect.bottom},
						{(FLOAT)e.instruction.rect.left, (FLOAT)e.instruction.rect.top}
					};
					if (figureOpen && lastPos != CPoint (e.instruction.rect.left, e.instruction.rect.top))
					{
						sink->EndFigure (D2D1_FIGURE_END_OPEN);
						figureOpen = false;
					}
					if (figureOpen == false)
					{
						sink->BeginFigure (points[3], D2D1_FIGURE_BEGIN_FILLED);
						figureOpen = true;
					}
					sink->AddLine (points[0]);
					sink->AddLine (points[1]);
					sink->AddLine (points[2]);
					sink->AddLine (points[3]);
					lastPos = CPoint (e.instruction.rect.left, e.instruction.rect.top);
					break;
				}
				case Element::kLine:
				{
					if (figureOpen)
					{
						D2D1_POINT_2F end = {(FLOAT)e.instruction.point.x, (FLOAT)e.instruction.point.y};
						sink->AddLine (end);
						lastPos = CPoint (e.instruction.point.x, e.instruction.point.y);
					}
					break;
				}
				case Element::kBezierCurve:
				{
					if (figureOpen)
					{
						D2D1_POINT_2F control1 = {(FLOAT)e.instruction.curve.control1.x, (FLOAT)e.instruction.curve.control1.y};
						D2D1_POINT_2F control2 = {(FLOAT)e.instruction.curve.control2.x, (FLOAT)e.instruction.curve.control2.y};
						D2D1_POINT_2F end = {(FLOAT)e.instruction.curve.end.x, (FLOAT)e.instruction.curve.end.y};
						D2D1_BEZIER_SEGMENT bezier = D2D1::BezierSegment (control1, control2, end);
						sink->AddBezier (bezier);
						lastPos = CPoint (e.instruction.curve.end.x, e.instruction.curve.end.y);
					}
					break;
				}
				case Element::kBeginSubpath:
				{
					if (figureOpen)
						sink->EndFigure (D2D1_FIGURE_END_OPEN);
					D2D1_POINT_2F start = {(FLOAT)e.instruction.point.x, (FLOAT)e.instruction.point.y};
					sink->BeginFigure (start, D2D1_FIGURE_BEGIN_FILLED);
					figureOpen = true;
					lastPos = CPoint (e.instruction.point.x, e.instruction.point.y);
					break;
				}
				case Element::kCloseSubpath:
				{
					if (figureOpen)
					{
						sink->EndFigure (D2D1_FIGURE_END_CLOSED);
						figureOpen = false;
					}
					break;
				}
			}
		}
		if (figureOpen)
			sink->EndFigure (D2D1_FIGURE_END_OPEN);
		HRESULT res = sink->Close ();
		if (!SUCCEEDED (res))
		{
			path->Release ();
			path = 0;
		}
		sink->Release ();
	}
	return path;
}
Example #6
0
VOID CreateD2DResource(HWND hWnd)
{
	// This function was called in the DrawRectangle function which in turn called to response the
	// WM_PAINT Message, to avoid creating resource every time, we test the pointer to g_pRenderTarget
	// If the resource already create, skip the function
	if (!g_pRenderTarget)
	{
		HRESULT hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &g_pD2DFactory) ;
		if (FAILED(hr))
		{
			MessageBox(hWnd, "Create D2D factory failed!", "Error", 0) ;
			return ;
		}

		// Obtain the size of the drawing area
		RECT rc ;		
		GetClientRect(hWnd, &rc) ;

		// Create a Direct2D render target
		hr = g_pD2DFactory->CreateHwndRenderTarget(
			D2D1::RenderTargetProperties(),
			D2D1::HwndRenderTargetProperties(
			hWnd, 
			D2D1::SizeU(rc.right - rc.left,rc.bottom - rc.top)
			), 
			&g_pRenderTarget
			) ;
		if (FAILED(hr))
		{
			MessageBox(hWnd, "Create render target failed!", "Error", 0) ;
			return ;
		}

		// Create a brush
		hr = g_pRenderTarget->CreateSolidColorBrush(
			D2D1::ColorF(D2D1::ColorF::Black),
			&g_pSceneBrush
			) ;
		if (FAILED(hr))
		{
			MessageBox(hWnd, "Create brush failed!", "Error", 0) ;
			return ;
		}

		// Create left mountain geometry
		hr = g_pD2DFactory->CreatePathGeometry(&g_pLeftMountainGeometry) ;
		if (SUCCEEDED(hr))
		{
			ID2D1GeometrySink *pSink = NULL;

			hr = g_pLeftMountainGeometry->Open(&pSink);
			if (SUCCEEDED(hr))
			{
				pSink->SetFillMode(D2D1_FILL_MODE_WINDING);

				pSink->BeginFigure(
					D2D1::Point2F(346,255),
					D2D1_FIGURE_BEGIN_FILLED
					);
				D2D1_POINT_2F points[5] = {
					D2D1::Point2F(267, 177),
					D2D1::Point2F(236, 192),
					D2D1::Point2F(212, 160),
					D2D1::Point2F(156, 255),
					D2D1::Point2F(346, 255), 
				};
				pSink->AddLines(points, ARRAYSIZE(points));
				pSink->EndFigure(D2D1_FIGURE_END_CLOSED);
			}
			pSink->Close() ;

			SAFE_RELEASE(pSink) ;
		}
		
		// Create right mountain geometry
		hr = g_pD2DFactory->CreatePathGeometry(&g_pRightMountainGeometry) ;
		if (SUCCEEDED(hr))
		{
			ID2D1GeometrySink *pSink = NULL;

			hr = g_pRightMountainGeometry->Open(&pSink);
			if (SUCCEEDED(hr))
			{
				pSink->SetFillMode(D2D1_FILL_MODE_WINDING);

				pSink->BeginFigure(
					D2D1::Point2F(575,263),
					D2D1_FIGURE_BEGIN_FILLED
					);
				D2D1_POINT_2F points[] = {
					D2D1::Point2F(481, 146),
					D2D1::Point2F(449, 181),
					D2D1::Point2F(433, 159),
					D2D1::Point2F(401, 214),
					D2D1::Point2F(381, 199), 
					D2D1::Point2F(323, 263), 
					D2D1::Point2F(575, 263)
				};
				pSink->AddLines(points, ARRAYSIZE(points));
				pSink->EndFigure(D2D1_FIGURE_END_CLOSED);
			}
			hr = pSink->Close();

			SAFE_RELEASE(pSink);

		}
		// Create sun geometry
		hr = g_pD2DFactory->CreatePathGeometry(&g_pSunGeometry) ;
		if (SUCCEEDED(hr))
		{
			ID2D1GeometrySink *pSink = NULL;

			hr = g_pSunGeometry->Open(&pSink);
			if (SUCCEEDED(hr))
			{
				pSink->SetFillMode(D2D1_FILL_MODE_WINDING);

				pSink->BeginFigure(
					D2D1::Point2F(270, 255),
					D2D1_FIGURE_BEGIN_FILLED
					);
				pSink->AddArc(
					D2D1::ArcSegment(
					D2D1::Point2F(440, 255), // end point
					D2D1::SizeF(85, 85),
					0.0f, // rotation angle
					D2D1_SWEEP_DIRECTION_CLOCKWISE,
					D2D1_ARC_SIZE_SMALL
					));            
				pSink->EndFigure(D2D1_FIGURE_END_CLOSED);

				pSink->BeginFigure(
					D2D1::Point2F(299, 182),
					D2D1_FIGURE_BEGIN_HOLLOW
					);
				pSink->AddBezier(
					D2D1::BezierSegment(
					D2D1::Point2F(299, 182),
					D2D1::Point2F(294, 176),
					D2D1::Point2F(285, 178)
					));
				pSink->AddBezier(
					D2D1::BezierSegment(
					D2D1::Point2F(276, 179),
					D2D1::Point2F(272, 173),
					D2D1::Point2F(272, 173)
					));
				pSink->EndFigure(D2D1_FIGURE_END_OPEN);

				pSink->BeginFigure(
					D2D1::Point2F(354, 156),
					D2D1_FIGURE_BEGIN_HOLLOW
					);
				pSink->AddBezier(
					D2D1::BezierSegment(
					D2D1::Point2F(354, 156),
					D2D1::Point2F(358, 149),
					D2D1::Point2F(354, 142)
					));
				pSink->AddBezier(
					D2D1::BezierSegment(
					D2D1::Point2F(349, 134),
					D2D1::Point2F(354, 127),
					D2D1::Point2F(354, 127)
					));
				pSink->EndFigure(D2D1_FIGURE_END_OPEN);

				pSink->BeginFigure(
					D2D1::Point2F(322,164),
					D2D1_FIGURE_BEGIN_HOLLOW
					);
				pSink->AddBezier(
					D2D1::BezierSegment(
					D2D1::Point2F(322, 164),
					D2D1::Point2F(322, 156),
					D2D1::Point2F(314, 152)
					));
				pSink->AddBezier(
					D2D1::BezierSegment(
					D2D1::Point2F(306, 149),
					D2D1::Point2F(305, 141),
					D2D1::Point2F(305, 141)
					));              
				pSink->EndFigure(D2D1_FIGURE_END_OPEN);

				pSink->BeginFigure(
					D2D1::Point2F(385, 164),
					D2D1_FIGURE_BEGIN_HOLLOW
					);
				pSink->AddBezier(
					D2D1::BezierSegment(
					D2D1::Point2F(385,164),
					D2D1::Point2F(392,161),
					D2D1::Point2F(394,152)
					));
				pSink->AddBezier(
					D2D1::BezierSegment(
					D2D1::Point2F(395,144),
					D2D1::Point2F(402,141),
					D2D1::Point2F(402,142)
					));                
				pSink->EndFigure(D2D1_FIGURE_END_OPEN);

				pSink->BeginFigure(
					D2D1::Point2F(408,182),
					D2D1_FIGURE_BEGIN_HOLLOW
					);
				pSink->AddBezier(
					D2D1::BezierSegment(
					D2D1::Point2F(408,182),
					D2D1::Point2F(416,184),
					D2D1::Point2F(422,178)
					));
				pSink->AddBezier(
					D2D1::BezierSegment(
					D2D1::Point2F(428,171),
					D2D1::Point2F(435,173),
					D2D1::Point2F(435,173)
					));
				pSink->EndFigure(D2D1_FIGURE_END_OPEN);
			}
			hr = pSink->Close();

			SAFE_RELEASE(pSink);
		}

		// Create river geometry
		hr = g_pD2DFactory->CreatePathGeometry(&g_pRiverGeometry) ;
		if (SUCCEEDED(hr))
		{
			ID2D1GeometrySink *pSink = NULL;

			hr = g_pRiverGeometry->Open(&pSink);
			if (SUCCEEDED(hr))
			{
				pSink->SetFillMode(D2D1_FILL_MODE_WINDING);
				pSink->BeginFigure(
					D2D1::Point2F(183, 392),
					D2D1_FIGURE_BEGIN_FILLED
					);
				pSink->AddBezier(
					D2D1::BezierSegment(
					D2D1::Point2F(238, 284),
					D2D1::Point2F(472, 345),
					D2D1::Point2F(356, 303)
					));
				pSink->AddBezier(
					D2D1::BezierSegment(
					D2D1::Point2F(237, 261),
					D2D1::Point2F(333, 256),
					D2D1::Point2F(333, 256)
					));
				pSink->AddBezier(
					D2D1::BezierSegment(
					D2D1::Point2F(335, 257),
					D2D1::Point2F(241, 261),
					D2D1::Point2F(411, 306)
					));
				pSink->AddBezier(
					D2D1::BezierSegment(
					D2D1::Point2F(574, 350),
					D2D1::Point2F(288, 324),
					D2D1::Point2F(296, 392)
					));
				pSink->EndFigure(D2D1_FIGURE_END_OPEN);
			}
			pSink->Close() ;
			SAFE_RELEASE(pSink) ;
		}
	}
}
Example #7
0
HRESULT DemoApp::CreateDeviceIndependentResources()
{



	static const WCHAR msc_fontName[] = L"Verdana";   //사용할 폰트 이름
    static const FLOAT msc_fontSize = 20;			  //폰트 크기
	

    HRESULT hr = S_OK;
    ID2D1GeometrySink *pSink = NULL;

    // Create a Direct2D factory.
    hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &m_pD2DFactory);
	
	if (SUCCEEDED(hr))
    {
        // Create WIC factory.
        hr = CoCreateInstance(CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&m_pWICFactory));
    }

	if (SUCCEEDED(hr))
	{
        // Create a DirectWrite factory.
        hr = DWriteCreateFactory(
            DWRITE_FACTORY_TYPE_SHARED,
            __uuidof(m_pDWriteFactory),
            reinterpret_cast<IUnknown **>(&m_pDWriteFactory)
            );
    }
	 if (SUCCEEDED(hr))
    {
        // Create a DirectWrite text format object.
        hr = m_pDWriteFactory->CreateTextFormat(
            msc_fontName,
            NULL,
            DWRITE_FONT_WEIGHT_NORMAL,
            DWRITE_FONT_STYLE_NORMAL,
            DWRITE_FONT_STRETCH_NORMAL,
            msc_fontSize,
            L"", //locale
            &m_pTextFormat
            );
    }

		if (SUCCEEDED(hr))  //  바퀴벌레 기하
			{
				hr = m_pD2DFactory->CreateEllipseGeometry(D2D1::Ellipse(D2D1::Point2F(0,0), 10, 5),&m_pWheel);

			}

	
		if (SUCCEEDED(hr))  //  칼날 반원 기하
		{
			hr = m_pD2DFactory->CreatePathGeometry(&m_pPathGeometry);

			if (SUCCEEDED(hr))
			{
				// Write to the path geometry using the geometry sink.
				hr = m_pPathGeometry->Open(&pSink);

				if (SUCCEEDED(hr))
				{
					pSink->BeginFigure(
						D2D1::Point2F(200 , 100),  // 200 ,100
						D2D1_FIGURE_BEGIN_FILLED
						);
         

					pSink->AddBezier(D2D1::BezierSegment( D2D1::Point2F(220, 300), D2D1::Point2F(380, -100) , D2D1::Point2F(400, 100) ) );   // 220, 300    380 -100     400 100
					
			

					pSink->EndFigure(D2D1_FIGURE_END_CLOSED);


					hr = pSink->Close();
				}

				   SafeRelease(&pSink);
			}
		}


			if (SUCCEEDED(hr))  //  바퀴 경로 기하
			{
			hr = m_pD2DFactory->CreatePathGeometry(&m_wheelPath);

			if (SUCCEEDED(hr))
			{
				// Write to the path geometry using the geometry sink.
				hr = m_wheelPath->Open(&pSink);

				if (SUCCEEDED(hr))
				{
					pSink->BeginFigure(D2D1::Point2F(200,0),D2D1_FIGURE_BEGIN_FILLED);
          
				pSink->AddBezier(D2D1::BezierSegment(
					D2D1::Point2F(250,-50),D2D1::Point2F(80,-80),D2D1::Point2F(0,-50)));
				pSink->AddBezier(D2D1::BezierSegment(
					D2D1::Point2F(-50,-10),D2D1::Point2F(-180,-80),D2D1::Point2F(-200,0)));
				pSink->AddBezier(D2D1::BezierSegment(
					D2D1::Point2F(-230,60),D2D1::Point2F(-80,70),D2D1::Point2F(0,50)));
				pSink->AddBezier(D2D1::BezierSegment(
					D2D1::Point2F(50,10),D2D1::Point2F(180,80),D2D1::Point2F(200,0)));
					
					
		
					pSink->EndFigure(D2D1_FIGURE_END_CLOSED);

					hr = pSink->Close();
				}

				   SafeRelease(&pSink);
			}
		}



		
			if (SUCCEEDED(hr))  // 파리 경로 기하
			{
				hr = m_pD2DFactory->CreatePathGeometry(&m_flyPath);

			if (SUCCEEDED(hr))
			{
				// Write to the path geometry using the geometry sink.
				hr = m_flyPath->Open(&pSink);

				if (SUCCEEDED(hr))
				{
					pSink->BeginFigure(D2D1::Point2F(200,0),D2D1_FIGURE_BEGIN_FILLED);
          
				pSink->AddBezier(D2D1::BezierSegment(
					D2D1::Point2F(250,-50),D2D1::Point2F(80,-80),D2D1::Point2F(-100,-50)));
				pSink->AddBezier(D2D1::BezierSegment(
					D2D1::Point2F(-50,-10),D2D1::Point2F(-180,-80),D2D1::Point2F(-100,0)));
				pSink->AddBezier(D2D1::BezierSegment(
					D2D1::Point2F(-230,60),D2D1::Point2F(-80,70),D2D1::Point2F(50,50)));
				pSink->AddBezier(D2D1::BezierSegment(
					D2D1::Point2F(50,10),D2D1::Point2F(180,80),D2D1::Point2F(300,60)));
					
					
		
					pSink->EndFigure(D2D1_FIGURE_END_CLOSED);

					hr = pSink->Close();
				}

				   SafeRelease(&pSink);
			}
		}

			
	if(SUCCEEDED(hr)) //파리 몸통 기하
    {
        hr = m_pD2DFactory->CreateEllipseGeometry(
			D2D1::Ellipse(D2D1::Point2F(0,0), 20, 10), &m_pFlyGeometry);
    }
	if(SUCCEEDED(hr)) //파리 오른쪽 눈알 기하
    {
        hr = m_pD2DFactory->CreateEllipseGeometry(
			D2D1::Ellipse(D2D1::Point2F(20,-5), 5, 5), &m_pRightEyeGeometry);
    }
	if(SUCCEEDED(hr)) //파리 왼쪽 눈알 기하
    {
        hr = m_pD2DFactory->CreateEllipseGeometry(
			D2D1::Ellipse(D2D1::Point2F(20,5), 5, 5), &m_pLeftEyeGeometry);
    }

	if(SUCCEEDED(hr)) //파리 날개 가운데 기하
    {
        hr = m_pD2DFactory->CreatePathGeometry(&m_pMiddleWingGeometry);
        if(SUCCEEDED(hr))
        {
            ID2D1GeometrySink *pSink = NULL;

            hr = m_pMiddleWingGeometry->Open(&pSink);
            if (SUCCEEDED(hr))
            {
                pSink->SetFillMode(D2D1_FILL_MODE_WINDING);

                pSink->BeginFigure(
                    D2D1::Point2F(10, -9),
                    D2D1_FIGURE_BEGIN_FILLED
                    );

				pSink->AddLine(D2D1::Point2F(10, -15));
				pSink->AddArc(D2D1::ArcSegment(D2D1::Point2F(-10,-15),D2D1::SizeF(10,5),0,
					D2D1_SWEEP_DIRECTION_COUNTER_CLOCKWISE,D2D1_ARC_SIZE_SMALL));
				pSink->AddLine(D2D1::Point2F(-10, -9));
				pSink->AddLine(D2D1::Point2F(-10, 9));
				pSink->AddLine(D2D1::Point2F(-10, 15));
				pSink->AddArc(D2D1::ArcSegment(D2D1::Point2F(10,15),D2D1::SizeF(10,5),0,
					D2D1_SWEEP_DIRECTION_COUNTER_CLOCKWISE,D2D1_ARC_SIZE_SMALL));

                pSink->EndFigure(D2D1_FIGURE_END_CLOSED);
            }
            hr = pSink->Close();

            SafeRelease(&pSink);
       }
    }
	if(SUCCEEDED(hr)) //파리 날개 위쪽 기하
    {
        hr = m_pD2DFactory->CreatePathGeometry(&m_pUpWingGeometry);
        if(SUCCEEDED(hr))
        {
            ID2D1GeometrySink *pSink = NULL;

            hr = m_pUpWingGeometry->Open(&pSink);
            if (SUCCEEDED(hr))
            {
                pSink->SetFillMode(D2D1_FILL_MODE_WINDING);

                pSink->BeginFigure(
                    D2D1::Point2F(10, -9),
                    D2D1_FIGURE_BEGIN_FILLED
                    );

				pSink->AddLine(D2D1::Point2F(10, -15));
				pSink->AddArc(D2D1::ArcSegment(D2D1::Point2F(-10,-15),D2D1::SizeF(10,5),45,
					D2D1_SWEEP_DIRECTION_COUNTER_CLOCKWISE,D2D1_ARC_SIZE_SMALL));
				pSink->AddLine(D2D1::Point2F(-10, -9));
				pSink->AddLine(D2D1::Point2F(-10, 9));
				pSink->AddLine(D2D1::Point2F(-10, 15));
				pSink->AddArc(D2D1::ArcSegment(D2D1::Point2F(10,15),D2D1::SizeF(10,5),-45,
					D2D1_SWEEP_DIRECTION_COUNTER_CLOCKWISE,D2D1_ARC_SIZE_SMALL));

                pSink->EndFigure(D2D1_FIGURE_END_CLOSED);
            }
            hr = pSink->Close();

            SafeRelease(&pSink);
       }
    }
	if(SUCCEEDED(hr)) //파리 날개 아래쪽 기하
    {
        hr = m_pD2DFactory->CreatePathGeometry(&m_pDownWingGeometry);
        if(SUCCEEDED(hr))
        {
            ID2D1GeometrySink *pSink = NULL;

            hr = m_pDownWingGeometry->Open(&pSink);
            if (SUCCEEDED(hr))
            {
                pSink->SetFillMode(D2D1_FILL_MODE_WINDING);

                pSink->BeginFigure(
                    D2D1::Point2F(10, -9),
                    D2D1_FIGURE_BEGIN_FILLED
                    );

				pSink->AddLine(D2D1::Point2F(10, -15));
				pSink->AddArc(D2D1::ArcSegment(D2D1::Point2F(-10,-15),D2D1::SizeF(10,5),-45,
					D2D1_SWEEP_DIRECTION_COUNTER_CLOCKWISE,D2D1_ARC_SIZE_SMALL));
				pSink->AddLine(D2D1::Point2F(-10, -9));
				pSink->AddLine(D2D1::Point2F(-10, 9));
				pSink->AddLine(D2D1::Point2F(-10, 15));
				pSink->AddArc(D2D1::ArcSegment(D2D1::Point2F(10,15),D2D1::SizeF(10,5),45,
					D2D1_SWEEP_DIRECTION_COUNTER_CLOCKWISE,D2D1_ARC_SIZE_SMALL));

                pSink->EndFigure(D2D1_FIGURE_END_CLOSED);
            }
            hr = pSink->Close();

            SafeRelease(&pSink);
       }
    }


	m_pWingGeometry[0] = m_pMiddleWingGeometry;	//중간위치의 날개
	m_pWingGeometry[1] = m_pUpWingGeometry;		//위쪽 위치의 날개
	m_pWingGeometry[2] = m_pMiddleWingGeometry;	//중간위치의 날개
	m_pWingGeometry[3] = m_pDownWingGeometry;	//아래쪽 위치의 날개

    return hr;
}