Tasks/HUD.py

# Copyright 2011 Autodesk, Inc.  All rights reserved.
# Use of this software is subject to the terms of the Autodesk license agreement 
# provided at the time of installation or download, or which otherwise accompanies
# this software in either electronic or hard copy form.
#
# Script description:
# Creates a "static" FBHUDTextElement (at center) and a moving
# FBHUDTextElement (scrolling up vertically).
#
# Topic: FBHUD, FBHUDTextElement
#
from pyfbsdk import *

def HUDDisplay(HUD, event):
    HUDTextElement.Y = HUDTextElement.Y + 1
    if(HUDTextElement.Y > 100):
        HUDTextElement.Y = 0

#Init
Scene = FBSystem().Scene
System = FBSystem()
Application = FBApplication()

#Create HUD with Text Element
Application.FileNew()

HUD = FBHUD("MyHUD")
HUDTextElement = FBHUDTextElement("Center Element")
Scene.ConnectSrc(HUD)          # Connect the HUD to the scene
HUDTextElement.Content =  "HUD Element in the Center of the viewer"
HUDTextElement.X = 0
HUDTextElement.Y = 0
HUDTextElement.Scale = 2
HUDTextElement.Justification = FBHUDElementHAlignment.kFBHUDCenter
HUDTextElement.HorizontalDock = FBHUDElementHAlignment.kFBHUDCenter
HUDTextElement.VerticalDock = FBHUDElementVAlignment.kFBHUDVCenter
HUD.ConnectSrc(HUDTextElement) # Connect HUDTextElement to the HUD
Scene.Cameras[0].ConnectSrc(HUD) # Connect to Perspective camera

HUDTextElement = FBHUDTextElement("Top Element")
Scene.ConnectSrc(HUD)          # Connect the HUD to the scene
HUDTextElement.Content = "Free memory : %d MB"
HUDTextElement.X = 0
HUDTextElement.Y = 0
HUDTextElement.Scale = 2
HUDTextElement.Justification = FBHUDElementHAlignment.kFBHUDCenter
HUDTextElement.HorizontalDock = FBHUDElementHAlignment.kFBHUDCenter
HUDTextElement.VerticalDock = FBHUDElementVAlignment.kFBHUDTop
HUDTextElement.PropertyAddReferenceProperty(HUD.PropertyList.Find("FreeMemory"))
HUD.ConnectSrc(HUDTextElement) # Connect HUDTextElement to the HUD
Scene.Cameras[0].ConnectSrc(HUD) # Connect to Perspective camera

# Register for HUD Display
HUD.OnDisplay.Add(HUDDisplay)