public ScreenMediaType(ReflowDocument doc) { // Load all the values now: Css.Value width = new Css.Units.PxUnit(Width); Css.Value height = new Css.Units.PxUnit(Height); Css.Value aspect = new Css.Units.DecimalUnit((float)Width / (float)Height); // Pull in the default values: // Note that if any are numeric and 0, it treats it as a null. // (which in turn makes the feature unavailable, as expected by the HasFeature property). this["width"] = width; this["height"] = height; this["device-width"] = width; this["device-height"] = height; this["aspect-ratio"] = aspect; this["device-aspect-ratio"] = aspect; this["orientation"] = new Css.Units.TextUnit(Landscape?"landscape":"portrait"); this["resolution"] = new Css.Units.DecimalUnit(Resolution); this["color"] = new Css.Units.DecimalUnit(Color); this["color-index"] = new Css.Units.DecimalUnit(ColorIndex); this["monochrome"] = new Css.Units.DecimalUnit(Monochrome); this["scan"] = new Css.Units.TextUnit(Scan); this["grid"] = new Css.Units.DecimalUnit(Grid); // Ready! Ready(doc); }
protected override Value Clone() { DecimalUnit result = new DecimalUnit(); result.Type = Type; result.RawValue = RawValue; return(result); }
public ColourUnit(float r, float g, float b) { Count = 4; this[0] = new DecimalUnit(r); this[1] = new DecimalUnit(g); this[2] = new DecimalUnit(b); this[3] = new DecimalUnit(1f); }
public ColourUnit(Color col) { Count = 4; this[0] = new DecimalUnit(col.r); this[1] = new DecimalUnit(col.g); this[2] = new DecimalUnit(col.b); this[3] = new DecimalUnit(col.a); }
public override bool Equals(Value value) { if (value == null) { return(false); } DecimalUnit du = value as DecimalUnit; if (du == null || value.GetType() != GetType()) { return(false); } return(du.RawValue == RawValue); }
/// <summary>Sets this colour from the given hex string.</summary> public void SetHex(string hex) { int r; int g; int b; int a; ColourMap.GetHexColour(hex, out r, out g, out b, out a); Count = 4; this[0] = new DecimalUnit((float)r / 255f); this[1] = new DecimalUnit((float)g / 255f); this[2] = new DecimalUnit((float)b / 255f); this[3] = new DecimalUnit((float)a / 255f); }
public virtual 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; } // Make sure they're the same units. if (ValueObject != null && RawStart.GetType() == RawTarget.GetType()) { // Raw start/end values: StartValue = RawStart.GetRawDecimal(); DeltaValue = RawTarget.GetRawDecimal(); // Update delta: DeltaValue -= StartValue; } else { // Different units or are non-numeric! Also applies to e.g. "none" -> "x%". // We'll be using pixel values here, but we must use GetDecimal every frame of the animation. // Force it to be a raw decimal: ValueObject = new Css.Units.DecimalUnit(0f); // Write it straight out to the computed style: // (Internally handles any aliases for us) Animation.ComputedStyle[InnerPropertyInfo] = ValueObject; // If it's not an alias, update hostValue: if (!InnerPropertyInfo.IsAlias) { PropertyValueObject = ValueObject; } } // Setup targets etc. // Instant? if (Animation.Duration == 0f) { Complete(); 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; // Make sure we are exactly the right value. Complete(); // Stop there: return; } // 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; } if (RawStart != ValueObject) { // Get the current from/to values: StartValue = RawStart.GetDecimal(computed.RenderData, InnerPropertyInfo); DeltaValue = RawTarget.GetDecimal(computed.RenderData, InnerPropertyInfo); // Update delta: DeltaValue -= StartValue; } // Read the value: ActiveValue = StartValue + (DeltaValue * progress); // Write it out to the CSS value: ValueObject.RawValue = ActiveValue; if (UpdateCss) { // And Tell the style it changed: // Note that in grouped properties, only the last one actually runs the update. computed.ChangeProperty(PropertyInfo, PropertyValueObject); } }
/// <summary>Sets up the initial value.</summary> public void SetupValue(Css.Value hostValue, Css.Value rawValue) { RawStart = rawValue; ValueObject = rawValue as Css.Units.DecimalUnit; PropertyValueObject = hostValue; }