0
你好我正在使用Direct2D,而我正在使用径向渐变画笔,但我被困在一个地方。C++ Direct2D径向渐变画笔
我的径向渐变画笔代码
结构SampleWindow:DesktopWindow
{
//FOr Radial Gradient Brush
ComPtr<ID2D1RadialGradientBrush> radialBrush;
void CrateDeviceResources()
{
D2D1_GRADIENT_STOP stops[] =
{
{0.0f, COLOR_WHITE},
{1.0f, COLOR_BLUE}
};
ComPtr<ID2D1GradientStopCollection> collection;
m_target->CreateGradientStopCollection(stops, _countof(stops),collection.ReleaseAndGetAddressOf());
D2D1_RADIAL_GRADIENT_BRUSH_PROPERTIES props = {};
m_target->CreateRadialGradientBrush(props,collection.Get(),radialBrush.ReleaseAndGetAddressOf());
}
void Draw()
{
auto size = m_target->GetSize();
radialBrush -> SetCenter(Point2F(size.width/2.0f, size.height/2.0f));
radialBrush -> SetRadiusX(size.width/2.0f);
radialBrush -> SetRadiusY(size.height/2.0f);
auto rect = RectF(0.0f, 0.0f, size.width, size.height);
m_target -> FillRectangle(rect,radialBrush.Get());
}
void MouseMoved(int x, int y, WPARAM)
{
auto centere = radialBrush->GetCenter();
radialBrush->SetGradientOriginOffset(Point2F(x - centere.x, y - centere.y));
Invalidate();
}
}
在功能鼠标移动时,我用这条线
auto centere = radialBrush->GetCenter();
我的计划打破它告诉我,
Access violation Exception
的DesktopWindow类代码是:
BEGIN_MSG_MAP()
MESSAGE_HANDLER(WM_PAINT, PaintHandler)
MESSAGE_HANDLER(WM_DESTROY, DestroyHandler)
MESSAGE_HANDLER(WM_SIZE, SizeHandler)
MESSAGE_HANDLER(WM_DISPLAYCHANGE, DisplayChangeHandler)
MESSAGE_HANDLER(WM_MOUSEMOVE, MouseMovedHandler)
END_MSG_MAP()
LRESULT MouseMovedHandler(UINT, WPARAM wParam, LPARAM lParam,BOOL &)
{
MouseMoved(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam),wParam);
return 0;
}
virtual void MouseMoved(int x, int y, WPARAM)
{
}
我做的mouseMoved功能虚拟的,这样我就可以在ovverride我的其他类此功能。我无法理解我在哪里做错了请纠正我在哪里应该在我的代码中进行更正。