Scope
D2ChannelRender.h
1 #pragma once
2 
3 #include "d2wrap.h"
4 
5 namespace d2d {
6 
10 
11 protected:
13  mutable std::mutex mutex;
14 
16  std::unique_ptr<RenderTarget> render_target;
17 
19  ID2D1Bitmap* bitmap;
20 
22  ID2D1SolidColorBrush* text_brush;
23 
25  IDWriteTextFormat* text_format;
26 
28  HWND hwnd;
29 
31  std::wstring scaletext;
32 
33 protected:
36 
37 public:
39 
42 
45  virtual void Create(const HWND& _hwnd, const uint32_t& _xres, const uint32_t& _yres);
46 
48  virtual void Render();
49 
51  ID2D1Bitmap* Bitmap() const { return bitmap; }
52 
56  bool ResizeBitmap(const uint32_t& _xres, const uint32_t& _yres);
57 
59  void DrawBitmap() { render_target->DrawBitmap(bitmap); }
60 
64  virtual bool Resize(const uint32_t& _xres, const uint32_t& _yres);
65 
67  D2D1_SIZE_F GetSize(void) const { return render_target->GetSize(); }
68 
70  virtual void UpdateScaleText(const std::wstring& _text);
71 };
72 
74 typedef std::shared_ptr<D2ChannelRender> D2ChannelRenderPtr;
75 
76 }
ID2D1SolidColorBrush * text_brush
Direct2D brush for text (do not use a unique_ptr for COM interfaces)
virtual bool Resize(const uint32_t &_xres, const uint32_t &_yres)
Resizes the render target.
~D2ChannelRender()
Discard resources and delete the render_target.
virtual void UpdateScaleText(const std::wstring &_text)
Update the scale text.
D2D1_SIZE_F GetSize(void) const
std::shared_ptr< D2ChannelRender > D2ChannelRenderPtr
Shared pointer to a D2ChannelRender.
void DrawBitmap()
Draws current bitmap in render target.
HWND hwnd
Window handle.
Wrappers around the Direct2D interface.
Handles all Direct2D rendering in a CChannelView.
Parts of the code are modified from Microsoft's Direct2D nbody example: Copyright (c) Microsoft Corpo...
void DiscardDeviceResources()
Safely release all Direct2D resources.
virtual void Render()
Renders the bitmap and the scale text.
ID2D1Bitmap * Bitmap() const
IDWriteTextFormat * text_format
Direct2D text format (do not use a unique_ptr for COM interfaces)
std::unique_ptr< RenderTarget > render_target
Direct2D render target.
std::mutex mutex
mutex for protection
ID2D1Bitmap * bitmap
Direct2D bitmap (do not use a unique_ptr for COM interfaces)
bool ResizeBitmap(const uint32_t &_xres, const uint32_t &_yres)
Resizes the bitmap.
virtual void Create(const HWND &_hwnd, const uint32_t &_xres, const uint32_t &_yres)
Creates the render target for a hwnd, a bitmap with the desired resolution, a brushes for painting ...
std::wstring scaletext
String with the scale information, ala L"9.5 µm".