// creates a button in the desired geometry shape public void Create() { entry = GameObjectFactory.CreateParentGO(UniqueNames.GetNext("HUDLabel")); bgMesh = new fGameObject(AppendMeshGO("background", make_background_mesh(), MaterialUtil.CreateFlatMaterialF(BackgroundColor), entry)); bgMesh.RotateD(Vector3f.AxisX, -90.0f); BoxPosition horzAlign = BoxPosition.CenterLeft; if (AlignmentHorz == HorizontalAlignment.Center) { horzAlign = BoxPosition.Center; } else if (AlignmentHorz == HorizontalAlignment.Right) { horzAlign = BoxPosition.CenterRight; } textMesh = GameObjectFactory.CreateTextMeshGO( "text", Text, TextColor, TextHeight, horzAlign, SceneGraphConfig.TextLabelZOffset); Vector2f toPos = BoxModel.GetBoxPosition(this, horzAlign); BoxModel.Translate(textMesh, Vector2f.Zero, toPos); AppendNewGO(textMesh, entry, false); }
/// <summary> /// This is very hacky. /// </summary> public static void AddDropShadow(HUDStandardItem item, Colorf color, float falloffWidth, Vector2f offset, float fZShift) { if (item is IBoxModelElement == false) { throw new Exception("HUDUtil.AddDropShadow: can only add drop shadow to IBoxModelElement"); } // [TODO] need interface that provides a HUDShape? var shape = item as IBoxModelElement; float w = shape.Size2D.x + falloffWidth; float h = shape.Size2D.y + falloffWidth; fRectangleGameObject meshGO = GameObjectFactory.CreateRectangleGO("shadow", w, h, color, false); meshGO.RotateD(Vector3f.AxisX, -90.0f); fMaterial dropMat = MaterialUtil.CreateDropShadowMaterial(color, w, h, falloffWidth); meshGO.SetMaterial(dropMat); item.AppendNewGO(meshGO, item.RootGameObject, false); BoxModel.Translate(meshGO, offset, fZShift); Vector3 posW = item.RootGameObject.PointToWorld(meshGO.GetLocalPosition()); ((Material)dropMat).SetVector("_Center", new Vector4(posW.x, posW.y, posW.z, 0)); }
// actually create GO elements, etc public void Create() { entry = GameObjectFactory.CreateParentGO(UniqueNames.GetNext("HUDPopupMessage")); bgMesh = AppendMeshGO("background", make_background_mesh(), MaterialUtil.CreateFlatMaterialF(BackgroundColor), entry); bgMesh.RotateD(Vector3f.AxisX, -90.0f); IBoxModelElement contentArea = BoxModel.PaddedBounds(this, Padding); BoxPosition titleBoxPos = BoxModel.ToPosition(TitleAlignment, VerticalAlignment.Top); titleTextMesh = (titleText == "") ? null : GameObjectFactory.CreateTextMeshGO( "title", TitleText, TextColor, TitleTextHeight, titleBoxPos, SceneGraphConfig.TextLabelZOffset); float fTitleHeight = 0; if (titleTextMesh != null) { Vector2f titleToPos = BoxModel.GetBoxPosition(contentArea, titleBoxPos); BoxModel.Translate(titleTextMesh, Vector2f.Zero, titleToPos); AppendNewGO(titleTextMesh, entry, false); fTitleHeight = TitleTextHeight; } IBoxModelElement messageArea = BoxModel.PaddedBounds(contentArea, 0, 0, 0, Padding + fTitleHeight); Vector2f textDims = messageArea.Size2D; BoxPosition textBoxPos = BoxModel.ToPosition(Alignment, VerticalAlignment.Top); textMesh = GameObjectFactory.CreateTextAreaGO( "message", Text, TextColor, TextHeight, textDims, Alignment, textBoxPos, SceneGraphConfig.TextLabelZOffset); Vector2f textToPos = BoxModel.GetBoxPosition(messageArea, textBoxPos); BoxModel.Translate(textMesh, Vector2f.Zero, textToPos); AppendNewGO(textMesh, entry, false); if (EnableClickToDismiss) { footerTextMesh = GameObjectFactory.CreateTextMeshGO( "footer", DismissText, DismissTextColor, TextHeight * 0.5f, BoxPosition.CenterBottom, SceneGraphConfig.TextLabelZOffset); BoxModel.Translate(footerTextMesh, Vector2f.Zero, BoxModel.GetBoxPosition(contentArea, BoxPosition.CenterBottom)); AppendNewGO(footerTextMesh, entry, false); } }
// creates a button in the desired geometry shape public void Create() { entry = GameObjectFactory.CreateParentGO(UniqueNames.GetNext("HUDLabel")); bgMesh = AppendMeshGO("background", HUDUtil.MakeBackgroundMesh(Shape), MaterialUtil.CreateFlatMaterialF(BackgroundColor), entry); bgMesh.RotateD(Vector3f.AxisX, -90.0f); if (EnableBorder) { HUDShape borderShape = Shape; borderShape.Radius += BorderWidth; borderShape.Height += 2 * BorderWidth; borderShape.Width += 2 * BorderWidth; border = AppendMeshGO("border", HUDUtil.MakeBackgroundMesh(borderShape), MaterialUtil.CreateFlatMaterialF(BorderColor), entry); border.RotateD(Vector3f.AxisX, -90.0f); border.Translate(-0.001f * Vector3f.AxisY, true); } BoxPosition horzAlign = BoxPosition.CenterLeft; if (AlignmentHorz == HorizontalAlignment.Center) { horzAlign = BoxPosition.Center; } else if (AlignmentHorz == HorizontalAlignment.Right) { horzAlign = BoxPosition.CenterRight; } textMesh = GameObjectFactory.CreateTextMeshGO( "text", Text, TextColor, TextHeight, horzAlign, SceneGraphConfig.TextLabelZOffset); textMesh.TextObject.SetFixedWidth(Shape.Width); textMesh.TextObject.SetOverflowMode(TextOverflowMode.Ellipses); Vector2f toPos = BoxModel.GetBoxPosition(this, horzAlign); BoxModel.Translate(textMesh, Vector2f.Zero, toPos); AppendNewGO(textMesh, entry, false); MaterialUtil.DisableShadows(RootGameObject); }
protected virtual void update_ticks() { if (TicksAreVisible == false) { foreach (var tick in ticks) { tick.go.SetVisible(false); } return; } TickMaterial.color = tickColor; Vector2f tickSize = TickDimensions; AxisAlignedBox2f localBounds = BoxModel.LocalBounds(this); // create extra ticks if we need them if (tick_count > tick_count_cache) { while (ticks.Count < tick_count) { TickGO tick = new TickGO(); tick.go = create_tick_go(tickSize, TickMaterial); AppendNewGO(tick.go, rootGO, false); BoxModel.Translate(tick.go, Vector2f.Zero, localBounds.CenterLeft, -Height * 0.01f); ticks.Add(tick); } tick_count_cache = tick_count; } // align and show/hide ticks for (int i = 0; i < ticks.Count; ++i) { fGameObject go = ticks[i].go; if (i < tick_count) { float t = (float)i / (float)(tick_count - 1); update_tick_go(i, go, tickSize, t); BoxModel.MoveTo(go, localBounds.CenterLeft, -Height * 0.01f); BoxModel.Translate(go, new Vector2f(t * Width, 0)); go.SetVisible(true); } else { ticks[i].go.SetVisible(false); } } }
protected void update_labels() { AxisAlignedBox2f localBounds = BoxModel.LocalBounds(this); foreach (var pair in Labels) { float t = (float)(pair.Key); PositionLabel labelinfo = pair.Value; if (labelinfo.go == null) { BoxPosition boxPos = BoxPosition.CenterTop; if (labelinfo.position == LabelPositionType.CenteredAbove) { boxPos = BoxPosition.CenterBottom; } else if (labelinfo.position == LabelPositionType.BelowLeftAligned) { boxPos = BoxPosition.TopLeft; } else if (labelinfo.position == LabelPositionType.BelowRightAligned) { boxPos = BoxPosition.TopRight; } labelinfo.go = GameObjectFactory.CreateTextMeshGO("sliderlabel_" + labelinfo.text, labelinfo.text, labelinfo.color, LabelTextHeight, boxPos); AppendNewGO(labelinfo.go, rootGO, false); } if (labelinfo.position == LabelPositionType.CenteredBelow || labelinfo.position == LabelPositionType.BelowLeftAligned || labelinfo.position == LabelPositionType.BelowRightAligned) { BoxModel.MoveTo(labelinfo.go, localBounds.BottomLeft, -Height * 0.01f); } else if (labelinfo.position == LabelPositionType.CenteredAbove) { BoxModel.MoveTo(labelinfo.go, localBounds.TopLeft, -Height * 0.01f); } else { throw new NotSupportedException("HUDSliderBase.update_labels : unhandled LabelPositionType"); } BoxModel.Translate(labelinfo.go, new Vector2f(t * Width, 0) + labelinfo.offset); } }
public override void PreRender() { if (IsEditing) { // cursor blinks every 0.5s float dt = FPlatform.RealTime() - start_active_time; cursor.SetVisible((int)(2 * dt) % 2 == 0); // DO NOT DO THIS EVERY FRAME!!! BoxModel.MoveTo(cursor, this.Bounds2D.CenterLeft, -Height * 0.1f); Vector2f cursorPos = textMesh.TextObject.GetCursorPosition(cursor_position); BoxModel.Translate(cursor, cursorPos); } else { cursor.SetVisible(false); } }
/// <summary> /// This is very hacky. /// </summary> public static void AddDropShadow(HUDStandardItem item, Cockpit cockpit, Colorf color, float falloffWidthPx, Vector2f offset, float fZShift, bool bTrackCockpitScaling = true) { if (item is IBoxModelElement == false) { throw new Exception("HUDUtil.AddDropShadow: can only add drop shadow to IBoxModelElement"); } float falloffWidth = falloffWidthPx * cockpit.GetPixelScale(); // [TODO] need interface that provides a HUDShape? var shape = item as IBoxModelElement; float w = shape.Size2D.x + falloffWidth; float h = shape.Size2D.y + falloffWidth; fRectangleGameObject meshGO = GameObjectFactory.CreateRectangleGO("shadow", w, h, color, false); meshGO.RotateD(Vector3f.AxisX, -90.0f); fMaterial dropMat = MaterialUtil.CreateDropShadowMaterial(color, w, h, falloffWidth); meshGO.SetMaterial(dropMat); item.AppendNewGO(meshGO, item.RootGameObject, false); BoxModel.Translate(meshGO, offset, fZShift); if (bTrackCockpitScaling) { PreRenderBehavior pb = meshGO.AddComponent <PreRenderBehavior>(); pb.ParentFGO = meshGO; pb.AddAction(() => { Vector3f posW = item.RootGameObject.PointToWorld(meshGO.GetLocalPosition()); ((Material)dropMat).SetVector("_Center", new Vector4(posW.x, posW.y, posW.z, 0)); float curWidth = falloffWidthPx * cockpit.GetPixelScale(); Vector2f origSize = shape.Size2D + falloffWidth * Vector2f.One; Vector2f size = cockpit.GetScaledDimensions(origSize); float ww = size.x; float hh = size.y; ((Material)dropMat).SetVector("_Extents", new Vector4(ww / 2, hh / 2, 0, 0)); float newWidth = falloffWidthPx * cockpit.GetPixelScale(); ((Material)dropMat).SetFloat("_FalloffWidth", newWidth); }); } }
void UpdateText() { if (button == null) { return; } if (labelMesh == null && text.Length > 0) { labelMesh = GameObjectFactory.CreateTextMeshGO( "label", Text, TextColor, TextHeight, BoxPosition.Center, SceneGraphConfig.TextLabelZOffset); BoxModel.Translate(labelMesh, Vector2f.Zero, this.Bounds2D.Center); AppendNewGO(labelMesh, button, false); } if (labelMesh != null) { labelMesh.SetColor(TextColor); labelMesh.SetText(Text); } }
// creates a button in the desired geometry shape public void Create() { entry = new GameObject(UniqueNames.GetNext("HUDTextEntry")); Mesh mesh = MeshGenerators.CreateTrivialRect(Width, Height, MeshGenerators.UVRegionType.FullUVSquare); backgroundMaterial = MaterialUtil.CreateFlatMaterialF(BackgroundColor); activeBackgroundMaterial = MaterialUtil.CreateFlatMaterialF(ActiveBackgroundColor); bgMesh = AppendMeshGO("background", mesh, backgroundMaterial, entry); bgMesh.transform.Rotate(Vector3.right, -90.0f); // ?? BoxPosition horzAlign = BoxPosition.CenterLeft; if (AlignmentHorz == HorizontalAlignment.Center) { horzAlign = BoxPosition.Center; } else if (AlignmentHorz == HorizontalAlignment.Right) { horzAlign = BoxPosition.CenterRight; } textMesh = GameObjectFactory.CreateTextMeshGO( "text", Text, TextColor, TextHeight, horzAlign, SceneGraphConfig.TextLabelZOffset); Vector2f toPos = BoxModel.GetBoxPosition(this, horzAlign); BoxModel.Translate(textMesh, Vector2f.Zero, toPos); AppendNewGO(textMesh, entry, false); cursor = GameObjectFactory.CreateRectangleGO("cursor", Height * 0.1f, Height * 0.8f, Colorf.VideoBlack, false); BoxModel.Translate(cursor, Vector2f.Zero, this.Bounds2D.CenterLeft, -Height * 0.1f); cursor.RotateD(Vector3f.AxisX, -90.0f); AppendNewGO(cursor, entry, false); cursor.SetVisible(false); }