3 #include "helpers/hresult_exception.h"
12 , dwrite_factory(nullptr)
13 , pixelformat(D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_IGNORE)) {
18 GetClientRect(_hwnd, &rc);
19 D2D1_SIZE_U size = D2D1::SizeU( rc.right - rc.left, rc.bottom - rc.top );
22 const D2D1_RENDER_TARGET_PROPERTIES targetProperties = D2D1::RenderTargetProperties(D2D1_RENDER_TARGET_TYPE_DEFAULT,
pixelformat);
25 , D2D1::HwndRenderTargetProperties(_hwnd, size, D2D1_PRESENT_OPTIONS_IMMEDIATELY)
30 hr(__FUNCTION__) = DWriteCreateFactory( DWRITE_FACTORY_TYPE_SHARED
31 , __uuidof(IDWriteFactory)
34 target->SetAntialiasMode(D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);
38 DBOUT(L
"Exception in d2d::render_target::render_target, hresult" << e.
hr);
49 return HResult(
target->CreateSolidColorBrush(_color, _brush), __FUNCTION__);
59 FLOAT systemdpi_x = 96;
60 FLOAT systemdpi_y = 96;
63 hr(__FUNCTION__) =
target->CreateBitmap(
64 D2D1::SizeU(_xres, _yres),
69 D2D1::BitmapProperties(
pixelformat, systemdpi_x, systemdpi_y),
74 DBOUT(L
"Exception in d2d::render_target.CreateBitmap, hresult=" << e.
hr);
84 DWRITE_FONT_WEIGHT_REGULAR,
85 DWRITE_FONT_STYLE_NORMAL,
86 DWRITE_FONT_STRETCH_NORMAL,
89 _text_format ), __FUNCTION__);
91 hr(__FUNCTION__) = (*_text_format)->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_LEADING);
106 return target->CheckWindowState();
110 target->SetTransform(_transform);
114 target->SetTransform(D2D1::Matrix3x2F::Identity());
115 target->Clear(D2D1::ColorF(255.0f, 255.0f, 255.0f,0.f));
119 target->SetTransform(D2D1::Matrix3x2F::Identity());
120 target->Clear(_clearColor);
124 ATLASSERT(_bitmap !=
nullptr);
125 auto size =
target->GetSize();
126 auto sizebitmap = _bitmap->GetSize();
127 auto p = _bitmap->GetPixelSize();
128 target->DrawBitmap(_bitmap, D2D1::RectF(0, 0, size.width, size.height), 1, _mode);
131 void RenderTarget::DrawLine(
const D2D1_POINT_2F& _point0,
const D2D1_POINT_2F& _point1, ID2D1Brush* _brush,
const FLOAT& _strokeWidth) {
132 target->DrawLine(_point0, _point1, _brush, _strokeWidth);
135 void RenderTarget::DrawText(
const CString& _text,
const D2D1_RECT_F* _layoutRect, IDWriteTextFormat* _text_format, ID2D1Brush* _brush) {
136 target->DrawText(_text.GetString()
144 target->FillRectangle(_rect, _brush);
void Clear(const D2D1_COLOR_F &_clearColor=D2D1::ColorF(D2D1::ColorF::White))
Clear the window with a certain color.
IDWriteFactory * dwrite_factory
Direct2D write factory for text rendering (do not use a unique_ptr for COM interfaces) ...
void ClearWindow()
Clear the window with black.
Exception class for HRESULTs.
HRESULT CreateBitmap(ID2D1Bitmap **_bitmap, const uint32_t &_yres, const uint32_t &_xres)
Creates a new Direct2D bitmap.
void SetTransform(const D2D1_MATRIX_3X2_F &_transform)
Set current transform matrix.
void DrawLine(const D2D1_POINT_2F &_point0, const D2D1_POINT_2F &_point1, ID2D1Brush *_brush, const FLOAT &_strokeWidth)
Draw a line.
HRESULT CreateTextFormat(IDWriteTextFormat **_text_format)
Create a text format.
d2dfactory< D2D1_FACTORY_TYPE_MULTI_THREADED > factory
Direct2D factory.
void BeginDraw()
Trigger Direct2D begin draw.
ID2D1HwndRenderTarget * target
Direct2D render target (do not use a unique_ptr for COM interfaces)
Wrappers around the Direct2D interface.
void FillRectangle(const D2D1_RECT_F *_rect, ID2D1Brush *_brush)
Fill a rectangle.
static float scaleX
x scale factor
void SafeRelease(Interface **ppInterfaceToRelease)
A safe release for COM objects.
Parts of the code are modified from Microsoft's Direct2D nbody example: Copyright (c) Microsoft Corpo...
ID2D1Factory * pd2d_factory
Direct2D factory (do not use a unique_ptr for COM interfaces)
HRESULT hr
Current HRESULT.
This is the include file for standard system include files, or project specific include files that ar...
HRESULT EndDraw()
Trigger Direct2D end draw.
HRESULT Resize(const D2D1_SIZE_U &_pixelSize)
Resize render target.
HRESULT CreateSolidColorBrush(ID2D1SolidColorBrush **_brush, const D2D1_COLOR_F &_color=D2D1::ColorF(D2D1::ColorF::White))
Create a solid color brush.
#define DBOUT(s)
A debug output to the debug console.
D2D1_PIXEL_FORMAT pixelformat
current pixel format
static float scaleY
y scale factor
void DrawText(const CString &_text, const D2D1_RECT_F *_layoutRect, IDWriteTextFormat *_text_format, ID2D1Brush *_brush)
Draw text.
HRESULT CreateRectangleGeometry(const D2D1_RECT_F &_rectangle, ID2D1RectangleGeometry **_rectangleGeometry)
Create a rectangle geometry.
D2D1_SIZE_F GetSize() const
Get size of render target.
~RenderTarget()
Release resources.
RenderTarget(const RenderTarget &)
disable copy
void DrawBitmap(ID2D1Bitmap *_bitmap, D2D1_BITMAP_INTERPOLATION_MODE _mode=D2D1_BITMAP_INTERPOLATION_MODE_LINEAR)
Draws a Direct2D bitmap.
HRESULT Flush()
Flush the render target.
D2D1_WINDOW_STATE CheckWindowState()
Check state of window, e.g.