Esempio n. 1
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. 2
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. 3
0
        void SetBounds(AxisAlignedBox2f bounds)
        {
            m_bounds = bounds;

            m_fXShift = (bounds.Min.x < 0) ? bounds.Min.x : -bounds.Min.x;
            m_fYShift = (bounds.Min.y < 0) ? bounds.Min.y : -bounds.Min.y;

            m_fScale = (bounds.Width > bounds.Height) ? bounds.Width : bounds.Height;

            m_fCellSize = m_fScale / m_nCells;
        }
Esempio n. 4
0
        // updates cockpit scaling to maintain constant size - call in OnWindowResized()
        protected virtual void constant_size_update()
        {
            AxisAlignedBox2f uiBounds    = GetOrthoViewBounds();
            AxisAlignedBox2f pixelBounds = GetPixelViewBounds_DpiIndependent();

            cur_pixel_scale = new Vector2f(
                uiBounds.Width / pixelBounds.Width,
                uiBounds.Height / pixelBounds.Height);

            const_scale = cur_pixel_scale / start_pixel_scale;
            this.RootGameObject.SetLocalScale(new Vector3f(const_scale.x, const_scale.y, 1));
        }
Esempio n. 5
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);
        }
Esempio n. 6
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);
                }
            }
        }
Esempio n. 7
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);
            }
        }
Esempio n. 8
0
        public MarchingQuads(int nSubdivisions, AxisAlignedBox2f bounds, float fIsoValue)
        {
            m_stroke = new DPolyLine2f();
            m_bounds = new AxisAlignedBox2f();

            m_nCells = nSubdivisions;
            SetBounds(bounds);

            m_cells = null;
            InitializeCells();

            m_seedPoints = new ArrayList();
            m_cellStack  = new ArrayList();

            m_bEdgeSigns = new bool[4];

            m_fIsoValue = fIsoValue;
        }
Esempio n. 9
0
        /// <summary>
        /// Returns dpi-independent pixel scaling factor. Mainly intended to be used
        /// for sizing UI elements.
        /// This function multiplies by FPlatform.PixelScaleFactor.
        /// </summary>
        public float GetPixelScale(bool bDpiIndependent = true)
        {
            AxisAlignedBox2f uiBounds    = GetOrthoViewBounds();
            AxisAlignedBox2f pixelBounds =
                (bDpiIndependent) ? GetPixelViewBounds_DpiIndependent() : GetPixelViewBounds_Absolute();
            float fScale = uiBounds.Height / pixelBounds.Height;

            // use ValidScreenDimensionRange to manipulate scale here?

            if (FPlatform.InUnityEditor())
            {
                fScale *= FPlatform.EditorPixelScaleFactor;
            }
            else
            {
                fScale *= FPlatform.PixelScaleFactor;
            }
            return(fScale);
        }
Esempio n. 10
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. 11
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?
            }
        }
Esempio n. 12
0
        /// <summary>
        /// GetOrthoViewBounds() inverse scaled by constant-size scaling factor,
        /// so corners stay at corners of screen as cockpit is scaled
        /// </summary>
        public virtual AxisAlignedBox2f GetConstantSizeOrthoViewBounds()
        {
            AxisAlignedBox2f bounds = GetOrthoViewBounds();

            return(new AxisAlignedBox2f(bounds.Center, bounds.Width * 0.5f / const_scale.x, bounds.Height * 0.5f / const_scale.y));
        }
Esempio n. 13
0
        public static Vector2f GetBoxPosition(IBoxModelElement element, BoxPosition pos)
        {
            AxisAlignedBox2f bounds = element.Bounds2D;

            return(GetBoxPosition(ref bounds, pos));
        }
        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);
        }
Esempio n. 15
0
 private void OnProviderBoundsModified(object sender)
 {
     bounds = Provider.ContainerBounds;
     FUtil.SafeSendAnyEvent(OnContainerBoundsModified, this);
 }
Esempio n. 16
0
 public BoxContainer(IContainerBoundsProvider provider)
 {
     Provider = provider;
     Provider.OnContainerBoundsModified += OnProviderBoundsModified;
     bounds = Provider.ContainerBounds;
 }
Esempio n. 17
0
 public FixedBoxModelElement(AxisAlignedBox2f b)
 {
     Box = b;
 }
Esempio n. 18
0
 public PlaneBoxRegion()
 {
     Frame      = new Frame3f(Vector3f.Zero, -Vector3f.AxisZ);
     Dimensions = new AxisAlignedBox2f(1.0f);
 }
Esempio n. 19
0
 public HUDContainer(HUDContainerProvider provider)
 {
     Provider = provider;
     Provider.OnContainerBoundsModified += OnProviderBoundsModified;
     bounds = Provider.ContainerBounds;
 }