// 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> /// constructs a Func that returns a 2D point + 2D offset /// </summary> public static Func <Vector2f> BoxPointF(IBoxModelElement element, BoxPosition pos, Vector2f vDelta) { Func <Vector2f> f = () => { return(BoxModel.GetBoxPosition(element, pos) + vDelta); }; return(f); }
/// <summary> /// constructs a Func that returns a 2D point /// </summary> public static Func <Vector2f> BoxPointInterpF(IBoxModelElement element, BoxPosition pos1, BoxPosition pos2, float alpha) { Func <Vector2f> f = () => { Vector2f p1 = BoxModel.GetBoxPosition(element, pos1); Vector2f p2 = BoxModel.GetBoxPosition(element, pos2); return(Vector2f.Lerp(p1, p2, alpha)); }; return(f); }
/// <summary> /// Constructs func that returns 2D point in origin-centered box (rather than current position) /// </summary> public static Func <Vector2f> LocalBoxPointF(IBoxModelElement element, BoxPosition pos) { Func <Vector2f> f = () => { Vector2f size = element.Size2D; AxisAlignedBox2f box = new AxisAlignedBox2f(Vector2f.Zero, size.x * 0.5f, size.y * 0.5f); return(BoxModel.GetBoxPosition(ref box, pos)); }; return(f); }
/// <summary> /// constructs a Func that returns a 2D point /// </summary> public static Func <Vector2f> BoxPointSplitXYF(IBoxModelElement elementX, BoxPosition posX, IBoxModelElement elementY, BoxPosition posY, Vector2f vDelta) { Func <Vector2f> f = () => { Vector2f x = BoxModel.GetBoxPosition(elementX, posX); Vector2f y = BoxModel.GetBoxPosition(elementY, posY); return(new Vector2f(x.x + vDelta.x, y.y + vDelta.y)); }; return(f); }
void update_layout() { FixedBoxModelElement frameBounds = BoxModel.PaddedBounds(this, Padding); Vector2f topLeft = BoxModel.GetBoxPosition(frameBounds, BoxPosition.TopLeft); float fZ = -0.01f * Width; if (ParametersList != null) { BoxModel.SetObjectPosition(ParametersList, BoxPosition.TopLeft, topLeft, fZ); } }
/// <summary> /// constructs func that returns box point in 2D layout space of the passed solver /// (eg if laying out on a 3D plane, for example) /// </summary> public static Func <Vector2f> InLayoutSpaceBoxPointF(IBoxModelElement element, BoxPosition pos, PinnedBoxesLayoutSolver solver, Vector2f vDelta) { Func <Vector2f> f = () => { Vector2f solverPos = solver.GetLayoutCenter(element as SceneUIElement); Vector2f size = element.Size2D; AxisAlignedBox2f box = new AxisAlignedBox2f(solverPos, size.x * 0.5f, size.y * 0.5f); return(BoxModel.GetBoxPosition(ref box, pos) + vDelta); }; return(f); }
protected override void update_layout() { base.update_layout(); FixedBoxModelElement contentBounds = BoxModel.PaddedContentBounds(this, Padding); Vector2f topLeft = BoxModel.GetBoxPosition(contentBounds, BoxPosition.TopLeft); float fZ = 0.05f * Width; Background.Shape = new HUDShape(HUDShapeType.Rectangle, this.VisibleListWidth, this.VisibleListHeight); BoxModel.SetObjectPosition(Background, BoxPosition.TopLeft, topLeft, fZ); }
public static void PositionRelative2D(GameObject setGO, BoxPosition setBoxPos, GameObject relativeToGO, BoxPosition relBoxPos, Vector2f offset) { RectTransform setRectT = setGO.GetComponent <RectTransform>(); AxisAlignedBox2f setBox = GetBounds2D(setRectT); Vector2f fromPos = BoxModel.GetBoxPosition(ref setBox, setBoxPos); AxisAlignedBox2f relBox = GetBounds2D(relativeToGO); Vector2f toPos = BoxModel.GetBoxPosition(ref relBox, relBoxPos); Vector2f dv = toPos - fromPos + offset; Translate(setRectT, dv); }
// 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); }
// 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); }
protected virtual void update_layout() { FixedBoxModelElement contentBounds = BoxModel.PaddedContentBounds(this, Padding); Vector2f topLeft = BoxModel.GetBoxPosition(contentBounds, BoxPosition.TopLeft); Vector2f insertPos = topLeft; int N = ListItems.Count; int visible = 0; float spaceRequired = 0; for (int i = 0; i < N; ++i) { if (ListItems[i].IsVisible) { visible++; IBoxModelElement boxelem = ListItems[i] as IBoxModelElement; spaceRequired += (Direction == ListDirection.Vertical) ? boxelem.Size2D.y : boxelem.Size2D.x; if (i < N - 1) { spaceRequired += Spacing; } } } if (Direction == ListDirection.Vertical) { VisibleListHeight = spaceRequired; VisibleListWidth = Width; } else { VisibleListHeight = Height; VisibleListWidth = spaceRequired; } BoxPosition sourcePos = BoxPosition.TopLeft; if (Direction == ListDirection.Horizontal) { if (VertAlign == VerticalAlignment.Center) { sourcePos = BoxPosition.CenterLeft; insertPos = BoxModel.GetBoxPosition(contentBounds, BoxPosition.CenterLeft); } else if (VertAlign == VerticalAlignment.Bottom) { sourcePos = BoxPosition.BottomLeft; insertPos = BoxModel.GetBoxPosition(contentBounds, BoxPosition.BottomLeft); } if (HorzAlign == HorizontalAlignment.Center) { insertPos.x += (this.Size2D.x - spaceRequired) / 2; } else if (HorzAlign == HorizontalAlignment.Right) { insertPos.x += this.Size2D.x - spaceRequired; } } else { if (HorzAlign == HorizontalAlignment.Center) { sourcePos = BoxPosition.CenterTop; insertPos = BoxModel.GetBoxPosition(contentBounds, BoxPosition.CenterTop); } else if (HorzAlign == HorizontalAlignment.Right) { sourcePos = BoxPosition.TopRight; insertPos = BoxModel.GetBoxPosition(contentBounds, BoxPosition.TopRight); } } for (int i = 0; i < N; ++i) { IBoxModelElement boxelem = ListItems[i] as IBoxModelElement; if (ListItems[i].IsVisible == false) { BoxModel.SetObjectPosition(boxelem, BoxPosition.TopLeft, topLeft); continue; } Vector2f usePos = insertPos + ItemNudge[i].xy; BoxModel.SetObjectPosition(boxelem, sourcePos, usePos, ItemNudge[i].z); if (Direction == ListDirection.Vertical) { insertPos.y -= boxelem.Size2D.y + Spacing; } else { insertPos.x += boxelem.Size2D.x + Spacing; } } is_layout_valid = true; }
protected virtual void update_layout() { int N = ListItems.Count; if (N == 0) { return; } // update initial visibility int total_visible = 0; for (int i = 0; i < ListItems.Count; ++i) { if (ListItems[i].IsVisible) { InternalVisibility[i] = VisibleState.WasVisible; total_visible++; } else { InternalVisibility[i] = VisibleState.WasHidden; } } // this is messy. does multiple things: // - computes visible dimensions / required space // - in limit-to-bounds mode, figures out how many items are visible, // and hides items that should not be visible // - ?? int Nstop = -1; int actual_visible = 0; float spaceRequired = 0; float otherDimMax = 0; float availableSpace = (Direction == ListDirection.Vertical) ? Height : Width; int li = 0; if (size_mode == SizeModes.FixedSize_LimitItemsToBounds) { // skip first scroll_index items int items_hidden = 0; while (li < N && items_hidden < scroll_index) { if (InternalVisibility[li] == VisibleState.WasVisible) { InternalVisibility[li] = VisibleState.WasVisible_SetHidden; ListItems[li].IsVisible = false; items_hidden++; } li++; } } while (li < N) { if (InternalVisibility[li] == VisibleState.WasHidden) { li++; continue; } if (Nstop >= 0) { InternalVisibility[li] = VisibleState.WasVisible_SetHidden; ListItems[li].IsVisible = false; li++; continue; } actual_visible++; IBoxModelElement boxelem = ListItems[li] as IBoxModelElement; Vector2f elemSize = boxelem.Size2D; if (Direction == ListDirection.Vertical) { spaceRequired += elemSize.y; otherDimMax = Math.Max(otherDimMax, elemSize.x); } else { spaceRequired += elemSize.x; otherDimMax = Math.Max(otherDimMax, elemSize.y); } if (size_mode == SizeModes.FixedSize_LimitItemsToBounds && spaceRequired > availableSpace) { InternalVisibility[li] = VisibleState.WasVisible_SetHidden; ListItems[li].IsVisible = false; Nstop = li; spaceRequired = availableSpace; actual_visible--; } else if (li < N - 1) { spaceRequired += Spacing; } ++li; } if (Direction == ListDirection.Vertical) { VisibleListHeight = spaceRequired; VisibleListWidth = otherDimMax; } else { VisibleListHeight = otherDimMax; VisibleListWidth = spaceRequired; } // in auto-size mode, we can auto-size now that we know dimensions if (SizeMode == SizeModes.AutoSizeToFit) { float auto_width = VisibleListWidth + 2 * Padding; float auto_height = VisibleListHeight + 2 * Padding; if (Math.Abs(Width - auto_width) > 0.001f || Math.Abs(Height - auto_height) > 0.001f) { Width = VisibleListWidth + 2 * Padding; Height = VisibleListHeight + 2 * Padding; } } // track number of items that fit in bounds scroll_items = 0; if (size_mode == SizeModes.FixedSize_LimitItemsToBounds) { scroll_items = total_visible - actual_visible; } // now do actual layout FixedBoxModelElement contentBounds = BoxModel.PaddedContentBounds(this, Padding); Vector2f topLeft = BoxModel.GetBoxPosition(contentBounds, BoxPosition.TopLeft); Vector2f insertPos = topLeft; // compute insertion position based on alignment settings BoxPosition sourcePos = BoxPosition.TopLeft; if (Direction == ListDirection.Horizontal) { if (VertAlign == VerticalAlignment.Center) { sourcePos = BoxPosition.CenterLeft; insertPos = BoxModel.GetBoxPosition(contentBounds, BoxPosition.CenterLeft); } else if (VertAlign == VerticalAlignment.Bottom) { sourcePos = BoxPosition.BottomLeft; insertPos = BoxModel.GetBoxPosition(contentBounds, BoxPosition.BottomLeft); } if (HorzAlign == HorizontalAlignment.Center) { insertPos.x += (this.Size2D.x - spaceRequired) / 2; } else if (HorzAlign == HorizontalAlignment.Right) { insertPos.x += this.Size2D.x - spaceRequired; } } else { if (HorzAlign == HorizontalAlignment.Center) { sourcePos = BoxPosition.CenterTop; insertPos = BoxModel.GetBoxPosition(contentBounds, BoxPosition.CenterTop); } else if (HorzAlign == HorizontalAlignment.Right) { sourcePos = BoxPosition.TopRight; insertPos = BoxModel.GetBoxPosition(contentBounds, BoxPosition.TopRight); } } // position visible elements for (int i = 0; i < N; ++i) { IBoxModelElement boxelem = ListItems[i] as IBoxModelElement; if (ListItems[i].IsVisible == false) { BoxModel.SetObjectPosition(boxelem, BoxPosition.TopLeft, topLeft); continue; } Vector2f usePos = insertPos + ItemNudge[i].xy; BoxModel.SetObjectPosition(boxelem, sourcePos, usePos, ItemNudge[i].z); if (Direction == ListDirection.Vertical) { insertPos.y -= boxelem.Size2D.y + Spacing; } else { insertPos.x += boxelem.Size2D.x + Spacing; } } is_layout_valid = true; }