Sample code is tested on hps_mfc_sandbox.
class MouseCrosshairOperator : public HPS::Operator {
public:
explicit MouseCrosshairOperator(HPS::Canvas const& canvas) :
HPS::Operator(), _canvas(canvas)
{
crosshairSegment =
_canvas.GetFrontView().GetSegmentKey().Subsegment("mouse_crosshair");
_canvas.GetFrontView().GetSegmentKey().Subsegment("mouse_crosshair");
crosshairSegment.GetDrawingAttributeControl().SetOverlay(
HPS::Drawing::Overlay::Default);
crosshairSegment.GetVisualEffectsControl().SetPostProcessEffectsEnabled(false);
crosshairSegment.GetSelectabilityControl().SetEverything(false); //added
HPS::GlyphKit myGlyphKit = HPS::GlyphKit::GetDefault(HPS::Glyph::Default::Plus);
HPS::PortfolioKey myPortfolio;
// you must name the glyph so it can be referenced later
_canvas.GetPortfolioKey().DefineGlyph("crosshair", myGlyphKit);
crosshairSegment.GetMarkerAttributeControl().SetSymbol("crosshair");
HPS::Point const origin(0.0f, 0.0f, 0.0f);
markKey = crosshairSegment.Subsegment("marker").InsertMarker(origin);
crosshairSegment.GetVisibilityControl().SetMarkers(true);
crosshairSegment.GetMarkerAttributeControl().SetSize(30, HPS::Marker::SizeUnits::Points).SetSymbol("crosshair");
crosshairSegment.GetDrawingAttributeControl().SetDepthRange(0, 0.1f); // always drawn in front
}
HPS::UTF8 GetName() const override { return "MouseCrosshairOperator"; }
bool OnMouseMove(HPS::MouseState const& in_state) override
{
_canvas.Update();
HPS::Point const cursor = in_state.GetLocation();
HPS::Point markerWorld;
HPS::SprocketPath sprkPath(_canvas);
sprkPath.GetKeyPath().ConvertCoordinate(HPS::Coordinate::Space::Window, cursor, HPS::Coordinate::Space::World, markerWorld);
// Testing deleting vs modifying
if (false)
{
markKey.SetPoint(markerWorld);
}
else
{
crosshairSegment.Subsegment("marker").Flush();
crosshairSegment.Subsegment("marker").InsertMarker(markerWorld);
}
_canvas.Update();
return false;
}
private:
HPS::Canvas _canvas;
HPS::MarkerKey markKey;
HPS::SegmentKey crosshairSegment;
};
void CHPSView::OnUserCode4()
{
_canvas.GetWindowKey().GetDebuggingControl().SetResourceMonitor(true);
GetCanvas()
.GetFrontView()
.GetOperatorControl()
.Push(
new MouseCrosshairOperator(GetCanvas()),
HPS::Operator::Priority::High);
GetCanvas().Update(HPS::Window::UpdateType::Refresh);
}