Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Below is In our forum post, we have sample code on how to create buttons using HPS API. Sample code can be tested using hps_mfc_sandbox. Please replace the following functions in CHPSView.cpp.
Steps:
1. Build and run hps_mfc_sandbox with sample code
2. Click on UserCode3 (setup buttons)
3. Load any model
4. Click on button to activate corresponding operator
Notes:

We have an overload function to SetSubwindow(Rectangle const & position, IntRectangle const & offsets, Subwindow::Type type) which will make your buttons remain the same size.

The position values are still given as [-1,1] floats relative to the parent, but the offsets are pixel values relative to those. 

Position gives a fractional location (where you measure from) and offset moves a fixed distance from that.For instance, you could make a subwindow that is always inset 25 pixels from its parent by specifying (-1,1,-1,1) & (25,-25,25,-25).

A 100x80 box stuck to the top-left corner would be (-1,-1,1,1) & (0, 100,-80,0).

A 10 pixel high along the top middle third of the parent would be (-0.333,0.333,1,1) & (0,0,-10,0).

Let's say the two boxes are 50x50, 75 pixels from the bottom, and they are a bit left of center (let's say centered about x = -0.1),  one box could be (-0.1,-0.1,-1,-1) & (-50,0,75,126) and the other (-0.1,-0.1,-1,-1) & (0, 50, 75,125).

...

.

...

Code Block
void CHPSView::OnLButtonDown(UINT nFlags, CPoint point)
{
	Point pixelPoint(point.x, point.y, 0);
	Point windowPoint;

	GetCanvas().GetWindowKey().ConvertCoordinate(HPS::Coordinate::Space::Pixel, pixelPoint, HPS::Coordinate::Space::Window, windowPoint);

	GetCanvas().GetWindowKey().GetSelectionOptionsControl().SetLevel(HPS::Selection::Level::Entity); // choosing entity-level selection
	GetCanvas().GetWindowKey().GetSelectionOptionsControl().SetProximity(0.01f);
	GetCanvas().GetWindowKey().GetSelectionOptionsControl().SetAlgorithm(HPS::Selection::Algorithm::Analytic);

    

	HPS::SelectionResults selectionResults;
	size_t numSelectedItems = GetCanvas().GetWindowKey().GetSelectionControl().SelectByPoint(  // this is the actual selection call
		windowPoint,        // the endpoint of the ray, typically the camera location
		selectionResults);
		
    // Check if button was button selected
	HPS::SelectionResultsIterator iter = selectionResults.GetIterator();
	while (iter.IsValid())
	{
		HPS::SelectionItem selectionItem = iter.GetItem();
		Key key;
		selectionItem.ShowSelectedItem(key); // 'key' is the HPS::Key of the selected item

		if (key.Type() == HPS::Type::ShellKey)
		{
			// do something with this key
			HPS::SegmentKey ownerSegment = key.Owner();

			if (ownerSegment.Name() == "panOperator")
			{
				GetCanvas().GetFrontView().GetOperatorControl().Pop();
				GetCanvas().GetFrontView().GetOperatorControl().Push(new HPS::PanOperator(MouseButtons::ButtonLeft()));
             
                // Highlight button 
                // Please see Highlight section for sample code.
			}

			if (ownerSegment.Name() == "zoomOperator")
			{
				GetCanvas().GetFrontView().GetOperatorControl().Pop();
				GetCanvas().GetFrontView().GetOperatorControl().Push(new HPS::ZoomOperator(MouseButtons::ButtonLeft()));
				
				// Highlight button 
                // Please see Highlight section for sample code.
			}
		}

		iter.Next();
	}


	SetCapture();
	_canvas.GetWindowKey().GetEventDispatcher().InjectEvent(
		BuildMouseEvent(HPS::MouseEvent::Action::ButtonDown, HPS::MouseButtons::ButtonLeft(), point, nFlags, 1));

	CView::OnLButtonDown(nFlags, point);
}

Image Removed