/// <summary>Called when this image is going to be displayed.</summary> public void GoingOnDisplay(Css.RenderableData context) { if (Contents != null) { Contents.GoingOnDisplay(context); } }
/// <summary> /// Gets the path representing this element. /// </summary> public override VectorPath GetPath(SVGElement context, RenderContext renderer) { Css.RenderableData rd = context.RenderData; // Don't build the path if there's no radius: float radius = Radius.GetDecimal(rd, ViewportAxis.None); if (radius <= 0) { return(null); } if (_Path == null) { // Don't need to consider stroke width. _Path = new VectorPath(); float centerX = CenterX.GetDecimal(rd, ViewportAxis.X); float centerY = CenterX.GetDecimal(rd, ViewportAxis.Y); // Get the C values: float cX = BezierC * radius; float cY = cX; // Offset to match the center: cX += centerX; cY += centerY; float radiusX = centerX + radius; float radiusY = centerY + radius; float nRadiusX = centerX - radius; float nRadiusY = centerY - radius; _Path.MoveTo(centerX, radiusY); // First quadrant (top right, going clockwise): _Path.CurveTo(cX, radiusY, radiusX, cY, radiusX, centerY); // Bottom right: _Path.CurveTo(radiusX, -cY, cX, nRadiusY, centerX, nRadiusY); // Bottom left: _Path.CurveTo(-cX, nRadiusY, nRadiusX, -cY, nRadiusX, centerY); // Top left: _Path.CurveTo(nRadiusX, cY, -cX, radiusY, centerX, radiusY); // Mark as closed: _Path.LatestPathNode.IsClose = true; } return(_Path); }
/// <summary> /// Gets the path representing this element. /// </summary> public override VectorPath GetPath(SVGElement context, RenderContext renderer) { Css.RenderableData rd = context.RenderData; if (_Path == null) { _Path = new VectorPath(); try{ Css.Value points = Points; int count = points.Count; for (int i = 2; (i + 1) < count; i += 2) { float endPointX = points[i].GetDecimal(rd, ViewportAxis.X); float endPointY = points[i + 1].GetDecimal(rd, ViewportAxis.Y); if (Close) { //first line if (_Path.FirstPathNode == null) { // Wrap around: float startPointX = points[i - 2].GetDecimal(rd, ViewportAxis.X); float startPointY = points[i - 1].GetDecimal(rd, ViewportAxis.Y); _Path.MoveTo(startPointX, startPointY); } _Path.LineTo(endPointX, endPointY); } else { // It's a polyline //first line if (_Path.FirstPathNode == null) { _Path.MoveTo(endPointX, endPointY); } else { _Path.LineTo(endPointX, endPointY); } } } } catch { Dom.Log.Add("Warning: Failed to parse a set of points for a polygon definition in either an SVG or your CSS."); } } return(_Path); }
/// <summary> /// Gets the path representing this element. /// </summary> public override VectorPath GetPath(SVGElement context, RenderContext renderer) { Css.RenderableData rd = context.RenderData; if (_Path == null) { _Path = new VectorPath(); float startX = StartX.GetDecimal(rd, ViewportAxis.X); float startY = StartY.GetDecimal(rd, ViewportAxis.Y); float endX = EndX.GetDecimal(rd, ViewportAxis.X); float endY = EndY.GetDecimal(rd, ViewportAxis.Y); _Path.MoveTo(startX, startY); _Path.LineTo(endX, endY); } return(_Path); }
/// <summary>Gets the image.</summary> public override ImageFormat GetImage(Css.RenderableData context, CssProperty property) { if (Image == null) { // Get first value (either a colour stop, angle or 'to x'): int firstColour = 1; Angle = LoadAngle(this[0]); if (Angle == float.MaxValue) { // It's the first colour. Angle is 180deg: Angle = (float)Math.PI; firstColour = 0; } // Load the gradient: Gradient2D grad = LoadGradient(firstColour, this, false); // Render the gradient: Color32[] rendered = grad.Render32(Resolution, true).Pixels; Color32[] pixels = null; // Create the image now. Texture2D image; // If angle is perfectly vertical, or perfectly horizontal.. if (Angle == 0f || Angle == (float)Math.PI) { // Vertical: image = new Texture2D(1, Resolution); if (Angle == (float)Math.PI) { // Set the pixels as-is: pixels = rendered; } else { // Pixels is a new set: pixels = new Color32[Resolution]; // Backwards: for (int i = 0; i < Resolution; i++) { pixels[i] = rendered[Resolution - 1 - i]; } } } else if (Angle == (Fourty5Deg * 6f) || Angle == (Fourty5Deg * 2f)) { // Horizontal: image = new Texture2D(Resolution, 1); if (Angle == (Fourty5Deg * 6f)) { // Set the pixels as-is: pixels = rendered; } else { // Pixels is a new set: pixels = new Color32[Resolution]; // Backwards: for (int i = 0; i < Resolution; i++) { pixels[i] = rendered[Resolution - 1 - i]; } } } else { // Any other angle: image = new Texture2D(Resolution, Resolution); pixels = new Color32[Resolution * Resolution]; float cos = (float)System.Math.Cos(-Angle); float sin = (float)System.Math.Sin(-Angle); // Other angles ignored for now: int index = 0; float max = (float)Resolution - 1f; float delta = 1f / (max - 1f); float yPoint = 0.5f - delta; for (int y = Resolution - 1; y >= 0; y--) { float xPoint = -0.5f; for (int x = 0; x < Resolution; x++) { // int rotatedX=(int)( (xPoint * cos) - (yPoint * sin) ); int rotatedY = (int)(((xPoint * sin) + (yPoint * cos)) * max); if (rotatedY < 0) { rotatedY = 0; } else if (rotatedY >= Resolution) { rotatedY = Resolution - 1; } pixels[index] = rendered[rotatedY]; xPoint += delta; index++; } yPoint -= delta; } } // Set: image.SetPixels32(pixels); // Flush: image.Apply(); // Apply the image: Image = new SparkSpecialImageFormat(); Image.Image = image; } return(Image); }
/// <summary> /// Gets the path representing this element. /// </summary> public override VectorPath GetPath(SVGElement context, RenderContext renderer) { Css.RenderableData rd = context.RenderData; // Get w/h: float width = Width.GetDecimal(rd, ViewportAxis.X); float height = Height.GetDecimal(rd, ViewportAxis.Y); if (width <= 0f && height > 0f) { return(null); } if (_Path == null) { _Path = new VectorPath(); // Get corner radius: float rx = CornerRadiusX.GetDecimal(rd, ViewportAxis.X); float ry = CornerRadiusY.GetDecimal(rd, ViewportAxis.Y); // Get x/y: float x = X.GetDecimal(rd, ViewportAxis.X); float y = Y.GetDecimal(rd, ViewportAxis.Y); // Note: This goes clockwise (like the other standard shapes). // If the corners aren't to be rounded just create a rectangle if (rx == 0f && ry == 0f) { // Ordinary rectangle. _Path.MoveTo(x, y); _Path.LineTo(x, y + height); _Path.LineTo(x + width, y + height); _Path.LineTo(x + width, y); _Path.ClosePath(); } else { // Clip the corner radius: rx = (float)Math.Min(rx * 2, width); ry = (float)Math.Min(ry * 2, height); // Get the C values (used to shape the 4 corners arcs - see CircleProvider for some clarity): float cx = (CircleProvider.BezierC * rx); float cy = (CircleProvider.BezierC * ry); float limit = x + width * 0.5f; // The start/ end of arcs from the left along x. float leftArcX = Math.Min(x + rx, limit); // The start/ end of arcs from the right along x. float rightArcX = Math.Max(x + width - rx, limit); limit = y + height * 0.5f; // The start/ end of arcs from the bottom along y. float bottomArcY = Math.Min(y + ry, limit); // The start/ end of arcs from the top along y. float topArcY = Math.Max(y + height - ry, limit); // Start from bottom left: _Path.MoveTo( leftArcX, y ); // First arc (bottom left): _Path.CurveTo( leftArcX - cx, y, x, bottomArcY - cy, x, bottomArcY ); // Up the left edge: _Path.LineTo(x, topArcY); // Top left arc: _Path.CurveTo( x, topArcY + cy, leftArcX - cx, y + height, leftArcX, y + height ); // Along the top edge: _Path.LineTo(rightArcX, y); // Top right arc: _Path.CurveTo( rightArcX + cx, y, x + width, topArcY + cy, x + width, topArcY ); // Down the right edge: _Path.LineTo(x + width, bottomArcY); // Bottom right arc: _Path.CurveTo( x + width, bottomArcY - cy, rightArcX + cx, y, rightArcX, y ); // Line along the bottom! _Path.ClosePath(); } } return(_Path); }
/// <summary>Sets the given context. Enables the node to receive events.</summary> public void SetContext(Css.RenderableData context) { EventReceiver = context.Node; }