internal RadialGradientBrush(Direct2DRenderTarget renderTargetOwner, GradientStop[] gradientStops, ExtendMode extendMode, PointF centerPoint, PointF gradientOriginOffset, SizeF radius) { m_renderTargetOwner = renderTargetOwner; m_extendMode = extendMode; m_radius = radius; m_gradientOriginOffset = gradientOriginOffset; m_centerPoint = centerPoint; var gradientStopList = new List<SlimDX.Direct2D.GradientStop>(gradientStops.Length); for (int i = 0; i < gradientStops.Length; i++) { gradientStopList.Add(gradientStops[i].InternalGradientStop); } var props = new RadialGradientBrushProperties(); props.CenterPoint = centerPoint.InternalPointF; props.GradientOriginOffset = gradientOriginOffset.InternalPointF; props.HorizontalRadius = radius.Width; props.VerticalRadius = radius.Height; m_internalGradientStopCollection = new GradientStopCollection(m_renderTargetOwner.InternalRenderTarget, gradientStopList.ToArray(), Gamma.Linear, (SlimDX.Direct2D.ExtendMode)extendMode); m_internalRadialGradientBrush = new SlimDX.Direct2D.RadialGradientBrush(m_renderTargetOwner.InternalRenderTarget, m_internalGradientStopCollection, props); }
/// <summary> /// Gets an extend mode attribute /// </summary> /// <param name="name">Attribute name</param> /// <param name="extendMode">When this returns , contains the attribute value</param> public unsafe void GetAttributeValue(string name, out ExtendMode extendMode) { fixed(ExtendMode *ptr = &extendMode) { GetAttributeValue(name, SvgAttributePodType.ExtendMode, new IntPtr(ptr), sizeof(ExtendMode)); } }
public GradientStopCollection([NotNull] GradientStop[] gradientStops, Gamma gamma, ExtendMode extendMode) { if (gradientStops.Length < 2) { throw new ArgumentException("There must be at least 2 gradient stops.", nameof(gradientStops)); } if (gradientStops.Length > MaximumGradientStops) { throw new ArgumentException($"GradientStopCollection supports maximum {MaximumGradientStops} gradient stops.", nameof(gradientStops)); } var currentStopPos = gradientStops[0].Position; for (var i = 1; i < gradientStops.Length; ++i) { if (gradientStops[i].Position <= currentStopPos) { throw new ArgumentException($"Position of gradient stop #{i} is less than its predecessor."); } currentStopPos = gradientStops[i].Position; } GradientStopsDirect = (GradientStop[])gradientStops.Clone(); GradientStops = GradientStopsDirect; Gamma = gamma; ExtendMode = extendMode; }
/// <summary> /// Initializes a new instance of the <see cref="ImageBrushProperties"/> struct. /// </summary> /// <param name="sourceRectangle">The source rectangle in the image space from which the image will be tiled or interpolated.</param> /// <param name="extendModeX">The extend mode in the image x-axis.</param> /// <param name="extendModeY">The extend mode in the image y-axis.</param> /// <param name="interpolationMode">The interpolation mode to use when scaling the image brush.</param> public ImageBrushProperties(Rect sourceRectangle, ExtendMode extendModeX, ExtendMode extendModeY, InterpolationMode interpolationMode) { SourceRectangle = sourceRectangle; ExtendModeX = extendModeX; ExtendModeY = extendModeY; InterpolationMode = interpolationMode; }
public static MemoryStream CreateRadiusGradientBitmapStream(IDevice2DResources deviceResources, int width, int height, Direct2DImageFormat imageType, Vector2 center, Vector2 gradientOriginOffset, float radiusX, float radiusY, GradientStop[] gradients, ExtendMode extendMode = ExtendMode.Clamp, Gamma gamma = Gamma.StandardRgb) { using (var bmp = CreateBitmapStream(deviceResources, width, height, imageType, (target) => { using (var gradientCol = new GradientStopCollection(target, gradients, gamma, extendMode)) { using (var brush = new RadialGradientBrush(target, new RadialGradientBrushProperties() { Center = center, GradientOriginOffset = gradientOriginOffset, RadiusX = radiusX, RadiusY = radiusY, }, gradientCol)) { target.FillRectangle(new RawRectangleF(0, 0, width, height), brush); } } })) { return(bmp.ToMemoryStream(deviceResources, imageType)); } }
internal LinearGradientBrush(Direct2DRenderTarget renderTargetOwner, GradientStop[] gradientStops, ExtendMode extendMode, PointF startPoint, PointF endPoint) { m_renderTargetOwner = renderTargetOwner; var gradientStopList = new List<SlimDX.Direct2D.GradientStop>(gradientStops.Length); for (int i = 0; i < gradientStops.Length; i++) { gradientStopList.Add(gradientStops[i].InternalGradientStop); } var props = new LinearGradientBrushProperties(); props.StartPoint = startPoint.InternalPointF; props.EndPoint = endPoint.InternalPointF; m_startPoint = startPoint; m_endPoint = endPoint; var internalRt = m_renderTargetOwner.InternalRenderTarget; m_internalGradientStopCollection = new GradientStopCollection(internalRt, gradientStopList.ToArray(), Gamma.Linear, (SlimDX.Direct2D.ExtendMode)extendMode); m_internalLinearGradientBrush = new SlimDX.Direct2D.LinearGradientBrush(internalRt, m_internalGradientStopCollection, props); }
public D2DSpriteGradientStopCollection(D2DSpriteBatch batch, GradientStop[] stops, Gamma gamma, ExtendMode mode) { batch.BatchDisposing += batch_BatchDisposing; _extendMode = mode; _gamma = gamma; _stops = stops; _batch = batch; }
public BitmapBrushProperties( ExtendMode extendModeX = ExtendMode.Clamp, ExtendMode extendModeY = ExtendMode.Clamp, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.Linear) { ExtendModeX = extendModeX; ExtendModeY = extendModeY; InterpolationMode = interpolationMode; }
private ExtendMode RandomExtendMode() { double which = Random.NextDouble(); ExtendMode ret = which < 0.33 ? ExtendMode.Wrap : which < 0.65 ? ExtendMode.Mirror : ExtendMode.Clamp; #if _D2DTRACE Trace.WriteLine(" ExtendMode:" + ret); #endif return(ret); }
public D2DImageBrush(RenderContext context, ID2DImage image, ExtendMode extendModeX, ExtendMode extendModeY, InterpolationMode interpolationMode, RectangleF sourceRectangle) { var brushProperties = new ImageBrushProperties { ExtendModeX = extendModeX, ExtendModeY = extendModeY, InterpolationMode = interpolationMode, SourceRectangle = sourceRectangle.ToD2DRectF() }; NativeBrush = new ImageBrush(context.RenderTarget.DeviceContext2D, image.NativeImage, brushProperties); }
public D2DImageBrush(RenderContext context, D2DBitmap bitmap, ExtendMode extendModeX, ExtendMode extendModeY, InterpolationMode interpolationMode) { var brushProperties = new ImageBrushProperties { ExtendModeX = extendModeX, ExtendModeY = extendModeY, InterpolationMode = interpolationMode, SourceRectangle = new RawRectangleF(0, 0, bitmap.Width, bitmap.Height) }; NativeBrush = new ImageBrush(context.RenderTarget.DeviceContext2D, bitmap.NativeImage, brushProperties); }
private void LinearGradientBrushAddClicked(object sender, EventArgs e) { ExtendMode ex = gradBrushExtendModeCombo.SelectedIndex > 0 ? (ExtendMode)gradBrushExtendModeCombo.SelectedIndex : ExtendMode.Clamp; Gamma gamma; switch (gammaComboBox.SelectedIndex) { case 0: gamma = Gamma.Linear; break; case 1: gamma = Gamma.StandardRgb; break; default: throw new InvalidOperationException("Unknown gamma selected"); } GradientStop[] stops = { new GradientStop(0.0f, color1), new GradientStop(1.0f, color2), }; GradientStopCollection stopCollection = renderTarget.CreateGradientStopCollection( stops, gamma, ex); LinearGradientBrushProperties properties; if (ex == ExtendMode.Clamp) { properties = new LinearGradientBrushProperties( new Point2F(50, 50), new Point2F(600, 400)); } else { properties = new LinearGradientBrushProperties( new Point2F(50, 50), new Point2F(0, 0)); } LinearGradientBrush brush = renderTarget.CreateLinearGradientBrush( properties, stopCollection); parent.brushes.Add(brush); parent.currentBrushIndex = parent.brushes.Count - 1; FillBrushesListBox(); }
/// <summary> /// Initializes a new instance of the <see cref="SolidBrushResource" /> class. /// </summary> /// <param name="startPoint">The start point of the gradient.</param> /// <param name="endPoint">The end point of the gradient.</param> /// <param name="gradientStops">All points within the color gradient.</param> /// <param name="extendMode">How to draw outside the content area?</param> /// <param name="gamma">The gama configuration.</param> /// <param name="opacity">The opacity value of the brush.</param> public LinearGradientBrushResource( Vector2 startPoint, Vector2 endPoint, GradientStop[] gradientStops, ExtendMode extendMode = ExtendMode.Clamp, Gamma gamma = Gamma.StandardRgb, float opacity = 1f) { startPoint.EnsureNotEqual(endPoint, nameof(startPoint), nameof(endPoint)); gradientStops.EnsureNotNullOrEmpty(nameof(gradientStops)); _gradientStops = gradientStops; this.StartPoint = startPoint; this.EndPoint = endPoint; this.ExtendMode = extendMode; this.Gamma = gamma; _opacity = opacity; _loadedBrushes = new LoadedBrushResources[GraphicsCore.Current.DeviceCount]; }
public static MemoryStream CreateLinearGradientBitmapStream(IDevice2DResources deviceResources, int width, int height, Direct2DImageFormat imageType, Vector2 startPoint, Vector2 endPoint, GradientStop[] gradients, ExtendMode extendMode = ExtendMode.Clamp, Gamma gamma = Gamma.StandardRgb) { using (var bmp = CreateBitmapStream(deviceResources, width, height, imageType, (target) => { using (var brush = new LinearGradientBrush(target, new LinearGradientBrushProperties() { StartPoint = startPoint, EndPoint = endPoint }, new GradientStopCollection(target, gradients, gamma, extendMode))) { target.FillRectangle(new RawRectangleF(0, 0, width, height), brush); } })) { return(bmp.ToMemoryStream(deviceResources, imageType)); } }
private void addBitmapBrushBotton_Click(object sender, EventArgs e) { ExtendMode ex = extendedModeXComboBox.SelectedIndex > 0 ? (ExtendMode)extendedModeXComboBox.SelectedIndex : ExtendMode.Wrap; ExtendMode ey = extendedModeYComboBox.SelectedIndex > 0 ? (ExtendMode)extendedModeYComboBox.SelectedIndex : ExtendMode.Wrap; D2DBitmap brushBitmap = BitmapUtilities.LoadBitmapFromFile(renderTarget, parent.wicFactory, imageFilename); BitmapBrush brush = renderTarget.CreateBitmapBrush( brushBitmap, new BitmapBrushProperties( ex, ey, BitmapInterpolationMode.NearestNeighbor), new BrushProperties( opacity, Matrix3x2F.Identity)); parent.brushes.Add(brush); parent.currentBrushIndex = parent.brushes.Count - 1; FillBrushesListBox(); }
/// <summary> /// Initializes a new instance of the <see cref="RadialGradientBrushResource" /> class. /// </summary> public RadialGradientBrushResource( Vector2 center, Vector2 gradientOriginOffset, float radiusX, float radiusY, GradientStop[] gradientStops, ExtendMode extendMode = ExtendMode.Clamp, Gamma gamma = Gamma.StandardRgb, float opacity = 1f) { gradientStops.EnsureNotNullOrEmpty(nameof(gradientStops)); opacity.EnsureInRange(0f, 1f, nameof(opacity)); radiusX.EnsurePositiveOrZero(nameof(radiusX)); radiusY.EnsurePositiveOrZero(nameof(radiusY)); _gradientStops = gradientStops; this.Center = center; this.GradientOriginOffset = gradientOriginOffset; this.RadiusX = radiusX; this.RadiusY = radiusY; this.ExtendMode = extendMode; this.Gamma = gamma; _opacity = opacity; _loadedBrushes = new LoadedBrushResources[GraphicsCore.Current.DeviceCount]; }
protected override void OnSelectionStarted() { var position = this.CurrentMouseTilePosition; var selectionBounds = this.SelectionBounds; if (!selectionBounds.Contains(position)) { // clicked outside - create new rectangle this.currentExtendMode = ExtendMode.None; base.OnSelectionStarted(); return; } this.currentExtendMode = CalculateExtendMode(ref position, selectionBounds); //Logger.WriteDev("Selection rectangle extending started: " + this.currentExtendMode); // normalize start-end positions this.SelectionRectStartPosition = selectionBounds.Offset; this.SelectionRectEndPosition = (selectionBounds.Offset + selectionBounds.Size - Vector2Ushort.One).ToVector2Ushort(); this.lastMouseTilePosition = position; }
public RadialGradient(string name, Vector2 center, Vector2 originOffset, float radiusX, float radiusY, IEnumerable <GradientStop> gradientStops, ExtendMode extendMode = ExtendMode.Clamp, float opacity = 1.0f, bool shared = true) : base(name, gradientStops, extendMode, ColorType.RadialGradient, opacity, shared) { Center = center; OriginOffset = originOffset; RadiusX = radiusX; RadiusY = radiusY; }
public static BitmapBrush1 GetBrush(D2D.DeviceContext context, Bitmap1 bitmap, ExtendMode mode) { return(new BitmapBrush1(context, bitmap) { ExtendModeX = mode, ExtendModeY = mode }); }
/// <summary> /// Sets how the bitmap is to be treated outside of its natural extent on the Y axis. /// </summary> public void SetExtendModeY(ExtendMode extendModeY) { GetMethodDelegate <SetExtendModeYDelegate>().Invoke(this, extendModeY); }
public ID2D1GradientStopCollection CreateGradientStopCollection(GradientStop[] gradientStops, ExtendMode extendMode) { return(CreateGradientStopCollection_(gradientStops, gradientStops.Length, Gamma.StandardRgb, extendMode)); }
public LinearGradientBrush CreateLinearGradientBrush(GradientStop[] gradientStops, ExtendMode extendMode, PointF startPoint, PointF endPoint) { return new LinearGradientBrush(m_renderTargetResourceOwner, gradientStops, extendMode, startPoint, endPoint); }
public LinearGradient(string name, Vector2 startPoint, Vector2 endPoint, IEnumerable <GradientStop> gradientStops, ExtendMode extendMode = ExtendMode.Clamp, float opacity = 1.0f, bool shared = true) : base(name, gradientStops, extendMode, ColorType.LinearGradient, opacity, shared) { Contract.Requires <ArgumentNullException>(gradientStops != null, "gradientStops"); StartPoint = startPoint; EndPoint = endPoint; }
public RadialGradientBrush CreateRadialGradientBrush(GradientStop[] gradientStops, ExtendMode extendMode, PointF centerPoint, PointF gradientOriginOffset, SizeF radius) { return new RadialGradientBrush(m_renderTargetResourceOwner, gradientStops, extendMode, centerPoint, gradientOriginOffset, radius); }
public ID2D1GradientStopCollection CreateGradientStopCollection(GradientStop[] gradientStops, Gamma colorInterpolationGamma, ExtendMode extendMode) { Guard.NotNullOrEmpty(gradientStops, nameof(gradientStops)); return(CreateGradientStopCollection(gradientStops, gradientStops.Length, colorInterpolationGamma, extendMode)); }
public ID2D1GradientStopCollection CreateGradientStopCollection(GradientStop[] gradientStops, Gamma colorInterpolationGamma, ExtendMode extendMode) { return(CreateGradientStopCollection_(gradientStops, gradientStops.Length, colorInterpolationGamma, extendMode)); }
protected Gradient(string name, IEnumerable <GradientStop> gradientStops, ExtendMode extendMode, ColorType type, float opacity, bool shared) : base(name, type, opacity, shared) { this.gradientStops = new GradientStopCollection(gradientStops); this.gradientStops.ExtendMode = extendMode; }
/// <summary> /// Sets extend mode attribute /// </summary> /// <param name="name">Attribute name</param> /// <param name="extendMode">New extend mode</param> public unsafe void SetAttributeValue(string name, ExtendMode extendMode) { SetAttributeValue(name, SvgAttributePodType.ExtendMode, new IntPtr(&extendMode), sizeof(ExtendMode)); }
/// <summary> /// Initializes a new instance of the <see cref="BitmapBrushProperties"/> struct. /// </summary> /// <param name="extendModeX">A value that describes how the brush horizontally tiles those areas that extend past its bitmap.</param> /// <param name="extendModeY">A value that describes how the brush vertically tiles those areas that extend past its bitmap.</param> /// <param name="interpolationMode">A value that specifies how the bitmap is interpolated when it is scaled or rotated.</param> public BitmapBrushProperties(ExtendMode extendModeX, ExtendMode extendModeY, BitmapInterpolationMode interpolationMode) { ExtendModeX = extendModeX; ExtendModeY = extendModeY; InterpolationMode = interpolationMode; }
//if do not have input parameter -> ExtendMode.NORMAL public ColorMixer(ExtendMode extendMode = ExtendMode.NORMAL) { colors = new LinkedList <ColorNode>(); this.extendMode = extendMode; }