private void AnimatedControl_CreateResources(CanvasAnimatedControl sender, CanvasCreateResourcesEventArgs args)
        {
            // Initialize the brushes.
            backgroundDefaultBrush = CreateRadialGradientBrush(sender,
                                                               Color.FromArgb(0x00, 0x6E, 0xEF, 0xF8), Color.FromArgb(0x4D, 0x6E, 0xEF, 0xF8));
            backgroundAnswerCorrectBrush = CreateRadialGradientBrush(sender,
                                                                     Color.FromArgb(0x00, 0x42, 0xC9, 0xC5), Color.FromArgb(0x4D, 0x42, 0xC9, 0xC5));
            backgroundAnswerIncorrectBrush = CreateRadialGradientBrush(sender,
                                                                       Color.FromArgb(0x00, 0xDE, 0x01, 0x99), Color.FromArgb(0x4D, 0xDE, 0x01, 0x99));
            borderDefaultBrush  = new CanvasSolidColorBrush(sender, Color.FromArgb(0xFF, 0x6E, 0xEF, 0xF8));
            borderGradientBrush = new CanvasLinearGradientBrush(sender,
                                                                Color.FromArgb(0xFF, 0x0F, 0x56, 0xA4), Color.FromArgb(0xFF, 0x6E, 0xEF, 0xF8))
            {
                StartPoint = new Vector2(centerPoint.X - radius, centerPoint.Y),
                EndPoint   = new Vector2(centerPoint.X + radius, centerPoint.Y)
            };
            borderAnswerCorrectBrush   = new CanvasSolidColorBrush(sender, Color.FromArgb(0xFF, 0x42, 0xC9, 0xC5));
            borderAnswerIncorrectBrush = new CanvasSolidColorBrush(sender, Color.FromArgb(0xFF, 0xDE, 0x01, 0x99));

            // Calculate the text position for vertical centering to account for the
            // fact that text is not vertically centered within its layout bounds.
            var textLayout        = new CanvasTextLayout(sender, "0123456789", textFormat, 0, 0);
            var drawMidpoint      = (float)(textLayout.DrawBounds.Top + (textLayout.DrawBounds.Height / 2));
            var layoutMidpoint    = (float)(textLayout.LayoutBounds.Top + (textLayout.LayoutBounds.Height / 2));
            var textPositionDelta = drawMidpoint - layoutMidpoint;

            textPosition = new Vector2(centerPoint.X, centerPoint.Y - textPositionDelta);
        }
예제 #2
0
        public override void Draw(CanvasControl CanvasControl, CanvasDrawingSession ds, HSL HSL, Vector2 Center, float SquareHalfWidth, float SquareHalfHeight)
        {
            //Palette
            Rect rect = new Rect(Center.X - SquareHalfWidth, Center.Y - SquareHalfHeight, SquareHalfWidth * 2, SquareHalfHeight * 2);

            using (CanvasLinearGradientBrush rainbow = new CanvasLinearGradientBrush(CanvasControl, this.BackgroundStops))
            {
                rainbow.StartPoint = new Vector2(Center.X - SquareHalfWidth, Center.Y);
                rainbow.EndPoint   = new Vector2(Center.X + SquareHalfWidth, Center.Y);
                ds.FillRoundedRectangle(rect, 4, 4, rainbow);
            }
            using (CanvasLinearGradientBrush brush = new CanvasLinearGradientBrush(CanvasControl, this.ForegroundStops))
            {
                brush.StartPoint = new Vector2(Center.X, Center.Y - SquareHalfHeight);
                brush.EndPoint   = new Vector2(Center.X, Center.Y + SquareHalfHeight);
                ds.FillRoundedRectangle(rect, 4, 4, brush);
            }
            ds.DrawRoundedRectangle(rect, 4, 4, Windows.UI.Colors.Gray);

            //Thumb
            float px = ((float)HSL.H - 180) * SquareHalfWidth / 180 + Center.X;
            float py = (50 - (float)HSL.S) * SquareHalfHeight / 50 + Center.Y;

            ds.DrawCircle(px, py, 8, Windows.UI.Colors.Black, 4);
            ds.DrawCircle(px, py, 8, Windows.UI.Colors.White, 2);
        }
예제 #3
0
        protected void CreateInnerCircleBrush(CanvasControl sender)
        {
            Color step1Color = this.GaugeColor;
            Color step2Color = ColorHelper.FromArgb(step1Color.A,
                                                    Convert.ToByte(~step1Color.R & 0xFF),
                                                    Convert.ToByte(~step1Color.G & 0xFF),
                                                    Convert.ToByte(~step1Color.B & 0xFF));

            if (step1Color == Colors.Red)
            {
                step2Color = Colors.Black;
            }

            var stops = new CanvasGradientStop[]
            {
                new CanvasGradientStop()
                {
                    Color = step1Color, Position = -0.2f
                },
                new CanvasGradientStop()
                {
                    Color = step2Color, Position = 1.0f
                },
            };

            InnerCircleBrush            = new CanvasLinearGradientBrush(sender, stops);
            InnerCircleBrush.StartPoint = new Vector2(Center.X, Center.Y - InnerCircleRadius);
            InnerCircleBrush.EndPoint   = new Vector2(Center.X, Center.Y + InnerCircleRadius);
        }
예제 #4
0
        void EnsureResources(ICanvasResourceCreatorWithDpi resourceCreator, Size targetSize)
        {
            if (resourceRealizationSize != targetSize && !needsResourceRecreation)
            {
                return;
            }

            float canvasWidth  = (float)targetSize.Width;
            float canvasHeight = (float)targetSize.Height;

            if (textLayout != null)
            {
                textLayout.Dispose();
            }
            textLayout = CreateTextLayout(resourceCreator, canvasWidth, canvasHeight);

            Rect layoutBounds = textLayout.LayoutBounds;

            textBrush            = new CanvasLinearGradientBrush(resourceCreator, Colors.Red, Colors.Green);
            textBrush.StartPoint = new System.Numerics.Vector2((float)(layoutBounds.Left + layoutBounds.Right) / 2, (float)layoutBounds.Top);
            textBrush.EndPoint   = new System.Numerics.Vector2((float)(layoutBounds.Left + layoutBounds.Right) / 2, (float)layoutBounds.Bottom);

            selectionTextBrush            = new CanvasLinearGradientBrush(resourceCreator, Colors.Green, Colors.Red);
            selectionTextBrush.StartPoint = textBrush.StartPoint;
            selectionTextBrush.EndPoint   = textBrush.EndPoint;

            needsResourceRecreation = false;
            resourceRealizationSize = targetSize;
        }
예제 #5
0
        /// <summary> Override <see cref="PalettePicker.Draw"/>. </summary>
        public override void Draw(CanvasControl sender, CanvasDrawingSession ds, HSV hsv, Vector2 center, float squareHalfWidth, float squareHalfHeight, SolidColorBrush stroke)
        {
            //Palette
            Rect rect = new Rect(center.X - squareHalfWidth, center.Y - squareHalfHeight, squareHalfWidth * 2, squareHalfHeight * 2);

            using (CanvasLinearGradientBrush rainbow = new CanvasLinearGradientBrush(sender, this.BackgroundStops))
            {
                rainbow.StartPoint = new Vector2(center.X - squareHalfWidth, center.Y);
                rainbow.EndPoint   = new Vector2(center.X + squareHalfWidth, center.Y);
                ds.FillRoundedRectangle(rect, 4, 4, rainbow);
            }
            using (CanvasLinearGradientBrush brush = new CanvasLinearGradientBrush(sender, this.ForegroundStops))
            {
                brush.StartPoint = new Vector2(center.X, center.Y - squareHalfHeight);
                brush.EndPoint   = new Vector2(center.X, center.Y + squareHalfHeight);
                ds.FillRoundedRectangle(rect, 4, 4, brush);
            }
            ds.DrawRoundedRectangle(rect, 4, 4, stroke.Color);

            //Thumb
            float px = ((float)hsv.H - 180) * squareHalfWidth / 180 + center.X;
            float py = (50 - (float)hsv.S) * squareHalfHeight / 50 + center.Y;

            ds.FillCircle(px, py, 12, stroke.Color);
            ds.FillCircle(px, py, 11, HSV.HSVtoRGB(hsv));
        }
예제 #6
0
        private void canvasControl_Draw(CanvasControl sender, CanvasDrawEventArgs args)
        {
            //图片
            args.DrawingSession.DrawImage(App.GrayWhiteGrid);

            //渐变
            CanvasLinearGradientBrush Linear = new CanvasLinearGradientBrush(App.Model.VirtualControl, App.Setting.GradientStops.ToArray());

            Linear.StartPoint = new Vector2(0, CanvasHalfHeight);
            Linear.EndPoint   = new Vector2(CanvasWidth, CanvasHalfHeight);
            args.DrawingSession.FillRectangle(0, 0, CanvasWidth + Space + Space, CanvasHeight, Linear);

            //点
            for (int i = 0; i < App.Setting.GradientStops.Count; i++)
            {
                Vector2 v = new Vector2(App.Setting.GradientStops[i].Position * CanvasWidth + Space, CanvasHalfHeight);

                //主点
                args.DrawingSession.FillEllipse(v, 10, 10, Colors.Black);//环线
                if (i == App.Setting.GradientCurrent)
                {
                    args.DrawingSession.FillEllipse(v, 9, 9, Colors.White);
                }
                else
                {
                    args.DrawingSession.FillEllipse(v, 9, 9, Colors.DarkGray);
                    args.DrawingSession.FillEllipse(v, 6, 6, Colors.White);
                }
                args.DrawingSession.FillEllipse(v, 6, 6, App.Setting.GradientStops[i].Color);//主题色
            }
        }
예제 #7
0
        /// <summary> Override <see cref="PaletteBase.Draw"/>. </summary>
        public override void Draw(CanvasControl sender, CanvasDrawingSession ds, HSV HSV, Vector2 center, float squareHalfWidth, float squareHalfHeight)
        {
            //Palette
            Rect rect = new Rect(center.X - squareHalfWidth, center.Y - squareHalfHeight, squareHalfWidth * 2, squareHalfHeight * 2);

            using (CanvasLinearGradientBrush rainbow = new CanvasLinearGradientBrush(sender, this.BackgroundStops))
            {
                rainbow.StartPoint = new Vector2(center.X - squareHalfWidth, center.Y);
                rainbow.EndPoint   = new Vector2(center.X + squareHalfWidth, center.Y);
                ds.FillRoundedRectangle(rect, 4, 4, rainbow);
            }
            using (CanvasLinearGradientBrush brush = new CanvasLinearGradientBrush(sender, this.ForegroundStops))
            {
                brush.StartPoint = new Vector2(center.X, center.Y - squareHalfHeight);
                brush.EndPoint   = new Vector2(center.X, center.Y + squareHalfHeight);
                ds.FillRoundedRectangle(rect, 4, 4, brush);
            }
            ds.DrawRoundedRectangle(rect, 4, 4, Windows.UI.Colors.Gray);

            //Thumb
            float px = ((float)HSV.H - 180) * squareHalfWidth / 180 + center.X;
            float py = ((float)(50 - HSV.V)) * squareHalfHeight / 50 + center.Y;

            ds.DrawCircle(px, py, 9, Windows.UI.Colors.Black, 5);
            ds.DrawCircle(px, py, 9, Windows.UI.Colors.White, 3);
        }
예제 #8
0
 private void Dispose(bool disposing)
 {
     if (_canvasLinearGradientBrush != null)
     {
         _canvasLinearGradientBrush.Dispose();
         _canvasLinearGradientBrush = null;
     }
 }
예제 #9
0
 //@Constructs
 /// <summary>
 /// Initialize a brush for drawing dotted-line.
 /// </summary>
 /// <param name="resourceCreator"> The resource-creator. </param>
 /// <param name="distance"> The sistance between two gradient points. </param>
 public DottedLineBrush(ICanvasResourceCreator resourceCreator, float distance = 6)
 {
     this.Brush = new CanvasLinearGradientBrush(resourceCreator, Stops, CanvasEdgeBehavior.Mirror, CanvasAlphaMode.Premultiplied)
     {
         StartPoint = new Vector2(0, 0),
         EndPoint   = new Vector2(distance, distance)
     };
 }
예제 #10
0
        private void CustomVisualizer_Draw(IVisualizer sender, VisualizerDrawEventArgs args)
        {
            if (!MainPageViewModel.Current.IsVisualizing)
            {
                return;
            }
            var drawingSession = (CanvasDrawingSession)args.DrawingSession;

            float barWidth = canvasWidth / (2 * Consts.SpectrumBarCount);
            // Calculate spectum metrics
            var barSize = new Vector2(barWidth, canvasHeight - 2 * barWidth);

            // Get the data if data exists and source is in play state, else use empty
            var spectrumData = args.Data != null && Visualizer.Source?.PlaybackState == SourcePlaybackState.Playing ?
                               args.Data.Spectrum.LogarithmicTransform(Consts.SpectrumBarCount, 20f, 20000f) : _emptySpectrum;

            _previousSpectrum     = spectrumData.ApplyRiseAndFall(_previousSpectrum, _rmsRiseTime, _rmsFallTime, _frameDuration);
            _previousPeakSpectrum = spectrumData.ApplyRiseAndFall(_previousPeakSpectrum, _peakRiseTime, _peakFallTime, _frameDuration);

            var logSpectrum     = _previousSpectrum.ConvertToDecibels(-50, 0);
            var logPeakSpectrum = _previousPeakSpectrum.ConvertToDecibels(-50, 0);

            var step = canvasWidth / Consts.SpectrumBarCount;
            var flaw = (step - barSize.X) / 2;

            using (var brush = new CanvasLinearGradientBrush(drawingSession, new CanvasGradientStop[] { new CanvasGradientStop()
                                                                                                        {
                                                                                                            Color = Context.CurrentColor[0], Position = 0f
                                                                                                        }, new CanvasGradientStop()
                                                                                                        {
                                                                                                            Color = Context.CurrentColor[1], Position = 1f
                                                                                                        } })
            {
                StartPoint = new Vector2(canvasWidth, 0),
                EndPoint = new Vector2(0, canvasHeight)
            })
            {
                // Draw spectrum bars
                for (int index = 0; index < Consts.SpectrumBarCount; index++)
                {
                    float barX = step * index + flaw;
                    // use average of 2 channel
                    float spectrumBarHeight = barSize.Y * (1.0f - (logSpectrum[0][index] + logSpectrum[1][index]) / -100.0f);
                    drawingSession.FillRoundedRectangle(barX, canvasHeight - barWidth - spectrumBarHeight, barSize.X, spectrumBarHeight, barSize.X / 2, barSize.X / 2, brush);
                }
            }

            // Spectrum points to draw a slow decay line
            for (int index = 0; index < Consts.SpectrumBarCount; index++)
            {
                float X = (index + 0.5f) * step;

                float spectrumBarHeight = barSize.Y * (1.0f - (logPeakSpectrum[0][index] + logPeakSpectrum[1][index]) / -100.0f);

                var decayPoint = new Vector2(X, canvasHeight - barWidth - spectrumBarHeight);
                drawingSession.FillCircle(decayPoint, barSize.X / 2, Context.CurrentColor[0]);
            }
        }
예제 #11
0
        private CanvasLinearGradientBrush CreateLinearGradient(CanvasDrawingSession session, Rect area, SvgLinearGradientElement element)
        {
            if (this.ResourceCache.ContainsKey(element))
            {
                return((CanvasLinearGradientBrush)this.ResourceCache[element]);
            }

            var stops = element.ChildNodes.Cast <SvgStopElement>().Select(s =>
            {
                var alpha = s.Style.StopOpacity.HasValue ? (byte)(255.0F * s.Style.StopOpacity.Value) : (byte)0xff;
                var stop  = new CanvasGradientStop()
                {
                    Position = s.Offset,
                    Color    = s.Style.StopColor.StopColorType == SvgStopColorType.CurrentColor
                                                ? s.Style.Color.ToPlatformColor(alpha)
                                                : s.Style.StopColor?.ToPlatformColor(alpha) ?? Color.FromArgb(alpha, 0, 0, 0)
                };
                return(stop);
            }).ToArray();

            var m         = element.GradientTransform.Result;
            var transform = new Matrix3x2 {
                M11 = (float)m.A, M12 = (float)m.B, M21 = (float)m.C, M22 = (float)m.D, M31 = (float)m.E, M32 = (float)m.F
            };

            float x1, y1, x2, y2;

            if (element.GradientUnits != SvgUnitType.UserSpaceOnUse)
            {
                x1 = this.LengthConverter.ConvertXForOBBU(element.X1, (float)area.X, (float)area.Width);
                y1 = this.LengthConverter.ConvertYForOBBU(element.Y1, (float)area.Y, (float)area.Height);
                x2 = this.LengthConverter.ConvertXForOBBU(element.X2, (float)area.X, (float)area.Width);
                y2 = this.LengthConverter.ConvertYForOBBU(element.Y2, (float)area.Y, (float)area.Height);
            }
            else
            {
                x1 = this.LengthConverter.ConvertX(element.X1);
                y1 = this.LengthConverter.ConvertY(element.Y1);
                x2 = this.LengthConverter.ConvertX(element.X2);
                y2 = this.LengthConverter.ConvertY(element.Y2);
            }
            var spreadMethod = GetSpreadMethod(element.SpreadMethod);
            var brush        = new CanvasLinearGradientBrush(this.ResourceCreator, stops, spreadMethod, CanvasAlphaMode.Straight)
            {
                StartPoint = new Vector2 {
                    X = x1, Y = y1
                },
                EndPoint = new Vector2 {
                    X = x2, Y = y2
                },
                Transform = transform,
            };

            this.DisposableObjects.Add(brush);
            this.ResourceCache.Add(element, brush);
            return(brush);
        }
예제 #12
0
        /// <summary>
        /// background design
        /// </summary>
        /// <param name="dp"></param>
        /// <param name="sr"></param>
        protected virtual void drawBackground(DrawProperty dp, ScreenRect sr)
        {
            var bg = new CanvasLinearGradientBrush(dp.Canvas, Parent.BackgroundColor1, Parent.BackgroundColor2)
            {
                StartPoint = _(ScreenPos.From(sr.LT.X, sr.LT.Y)),
                EndPoint   = _(ScreenPos.From(sr.RB.X, sr.RB.Y)),
            };

            dp.Graphics.FillRectangle(_(dp.PaneRect), bg);
        }
        /// <summary>
        /// Creates the CanvasLinearGradientBrush from the parsed data
        /// </summary>
        /// <param name="resourceCreator">ICanvasResourceCreator object</param>
        /// <returns></returns>
        public override ICanvasBrush CreateBrush(ICanvasResourceCreator resourceCreator)
        {
            var brush = CanvasLinearGradientBrush.CreateHdr(resourceCreator, _gradientStopHdrs.ToArray(), _edgeBehavior,
                                                            _alphaMode, _preInterpolationColorSpace, _postInterpolationColorSpace, _bufferPrecision);

            brush.StartPoint = _startPoint;
            brush.EndPoint   = _endPoint;
            brush.Opacity    = _opacity;

            return(brush);
        }
예제 #14
0
        async Task Canvas_CreateResourcesAsync(CanvasControl sender)
        {
            bitmap = await CanvasBitmap.LoadAsync(sender, "imageTiger.jpg");

            redBrush   = CreateGradientBrush(sender, 255, 0, 0);
            greenBrush = CreateGradientBrush(sender, 0, 255, 0);
            blueBrush  = CreateGradientBrush(sender, 0, 0, 255);

            brightnessEffect = new BrightnessEffect  { Source = bitmap };
            saturationEffect = new SaturationEffect  { Source = brightnessEffect };
            hueEffect        = new HueRotationEffect { Source = saturationEffect };
        }
예제 #15
0
        //初始化:??????
        public Lasso2(ICanvasResourceCreator rc, float Distance = 6, float Spa = 1)
        {
            CommandList = new CanvasCommandList(rc);

            StartPoint = new Vector2(0, 0);
            EndPoint   = new Vector2(Distance, Distance);
            Space      = new Vector2(Spa, Spa);



            lgb            = new CanvasLinearGradientBrush(rc, stop, CanvasEdgeBehavior.Mirror, CanvasAlphaMode.Premultiplied);
            lgb.StartPoint = StartPoint;
            lgb.EndPoint   = EndPoint;
        }
예제 #16
0
        public void SetGradientPoints(winFound.Rect bounds)
        {
            CanvasLinearGradientBrush brush = Brush as CanvasLinearGradientBrush;

            if (brush == null)
            {
                return;
            }

            brush.StartPoint = new Vector2((float)(bounds.Left + StartPoint.X * bounds.Width),
                                           (float)(bounds.Top + StartPoint.Y * bounds.Height));

            brush.EndPoint = new Vector2((float)(bounds.Left + EndPoint.X * bounds.Width),
                                         (float)(bounds.Top + EndPoint.Y * bounds.Height));
        }
예제 #17
0
        private CanvasLinearGradientBrush CreateLinearGradient(CanvasDrawingSession session, Rect area, SvgLinearGradientElement element)
        {
            if (this.ResourceCache.ContainsKey(element))
            {
                return((CanvasLinearGradientBrush)this.ResourceCache[element]);
            }

            var stops = element.ChildNodes.Cast <SvgStopElement>().Select(s =>
            {
                var alpha = s.Style.StopOpacity.HasValue ? (byte)(255.0F * s.Style.StopOpacity.Value) : (byte)0xff;
                var stop  = new CanvasGradientStop()
                {
                    Position = s.Offset,
                    Color    = Color.FromArgb(alpha, s.Style.StopColor.RgbColor.Red, s.Style.StopColor.RgbColor.Green, s.Style.StopColor.RgbColor.Blue)
                };
                return(stop);
            }).ToArray();

            var m = element.GradientTransform.Result;

            if (element.GradientUnits == SvgUnitType.ObjectBoundingBox)
            {
                m = new SvgMatrix(area.Width, 0.0, 0.0, area.Height, area.X, area.Y) * m;
            }
            var transform = new Matrix3x2 {
                M11 = (float)m.A, M12 = (float)m.B, M21 = (float)m.C, M22 = (float)m.D, M31 = (float)m.E, M32 = (float)m.F
            };

            var x1           = this.LengthConverter.ConvertX(element.X1);
            var y1           = this.LengthConverter.ConvertY(element.Y1);
            var x2           = this.LengthConverter.ConvertX(element.X2);
            var y2           = this.LengthConverter.ConvertY(element.Y2);
            var spreadMethod = GetSpreadMethod(element.SpreadMethod);
            var brush        = new CanvasLinearGradientBrush(this.ResourceCreator, stops, spreadMethod, CanvasAlphaMode.Straight)
            {
                StartPoint = new Vector2 {
                    X = x1, Y = y1
                },
                EndPoint = new Vector2 {
                    X = x2, Y = y2
                },
                Transform = transform,
            };

            this.DisposableObjects.Add(brush);
            this.ResourceCache.Add(element, brush);
            return(brush);
        }
예제 #18
0
        private void prologControl_CreateResources(Microsoft.Graphics.Canvas.UI.Xaml.CanvasAnimatedControl sender, Microsoft.Graphics.Canvas.UI.CanvasCreateResourcesEventArgs args)
        {
            var stops = new CanvasGradientStop[]
            {
                new CanvasGradientStop()
                {
                    Color = Colors.Transparent, Position = 0.0f
                },
                new CanvasGradientStop()
                {
                    Color = Color.FromArgb(0xff, 0x53, 0xef, 0xef), Position = 0.1f
                },
                new CanvasGradientStop()
                {
                    Color = Color.FromArgb(0xff, 0x53, 0xef, 0xef), Position = 0.9f
                },
                new CanvasGradientStop()
                {
                    Color = Colors.Transparent, Position = 1.0f
                }
            };

            mTextOpacityBrush = new CanvasLinearGradientBrush(sender, stops, CanvasEdgeBehavior.Clamp, CanvasAlphaMode.Premultiplied);

            stops = new CanvasGradientStop[]
            {
                new CanvasGradientStop()
                {
                    Color = Colors.White, Position = 0.0f
                },
                new CanvasGradientStop()
                {
                    Color = Colors.Transparent, Position = 0.3f
                },
                new CanvasGradientStop()
                {
                    Color = Colors.Transparent, Position = 0.7f
                },
                new CanvasGradientStop()
                {
                    Color = Colors.White, Position = 1.0f
                },
            };

            mBlurOpacityBrush = new CanvasLinearGradientBrush(sender, stops, CanvasEdgeBehavior.Clamp, CanvasAlphaMode.Premultiplied);
        }
예제 #19
0
        public UGLinearGradientBrush(IUGContext context, Vector2 startPoint, Vector2 endPoint, IEnumerable <UGGradientStop> gradientStops, UGEdgeBehavior edgeBehavior)
        {
            var count = gradientStops.Count();

            if (count < 2)
            {
                throw new ArgumentException(nameof(gradientStops));
            }

            var device     = ((UGContext)context).Device;
            var winrtStops = gradientStops.ToWinRTGradientStops();
            var native     = new CanvasLinearGradientBrush(device, winrtStops, edgeBehavior.ToWinRTEdgeBehavior(), CanvasAlphaMode.Premultiplied);

            native.StartPoint = startPoint;
            native.EndPoint   = endPoint;
            _native           = native;
        }
예제 #20
0
        private void OnCreateResources(CanvasAnimatedControl sender, CanvasCreateResourcesEventArgs args)
        {
            var stops = new CanvasGradientStop[]
            {
                new CanvasGradientStop()
                {
                    Color = Colors.Transparent, Position = 0.1f
                },
                new CanvasGradientStop()
                {
                    Color = Colors.White, Position = 0.3f
                },
                new CanvasGradientStop()
                {
                    Color = Colors.White, Position = 0.7f
                },
                new CanvasGradientStop()
                {
                    Color = Colors.Transparent, Position = 0.9f
                },
            };

            textOpacityBrush = new CanvasLinearGradientBrush(sender, stops, CanvasEdgeBehavior.Clamp, CanvasAlphaMode.Premultiplied);

            stops = new CanvasGradientStop[]
            {
                new CanvasGradientStop()
                {
                    Color = Colors.White, Position = 0.0f
                },
                new CanvasGradientStop()
                {
                    Color = Colors.Transparent, Position = 0.3f
                },
                new CanvasGradientStop()
                {
                    Color = Colors.Transparent, Position = 0.7f
                },
                new CanvasGradientStop()
                {
                    Color = Colors.White, Position = 1.0f
                },
            };

            blurOpacityBrush = new CanvasLinearGradientBrush(sender, stops, CanvasEdgeBehavior.Clamp, CanvasAlphaMode.Premultiplied);
        }
        public static void CalculateGradient(
            Color clr1,
            Color clr2,
            int nThickness,
            IList <Color> list)
        {
            list.Clear();
            int nWidth = nThickness;

            CanvasGradientStop[] grad_stops = new CanvasGradientStop[2];
            grad_stops[0]          = new CanvasGradientStop();
            grad_stops[0].Color    = clr1;
            grad_stops[0].Position = 0.0f;
            grad_stops[1]          = new CanvasGradientStop();
            grad_stops[1].Color    = clr2;
            grad_stops[1].Position = 1.0f;
            CanvasDevice device             = CanvasDevice.GetSharedDevice();
            CanvasLinearGradientBrush brush = new CanvasLinearGradientBrush(device, grad_stops);

            brush.StartPoint = new Vector2(0, 0);
            brush.EndPoint   = new Vector2(nWidth, 0);

            using (CanvasRenderTarget offscreen = new CanvasRenderTarget(device, nWidth, 1, 96, Windows.Graphics.DirectX.DirectXPixelFormat.B8G8R8A8UIntNormalized,
                                                                         CanvasAlphaMode.Premultiplied))
            {
                using (CanvasDrawingSession ds = offscreen.CreateDrawingSession())
                {
                    ds.DrawRectangle(new Rect(0, 0, nWidth, 1), brush);
                }

                uint   stride = 4;
                byte[] pixels = offscreen.GetPixelBytes();

                for (uint row = 0; row < 1; ++row)
                {
                    for (uint col = 0; col < nWidth; ++col)
                    {
                        uint  index    = (uint)(row * stride + col) * 4;
                        uint  color    = pixels[index];
                        Color gdiColor = Color.FromArgb(pixels[index + 3], pixels[index + 2], pixels[index + 1], pixels[index]);
                        list.Add(gdiColor);
                    }
                }
            }
        }
예제 #22
0
        public TextControl()
        {
            this.InitializeComponent();

            _textFormat = new CanvasTextFormat
            {
                FontFamily   = "Consolas",
                FontSize     = 12,
                WordWrapping = CanvasWordWrapping.NoWrap
            };

            CanvasRoot.CreateResources += (s, e) =>
            {
                _defaultForegroundBrush = new CanvasSolidColorBrush(s, _defaultForegroundColor);
                _addedForegroundBrush   = new CanvasSolidColorBrush(s, _addedForegroundColor);
                _removedForegroundBrush = new CanvasSolidColorBrush(s, _removedForegroundColor);

                var stops = new CanvasGradientStop[4]
                {
                    new CanvasGradientStop {
                        Color = _defaultBackgroundColor, Position = 0
                    },
                    new CanvasGradientStop {
                        Color = _defaultBackgroundColor, Position = 0.5f
                    },
                    new CanvasGradientStop {
                        Color = _nullBackgroundColor, Position = 0.5f
                    },
                    new CanvasGradientStop {
                        Color = _nullBackgroundColor, Position = 1
                    }
                };

                _nullBrush = new CanvasLinearGradientBrush(s, stops, CanvasEdgeBehavior.Mirror, CanvasAlphaMode.Premultiplied)
                {
                    StartPoint = new System.Numerics.Vector2(0, 0),
                    EndPoint   = new System.Numerics.Vector2(4, 4)
                };
            };

            CanvasRoot.SizeChanged += (s, e) =>
            {
                CanvasRoot.Invalidate();
            };
        }
예제 #23
0
 private void Dispose(bool disposing)
 {
     if (_canvasLinearGradientBrush != null)
     {
         try
         {
             _canvasLinearGradientBrush.Dispose();
         }
         catch
         {
             // Ignore
         }
         finally
         {
             _canvasLinearGradientBrush = null;
         }
     }
 }
예제 #24
0
        async Task Canvas_CreateResourcesAsync(CanvasControl sender)
        {
            bitmap = await CanvasBitmap.LoadAsync(sender, "imageTiger.jpg");

            redBrush   = CreateGradientBrush(sender, 255, 0, 0);
            greenBrush = CreateGradientBrush(sender, 0, 255, 0);
            blueBrush  = CreateGradientBrush(sender, 0, 0, 255);

            brightnessEffect = new BrightnessEffect {
                Source = bitmap
            };
            saturationEffect = new SaturationEffect {
                Source = brightnessEffect
            };
            hueEffect = new HueRotationEffect {
                Source = saturationEffect
            };
        }
예제 #25
0
        public override ICanvasBrush GetBrush(CanvasDevice device, byte alpha)
        {
            var startPoint = new Vector2(_x0, _y0);
            var endPoint   = new Vector2(_x1, _y1);

            startPoint = LocalMatrix.Transform(startPoint);
            endPoint   = LocalMatrix.Transform(endPoint);

            var canvasLinearGradientBrush = new CanvasLinearGradientBrush(device,
                                                                          _canvasGradientStopCollection, CanvasEdgeBehavior.Clamp, CanvasAlphaMode.Straight)
            {
                StartPoint = startPoint,
                EndPoint   = endPoint,
                Opacity    = alpha / 255f
            };

            return(canvasLinearGradientBrush);
        }
        private void CanvasAnimatedControl_Draw(Microsoft.Graphics.Canvas.UI.Xaml.ICanvasAnimatedControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasAnimatedDrawEventArgs args)
        {
            using (var cpb = new CanvasPathBuilder(args.DrawingSession))
            {
                cpb.BeginFigure(0, height);
                average = averageSmoother.Smooth(AudioManager.AudioAverage);
                Vector2 p0 = new Vector2(Point0, height - Adjust(smoother1.Smooth(AudioManager.AudioSpec1)) * height);
                Vector2 p1 = new Vector2(Point1, height - Adjust(smoother2.Smooth(AudioManager.AudioSpec2)) * height);
                Vector2 p2 = new Vector2(Point2, height - Adjust(smoother3.Smooth(AudioManager.AudioSpec3)) * height);
                Vector2 p3 = new Vector2(Point3, height - Adjust(smoother4.Smooth(AudioManager.AudioSpec4)) * height);
                Vector2 p4 = new Vector2(Point4, height - Adjust(smoother5.Smooth(AudioManager.AudioSpec5)) * height);
                Vector2 p5 = new Vector2(Point5, height - Adjust(smoother6.Smooth(AudioManager.AudioSpec6)) * height);
                Vector2 p6 = new Vector2(Point6, height - Adjust(smoother7.Smooth(AudioManager.AudioSpec7)) * height);
                Vector2 p7 = new Vector2(Point7, height - Adjust(smoother8.Smooth(AudioManager.AudioSpec8)) * height);
                Vector2 p8 = new Vector2(Point8, height - Adjust(smoother9.Smooth(AudioManager.AudioSpec9)) * height);



                cpb.AddLine(p0);
                cpb.AddCubicBezier(GetC1(p0), GetC2(p1), p1);
                cpb.AddCubicBezier(GetC1(p1), GetC2(p2), p2);
                cpb.AddCubicBezier(GetC1(p2), GetC2(p3), p3);
                cpb.AddCubicBezier(GetC1(p3), GetC2(p4), p4);
                cpb.AddCubicBezier(GetC1(p4), GetC2(p5), p5);
                cpb.AddCubicBezier(GetC1(p5), GetC2(p6), p6);
                cpb.AddCubicBezier(GetC1(p6), GetC2(p7), p7);
                cpb.AddCubicBezier(GetC1(p7), GetC2(p8), p8);
                cpb.AddLine(new Vector2(p8.X, height));


                cpb.EndFigure(CanvasFigureLoop.Closed);
                CanvasLinearGradientBrush gradient = new CanvasLinearGradientBrush(sender, TransparentBlurple, Blurple)
                {
                    EndPoint   = new Vector2(0, height + 48),
                    StartPoint = new Vector2(0, -12)
                };
                var path = CanvasGeometry.CreatePath(cpb);
                //args.DrawingSession.DrawGeometry(path, Blurple, 1);
                args.DrawingSession.FillGeometry(path, gradient);
            }
        }
예제 #27
0
        internal virtual void fillLinearGradient(int startColor, int endColor, int x, int y, int width, int height, bool horizontal)
        {
            //using (createAlphaLayer())
            //{
            var starcolor = new Color()
            {
                A = (byte)alpha, B = (byte)(startColor & 0xff), G = (byte)((startColor >> 8) & 0xff), R = (byte)((startColor >> 16) & 0xff)
            };
            var endcolor = new Color()
            {
                A = (byte)alpha, B = (byte)(endColor & 0xff), G = (byte)((endColor >> 8) & 0xff), R = (byte)((endColor >> 16) & 0xff)
            };

            CanvasLinearGradientBrush brush = new CanvasLinearGradientBrush(graphics, starcolor, endcolor);

            brush.StartPoint = new Vector2()
            {
                X = x,
                Y = y,
            };
            if (horizontal)
            {
                brush.EndPoint = new Vector2()
                {
                    X = x + width,
                    Y = y,
                };
            }
            else
            {
                brush.EndPoint = new Vector2()
                {
                    X = x,
                    Y = y + height,
                };
            }
            graphics.FillRectangle(x, y, width, height, brush);
            //}
        }
예제 #28
0
        void CreateLinearGradient(ICanvasResourceCreator resourceCreator)
        {
            var commandList = new CanvasCommandList(resourceCreator);

            using (var drawingSession = commandList.CreateDrawingSession())
            {
                var brush = new CanvasLinearGradientBrush(resourceCreator, Colors.White, Colors.Black)
                {
                    StartPoint = new Vector2(-tigerSize.X / 4, 0),
                    EndPoint   = new Vector2(tigerSize.X * 5 / 4, 0),
                };

                // Expand the bounds to avoid going past the edge of the gradient as we rotate it.
                var expandedBounds = new Rect((-tigerSize).ToPoint(), (tigerSize * 2).ToPoint());

                drawingSession.FillRectangle(expandedBounds, brush);
            }

            linearGradient = new Transform2DEffect
            {
                Source = commandList
            };
        }
예제 #29
0
        void m_canvasControl_CreateResources(CanvasControl sender, object args)
        {
            m_bitmap_tiger      = null;
            m_bitmap_colorGrids = null;

            UpdateCanvasControlSize();
            m_imageBrush = new CanvasImageBrush(sender);

            m_offscreenTarget = new CanvasRenderTarget(sender, 100, 100);

            using (CanvasDrawingSession ds = m_offscreenTarget.CreateDrawingSession())
            {
                ds.Clear(Colors.DarkBlue);
                ds.FillRoundedRectangle(new Rect(0, 0, 100, 100), 30, 30, Colors.DarkRed);
                ds.DrawRoundedRectangle(new Rect(0, 0, 100, 100), 30, 30, Colors.LightGreen);
                ds.DrawText("Abc", 0, 0, Colors.LightGray);
                ds.DrawText("Def", 25, 25, Colors.LightGray);
                ds.DrawText("Efg", 50, 50, Colors.LightGray);
            }

            CanvasGradientStop[] stops = new CanvasGradientStop[4];
            stops[0].Position     = 0;
            stops[0].Color        = Colors.Black;
            stops[1].Position     = 1;
            stops[1].Color        = Colors.White;
            stops[2].Position     = 0.2f;
            stops[2].Color        = Colors.Purple;
            stops[3].Position     = 0.7f;
            stops[3].Color        = Colors.Green;
            m_linearGradientBrush = CanvasLinearGradientBrush.CreateRainbow(sender, 0.0f);
            m_radialGradientBrush = new CanvasRadialGradientBrush(
                sender,
                stops,
                CanvasEdgeBehavior.Clamp,
                CanvasAlphaMode.Premultiplied);
        }
예제 #30
0
        public static CanvasRenderTarget GenImage(int width, int height, CanvasLinearGradientBrush brush, byte alpha)
        {
            CanvasDevice device = CanvasDevice.GetSharedDevice();

            CanvasRenderTarget offscreen = new CanvasRenderTarget(device, width, height, 96, Windows.Graphics.DirectX.DirectXPixelFormat.B8G8R8A8UIntNormalized,
                                                                  CanvasAlphaMode.Premultiplied);

            using (CanvasDrawingSession ds = offscreen.CreateDrawingSession())
            {
                ds.FillRectangle(new Rect(0.0, 0.0, offscreen.SizeInPixels.Width, offscreen.SizeInPixels.Height), brush);
            }

            byte[] pixels = offscreen.GetPixelBytes();

            if (pixels == null)
            {
                return(null);
            }

            uint col    = 0;
            uint stride = offscreen.SizeInPixels.Width;

            for (uint row = 0; row < offscreen.SizeInPixels.Height; ++row)
            {
                uint total_row_len = (uint)(row * stride);
                for (col = 0; col < offscreen.SizeInPixels.Width; ++col)
                {
                    uint index = (total_row_len + col) * 4;

                    pixels[index + 3] = alpha;
                }
            }
            offscreen.SetPixelBytes(pixels);

            return(offscreen);
        }
예제 #31
0
        void CreateLinearGradient(ICanvasResourceCreator resourceCreator)
        {
            var commandList = new CanvasCommandList(resourceCreator);

            using (var drawingSession = commandList.CreateDrawingSession())
            {
                var brush = new CanvasLinearGradientBrush(resourceCreator, Colors.White, Colors.Black)
                {
                    StartPoint = new Vector2(-tigerSize.X / 4, 0),
                    EndPoint   = new Vector2(tigerSize.X * 5 / 4, 0),
                };

                drawingSession.FillRectangle(bitmapTiger.Bounds, brush);
            }

            // Wrap the gradient with a border effect to avoid edge artifacts as we rotate it.
            linearGradient = new Transform2DEffect
            {
                Source = new BorderEffect
                {
                    Source = commandList
                }
            };
        }
예제 #32
0
        private void OnCreateResources(CanvasAnimatedControl sender, CanvasCreateResourcesEventArgs args)
        {
            var stops = new CanvasGradientStop[]
            {
                new CanvasGradientStop() { Color=Colors.Transparent, Position=0.1f },
                new CanvasGradientStop() { Color=Colors.White, Position = 0.3f },
                new CanvasGradientStop() { Color=Colors.White, Position = 0.7f },
                new CanvasGradientStop() { Color=Colors.Transparent, Position = 0.9f },
            };

            textOpacityBrush = new CanvasLinearGradientBrush(sender, stops, CanvasEdgeBehavior.Clamp, CanvasAlphaMode.Premultiplied);

            stops = new CanvasGradientStop[]
            {
                new CanvasGradientStop() { Color=Colors.White, Position=0.0f },
                new CanvasGradientStop() { Color=Colors.Transparent, Position = 0.3f },
                new CanvasGradientStop() { Color=Colors.Transparent, Position = 0.7f },
                new CanvasGradientStop() { Color=Colors.White, Position = 1.0f },
            };

            blurOpacityBrush = new CanvasLinearGradientBrush(sender, stops, CanvasEdgeBehavior.Clamp, CanvasAlphaMode.Premultiplied);
        }
예제 #33
0
        void DrawHistogram(CanvasDrawingSession drawingSession, Size size, EffectChannelSelect channelSelect, CanvasLinearGradientBrush brush)
        {
            const int binCount = 64;
            const float graphPower = 0.25f; // Nonlinear scale makes the graph show small changes more clearly.

            float[] histogram = CanvasImage.ComputeHistogram(hueEffect, bitmap.Bounds, drawingSession, channelSelect, binCount);

            var w = (float)size.Width / binCount;
            var h = (float)size.Height;

            for (int i = 0; i < binCount; i++)
            {
                var x = i * w;
                var y = (1 - (float)Math.Pow(histogram[i], graphPower)) * h;

                brush.StartPoint = new Vector2(x, y);
                brush.EndPoint = new Vector2(x, h);

                drawingSession.FillRectangle(x, y, w, h - y, brush);
            }
        }
        /// <summary>
        /// Creates a reflection of the given Visual
        /// </summary>
        /// <param name="visual">Visual whose reflection has to be created</param>
        /// <param name="reflectionDistance">Distance of the reflection from the visual</param>
        /// <param name="reflectionLength">Normalized Length of the reflected visual that will be visible.</param>
        /// <param name="location"> <see cref="ReflectionLocation"/> - Location of the reflection with respect 
        /// to the Visual - Bottom, Top, Left or Right</param>
        public void CreateReflection(ContainerVisual visual, float reflectionDistance = 0f,
            float reflectionLength = 0.7f, ReflectionLocation location = ReflectionLocation.Bottom)
        {
            // Create the visual layer that will contained the visual's reflection
            var reflectionLayer = _compositor.CreateLayerVisual();
            reflectionLayer.Size = visual.Size;
            reflectionLayer.CenterPoint = new Vector3(visual.Size * 0.5f, 0);

            // Create the effect to create the opacity mask
            var effect = new CompositeEffect
            {
                // CanvasComposite.DestinationIn - Intersection of source and mask. 
                // Equation: O = MA * S
                // where O - Output pixel, MA - Mask Alpha, S - Source pixel.
                Mode = CanvasComposite.DestinationIn,
                Sources =
                        {
                            new CompositionEffectSourceParameter("source"),
                            new CompositionEffectSourceParameter("mask")
                        }
            };

            var effectFactory = _compositor.CreateEffectFactory(effect);
            var effectBrush = effectFactory.CreateBrush();

            // Create the gradient brush for the effect
            var gradientBrush = new CanvasLinearGradientBrush(_canvasDevice,
                                                                Colors.White, Colors.Transparent);

            // Based on the reflection location,
            // Set the Offset, RotationAxis and RotationAngleInDegrees of the reflectionLayer and
            // set the StartPoint and EndPoint of the gradientBrush
            switch (location)
            {
                case ReflectionLocation.Bottom:
                    reflectionLayer.RotationAxis = new Vector3(1, 0, 0);
                    reflectionLayer.RotationAngleInDegrees = 180;
                    reflectionLayer.Offset = new Vector3(0, visual.Size.Y + reflectionDistance, 0);
                    gradientBrush.StartPoint = new Vector2(visual.Size.X * 0.5f, 0);
                    gradientBrush.EndPoint = new Vector2(visual.Size.X * 0.5f, visual.Size.Y * reflectionLength);
                    break;
                case ReflectionLocation.Top:
                    reflectionLayer.RotationAxis = new Vector3(1, 0, 0);
                    reflectionLayer.RotationAngleInDegrees = -180;
                    reflectionLayer.Offset = new Vector3(0, -visual.Size.Y - reflectionDistance, 0);
                    gradientBrush.StartPoint = new Vector2(visual.Size.X * 0.5f, visual.Size.Y);
                    gradientBrush.EndPoint = new Vector2(visual.Size.X * 0.5f, visual.Size.Y * (1f - reflectionLength));
                    break;
                case ReflectionLocation.Left:
                    reflectionLayer.RotationAxis = new Vector3(0, 1, 0);
                    reflectionLayer.RotationAngleInDegrees = -180;
                    reflectionLayer.Offset = new Vector3(-visual.Size.X - reflectionDistance, 0, 0);
                    gradientBrush.StartPoint = new Vector2(visual.Size.X, visual.Size.Y * 0.5f);
                    gradientBrush.EndPoint = new Vector2(visual.Size.X * (1f - reflectionLength), visual.Size.Y * 0.5f);
                    break;
                case ReflectionLocation.Right:
                    reflectionLayer.RotationAxis = new Vector3(0, 1, 0);
                    reflectionLayer.RotationAngleInDegrees = 180;
                    reflectionLayer.Offset = new Vector3(visual.Size.X + reflectionDistance, 0, 0);
                    gradientBrush.StartPoint = new Vector2(0, visual.Size.Y * 0.5f);
                    gradientBrush.EndPoint = new Vector2(visual.Size.X * reflectionLength, visual.Size.Y * 0.5f);
                    break;
            }

            // Create a mask filled with gradientBrush
            var mask = CreateGeometrySurface(visual.Size.ToSize(), null, Colors.Transparent, gradientBrush);

            // Set the 'mask' parameter of the effectBrush
            effectBrush.SetSourceParameter("mask", _compositor.CreateSurfaceBrush(mask.Surface));

            // Set the effect for the reflection layer
            reflectionLayer.Effect = effectBrush;

            // Now we need to duplicate the visual tree of the visual
            ArrangeVisualReflection(visual, reflectionLayer, true);

            visual.Children.InsertAtTop(reflectionLayer);
        }
예제 #35
0
        void CreateLinearGradient(ICanvasResourceCreator resourceCreator)
        {
            var commandList = new CanvasCommandList(resourceCreator);

            using (var drawingSession = commandList.CreateDrawingSession())
            {
                var brush = new CanvasLinearGradientBrush(resourceCreator, Colors.White, Colors.Black)
                {
                    StartPoint = new Vector2(-tigerSize.X / 4, 0),
                    EndPoint = new Vector2(tigerSize.X * 5 / 4, 0),
                };

                // Expand the bounds to avoid going past the edge of the gradient as we rotate it.
                var expandedBounds = new Rect((-tigerSize).ToPoint(), (tigerSize * 2).ToPoint());

                drawingSession.FillRectangle(expandedBounds, brush);
            }

            linearGradient = new Transform2DEffect
            {
                Source = commandList
            };
        }
예제 #36
0
        void CreateLinearGradient(ICanvasResourceCreator resourceCreator)
        {
            var commandList = new CanvasCommandList(resourceCreator);

            using (var drawingSession = commandList.CreateDrawingSession())
            {
                var brush = new CanvasLinearGradientBrush(resourceCreator, Colors.White, Colors.Black)
                {
                    StartPoint = new Vector2(-tigerSize.X / 4, 0),
                    EndPoint = new Vector2(tigerSize.X * 5 / 4, 0),
                };

                drawingSession.FillRectangle(bitmapTiger.Bounds, brush);
            }

            // Wrap the gradient with a border effect to avoid edge artifacts as we rotate it.
            linearGradient = new Transform2DEffect
            {
                Source = new BorderEffect
                {
                    Source = commandList
                }
            };
        }
예제 #37
0
        void EnsureResources(ICanvasResourceCreatorWithDpi resourceCreator, Size targetSize)
        {
            if (resourceRealizationSize == targetSize && !needsResourceRecreation)
                return;

            float canvasWidth = (float)targetSize.Width;
            float canvasHeight = (float)targetSize.Height;

            if (textLayout != null) 
                textLayout.Dispose();
            textLayout = CreateTextLayout(resourceCreator, canvasWidth, canvasHeight);

            inlineObject.SetLayout(textLayout);

            Rect layoutBounds = textLayout.LayoutBounds;

            textBrush = new CanvasLinearGradientBrush(resourceCreator, Colors.Red, Colors.Green);
            textBrush.StartPoint = new System.Numerics.Vector2((float)(layoutBounds.Left + layoutBounds.Right) / 2, (float)layoutBounds.Top);
            textBrush.EndPoint = new System.Numerics.Vector2((float)(layoutBounds.Left + layoutBounds.Right) / 2, (float)layoutBounds.Bottom);

            selectionTextBrush = new CanvasLinearGradientBrush(resourceCreator, Colors.Green, Colors.Red);
            selectionTextBrush.StartPoint = textBrush.StartPoint;
            selectionTextBrush.EndPoint = textBrush.EndPoint;

            inlineObjectsEnabledChanged = true;

            needsResourceRecreation = false;
            resourceRealizationSize = targetSize;
        }
예제 #38
0
        internal virtual void fillLinearGradient( int startColor, int endColor, int x, int y, int width, int height, bool horizontal)
        {
            var starcolor = new Color() { A = 0xff, B = (byte)(startColor & 0xff), G = (byte)((startColor >> 8) & 0xff), R = (byte)((startColor >> 16) & 0xff) };
            var endcolor = new Color() { A = 0xff, B = (byte)(endColor & 0xff), G = (byte)((endColor >> 8) & 0xff), R = (byte)((endColor >> 16) & 0xff) };

            CanvasLinearGradientBrush brush = new CanvasLinearGradientBrush(graphics, starcolor, endcolor);
            brush.StartPoint = new Vector2()
            {
                X = x,
                Y = y,
            };
            if (horizontal)
            {
                brush.EndPoint = new Vector2()
                {
                    X = x + width,
                    Y = y,
                };
            }
            else
            {
                brush.EndPoint = new Vector2()
                {
                    X = x,
                    Y = y + height,
                };
            }
            graphics.FillRectangle(x, y, width, height, brush);
        }