How-To (HPS): How to create a Legend using subwindows

Below is sample code on how to create a Legend using subwindow.

When you re-size the main window, the size of the Legend does not change.

     HPS::SubwindowKit subwindowKit;

    // set a anchor point on top-left corner of the main window
	//  HPS::IntRectangle(left, right, down, up)  represent the size of your subwindow in pixels.
    subwindowKit.SetSubwindow(HPS::Rectangle(-1, -1, 1, 1), HPS::IntRectangle(0, 150, -400, 0), HPS::Subwindow::Type::Lightweight);

	


    // set a anchor point on top-right corner of the main window
    // HPS::IntRectangle(left, right, down, up)  represent the size of your subwindow in pixels.
    // subwindowKit.SetSubwindow(HPS::Rectangle(1, 1, 1, 1), HPS::IntRectangle(-150, 0, -400, 0), HPS::Subwindow::Type::Lightweight);

    // set a anchor point on bottom-left corner of the main window
    // HPS::IntRectangle(left, right, down, up)  represent the size of your subwindow in pixels.
    // subwindowKit.SetSubwindow(HPS::Rectangle(-1, -1, -1, -1), HPS::IntRectangle(0, 150, 0, 400), HPS::Subwindow::Type::Lightweight);

    // set a anchor point on bottom-right corner of the main window
    // HPS::IntRectangle(left, right, down, up)  represent the size of your subwindow in pixels.
    // subwindowKit.SetSubwindow(HPS::Rectangle(1, 1, -1, -1), HPS::IntRectangle(-150, 0, 0, 400), HPS::Subwindow::Type::Lightweight);



    HPS::SegmentKey anotherSegmentKey = GetCanvas().GetFrontView().GetSegmentKey().Down("subwindow", true);
    anotherSegmentKey.SetSubwindow(subwindowKit);
    anotherSegmentKey.GetVisibilityControl().SetEverything(false).SetEdges(true).SetText(true).SetVertices(true);


	//Read in Legend.hsf

    HPS::Stream::ImportNotifier importNotifier;

    try {
        HPS::Stream::ImportOptionsKit importOptionsKit;
        importOptionsKit.SetSegment(anotherSegmentKey); // set destination segment

        importNotifier = HPS::Stream::File::Import("D:/legend.hsf", importOptionsKit);

        // the notifier can be used to check the load progress
        float percent_complete;
        importNotifier.Status(percent_complete);

        // pauses this thread until the HSF is finished loading
        importNotifier.Wait();
    }
    catch (HPS::IOException ioe) {
        // handle exception
        throw;
    }



    // setting the camera using the CameraControl and method chaining
    anotherSegmentKey.GetCameraControl()
        .SetUpVector(Vector(0, 1, 0))
        .SetPosition(Point(0, 0, 1))
        .SetTarget(Point(0, 0, 0))
        .SetField(0.5f, 0.5f)
        .SetProjection(HPS::Camera::Projection::Orthographic);


	// Dolly camera to fit legend inside sub-window
	anotherSegmentKey.GetCameraControl().Dolly(-0.2, -0.7, 0);


    GetCanvas().UpdateWithNotifier().Wait();

**Video **

legend

Legend.hsf file :

legend.zip (4.2 KB)