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

**URL:** <https://forum.techsoft3d.com/t/how-to-hps-how-to-create-a-legend-using-subwindows/4589>\
**Category:** HOOPS Visualize Desktop\
**Tags:** knowledge-base, how-to\
**Created:** [April 24, 2025, 11:35pm UTC](https://forum.techsoft3d.com/t/how-to-hps-how-to-create-a-legend-using-subwindows/4589 "2025-04-24T23:35:48Z")\
**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:** [April 24, 2025, 11:35pm UTC](https://forum.techsoft3d.com/t/how-to-hps-how-to-create-a-legend-using-subwindows/4589/1 "2025-04-24T23:35:48Z")

</div>

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.

```auto
     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](https://us1.discourse-cdn.com/flex020/uploads/techsoft3d/original/2X/5/50a6943a0303f44bc54ae5ba7f4635adca673a6b.gif)

Legend.hsf file :

[legend.zip](https://forum.techsoft3d.com/uploads/short-url/uLSK5C0SqPzeC2kkfXrBKgcsWv6.zip) (4.2 KB)
