Example #1
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;
}
RoundedRectangle::RoundedRectangle(FLOAT x, FLOAT y, FLOAT width, FLOAT height,
	FLOAT xRadius, FLOAT yRadius) : Shape(ShapeType::RoundedRectangle),
		m_X(x),
		m_Y(y),
		m_Width(width + x),
		m_Height(height + y),
		m_XRadius(xRadius),
		m_YRadius(yRadius)
{
	HRESULT hr = E_FAIL;
	const D2D1_ROUNDED_RECT rect = { m_X, m_Y, m_Width, m_Height, m_XRadius, m_YRadius };

	Microsoft::WRL::ComPtr<ID2D1RoundedRectangleGeometry> rectangle;
	hr = Canvas::c_D2DFactory->CreateRoundedRectangleGeometry(rect, rectangle.GetAddressOf());
	if (FAILED(hr))
	{
		LogErrorF(
			L"Could not create rounded rectangle object. X=%i, Y=%i, W=%i, H=%i, XRadius=%i, YRadius=%i",
			(int)m_X, (int)m_Y, (int)m_Width, (int)m_Height, (int)m_XRadius, (int)m_YRadius);
		return;
	}

	hr = rectangle.CopyTo(m_Shape.GetAddressOf());
	if (FAILED(hr)) LogErrorF(
		L"Could not copy rounded rectangle object to shape object. X=%i, Y=%i, W=%i, H=%i, XRadius=%i, YRadius=%i",
		(int)m_X, (int)m_Y, (int)m_Width, (int)m_Height, (int)m_XRadius, (int)m_YRadius);
}
Example #3
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);
}
Example #4
0
void Shape::CreateRadialGradient(ID2D1RenderTarget* target, ID2D1GradientStopCollection* collection,
	Microsoft::WRL::ComPtr<ID2D1Brush>& brush, bool isStroke)
{
	auto swapIfNotDefined = [](D2D1_POINT_2F& pt1, const D2D1_POINT_2F pt2) -> void
	{
		if (pt2.x != FLT_MAX) pt1.x = pt2.x;
		if (pt2.y != FLT_MAX) pt1.y = pt2.y;
	};

	auto bounds = GetBounds(false);
	D2D1_POINT_2F offset = D2D1::Point2F();
	D2D1_POINT_2F center = D2D1::Point2F(((bounds.left + bounds.right) / 2.0f), ((bounds.top + bounds.bottom) / 2.0f));
	D2D1_POINT_2F radius = D2D1::Point2F((bounds.right - bounds.left) / 2.0f, (bounds.bottom - bounds.top) / 2.0f);

	// Offset from actual center of shape
	center = Util::AddPoint2F(center, isStroke ? m_StrokeRadialGradientCenter : m_FillRadialGradientCenter);

	// Check if offset and radii are defined
	swapIfNotDefined(offset, isStroke ? m_StrokeRadialGradientOffset : m_FillRadialGradientOffset);
	swapIfNotDefined(radius, isStroke ? m_StrokeRadialGradientRadius : m_FillRadialGradientRadius);

	Microsoft::WRL::ComPtr<ID2D1RadialGradientBrush> radial;
	HRESULT hr = target->CreateRadialGradientBrush(
		D2D1::RadialGradientBrushProperties(
			center,
			offset,
			radius.x,
			radius.y),
		collection,
		radial.GetAddressOf());

	if (SUCCEEDED(hr)) radial.CopyTo(brush.ReleaseAndGetAddressOf());
}
Example #5
0
void Shape::CreateSolidBrush(ID2D1RenderTarget* target, Microsoft::WRL::ComPtr<ID2D1Brush>& brush,
	const D2D1_COLOR_F& color)
{
	Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> solid;
	HRESULT hr = target->CreateSolidColorBrush(color, solid.GetAddressOf());

	if (SUCCEEDED(hr)) solid.CopyTo(brush.ReleaseAndGetAddressOf());
}
Example #6
0
void EvrPanel::SetVideoDisplayControl(::Microsoft::WRL::ComPtr<IMFVideoDisplayControl> videoDisplayControl)
{
	videoDisplayControl.CopyTo(&videoDisplayControl_);
	if (videoDisplayControl_)
	{
		videoDisplayControl_->SetVideoWindow(hwnd());

		auto& scale_factor = root().scale_factor();
		MFVideoNormalizedRect mvnr = { 0, 0, 1, 1 };
		RECT rect = { 0, 0, 0, 0 };
		GetWindowRect(hwnd(), &rect);
		rect.top = 0;
		rect.left = 0;
		videoDisplayControl_->SetVideoPosition(&mvnr, &rect);
	}
}
Example #7
0
void Shape::CreateLinearGradient(ID2D1RenderTarget* target, ID2D1GradientStopCollection* collection,
	Microsoft::WRL::ComPtr<ID2D1Brush>& brush, const FLOAT angle)
{
	auto bounds = GetBounds(false);
	D2D1_POINT_2F start = Util::FindEdgePoint(angle,
		bounds.left, bounds.top, bounds.right - bounds.left, bounds.bottom - bounds.top);
	D2D1_POINT_2F end = Util::FindEdgePoint(angle + 180,
		bounds.left, bounds.top, bounds.right - bounds.left, bounds.bottom - bounds.top);

	Microsoft::WRL::ComPtr<ID2D1LinearGradientBrush> linear;
	HRESULT hr = target->CreateLinearGradientBrush(
		D2D1::LinearGradientBrushProperties(start, end),
		collection,
		linear.GetAddressOf());

	if (SUCCEEDED(hr)) linear.CopyTo(brush.ReleaseAndGetAddressOf());
}
Example #8
0
Ellipse::Ellipse(FLOAT x, FLOAT y, FLOAT xRadius, FLOAT yRadius) : Shape(ShapeType::Ellipse),
	m_CenterPoint(D2D1::Point2F(x, y)),
	m_RadiusX(xRadius),
	m_RadiusY(yRadius)
{
	HRESULT hr = E_FAIL;
	const D2D1_ELLIPSE ellipse = D2D1::Ellipse(m_CenterPoint, m_RadiusX, m_RadiusY);

	Microsoft::WRL::ComPtr<ID2D1EllipseGeometry> geometry;
	hr = Canvas::c_D2DFactory->CreateEllipseGeometry(ellipse, geometry.GetAddressOf());
	if (FAILED(hr))
	{
		LogErrorF(
			L"Could not create ellipse object. X=%i, Y=%i, RadiusX=%i, RadiusY=%i",
			(int)x, (int)y, (int)xRadius, (int)yRadius);
		return;
	}

	hr = geometry.CopyTo(m_Shape.GetAddressOf());
	if (FAILED(hr)) LogErrorF(
		L"Could not copy ellipse object to shape object. X=%i, Y=%i, RadiusX=%i, RadiusY=%i",
		(int)x, (int)y, (int)xRadius, (int)yRadius);
}