# How-To (HPS C++): Create operator that render a cross-hair under the mouse cursor

**URL:** <https://forum.techsoft3d.com/t/how-to-hps-c-create-operator-that-render-a-cross-hair-under-the-mouse-cursor/5252>\
**Category:** HOOPS Visualize Desktop\
**Tags:** knowledge-base, how-to\
**Created:** [November 12, 2026, 6:10pm UTC](https://forum.techsoft3d.com/t/how-to-hps-c-create-operator-that-render-a-cross-hair-under-the-mouse-cursor/5252 "2026-11-12T18:10:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![simon](https://avatars.discourse-cdn.com/v4/letter/s/f07891/32.png) [@simon](https://forum.techsoft3d.com/u/simon)\
**Post date:** [November 12, 2026, 6:10pm UTC](https://forum.techsoft3d.com/t/how-to-hps-c-create-operator-that-render-a-cross-hair-under-the-mouse-cursor/5252/1 "2026-11-12T18:10:11Z")

</div>

Sample code is tested on hps\_mfc\_sandbox.

```auto
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);

}

```
