Esempio n. 1
0
        // This returns Bounds2D-Padding. Note that Bounds2D includes local translation
        //  (ie relative to parent)
        public static FixedBoxModelElement PaddedBounds(IBoxModelElement element, float fPadding)
        {
            AxisAlignedBox2f bounds = element.Bounds2D;

            bounds.Contract(fPadding);
            return(new FixedBoxModelElement(bounds));
        }
Esempio n. 2
0
        public static AxisAlignedBox2f LocalBounds(IBoxModelElement element)
        {
            AxisAlignedBox2f bounds = element.Bounds2D;

            bounds.Translate(-bounds.Center);
            return(bounds);
        }
Esempio n. 3
0
        // This returns Bounds2D-Padding. Note that Bounds2D includes local translation
        //  (ie relative to parent)
        public static FixedBoxModelElement PaddedBounds(IBoxModelElement element, float fPadLeft, float fPadRight, float fPadBottom, float fPadTop)
        {
            AxisAlignedBox2f bounds = element.Bounds2D;

            bounds.Pad(-fPadLeft, -fPadRight, -fPadBottom, -fPadTop);
            return(new FixedBoxModelElement(bounds));
        }
Esempio n. 4
0
        void add(HUDStandardItem element, LayoutOptions options)
        {
            if (element.IsVisible == false)
            {
                element.IsVisible = true;
            }

            IBoxModelElement elemBoxModel = element as IBoxModelElement;

            childSet.Add(element);

            Func <Vector2f> pinSourceF = options.PinSourcePoint2D;

            if (pinSourceF == null)
            {
                pinSourceF = LayoutUtil.BoxPointF(elemBoxModel, BoxPosition.Center);
            }

            Func <Vector2f> pinTargetF = options.PinTargetPoint2D;

            if (pinTargetF == null)
            {
                pinTargetF = LayoutUtil.BoxPointF(Solver.Container, BoxPosition.Center);
            }

            Solver.AddLayoutItem(element, pinSourceF, pinTargetF, this.StandardDepth + options.DepthShift);
        }
Esempio n. 5
0
        // This returns element.Bounds2D re-centered at origin, ie without the local
        // translation of element. Child elements should be laid out relative to this box.
        public static FixedBoxModelElement ContentBounds(IBoxModelElement element, float fPadding)
        {
            AxisAlignedBox2f bounds = element.Bounds2D;

            bounds.Translate(-bounds.Center);
            return(new FixedBoxModelElement(bounds));
        }
Esempio n. 6
0
        // This returns Size-Padding
        public static Vector2f PaddedSize(IBoxModelElement element, float fPadding)
        {
            Vector2f size = element.Size2D;

            size -= 2 * fPadding;
            return(size);
        }
Esempio n. 7
0
        public static Vector2f GetBoxPosition(IBoxModelElement element, BoxPosition pos)
        {
            AxisAlignedBox2f bounds = element.Bounds2D;

            switch (pos)
            {
            case BoxPosition.Center: return(bounds.Center);

            case BoxPosition.BottomLeft: return(bounds.BottomLeft);

            case BoxPosition.BottomRight: return(bounds.BottomRight);

            case BoxPosition.TopRight: return(bounds.TopRight);

            case BoxPosition.TopLeft: return(bounds.TopLeft);

            case BoxPosition.CenterLeft: return(bounds.CenterLeft);

            case BoxPosition.CenterRight: return(bounds.CenterRight);

            case BoxPosition.CenterTop: return(bounds.CenterTop);

            case BoxPosition.CenterBottom: return(bounds.CenterBottom);

            default: return(bounds.Center);
            }
        }
        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);
        }
Esempio n. 9
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;
        }
Esempio n. 10
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?
                }
            }
        }
Esempio n. 11
0
        // This returns ContentBounds with a padding offset
        public static AxisAlignedBox2f PaddedContentBounds(IBoxModelElement element, float fPadding)
        {
            AxisAlignedBox2f bounds = element.Bounds2D;

            bounds.Translate(-bounds.Center);
            bounds.Contract(fPadding);
            return(bounds);
        }
Esempio n. 12
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);
        }
Esempio n. 13
0
        public static void Translate(IBoxModelElement element, Vector2f delta, float z = 0)
        {
            IElementFrame item = element as IElementFrame;
            Frame3f       f    = item.GetObjectFrame();

            f.Origin += new Vector3f(delta.x, delta.y, z);
            item.SetObjectFrame(f);
        }
Esempio n. 14
0
        public static void SetObjectPosition(IBoxModelElement element, BoxPosition elemPos,
                                             IBoxModelElement relativeTo, BoxPosition relPos,
                                             Vector2f vOffset, float z = 0)
        {
            Vector2f pos = GetBoxPosition(relativeTo, relPos);

            pos += vOffset;
            SetObjectPosition(element, elemPos, pos, z);
        }
Esempio n. 15
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);
        }
Esempio n. 16
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);
        }
Esempio n. 17
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);
        }
Esempio n. 18
0
 public static LayoutOptions PointToPoint(IBoxModelElement eFrom, BoxPosition posFrom,
                                          IBoxModelElement eTo, BoxPosition posTo, float fShiftZ = 0)
 {
     return(new LayoutOptions()
     {
         Flags = LayoutFlags.None,
         PinSourcePoint2D = BoxPointF(eFrom, posFrom),
         PinTargetPoint2D = BoxPointF(eTo, posTo),
         DepthShift = fShiftZ
     });
 }
Esempio n. 19
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);
        }
Esempio n. 20
0
        // kind of feeling like this should maybe go somewhere else...
        public static void SetObjectPosition(IBoxModelElement element, Vector2f vObjectPoint,
                                             Vector2f vTargetPoint, float z = 0)
        {
            IElementFrame item = element as IElementFrame;

            Vector2f vOffset = GetRelativeOffset(element, vObjectPoint);
            Vector2f vNewPos = vTargetPoint - vOffset;

            Frame3f f = new Frame3f(new Vector3f(vNewPos.x, vNewPos.y, z));

            item.SetObjectFrame(f);
        }
Esempio n. 21
0
        // kind of feeling like this should maybe go somewhere else...
        public static void SetObjectPosition(IBoxModelElement element, BoxPosition objectPos,
                                             Vector2f pos, float z = 0)
        {
            IElementFrame item = element as IElementFrame;

            Vector2f corner_offset = GetBoxOffset(element, objectPos);
            Vector2f new_pos       = pos - corner_offset;

            Frame3f f = new Frame3f(new Vector3f(new_pos.x, new_pos.y, z));

            item.SetObjectFrame(f);
        }
Esempio n. 22
0
        void add(HUDStandardItem element, LayoutOptions options)
        {
            if (element.IsVisible == false)
            {
                element.IsVisible = true;
            }

            IBoxModelElement elemBoxModel = element as IBoxModelElement;

            // for 2D view (but doesn't matter if we are doing a layout anyway!)
            Frame3f viewFrame = Cockpit.GetViewFrame2D();

            // with 3D view we should use this...
            //Frame3f viewFrame = Frame3f.Identity;

            element.SetObjectFrame(Frame3f.Identity);
            HUDUtil.PlaceInViewPlane(element, viewFrame);
            Cockpit.AddUIElement(element);

            Func <Vector2f> pinSourceF = options.PinSourcePoint2D;

            if (pinSourceF == null)
            {
                pinSourceF = LayoutUtil.BoxPointF(elemBoxModel, BoxPosition.Center);
            }

            Func <Vector2f> pinTargetF = options.PinTargetPoint2D;

            if (pinTargetF == null)
            {
                pinTargetF = LayoutUtil.BoxPointF(Solver.Container, BoxPosition.Center);
            }

            Solver.AddLayoutItem(element, pinSourceF, pinTargetF, this.StandardDepth + options.DepthShift);

            // if we want to shift result in its layout frame, do that via a post-transform
            if (options.FrameAxesShift != Vector3f.Zero)
            {
                Solver.AddPostTransform(element, (e) => {
                    Frame3f f = (e as IElementFrame).GetObjectFrame();
                    f.Translate(options.FrameAxesShift.x * f.X + options.FrameAxesShift.y * f.Y + options.FrameAxesShift.z * f.Z);
                    (e as IElementFrame).SetObjectFrame(f);
                });
            }


            // auto-show
            if ((options.Flags & LayoutFlags.AnimatedShow) != 0)
            {
                HUDUtil.AnimatedShow(element);
            }
        }
Esempio n. 23
0
 public static LayoutOptions PointToPointSplitXY(IBoxModelElement eFrom, BoxPosition posFrom,
                                                 IBoxModelElement eToX, BoxPosition posToX,
                                                 IBoxModelElement eToY, BoxPosition posToY,
                                                 Vector2f vToDelta, float fShiftZ = 0)
 {
     return(new LayoutOptions()
     {
         Flags = LayoutFlags.None,
         PinSourcePoint2D = BoxPointF(eFrom, posFrom),
         PinTargetPoint2D = BoxPointSplitXYF(eToX, posToX, eToY, posToY, vToDelta),
         DepthShift = fShiftZ
     });
 }
Esempio n. 24
0
        // kind of feeling like this should maybe go somewhere else...
        public static void SetObjectPosition(IBoxModelElement element, BoxPosition objectPos,
                                             Vector2f pos, float z = 0)
        {
            // [RMS] this is true for now...need to rethink though
            HUDStandardItem item = element as HUDStandardItem;

            Vector2f corner_offset = GetBoxOffset(element, objectPos);
            Vector2f new_pos       = pos - corner_offset;

            Frame3f f = new Frame3f(new Vector3f(new_pos.x, new_pos.y, z));

            item.SetObjectFrame(f);
        }
Esempio n. 25
0
        // kind of feeling like this should maybe go somewhere else...
        public static void SetObjectPosition(IBoxModelElement element, Vector2f vObjectPoint,
                                             Vector2f vTargetPoint, float z = 0)
        {
            // [RMS] this is true for now...need to rethink though
            HUDStandardItem item = element as HUDStandardItem;

            Vector2f vOffset = GetRelativeOffset(element, vObjectPoint);
            Vector2f vNewPos = vTargetPoint - vOffset;

            Frame3f f = new Frame3f(new Vector3f(vNewPos.x, vNewPos.y, z));

            item.SetObjectFrame(f);
        }
Esempio n. 26
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);
            }
        }
Esempio n. 27
0
        void add(HUDStandardItem element, LayoutOptions options)
        {
            if (element.IsVisible == false)
            {
                element.IsVisible = true;
            }

            IBoxModelElement elemBoxModel = element as IBoxModelElement;

            // for 2D view (but doesn't matter if we are doing a layout anyway!)
            Frame3f viewFrame = Cockpit.GetViewFrame2D();

            // with 3D view we should use this...
            //Frame3f viewFrame = Frame3f.Identity;

            element.SetObjectFrame(Frame3f.Identity);
            HUDUtil.PlaceInViewPlane(element, viewFrame);
            Cockpit.AddUIElement(element);

            Func <Vector2f> pinSourceF = options.PinSourcePoint2D;

            if (pinSourceF == null)
            {
                pinSourceF = LayoutUtil.BoxPointF(elemBoxModel, BoxPosition.Center);
            }

            Func <Vector2f> pinTargetF = options.PinTargetPoint2D;

            if (pinTargetF == null)
            {
                pinTargetF = LayoutUtil.BoxPointF(Solver.Container, BoxPosition.Center);
            }

            Solver.AddLayoutItem(element, pinSourceF, pinTargetF, this.StandardDepth + options.DepthShift);

            // auto-show
            if ((options.Flags & LayoutFlags.AnimatedShow) != 0)
            {
                HUDUtil.AnimatedShow(element);
            }
        }
Esempio n. 28
0
        protected override void layout_item(SceneUIElement e)
        {
            AxisAlignedBox2f box = Container.Bounds2D;

            IBoxModelElement boxElem = e as IBoxModelElement;
            IElementFrame    eFramed = e as IElementFrame;

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

                // evaluate pin constraints in 2D box space
                Vector2f SourcePos = pin.FromF();
                Vector2f PinToPos  = pin.ToF();

                // map center of object into box space
                //  note: ignores orientation!
                Frame3f  objF    = eFramed.GetObjectFrame();
                Vector2f center2 = Region.To2DCoords(objF.Origin);

                // construct new 2D position
                Vector2f vOffset = SourcePos - center2;
                Vector2f vNewPos = PinToPos - vOffset;

                // map 2D position back to 3D surface and orient object
                Frame3f frame = Region.From2DCoords(vNewPos, pin.fZ);
                eFramed.SetObjectFrame(frame);
            }
            else if (boxElem != null)
            {
                // position object at center of box region
                Frame3f frame = Region.From2DCoords(Vector2f.Zero, 0);
                eFramed.SetObjectFrame(frame);
            }
            else
            {
                // do nothing?
            }
        }
Esempio n. 29
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?
            }
        }
        protected override Vector3f layout_item(SceneUIElement e)
        {
            AxisAlignedBox2f box = Container.Bounds2D;

            IBoxModelElement boxElem = e as IBoxModelElement;
            IElementFrame    eFramed = e as IElementFrame;

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

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

                // [TODO] We have to xform the center of the object. But if we pin
                //   a corner, we want to enforce the corner position in 3D (eg on curved surf).
                //   Currently we pin the corner in 2D, but then conver that to a 2D-center
                //   and then use that position. So on curved surf, things overlap, etc

                // evaluate pin constraints in 2D box space
                Vector2f SourcePos = pin.FromF();
                Vector2f PinToPos  = pin.ToF();

                // map center of object into box space
                //  note: ignores orientation!
                //Frame3f objF = eFramed.GetObjectFrame();
                //Vector2f center2 = Region.To2DCoords(objF.Origin);
                Vector2f center2 = Vector2f.Zero;

                // construct new 2D position
                Vector2f vOffset = SourcePos - center2;
                Vector2f vNewPos = PinToPos - vOffset;
                vNewPos3 = new Vector3f(vNewPos.x, vNewPos.y, pin.fZ);

                // map 2D position back to 3D surface and orient object
                Frame3f frame = Region.From2DCoords(vNewPos, pin.fZ);
                eFramed.SetObjectFrame(frame);
            }
            else if (boxElem != null)
            {
                Vector2f vNewPos = Vector2f.Zero;
                vNewPos3 = new Vector3f(vNewPos.x, vNewPos.y, 0);

                // position object at center of box region
                Frame3f frame = Region.From2DCoords(vNewPos, 0);
                eFramed.SetObjectFrame(frame);
            }
            else
            {
                // do nothing?
            }

            if (PostTransforms.ContainsKey(e))
            {
                foreach (var xform in PostTransforms[e])
                {
                    xform(e);
                }
            }

            return(vNewPos3);
        }