Example #1
0
 /// <summary>
 /// converts given <see cref="UVector2"/> to absolute <see cref="Vector2f"/>
 /// </summary>
 /// <param name="v"></param>
 /// <param name="base"></param>
 /// <param name="pixelAlign"></param>
 /// <returns></returns>
 public static Lunatics.Mathematics.Vector2 AsAbsolute(UVector2 v, Sizef @base, bool pixelAlign = true)
 {
     return(new Lunatics.Mathematics.Vector2(AsAbsolute(v.d_x, @base.Width, pixelAlign),
                                             AsAbsolute(v.d_y, @base.Height, pixelAlign)));
 }
Example #2
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
        }
Example #3
0
 public URect(UVector2 min, UVector2 max)
 {
     d_min = min;
     d_max = max;
 }
        public override List <GeometryBuffer> CreateRenderGeometry(Window refWnd, Vector2 position, ColourRect modColours, Rectf?clipRect, float verticalSpace, float spaceExtra)
        {
            var window = GetEffectiveWindow(refWnd);

            if (window == null)
            {
                return(new List <GeometryBuffer>());
            }

            var geomBuffers = new List <GeometryBuffer>();

            // HACK: re-adjust for inner-rect of parent
            float xAdj = 0, yAdj = 0;
            var   parent = window.GetParent();

            if (parent != null)
            {
                var outer = parent.GetUnclippedOuterRect().Get();
                var inner = parent.GetUnclippedInnerRect().Get();
                xAdj = inner.d_min.X - outer.d_min.X;
                yAdj = inner.d_min.Y - outer.d_min.Y;
            }
            // HACK: re-adjust for inner-rect of parent (Ends)

            var finalPos = position;

            // handle formatting options
            switch (d_verticalFormatting)
            {
            case VerticalFormatting.BottomAligned:
                finalPos.Y += verticalSpace - GetPixelSize(refWnd).Height;
                break;

            case VerticalFormatting.Stretched:
            case VerticalFormatting.CentreAligned:
                if (d_verticalFormatting == VerticalFormatting.Stretched)
                {
                    System.GetSingleton().Logger.LogEvent("RenderedStringWidgetComponent::draw: " +
                                                          "VerticalFormatting.Stretched specified but is unsupported for Widget types; " +
                                                          "defaulting to VerticalFormatting.CentreAligned instead.");
                }

                finalPos.Y += (verticalSpace - GetPixelSize(refWnd).Height) / 2;
                break;

            case VerticalFormatting.TopAligned:
                // nothing additional to do for this formatting option.
                break;

            default:
                throw new InvalidRequestException("unknown VerticalFormatting option specified.");
            }

            // render the selection if needed
            if (d_selectionImage != null && d_selected)
            {
                var selectArea        = new Rectf(position, GetPixelSize(refWnd));
                var imgRenderSettings = new ImageRenderSettings(selectArea, clipRect, true, new ColourRect(0xFF002FFF));
                geomBuffers.AddRange(d_selectionImage.CreateRenderGeometry(imgRenderSettings));
            }

            // we do not actually draw the widget, we just move it into position.
            var wpos = new UVector2(new UDim(0, finalPos.X + d_padding.d_min.X - xAdj),
                                    new UDim(0, finalPos.Y + d_padding.d_min.Y - yAdj));

            window.SetPosition(wpos);

            return(geomBuffers);
        }
Example #5
0
 public URect(UVector2 pos, USize size)
     : this(pos, new UVector2(pos.d_x + size.d_width, pos.d_y + size.d_height))
 {
 }