コード例 #1
0
 public Brush ConvertBack([NotNull] SolidColorBrush brush)
 {
     if (brush.IsFrozen)
     {
         brush = brush.CloneCurrentValue();
     }
     brush.Color = ConvertBack(brush.Color);
     return(brush);
 }
コード例 #2
0
 public static Brush StatusToBrush(ProcessingStatus status)
 {
     if (status == ProcessingStatus.Processed)
     {
         return(BrushProcessed.CloneCurrentValue());
     }
     else if (status == ProcessingStatus.Outdated)
     {
         return(BrushOutdated.CloneCurrentValue());
     }
     else if (status == ProcessingStatus.Unprocessed)
     {
         return(BrushUnprocessed.CloneCurrentValue());
     }
     else if (status == ProcessingStatus.FilteredOut)
     {
         return(BrushFilteredOut.CloneCurrentValue());
     }
     else
     {
         return(BrushDeselected.CloneCurrentValue());
     }
 }
コード例 #3
0
        protected object NormalConvert(object value, Type targetType, object parameter, CultureInfo culture, ExOpration operation)
        {
            //解析参数
            Boolean TryParse2Byte(String str, out Byte result)
            {
                if (Double.TryParse(str, out double dr))
                {
                    if (dr >= 0 && dr <= 1)
                    {
                        result = (Byte)(Byte.MaxValue * dr);
                        return(true);
                    }
                    if (dr > 1 && dr <= 255)
                    {
                        result = (Byte)dr;
                        return(true);
                    }
                }
                result = 0;
                return(false);
            }

            Color devColor;

            if (parameter is String)
            {
                devColor = defaultDevColor;
                String[] vs   = ((String)parameter).Split(new char[] { ';' }, 4, StringSplitOptions.RemoveEmptyEntries);
                bool     flag = true;
                int      len  = vs.Length;
                Byte[]   bs   = new Byte[len];
                for (int i = 0; i < len; i++)
                {
                    if (!TryParse2Byte(vs[i], out bs[i]))
                    {
                        flag = false;
                        break;
                    }
                }
                if (flag)
                {
                    if (len == 1)
                    {
                        devColor = Color.FromRgb(bs[0], bs[0], bs[0]);
                    }
                    else if (len == 2)
                    {
                        devColor = Color.FromArgb(bs[0], bs[1], bs[1], bs[1]);
                    }
                    else if (len == 3)
                    {
                        devColor = Color.FromRgb(bs[0], bs[1], bs[2]);
                    }
                    else if (len == 4)
                    {
                        devColor = Color.FromArgb(bs[0], bs[1], bs[2], bs[3]);
                    }
                    else
                    {
                        devColor = defaultDevColor;
                    }
                }
            }
            else
            {
                devColor = defaultDevColor;
            }

            //转换
            if (targetType == typeof(Color))
            {
                if (value is Color)
                {
                    return(ExColorOpration((Color)value, devColor, operation));
                }
                if (value is SolidColorBrush)
                {
                    return(ExColorOpration(((SolidColorBrush)value).Color, devColor, operation));
                }
            }
            else if (targetType == typeof(Brush))
            {
                if (value is Color)
                {
                    return(new SolidColorBrush(ExColorOpration((Color)value, devColor, operation)));
                }
                if (value is SolidColorBrush)
                {
                    SolidColorBrush scb = value as SolidColorBrush;
                    SolidColorBrush ns  = scb.CloneCurrentValue();
                    ns.Color = ExColorOpration(scb.Color, devColor, operation);
                    return(ns);
                }
                if (value is GradientBrush)
                {
                    GradientBrush gb = value as GradientBrush;
                    GradientBrush ng = gb.CloneCurrentValue();
                    foreach (var g in ng.GradientStops)
                    {
                        g.Color = ExColorOpration(g.Color, devColor, operation);
                    }
                    return(ng);
                }
            }
            return(null);
        }
コード例 #4
0
        private void UpdateGridVisual()
        {
            if (GridVisual != null && IsLoaded)
            {
                DrawingContext dc = GridVisual.RenderOpen();

                Matrix mtx       = PresentationSource.FromVisual(GridVisual).CompositionTarget.TransformToDevice;
                double dpiFactor = 1 / mtx.M11;
                double delt      = dpiFactor / 2;

                double xlen = PageSize.Width * PageScale;
                double ylen = PageSize.Height * PageScale;

                Brush brush    = new SolidColorBrush(GridColor);
                Pen   majorPen = new Pen(brush.CloneCurrentValue(), 1 * dpiFactor);
                brush.Opacity = 0.5;
                Pen minorPen = new Pen(brush.CloneCurrentValue(), 1 * dpiFactor);

                if (majorPen.CanFreeze)
                {
                    majorPen.Freeze();
                }
                if (minorPen.CanFreeze)
                {
                    minorPen.Freeze();
                }

                double border = 10 * PageScale;

                GuidelineSet guidelineSet = new GuidelineSet();
                guidelineSet.GuidelinesX.Add(0 - delt);
                //guidelineSet.GuidelinesX.Add(-border - delt);
                guidelineSet.GuidelinesX.Add(xlen - delt);
                //guidelineSet.GuidelinesX.Add(xlen + border * 2.0 - delt);

                guidelineSet.GuidelinesY.Add(0 - delt);
                //guidelineSet.GuidelinesY.Add(-border - delt);
                guidelineSet.GuidelinesY.Add(ylen - delt);
                //guidelineSet.GuidelinesY.Add(ylen + border * 2.0 - delt);

                dc.PushGuidelineSet(guidelineSet);
                dc.DrawRectangle(PageBackColor, majorPen, new Rect(-border, -border, xlen + border * 2.0, ylen + border * 2.0));
                dc.DrawRectangle(null, minorPen, new Rect(0, 0, xlen, ylen));
                dc.Pop();

                if (ShowGrid)
                {
                    LineGeometry lgx = new LineGeometry(new Point(0, 0), new Point(0, ylen));
                    LineGeometry lgy = new LineGeometry(new Point(0, 0), new Point(xlen, 0));
                    if (lgx.CanFreeze)
                    {
                        lgx.Freeze();
                    }
                    if (lgy.CanFreeze)
                    {
                        lgy.Freeze();
                    }


                    for (double x = 0; x <= PageSize.Width; x += GridSize)
                    {
                        GuidelineSet gridGuidelines = new GuidelineSet();
                        gridGuidelines.GuidelinesX.Add(x * PageScale - delt);

                        dc.PushGuidelineSet(gridGuidelines);
                        dc.PushTransform(new TranslateTransform(x * PageScale, 0));
                        dc.DrawGeometry(null, (x / GridSize) % 5 == 0 ? majorPen : minorPen, lgx);
                        dc.Pop();
                        dc.Pop();
                    }

                    for (double y = 0; y <= PageSize.Height; y += GridSize)
                    {
                        GuidelineSet gridGuidelines = new GuidelineSet();
                        gridGuidelines.GuidelinesY.Add(y * PageScale - delt);

                        dc.PushGuidelineSet(gridGuidelines);
                        dc.PushTransform(new TranslateTransform(0, y * PageScale));
                        dc.DrawGeometry(null, (y / GridSize) % 5 == 0 ? majorPen : minorPen, lgy);
                        dc.Pop();
                        dc.Pop();
                    }
                }

                dc.Close();
            }
        }