2 #include "D2HistogramRender.h"
3 #include "helpers/hresult_exception.h"
4 #include "helpers/ScopeMultiHistogram.h"
11 , render_target(nullptr)
14 , brushyellow(nullptr)
16 , llpos(channels, 0.0)
17 , ulpos(channels, 512.0)
32 std::lock_guard<std::mutex> lock(
mutex);
37 GetClientRect(
hwnd, &rect);
38 assert(( rect.right-rect.left) ==
width );
50 std::lock_guard<std::mutex> lock(
mutex);
55 std::lock_guard<std::mutex> lock(
mutex);
57 if ( 0 == (D2D1_WINDOW_STATE_OCCLUDED &
render_target->CheckWindowState()) ) {
63 std::vector<uint32_t> maxvals(
hist->MaxCounts());
64 float channelheight = size.height/
channels;
66 for ( uint32_t c = 0 ; c <
channels ; c++ ) {
68 multiplier = channelheight / (maxvals[c]+1.0f);
70 const std::vector<uint32_t>* h =
hist->GetHistConst(c);
71 assert(h->size() >= size.width);
73 for (
float pos = 0.0f ; pos < size.width ; pos += 1.0f ) {
74 render_target->DrawLine( D2D1::Point2F(pos, channelheight*(c+1.0f))
75 , D2D1::Point2F(pos, channelheight*(c+1.0f) - static_cast<float>(h->at(static_cast<size_t>(pos))) * multiplier)
79 hist->ReleaseHistConst(c);
82 , D2D1::Point2F(
ulpos[c], channelheight*(c+1.0f))
85 , D2D1::Point2F(
llpos[c], channelheight*(c+1.0f))
92 if ((HRESULT)hr == D2DERR_RECREATE_TARGET) {
93 hr(__FUNCTION__) = S_OK;
100 std::lock_guard<std::mutex> lock(
mutex);
101 ID2D1RectangleGeometry* hitTestlower =
nullptr;
102 ID2D1RectangleGeometry* hitTestupper =
nullptr;
105 D2D1_POINT_2F point = D2D1::Point2F(static_cast<FLOAT>(_clickpoint.x), static_cast<FLOAT>(_clickpoint.y));
106 for ( uint32_t c = 0 ; c <
channels ; c++ ) {
109 ,
llpos[c]+5.0f, channelheight*(c+1.0f)), &hitTestlower);
111 ,
ulpos[c]+5.0f, channelheight*(c+1.0f)), &hitTestupper);
113 hitTestlower->FillContainsPoint(point, NULL, &hit);
121 hitTestupper->FillContainsPoint(point, NULL, &hit);
135 std::lock_guard<std::mutex> lock(
mutex);
136 llpos[_channel] = _pos;
140 std::lock_guard<std::mutex> lock(
mutex);
141 ulpos[_channel] = _pos;
145 std::lock_guard<std::mutex> lock(
mutex);
147 DBOUT(L
"New size x: " << size.cx << L
" old size x: " <<
render_target->GetSize().width);
149 FLOAT s = ((size.cx==0)?1.0f:static_cast<FLOAT>(size.cx));
152 for ( FLOAT& p :
llpos )
154 for ( FLOAT& p :
ulpos )
std::unique_ptr< RenderTarget > render_target
Direct2D render target.
const uint32_t width
constant width of the renderer
scope::ScopeMultiHistogramPtr hist
Pointer to the currently rendered multi histogram.
Wrappers around the Direct2D interface.
void SetHistogram(scope::ScopeMultiHistogramPtr _hist)
Sets the pointer to the current multi histogram.
void Render()
Draws the current multi histogram with the limit lines.
void SafeRelease(Interface **ppInterfaceToRelease)
A safe release for COM objects.
void DiscardDeviceResources()
Safely release all Direct2D resources.
bool ClickedAt(const CPoint _clickpoint, uint32_t &_channel, bool &_uplo)
Checks if click hit a limit (+-5 pixel) and if yes, on which channel and upper or lower limit line...
D2HistogramRender(const D2HistogramRender &)
Disable copy.
This is the include file for standard system include files, or project specific include files that ar...
std::vector< FLOAT > ulpos
Keeps track of the upper limit positions in screen coordinates.
ID2D1SolidColorBrush * brushwhite
Direct2D white brush.
void Create(const HWND &_hwnd)
Creates the render target for a hwnd, the brushes for painting, and sets the limit position to the wi...
void SetLowerLimitPosition(const uint32_t &_channel, const FLOAT &_pos)
Set position of a lower limit line.
std::vector< FLOAT > llpos
Keeps track of the lower limit positions in screen coordinates.
#define DBOUT(s)
A debug output to the debug console.
ID2D1SolidColorBrush * brushyellow
Direct2D yellow brush.
const uint32_t channels
number of channels
void Size(const CSize &size)
Resizes the renderer and the limit positions.
Wrapper around a Direct2D render target and the underlying Direct2D factory and IDWriteFactory.
std::mutex mutex
mutex for protection
void SetUpperLimitPosition(const uint32_t &_channel, const FLOAT &_pos)
Set position of an upper limit line.
~D2HistogramRender()
Discard device resources.
ID2D1SolidColorBrush * brushred
Direct2D red brush.