예제 #1
0
        public void RenderSelectedStrokes(IEnumerable <Identifier> selectedStrokeIds)
        {
            if (!StrokeHandler.IsSelecting)
            {
                throw new InvalidOperationException("Unexpected call to RenderSelectedStrokes");
            }

            RenderingContext.SetTarget(TranslationLayer);
            RenderingContext.ClearColor(MediaColor.FromArgb(27, 0, 0, 0)); // Black transparent background

            RenderingContext.TransformMatrix = StrokeHandler.TransformationMatrix;

            // Draw the selected strokes
            Rect rect = StrokeHandler.DoRenderSelectedStrokes(RenderingContext, selectedStrokeIds);

            if (selectedStrokeIds.Count() == 0)
            {
                TranslationLayerPainted = false;
            }
            else
            {
                TranslationLayerPainted = true;
            }
            RenderingContext.TransformMatrix = Matrix3x2.Identity;
        }
예제 #2
0
 private void UpdateControl(RangeSliderControl control, RangeSlider element)
 {
     control.IgnoreRangeChecks     = true;
     control.Minimum               = element.MinimumValue;
     control.Maximum               = element.MaximumValue;
     control.RangeMin              = element.LowerValue;
     control.RangeMax              = element.UpperValue;
     control.MinThumbHidden        = element.MinThumbHidden;
     control.MinThumbTextHidden    = element.MinThumbTextHidden;
     control.MaxThumbHidden        = element.MaxThumbHidden;
     control.MaxThumbTextHidden    = element.MaxThumbTextHidden;
     control.StepValue             = element.StepValue;
     control.StepValueContinuously = element.StepValueContinuously;
     if (element.BarHeight.HasValue)
     {
         control.SetBarHeight(element.BarHeight.Value);
     }
     control.ShowTextAboveThumbs = element.ShowTextAboveThumbs;
     control.TextSize            = (int)element.TextSize;
     control.TextFormat          = element.TextFormat;
     if (element.TextColor != Xamarin.Forms.Color.Default)
     {
         control.TextColor = Color.FromArgb((byte)(element.TextColor.A * 255), (byte)(element.TextColor.R * 255), (byte)(element.TextColor.G * 255), (byte)(element.TextColor.B * 255));
     }
     control.FormatLabel       = element.FormatLabel;
     control.IgnoreRangeChecks = false;
     control.ValidateMinValue(element.LowerValue);
     control.ValidateMaxValue(element.UpperValue);
     if (element.ActiveColor != Xamarin.Forms.Color.Default)
     {
         control.ActiveColor = Color.FromArgb((byte)(element.ActiveColor.A * 255), (byte)(element.ActiveColor.R * 255), (byte)(element.ActiveColor.G * 255), (byte)(element.ActiveColor.B * 255));
     }
 }
        public override void StartSelectionMode(SelectionMode mode)
        {
            mSavedColor = BrushColor;

            if (mSelectTool != null && mSelectTool.SelectedStrokes.Count > 0)
            {
                mRenderer.InvokeRedrawAllStrokes();
            }

            ManipulationMode manipulation = (mode & SelectionMode.Whole) != 0 ? ManipulationMode.WholeStroke : ManipulationMode.PartialStroke;

            if ((mode & SelectionMode.Manipulate) != 0)
            {
                var manipulationTool = new VectorManipulationTool(this, manipulation);
                manipulationTool.OnTranslate       += OnToolTranslate;
                manipulationTool.TranslateFinished += OnToolTranslateFinished;
                manipulationTool.DrawingFinished   += OnManipulationSelectFinished;
                mSelectTool = manipulationTool;
            }
            else if ((mode & SelectionMode.Erase) != 0)
            {
                var eraseTool = new VectorEraserTool(manipulation);
                eraseTool.DrawingFinished += OnEraseSelectFinished;
                mSelectTool = eraseTool;
            }

            mSelectTool.PointsAdded += OnPointsAdded;
            mActiveTool              = mSelectTool;

            BrushColor = MediaColor.FromArgb(96, 0, 0, 0);
        }
예제 #4
0
        /// <summary>
        /// Creates a <see cref="Color"/> from the specified hue, saturation, value, and alpha values.
        /// </summary>
        /// <param name="hue">0..360 range hue</param>
        /// <param name="saturation">0..1 range saturation</param>
        /// <param name="value">0..1 range value</param>
        /// <param name="alpha">0..1 alpha</param>
        /// <returns>The created <see cref="Color"/>.</returns>
        public static Color FromHsv(double hue, double saturation, double value, double alpha = 1.0)
        {
            if (hue < 0 || hue > 360)
            {
                throw new ArgumentOutOfRangeException(nameof(hue));
            }

            double chroma = value * saturation;
            double h1 = hue / 60;
            double x = chroma * (1 - Math.Abs((h1 % 2) - 1));
            double m = value - chroma;
            double r1, g1, b1;

            if (h1 < 1)
            {
                r1 = chroma;
                g1 = x;
                b1 = 0;
            }
            else if (h1 < 2)
            {
                r1 = x;
                g1 = chroma;
                b1 = 0;
            }
            else if (h1 < 3)
            {
                r1 = 0;
                g1 = chroma;
                b1 = x;
            }
            else if (h1 < 4)
            {
                r1 = 0;
                g1 = x;
                b1 = chroma;
            }
            else if (h1 < 5)
            {
                r1 = x;
                g1 = 0;
                b1 = chroma;
            }
            else
            {
                r1 = chroma;
                g1 = 0;
                b1 = x;
            }

            byte r = (byte)(255 * (r1 + m));
            byte g = (byte)(255 * (g1 + m));
            byte b = (byte)(255 * (b1 + m));
            byte a = (byte)(255 * alpha);

            return(Color.FromArgb(a, r, g, b));
        }
예제 #5
0
        //颜色选择器变化
        private void ColorPicker_ColorChanged(Windows.UI.Color Color, SolidColorBrush Brush)
        {
            isSalf     = true;
            this.Color = Color.FromArgb(Color.A, Color.R, Color.G, Color.B);  //改变颜色
            ColorChanged?.Invoke(this.Color);

            isSalf = false;

            Border.Background = Brush;
        }
예제 #6
0
        void IAstVisitor <ParsingContext> .Visit(FontNode node, ParsingContext context)
        {
            bool flag = false;

            if (node.HexColor.Length > 0)
            {
                flag = true;
                var c     = (System.Drawing.Color)colorConverter.ConvertFromString(node.HexColor);
                var color = Color.FromArgb(c.A, c.R, c.G, c.B);
                context.Colors.Push(new SolidColorBrush(color));
            }
            foreach (var item in node.Children)
            {
                item.Accept(this, context);
            }
            if (flag)
            {
                context.Colors.Pop();
            }
        }
예제 #7
0
        private void DrawTargetContacts(CanvasDrawingSession ds)
        {
            const float Z = 0;
            const float E = EditMargin + EditSize + EditMargin;

            var cp = Center;

            CheckContacts();
            var N = _contactTargets.Count;

            _targetPoints.Clear();
            for (int i = 0; i < N; i++)
            {
                var(cont, targ, point, size) = _contactTargets[i];
                var p = point * EditScale;
                var c = Center + p;
                _targetPoints.Add(c);
                ds.DrawCircle(c, 8, Colors.Cyan, 5);

                #region DrawSimulatedEdge  ====================================
                switch (targ)
                {
                case Target.N:
                    ds.DrawLine(c.X, c.Y, c.X, Z, Colors.Cyan, 3);
                    break;

                case Target.S:
                    ds.DrawLine(c.X, c.Y, c.X, E, Colors.Cyan, 3);
                    break;

                case Target.E:
                    ds.DrawLine(c.X, c.Y, E, c.Y, Colors.Cyan, 3);
                    break;

                case Target.W:
                    ds.DrawLine(c.X, c.Y, Z, c.Y, Colors.Cyan, 3);
                    break;

                case Target.NE:
                    ds.DrawLine(c.X, c.Y, c.X, Z, Colors.Cyan, 3);
                    break;

                case Target.NW:
                    ds.DrawLine(c.X, c.Y, c.X, Z, Colors.Cyan, 3);
                    break;

                case Target.SE:
                    ds.DrawLine(c.X, c.Y, c.X, E, Colors.Cyan, 3);
                    break;

                case Target.SW:
                    ds.DrawLine(c.X, c.Y, c.X, E, Colors.Cyan, 3);
                    break;

                case Target.EN:
                    ds.DrawLine(c.X, c.Y, E, c.Y, Colors.Cyan, 3);
                    break;

                case Target.ES:
                    ds.DrawLine(c.X, c.Y, E, c.Y, Colors.Cyan, 3);
                    break;

                case Target.WN:
                    ds.DrawLine(c.X, c.Y, Z, c.Y, Colors.Cyan, 3);
                    break;

                case Target.WS:
                    ds.DrawLine(c.X, c.Y, Z, c.Y, Colors.Cyan, 3);
                    break;

                case Target.NEC:
                    ds.DrawLine(c.X, c.Y, E, Z, Colors.Cyan, 3);
                    break;

                case Target.NWC:
                    ds.DrawLine(c.X, c.Y, Z, Z, Colors.Cyan, 3);
                    break;

                case Target.SEC:
                    ds.DrawLine(c.X, c.Y, E, E, Colors.Cyan, 3);
                    break;

                case Target.SWC:
                    ds.DrawLine(c.X, c.Y, Z, E, Colors.Cyan, 3);
                    break;
                }
                #endregion

                if (cont == Contact.Any && size > 0)
                {
                    var(p1, p2) = XYTuple.GetScaledNormal(targ, point, size, Center, EditScale);
                    ds.DrawLine(p1, p2, Color.FromArgb(0x80, 0xFF, 0, 0), 20);
                }
            }
        }
예제 #8
0
        private void DrawEditorBackgroundGrid(CanvasDrawingSession ds)
        {
            var color1 = Color.FromArgb(0xff, 0xff, 0xff, 0xff);
            var color2 = Color.FromArgb(0xff, 0xff, 0xff, 0x80);
            var color3 = Color.FromArgb(0x80, 0xff, 0xff, 0x00);
            var color4 = Color.FromArgb(0x40, 0xff, 0xff, 0xff);

            var a = EditMargin;   //north or west axis line
            var b = a + EditSize; //south or east axis line
            var c = EDITCenter;   //center axis line
            var r = EditSize / 2;

            var d = r * Math.Sin(Math.PI / 8);
            var e = (float)(c - d);
            var f = (float)(c + d);

            for (int i = 0; i <= EditSize; i += _workGrid)
            {
                var z = a + i;
                ds.DrawLine(z, a, z, b, color3);
                ds.DrawLine(a, z, b, z, color3);
            }
            ds.DrawLine(2, 2, 10, 14, color1, 3);
            ds.DrawLine(2, 2, 14, 10, color1, 3);
            ds.DrawLine(0, 0, b, b, color1);
            ds.DrawLine(0, 0, b, b, color1);
            ds.DrawLine(a, b, b, a, color1);

            ds.DrawLine(a, e, b, f, color4);
            ds.DrawLine(e, a, f, b, color4);

            ds.DrawLine(a, f, b, e, color4);
            ds.DrawLine(f, a, e, b, color4);

            ds.DrawCircle(c, c, r, color2);
            ds.DrawCircle(c, c, r / 2, color4);

            for (int i = 0; i <= EditSize; i += _workAxis)
            {
                var z = a + i;
                ds.DrawLine(z, a, z, b, color1);
                ds.DrawLine(a, z, b, z, color1);
            }
            var xC  = c - 6;
            var yN  = -2;
            var yS  = b - 3;
            var xe  = b - _workAxis - 10;
            var xw  = a + _workAxis - 10;
            var xec = b - 10;
            var xwc = a - 16;

            ds.DrawText("nec", xec, yN, color3);
            ds.DrawText("ne", xe, yN, color3);
            ds.DrawText("N", xC, yN, color1);
            ds.DrawText("nw", xw, yN, color3);
            ds.DrawText("nwc", xwc, yN, color3);

            ds.DrawText("sec", xec, yS, color3);
            ds.DrawText("se", xe, yS, color3);
            ds.DrawText("S", xC, yS, color1);
            ds.DrawText("sw", xw, yS, color3);
            ds.DrawText("swc", xwc, yS, color3);


            var xE = b + 3;
            var xW = 8;
            var yC = c - 14;
            var yn = a + _workAxis - 14;
            var ys = b - _workAxis - 14;

            ds.DrawText("en", xE, yn, color3);
            ds.DrawText("E", xE, yC, color1);
            ds.DrawText("es", xE, ys, color3);

            ds.DrawText("wn", xW - 4, yn, color3);
            ds.DrawText("W", xW, yC, color1);
            ds.DrawText("ws", xW - 4, ys, color3);
        }
예제 #9
0
        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

            if (e.PropertyName == RangeSlider.LowerValueProperty.PropertyName)
            {
                Control.RangeMin = Element.LowerValue;
            }
            else if (e.PropertyName == RangeSlider.UpperValueProperty.PropertyName)
            {
                Control.RangeMax = Element.UpperValue;
            }
            else if (e.PropertyName == RangeSlider.MinimumValueProperty.PropertyName)
            {
                Control.Minimum = Element.MinimumValue;
            }
            else if (e.PropertyName == RangeSlider.MaximumValueProperty.PropertyName)
            {
                Control.Maximum = Element.MaximumValue;
            }
            else if (e.PropertyName == RangeSlider.MaxThumbHiddenProperty.PropertyName)
            {
                Control.MaxThumbHidden = Element.MaxThumbHidden;
            }
            else if (e.PropertyName == RangeSlider.MinThumbHiddenProperty.PropertyName)
            {
                Control.MinThumbHidden = Element.MinThumbHidden;
            }
            else if (e.PropertyName == RangeSlider.StepValueProperty.PropertyName)
            {
                Control.StepValue = Element.StepValue;
            }
            else if (e.PropertyName == RangeSlider.StepValueContinuouslyProperty.PropertyName)
            {
                Control.StepValueContinuously = Element.StepValueContinuously;
            }
            else if (e.PropertyName == RangeSlider.BarHeightProperty.PropertyName)
            {
                if (Element.BarHeight.HasValue)
                {
                    Control.SetBarHeight(Element.BarHeight.Value);
                }
            }
            else if (e.PropertyName == RangeSlider.ShowTextAboveThumbsProperty.PropertyName)
            {
                Control.ShowTextAboveThumbs = Element.ShowTextAboveThumbs;
            }
            else if (e.PropertyName == RangeSlider.TextSizeProperty.PropertyName)
            {
                Control.TextSize = (int)Element.TextSize;
            }
            else if (e.PropertyName == RangeSlider.TextFormatProperty.PropertyName)
            {
                Control.TextFormat = Element.TextFormat;
            }
            else if (e.PropertyName == RangeSlider.TextColorProperty.PropertyName)
            {
                if (Element.TextColor != Xamarin.Forms.Color.Default)
                {
                    Control.TextColor = Color.FromArgb((byte)(Element.TextColor.A * 255), (byte)(Element.TextColor.R * 255), (byte)(Element.TextColor.G * 255), (byte)(Element.TextColor.B * 255));
                }
            }
            else if (e.PropertyName == RangeSlider.FormatLabelProperty.PropertyName)
            {
                Control.FormatLabel = Element.FormatLabel;
            }
            else if (e.PropertyName == RangeSlider.ActiveColorProperty.PropertyName)
            {
                if (Element.ActiveColor != Xamarin.Forms.Color.Default)
                {
                    Control.ActiveColor = Color.FromArgb((byte)(Element.ActiveColor.A * 255), (byte)(Element.ActiveColor.R * 255), (byte)(Element.ActiveColor.G * 255), (byte)(Element.ActiveColor.B * 255));
                }
            }
            else if (e.PropertyName == RangeSlider.MinThumbTextHiddenProperty.PropertyName)
            {
                Control.MinThumbTextHidden = Element.MinThumbTextHidden;
            }
            else if (e.PropertyName == RangeSlider.MaxThumbTextHiddenProperty.PropertyName)
            {
                Control.MaxThumbTextHidden = Element.MaxThumbTextHidden;
            }
        }
예제 #10
0
        /// <summary>
        /// Creates a <see cref="Color"/> from a XAML color string.
        /// Any format used in XAML should work.
        /// </summary>
        /// <param name="colorString">The XAML color string.</param>
        /// <returns>The created <see cref="Color"/>.</returns>
        public static Color ToColor(this string colorString)
        {
            if (string.IsNullOrEmpty(colorString))
            {
                throw new ArgumentException(nameof(colorString));
            }

            if (colorString[0] == '#')
            {
                switch (colorString.Length)
                {
                case 9:
                {
                    var cuint = Convert.ToUInt32(colorString.Substring(1), 16);
                    var a     = (byte)(cuint >> 24);
                    var r     = (byte)((cuint >> 16) & 0xff);
                    var g     = (byte)((cuint >> 8) & 0xff);
                    var b     = (byte)(cuint & 0xff);

                    return(Color.FromArgb(a, r, g, b));
                }

                case 7:
                {
                    var cuint = Convert.ToUInt32(colorString.Substring(1), 16);
                    var r     = (byte)((cuint >> 16) & 0xff);
                    var g     = (byte)((cuint >> 8) & 0xff);
                    var b     = (byte)(cuint & 0xff);

                    return(Color.FromArgb(255, r, g, b));
                }

                case 5:
                {
                    var cuint = Convert.ToUInt16(colorString.Substring(1), 16);
                    var a     = (byte)(cuint >> 12);
                    var r     = (byte)((cuint >> 8) & 0xf);
                    var g     = (byte)((cuint >> 4) & 0xf);
                    var b     = (byte)(cuint & 0xf);
                    a = (byte)(a << 4 | a);
                    r = (byte)(r << 4 | r);
                    g = (byte)(g << 4 | g);
                    b = (byte)(b << 4 | b);

                    return(Color.FromArgb(a, r, g, b));
                }

                case 4:
                {
                    var cuint = Convert.ToUInt16(colorString.Substring(1), 16);
                    var r     = (byte)((cuint >> 8) & 0xf);
                    var g     = (byte)((cuint >> 4) & 0xf);
                    var b     = (byte)(cuint & 0xf);
                    r = (byte)(r << 4 | r);
                    g = (byte)(g << 4 | g);
                    b = (byte)(b << 4 | b);

                    return(Color.FromArgb(255, r, g, b));
                }

                default:
                    throw new FormatException(string.Format("The {0} string passed in the colorString argument is not a recognized Color format.", colorString));
                }
            }

            if (colorString.Length > 3 && colorString[0] == 's' && colorString[1] == 'c' && colorString[2] == '#')
            {
                var values = colorString.Split(',');

                if (values.Length == 4)
                {
                    var scA = double.Parse(values[0].Substring(3));
                    var scR = double.Parse(values[1]);
                    var scG = double.Parse(values[2]);
                    var scB = double.Parse(values[3]);

                    return(Color.FromArgb((byte)(scA * 255), (byte)(scR * 255), (byte)(scG * 255), (byte)(scB * 255)));
                }

                if (values.Length == 3)
                {
                    var scR = double.Parse(values[0].Substring(3));
                    var scG = double.Parse(values[1]);
                    var scB = double.Parse(values[2]);

                    return(Color.FromArgb(255, (byte)(scR * 255), (byte)(scG * 255), (byte)(scB * 255)));
                }

                throw new FormatException(string.Format("The {0} string passed in the colorString argument is not a recognized Color format (sc#[scA,]scR,scG,scB).", colorString));
            }

            var prop = typeof(Colors).GetTypeInfo().GetDeclaredProperty(colorString);

            if (prop != null)
            {
                return((Color)prop.GetValue(null));
            }

            throw new FormatException(string.Format("The {0} string passed in the colorString argument is not a recognized Color.", colorString));
        }
예제 #11
0
        /// <summary>
        /// Creates a <see cref="Color"/> from a XAML color string.
        /// Any format used in XAML should work.
        /// </summary>
        /// <param name="colorString">The XAML color string.</param>
        /// <returns>The created <see cref="Color"/>.</returns>
        public static Color ToColor(this string colorString)
        {
            if (string.IsNullOrEmpty(colorString))
            {
                ThrowArgumentException();
            }

            if (colorString[0] == '#')
            {
                switch (colorString.Length)
                {
                case 9:
                {
                    var cuint = Convert.ToUInt32(colorString.Substring(1), 16);
                    var a     = (byte)(cuint >> 24);
                    var r     = (byte)((cuint >> 16) & 0xff);
                    var g     = (byte)((cuint >> 8) & 0xff);
                    var b     = (byte)(cuint & 0xff);

                    return(Color.FromArgb(a, r, g, b));
                }

                case 7:
                {
                    var cuint = Convert.ToUInt32(colorString.Substring(1), 16);
                    var r     = (byte)((cuint >> 16) & 0xff);
                    var g     = (byte)((cuint >> 8) & 0xff);
                    var b     = (byte)(cuint & 0xff);

                    return(Color.FromArgb(255, r, g, b));
                }

                case 5:
                {
                    var cuint = Convert.ToUInt16(colorString.Substring(1), 16);
                    var a     = (byte)(cuint >> 12);
                    var r     = (byte)((cuint >> 8) & 0xf);
                    var g     = (byte)((cuint >> 4) & 0xf);
                    var b     = (byte)(cuint & 0xf);
                    a = (byte)(a << 4 | a);
                    r = (byte)(r << 4 | r);
                    g = (byte)(g << 4 | g);
                    b = (byte)(b << 4 | b);

                    return(Color.FromArgb(a, r, g, b));
                }

                case 4:
                {
                    var cuint = Convert.ToUInt16(colorString.Substring(1), 16);
                    var r     = (byte)((cuint >> 8) & 0xf);
                    var g     = (byte)((cuint >> 4) & 0xf);
                    var b     = (byte)(cuint & 0xf);
                    r = (byte)(r << 4 | r);
                    g = (byte)(g << 4 | g);
                    b = (byte)(b << 4 | b);

                    return(Color.FromArgb(255, r, g, b));
                }

                default: return(ThrowFormatException());
                }
            }

            if (colorString.Length > 3 && colorString[0] == 's' && colorString[1] == 'c' && colorString[2] == '#')
            {
                var values = colorString.Split(',');

                if (values.Length == 4)
                {
                    var scA = double.Parse(values[0].Substring(3), CultureInfo.InvariantCulture);
                    var scR = double.Parse(values[1], CultureInfo.InvariantCulture);
                    var scG = double.Parse(values[2], CultureInfo.InvariantCulture);
                    var scB = double.Parse(values[3], CultureInfo.InvariantCulture);

                    return(Color.FromArgb((byte)(scA * 255), (byte)(scR * 255), (byte)(scG * 255), (byte)(scB * 255)));
                }

                if (values.Length == 3)
                {
                    var scR = double.Parse(values[0].Substring(3), CultureInfo.InvariantCulture);
                    var scG = double.Parse(values[1], CultureInfo.InvariantCulture);
                    var scB = double.Parse(values[2], CultureInfo.InvariantCulture);

                    return(Color.FromArgb(255, (byte)(scR * 255), (byte)(scG * 255), (byte)(scB * 255)));
                }

                return(ThrowFormatException());
            }

            var prop = typeof(Colors).GetTypeInfo().GetDeclaredProperty(colorString);

            if (prop != null)
            {
                return((Color)prop.GetValue(null));
            }

            return(ThrowFormatException());