예제 #1
0
        public override void RecomputeLayout()
        {
            AxisAlignedBox2f box = container.Bounds2D;

            foreach (SceneUIElement e in LayoutItems)
            {
                IBoxModelElement boxElem = e as IBoxModelElement;
                if (PinConstraints.ContainsKey(e))
                {
                    Pin pin = PinConstraints[e];

                    Vector2f SourcePos = pin.FromF();
                    Vector2f PinToPos  = pin.ToF();
                    BoxModel.SetObjectPosition(boxElem, SourcePos, PinToPos, pin.fZ);
                }
                else if (boxElem != null)
                {
                    BoxModel.SetObjectPosition(boxElem, BoxPosition.Center, box.Center, 0);
                }
                else
                {
                    // do nothing?
                }
            }
        }
        protected override Vector3f layout_item(SceneUIElement e)
        {
            AxisAlignedBox2f box = Container.Bounds2D;

            Vector3f vNewPos3 = Vector3f.Zero;   // 2.5d center coordinate

            IBoxModelElement boxElem = e as IBoxModelElement;

            if (PinConstraints.ContainsKey(e))
            {
                Pin pin = PinConstraints[e];

                Vector2f SourcePos = pin.FromF();
                Vector2f PinToPos  = pin.ToF();
                vNewPos3 = BoxModel.SetObjectPosition(boxElem, SourcePos, PinToPos, pin.fZ);
            }
            else if (boxElem != null)
            {
                vNewPos3 = BoxModel.SetObjectPosition(boxElem, BoxPosition.Center, box.Center, 0);
            }
            else
            {
                // do nothing?
            }

            return(vNewPos3);
        }
예제 #3
0
        // 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);
        }
예제 #4
0
        void update_layout()
        {
            AxisAlignedBox2f contentBounds = BoxModel.PaddedContentBounds(this, Padding);
            Vector2f         insertPos     = contentBounds.TopLeft;

            int N = ListItems.Count;

            for (int i = 0; i < N; ++i)
            {
                IBoxModelElement boxelem = ListItems[i] as IBoxModelElement;
                if (ListItems[i].IsVisible == false)
                {
                    BoxModel.SetObjectPosition(boxelem, BoxPosition.TopLeft, contentBounds.TopLeft);
                    continue;
                }

                BoxModel.SetObjectPosition(boxelem, BoxPosition.TopLeft, insertPos);

                if (Direction == ListDirection.Vertical)
                {
                    insertPos.y -= boxelem.Size2D.y + Spacing;
                }
                else
                {
                    insertPos.x += boxelem.Size2D.x + Spacing;
                }
            }

            is_layout_valid = true;
        }
예제 #5
0
        /// <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));
        }
예제 #6
0
        /// <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);
        }
예제 #7
0
        /// <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);
        }
예제 #8
0
        /// <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);
        }
예제 #9
0
        /// <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);
        }
예제 #10
0
        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);
            }
        }
예제 #11
0
        /// <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);
        }
예제 #12
0
        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);
        }
예제 #13
0
        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);
        }
예제 #14
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);
            }
        }
예제 #15
0
        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);
                }
            }
        }
예제 #16
0
        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);
            }
        }
예제 #17
0
        // 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);
        }
예제 #18
0
        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);
            }
        }
예제 #19
0
        /// <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);
                });
            }
        }
예제 #20
0
        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);
            }
        }
예제 #21
0
        protected override void layout_item(SceneUIElement e)
        {
            AxisAlignedBox2f box = Container.Bounds2D;

            IBoxModelElement boxElem = e as IBoxModelElement;

            if (PinConstraints.ContainsKey(e))
            {
                Pin pin = PinConstraints[e];

                Vector2f SourcePos = pin.FromF();
                Vector2f PinToPos  = pin.ToF();
                BoxModel.SetObjectPosition(boxElem, SourcePos, PinToPos, pin.fZ);
            }
            else if (boxElem != null)
            {
                BoxModel.SetObjectPosition(boxElem, BoxPosition.Center, box.Center, 0);
            }
            else
            {
                // do nothing?
            }
        }
예제 #22
0
        // 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);
        }
예제 #23
0
        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;
        }
예제 #24
0
        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;
        }
예제 #25
0
        public override void Create()
        {
            base.Create();

            HUDElementLayout layout          = new HUDElementLayout(this, new HUDPanelContentBox(this), this.Children);
            float            fZ              = -0.01f;
            Vector2f         vertFieldOffset = -this.Padding * Vector2f.AxisY;

            background = new HUDShapeElement()
            {
                Shape = BackgroundShapeF(this.Width, this.Height),
                Color = this.BackgroundColor, IsInteractive = false
            };
            background.Create();
            background.Name = "background";
            layout.Add(background, new LayoutOptions()
            {
                Flags            = LayoutFlags.None,
                PinSourcePoint2D = LayoutUtil.BoxPointF(background, BoxPosition.Center),
                PinTargetPoint2D = LayoutUtil.BoxPointF(layout.BoxElement, BoxPosition.Center)
            });


            header_label = new HUDLabel(this.PaddedWidth, HeaderStyle.TextHeight, HeaderStyle)
            {
                Text = TitleText, IsInteractive = false
            };
            header_label.Create();
            header_label.Name = "header_label";
            BoxPosition headerBoxPos = BoxModel.ToPosition(HeaderStyle.AlignmentHorz, VerticalAlignment.Top);

            layout.Add(header_label,
                       LayoutUtil.PointToPoint(header_label, headerBoxPos, layout.BoxElement, headerBoxPos, fZ));


            float message_height = this.PaddedHeight - HeaderStyle.TextHeight - ButtonStyle.Height;

            message_area = new HUDMultiLineLabel(this.PaddedWidth, message_height, MessageStyle)
            {
                Text = MessageText, IsInteractive = false
            };
            message_area.Create();
            message_area.Name = "message_area";
            BoxPosition messageAreaBoxPos = BoxModel.ToPosition(MessageStyle.AlignmentHorz, VerticalAlignment.Top);

            layout.Add(message_area,
                       LayoutUtil.PointToPoint(message_area, messageAreaBoxPos, header_label, BoxModel.ToBottom(headerBoxPos), vertFieldOffset, fZ));


            IBoxModelElement prev      = layout.BoxElement;
            BoxPosition      prevPos   = BoxPosition.BottomRight;
            Vector2f         prevShift = Vector2f.Zero;

            for (int i = buttons.Count - 1; i >= 0; --i)
            {
                buttons[i].Create();
                buttons[i].Name = buttons[i].Text;
                layout.Add(buttons[i],
                           LayoutUtil.PointToPoint(buttons[i], BoxPosition.BottomRight, prev, prevPos, prevShift, fZ));
                prev      = buttons[i];
                prevPos   = BoxPosition.BottomLeft;
                prevShift = -Padding * Vector2f.AxisX;
            }
        }