STK Graphics PrimitivesSend comments on this topic.
IAgStkGraphicsScreenOverlay Interface

Description

A visible element drawn in screen space. Overlays are useful for floating logos, heads up displays, and integrating user interfaces into the 3D window.

Interfaces

CoClasses that Implement IAgStkGraphicsScreenOverlay

Example

Add overlays to a panel overlay
[C#]
IAgStkGraphicsSceneManager manager = ((IAgScenario)root.CurrentScenario).SceneManager;
IAgStkGraphicsScreenOverlayCollectionBase overlayManager = (IAgStkGraphicsScreenOverlayCollectionBase)manager.ScreenOverlays.Overlays;

IAgStkGraphicsTextureScreenOverlay overlay =
    manager.Initializers.TextureScreenOverlay.InitializeWithXYWidthHeight(0, 0,
    188, 200);
((IAgStkGraphicsOverlay)overlay).Origin = AgEStkGraphicsScreenOverlayOrigin.eStkGraphicsScreenOverlayOriginTopLeft;
((IAgStkGraphicsOverlay)overlay).Color = Color.LightSkyBlue;
((IAgStkGraphicsOverlay)overlay).Translucency = 0.7f;
((IAgStkGraphicsOverlay)overlay).BorderTranslucency = 0.3f;
((IAgStkGraphicsOverlay)overlay).BorderSize = 1;
((IAgStkGraphicsOverlay)overlay).BorderColor = Color.LightBlue;

IAgStkGraphicsTextureScreenOverlay childOverlay =
    manager.Initializers.TextureScreenOverlay.InitializeWithXYWidthHeight(
    0, 0, ((IAgStkGraphicsOverlay)overlay).Width, ((IAgStkGraphicsOverlay)overlay).Height);
((IAgStkGraphicsOverlay)childOverlay).Origin = AgEStkGraphicsScreenOverlayOrigin.eStkGraphicsScreenOverlayOriginCenter;

childOverlay.Texture = manager.Textures.LoadFromStringUri(imageFile);

//
// Create the RasterStream from the plugin the same way as in ImageDynamicCodeSnippet.cs
//
IAgStkGraphicsProjectionRasterStreamPluginActivator activator =
    manager.Initializers.ProjectionRasterStreamPluginActivator.Initialize();
IAgStkGraphicsProjectionRasterStreamPluginProxy proxy =
    activator.CreateFromDisplayName("ProjectionRasterStreamPlugin.CSharp");
Type plugin = proxy.RealPluginObject.GetType();
plugin.GetProperty("RasterPath").SetValue(proxy.RealPluginObject, rasterFile, null);

IAgStkGraphicsRasterStream rasterStream = proxy.RasterStream;
rasterStream.UpdateDelta = 0.01667;
IAgStkGraphicsRendererTexture2D texture2D = manager.Textures.FromRaster((IAgStkGraphicsRaster)rasterStream);

IAgStkGraphicsTextureScreenOverlay secondChildOverlay =
    manager.Initializers.TextureScreenOverlay.InitializeWithXYWidthHeight(0, 0,
    128, 128);
((IAgStkGraphicsOverlay)secondChildOverlay).Origin = AgEStkGraphicsScreenOverlayOrigin.eStkGraphicsScreenOverlayOriginTopRight;
((IAgStkGraphicsOverlay)secondChildOverlay).TranslationX = -36;
((IAgStkGraphicsOverlay)secondChildOverlay).TranslationY = -18;
((IAgStkGraphicsOverlay)secondChildOverlay).ClipToParent = false;
secondChildOverlay.Texture = texture2D;

overlayManager.Add((IAgStkGraphicsScreenOverlay)overlay);

IAgStkGraphicsScreenOverlayCollectionBase parentOverlayManager = ((IAgStkGraphicsOverlay)overlay).Overlays as IAgStkGraphicsScreenOverlayCollectionBase;
parentOverlayManager.Add((IAgStkGraphicsScreenOverlay)childOverlay);

IAgStkGraphicsScreenOverlayCollectionBase childOverlayManager = ((IAgStkGraphicsOverlay)childOverlay).Overlays as IAgStkGraphicsScreenOverlayCollectionBase;
childOverlayManager.Add((IAgStkGraphicsScreenOverlay)secondChildOverlay);
Write text to a texture overlay
[C#]
IAgStkGraphicsSceneManager manager = ((IAgScenario)root.CurrentScenario).SceneManager;
IAgStkGraphicsScreenOverlayCollectionBase overlayManager = (IAgStkGraphicsScreenOverlayCollectionBase)manager.ScreenOverlays.Overlays;
Font font = new Font("Arial", 12, FontStyle.Bold);
string text = "STK Engine\nAnalytical Graphics\nOverlays";
Size textSize = MeasureString(text, font);
Bitmap textBitmap = new Bitmap(textSize.Width, textSize.Height);
Graphics gfx = Graphics.FromImage(textBitmap);
gfx.DrawString(text, font, Brushes.White, new PointF(0, 0));

IAgStkGraphicsTextureScreenOverlay overlay =
    manager.Initializers.TextureScreenOverlay.InitializeWithXYWidthHeight(10, 10, textSize.Width, textSize.Height);
((IAgStkGraphicsOverlay)overlay).Origin = AgEStkGraphicsScreenOverlayOrigin.eStkGraphicsScreenOverlayOriginBottomLeft;

//
// Any bitmap can be written to a texture by temporarily saving the texture to disk.
//
string filePath = temporaryFile;
textBitmap.Save(filePath);
overlay.Texture = manager.Textures.LoadFromStringUri(filePath);
System.IO.File.Delete(filePath); // The temporary file is not longer required and can be deleted
overlay.TextureFilter = manager.Initializers.TextureFilter2D.NearestClampToEdge;

overlayManager.Add((IAgStkGraphicsScreenOverlay)overlay);
Add a company logo with a texture overlay
[C#]
IAgStkGraphicsSceneManager manager = ((IAgScenario)root.CurrentScenario).SceneManager;
IAgStkGraphicsScreenOverlayCollectionBase overlayManager = (IAgStkGraphicsScreenOverlayCollectionBase)manager.ScreenOverlays.Overlays;

IAgStkGraphicsRendererTexture2D texture2D = manager.Textures.LoadFromStringUri(
    imageFile);

IAgStkGraphicsTextureScreenOverlay overlay = manager.Initializers.TextureScreenOverlay.InitializeWithXYWidthHeight(
    10, 0,
    texture2D.Template.Width / 2,
    texture2D.Template.Height / 2);
((IAgStkGraphicsOverlay)overlay).Translucency = 0.1f;
((IAgStkGraphicsOverlay)overlay).Origin = AgEStkGraphicsScreenOverlayOrigin.eStkGraphicsScreenOverlayOriginCenterRight;
overlay.Texture = texture2D;

overlayManager.Add((IAgStkGraphicsScreenOverlay)overlay);
Add a video with a texture overlay
[C#]
IAgStkGraphicsSceneManager manager = ((IAgScenario)root.CurrentScenario).SceneManager;
IAgStkGraphicsScreenOverlayCollectionBase overlayManager = (IAgStkGraphicsScreenOverlayCollectionBase)manager.ScreenOverlays.Overlays;

IAgStkGraphicsVideoStream videoStream = manager.Initializers.VideoStream.InitializeWithStringUri(videoFile);
videoStream.Playback = AgEStkGraphicsVideoPlayback.eStkGraphicsVideoPlaybackRealTime;
videoStream.Loop = true;

IAgStkGraphicsTextureScreenOverlay overlay = manager.Initializers.TextureScreenOverlay.InitializeWithXYWidthHeight(
    0, 0,
    ((IAgStkGraphicsRaster)videoStream).Width / 4,
    ((IAgStkGraphicsRaster)videoStream).Height / 4);
((IAgStkGraphicsOverlay)overlay).Translucency = 0.3f;
((IAgStkGraphicsOverlay)overlay).Origin = AgEStkGraphicsScreenOverlayOrigin.eStkGraphicsScreenOverlayOriginTopRight;
((IAgStkGraphicsOverlay)overlay).BorderSize = 1;
((IAgStkGraphicsOverlay)overlay).BorderTranslucency = 0.3f;
overlay.Texture = manager.Textures.FromRaster((IAgStkGraphicsRaster)videoStream);

overlayManager.Add((IAgStkGraphicsScreenOverlay)overlay);
Add overlays to a panel overlay
[Visual Basic .NET]
Dim manager As IAgStkGraphicsSceneManager = DirectCast(root.CurrentScenario, IAgScenario).SceneManager
Dim overlayManager As IAgStkGraphicsScreenOverlayCollectionBase = DirectCast(manager.ScreenOverlays.Overlays, IAgStkGraphicsScreenOverlayCollectionBase)

Dim overlay As IAgStkGraphicsTextureScreenOverlay = manager.Initializers.TextureScreenOverlay.InitializeWithXYWidthHeight(0, 0, 188, 200)
DirectCast(overlay, IAgStkGraphicsOverlay).Origin = AgEStkGraphicsScreenOverlayOrigin.eStkGraphicsScreenOverlayOriginTopLeft
DirectCast(overlay, IAgStkGraphicsOverlay).BorderTranslucency = 0.3F
DirectCast(overlay, IAgStkGraphicsOverlay).BorderSize = 1
DirectCast(overlay, IAgStkGraphicsOverlay).BorderColor = Color.LightBlue
DirectCast(overlay, IAgStkGraphicsOverlay).Color = Color.LightSkyBlue
DirectCast(overlay, IAgStkGraphicsOverlay).Translucency = 0.7F

Dim childOverlay As IAgStkGraphicsTextureScreenOverlay = manager.Initializers.TextureScreenOverlay.InitializeWithXYWidthHeight(0, 0, DirectCast(overlay, IAgStkGraphicsOverlay).Width, DirectCast(overlay, IAgStkGraphicsOverlay).Height)
DirectCast(childOverlay, IAgStkGraphicsOverlay).Origin = AgEStkGraphicsScreenOverlayOrigin.eStkGraphicsScreenOverlayOriginCenter

childOverlay.Texture = manager.Textures.LoadFromStringUri(imageFile)

'
' Create the RasterStream from the plugin the same way as in ImageDynamicCodeSnippet.cs
'
Dim activator As IAgStkGraphicsProjectionRasterStreamPluginActivator = manager.Initializers.ProjectionRasterStreamPluginActivator.Initialize()
Dim proxy As IAgStkGraphicsProjectionRasterStreamPluginProxy = activator.CreateFromDisplayName("ProjectionRasterStreamPlugin.VBNET")
Dim plugin As Type = proxy.RealPluginObject.[GetType]()
plugin.GetProperty("RasterPath").SetValue(proxy.RealPluginObject, rasterFile, Nothing)

Dim rasterStream As IAgStkGraphicsRasterStream = proxy.RasterStream
rasterStream.UpdateDelta = 0.01667
Dim texture2D As IAgStkGraphicsRendererTexture2D = manager.Textures.FromRaster(DirectCast(rasterStream, IAgStkGraphicsRaster))

Dim secondChildOverlay As IAgStkGraphicsTextureScreenOverlay = manager.Initializers.TextureScreenOverlay.InitializeWithXYWidthHeight(0, 0, 128, 128)
DirectCast(secondChildOverlay, IAgStkGraphicsOverlay).Origin = AgEStkGraphicsScreenOverlayOrigin.eStkGraphicsScreenOverlayOriginTopRight
DirectCast(secondChildOverlay, IAgStkGraphicsOverlay).TranslationX = -36
DirectCast(secondChildOverlay, IAgStkGraphicsOverlay).TranslationY = -18
DirectCast(secondChildOverlay, IAgStkGraphicsOverlay).ClipToParent = False
secondChildOverlay.Texture = texture2D

overlayManager.Add(DirectCast(overlay, IAgStkGraphicsScreenOverlay))

Dim parentOverlayManager As IAgStkGraphicsScreenOverlayCollectionBase = TryCast(DirectCast(overlay, IAgStkGraphicsOverlay).Overlays, IAgStkGraphicsScreenOverlayCollectionBase)
parentOverlayManager.Add(DirectCast(childOverlay, IAgStkGraphicsScreenOverlay))

Dim childOverlayManager As IAgStkGraphicsScreenOverlayCollectionBase = TryCast(DirectCast(childOverlay, IAgStkGraphicsOverlay).Overlays, IAgStkGraphicsScreenOverlayCollectionBase)
childOverlayManager.Add(DirectCast(secondChildOverlay, IAgStkGraphicsScreenOverlay))

Write text to a texture overlay
[Visual Basic .NET]
Dim manager As IAgStkGraphicsSceneManager = DirectCast(root.CurrentScenario, IAgScenario).SceneManager
Dim overlayManager As IAgStkGraphicsScreenOverlayCollectionBase = DirectCast(manager.ScreenOverlays.Overlays, IAgStkGraphicsScreenOverlayCollectionBase)

Dim font As New Font("Arial", 12, CType(FontStyle.Bold, System.Drawing.FontStyle))
Dim text As String = "Insight3D" & vbLf & "Analytical Graphics" & vbLf & "Overlays"
Dim textSize As Size = MeasureString(text, font)
Dim textBitmap As New Bitmap(textSize.Width, textSize.Height)
Dim gfx As Graphics = Graphics.FromImage(textBitmap)
gfx.DrawString(text, font, Brushes.White, New PointF(0, 0))

Dim overlay As IAgStkGraphicsTextureScreenOverlay = manager.Initializers.TextureScreenOverlay.InitializeWithXYWidthHeight(10, 10, textSize.Width, textSize.Height)
DirectCast(overlay, IAgStkGraphicsOverlay).Origin = AgEStkGraphicsScreenOverlayOrigin.eStkGraphicsScreenOverlayOriginBottomLeft

'
' Any bitmap can be written to a texture by temporarily saving the texture to disk.
'
Dim filePath As String = temporaryFile
textBitmap.Save(filePath)
overlay.Texture = manager.Textures.LoadFromStringUri(filePath)
' The temporary file is no longer required and can be deleted
System.IO.File.Delete(filePath)

overlay.TextureFilter = manager.Initializers.TextureFilter2D.NearestClampToEdge

overlayManager.Add(DirectCast(overlay, IAgStkGraphicsScreenOverlay))
Add a company logo with a texture overlay
[Visual Basic .NET]
Dim manager As IAgStkGraphicsSceneManager = DirectCast(root.CurrentScenario, IAgScenario).SceneManager
Dim overlayManager As IAgStkGraphicsScreenOverlayCollectionBase = DirectCast(manager.ScreenOverlays.Overlays, IAgStkGraphicsScreenOverlayCollectionBase)

Dim texture2D As IAgStkGraphicsRendererTexture2D = manager.Textures.LoadFromStringUri( _
    imageFile)

Dim overlay As IAgStkGraphicsTextureScreenOverlay = manager.Initializers.TextureScreenOverlay.InitializeWithXYWidthHeight(10, 0, texture2D.Template.Width / 2, texture2D.Template.Height / 2)
DirectCast(overlay, IAgStkGraphicsOverlay).X = 10
DirectCast(overlay, IAgStkGraphicsOverlay).XUnit = AgEStkGraphicsScreenOverlayUnit.eStkGraphicsScreenOverlayUnitPixels
DirectCast(overlay, IAgStkGraphicsOverlay).Translucency = 0.1F
DirectCast(overlay, IAgStkGraphicsOverlay).Origin = AgEStkGraphicsScreenOverlayOrigin.eStkGraphicsScreenOverlayOriginBottomRight
overlay.Texture = texture2D

overlayManager.Add(DirectCast(overlay, IAgStkGraphicsScreenOverlay))
Add a video with a texture overlay
[Visual Basic .NET]
Dim manager As IAgStkGraphicsSceneManager = DirectCast(root.CurrentScenario, IAgScenario).SceneManager
Dim overlayManager As IAgStkGraphicsScreenOverlayCollectionBase = DirectCast(manager.ScreenOverlays.Overlays, IAgStkGraphicsScreenOverlayCollectionBase)

Dim videoStream As IAgStkGraphicsVideoStream = manager.Initializers.VideoStream.InitializeWithStringUri(videoFile)
videoStream.Playback = AgEStkGraphicsVideoPlayback.eStkGraphicsVideoPlaybackRealTime
videoStream.[Loop] = True

Dim overlay As IAgStkGraphicsTextureScreenOverlay = manager.Initializers.TextureScreenOverlay.InitializeWithXYWidthHeight(0, 0, DirectCast(videoStream, IAgStkGraphicsRaster).Width / 4, DirectCast(videoStream, IAgStkGraphicsRaster).Height / 4)
DirectCast(overlay, IAgStkGraphicsOverlay).BorderSize = 1
DirectCast(overlay, IAgStkGraphicsOverlay).BorderTranslucency = 0.3F
DirectCast(overlay, IAgStkGraphicsOverlay).Translucency = 0.3F
DirectCast(overlay, IAgStkGraphicsOverlay).Origin = AgEStkGraphicsScreenOverlayOrigin.eStkGraphicsScreenOverlayOriginTopRight
overlay.Texture = manager.Textures.FromRaster(DirectCast(videoStream, IAgStkGraphicsRaster))

overlayManager.Add(DirectCast(overlay, IAgStkGraphicsScreenOverlay))

See Also

© 2024 Analytical Graphics, Inc. All Rights Reserved.