Exemplo n.º 1
0
 public UBox(UDim dTop, UDim dLeft, UDim dBottom, UDim dRight)
 {
     d_top    = dTop;
     d_left   = dLeft;
     d_bottom = dBottom;
     d_right  = dRight;
 }
Exemplo n.º 2
0
        public static UBox Parse(string value, IFormatProvider formatProvider)
        {
            var matches = Parser.Matches(value);

            if (matches.Count == 1)
            {
                return(new UBox(
                           UDim.Parse(matches[0].Groups[1].Captures[0].Value, formatProvider),
                           UDim.Parse(matches[0].Groups[2].Captures[0].Value, formatProvider),
                           UDim.Parse(matches[0].Groups[3].Captures[0].Value, formatProvider),
                           UDim.Parse(matches[0].Groups[4].Captures[0].Value, formatProvider)));
            }

            throw new FormatException();
        }
Exemplo n.º 3
0
        public void Layout(Window owner)
        {
            try
            {
                var pixelArea  = _area.GetPixelRect(owner);
                var windowArea = new URect(UDim.Absolute(pixelArea.Left),
                                           UDim.Absolute(pixelArea.Top),
                                           UDim.Absolute(pixelArea.Right),
                                           UDim.Absolute(pixelArea.Bottom));

                var wnd = owner.GetChild(_name);
                wnd.SetArea(windowArea);
                wnd.NotifyScreenAreaChanged();
            }
            catch (UnknownObjectException)
            {
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Set the area that the mouse cursor is constrained to.
        /// </summary>
        /// <param name="area">
        /// Pointer to a URect object that describes the area of the display that the mouse is allowed to occupy.
        /// The given area will be clipped to the current Renderer screen area - it is never possible for the mouse
        /// to leave this area.  If this parameter is NULL, the constraint is set to the size of the current Renderer
        /// screen area.
        /// </param>
        public void SetUnifiedConstraintArea(URect?area)
        {
            var rendererArea = new Rectf(Lunatics.Mathematics.Vector2.Zero,
                                         System.GetSingleton().GetRenderer().GetDisplaySize());

            if (area.HasValue)
            {
                d_constraints = area.Value;
            }
            else
            {
                d_constraints.d_min.d_x = UDim.Relative(rendererArea.d_min.X / rendererArea.Width);
                d_constraints.d_min.d_y = UDim.Relative(rendererArea.d_min.Y / rendererArea.Height);
                d_constraints.d_max.d_x = UDim.Relative(rendererArea.d_max.X / rendererArea.Width);
                d_constraints.d_max.d_y = UDim.Relative(rendererArea.d_max.Y / rendererArea.Height);
            }

            ConstrainPosition();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Set the area that the mouse cursor is constrained to.
        /// </summary>
        /// <param name="area">
        /// Pointer to a Rect object that describes the area of the display that the mouse is allowed to occupy.
        /// The given area will be clipped to the current Renderer screen area - it is never possible for the
        /// mouse to leave this area. If this parameter is NULL, the constraint is set to the size of the current
        /// Renderer screen area.
        ///  </param>
        public void SetConstraintArea(Rectf?area)
        {
            var rendererArea = new Rectf(Vector2f.Zero, System.GetSingleton().GetRenderer().GetDisplaySize());

            if (!area.HasValue)
            {
                d_constraints.d_min.d_x = UDim.Relative(rendererArea.d_min.d_x / rendererArea.Width);
                d_constraints.d_min.d_y = UDim.Relative(rendererArea.d_min.d_y / rendererArea.Height);
                d_constraints.d_max.d_x = UDim.Relative(rendererArea.d_max.d_x / rendererArea.Width);
                d_constraints.d_max.d_y = UDim.Relative(rendererArea.d_max.d_y / rendererArea.Height);
            }
            else
            {
                var finalArea = area.Value.GetIntersection(rendererArea);

                d_constraints.d_min.d_x = UDim.Relative(finalArea.d_min.d_x / rendererArea.Width);
                d_constraints.d_min.d_y = UDim.Relative(finalArea.d_min.d_y / rendererArea.Height);
                d_constraints.d_max.d_x = UDim.Relative(finalArea.d_max.d_x / rendererArea.Width);
                d_constraints.d_max.d_y = UDim.Relative(finalArea.d_max.d_y / rendererArea.Height);
            }

            ConstrainPosition();
        }
Exemplo n.º 6
0
 /// <summary>
 /// converts given UDim to absolute value
 /// </summary>
 /// <param name="u"></param>
 /// <param name="base"></param>
 /// <param name="pixelAlign"></param>
 /// <returns></returns>
 public static float AsAbsolute(UDim u, float @base, bool pixelAlign = true)
 {
     return(pixelAlign ? AlignToPixels(@base * u.d_scale + u.d_offset) : @base *u.d_scale + u.d_offset);
 }
Exemplo n.º 7
0
 public static float AsRelative(UDim u, float @base)
 {
     return((Math.Abs(@base - 0.0f) > float.Epsilon)
                ? u.d_offset / @base + u.d_scale
                : 0.0f);
 }
Exemplo n.º 8
0
 public USize(UDim width, UDim height)
 {
     d_width  = width;
     d_height = height;
 }
Exemplo n.º 9
0
        static PropertyHelper()
        {
            RegisterFunction <Boolean>(
                x => Boolean.Parse(x),
                x => ((Boolean)x).ToString(CultureInfo.InvariantCulture));

            RegisterFunction <Byte>(
                x => Byte.Parse(x, CultureInfo.InvariantCulture),
                x => ((Byte)x).ToString(CultureInfo.InvariantCulture));

            RegisterFunction <Int16>(
                x => Int16.Parse(x, CultureInfo.InvariantCulture),
                x => ((Int16)x).ToString(CultureInfo.InvariantCulture));

            RegisterFunction <Int32>(
                x => Int32.Parse(x, CultureInfo.InvariantCulture),
                x => ((Int32)x).ToString(CultureInfo.InvariantCulture));

            RegisterFunction <Int64>(
                x => Int64.Parse(x, CultureInfo.InvariantCulture),
                x => ((Int64)x).ToString(CultureInfo.InvariantCulture));

            RegisterFunction <UInt16>(
                x => UInt16.Parse(x, CultureInfo.InvariantCulture),
                x => ((UInt16)x).ToString(CultureInfo.InvariantCulture));

            RegisterFunction <UInt32>(
                x => UInt32.Parse(x, CultureInfo.InvariantCulture),
                x => ((UInt32)x).ToString(CultureInfo.InvariantCulture));

            RegisterFunction <UInt64>(
                x => UInt64.Parse(x, CultureInfo.InvariantCulture),
                x => ((UInt64)x).ToString(CultureInfo.InvariantCulture));

            RegisterFunction <Char>(
                x => Char.Parse(x),
                x => ((Char)x).ToString(CultureInfo.InvariantCulture));

            RegisterFunction <Single>(
                x => String.IsNullOrEmpty(x) ? 0f : Single.Parse(x, CultureInfo.InvariantCulture),
                x => ((Single)x).ToString(CultureInfo.InvariantCulture));

            RegisterFunction <Double>(
                x => Double.Parse(x, CultureInfo.InvariantCulture),
                x => ((Double)x).ToString(CultureInfo.InvariantCulture));

            RegisterFunction <String>(
                x => x,
                x => (string)x);

            RegisterFunction <Colour>(
                x => Colour.Parse(x),
                x => ((Colour)x).ToString());

            RegisterFunction <ColourRect>(
                x => ColourRect.Parse(x, CultureInfo.InvariantCulture),
                x => x.ToString());

            RegisterFunction <Sizef>(
                x => Sizef.Parse(x, CultureInfo.InvariantCulture),
                x => ((Sizef)x).ToString());

            RegisterFunction <Lunatics.Mathematics.Vector3>(
                x => MathematicsEx.Vector3Parse(x, CultureInfo.InvariantCulture),
                x => MathematicsEx.ToString((Lunatics.Mathematics.Vector3)x));

            RegisterFunction <Rectf>(
                x => Rectf.Parse(x, CultureInfo.InvariantCulture),
                x => ((Rectf)x).ToString());

            RegisterFunction <Lunatics.Mathematics.Quaternion>(
                x => MathematicsEx.QuaternionParse(x, CultureInfo.InvariantCulture),
                x => MathematicsEx.ToString((Lunatics.Mathematics.Quaternion)x));

            RegisterFunction <UDim>(
                x => UDim.Parse(x, CultureInfo.InvariantCulture),
                x => ((UDim)x).ToString());

            RegisterFunction <UVector2>(
                x => UVector2.Parse(x, CultureInfo.InvariantCulture),
                x => ((UVector2)x).ToString());

            RegisterFunction <USize>(
                x => USize.Parse(x, CultureInfo.InvariantCulture),
                x => ((USize)x).ToString());

            RegisterFunction <URect>(
                x => URect.Parse(x, CultureInfo.InvariantCulture),
                x => ((URect)x).ToString());

            RegisterFunction <UBox>(
                x => UBox.Parse(x, CultureInfo.InvariantCulture),
                x => ((UBox)x).ToString());

            RegisterFunction <Image>(
                x => String.IsNullOrEmpty(x) ? null : ImageManager.GetSingleton().Get(x),
                x => x != null ? ((Image)x).GetName() : String.Empty);

            RegisterFunction <Font>(
                x => String.IsNullOrEmpty(x) ? null : FontManager.GetSingleton().Get(x),
                x => x != null ? ((Font)x).GetName() : String.Empty);

            RegisterFunction <FontMetricType>(
                x => (FontMetricType)Enum.Parse(typeof(FontMetricType), x, true),
                x => ((FontMetricType)x).ToString());

            RegisterFunction <AspectMode>(
                x => (AspectMode)Enum.Parse(typeof(AspectMode), x, true),
                x => ((AspectMode)x).ToString());

            RegisterFunction <HorizontalAlignment>(
                x =>
            {
                HorizontalAlignment value;
                if (!Enum.TryParse(x, true, out value))
                {
                    switch (x.ToLowerInvariant())
                    {
                    case "leftaligned":
                        return(HorizontalAlignment.Left);

                    case "centrealigned":
                        return(HorizontalAlignment.Centre);

                    case "rightaligned":
                        return(HorizontalAlignment.Right);
                    }
                }

                return(value);
            },
                x => ((HorizontalAlignment)x).ToString());

            RegisterFunction <VerticalAlignment>(
                x =>
            {
                VerticalAlignment value;
                if (!Enum.TryParse(x, true, out value))
                {
                    switch (x.ToLowerInvariant())
                    {
                    case "topaligned":
                        return(VerticalAlignment.Top);

                    case "centrealigned":
                        return(VerticalAlignment.Centre);

                    case "bottomaligned":
                        return(VerticalAlignment.Bottom);
                    }
                }

                return(value);
            },
                x => ((VerticalAlignment)x).ToString());

            RegisterFunction <VerticalTextFormatting>(
                x => (VerticalTextFormatting)Enum.Parse(typeof(VerticalTextFormatting), x, true),
                x => ((VerticalTextFormatting)x).ToString());

            RegisterFunction <HorizontalTextFormatting>(
                x => (HorizontalTextFormatting)Enum.Parse(typeof(HorizontalTextFormatting), x, true),
                x => ((HorizontalTextFormatting)x).ToString());

            RegisterFunction <AutoScaledMode>(
                x =>
            {
                AutoScaledMode value;
                if (!Enum.TryParse(x, true, out value))
                {
                    if (x.ToLowerInvariant() == "false")
                    {
                        return(AutoScaledMode.Disabled);
                    }
                }
                return(value);
            },
                x => ((AutoScaledMode)x).ToString());

            RegisterFunction <VerticalFormatting>(
                x => (VerticalFormatting)Enum.Parse(typeof(VerticalFormatting), x, true),
                x => ((VerticalFormatting)x).ToString());

            RegisterFunction <HorizontalFormatting>(
                x => (HorizontalFormatting)Enum.Parse(typeof(HorizontalFormatting), x, true),
                x => ((HorizontalFormatting)x).ToString());

            RegisterFunction <FrameImageComponent>(
                x => (FrameImageComponent)Enum.Parse(typeof(FrameImageComponent), x, true),
                x => ((FrameImageComponent)x).ToString());

            RegisterFunction <DimensionType>(
                x => (DimensionType)Enum.Parse(typeof(DimensionType), x, true),
                x => ((DimensionType)x).ToString());

            RegisterFunction <DimensionOperator>(
                x => (DimensionOperator)Enum.Parse(typeof(DimensionOperator), x, true),
                x => ((DimensionOperator)x).ToString());

            RegisterFunction <WindowUpdateMode>(
                x => (WindowUpdateMode)Enum.Parse(typeof(WindowUpdateMode), x, true),
                x => ((WindowUpdateMode)x).ToString());

            RegisterFunction <ScrollbarDisplayMode>(
                x => (ScrollbarDisplayMode)Enum.Parse(typeof(ScrollbarDisplayMode), x, true),
                x => ((ScrollbarDisplayMode)x).ToString());

            RegisterFunction <ViewSortMode>(
                x => (ViewSortMode)Enum.Parse(typeof(ViewSortMode), x, true),
                x => ((ViewSortMode)x).ToString());

            RegisterFunction <Tuple <float, float> >(
                x => { throw new NotImplementedException(); },
                x => String.Format("min:{0} max:{1}", ((Tuple <float, float>)x).Item1, ((Tuple <float, float>)x).Item1));

            #region Types from Widgets

            RegisterFunction <ListHeaderSegment.SortDirection>(
                x => (ListHeaderSegment.SortDirection)Enum.Parse(typeof(ListHeaderSegment.SortDirection), x, true),
                x => ((ListHeaderSegment.SortDirection)x).ToString());

            RegisterFunction <MultiColumnList.SelectionMode>(
                x => (MultiColumnList.SelectionMode)Enum.Parse(typeof(MultiColumnList.SelectionMode), x, true),
                x => ((MultiColumnList.SelectionMode)x).ToString());

            RegisterFunction <ItemListBase.SortMode>(
                x => (ItemListBase.SortMode)Enum.Parse(typeof(ItemListBase.SortMode), x, true),
                x => ((ItemListBase.SortMode)x).ToString());

            RegisterFunction <Spinner.TextInputMode>(
                x => (Spinner.TextInputMode)Enum.Parse(typeof(Spinner.TextInputMode), x, true),
                x => ((Spinner.TextInputMode)x).ToString());

            RegisterFunction <GridLayoutContainer.AutoPositioning>(
                x => (GridLayoutContainer.AutoPositioning)Enum.Parse(typeof(GridLayoutContainer.AutoPositioning), x, true),
                x => ((GridLayoutContainer.AutoPositioning)x).ToString());

            #endregion
        }
Exemplo n.º 10
0
 /// <summary>
 /// Set the current value of the UnifiedDim.
 /// </summary>
 /// <param name="val"></param>
 public void SetBaseValue(UDim val)
 {
     d_value = val;
 }
Exemplo n.º 11
0
        //public UnifiedDim(){}

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="value">
        /// UDim holding the value to assign to this UnifiedDim.
        /// </param>
        /// <param name="dim">
        /// DimensionType value indicating what this UnifiedDim is to represent.  This is required
        /// because we need to know what part of the base Window that the UDim scale component is
        /// to operate against.
        /// </param>
        public UnifiedDim(UDim value, DimensionType dim)
        {
            d_value = value;
            d_what  = dim;
        }
Exemplo n.º 12
0
 public UBox(UDim margin)
     : this(margin, margin, margin, margin)
 {
 }
Exemplo n.º 13
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="x"></param>
 /// <param name="y"></param>
 public UVector2(UDim x, UDim y)
 {
     d_x = x;
     d_y = y;
 }
Exemplo n.º 14
0
 public URect(UDim left, UDim top, UDim right, UDim bottom)
     : this(new UVector2(left, top), new UVector2(right, bottom))
 {
 }