Beispiel #1
0
Arc::Arc(FLOAT x1, FLOAT y1, FLOAT x2, FLOAT y2, FLOAT xRadius, FLOAT yRadius, FLOAT angle,
	D2D1_SWEEP_DIRECTION sweep, D2D1_ARC_SIZE size, D2D1_FIGURE_END ending) : Shape(ShapeType::Arc),
	m_StartPoint(D2D1::Point2F(x1, y1)),
	m_ArcSegment(D2D1::ArcSegment(
		D2D1::Point2F(x2, y2),
		D2D1::SizeF(xRadius, yRadius),
		angle,
		sweep,
		size)),
	m_ShapeEnding(ending)
{
	Microsoft::WRL::ComPtr<ID2D1GeometrySink> sink;
	Microsoft::WRL::ComPtr<ID2D1PathGeometry> path;
	HRESULT hr = Canvas::c_D2DFactory->CreatePathGeometry(path.GetAddressOf());
	if (SUCCEEDED(hr))
	{
		hr = path->Open(sink.GetAddressOf());
		if (SUCCEEDED(hr))
		{
			sink->BeginFigure(m_StartPoint, D2D1_FIGURE_BEGIN_FILLED);
			sink->AddArc(m_ArcSegment);
			sink->EndFigure(m_ShapeEnding);
			sink->Close();

			hr = path.CopyTo(m_Shape.GetAddressOf());
			if (SUCCEEDED(hr)) return;
		}
	}

	LogErrorF(L"Could not create arc object. X1=%i, Y1=%i, X2=%i, Y2=%i, XRadius=%i, YRadius=%i, Angle=%i",
		(int)x1, (int)y1, (int)x2, (int)y2, (int)xRadius, (int)yRadius, (int)angle);
}
Beispiel #2
0
bool Shape::CombineWith(Shape* otherShape, D2D1_COMBINE_MODE mode)
{
	Microsoft::WRL::ComPtr<ID2D1GeometrySink> sink;
	Microsoft::WRL::ComPtr<ID2D1PathGeometry> path;
	HRESULT hr = Canvas::c_D2DFactory->CreatePathGeometry(path.GetAddressOf());
	if (FAILED(hr)) return false;

	hr = path->Open(sink.GetAddressOf());
	if (FAILED(hr)) return false;

	if (otherShape)
	{
		hr = m_Shape->CombineWithGeometry(
			otherShape->m_Shape.Get(),
			mode,
			otherShape->GetShapeMatrix(),
			sink.Get());
		if (FAILED(hr)) return false;

		sink->Close();

		hr = path.CopyTo(m_Shape.ReleaseAndGetAddressOf());
		if (FAILED(hr)) return false;

		return true;
	}

	static const D2D1_RECT_F rect = { 0.0f, 0.0f, 0.0f, 0.0f };
	Microsoft::WRL::ComPtr<ID2D1RectangleGeometry> emptyShape;
	hr = Canvas::c_D2DFactory->CreateRectangleGeometry(rect, emptyShape.GetAddressOf());
	if (FAILED(hr)) return false;

	hr = emptyShape->CombineWithGeometry(m_Shape.Get(), mode, GetShapeMatrix(), sink.Get());

	sink->Close();

	if (FAILED(hr)) return false;

	hr = path.CopyTo(m_Shape.ReleaseAndGetAddressOf());
	if (FAILED(hr)) return false;

	m_Rotation = 0.0f;
	m_RotationAnchor = D2D1::Point2F();
	m_RotationAnchorDefined = false;
	m_Scale = D2D1::SizeF(1.0f, 1.0f);
	m_ScaleAnchor = D2D1::Point2F();
	m_ScaleAnchorDefined = false;
	m_Skew = D2D1::Point2F();
	m_SkewAnchor = D2D1::Point2F();
	m_SkewAnchorDefined = false;
	m_Offset = D2D1::SizeF(0.0f, 0.0f);

	return true;
}
IFACEMETHODIMP CustomTextRenderer::DrawGlyphRun(
    _In_opt_ void* clientDrawingContext,
    FLOAT baselineOriginX,
    FLOAT baselineOriginY,
    DWRITE_MEASURING_MODE measuringMode,
    _In_ DWRITE_GLYPH_RUN const* glyphRun,
    _In_ DWRITE_GLYPH_RUN_DESCRIPTION const* glyphRunDescription,
    IUnknown* clientDrawingEffect
    )
{
    HRESULT hr = S_OK;

    // Create the path geometry.
    Microsoft::WRL::ComPtr<ID2D1PathGeometry> pathGeometry;
    hr = D2DFactory->CreatePathGeometry(&pathGeometry);

    // Write to the path geometry using the geometry sink.
    Microsoft::WRL::ComPtr<ID2D1GeometrySink> sink;
    if (SUCCEEDED(hr))
    {
        hr = pathGeometry->Open(&sink);
    }

    // Get the glyph run outline geometries back from DirectWrite and place them within the
    // geometry sink.
    if (SUCCEEDED(hr))
    {
        hr = glyphRun->fontFace->GetGlyphRunOutline(
            glyphRun->fontEmSize,
            glyphRun->glyphIndices,
            glyphRun->glyphAdvances,
            glyphRun->glyphOffsets,
            glyphRun->glyphCount,
            glyphRun->isSideways,
            glyphRun->bidiLevel%2,
            sink.Get()
            );
    }

    // Close the geometry sink
    if (SUCCEEDED(hr))
    {
        hr = sink.Get()->Close();
    }

	/*Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> shadowBrush;
	Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> shadowOutlineBrush;
	if(SUCCEEDED(hr))
	{
		hr = D2DDeviceContext->CreateSolidColorBrush(
		D2D1::ColorF(0.0,0.0,0.0,0.6),
		&shadowBrush
		);
	}
	if(SUCCEEDED(hr))
	{
		hr = D2DDeviceContext->CreateSolidColorBrush(
		D2D1::ColorF(0.0,0.0,0.0,0.6),
		&shadowOutlineBrush
		);
	}
	D2D1_RECT_F bounds;
	pathGeometry->GetBounds(&D2D1::Matrix3x2F::Identity(),&bounds);*/

    // Initialize a matrix to translate the origin of the glyph run.
    D2D1::Matrix3x2F const matrix = D2D1::Matrix3x2F(
        1.0f, 0.0f,
        0.0f, 1.0f,
        baselineOriginX, baselineOriginY
        );

	/*D2D1::Matrix3x2F const shadowMatrix = D2D1::Matrix3x2F(
		1.0f, 0.0f,
		0.0f, 1.0f,
		-bounds.left, -bounds.top
		);
	*/
	
	// Create the transformed geometry
	Microsoft::WRL::ComPtr<ID2D1TransformedGeometry> transformedGeometry;
	if (SUCCEEDED(hr))
	{
        hr = D2DFactory.Get()->CreateTransformedGeometry(
            pathGeometry.Get(),
            &matrix,
            &transformedGeometry
            );
    }

    // Draw the outline of the glyph run
    D2DDeviceContext->DrawGeometry(
        transformedGeometry.Get(),
        outlineBrush.Get(),
		2.0
        );

    // Fill in the glyph run
    D2DDeviceContext->FillGeometry(
        transformedGeometry.Get(),
        fillBrush.Get()
        );

	

    return hr;
}