Beispiel #1
0
bool CDirectWriteRenderer::DrawText(
	LPCWSTR pText, int Length, const RECT &Rect,
	CDirectWriteFont &Font, CDirectWriteBrush &Brush, unsigned int Flags)
{
	if (pText == nullptr)
		return false;
	if (m_pRenderTarget == nullptr)
		return false;

	bool fOK = false;

	IDWriteTextFormat *pTextFormat = Font.GetTextFormat();

	if (pTextFormat != nullptr) {
		ID2D1Brush *pBrush = Brush.GetBrush();

		if (pBrush != nullptr) {
			pTextFormat->SetTextAlignment(
				(Flags & DRAW_TEXT_ALIGN_HORZ_CENTER) != 0 ?
					DWRITE_TEXT_ALIGNMENT_CENTER :
				(Flags & DRAW_TEXT_ALIGN_RIGHT) != 0 ?
					DWRITE_TEXT_ALIGNMENT_TRAILING :
				((Flags & DRAW_TEXT_ALIGN_JUSTIFIED) != 0
					&& Util::OS::IsWindows8OrLater()) ?
					DWRITE_TEXT_ALIGNMENT_JUSTIFIED :
					DWRITE_TEXT_ALIGNMENT_LEADING);
			pTextFormat->SetParagraphAlignment(
				(Flags & DRAW_TEXT_ALIGN_VERT_CENTER) != 0 ?
					DWRITE_PARAGRAPH_ALIGNMENT_CENTER :
				(Flags & DRAW_TEXT_ALIGN_BOTTOM) != 0 ?
					DWRITE_PARAGRAPH_ALIGNMENT_FAR :
					DWRITE_PARAGRAPH_ALIGNMENT_NEAR);
			pTextFormat->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP);
			DWRITE_TRIMMING Trimming = {DWRITE_TRIMMING_GRANULARITY_NONE, 0, 0};
			pTextFormat->SetTrimming(&Trimming, nullptr);

			m_pRenderTarget->DrawText(
				pText,
				Length >= 0 ? Length : ::lstrlenW(pText),
				pTextFormat,
				D2DRectF(Rect),
				pBrush);
			fOK = true;

			pBrush->Release();
		}

		pTextFormat->Release();
	}

	return fOK;
}
void MWinDeviceImpl::SetBackColor(
	MColor				inColor)
{
	if (mBackBrush != nil)
		mBackBrush->Release();

	ID2D1SolidColorBrush* brush;
	THROW_IF_HRESULT_ERROR(
		mRenderTarget->CreateSolidColorBrush(D2D1::ColorF(inColor.red / 255.f, inColor.green / 255.f, inColor.blue / 255.f), &brush));

	mBackBrush = brush;
}
void MWinDeviceImpl::CreateAndUsePattern(
	MColor				inColor1,
	MColor				inColor2)
{
	uint32 data[8][8];

	uint32 c1 = 0, c2 = 0;

	c1 |= inColor1.red << 16;
	c1 |= inColor1.green << 8;
	c1 |= inColor1.blue << 0;
	
	c2 |= inColor2.red << 16;
	c2 |= inColor2.green << 8;
	c2 |= inColor2.blue << 0;

	for (uint32 y = 0; y < 8; ++y)
	{
		for (uint32 x = 0; x < 4; ++x)
			data[y][x] = c1;
		for (uint32 x = 4; x < 8; ++x)
			data[y][x] = c2;
	}

	ID2D1BitmapBrush* brush;

	ID2D1Bitmap* bitmap;
	THROW_IF_HRESULT_ERROR(mRenderTarget->CreateBitmap(D2D1::SizeU(8, 8), data, 32,
		D2D1::BitmapProperties(
			D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_IGNORE)
		), &bitmap));

	THROW_IF_HRESULT_ERROR(mRenderTarget->CreateBitmapBrush(
		bitmap,
		D2D1::BitmapBrushProperties(D2D1_EXTEND_MODE_WRAP, D2D1_EXTEND_MODE_WRAP),
		D2D1::BrushProperties(1.0f, D2D1::Matrix3x2F::Rotation(45.f)),
		&brush));

	bitmap->Release();

	if (mForeBrush != nil)
		mForeBrush->Release();

	mForeBrush = brush;
}
Beispiel #4
0
 virtual ~D2DPaintRendererState() {
     if (brush) {
         brush->Release();
         brush = NULL;
     }
 }