public override void Apply(ComputedStyle style,Value value){
			
			// Get the background image:
			PowerUI.Css.BackgroundImage background=GetBackground(style);
			
			if(value==null){
				background.Filtering=FilterMode.Point;
			}else{
				
				switch(value.Text){
					case "bilinear":
						background.Filtering=FilterMode.Bilinear;
					break;
					case "trilinear":
						background.Filtering=FilterMode.Trilinear;
					break;
					default:
						background.Filtering=FilterMode.Point;
					break;
				}
				
			}
			
			if(background.Image!=null && background.Image.Image!=null){
				background.Image.Image.filterMode=background.Filtering;
			}
			
			// Request a layout:
			background.RequestLayout();
			
		}
		public override void Apply(ComputedStyle style,Value value){
			
			if(value==null){
				
				// Assume auto:
				style.HorizontalAlign=HorizontalAlignType.Auto;
				
			}else{
			
				switch(value.Text){
					case "right":
						style.HorizontalAlign=HorizontalAlignType.Right;
					break;
					case "justify":
						style.HorizontalAlign=HorizontalAlignType.Justify;
					break;
					case "center":
						style.HorizontalAlign=HorizontalAlignType.Center;
					break;
					case "left":
						style.HorizontalAlign=HorizontalAlignType.Left;
					break;
					default:
						style.HorizontalAlign=HorizontalAlignType.Auto;
					break;
				}
				
			}
			
			style.RequestLayout();
		}
		public override void Apply(ComputedStyle style,Value value){
			
			// Get the text:
			TextRenderingProperty text=GetText(style);
			
			if(text==null){
				return;
			}
			
			// Apply the property:
			
			string fontName=value.Text;
			
			if(fontName==null){
				return;
			}
			
			Find(fontName,text);
			
			if(text.FontToDraw==null){
				
				// No fonts at all.
				// We're going to load and use the default one:
				text.FontToDraw=DynamicFont.GetDefaultFamily();
				
			}
			
			// Apply the changes:
			text.SetText();
			
		}
		public override void Apply(ComputedStyle style,Value value){
			
			if(style.SetupTransform(value)){
					
				if(value==null){
					style.Transform.Scale=Vector3.one;
				}else{
					float x=1f;
					float y=1f;
					float z=1f;
					
					if(value[0]!=null){
						x=value[0].Single;
					}
					
					if(value[1]!=null){
						y=value[1].Single;
					}
					
					if(value[2]!=null){
						z=value[2].Single;
					}
					
					style.Transform.Scale=new Vector3(x,y,z);
				}
				
			}
			
			style.RequestTransform();
			
		}
		public override void Apply(ComputedStyle style,Value value){
			
			// Get the border:
			BorderProperty border=GetBorder(style);
			
			if(value==null){
				// No corners:
				border.Corners=null;
			}else{
				
				// Apply top left:
				border.SetCorner(RoundCornerPosition.TopLeft,value.GetPX(0));
				
				// Apply top right:
				border.SetCorner(RoundCornerPosition.TopRight,value.GetPX(1));
				
				// Apply bottom right:
				border.SetCorner(RoundCornerPosition.BottomLeft,value.GetPX(2));
				
				// Apply bottom left:
				border.SetCorner(RoundCornerPosition.BottomRight,value.GetPX(3));
				
			}
			
			// Request a layout:
			border.RequestLayout();
			
		}
		public override void Apply(ComputedStyle style,Value value){
			
			// Get the background image (always created if needed):
			PowerUI.Css.BackgroundImage image=GetBackground(style);
			
			if(value==null){
				image.Clipping=BackgroundClipping.BorderBox;
			}else{
				
				switch(value.Text){
					case "text":
						image.Clipping=BackgroundClipping.Text;
					break;
					case "padding-box":
						image.Clipping=BackgroundClipping.PaddingBox;
					break;
					case "content-box":
						image.Clipping=BackgroundClipping.ContentBox;
					break;
					default:
						image.Clipping=BackgroundClipping.BorderBox;
					break;
				}
				
			}
			
			// Request a layout:
			image.RequestLayout();
			
		}
		public override void Apply(ComputedStyle style,Value value){
			// E.g. relative, fixed.
			
			if(style.SetupTransform(value)){
				
				if(value==null){
					
					style.Transform.OriginPosition=PositionType.Relative;
					
				}else{
				
					if(value.Text=="fixed"){
						
						style.Transform.OriginPosition=PositionType.Fixed;
						
					}else if(value.Text=="absolute"){
						
						style.Transform.OriginPosition=PositionType.Absolute;
						
					}else{
						
						style.Transform.OriginPosition=PositionType.Relative;
						
					}
					
				}
				
			}
			
			style.RequestTransform();
		}
		public override void Apply(ComputedStyle style,Value value){
			
			if(style.SetupTransform(value)){
				
				if(value==null){
					
					style.Transform.Skew=Matrix4x4.identity;
					
				}else{
					
					// Get the radian values:
					float rotationX=value.GetRadians(0);
					float rotationY=value.GetRadians(1);
					
					// Get the base matrix:
					Matrix4x4 skewMatrix=Matrix4x4.identity;
					
					// Find the tan values:
					rotationX=Mathf.Tan(rotationX);
					rotationY=Mathf.Tan(rotationY);
					
					// Apply them to the matrix using the flattened accessor:
					skewMatrix[4]=rotationX;
					skewMatrix[1]=rotationY;
					
					// Set the skew:
					style.Transform.Skew=skewMatrix;
					
				}
				
			}
			
			style.RequestTransform();
		}
		public override void Apply(ComputedStyle style,Value value){
			
			// Get the text:
			TextRenderingProperty text=GetText(style);
			
			if(text==null){
				return;
			}
			
			if(value==null){
				
				// No extrude:
				text.Extrude=0f;
				
			}else{
				
				if(value.Single<0f){
					text.Extrude=0f;
				}else{
					text.Extrude=value.Single;
				}
				
			}
			
			// Apply the changes:
			text.SetText();
			
		}
		public override void Apply(ComputedStyle style,Value value){
			
			// Get the border:
			BorderProperty border=GetBorder(style);
			
			if(value==null){
				border.WidthTop=border.WidthLeft=0;
				border.WidthRight=border.WidthBottom=0;
			}else{
				border.WidthTop=value.GetPX(0);
				border.WidthRight=value.GetPX(1);
				border.WidthBottom=value.GetPX(2);
				border.WidthLeft=value.GetPX(3);
			}
			
			// Does the border have any corners? If so, we need to update them:
			if(border.Corners!=null){
				border.Corners.Recompute();
			}
			
			// Request a layout:
			border.RequestLayout();
			
			// Set the styles size:
			style.SetSize();
		}
		public override void Apply(ComputedStyle style,Value value){
			
			// Get the text property:
			TextRenderingProperty text=style.Text;
			
			if(text==null){
				// Create one - note that content is the only property that can create a TRP.
				style.Text=text=new TextRenderingProperty(style.Element);
				
				// Next, apply every textual style immediately.
				// Note: properties with multiple names are applied multiple times.
				// This is fine. It's expected to be such a rare case and it will work fine anyway.
				foreach(KeyValuePair<string,CssProperty> kvp in CssProperties.TextProperties){
					SetValue(kvp.Value,style);
				}
				
			}
			
			// Set the actual text:
			if(value==null){
				text.Text="";
			}else{
				text.Text=value.Text;
			}
				
			// And apply it:
			text.SetText();
			
			// Flag it as having changed:
			text.Changed=true;
			
		}
		public override void Apply(ComputedStyle style,Value value){
			
			if(value==null){
				
				// Assume none if blank:
				style.Float=FloatType.None;
				
			}else{
			
				switch(value.Text){
					case "left":
						
						// Float left:
						style.Float=FloatType.Left;
						
					break;
					case "right":
						
						// Float right:
						style.Float=FloatType.Right;
						
					break;
					default:
						
						// No float (default):
						style.Float=FloatType.None;
						
					break;
				}
				
			}
			
			style.RequestLayout();
			
		}
		public override void Apply(ComputedStyle style,Value value){
			
			// Get the background image:
			PowerUI.Css.BackgroundImage image=GetBackground(style);
			
			if(value==null){
				image.SizeX=null;
				image.SizeY=null;
			}else if(value.Type==Css.ValueType.Text){
				
				if(value.Text=="auto" || value.Text=="initial"){
					// Same as the default:
					image.SizeX=null;
					image.SizeY=null;
					
				}else if(value.Text=="cover"){
					// Same as 100% on both axis:
					image.SizeX=new Css.Value("100%",Css.ValueType.Percentage);
					image.SizeY=new Css.Value("100%",Css.ValueType.Percentage);
					
				}
				
			}else{
				// It's a vector:
				image.SizeX=value[0];
				image.SizeY=value[1];
			}
			
			// Request a layout:
			image.RequestLayout();
			
		}
		public override void Apply(ComputedStyle style,Value value){
			if(value==null){
				// Assume auto:
				style.HorizontalAlignLast=HorizontalAlignType.Auto;
				
			}else{
				
				if(value.Text=="right"){
					style.HorizontalAlignLast=HorizontalAlignType.Right;
				}else if(value.Text=="justify"){
					style.HorizontalAlignLast=HorizontalAlignType.Justify;
				}else if(value.Text=="center"){
					style.HorizontalAlignLast=HorizontalAlignType.Center;
				}else if(value.Text=="left"){
					style.HorizontalAlignLast=HorizontalAlignType.Left;
				}else if(value.Text=="start"){
					style.HorizontalAlignLast=HorizontalAlignType.Start;
				}else if(value.Text=="end"){
					style.HorizontalAlignLast=HorizontalAlignType.End;
				}else{
					style.HorizontalAlignLast=HorizontalAlignType.Auto;
				}
				
			}
			
			style.RequestLayout();
		}
		public override void Apply(ComputedStyle style,Value value){
			
			// Get the text:
			TextRenderingProperty text=GetText(style);
			
			if(text==null){
				return;
			}
			
			bool auto=(value==null || value.Text=="auto" || value.Text=="anti-alias");
			
			if(auto){
				text.Alias=float.MaxValue;
			}else if(value.PX!=0){
				text.Alias=(float)value.PX;
			}else{
				text.Alias=value.Single;
			}
			
			// Set width/height directly to the computed style:
			text.SetDimensions();
			
			// Request a redraw:
			style.RequestLayout();
			
		}
		public override void Apply(ComputedStyle style,Value value){
			
			// The new overlay colour:
			Color overlay=Color.white;
			
			if(value!=null){
				overlay=value.ToColor();
			}
			
			// Apply it:
			style.ColorOverlay=overlay;
			
			
			// Special case here - everything needs to be told!
			if(style.BGImage!=null){
				style.BGImage.SetOverlayColour(overlay);
			}
			
			if(style.BGColour!=null){
				style.BGColour.SetOverlayColour(overlay);
			}
			
			if(style.Border!=null){
				style.Border.SetOverlayColour(overlay);
			}
			
			if(style.Text!=null){
				style.Text.SetOverlayColour(overlay);
			}
			
		}
		public override void Apply(ComputedStyle style,Value value){
			
			// Get the background image:
			BackgroundImage image=GetBackground(style);
			
			if(value==null || value.Text=="" || value.Text=="repeat"){
				// Repeat by default:
				
				image.RepeatX=image.RepeatY=true;
				
			}else{
			
				if(value.Text=="repeat-x"){
					// X only.
					
					image.RepeatX=true;
					image.RepeatY=false;
				}else if(value.Text=="repeat-y"){
					// Y only.
					
					image.RepeatY=true;
					image.RepeatX=false;
				}else{
					// No repeat.
					
					image.RepeatX=false;
					image.RepeatY=false;
				}
				
			}
			
			// Request a layout:
			image.RequestLayout();
			
		}
		public override void Apply(ComputedStyle style,Value value){
			
			// Get the border:
			BorderProperty border=GetBorder(style);
			
			
			if(value!=null && value.Type==ValueType.Text){
				
				if(value.Text=="transparent"){
					// Currently assume the default colour (black):
					// (Use #00000000 instead)
					value=null;
				}
				
			}
			
			// Apply the base colour:
			border.BaseColour=value;
			
			// Reset the border colour:
			border.ResetColour();
			
			// Tell it a colour changed:
			border.ColourChanged();
			
		}
		public override void Apply(ComputedStyle style,Value value){
			
			// Get the text:
			TextRenderingProperty text=GetText(style);
			
			if(text==null){
				return;
			}
			
			if(text.TextLine==null){
				return;
			}
			
			// Apply the property:
			if(value==null || value.Text=="initial"){
				// No longer custom:
				text.TextLine.ColourOverride=false;
			}else{
				// Set the colour:
				text.TextLine.SetColour(value.ToColor());
			}
			
			// Let it know a colour changed:
			text.ColourChanged();
			
		}
		public override void Apply(ComputedStyle style,Value value){
		
			if(value==null){
				
				style.PaddingTop=style.PaddingLeft=0;
				style.PaddingRight=style.PaddingBottom=0;
				
			}else{
				// Top:
				style.PaddingTop=value.GetPX(0);
				
				// Right:
				style.PaddingRight=value.GetPX(1);
				
				// Bottom:
				style.PaddingBottom=value.GetPX(2);
				
				// Left:
				style.PaddingLeft=value.GetPX(3);
			}
			
			style.SetSize();
			
			// Fire percent passes:
			style.Element.SetHeightForKids(style);
			style.Element.SetWidthForKids(style);
			
			style.RequestLayout();
		}
		/// <summary>Sets the named css property from the given style if the property exists in the style.</summary>
		/// <param name="property">The css property, e.g. color.</param>
		/// <param name="style">The style to load value of the property from. This should be the computed style for the parent element.</param>
		private void SetValue(CssProperty property,ComputedStyle style){
			// Get the current value:
			Value value=style[property];
			
			if(value!=null){
				// Apply it:
				property.Apply(style,value);
			}
		}
		public override void Apply(ComputedStyle style,Value value){
			
			// Get the border:
			BorderProperty border=GetBorder(style);
			
			// Tell it a colour changed:
			border.ColourChanged();
			
		}
		public override void Apply(ComputedStyle style,Value value){
			
			if(value==null){
				style.MinimumWidth=int.MinValue;
			}else{
				style.MinimumWidth=value.PX;
			}
			
			style.RequestLayout();
		}
		public override void Apply(ComputedStyle style,Value value){
			
			if(value==null){
				style.MaximumHeight=int.MaxValue;
			}else{
				style.MaximumHeight=value.PX;
			}
			
			style.RequestLayout();
		}
		public override void Apply(ComputedStyle style,Value value){
			style.BottomPositioned=true;
			
			if(value==null){
				style.PositionBottom=0;
			}else{
				style.PositionBottom=value.PX;
			}
			
			style.RequestLayout();
		}
		public override void Apply(ComputedStyle style,Value value){
			// E.g. 50% 10% 100%, 0px 0px 0px.
			
			if(style.SetupTransform(value)){
				
				style.Transform.OriginOffset=value;
			
			}
			
			style.RequestTransform();
		}
		public override void Apply(ComputedStyle style,Value value){
			style.RightPositioned=false;
			
			if(value==null){
				style.PositionLeft=0;
			}else{
				style.PositionLeft=value.PX;
			}
			
			style.RequestLayout();
		}
		public override void Apply(ComputedStyle style,Value value){
			
			if(value==null){
				style.FixedDepth=false;
				style.ZIndex=0f;
			}else{
				style.FixedDepth=true;
				style.FixedZIndex=value.ToFloat() * style.Element.Document.Renderer.DepthResolution;
			}
			
			style.RequestLayout();
		}
		public override void Apply(ComputedStyle style,Value value){
			
			if(style.SetupTransform(value)){
			
				if(value==null){
					style.Transform.Translate=Vector3.zero;
				}else{
					style.Transform.Translate=new Vector3(value.GetFloat(0),value.GetFloat(1),value.GetFloat(2));
				}
				
			}
			
			style.RequestTransform();
		}
		public override void Apply(ComputedStyle style,Value value){
			
			if(value==null){
				style.OverflowX=OverflowType.Visible;
				style.OverflowY=OverflowType.Visible;
			}else{
				style.OverflowX=GetOverflowType(value.GetText(0));
				style.OverflowY=GetOverflowType(value.GetText(1));
			}
			
			style.ResetScrollbars();
			
			style.RequestLayout();
		}
Exemple #31
0
        public override ApplyState Apply(ComputedStyle style, Value value)
        {
            // Get the background image (always created if needed):
            Css.BackgroundImage image = GetBackground(style);

            if (value == null)
            {
                image.Clipping = BackgroundClipping.BorderBox;
            }
            else
            {
                switch (value.Text)
                {
                case "text":
                    image.Clipping = BackgroundClipping.Text;
                    break;

                case "padding-box":
                    image.Clipping = BackgroundClipping.PaddingBox;
                    break;

                case "content-box":
                    image.Clipping = BackgroundClipping.ContentBox;
                    break;

                default:
                    image.Clipping = BackgroundClipping.BorderBox;
                    break;
                }
            }

            // Request a layout:
            image.RequestLayout();

            // Ok!
            return(ApplyState.Ok);
        }
        public override void Apply(ComputedStyle style, Value value)
        {
            if (value == null)
            {
                style.VerticalAlign = VerticalAlignType.Top;
            }
            else
            {
                if (value.Text == "middle")
                {
                    style.VerticalAlign = VerticalAlignType.Middle;
                }
                else if (value.Text == "bottom")
                {
                    style.VerticalAlign = VerticalAlignType.Bottom;
                }
                else
                {
                    style.VerticalAlign = VerticalAlignType.Top;
                }
            }

            style.RequestLayout();
        }
Exemple #33
0
        public override bool OnAttributeChange(string property)
        {
            if (base.OnAttributeChange(property))
            {
                return(true);
            }

            if (property == "dir")
            {
                // Grab the direction:
                string direction = Element["dir"];

                // Grab the computed style:
                ComputedStyle computed = Element.style.Computed;

                // Apply it to CSS - it's exactly the same value for the direction CSS property:
                computed.ChangeTagProperty("direction", new Css.Value(direction, Css.ValueType.Text));

                return(true);
            }


            return(false);
        }
Exemple #34
0
        public override bool OnAttributeChange(string property)
        {
            if (base.OnAttributeChange(property))
            {
                return(true);
            }

            if (property == "dir")
            {
                // Grab the direction:
                string direction = getAttribute("dir");

                // Grab the computed style:
                ComputedStyle computed = Style.Computed;

                // Apply it to CSS - it's exactly the same value for the direction CSS property:
                computed.ChangeTagProperty("direction", direction);

                return(true);
            }


            return(false);
        }
Exemple #35
0
        public override void Apply(ComputedStyle style, Value value)
        {
            if (value == null)
            {
                // Assume none if blank:
                style.Float = FloatType.None;
            }
            else
            {
                switch (value.Text)
                {
                case "left":

                    // Float left:
                    style.Float = FloatType.Left;

                    break;

                case "right":

                    // Float right:
                    style.Float = FloatType.Right;

                    break;

                default:

                    // No float (default):
                    style.Float = FloatType.None;

                    break;
                }
            }

            style.RequestLayout();
        }
Exemple #36
0
        /// <summary>Called when ScrollTop or ScrollLeft has changed.</summary>
        public void ElementScrolled()
        {
            if (Thumb != null)
            {
                HtmlElement target = scrollTarget;

                if (target == null)
                {
                    return;
                }

                ComputedStyle cs = target.style.Computed;

                float barProgress = 0f;

                if (IsVertical)
                {
                    barProgress = (float)cs.ScrollTop / (float)cs.ContentHeight;
                }
                else
                {
                    barProgress = (float)cs.ScrollLeft / (float)cs.ContentWidth;
                }

                if (barProgress < 0f)
                {
                    barProgress = 0f;
                }
                else if (barProgress > 1f)
                {
                    barProgress = 1f;
                }

                Thumb.ElementScrolled(barProgress);
            }
        }
Exemple #37
0
        /// <summary>Gets the nearest focusable element below this.</summary>
        /// <returns>The nearest focusable element below. Null if there is none.</returns>
        public Element GetFocusableBelow()
        {
            // Has the element defined something specific?
            Element target = GetFocusableOverride("down");

            if (target != null)
            {
                // Yep, it did!
                return(target);
            }

            // Distance of the nearest element (set when nearest is first set):
            float nearestDistance = 0f;
            // The current nearest element:
            Element nearest = null;
            // Grab my computed style:
            ComputedStyle computed = Style.Computed;
            // Get hold of the iterator (so we can safely skip child elements):
            DocumentElements allElements = Document.allElements;

            // Grab my x position:
            float myX = computed.GetMidpointX();
            // Grab the midpoint of this element on Y:
            float myY = computed.GetMidpointY();


            // For each element in the dom that is focusable and below this..
            foreach (Element element in allElements)
            {
                if (element != this && element.IsBelow(computed) && element.focusable)
                {
                    // We have an element below.

                    // Check if it is closer than the current result.
                    // If it is, it's the current result.

                    // Is it nearer?
                    float distance = element.DistanceFromFast(myX, myY);

                    // Next, weight the distance by it's verticalness - that's by how much above/below the element actually looks.
                    float verticalness = element.VerticalDistanceRatio(myX, myY);

                    if (verticalness < 0.01f)
                    {
                        verticalness = 0.01f;
                    }

                    distance *= verticalness;

                    // Is it the first we've found, or is it nearer?
                    if (nearest == null || distance < nearestDistance)
                    {
                        nearest         = element;
                        nearestDistance = distance;
                    }

                    // Make sure we don't now iterate its kids:
                    allElements.SkipChildren = true;
                }
            }

            return(nearest);
        }
Exemple #38
0
 /// <summary>Checks if this element is below the given style.</summary>
 /// <returns>True if this element is below the given style.</returns>
 public bool IsBelow(ComputedStyle computed)
 {
     // Check if my bottom edge is greater than (but not equal to) the given bottom edge.
     return((Style.Computed.OffsetTop + Style.Computed.PixelHeight) > (computed.OffsetTop + computed.PixelHeight));
 }
 static InitialStyle()
 {
     s_InitialStyle = ComputedStyle.CreateInitial();
     s_InitialStyle.layoutData.Write().alignContent            = Align.FlexStart;
     s_InitialStyle.layoutData.Write().alignItems              = Align.Stretch;
     s_InitialStyle.layoutData.Write().alignSelf               = Align.Auto;
     s_InitialStyle.visualData.Write().backgroundColor         = Color.clear;
     s_InitialStyle.visualData.Write().backgroundImage         = default(Background);
     s_InitialStyle.visualData.Write().borderBottomColor       = Color.clear;
     s_InitialStyle.visualData.Write().borderBottomLeftRadius  = 0f;
     s_InitialStyle.visualData.Write().borderBottomRightRadius = 0f;
     s_InitialStyle.layoutData.Write().borderBottomWidth       = 0f;
     s_InitialStyle.visualData.Write().borderLeftColor         = Color.clear;
     s_InitialStyle.layoutData.Write().borderLeftWidth         = 0f;
     s_InitialStyle.visualData.Write().borderRightColor        = Color.clear;
     s_InitialStyle.layoutData.Write().borderRightWidth        = 0f;
     s_InitialStyle.visualData.Write().borderTopColor          = Color.clear;
     s_InitialStyle.visualData.Write().borderTopLeftRadius     = 0f;
     s_InitialStyle.visualData.Write().borderTopRightRadius    = 0f;
     s_InitialStyle.layoutData.Write().borderTopWidth          = 0f;
     s_InitialStyle.layoutData.Write().bottom           = StyleKeyword.Auto.ToLength();
     s_InitialStyle.inheritedData.Write().color         = Color.black;
     s_InitialStyle.rareData.Write().cursor             = default(Cursor);
     s_InitialStyle.layoutData.Write().display          = DisplayStyle.Flex;
     s_InitialStyle.layoutData.Write().flexBasis        = StyleKeyword.Auto.ToLength();
     s_InitialStyle.layoutData.Write().flexDirection    = FlexDirection.Column;
     s_InitialStyle.layoutData.Write().flexGrow         = 0f;
     s_InitialStyle.layoutData.Write().flexShrink       = 1f;
     s_InitialStyle.layoutData.Write().flexWrap         = Wrap.NoWrap;
     s_InitialStyle.inheritedData.Write().fontSize      = 0f;
     s_InitialStyle.layoutData.Write().height           = StyleKeyword.Auto.ToLength();
     s_InitialStyle.layoutData.Write().justifyContent   = Justify.FlexStart;
     s_InitialStyle.layoutData.Write().left             = StyleKeyword.Auto.ToLength();
     s_InitialStyle.inheritedData.Write().letterSpacing = 0f;
     s_InitialStyle.layoutData.Write().marginBottom     = 0f;
     s_InitialStyle.layoutData.Write().marginLeft       = 0f;
     s_InitialStyle.layoutData.Write().marginRight      = 0f;
     s_InitialStyle.layoutData.Write().marginTop        = 0f;
     s_InitialStyle.layoutData.Write().maxHeight        = StyleKeyword.None.ToLength();
     s_InitialStyle.layoutData.Write().maxWidth         = StyleKeyword.None.ToLength();
     s_InitialStyle.layoutData.Write().minHeight        = StyleKeyword.Auto.ToLength();
     s_InitialStyle.layoutData.Write().minWidth         = StyleKeyword.Auto.ToLength();
     s_InitialStyle.visualData.Write().opacity          = 1f;
     s_InitialStyle.visualData.Write().overflow         = OverflowInternal.Visible;
     s_InitialStyle.layoutData.Write().paddingBottom    = 0f;
     s_InitialStyle.layoutData.Write().paddingLeft      = 0f;
     s_InitialStyle.layoutData.Write().paddingRight     = 0f;
     s_InitialStyle.layoutData.Write().paddingTop       = 0f;
     s_InitialStyle.layoutData.Write().position         = Position.Relative;
     s_InitialStyle.layoutData.Write().right            = StyleKeyword.Auto.ToLength();
     s_InitialStyle.transformData.Write().rotate        = StyleKeyword.None.ToRotate();
     s_InitialStyle.transformData.Write().scale         = StyleKeyword.None.ToScale();
     s_InitialStyle.rareData.Write().textOverflow       = TextOverflow.Clip;
     s_InitialStyle.inheritedData.Write().textShadow    = default(TextShadow);
     s_InitialStyle.layoutData.Write().top = StyleKeyword.Auto.ToLength();
     s_InitialStyle.transformData.Write().transformOrigin  = TransformOrigin.Initial();
     s_InitialStyle.transitionData.Write().transitionDelay = new List <TimeValue> {
         0
     };
     s_InitialStyle.transitionData.Write().transitionDuration = new List <TimeValue> {
         0
     };
     s_InitialStyle.transitionData.Write().transitionProperty = new List <StylePropertyName> {
         "all"
     };
     s_InitialStyle.transitionData.Write().transitionTimingFunction = new List <EasingFunction> {
         EasingMode.Ease
     };
     s_InitialStyle.transformData.Write().translate = StyleKeyword.None.ToTranslate();
     s_InitialStyle.rareData.Write().unityBackgroundImageTintColor = Color.white;
     s_InitialStyle.rareData.Write().unityBackgroundScaleMode      = ScaleMode.StretchToFill;
     s_InitialStyle.inheritedData.Write().unityFont               = default(Font);
     s_InitialStyle.inheritedData.Write().unityFontDefinition     = default(FontDefinition);
     s_InitialStyle.inheritedData.Write().unityFontStyleAndWeight = FontStyle.Normal;
     s_InitialStyle.rareData.Write().unityOverflowClipBox         = OverflowClipBox.PaddingBox;
     s_InitialStyle.inheritedData.Write().unityParagraphSpacing   = 0f;
     s_InitialStyle.rareData.Write().unitySliceBottom             = 0;
     s_InitialStyle.rareData.Write().unitySliceLeft               = 0;
     s_InitialStyle.rareData.Write().unitySliceRight              = 0;
     s_InitialStyle.rareData.Write().unitySliceTop              = 0;
     s_InitialStyle.inheritedData.Write().unityTextAlign        = TextAnchor.UpperLeft;
     s_InitialStyle.inheritedData.Write().unityTextOutlineColor = Color.clear;
     s_InitialStyle.inheritedData.Write().unityTextOutlineWidth = 0f;
     s_InitialStyle.rareData.Write().unityTextOverflowPosition  = TextOverflowPosition.End;
     s_InitialStyle.inheritedData.Write().visibility            = Visibility.Visible;
     s_InitialStyle.inheritedData.Write().whiteSpace            = WhiteSpace.Normal;
     s_InitialStyle.layoutData.Write().width          = StyleKeyword.Auto.ToLength();
     s_InitialStyle.inheritedData.Write().wordSpacing = 0f;
 }
Exemple #40
0
        public override void Update(float deltaTime)
        {
            if (Animation == null || Animation.Paused)
            {
                return;
            }

            if (CurrentTime == 0f)
            {
                if (deltaTime > 0.5f)
                {
                    // Block slow frames.
                    // This is almost always only ever the very first one
                    return;
                }

                // Setup targets etc.

                // Get or create the initial value:
                Css.Value hostValue;
                Css.Value rawValue = InnerPropertyInfo.GetOrCreateValue(Animation.Animating, Animation.ComputedStyle, false, out hostValue);

                // Setup values:
                ApplyValues(rawValue, RawTarget);

                if (Animation.Duration == 0f)
                {
                    // Make sure we are exactly the right value:
                    WriteProgress(1f);

                    // Remove from update queue:
                    Stop();

                    // Tell the style it changed:
                    // Note that in grouped properties, only the last one actually runs the update.
                    RawTransformValue.Recalculate(Animation.ComputedStyle);
                    Animation.ComputedStyle.RequestPaintAll();

                    // And call the done function:
                    Animation.Finished();

                    return;
                }
            }

            CurrentTime += deltaTime;

            if (!Animation.Animating.isRooted)
            {
                // Immediately stop - the element was removed (don't call the finished event):
                Stop();

                return;
            }

            // Get the style:
            ComputedStyle computed = Animation.ComputedStyle;

            float progress = CurrentTime / Animation.TotalTime;

            if (progress >= 1f)
            {
                // Done!
                progress = 1f;

                // Remove from the update queue:
                Stop();

                // Make sure we are exactly the right value.

                if (ProgressSampler != null)
                {
                    // Map through the progression curve:
                    ProgressSampler.Goto(progress, true);
                    progress = ProgressSampler.CurrentValue;
                }

                // Write it out to the CSS value:
                WriteProgress(progress);

                // If we're the main animation (updateCss is true), tell the style it changed:
                // Note that in grouped properties, only the last one actually runs the update.
                RawTransformValue.Recalculate(computed);
                computed.RequestPaintAll();

                // And call the done function:
                Animation.Finished();

                // Stop there:
                return;
            }
            else
            {
                // Set ActiveValue by sampling from the curve (if there is one):

                if (ProgressSampler != null)
                {
                    // Map through the progression curve:
                    ProgressSampler.Goto(progress, true);
                    progress = ProgressSampler.CurrentValue;
                }

                // Read the value:
                WriteProgress(progress);
            }

            // And Tell the style it changed:
            // Note that in grouped properties, only the last one actually runs the update.
            RawTransformValue.Recalculate(computed);
            computed.RequestPaintAll();
        }
Exemple #41
0
        public static void LoadInto(TextRenderingProperty trp, List <OpenTypeFeature> features, ComputedStyle cs)
        {
            Css.Value value = cs[GlobalProperty];

            if (value == null)
            {
                return;
            }

            if (Features == null)
            {
                Features = new OpenTypeFeatureSet();
            }

            switch (value.Text)
            {
            default:
            case "normal":
                // Do nothing
                break;

            case "small-caps":

                features.Add(Features["smcp"]);

                break;

            case "all-small-caps":

                features.Add(Features["smcp"]);
                features.Add(Features["c2sc"]);

                break;

            case "petite-caps":

                features.Add(Features["pcap"]);

                break;

            case "all-petite-caps":

                features.Add(Features["pcap"]);
                features.Add(Features["c2pc"]);

                break;

            case "unicase":

                features.Add(Features["unic"]);

                break;

            case "titling-caps":

                features.Add(Features["titl"]);

                break;
            }
        }
Exemple #42
0
        public override ApplyState Apply(ComputedStyle style, Value value)
        {
            // The name of the animation:
            string name = null;

            if (value != null)
            {
                // Get the name:
                name = value.GetText(style.RenderData, this);
            }

            if (name == "none" || name == "initial" || name == "normal")
            {
                name = null;
            }

            // Get the animation:
            KeyframesRule animation = style.document.GetAnimation(name);

            if (animation == null)
            {
                // Clear:

                if (style.AnimationInstance != null)
                {
                    // Stop without triggering OnDone:
                    style.AnimationInstance.Stop(false);
                }

                // Reset matched styles
                style.ApplyMatchedStyles();

                // Ok!
                return(ApplyState.Ok);
            }

            if (style.AnimationInstance != null)
            {
                if (style.AnimationInstance.RawAnimation == animation)
                {
                    // Stop there.
                    return(ApplyState.Ok);
                }
                else
                {
                    // Stop it:
                    style.AnimationInstance.Stop(false);

                    // Reset matched:
                    style.ApplyMatchedStyles();
                }
            }

            // Create an instance:
            style.AnimationInstance = new KeyframesAnimationInstance(style, animation);

            // Reapply other values:
            Reapply(style, "animation-duration");
            Reapply(style, "animation-timing-function");
            Reapply(style, "animation-delay");
            Reapply(style, "animation-iteration-count");
            Reapply(style, "animation-direction");
            Reapply(style, "animation-fill-mode");
            Reapply(style, "animation-play-state");

            // Start it:
            style.AnimationInstance.Start();

            // Ok!
            return(ApplyState.Ok);
        }
Exemple #43
0
        private void OnTick()
        {
            // Grab the computed style:
            ComputedStyle style = Style.Computed;

            float amount = ScrollAmount;

            // Is it odd? If so, it travels in the inverted direction.
            if (((int)Direction & 1) == 1)
            {
                // Invert the direction:
                amount = -ScrollAmount;
            }

            float scrollLeft = style.ScrollLeft;
            float scrollTop  = style.ScrollTop;

            if ((int)Direction <= 2)
            {
                // Vertical scroll:
                scrollTop += amount;

                // Grab the content height:
                float contentHeight = style.ContentHeight;

                // Grab the parent height:
                float height = style.InnerHeight;

                switch (Behaviour)
                {
                case MarqueeBehaviour.Scroll:

                    if (scrollTop < -height)
                    {
                        // Wrap:
                        scrollTop = contentHeight;

                        Wrapped();
                    }
                    else if (scrollTop > contentHeight)
                    {
                        // Wrap:
                        scrollTop = -height;

                        Wrapped();
                    }

                    break;

                case MarqueeBehaviour.Alternate:

                    float minimum = -(height - contentHeight);

                    if (minimum >= 0)
                    {
                        // No space to bounce anyway.
                        return;
                    }

                    if (scrollTop > 0f)
                    {
                        // Reset:
                        scrollTop = 0f;

                        // Flip the direction.
                        if (Direction == MarqueeDirection.Up)
                        {
                            Direction = MarqueeDirection.Down;
                        }
                        else
                        {
                            Direction = MarqueeDirection.Up;
                        }

                        Bounced();
                    }
                    else if (scrollTop < minimum)
                    {
                        scrollTop = minimum;

                        // Flip the direction.
                        if (Direction == MarqueeDirection.Up)
                        {
                            Direction = MarqueeDirection.Down;
                        }
                        else
                        {
                            Direction = MarqueeDirection.Up;
                        }

                        Bounced();
                    }

                    break;
                }
            }
            else
            {
                // Horizontal scroll:
                scrollLeft += amount;

                // Grab the content width:
                float contentWidth = style.ContentWidth;

                // Grab the parent width:
                float width = style.InnerWidth;

                switch (Behaviour)
                {
                case MarqueeBehaviour.Scroll:

                    if (scrollLeft < -width)
                    {
                        // Wrap:
                        scrollLeft = contentWidth;

                        Wrapped();
                    }
                    else if (scrollLeft > contentWidth)
                    {
                        // Wrap:
                        scrollLeft = -width;

                        Wrapped();
                    }

                    break;

                case MarqueeBehaviour.Alternate:

                    float minimum = -(width - contentWidth);

                    if (minimum >= 0f)
                    {
                        // No space to bounce anyway.
                        return;
                    }

                    if (scrollLeft > 0f)
                    {
                        // Reset:
                        scrollLeft = 0f;

                        // Flip the direction.
                        if (Direction == MarqueeDirection.Left)
                        {
                            Direction = MarqueeDirection.Right;
                        }
                        else
                        {
                            Direction = MarqueeDirection.Left;
                        }

                        Bounced();
                    }
                    else if (scrollLeft < minimum)
                    {
                        scrollLeft = minimum;

                        // Flip the direction.
                        if (Direction == MarqueeDirection.Left)
                        {
                            Direction = MarqueeDirection.Right;
                        }
                        else
                        {
                            Direction = MarqueeDirection.Left;
                        }

                        Bounced();
                    }

                    break;
                }
            }

            // Scroll now:
            scrollTo(scrollLeft, scrollTop);

            // Request a redraw:
            style.RequestLayout();
        }
Exemple #44
0
        public override void Apply(ComputedStyle style, Value value)
        {
            // Got any text at all?:
            if (GetText(style) == null)
            {
                return;
            }

            // Apply the property:
            if (value == null || value.Text == "none")
            {
                // Clear the stroke:
                style.TextStroke = null;
            }
            else
            {
                // The stroke properties:
                int   blur   = 0;
                Color colour = Color.black;

                int thickness = value[0].PX;

                if (thickness == 0)
                {
                    style.TextStroke = null;
                }
                else
                {
                    StrokeData data = style.TextStroke;

                    if (data == null)
                    {
                        data             = new StrokeData();
                        style.TextStroke = data;
                    }

                    data.Thickness = thickness;

                    // Grab the blur:
                    Value innerValue = value[1];

                    if (innerValue.Type == ValueType.Color)
                    {
                        colour = innerValue.ToColor();
                    }
                    else
                    {
                        blur = innerValue.PX;

                        // Grab the colour:
                        innerValue = value[2];

                        if (innerValue.Type == ValueType.Color)
                        {
                            colour = innerValue.ToColor();
                        }
                    }

                    data.Colour = colour;
                    data.Blur   = blur;
                }
            }

            // Apply the changes - doesn't change anything about the actual text, so we just want a layout:
            style.RequestLayout();
        }
Exemple #45
0
        /// <summary>Resolves the marker for the given computed style.</summary>
        public static string GetOrdinal(ComputedStyle style, bool prefixed)
        {
            Node             ele = style.Element;
            HtmlOListElement ol  = ele.parentNode as HtmlOListElement;

            int  start;
            bool reversed;

            if (ol == null)
            {
                start    = 1;
                reversed = false;
            }
            else
            {
                start    = ol.Start_;
                reversed = ol.Reversed_;
            }

            // Get the list style type for this element:
            Css.Value value = style[Css.Properties.ListStyleType.GlobalProperty];
            int       index;

            if (value == null)
            {
                index = ele.childElementIndex;

                if (reversed)
                {
                    index = start - index;
                }
                else
                {
                    index += start;
                }

                // Disc is the default:
                return(style.reflowDocument.GetOrdinal(index, "disc", prefixed) + " ");
            }
            else if (value.IsType(typeof(Css.Keywords.None)))
            {
                return("");
            }

            index = ele.childElementIndex;

            if (reversed)
            {
                index = start - index;
            }
            else
            {
                index += start;
            }

            // Get textual name:
            string name = value.Text;

            // Is it a named set?
            string result = style.reflowDocument.GetOrdinal(index, name, prefixed);

            if (result == null)
            {
                // It's possibly the symbols() function or alternatively it's just some text.
                // Assume it's some text for now!
                result = value.Text;
            }

            return(result);
        }
Exemple #46
0
        public void ResolveStyle(bool recursive = false)
        {
            markedStyleResolve          = false;
            markedStyleResolveRecursive = false;

            var inheritedChanges = ComputedStyle.HasInheritedChanges;


            var inlineStyles  = RuleHelpers.GetRuleDic(Style);
            var inlineLayouts = RuleHelpers.GetLayoutDic(Style);

            if (inlineLayouts != null)
            {
                foreach (var l in inlineLayouts)
                {
                    inlineStyles[l.prop.name] = l.value;
                }
            }

            List <RuleTreeNode <StyleData> > matchingRules;

            if (Tag == "_before")
            {
                matchingRules = Parent.BeforeRules;
            }
            else if (Tag == "_after")
            {
                matchingRules = Parent.AfterRules;
            }
            else
            {
                matchingRules = Context.StyleTree.GetMatchingRules(this).ToList();
            }

            var importantIndex = Math.Max(0, matchingRules.FindIndex(x => x.Specifity <= RuleHelpers.ImportantSpecifity));
            var cssStyles      = new List <Dictionary <string, object> > {
            };

            for (int i = 0; i < importantIndex; i++)
            {
                cssStyles.AddRange(matchingRules[i].Data?.Rules);
            }
            cssStyles.Add(inlineStyles);
            for (int i = importantIndex; i < matchingRules.Count; i++)
            {
                cssStyles.AddRange(matchingRules[i].Data?.Rules);
            }

            ComputedStyle.CssStyles = cssStyles;
            ApplyStyles();
            ApplyLayoutStyles();
            ComputedStyle.MarkChangesSeen();


            if (inheritedChanges || recursive)
            {
                BeforeRules = Context.StyleTree.GetMatchingBefore(this).ToList();
                //if (BeforeRules.Count > 0) AddBefore();
                //else RemoveBefore();
                BeforePseudo?.ResolveStyle();

                foreach (var child in Children)
                {
                    child.ResolveStyle(true);
                }

                AfterRules = Context.StyleTree.GetMatchingAfter(this).ToList();
                //if (AfterRules.Count > 0) AddAfter();
                //else RemoveAfter();
                AfterPseudo?.ResolveStyle();
            }
        }
Exemple #47
0
        public static void LoadInto(TextRenderingProperty trp, List <OpenTypeFeature> features, ComputedStyle cs)
        {
            Css.Value value = cs[GlobalProperty];

            if (value == null)
            {
                return;
            }

            if (Features == null)
            {
                Features = new OpenTypeFeatureSet();
            }

            for (int i = 0; i < value.Count; i++)
            {
                Css.Value current = value[i];

                // The feature name:
                string name;

                if (current is Css.ValueSet)
                {
                    // E.g. "swsh" 2
                    name = current[0].Text;

                    // Get the value (may be 'on' or 'off'):
                    Css.Value par = current[1];

                    if (par.Type == ValueType.Text)
                    {
                        if (par.Text == "off")
                        {
                            continue;
                        }

                        // name followed by 'on'.
                        features.Add(Features[name]);
                    }
                    else
                    {
                        int param = (int)current[1].GetRawDecimal();

                        features.Add(new OpenTypeFeature(name, param));
                    }
                }
                else
                {
                    // It's just a feature name:
                    name = current.Text;

                    features.Add(Features[name]);
                }
            }
        }
Exemple #48
0
        /*
         * public override void OnChildrenLoaded(){
         *
         *      // Construct the selector structure now:
         *      // Style.Computed.RefreshStructure();
         *
         * }
         */

        /// <summary>Part of shrink-to-fit. Computes the maximum and minimum possible width for an element.
        /// This does not include the elements own padding/margin/border.</summary>
        public virtual void GetWidthBounds(out float min, out float max)
        {
            min = 0f;
            max = 0f;

            // For each child, get its width bounds too.
            if (RenderData.FirstBox == null)
            {
                return;
            }

            if (childNodes_ != null)
            {
                // Current line:
                float cMin = 0f;
                float cMax = 0f;

                for (int i = 0; i < childNodes_.length; i++)
                {
                    Node child = childNodes_[i];

                    IRenderableNode renderable = (child as IRenderableNode);

                    if (renderable == null)
                    {
                        continue;
                    }

                    float bMin;
                    float bMax;

                    if (child is RenderableTextNode)
                    {
                        // Always get bounds:
                        renderable.GetWidthBounds(out bMin, out bMax);
                    }
                    else
                    {
                        // Get the first box from the render data:
                        ComputedStyle  cs  = renderable.ComputedStyle;
                        RenderableData rd  = renderable.RenderData;
                        LayoutBox      box = rd.FirstBox;

                        if (box == null)
                        {
                            continue;
                        }

                        int displayMode = box.DisplayMode;

                        // If it's inline (or float) then it's additive to the current line.
                        if ((displayMode & DisplayMode.OutsideBlock) != 0 && box.FloatMode == FloatMode.None)
                        {
                            // Line break!
                            cMin = 0f;
                            cMax = 0f;
                        }

                        // Get an explicit width:
                        bool wasAuto;
                        bMin = rd.GetWidth(true, out wasAuto);

                        if (bMin == float.MinValue)
                        {
                            // Get the bounds:
                            renderable.GetWidthBounds(out bMin, out bMax);
                        }
                        else
                        {
                            bMax = bMin;
                        }

                        // Add margins etc (NB: These are calculated twice due to %):
                        BoxStyle padding = cs.GetPaddingBox(displayMode);
                        BoxStyle border  = cs.GetBorderBox(displayMode);

                        // Compute the initial margin:
                        bool     marginAuto = false;
                        BoxStyle margin     = cs.GetMarginBox(displayMode, box.FloatMode, ref marginAuto);

                        float extraStyle = (
                            border.Left + border.Right +
                            padding.Left + padding.Right +
                            margin.Left + margin.Right
                            );

                        bMin += extraStyle;
                        bMax += extraStyle;
                    }

                    // Apply to line:
                    cMin += bMin;
                    cMax += bMax;

                    // Longest line?
                    if (cMin > min)
                    {
                        min = cMin;
                    }

                    if (cMax > max)
                    {
                        max = cMax;
                    }
                }
            }
        }
Exemple #49
0
        public override void Apply(ComputedStyle style, Value value)
        {
            // Got text at all?:
            if (GetText(style) == null)
            {
                return;
            }

            // Apply the property:
            if (value == null || value.Text == "none")
            {
                // Clear the shadow:
                style.TextShadow = null;
            }
            else
            {
                // The glow properties:
                int   blur   = 0;
                Color colour = Color.black;

                ShadowData data = style.TextShadow;

                if (data == null)
                {
                    data             = new ShadowData();
                    style.TextShadow = data;
                }

                data.HOffset = value[0].PX;
                data.VOffset = value[1].PX;

                // Grab the blur:
                Value innerValue = value[2];

                if (innerValue.Type == ValueType.Color)
                {
                    colour = innerValue.ToColor();
                }
                else
                {
                    blur = innerValue.PX;

                    // Grab the colour:
                    innerValue = value[3];

                    if (innerValue.Type == ValueType.Color)
                    {
                        colour = innerValue.ToColor();
                    }
                }

                if (colour.a == 1f)
                {
                    // Default transparency:
                    colour.a = 0.8f;
                }

                data.Colour = colour;
                data.Blur   = blur;
            }

            // Apply the changes - doesn't change anything about the actual text, so we just want a layout:
            style.RequestLayout();
        }
        public override void Apply(ComputedStyle style, Value value)
        {
            style.AutoMarginX = style.AutoMarginY = false;

            if (value == null)
            {
                style.MarginTop  = style.MarginBottom = 0;
                style.MarginLeft = style.MarginRight = 0;
            }
            else
            {
                // Top:
                Value innerValue = value[0];

                if (innerValue != null)
                {
                    if (innerValue.IsAuto())
                    {
                        style.AutoMarginY = true;
                    }
                    else
                    {
                        style.MarginTop = innerValue.PX;
                    }
                }
                else
                {
                    style.MarginTop = 0;
                }

                // Right:
                innerValue = value[1];

                if (innerValue != null)
                {
                    if (innerValue.IsAuto())
                    {
                        style.AutoMarginX = true;
                    }
                    else
                    {
                        style.MarginRight = innerValue.PX;
                    }
                }
                else
                {
                    style.MarginRight = 0;
                }

                // Bottom:
                innerValue = value[2];

                if (innerValue != null)
                {
                    if (!style.AutoMarginY || !innerValue.IsAuto())
                    {
                        style.AutoMarginY  = false;
                        style.MarginBottom = innerValue.PX;
                    }
                }
                else
                {
                    style.MarginBottom = 0;
                }

                // Left:
                innerValue = value[3];
                if (innerValue != null)
                {
                    if (!style.AutoMarginX || !innerValue.IsAuto())
                    {
                        style.AutoMarginX = false;
                        style.MarginLeft  = innerValue.PX;
                    }
                }
                else
                {
                    style.MarginLeft = 0;
                }
            }

            style.SetSize();

            style.RequestLayout();
        }
        public static void LoadInto(TextRenderingProperty trp, List <OpenTypeFeature> features, ComputedStyle cs)
        {
            Css.Value value = cs[GlobalProperty];

            if (value == null)
            {
                return;
            }

            if (Features == null)
            {
                Features = new OpenTypeFeatureSet();
            }

            if (value is CssFunction)
            {
                value.GetOpenTypeFeatures(trp, features);
                return;
            }

            for (int i = 0; i < value.Count; i++)
            {
                Css.Value current = value[i];

                if (current is CssFunction)
                {
                    // E.g. stylistic(..)
                    current.GetOpenTypeFeatures(trp, features);
                }
                else
                {
                    switch (current.Text)
                    {
                    default:
                    case "normal":
                        // Do nothing
                        break;

                    case "historical-forms":

                        features.Add(Features["hist"]);

                        break;
                    }
                }
            }
        }
Exemple #52
0
        public override bool OnAttributeChange(string property)
        {
            if (base.OnAttributeChange(property))
            {
                return(true);
            }

            if (property == "path")
            {
                // Go get the camera now!

                // Clear any existing one:
                Camera = null;

                Callback.MainThread(delegate(){
                    // Grab the path itself:
                    string path = this["path"];

                    // Get it:
                    GameObject gameObject = GameObject.Find(path);

                    if (gameObject != null)
                    {
                        // Grab the camera:
                        Camera = gameObject.GetComponent <Camera>();
                    }

                    if (Camera != null)
                    {
                        ComputedStyle computed = Style.Computed;

                        // Create RT if one is needed:
                        RenderTexture rt = Camera.targetTexture;

                        if (rt == null)
                        {
                            // Apply:
                            ApplyNewRenderTexture((int)computed.InnerWidth, (int)computed.InnerHeight);
                        }
                        else
                        {
                            // Apply to background:
                            image = rt;
                        }
                    }

                    ParentMask();
                });

                return(true);
            }
            else if (property == "noresize")
            {
                // Can't resize if noresize is not null:
                CanResize = (this["noresize"] == null);
            }
            else if (property == "mask")
            {
                // We've got a mask!

                // Grab the file path:
                string maskFile = this["mask"];

                if (maskFile == null)
                {
                    SetMask(null);
                }
                else
                {
                    // Create a package to get the mask:
                    ImagePackage package = new ImagePackage(maskFile, document.basepath);

                    package.onload = delegate(UIEvent e){
                        // Apply the mask:
                        PictureFormat pict = package.Contents as PictureFormat;

                        if (pict != null)
                        {
                            SetMask(pict.Image);
                        }
                    };

                    // Go get it:
                    package.send();
                }

                return(true);
            }

            return(false);
        }
        public override ApplyState Apply(ComputedStyle style, Value value)
        {
            // Get the background image:
            BackgroundImage image = GetBackground(style);

            Value offsetX = null;
            Value offsetY = null;
            float xOrigin = 0f;
            float yOrigin = 0f;

            if (value != null)
            {
                // Set true when center has been handled once before.
                bool center = false;
                bool xAxis  = true;

                // Get the inner value count:
                int count = value.Count;

                if (count == 1 || value is CssFunction)
                {
                    if (value.Type == ValueType.Text)
                    {
                        string text = value.Text;

                        // Occurs twice:
                        GetOrigin(text, ref xOrigin, ref yOrigin, ref center, ref xAxis);
                        GetOrigin(text, ref xOrigin, ref yOrigin, ref center, ref xAxis);
                    }
                    else
                    {
                        offsetX = offsetY = value;
                    }
                }
                else
                {
                    // Loops for e.g. right 10% top 5%
                    for (int i = 0; i < count; i++)
                    {
                        // Grab the inner value:
                        Value innerValue = value[i];

                        // Is it text?
                        if (innerValue.Type == ValueType.Text)
                        {
                            // Yep!
                            GetOrigin(innerValue.Text, ref xOrigin, ref yOrigin, ref center, ref xAxis);
                        }
                        else
                        {
                            // It's a %/ px/ some other fixed unit.
                            if (xAxis)
                            {
                                xAxis   = false;
                                offsetX = innerValue;
                            }
                            else
                            {
                                offsetY = innerValue;
                            }
                        }
                    }
                }
            }

            image.OffsetOriginX = xOrigin;
            image.OffsetOriginY = yOrigin;
            image.OffsetX       = offsetX;
            image.OffsetY       = offsetY;

            // Request a layout:
            image.RequestLayout();

            // Ok!
            return(ApplyState.Ok);
        }
Exemple #54
0
 /// <summary>Checks if this element is to the left of the given style.</summary>
 /// <returns>True if this element is to the left of the given style.</returns>
 public bool IsLeftOf(ComputedStyle computed)
 {
     // Check if my left edge is before (but not equal to) the given left edge.
     return(Style.Computed.OffsetLeft < computed.OffsetLeft);
 }
 static InitialStyle()
 {
     InitialStyle.s_InitialStyle = ComputedStyle.CreateUninitialized(true);
     InitialStyle.s_InitialStyle.nonInheritedData.alignContent            = Align.FlexStart;
     InitialStyle.s_InitialStyle.nonInheritedData.alignItems              = Align.Stretch;
     InitialStyle.s_InitialStyle.nonInheritedData.alignSelf               = Align.Auto;
     InitialStyle.s_InitialStyle.nonInheritedData.backgroundColor         = Color.clear;
     InitialStyle.s_InitialStyle.nonInheritedData.backgroundImage         = default(StyleBackground);
     InitialStyle.s_InitialStyle.nonInheritedData.borderBottomColor       = Color.clear;
     InitialStyle.s_InitialStyle.nonInheritedData.borderBottomLeftRadius  = 0f;
     InitialStyle.s_InitialStyle.nonInheritedData.borderBottomRightRadius = 0f;
     InitialStyle.s_InitialStyle.nonInheritedData.borderBottomWidth       = 0f;
     InitialStyle.s_InitialStyle.nonInheritedData.borderLeftColor         = Color.clear;
     InitialStyle.s_InitialStyle.nonInheritedData.borderLeftWidth         = 0f;
     InitialStyle.s_InitialStyle.nonInheritedData.borderRightColor        = Color.clear;
     InitialStyle.s_InitialStyle.nonInheritedData.borderRightWidth        = 0f;
     InitialStyle.s_InitialStyle.nonInheritedData.borderTopColor          = Color.clear;
     InitialStyle.s_InitialStyle.nonInheritedData.borderTopLeftRadius     = 0f;
     InitialStyle.s_InitialStyle.nonInheritedData.borderTopRightRadius    = 0f;
     InitialStyle.s_InitialStyle.nonInheritedData.borderTopWidth          = 0f;
     InitialStyle.s_InitialStyle.nonInheritedData.bottom         = StyleKeyword.Auto;
     InitialStyle.s_InitialStyle.inheritedData.color             = Color.black;
     InitialStyle.s_InitialStyle.nonInheritedData.cursor         = default(StyleCursor);
     InitialStyle.s_InitialStyle.nonInheritedData.display        = DisplayStyle.Flex;
     InitialStyle.s_InitialStyle.nonInheritedData.flexBasis      = StyleKeyword.Auto;
     InitialStyle.s_InitialStyle.nonInheritedData.flexDirection  = FlexDirection.Column;
     InitialStyle.s_InitialStyle.nonInheritedData.flexGrow       = 0f;
     InitialStyle.s_InitialStyle.nonInheritedData.flexShrink     = 1f;
     InitialStyle.s_InitialStyle.nonInheritedData.flexWrap       = Wrap.NoWrap;
     InitialStyle.s_InitialStyle.inheritedData.fontSize          = 0f;
     InitialStyle.s_InitialStyle.nonInheritedData.height         = StyleKeyword.Auto;
     InitialStyle.s_InitialStyle.nonInheritedData.justifyContent = Justify.FlexStart;
     InitialStyle.s_InitialStyle.nonInheritedData.left           = StyleKeyword.Auto;
     InitialStyle.s_InitialStyle.nonInheritedData.marginBottom   = 0f;
     InitialStyle.s_InitialStyle.nonInheritedData.marginLeft     = 0f;
     InitialStyle.s_InitialStyle.nonInheritedData.marginRight    = 0f;
     InitialStyle.s_InitialStyle.nonInheritedData.marginTop      = 0f;
     InitialStyle.s_InitialStyle.nonInheritedData.maxHeight      = StyleKeyword.None;
     InitialStyle.s_InitialStyle.nonInheritedData.maxWidth       = StyleKeyword.None;
     InitialStyle.s_InitialStyle.nonInheritedData.minHeight      = StyleKeyword.Auto;
     InitialStyle.s_InitialStyle.nonInheritedData.minWidth       = StyleKeyword.Auto;
     InitialStyle.s_InitialStyle.nonInheritedData.opacity        = 1f;
     InitialStyle.s_InitialStyle.nonInheritedData.overflow       = OverflowInternal.Visible;
     InitialStyle.s_InitialStyle.nonInheritedData.paddingBottom  = 0f;
     InitialStyle.s_InitialStyle.nonInheritedData.paddingLeft    = 0f;
     InitialStyle.s_InitialStyle.nonInheritedData.paddingRight   = 0f;
     InitialStyle.s_InitialStyle.nonInheritedData.paddingTop     = 0f;
     InitialStyle.s_InitialStyle.nonInheritedData.position       = Position.Relative;
     InitialStyle.s_InitialStyle.nonInheritedData.right          = StyleKeyword.Auto;
     InitialStyle.s_InitialStyle.nonInheritedData.textOverflow   = TextOverflow.Clip;
     InitialStyle.s_InitialStyle.nonInheritedData.top            = StyleKeyword.Auto;
     InitialStyle.s_InitialStyle.nonInheritedData.unityBackgroundImageTintColor = Color.white;
     InitialStyle.s_InitialStyle.nonInheritedData.unityBackgroundScaleMode      = ScaleMode.StretchToFill;
     InitialStyle.s_InitialStyle.inheritedData.unityFont = default(StyleFont);
     InitialStyle.s_InitialStyle.inheritedData.unityFontStyleAndWeight      = FontStyle.Normal;
     InitialStyle.s_InitialStyle.nonInheritedData.unityOverflowClipBox      = OverflowClipBox.PaddingBox;
     InitialStyle.s_InitialStyle.nonInheritedData.unitySliceBottom          = 0;
     InitialStyle.s_InitialStyle.nonInheritedData.unitySliceLeft            = 0;
     InitialStyle.s_InitialStyle.nonInheritedData.unitySliceRight           = 0;
     InitialStyle.s_InitialStyle.nonInheritedData.unitySliceTop             = 0;
     InitialStyle.s_InitialStyle.inheritedData.unityTextAlign               = TextAnchor.UpperLeft;
     InitialStyle.s_InitialStyle.nonInheritedData.unityTextOverflowPosition = TextOverflowPosition.End;
     InitialStyle.s_InitialStyle.inheritedData.visibility = Visibility.Visible;
     InitialStyle.s_InitialStyle.inheritedData.whiteSpace = WhiteSpace.Normal;
     InitialStyle.s_InitialStyle.nonInheritedData.width   = StyleKeyword.Auto;
 }
Exemple #56
0
 /// <summary>Checks if this element is to the right of the given style.</summary>
 /// <returns>True if this element is to the right of the given style.</returns>
 public bool IsRightOf(ComputedStyle computed)
 {
     // Check if my right edge is after (but not equal to) the given right edge.
     return((Style.Computed.OffsetLeft + Style.Computed.PixelWidth) > (computed.OffsetLeft + computed.PixelWidth));
 }
Exemple #57
0
 public override ApplyState Apply(ComputedStyle style, Value value)
 {
     // Ok!
     return(ApplyState.Ok);
 }
Exemple #58
0
 /// <summary>Checks if this element is above the given style.</summary>
 /// <returns>True if this element is above the given style.</returns>
 public bool IsAbove(ComputedStyle computed)
 {
     // Check if my top edge is less than (but not equal to) the given top edge.
     return(Style.Computed.OffsetTop < computed.OffsetTop);
 }
Exemple #59
0
        public virtual void ApplyStyles()
        {
            Element.style.backgroundColor = StylingHelpers.GetStyleColor(ComputedStyle, StyleProperties.backgroundColor);
            Element.style.color           = StylingHelpers.GetStyleColor(ComputedStyle, StyleProperties.color);
            Element.style.textOverflow    = StylingHelpers.GetStyleEnumCustom <TextOverflow>(ComputedStyle, StyleProperties.textOverflow);
            Element.style.visibility      = StylingHelpers.GetStyleBoolToEnum(ComputedStyle, StyleProperties.visibility, Visibility.Visible, Visibility.Hidden);
            Element.style.opacity         = StylingHelpers.GetStyleFloat(ComputedStyle, StyleProperties.opacity);
            Element.style.whiteSpace      = StylingHelpers.GetStyleBoolToEnum(ComputedStyle, StyleProperties.textWrap, WhiteSpace.Normal, WhiteSpace.NoWrap);

            if (ComputedStyle.HasValue(StyleProperties.fontSize))
            {
                Element.style.fontSize = ComputedStyle.fontSizeActual;
            }
            else
            {
                Element.style.fontSize = StyleKeyword.Null;
            }

            Element.style.borderBottomLeftRadius  = StylingHelpers.GetStyleBorderRadius(ComputedStyle, StyleProperties.borderBottomLeftRadius);
            Element.style.borderBottomRightRadius = StylingHelpers.GetStyleBorderRadius(ComputedStyle, StyleProperties.borderBottomRightRadius);
            Element.style.borderTopLeftRadius     = StylingHelpers.GetStyleBorderRadius(ComputedStyle, StyleProperties.borderTopLeftRadius);
            Element.style.borderTopRightRadius    = StylingHelpers.GetStyleBorderRadius(ComputedStyle, StyleProperties.borderTopRightRadius);

            Element.style.borderBottomColor = StylingHelpers.GetStyleBorderColor(ComputedStyle, StyleProperties.borderBottomColor);
            Element.style.borderTopColor    = StylingHelpers.GetStyleBorderColor(ComputedStyle, StyleProperties.borderTopColor);
            Element.style.borderLeftColor   = StylingHelpers.GetStyleBorderColor(ComputedStyle, StyleProperties.borderLeftColor);
            Element.style.borderRightColor  = StylingHelpers.GetStyleBorderColor(ComputedStyle, StyleProperties.borderRightColor);

            if (ComputedStyle.HasValue(StyleProperties.backgroundImage))
            {
                ComputedStyle.backgroundImage?.Get(Context, tx => Element.style.backgroundImage = tx);
            }
            else
            {
                Element.style.backgroundImage = StyleKeyword.Null;
            }

            if (ComputedStyle.HasValue(StyleProperties.fontStyle) || ComputedStyle.HasValue(StyleProperties.fontWeight))
            {
                Element.style.unityFontStyleAndWeight = StylingHelpers.ConvertFontStyle(ComputedStyle.fontStyle, ComputedStyle.fontWeight);
            }
            else
            {
                Element.style.unityFontStyleAndWeight = StyleKeyword.Null;
            }


            if (ComputedStyle.HasValue(StyleProperties.backgroundImage) && ComputedStyle.HasValue(StyleProperties.backgroundColor))
            {
                Element.style.unityBackgroundImageTintColor = ComputedStyle.backgroundColor;
            }
            else
            {
                Element.style.unityBackgroundImageTintColor = StyleKeyword.Null;
            }


            if (ComputedStyle.HasValue(StyleProperties.textAlign))
            {
                if (StylingHelpers.TextAlignMap.TryGetValue(ComputedStyle.textAlign, out var value))
                {
                    Element.style.unityTextAlign = value;
                }
                else
                {
                    Element.style.unityTextAlign = TextAnchor.MiddleCenter;
                }
            }
            else
            {
                Element.style.unityTextAlign = StyleKeyword.Null;
            }


            if (ComputedStyle.HasValue(StyleProperties.fontFamily))
            {
                if (ComputedStyle.fontFamily != null)
                {
                    ComputedStyle.fontFamily?.Get(Context, x =>
                    {
                        if (x?.sourceFontFile)
                        {
                            Element.style.unityFont = x?.sourceFontFile;
                        }
                        else
                        {
                            Element.style.unityFont = EditorResourcesHelper.DefaultFont;
                        }
                    });
                }
            }
            else
            {
                Element.style.unityFont = StyleKeyword.Null;
            }


            if (ComputedStyle.HasValue(StyleProperties.cursor))
            {
                var cursor = EditorResourcesHelper.UtilityCursorClassPrefix + ComputedStyle.cursor;
                if (currentCursor != cursor)
                {
                    if (currentCursor != null)
                    {
                        Element.RemoveFromClassList(currentCursor);
                        currentCursor = null;
                    }
                    if (cursor != null)
                    {
                        currentCursor = cursor;
                        Element.AddToClassList(currentCursor);
                    }
                }
            }
            else if (currentCursor != null)
            {
                Element.RemoveFromClassList(currentCursor);
                currentCursor = null;
            }

            // Transforms

            //Element.transform.position -= (Vector3)(Element.layout.size / 2);

            if (ComputedStyle.HasValue(StyleProperties.scale))
            {
                Element.transform.scale = new Vector3(ComputedStyle.scale.x, ComputedStyle.scale.y, 1);
            }
            else
            {
                Element.transform.scale = Vector3.one;
            }

            if (ComputedStyle.HasValue(StyleProperties.rotate))
            {
                Element.transform.rotation = Quaternion.Euler(ComputedStyle.rotate);
            }
            else
            {
                Element.transform.rotation = Quaternion.identity;
            }

            if (ComputedStyle.HasValue(StyleProperties.translate))
            {
                Element.transform.position = ComputedStyle.translate.AsVector();
            }
            else
            {
                Element.transform.position = Vector3.zero;
            }

            //Element.transform.position += (Vector3)(Element.layout.size / 2);
        }
Exemple #60
0
        /// <summary>Scrolls this scrollbar by the given number of pixels, optionally relative to a fixed point on the bar.
        /// Note that this may fail if the scrollbar cannot scroll any further.</summary>
        /// <param name="pixels">The number of pixels to scroll this bar by.</param>
        /// <param name="fromCurrent">True if pixels is relative to where the thumb currently is. False if pixels is relative
        /// to where the bar was when the mouse was clicked. See e.g. <see cref="PowerUI.VScrollTabTag.StartY"/>.</param>
        /// <param name="scrollTarget">True if the target should also be scrolled.</param>
        public void ScrollBy(float pixels, bool fromCurrent, bool scrollTarget)
        {
            // Scroll it by pixels from Start.
            float newLocation     = pixels;
            float currentPosition = Position;

            LayoutBox box = RenderData.FirstBox;

            if (fromCurrent)
            {
                newLocation += currentPosition;
            }
            else
            {
                newLocation += Start;
            }

            // Get the size of the button before the tab:
            float sizeBefore = StartArrowSize;

            float barSize = BarSize;

            float max = barSize + sizeBefore;

            if (IsVertical)
            {
                max -= box.Height;
            }
            else
            {
                max -= box.Width;
            }

            if (newLocation < sizeBefore)
            {
                newLocation = sizeBefore;
            }
            else if (newLocation > max)
            {
                newLocation = max;
            }

            if (newLocation == currentPosition)
            {
                return;
            }

            if (IsVertical)
            {
                Style.top = newLocation + "fpx";
            }
            else
            {
                Style.left = newLocation + "fpx";
            }

            // Fire a change event on the scrollbar:
            Dom.Event e = new Dom.Event("change");
            e.SetTrusted();
            ScrollBar.dispatchEvent(e);

            if (scrollTarget)
            {
                // Get info for the target:
                HtmlElement   target   = ScrollBar.scrollTarget;
                ComputedStyle targetCs = target.style.Computed;
                box = targetCs.FirstBox;

                if (target != null && box != null)
                {
                    // Get the progress:
                    float progress = (newLocation - sizeBefore) / barSize;

                    // Update CSS:
                    if (IsVertical)
                    {
                        targetCs.ChangeTagProperty("scroll-top", new Css.Units.DecimalUnit(progress * box.ContentHeight));
                    }
                    else
                    {
                        targetCs.ChangeTagProperty("scroll-left", new Css.Units.DecimalUnit(progress * box.ContentWidth));
                    }

                    // And request a redraw:
                    target.htmlDocument.RequestLayout();
                }
            }
        }