Ejemplo n.º 1
0
        /// <summary>
        /// Sets default values of the view.
        /// </summary>
        public override void SetDefaultValues()
        {
            base.SetDefaultValues();

            Alignment.DirectValue      = MarkLight.ElementAlignment.Center;
            Width.DirectValue          = new ElementSize(1.0f, ElementSizeUnit.Percents);
            Height.DirectValue         = new ElementSize(1.0f, ElementSizeUnit.Percents);
            OverrideWidth.DirectValue  = ElementSize.FromPixels(0);
            OverrideHeight.DirectValue = ElementSize.FromPixels(0);
            Margin.DirectValue         = new ElementMargin();
            Offset.DirectValue         = new ElementMargin();
            Alpha.DirectValue          = 1;
            IsVisible.DirectValue      = true;

            if (ImageComponent != null)
            {
                ImageComponent.color = Color.clear;
                ImageComponent.type  = UnityEngine.UI.Image.Type.Simple;
            }

            IsActive.DirectValue            = true;
            OffsetFromParent.DirectValue    = new ElementMargin();
            SortIndex.DirectValue           = 0;
            UpdateRectTransform.DirectValue = true;
            UpdateBackground.DirectValue    = true;
        }
Ejemplo n.º 2
0
 public static void AssertSize <T>(ElementSize elementSize)
 {
     if (TypeHelpers.ToElementSize <T>() != elementSize)
     {
         throw new InvalidOperationException($"Element size mismatch, T is {Unsafe.SizeOf<T>()}, pointer is {elementSize}");
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Value converter for ElementSize type.
        /// </summary>
        public override ConversionResult Convert(object value, ValueConverterContext context)
        {
            if (value == null)
            {
                return(base.Convert(value, context));
            }

            Type valueType = value.GetType();

            if (valueType == _type)
            {
                return(base.Convert(value, context));
            }
            else if (valueType == _stringType)
            {
                var stringValue = (string)value;
                try
                {
                    var convertedValue = ElementSize.Parse(stringValue, context.UnitSize);
                    return(new ConversionResult(convertedValue));
                }
                catch (Exception e)
                {
                    return(ConversionFailed(value, e));
                }
            }

            return(ConversionFailed(value));
        }
Ejemplo n.º 4
0
        public static StructAccessor <T> Create(ElementSize elementSize, short dataWords, short pointers)
        {
            try
            {
#if FULLCLR
                var methods = typeof(T).GetMethods(BindingFlags.Public | BindingFlags.Static);
#else
                var methods = typeof(T).GetRuntimeMethods();
#endif
                var op_toT   = FindMethod(methods, typeof(Pointer), typeof(T), "op_implicit") ?? FindMethod(methods, typeof(Pointer), typeof(T), "op_explicit");
                var op_fromT = FindMethod(methods, typeof(T), typeof(Pointer), "op_implicit") ?? FindMethod(methods, typeof(T), typeof(Pointer), "op_explicit");

                if (op_toT != null && op_fromT != null)
                {
#if FULLCLR
                    Func <Pointer, T> toT   = (Func <Pointer, T>)Delegate.CreateDelegate(typeof(Func <Pointer, T>), null, op_toT);
                    Func <T, Pointer> fromT = (Func <T, Pointer>)Delegate.CreateDelegate(typeof(Func <T, Pointer>), null, op_fromT);
#else
                    ParameterExpression p;
                    Func <Pointer, T>   toT = Expression.Lambda <Func <Pointer, T> >(
                        Expression.Convert(p = Expression.Parameter(typeof(T)), typeof(T), op_toT), p).Compile();
                    Func <T, Pointer> fromT = Expression.Lambda <Func <T, Pointer> >(
                        Expression.Convert(p = Expression.Parameter(typeof(T)), typeof(Pointer), op_fromT), p).Compile();
#endif
                    return(new OperatorBasedStructTypeAccessor(elementSize, dataWords, pointers, toT, fromT));
                }
            }
            catch { }
            return(new DynamicStructTypeAccessor(elementSize, dataWords, pointers));
        }
Ejemplo n.º 5
0
 public OperatorBasedStructTypeAccessor(ElementSize elementSize, short dataWords, short pointers,
                                        Func <Pointer, T> toT, Func <T, Pointer> fromT)
     : base(elementSize, dataWords, pointers)
 {
     this.toT   = toT;
     this.fromT = fromT;
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Sets default values of the view.
        /// </summary>
        public override void SetDefaultValues()
        {
            base.SetDefaultValues();

            Width.DirectValue  = ElementSize.FromPixels(160);
            Height.DirectValue = ElementSize.FromPixels(40);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Interpolates between two element sizes based on a weight.
        /// </summary>
        public override object Interpolate(object from, object to, float weight)
        {
            ElementSize a = from as ElementSize;
            ElementSize b = to as ElementSize;

            if (a == null || b == null)
            {
                return(base.Interpolate(from, to, weight));
            }

            if (a.Unit == ElementSizeUnit.Percents || b.Unit == ElementSizeUnit.Percents)
            {
                if (a.Unit != b.Unit)
                {
                    // can't interpolate between percent and another unit type
                    return(from);
                }
                else
                {
                    return(new ElementSize(Lerp(a.Percent, b.Percent, weight), ElementSizeUnit.Percents));
                }
            }

            return(new ElementSize(Lerp(a.Pixels, b.Pixels, weight), ElementSizeUnit.Pixels));
        }
Ejemplo n.º 8
0
        // TODO is there a way to run a callback when a field changes?
        public void SetItems(ObservableList <ItemInstance> items)
        {
            SetValue("Items", items);

            int NumInColumn = (int)Math.Ceiling((float)items.Count() / NumInRow);

            Height.Value = ElementSize.FromPixels(NumInColumn * Template.Height.Value.Pixels + ContainerNameLabel.Height.Value.Pixels);
        }
 public void MarginRight(bool toggle)
 {
     LayoutRegion.Margin.Value = new ElementMargin(
         LayoutRegion.Margin.Value.Left,
         LayoutRegion.Margin.Value.Top,
         toggle ? ElementSize.FromPixels(100) : new ElementSize(),
         LayoutRegion.Margin.Value.Bottom
         );
 }
 public void OffsetBottom(bool toggle)
 {
     LayoutRegion.Offset.Value = new ElementMargin(
         LayoutRegion.Offset.Value.Left,
         LayoutRegion.Offset.Value.Top,
         LayoutRegion.Offset.Value.Right,
         toggle ? ElementSize.FromPixels(100) : new ElementSize()
         );
 }
Ejemplo n.º 11
0
        public override void Initialize()
        {
            base.Initialize();

            float rowSpacing = Container.Spacing.Value.Pixels;
            float rowWidth   = NumInRow * Template.Width.Value.Pixels + (NumInRow + 1) * rowSpacing;

            Container.Width.Value = ElementSize.FromPixels(rowWidth);
        }
Ejemplo n.º 12
0
        public static string ToClassString(this ElementSize t, string prefix)
        {
            if (t == ElementSize.None)
            {
                return("");
            }

            return(prefix + ToClassString(t));
        }
Ejemplo n.º 13
0
 private int ConvertRealSize( ElementSize elementSize )
 {
     switch ( elementSize )
     {
         case ElementSize.Float1: return 4;
         case ElementSize.Float2: return 8;
         case ElementSize.Float3: return 12;
         case ElementSize.Float4: return 16;
         default: throw new ArgumentException ();
     }
 }
Ejemplo n.º 14
0
 private SharpDX.Direct3D9.DeclarationType ConvertType( ElementSize elementSize )
 {
     switch ( elementSize )
     {
         case ElementSize.Float1: return SharpDX.Direct3D9.DeclarationType.Float1;
         case ElementSize.Float2: return SharpDX.Direct3D9.DeclarationType.Float2;
         case ElementSize.Float3: return SharpDX.Direct3D9.DeclarationType.Float3;
         case ElementSize.Float4: return SharpDX.Direct3D9.DeclarationType.Float4;
         default: throw new ArgumentException ();
     }
 }
        /// <summary>
        /// Overloaded constructor used create an instance of the OptionsModel class during serialization.
        /// The public properties of this class are set by this contructor as they are obtained from the
        /// IChart interface object passed as the parameter.
        /// </summary>
        /// <param name="chart">Specifies the IChart interface object of the parent IChart object being serialized.</param>
        public OptionsModel(IChart chart)
        {
            BubbleMinSize = (double)chart.GetOption("BubbleMinSize");
            BubbleMaxSize = (double)chart.GetOption("BubbleMaxSize");

            ElementSize es = chart.GetOption("ClusterSize") as ElementSize;

            ClusterSizeType  = es.Equals(null) ? ElementSizeType.Percentage : es.SizeType;
            ClusterSizeValue = es.Equals(null) ? 70.0 : es.Value;

            InterpolateNulls = (bool)chart.GetOption("InterpolateNulls");
        }
Ejemplo n.º 16
0
        private VertexAttribPointerType ElementSizeToRealType( ElementSize elementSize )
        {
            switch ( elementSize )
            {
                case ElementSize.Float1:
                case ElementSize.Float2:
                case ElementSize.Float3:
                case ElementSize.Float4: return VertexAttribPointerType.Float;

                default: throw new ArgumentException ();
            }
        }
Ejemplo n.º 17
0
    public override void Initialize()
    {
        base.Initialize();
        OptionsWidth  = new ElementSize(400, ElementSizeUnit.Pixels);
        OptionsHeight = new ElementSize(350, ElementSizeUnit.Pixels);

        SoundTabHeader.Scale.Value   = new Vector3(0.0f, 0.0f, 0.0f);
        DisplayTabHeader.Scale.Value = new Vector3(0.0f, 0.0f, 0.0f);

        SunRaysMaterialTypeA = Resources.Load("Particles/Materials/Light_02", typeof(Material)) as Material;
        SunRaysMaterialTypeA.SetColor("_TintColor", Color.magenta);
    }
Ejemplo n.º 18
0
 public void ReactToElement(SystemicElement type, ElementSize size)
 {
     for (int i = 0; i < reactions.Length; i++)
     {
         if (reactions[i].theElement == type &&
             ((reactions[i].theSize != ElementSize.NONE && (int)size >= (int)reactions[i].theSize) ||
              reactions[i].theSize == ElementSize.NONE)
             )
         {
             reactions[i].actions.Invoke();
         }
     }
 }
Ejemplo n.º 19
0
        public static IDisposable BeginModal(this HtmlHelper helper, string id, ElementSize size = ElementSize.Normal)
        {
            var modalSize = String.Empty;
            if (size == ElementSize.ExtraSmall || size == ElementSize.Small)
                modalSize = " modal-sm";

            if (size == ElementSize.Large)
                modalSize = " modal-lg";

            helper.ViewContext.Writer.WriteLine("<div class=\"modal fade\" id=\"{0}\" tabindex=\"-1\" role=\"dialog\">", id);
            helper.ViewContext.Writer.WriteLine("<div class=\"modal-dialog{0}\">", modalSize);
            helper.ViewContext.Writer.WriteLine("<div class=\"modal-content\">");

            return new Modal(helper);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Sets default values of the view.
        /// </summary>
        public override void SetDefaultValues()
        {
            base.SetDefaultValues();
            Breadth.DirectValue     = new ElementSize(40);
            Length.DirectValue      = new ElementSize(120);
            TextPadding.DirectValue = new ElementMargin();

            // list item label
            if (ItemLabel != null)
            {
                ItemLabel.TextAlignment.DirectValue = ElementAlignment.Center;
                ItemLabel.Width.DirectValue         = ElementSize.FromPercents(1);
                ItemLabel.Height.DirectValue        = ElementSize.FromPercents(1);
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Sets default values of the view.
        /// </summary>
        public override void SetDefaultValues()
        {
            base.SetDefaultValues();

            Length.DirectValue                          = new ElementSize(160);
            Breadth.DirectValue                         = new ElementSize(40);
            Orientation.DirectValue                     = ElementOrientation.Horizontal;
            Min.DirectValue                             = 0;
            Max.DirectValue                             = 100;
            CanSlide.DirectValue                        = true;
            SetValueOnDragEnded.DirectValue             = false;
            SliderFillImageView.Alignment.DirectValue   = ElementAlignment.Left;
            SliderHandleImageView.Alignment.DirectValue = ElementAlignment.Left;
            SliderHandleImageView.Width.DirectValue     = new ElementSize(20);
            SliderHandleImageView.Height.DirectValue    = ElementSize.FromPercents(1);
        }
Ejemplo n.º 22
0
        public static string ToClassString(this ElementSize t)
        {
            switch (t)
            {
            case ElementSize.ExtraSmall: return("xs");

            case ElementSize.Small: return("sm");

            case ElementSize.Medium: return("md");

            case ElementSize.Large: return("lg");

            case ElementSize.ExtraLarge: return("xl");
            }

            return("sm");
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Updates the layout of the view.
        /// </summary>
        public override void LayoutChanged()
        {
            // set content margins based on tab list size and its orientation
            var contentMargin = new ElementMargin();
            var tabAlignment  = ElementAlignment.Center;

            if (TabHeaderList.Orientation == ElementOrientation.Horizontal)
            {
                if (TabHeaderList.Alignment.Value.HasFlag(ElementAlignment.Bottom))
                {
                    contentMargin.Bottom = ElementSize.FromPixels(TabHeaderList.Height.Value.Pixels);
                    tabAlignment         = ElementAlignment.Top;
                }
                else
                {
                    contentMargin.Top = ElementSize.FromPixels(TabHeaderList.Height.Value.Pixels);
                    tabAlignment      = ElementAlignment.Bottom;
                }
            }
            else
            {
                if (TabHeaderList.Alignment.Value.HasFlag(ElementAlignment.Right))
                {
                    contentMargin.Right = ElementSize.FromPixels(TabHeaderList.Width.Value.Pixels);
                    tabAlignment        = ElementAlignment.Left;
                }
                else
                {
                    contentMargin.Left = ElementSize.FromPixels(TabHeaderList.Width.Value.Pixels);
                    tabAlignment       = ElementAlignment.Right;
                }
            }

            if (AutoAdjustContentMargin)
            {
                TabContent.Margin.Value = contentMargin;
            }

            if (AutoAdjustTabListContentAlignment)
            {
                TabHeaderList.ContentAlignment.Value = tabAlignment;
            }

            base.LayoutChanged();
        }
Ejemplo n.º 24
0
        public static StructAccessor <T> Create(ElementSize elementSize, short dataWords, short pointers)
        {
            try
            {
                var methods  = typeof(T).GetMethods(BindingFlags.Public | BindingFlags.Static);
                var op_toT   = FindMethod(methods, typeof(Pointer), typeof(T), "op_implicit") ?? FindMethod(methods, typeof(Pointer), typeof(T), "op_explicit");
                var op_fromT = FindMethod(methods, typeof(T), typeof(Pointer), "op_implicit") ?? FindMethod(methods, typeof(T), typeof(Pointer), "op_explicit");

                if (op_toT != null && op_fromT != null)
                {
                    Func <Pointer, T> toT   = (Func <Pointer, T>)Delegate.CreateDelegate(typeof(Func <Pointer, T>), null, op_toT);
                    Func <T, Pointer> fromT = (Func <T, Pointer>)Delegate.CreateDelegate(typeof(Func <T, Pointer>), null, op_fromT);
                    return(new OperatorBasedStructTypeAccessor(elementSize, dataWords, pointers, toT, fromT));
                }
            }
            catch { }
            return(new DynamicStructTypeAccessor(elementSize, dataWords, pointers));
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Sets default values of the view.
        /// </summary>
        public override void SetDefaultValues()
        {
            base.SetDefaultValues();

            Width.DirectValue  = new ElementSize(200);
            Height.DirectValue = new ElementSize(40);

            // input text
            InputText.Margin.DirectValue        = new ElementMargin(9);
            InputText.TextAlignment.DirectValue = ElementAlignment.TopLeft;
            InputText.Width.DirectValue         = ElementSize.FromPercents(1);
            InputText.Height.DirectValue        = ElementSize.FromPercents(1);

            // inputfield component
            InputFieldComponent.textComponent = InputText.TextComponent;
            InputFieldComponent.placeholder   = InputFieldPlaceholder.ImageComponent;
            InputFieldComponent.transition    = Selectable.Transition.None;
        }
        public static string TranslateLabel(ElementSize size, float proportion)
        {
            float proportionInverse = 1 / proportion;

            int sm = Convert.ToInt32(4 * proportionInverse);
            int md = 6;
            int lg = Convert.ToInt32(3 * proportion);
            int xl = Convert.ToInt32(2 * proportion);

            switch (size)
            {
            case ElementSize.ExtraLarge:
                return("col-sm-4 col-lg-3 col-xl-2");

            default:
                return("col-sm-4 col-lg-3 col-xl-2");
            }
        }
Ejemplo n.º 27
0
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            ElementSize es = value as ElementSize;

            if (object.ReferenceEquals(es, null))
            {
                return(string.Empty);
            }
            switch (es.SizeType)
            {
            case ElementSizeType.Absolute:
                return(es.Value.ToString(culture) + "tw");

            case ElementSizeType.Percentage:
                return(es.Value.ToString(culture) + "%");
            }
            return(base.ConvertTo(context, culture, value, destinationType));
        }
Ejemplo n.º 28
0
        private string GetAttributeString()
        {
            var attributes = new Dictionary <string, string>();

            attributes.Add("protocol", this.Protocol.ToString());
            attributes.Add("gateway", this.Gateway);
            attributes.Add("path", Path);
            attributes.Add("plc", PlcType.ToString().ToLower());
            attributes.Add("elem_size", ElementSize?.ToString());
            attributes.Add("elem_count", ElementCount?.ToString());
            attributes.Add("name", Name);
            attributes.Add("read_cache_ms", ReadCacheMillisecondDuration?.ToString());
            if (UseConnectedMessaging.HasValue)
            {
                attributes.Add("use_connected_msg", UseConnectedMessaging.Value ? "1" : "0");
            }

            string separator = "&";

            return(string.Join(separator, attributes.Where(attr => attr.Value != null).Select(attr => $"{attr.Key}={attr.Value}")));
        }
Ejemplo n.º 29
0
        public override void Initialize()
        {
            base.Initialize();
            this.ForEachChild <View>(x => x.Deactivate(), false);

            if (!Application.isPlaying)
            {
                return;
            }

            // TODO: Hardcoded values
            Height.DirectValue = ElementSize.FromPixels(480f);
            Width.DirectValue  = ElementSize.FromPixels(800f);
            LayoutChanged();

            var height = (int)ActualHeight;
            var width  = (int)ActualWidth;

            var plane = GameObject.CreatePrimitive(PrimitiveType.Plane);

            //plane.transform.position = new Vector3(0f, -0.005f, -0.01f);
            plane.transform.rotation      = Quaternion.Euler(90, 180, 0);
            plane.transform.localScale    = new Vector3(width * 0.0001f, 1f, height * 0.0001f);
            plane.transform.parent        = transform;
            plane.transform.localPosition = new Vector3(0f, 0f, -0.01f);
            //plane.GetComponent<MeshCollider>().convex = true;
            var planeRigidbody = plane.AddComponent <Rigidbody>();

            planeRigidbody.useGravity  = false;
            planeRigidbody.isKinematic = true;
            // VRActor needed for mouse / flystick interactions
            plane.AddComponent <VRActor>().Grabable = false;

            _vrWebView        = plane.AddComponent <VRWebView>();
            _vrWebView.Width  = (int)(width * 1.5);
            _vrWebView.Height = (int)(height * 1.5);
            _vrWebView.MouseInteractionsIn3D = true;
        }
Ejemplo n.º 30
0
        public static int SizeOf(this ElementSize size)
        {
            switch (size)
            {
            case ElementSize.Zero: return(0);

            case ElementSize.OneBit: throw new ArgumentException("size is OneBit", nameof(size));

            case ElementSize.OneByte: return(1);

            case ElementSize.TwoBytes: return(2);

            case ElementSize.FourBytes: return(4);

            case ElementSize.EightBytesNonPointer:
            case ElementSize.EightBytesPointer:
                return(8);

            case ElementSize.Composite: throw new ArgumentException("size is Composite", nameof(size));

            default: throw new ArgumentException($"Invalid ElementSize: {size}");
            }
        }
Ejemplo n.º 31
0
 public DynamicStructTypeAccessor(ElementSize elementSize, short dataWords, short pointers)
     : base(elementSize, dataWords, pointers)
 {
 }
Ejemplo n.º 32
0
 public VertexElement( ElementType t, int i, ElementSize s )
 {
     Type = t; UsageIndex = i; Size = s;
 }
Ejemplo n.º 33
0
 private StructAccessor(ElementSize elementSize, short dataWords, short pointers)
 {
     this.elementSize = elementSize;
     this.dataWords   = dataWords;
     this.pointers    = pointers;
 }
Ejemplo n.º 34
0
 private SharpDX.DXGI.Format ConvertType( ElementSize elementSize )
 {
     switch ( elementSize )
     {
         case ElementSize.Float1: return SharpDX.DXGI.Format.R32_Float;
         case ElementSize.Float2: return SharpDX.DXGI.Format.R32G32_Float;
         case ElementSize.Float3: return SharpDX.DXGI.Format.R32G32B32_Float;
         case ElementSize.Float4: return SharpDX.DXGI.Format.R32G32B32A32_Float;
         default: throw new ArgumentException ();
     }
 }
Ejemplo n.º 35
0
 public override FixedSizeList <FixedSizeList <TInner> > CreateList(Pointer pointer, int count, ElementSize elementSize)
 {
     if (elementSize != ElementSize.EightBytesPointer)
     {
         throw new ArgumentException("Must be created as a list of size " + ElementSize.EightBytesPointer, "elementSize");
     }
     return(CreateList(pointer, count));
 }
Ejemplo n.º 36
0
 public virtual FixedSizeList <T> CreateList(Pointer pointer, int count, ElementSize elementSize)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 37
0
 public StructAttribute(ElementSize preferredSize, int dataWords = 0, int pointers = 0)
 {
     this.PreferredSize = preferredSize;
     this.DataWords = dataWords;
     this.Pointers = pointers;
 }