Пример #1
0
 public HighlightBrush(string color)
 {
     try
     {
         _brush = string.IsNullOrWhiteSpace(color)
             ? null
             : (SolidColorBrush) new BrushConverter().ConvertFromString(color);
     }
     catch (FormatException)
     {
         _brush = null;
     }
     _brush?.Freeze();
 }
        public static void ApplyCustomizationsToDefaultElements(TextEditor textEditor, IEnumerable <CustomizedHighlightingColor> customizations)
        {
            textEditor.ClearValue(TextEditor.BackgroundProperty);
            textEditor.ClearValue(TextEditor.ForegroundProperty);
            textEditor.ClearValue(TextEditor.LineNumbersForegroundProperty);
            textEditor.TextArea.ClearValue(TextArea.SelectionBorderProperty);
            textEditor.TextArea.ClearValue(TextArea.SelectionBrushProperty);
            textEditor.TextArea.ClearValue(TextArea.SelectionForegroundProperty);
            textEditor.TextArea.TextView.ClearValue(TextView.NonPrintableCharacterBrushProperty);

            bool assignedDefaultText           = false;
            bool assignedSelectedText          = false;
            bool assignedNonPrintableCharacter = false;
            bool assignedLineNumbers           = false;

            foreach (CustomizedHighlightingColor color in customizations)
            {
                switch (color.Name)
                {
                case DefaultTextAndBackground:
                    if (assignedDefaultText)
                    {
                        continue;
                    }
                    assignedDefaultText = true;

                    if (color.Background != null)
                    {
                        textEditor.Background = CreateFrozenBrush(color.Background.Value);
                    }
                    if (color.Foreground != null)
                    {
                        textEditor.Foreground = CreateFrozenBrush(color.Foreground.Value);
                    }
                    break;

                case SelectedText:
                    if (assignedSelectedText)
                    {
                        continue;
                    }
                    assignedSelectedText = true;

                    if (color.Background != null)
                    {
                        Pen pen = new Pen(CreateFrozenBrush(color.Background.Value), 1);
                        pen.Freeze();
                        textEditor.TextArea.SelectionBorder = pen;
                        SolidColorBrush back = new SolidColorBrush(color.Background.Value);
                        back.Opacity = 0.7;                                 // TODO : remove this constant, let the use choose the opacity.
                        back.Freeze();
                        textEditor.TextArea.SelectionBrush = back;
                    }
                    if (color.Foreground != null)
                    {
                        textEditor.TextArea.SelectionForeground = CreateFrozenBrush(color.Foreground.Value);
                    }
                    break;

                case NonPrintableCharacters:
                    if (assignedNonPrintableCharacter)
                    {
                        continue;
                    }
                    assignedNonPrintableCharacter = true;

                    if (color.Foreground != null)
                    {
                        textEditor.TextArea.TextView.NonPrintableCharacterBrush = CreateFrozenBrush(color.Foreground.Value);
                    }
                    break;

                case LineNumbers:
                    if (assignedLineNumbers)
                    {
                        continue;
                    }
                    assignedLineNumbers = true;

                    if (color.Foreground != null)
                    {
                        textEditor.LineNumbersForeground = CreateFrozenBrush(color.Foreground.Value);
                    }
                    break;
                }
            }
        }
Пример #3
0
        public void Draw(ICSharpCode.AvalonEdit.Rendering.TextView textView, DrawingContext drawingContext)
        {
            if (textView == null)
            {
                throw new ArgumentNullException(nameof(textView));
            }
            if (drawingContext == null)
            {
                throw new ArgumentNullException(nameof(drawingContext));
            }
            if (markers == null || !textView.VisualLinesValid)
            {
                return;
            }
            var visualLines = textView.VisualLines;

            if (visualLines.Count == 0)
            {
                return;
            }
            int viewStart = visualLines.First().FirstDocumentLine.Offset;
            int viewEnd   = visualLines.Last().LastDocumentLine.EndOffset;

            foreach (TextMarker marker in markers.FindOverlappingSegments(viewStart, viewEnd - viewStart))
            {
                if (marker.BackgroundColor != null)
                {
                    BackgroundGeometryBuilder geoBuilder = new BackgroundGeometryBuilder();
                    geoBuilder.AlignToWholePixels = true;
                    geoBuilder.CornerRadius       = 3;
                    geoBuilder.AddSegment(textView, marker);
                    Geometry geometry = geoBuilder.CreateGeometry();
                    if (geometry != null)
                    {
                        Color           color = marker.BackgroundColor.Value;
                        SolidColorBrush brush = new SolidColorBrush(color);
                        brush.Freeze();
                        drawingContext.DrawGeometry(brush, null, geometry);
                    }
                }
                var underlineMarkerTypes = TextMarkerTypes.SquigglyUnderline | TextMarkerTypes.NormalUnderline | TextMarkerTypes.DottedUnderline;
                if ((marker.MarkerTypes & underlineMarkerTypes) != 0)
                {
                    foreach (Rect r in BackgroundGeometryBuilder.GetRectsForSegment(textView, marker))
                    {
                        Point startPoint = r.BottomLeft;
                        Point endPoint   = r.BottomRight;

                        Brush usedBrush = new SolidColorBrush(marker.MarkerColor);
                        usedBrush.Freeze();
                        if ((marker.MarkerTypes & TextMarkerTypes.SquigglyUnderline) != 0)
                        {
                            double offset = 2.5;

                            int count = Math.Max((int)((endPoint.X - startPoint.X) / offset) + 1, 4);

                            StreamGeometry geometry = new StreamGeometry();

                            using (StreamGeometryContext ctx = geometry.Open()) {
                                ctx.BeginFigure(startPoint, false, false);
                                ctx.PolyLineTo(CreatePoints(startPoint, endPoint, offset, count).ToArray(), true, false);
                            }

                            geometry.Freeze();

                            Pen usedPen = new Pen(usedBrush, 1);
                            usedPen.Freeze();
                            drawingContext.DrawGeometry(Brushes.Transparent, usedPen, geometry);
                        }
                        if ((marker.MarkerTypes & TextMarkerTypes.NormalUnderline) != 0)
                        {
                            Pen usedPen = new Pen(usedBrush, 1);
                            usedPen.Freeze();
                            drawingContext.DrawLine(usedPen, startPoint, endPoint);
                        }
                        if ((marker.MarkerTypes & TextMarkerTypes.DottedUnderline) != 0)
                        {
                            Pen usedPen = new Pen(usedBrush, 1);
                            usedPen.DashStyle = DashStyles.Dot;
                            usedPen.Freeze();
                            drawingContext.DrawLine(usedPen, startPoint, endPoint);
                        }
                    }
                }
            }
        }
Пример #4
0
        /// <summary>
        /// 描画処理のオーバーライド
        /// </summary>
        /// <param name="drawingContext">描画先のコンテキストが与えられます。</param>
        protected override void OnRender(DrawingContext drawingContext)
        {
            //base.OnRender(drawingContext);

            var data   = this.Data != null ? this.Data : new ObservableCollection <byte>();
            var extent = this._extent;

            var color = SystemColors.ControlTextColor;

            if (!DesignerProperties.GetIsInDesignMode(this))
            {
                var colorResource = this.FindResource("ForegroundColor");
                if ((colorResource != null) && (colorResource.GetType() == typeof(Color)))
                {
                    color = (Color)Convert.ChangeType(colorResource, typeof(Color));
                }
            }
            var foreground = new SolidColorBrush(color);

            foreground.Freeze();

            var dataStyle = this.DataStyle;

            if (data.Count % (int)this.DataStyle != 0)
            {
                dataStyle = DataStyles.Byte;
            }

            // 何バイト表示かによってデータの最大文字数が変化する
            var w_max = this._charSize.Width;

            switch (dataStyle)
            {
            case DataStyles.Byte:
                if (this.NumStyle == NumStyles.Hexadecimal)
                {
                    w_max *= 3;
                }
                else
                {
                    w_max *= 4;
                }
                break;

            case DataStyles.Word:
                if (this.NumStyle == NumStyles.Hexadecimal)
                {
                    w_max *= 4;
                }
                else
                {
                    w_max *= 7;
                }
                break;

            case DataStyles.DoubleWord:
                if (this.NumStyle == NumStyles.Hexadecimal)
                {
                    w_max *= 8;
                }
                else
                {
                    w_max *= 14;
                }
                break;

            default:
            case DataStyles.QuadWord:
                if (this.NumStyle == NumStyles.Hexadecimal)
                {
                    w_max *= 16;
                }
                else
                {
                    w_max *= 26;
                }
                break;
            }
            var   w = this._charSize.Width;
            var   h = this._charSize.Height;
            Point pt;

            #region カーソル表示のための設定を更新する
            // 1 データ分の領域のサイズ
            this.DataUnitSize = new Size(w + w_max, h);
            // データ表示領域の原点
            this.DataOrigin = new Point(11 * w, h);
            #endregion カーソル表示のための設定を更新する

            #region ヘッダ部を描画
            pt = new Point(12 * w + w_max / 2, 0);
            foreach (var x in Enumerable.Range(0, 16 / (int)dataStyle).Select(i => (int)dataStyle * i))
            {
                var header = new FormattedText("+" + x.ToString("X02"), CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, this.Typeface, this.FontSize, foreground);
                header.TextAlignment = TextAlignment.Center;
                drawingContext.DrawText(header, pt);
                pt.Offset(w + w_max, 0);
            }
//            if (this.DataStyle == DataStyles.Byte)
            {
                pt.Offset(9 * w - w_max / 2.0, 0);
                var text = new FormattedText("ASCII", CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, this.Typeface, this.FontSize, foreground);
                text.TextAlignment = TextAlignment.Center;
                drawingContext.DrawText(text, pt);
            }
            #endregion ヘッダ部を描画

            #region データ部を描画
            if (data.Count > 0)
            {
                pt = new Point(0, h);
                var address = this.TopAddress;
                while (pt.Y < this._extent.Height)
                {
                    // アドレス部
                    var str  = "0x" + (address + this.AddressOffset).ToString("X08");
                    var text = new FormattedText(str, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, this.Typeface, this.FontSize, foreground);
                    drawingContext.DrawText(text, pt);

                    #region 16 個のデータを描画
                    var pt2  = new Point(12 * w + w_max, pt.Y);
                    var line = data.Count - address < 16 ? data.Skip(address).ToArray() : data.Skip(address).Take(16).ToArray();

                    // ASCII
                    for (var i = 0; i < line.Length; i += (int)DataStyles.Byte)
                    {
                        if ((0x20 <= line[i]) && (line[i] <= 0x7f))
                        {
                            str = System.Text.Encoding.ASCII.GetString(new byte[] { line[i] });
                        }
                        else
                        {
                            str = ".";
                        }
                        text = new FormattedText(str, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, this.Typeface, this.FontSize, foreground);
                        drawingContext.DrawText(text, new Point((13 + i) * this._charSize.Width + (this._charSize.Width + w_max) * 16 / (int)this.DataStyle, pt2.Y));
                    }

                    // バイナリデータ部
                    for (var i = 0; i < line.Length; i += (int)dataStyle)
                    {
                        var bytes = line.Skip(i).Take((int)dataStyle).Reverse().ToArray();
                        switch (bytes.Length)
                        {
                        case 1:
                            if (this.NumStyle == NumStyles.Hexadecimal)
                            {
                                str = line[i].ToString("X2");
                            }
                            else if (this.NumStyle == NumStyles.SignedDecimal)
                            {
                                str = ((sbyte)line[i]).ToString("N0");
                            }
                            else
                            {
                                str = line[i].ToString("N0");
                            }
                            break;

                        case 2:
                            if (this.NumStyle == NumStyles.Hexadecimal)
                            {
                                str = string.Concat(bytes.Reverse().Select(x => x.ToString("X2")).ToArray());
                            }
                            else if (this.NumStyle == NumStyles.SignedDecimal)
                            {
                                str = BitConverter.ToInt16(bytes, 0).ToString("N0");
                            }
                            else
                            {
                                str = BitConverter.ToUInt16(bytes, 0).ToString("N0");
                            }
                            break;

                        case 4:
                            if (this.NumStyle == NumStyles.Hexadecimal)
                            {
                                str = string.Concat(bytes.Reverse().Select(x => x.ToString("X2")).ToArray());
                            }
                            else if (this.NumStyle == NumStyles.SignedDecimal)
                            {
                                str = BitConverter.ToInt32(bytes, 0).ToString("N0");
                            }
                            else
                            {
                                str = BitConverter.ToUInt32(bytes, 0).ToString("N0");
                            }
                            break;

                        case 8:
                            if (this.NumStyle == NumStyles.Hexadecimal)
                            {
                                str = string.Concat(bytes.Reverse().Select(x => x.ToString("X2")).ToArray());
                            }
                            else if (this.NumStyle == NumStyles.SignedDecimal)
                            {
                                str = BitConverter.ToInt64(bytes, 0).ToString("N0");
                            }
                            else
                            {
                                str = BitConverter.ToUInt64(bytes, 0).ToString("N0");
                            }
                            break;

                        default:
                            break;
                        }   // end of switch

                        text = new FormattedText(str, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, this.Typeface, this.FontSize, foreground);
                        text.TextAlignment = TextAlignment.Right;
                        drawingContext.DrawText(text, pt2);
                        pt2.Offset(w + w_max, 0);
                    }
                    #endregion 16 個のデータを描画

                    #region 次の行へいくための前処理
                    pt.Offset(0, h);

                    address += 0x10;
                    if (address > data.Count - (this.IsMonitoringMode ? 1 : 0))
                    {
                        break;
                    }

                    if (double.IsPositiveInfinity(extent.Height))
                    {
                        if (address > this.TopAddress + 0x0100)
                        {
                            break;
                        }
                    }
                    #endregion 次の行へいくための前処理
                }   // end of while
            }
            #endregion データ部を描画
        }
Пример #5
0
 static MySimpleLabelStyle()
 {
     fillBrush = new SolidColorBrush(Color.FromArgb(255, 155, 226, 255));
     fillBrush.Freeze();
 }
Пример #6
0
 public SimpleHighlightingBrush(SolidColorBrush brush)
 {
     brush.Freeze();
     this.brush = brush;
 }
Пример #7
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);
            if (CourseModel == null || CourseModel.Waypoints.Count <= 1)
            {
                return;
            }

            var brush = new SolidColorBrush(Stroke);

            brush.Freeze();
            var pen = new Pen(brush, StrokeThickness / Scale);

            pen.Freeze();

            foreach (var point in CourseModel.Waypoints)
            {
                drawingContext.DrawEllipse(null, pen, point.Position, Radius / Scale, Radius / Scale);
            }
            //var pathGeometry = new PathGeometry();
            //var pathFigure = new PathFigure();
            //pathGeometry.Figures.Add(pathFigure);

            //var points = CourseFileModel.Courses.SelectMany(v => v.Waypoints).Select(v => v.Position).ToList();
            //if (points.Count == 0)
            //    return;

            ////Point? point = waypointModels.First().Position;
            ////Point? point = null;
            ////pathFigure.Segments.Add(new ArcSegment(waypointModel.Position, new Size(Radius * 2, Radius * 2), Math.PI, true, SweepDirection.Clockwise, true));
            ////pathGeometry.Figures.Add(pathFigure);
            //var diametr = 2 * Radius;
            //foreach (var pointModel in points)
            //{
            //    //if (point != null)
            //    var startCircle = new Point(pointModel.X - Radius, pointModel.Y);
            //    pathFigure.Segments.Add(new LineSegment(startCircle, false));
            //    pathFigure.Segments.Add(new ArcSegment(new Point(startCircle.X + diametr, startCircle.Y), new Size(Radius * 2, Radius * 2), 0, true, SweepDirection.Counterclockwise, true));
            //    pathFigure.Segments.Add(new ArcSegment(startCircle, new Size(Radius * 2, Radius * 2), 0, true, SweepDirection.Counterclockwise, true));

            //    //var pathFigure = new PathFigure();
            //    //pathFigure.Segments.Add(new ArcSegment(waypointModel.Position, new Size(Radius * 2, Radius * 2), Math.PI, true, SweepDirection.Clockwise, true));
            //    //pathGeometry.Figures.Add(pathFigure);
            //    //if (courseModel.Waypoints.Count <= 1)
            //    //    continue;

            //    //if (point != null)
            //    //{
            //    //    pathFigure.Segments.Add(new LineSegment(courseModel.Waypoints.First().Position, false));
            //    //}
            //    //point = courseModel.Waypoints.First().Position;

            //    //foreach (var waypointModel in courseModel.Waypoints.Skip(1))
            //    //{
            //    //    pathFigure.Segments.Add(new LineSegment(waypointModel.Position, true));
            //    //    point = waypointModel.Position;
            //    //}
            //}
            //var pen = new Pen(new SolidColorBrush(Stroke), StrokeThickness);
            //drawingContext.DrawGeometry(null, pen, pathGeometry);
        }
Пример #8
0
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            if (textView == null)
            {
                throw new ArgumentNullException(nameof(textView));
            }
            if (drawingContext == null)
            {
                throw new ArgumentNullException(nameof(drawingContext));
            }
            if (_markers == null || !textView.VisualLinesValid)
            {
                return;
            }
            var visualLines = textView.VisualLines;

            if (visualLines.Count == 0)
            {
                return;
            }
            var viewStart = visualLines.First().FirstDocumentLine.Offset;
            var viewEnd   = visualLines.Last().LastDocumentLine.EndOffset;

            foreach (var marker in _markers.FindOverlappingSegments(viewStart, viewEnd - viewStart))
            {
                if (marker.BackgroundColor != null)
                {
                    var geoBuilder = new BackgroundGeometryBuilder
                    {
                        AlignToWholePixels = true,
                        CornerRadius       = 3
                    };
                    geoBuilder.AddSegment(textView, marker);
                    var geometry = geoBuilder.CreateGeometry();
                    if (geometry != null)
                    {
                        var color = marker.BackgroundColor.Value;
                        var brush = new SolidColorBrush(color);
                        brush.Freeze();
                        drawingContext.DrawGeometry(brush, null, geometry);
                    }
                }
                foreach (var r in BackgroundGeometryBuilder.GetRectsForSegment(textView, marker))
                {
                    var startPoint = r.BottomLeft;
                    var endPoint   = r.BottomRight;

                    Brush usedBrush = new SolidColorBrush(marker.MarkerColor);
                    usedBrush.Freeze();
                    var offset = 2.5;

                    var count = Math.Max((int)((endPoint.X - startPoint.X) / offset) + 1, 4);

                    var geometry = new StreamGeometry();

                    using (var ctx = geometry.Open())
                    {
                        ctx.BeginFigure(startPoint, false, false);
                        ctx.PolyLineTo(CreatePoints(startPoint, offset, count).ToArray(), true, false);
                    }

                    geometry.Freeze();

                    var usedPen = new Pen(usedBrush, 1);
                    usedPen.Freeze();
                    drawingContext.DrawGeometry(Brushes.Transparent, usedPen, geometry);
                }
            }
        }
 static SpecialCharacterTextRun()
 {
     darkGrayBrush = new SolidColorBrush(Color.FromArgb(200, 128, 128, 128));
     darkGrayBrush.Freeze();
 }
Пример #10
0
        private Style ApplyNewStyle()
        {
            Style ds = new Style(typeof(Window));
            // Note that we can't set Top/Left/Width/Height in the style because the current implementation
            // of Window doesn't respect those properties set through a style.

            ControlTemplate template = new ControlTemplate(typeof(Window));
            Trigger         trigger;

            // border
            FrameworkElementFactory border = new FrameworkElementFactory(typeof(Border), "Border");

            border.SetValue(Border.BackgroundProperty, new SolidColorBrush(Colors.Aqua));

            //dockpanel
            FrameworkElementFactory dockPanel = new FrameworkElementFactory(typeof(DockPanel), "DockPanel");
            //button
            FrameworkElementFactory backButton = new FrameworkElementFactory(typeof(Button), "Button");

            backButton.SetValue(DockPanel.DockProperty, Dock.Left);
            FrameworkElementFactory backButtonBorder = new FrameworkElementFactory(typeof(Border), "ButtonImageContent");

            backButtonBorder.SetValue(Button.WidthProperty, 54.0);
            backButtonBorder.SetValue(Button.HeightProperty, 38.0);
            backButton.SetValue(DockPanel.DockProperty, Dock.Top);
            backButton.AppendChild(backButtonBorder);

            // Bottom DockPanel
            FrameworkElementFactory bottomDockPanel = new FrameworkElementFactory(typeof(DockPanel), "BottomDockPanel");

            bottomDockPanel.SetValue(DockPanel.DockProperty, Dock.Bottom);

            // Brushes for fore/back ground
            SolidColorBrush backgroundBrush = new SolidColorBrush(Colors.Yellow);

            backgroundBrush.Freeze();
            SolidColorBrush foregroundBrush = new SolidColorBrush(Colors.Red);

            foregroundBrush.Freeze();

            //ResizeGrip
            FrameworkElementFactory resizeGrip = new FrameworkElementFactory(typeof(ResizeGrip), "ResizeGrip");

            resizeGrip.SetValue(UIElement.VisibilityProperty, Visibility.Collapsed);
            resizeGrip.SetValue(DockPanel.DockProperty, Dock.Right);
            resizeGrip.SetValue(FrameworkElement.WidthProperty, 14.0d);
            resizeGrip.SetValue(FrameworkElement.HeightProperty, 23.0d);
            resizeGrip.SetValue(Control.BackgroundProperty, backgroundBrush);
            resizeGrip.SetValue(Control.ForegroundProperty, foregroundBrush);
            resizeGrip.SetValue(Control.IsTabStopProperty, false);

            trigger          = new Trigger();
            trigger.Property = Window.ResizeModeProperty;
            trigger.Value    = ResizeMode.CanResizeWithGrip;
            trigger.Setters.Add(new Setter(UIElement.VisibilityProperty, Visibility.Visible, "ResizeGrip"));
            template.Triggers.Add(trigger);

            // Make bottom visual tree
            bottomDockPanel.AppendChild(resizeGrip);

            // content presenter
            FrameworkElementFactory cp = new FrameworkElementFactory(typeof(ContentPresenter), "ContentSite");

            cp.SetValue(ContentControl.ContentProperty, new TemplateBindingExtension(Window.ContentProperty));

            border.AppendChild(dockPanel);
            dockPanel.AppendChild(backButton);
            dockPanel.AppendChild(bottomDockPanel);
            dockPanel.AppendChild(cp);

            template.VisualTree = border;
            ds.Setters.Add(new Setter(Control.TemplateProperty, template));

            return(ds);
        }
Пример #11
0
        private void DrawTimeTicks(DrawingContext dc, double scale, double offset)
        {
            Pen pen = new Pen(new SolidColorBrush(Color.FromArgb((byte)0, 0, 0, 0)), 1);

            pen.Freeze();

            if (scale > Constants.Epsilon)
            {
                double m_Width  = ActualWidth;
                double m_Height = ActualHeight;

                const float density = 0.02f;

                UsedPositions.Clear();

                scale = 1 / scale;

                int f = 0;
                while (f < m_Fractions.Count() - 1 &&
                       scale < m_Fractions[f + 1].ScaleMin * density)
                {
                    f++;
                }
                for (f = 0; f < m_Fractions.Count() - 1 && scale > m_Fractions[f + 1].ScaleMin * density; f++)
                {
                }
                /* DEBUG OUTPUT */
                //dc.DrawText(new FormattedText("Scale: " + (scale).ToString() + "  f=" +  f.ToString() + " ",
                //                                        CultureInfo.GetCultureInfo("en-us"),
                //                                        FlowDirection.LeftToRight,
                //                                        new Typeface("Verdana"),
                //                                        10,
                //                                        System.Windows.Media.Brushes.White
                //                                        ), new Point(0, 25));


                ScaleFraction frac = m_Fractions[f];


                foreach (LineDefinition linedef in frac.LineDefinitions)
                {
                    double t          = -offset % linedef.Spacing;
                    double fadeFactor = 0.0f;


                    fadeFactor = (scale - frac.ScaleMin * density) / (frac.ScaleMax * density - frac.ScaleMin * density);
                    if (fadeFactor < 0)
                    {
                        fadeFactor = 0.0;
                    }
                    else if (fadeFactor > 1)
                    {
                        fadeFactor = 1.0;
                    }

                    SolidColorBrush fadebrush = new SolidColorBrush(Color.FromArgb((byte)(255 - fadeFactor * 255), 0, 0, 0));
                    fadebrush.Freeze();
                    if (linedef.FadeLines)
                    {
                        pen = new Pen(fadebrush, 0.5);
                    }
                    else
                    {
                        pen = new Pen(Brushes.Black, 0.5);
                    }
                    pen.Freeze();


                    while (t / scale < m_Width)
                    {
                        int x = (int)(t / scale);

                        if (x > 0 && x < m_Width && !UsedPositions.ContainsKey(x))
                        {
                            UsedPositions[x] = t + offset + BPMTimeOffset;
                            //dc.DrawLine(pen, new Point(x+0.5, m_Height - linedef.Height), new Point(x+0.5, m_Height));
                            dc.DrawLine(pen, new Point(x + 0.5, 0), new Point(x + 0.5, m_Height));

                            if (linedef.Label != "")
                            {
                                String output = "";
                                foreach (char c in linedef.Label)
                                {
                                    if (c == 'F')
                                    {
                                        output += Math.Floor((float)(t + offset) * 30.0f % 30.0f).ToString("00");
                                    }
                                    else if (c == 'S')
                                    {
                                        output += Math.Floor((float)(t + offset) % 60.0f).ToString("00");
                                    }
                                    else if (c == 'M')
                                    {
                                        output += Math.Floor((float)(t + offset) / 60.0f % 60.0f).ToString("00");
                                    }
                                    else if (c == 'H')
                                    {
                                        output += Math.Floor((float)(t + offset) / (60.0 * 60.0) % 60.0).ToString("00");
                                    }
                                    else if (c == 'D')
                                    {
                                        output += Math.Floor((float)(t + offset) / (24 * 60.0 * 60.0) % 24).ToString("00");
                                    }
                                    else
                                    {
                                        output += c;
                                    }
                                }

                                Brush textbrush;
                                if (linedef.FadeLabels)
                                {
                                    textbrush = fadebrush;
                                }
                                else
                                {
                                    textbrush = Brushes.White;
                                }
                                FormattedText text = new FormattedText(output,
                                                                       CultureInfo.GetCultureInfo("en-us"),
                                                                       FlowDirection.LeftToRight,
                                                                       new Typeface("Verdana"),
                                                                       10,
                                                                       textbrush
                                                                       );
                                text.TextAlignment = TextAlignment.Center;
                                dc.DrawText(text, new Point(x, m_Height - 25));
                            }
                        }
                        t += linedef.Spacing;
                    }
                }
            }
        }
Пример #12
0
        private FlowDocument CreateChatDocument()
        {
            var doc = new FlowDocument();

            var para1 = new Paragraph()
            {
                Margin = ZeroMargin
            };

            if (this.IsExistChatCodeIndicator)
            {
                para1.Inlines.Add(this.ParentOverlaySettings != null ?
                                  new Run(this.ChatCodeIndicator + " ")
                {
                    FontSize          = this.ParentOverlaySettings.Font.Size * 0.9,
                    BaselineAlignment = BaselineAlignment.Center,
                } :
                                  new Run(this.ChatCodeIndicator + " "));
            }

            if (this.IsExistSpeaker)
            {
                para1.Inlines.Add(CreateSpeakerElement());

                if (this.IsExistSpeakerAlias)
                {
                    para1.Inlines.Add(new Run($"( {this.SpeakerAlias} )" + " "));
                }

                para1.Inlines.Add(new Run(": "));
            }

            para1.Inlines.Add(new Run($"{this.Message}"));
            doc.Blocks.Add(para1);

            if (this.discordLog == null)
            {
                return(doc);
            }

            var headerBrush    = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#fff1cf"));
            var hyperLinkBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#f8e58c"));

            headerBrush.Freeze();
            hyperLinkBrush.Freeze();

            var fontSize = this.ParentOverlaySettings != null ?
                           this.ParentOverlaySettings.Font.Size * 1.0 :
                           15;

            var contentWidth = this.ParentOverlaySettings != null ?
                               this.ParentOverlaySettings.W * 0.8 :
                               350;

            var files      = this.discordLog.Attachments.Where(x => !x.Url.IsImage());
            var imagesAtta = this.discordLog.Attachments.Where(x => x.Url.IsImage());

            // Attachments
            foreach (var atta in files)
            {
                var para = CreateSubParagraph();
                AddHyperLink(para, "File", atta.Filename, atta.Url);
                doc.Blocks.Add(para);
            }

            var imagesEmbeds = this.discordLog.Embeds
                               .Where(x => x.Image.HasValue)
                               .Select(x => x.Image.Value);

            var videos = this.discordLog.Embeds
                         .Where(x => x.Video.HasValue)
                         .Select(x => x.Video.Value);

            var links = this.discordLog.Embeds
                        .Where(x =>
                               x.Url != null &&
                               !imagesEmbeds.Any(image => image.Url == x.Url) &&
                               !videos.Any(video => video.Url == x.Url))
                        .Select(x => x.Url);

            // Attachments Images
            if (imagesAtta.Any())
            {
                var panel = new WrapPanel()
                {
                    Orientation = Orientation.Horizontal,
                    Margin      = new Thickness(0, 5, 0, 2),
                };

                foreach (var image in imagesAtta)
                {
                    var bitmap = new BitmapImage();
                    bitmap.BeginInit();
                    bitmap.UriSource = new Uri(image.Url);
                    bitmap.EndInit();

                    var inline = new InlineUIContainer(new Image()
                    {
                        Source = bitmap
                    });

                    var hyperlink = new Hyperlink(inline)
                    {
                        NavigateUri = new Uri(image.Url),
                    };

                    hyperlink.RequestNavigate += this.HyperlinkElement_RequestNavigate;

                    var view = new Viewbox()
                    {
                        Child    = new TextBlock(hyperlink),
                        MaxWidth = this.ParentOverlaySettings != null ?
                                   this.ParentOverlaySettings.W * AttachmentImageWidthRatio :
                                   250.0d,
                        HorizontalAlignment = HorizontalAlignment.Left,
                        Margin = new Thickness(0, 2, 4, 2)
                    };

                    panel.Children.Add(view);
                }

                doc.Blocks.Add(new BlockUIContainer(panel));
            }

            // Embeds Images
            if (imagesEmbeds.Any())
            {
                var panel = new WrapPanel()
                {
                    Orientation = Orientation.Horizontal
                };

                foreach (var image in imagesEmbeds)
                {
                    var bitmap = new BitmapImage();
                    bitmap.BeginInit();
                    bitmap.UriSource = new Uri(image.Url);
                    bitmap.EndInit();

                    var inline = new InlineUIContainer(new Image()
                    {
                        Source = bitmap
                    });

                    var hyperlink = new Hyperlink(inline)
                    {
                        NavigateUri = new Uri(image.Url),
                    };

                    hyperlink.RequestNavigate += this.HyperlinkElement_RequestNavigate;

                    var view = new Viewbox()
                    {
                        Child               = new TextBlock(hyperlink),
                        MaxWidth            = 250,
                        HorizontalAlignment = HorizontalAlignment.Left,
                        Margin              = new Thickness(0, 2, 4, 2)
                    };

                    panel.Children.Add(view);
                }

                doc.Blocks.Add(new BlockUIContainer(panel));
            }

            // Videos
            foreach (var video in videos)
            {
                var para = CreateSubParagraph();
                AddHyperLink(para, "Video", video.Url, video.Url);
                doc.Blocks.Add(para);
            }

            // Links
            foreach (var url in links)
            {
                var para = CreateSubParagraph();
                AddHyperLink(para, "Link", url, url);
                doc.Blocks.Add(para);
            }

            return(doc);

            Paragraph CreateSubParagraph()
            {
                return(new Paragraph()
                {
                    FontSize = fontSize,
                    Margin = ZeroMargin,
                    FontFamily = new FontFamily("Consolas")
                });
            }

            void AddHyperLink(
                Paragraph para,
                string header,
                string text,
                string url)
            {
                var headerElement = new Run($" {header}: ")
                {
                    BaselineAlignment = BaselineAlignment.Subscript,
                    Foreground        = headerBrush
                };

                var hyperlinkElement = new Hyperlink()
                {
                    Foreground = hyperLinkBrush
                };

                hyperlinkElement.Inlines.Add(new TextBlock()
                {
                    Text         = text,
                    MaxWidth     = contentWidth,
                    TextTrimming = TextTrimming.CharacterEllipsis,
                });

                hyperlinkElement.NavigateUri      = new Uri(url);
                hyperlinkElement.RequestNavigate += this.HyperlinkElement_RequestNavigate;

                para.Inlines.Add(headerElement);
                para.Inlines.Add(hyperlinkElement);
            }

            Inline CreateSpeakerElement()
            {
                if (this.discordLog != null ||
                    string.IsNullOrEmpty(this.SpeakerCharacterName) ||
                    this.ChatCode == ChatCodes.NPC ||
                    this.ChatCode == ChatCodes.NPCAnnounce ||
                    this.ChatCode == ChatCodes.CustomEmotes ||
                    this.ChatCode == ChatCodes.StandardEmotes)
                {
                    return(new Run(this.Speaker + " "));
                }

                var url    = string.Empty;
                var server = Uri.EscapeDataString(this.SpeakerServer);
                var name   = this.SpeakerCharacterName;

                var first  = string.Empty;
                var family = string.Empty;

                if (name.Contains(" "))
                {
                    var parts = name.Split(' ');
                    first  = parts[0].Replace(".", string.Empty);
                    family = parts[1].Replace(".", string.Empty);
                }
                else
                {
                    return(new Run(this.Speaker + " "));
                }

                var isInitialized = first.Length <= 1 || family.Length <= 1;

                if (!string.IsNullOrEmpty(this.SpeakerCharacterName) &&
                    !string.IsNullOrEmpty(server) &&
                    !isInitialized)
                {
                    var nameArgument = Uri.EscapeDataString($"{first} {family}");
                    url = $@"https://ja.fflogs.com/character/jp/{server}/{nameArgument}";
                }
                else
                {
                    url = $@"https://ja.fflogs.com/search/?term=";

                    if (!isInitialized)
                    {
                        url += Uri.EscapeDataString($"{first} {family}");
                    }
                    else
                    {
                        if (first.Length > 1)
                        {
                            url += Uri.EscapeDataString(first);
                        }
                        else
                        {
                            return(new Run(this.Speaker + " "));
                        }
                    }
                }

                var text = new Run()
                {
                    Text            = this.Speaker,
                    Cursor          = Cursors.Arrow,
                    TextDecorations = TextDecorations.Underline,
                    ToolTip         = url,
                    Tag             = new Uri(url),
                };

                text.MouseLeftButtonDown += this.Speaker_MouseLeftButtonDown;

                var span = new Span();

                span.Inlines.Add(text);
                span.Inlines.Add(new Run(" "));

                return(span);
            }
        }
Пример #13
0
 static GridRailAdorner()
 {
     bgBrush = new SolidColorBrush(Color.FromArgb(0x35, 0x1E, 0x90, 0xff));
     bgBrush.Freeze();
 }
Пример #14
0
 public RunnerViewModel()
 {
     _Background = new SolidColorBrush(Color.FromArgb(50, (byte)_Random.Next(0, 255), (byte)_Random.Next(0, 255), (byte)_Random.Next(0, 255)));
     _Background.Freeze();
 }
Пример #15
0
        private void RenderTheme(DrawingContext dc)
        {
            ThemeColor        themeColor    = ThemeColor;
            Size              size          = RenderSize;
            bool              horizontal    = Orientation == Orientation.Horizontal;
            bool              isClickable   = IsClickable && IsEnabled;
            bool              isHovered     = isClickable && IsHovered;
            bool              isPressed     = isClickable && IsPressed;
            ListSortDirection?sortDirection = SortDirection;
            bool              isSorted      = sortDirection != null;
            bool              isSelected    = IsSelected;

            EnsureCache((int)LunaFreezables.NumFreezables);

            if (horizontal)
            {
                // When horizontal, rotate the rendering by -90 degrees
                Matrix m1 = new Matrix();
                m1.RotateAt(-90.0, 0.0, 0.0);
                Matrix m2 = new Matrix();
                m2.Translate(0.0, size.Height);

                MatrixTransform horizontalRotate = new MatrixTransform(m1 * m2);
                horizontalRotate.Freeze();
                dc.PushTransform(horizontalRotate);

                double temp = size.Width;
                size.Width  = size.Height;
                size.Height = temp;
            }

            // Draw the background
            LunaFreezables      backgroundType = isPressed ? LunaFreezables.PressedBackground : isHovered ? LunaFreezables.HoveredBackground : LunaFreezables.NormalBackground;
            LinearGradientBrush background     = (LinearGradientBrush)GetCachedFreezable((int)backgroundType);

            if (background == null)
            {
                background            = new LinearGradientBrush();
                background.StartPoint = new Point();
                background.EndPoint   = new Point(0.0, 1.0);

                if (isPressed)
                {
                    if (themeColor == ThemeColor.Metallic)
                    {
                        background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xB9, 0xB9, 0xC8), 0.0));
                        background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xEC, 0xEC, 0xF3), 0.1));
                        background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xEC, 0xEC, 0xF3), 1.0));
                    }
                    else
                    {
                        background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xC1, 0xC2, 0xB8), 0.0));
                        background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xDE, 0xDF, 0xD8), 0.1));
                        background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xDE, 0xDF, 0xD8), 1.0));
                    }
                }
                else if (isHovered || isSelected)
                {
                    if (themeColor == ThemeColor.Metallic)
                    {
                        background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFE, 0xFE, 0xFE), 0.0));
                        background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFE, 0xFE, 0xFE), 0.85));
                        background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xBD, 0xBE, 0xCE), 1.0));
                    }
                    else
                    {
                        background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFA, 0xF9, 0xF4), 0.0));
                        background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFA, 0xF9, 0xF4), 0.85));
                        background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xEC, 0xE9, 0xD8), 1.0));
                    }
                }
                else
                {
                    if (themeColor == ThemeColor.Metallic)
                    {
                        background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xF9, 0xFA, 0xFD), 0.0));
                        background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xF9, 0xFA, 0xFD), 0.85));
                        background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xBD, 0xBE, 0xCE), 1.0));
                    }
                    else
                    {
                        background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xEB, 0xEA, 0xDB), 0.0));
                        background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xEB, 0xEA, 0xDB), 0.85));
                        background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xCB, 0xC7, 0xB8), 1.0));
                    }
                }

                background.Freeze();
                CacheFreezable(background, (int)backgroundType);
            }

            dc.DrawRectangle(background, null, new Rect(0.0, 0.0, size.Width, size.Height));

            if (isHovered && !isPressed && (size.Width >= 6.0) && (size.Height >= 4.0))
            {
                // When hovered, there is a colored tab at the bottom
                TranslateTransform positionTransform = new TranslateTransform(0.0, size.Height - 3.0);
                positionTransform.Freeze();
                dc.PushTransform(positionTransform);

                PathGeometry tabGeometry = new PathGeometry();
                PathFigure   tabFigure   = new PathFigure();

                tabFigure.StartPoint = new Point(0.5, 0.5);

                LineSegment line = new LineSegment(new Point(size.Width - 0.5, 0.5), true);
                line.Freeze();
                tabFigure.Segments.Add(line);

                ArcSegment arc = new ArcSegment(new Point(size.Width - 2.5, 2.5), new Size(2.0, 2.0), 90.0, false, SweepDirection.Clockwise, true);
                arc.Freeze();
                tabFigure.Segments.Add(arc);

                line = new LineSegment(new Point(2.5, 2.5), true);
                line.Freeze();
                tabFigure.Segments.Add(line);

                arc = new ArcSegment(new Point(0.5, 0.5), new Size(2.0, 2.0), 90.0, false, SweepDirection.Clockwise, true);
                arc.Freeze();
                tabFigure.Segments.Add(arc);

                tabFigure.IsClosed = true;
                tabFigure.Freeze();

                tabGeometry.Figures.Add(tabFigure);
                tabGeometry.Freeze();

                Pen tabStroke = (Pen)GetCachedFreezable((int)LunaFreezables.TabStroke);
                if (tabStroke == null)
                {
                    SolidColorBrush tabStrokeBrush = new SolidColorBrush((themeColor == ThemeColor.Homestead) ? Color.FromArgb(0xFF, 0xCF, 0x72, 0x25) : Color.FromArgb(0xFF, 0xF8, 0xA9, 0x00));
                    tabStrokeBrush.Freeze();

                    tabStroke = new Pen(tabStrokeBrush, 1.0);
                    tabStroke.Freeze();

                    CacheFreezable(tabStroke, (int)LunaFreezables.TabStroke);
                }

                LinearGradientBrush tabFill = (LinearGradientBrush)GetCachedFreezable((int)LunaFreezables.TabFill);
                if (tabFill == null)
                {
                    tabFill            = new LinearGradientBrush();
                    tabFill.StartPoint = new Point();
                    tabFill.EndPoint   = new Point(1.0, 0.0);
                    if (themeColor == ThemeColor.Homestead)
                    {
                        tabFill.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xE3, 0x91, 0x4F), 0.0));
                        tabFill.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xE3, 0x91, 0x4F), 1.0));
                    }
                    else
                    {
                        tabFill.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFC, 0xE0, 0xA6), 0.0));
                        tabFill.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xF6, 0xC4, 0x56), 0.1));
                        tabFill.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xF6, 0xC4, 0x56), 0.9));
                        tabFill.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xDF, 0x97, 0x00), 1.0));
                    }

                    tabFill.Freeze();
                    CacheFreezable(tabFill, (int)LunaFreezables.TabFill);
                }

                dc.DrawGeometry(tabFill, tabStroke, tabGeometry);

                dc.Pop(); // Translate Transform
            }

            if (isPressed && (size.Width >= 2.0) && (size.Height >= 2.0))
            {
                // When pressed, there is a border on the left and bottom
                SolidColorBrush border = (SolidColorBrush)GetCachedFreezable((int)LunaFreezables.PressedBorder);
                if (border == null)
                {
                    border = new SolidColorBrush((themeColor == ThemeColor.Metallic) ? Color.FromArgb(0xFF, 0x80, 0x80, 0x99) : Color.FromArgb(0xFF, 0xA5, 0xA5, 0x97));
                    border.Freeze();
                    CacheFreezable(border, (int)LunaFreezables.PressedBorder);
                }

                dc.DrawRectangle(border, null, new Rect(0.0, 0.0, 1.0, size.Height));
                dc.DrawRectangle(border, null, new Rect(0.0, Max0(size.Height - 1.0), size.Width, 1.0));
            }

            if (!isPressed && !isHovered && (size.Width >= 4.0))
            {
                if (SeparatorVisibility == Visibility.Visible)
                {
                    Brush sideBrush;
                    if (SeparatorBrush != null)
                    {
                        sideBrush = SeparatorBrush;
                    }
                    else
                    {
                        // When not pressed or hovered, draw the resize gripper
                        LinearGradientBrush gripper = (LinearGradientBrush)GetCachedFreezable((int)(horizontal ? LunaFreezables.HorizontalGripper : LunaFreezables.VerticalGripper));
                        if (gripper == null)
                        {
                            gripper            = new LinearGradientBrush();
                            gripper.StartPoint = new Point();
                            gripper.EndPoint   = new Point(1.0, 0.0);

                            Color highlight = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF);
                            Color shadow    = Color.FromArgb(0xFF, 0xC7, 0xC5, 0xB2);

                            if (horizontal)
                            {
                                gripper.GradientStops.Add(new GradientStop(highlight, 0.0));
                                gripper.GradientStops.Add(new GradientStop(highlight, 0.25));
                                gripper.GradientStops.Add(new GradientStop(shadow, 0.75));
                                gripper.GradientStops.Add(new GradientStop(shadow, 1.0));
                            }
                            else
                            {
                                gripper.GradientStops.Add(new GradientStop(shadow, 0.0));
                                gripper.GradientStops.Add(new GradientStop(shadow, 0.25));
                                gripper.GradientStops.Add(new GradientStop(highlight, 0.75));
                                gripper.GradientStops.Add(new GradientStop(highlight, 1.0));
                            }

                            gripper.Freeze();
                            CacheFreezable(gripper, (int)(horizontal ? LunaFreezables.HorizontalGripper : LunaFreezables.VerticalGripper));
                        }

                        sideBrush = gripper;
                    }

                    dc.DrawRectangle(sideBrush, null, new Rect(horizontal ? 0.0 : Max0(size.Width - 2.0), 4.0, 2.0, Max0(size.Height - 8.0)));
                }
            }

            if (isSorted && (size.Width > 14.0) && (size.Height > 10.0))
            {
                // When sorted, draw an arrow on the right
                TranslateTransform positionTransform = new TranslateTransform(size.Width - 15.0, (size.Height - 5.0) * 0.5);
                positionTransform.Freeze();
                dc.PushTransform(positionTransform);

                bool         ascending     = (sortDirection == ListSortDirection.Ascending);
                PathGeometry arrowGeometry = (PathGeometry)GetCachedFreezable(ascending ? (int)LunaFreezables.ArrowUpGeometry : (int)LunaFreezables.ArrowDownGeometry);
                if (arrowGeometry == null)
                {
                    arrowGeometry = new PathGeometry();
                    PathFigure arrowFigure = new PathFigure();

                    if (ascending)
                    {
                        arrowFigure.StartPoint = new Point(0.0, 5.0);

                        LineSegment line = new LineSegment(new Point(5.0, 0.0), false);
                        line.Freeze();
                        arrowFigure.Segments.Add(line);

                        line = new LineSegment(new Point(10.0, 5.0), false);
                        line.Freeze();
                        arrowFigure.Segments.Add(line);
                    }
                    else
                    {
                        arrowFigure.StartPoint = new Point(0.0, 0.0);

                        LineSegment line = new LineSegment(new Point(10.0, 0.0), false);
                        line.Freeze();
                        arrowFigure.Segments.Add(line);

                        line = new LineSegment(new Point(5.0, 5.0), false);
                        line.Freeze();
                        arrowFigure.Segments.Add(line);
                    }

                    arrowFigure.IsClosed = true;
                    arrowFigure.Freeze();

                    arrowGeometry.Figures.Add(arrowFigure);
                    arrowGeometry.Freeze();

                    CacheFreezable(arrowGeometry, ascending ? (int)LunaFreezables.ArrowUpGeometry : (int)LunaFreezables.ArrowDownGeometry);
                }

                SolidColorBrush arrowFill = (SolidColorBrush)GetCachedFreezable((int)LunaFreezables.ArrowFill);
                if (arrowFill == null)
                {
                    arrowFill = new SolidColorBrush(Color.FromArgb(0xFF, 0xAC, 0xA8, 0x99));
                    arrowFill.Freeze();
                    CacheFreezable(arrowFill, (int)LunaFreezables.ArrowFill);
                }

                dc.DrawGeometry(arrowFill, null, arrowGeometry);

                dc.Pop(); // Position Transform
            }

            if (horizontal)
            {
                dc.Pop(); // Horizontal Rotate
            }
        }
        // Token: 0x06006DD0 RID: 28112 RVA: 0x001F93C4 File Offset: 0x001F75C4
        private static Drawing CreateStrokeEraserDrawing()
        {
            DrawingGroup   drawingGroup   = new DrawingGroup();
            DrawingContext drawingContext = null;

            try
            {
                drawingContext = drawingGroup.Open();
                LinearGradientBrush linearGradientBrush = new LinearGradientBrush(Color.FromRgb(240, 242, byte.MaxValue), Color.FromRgb(180, 207, 248), 45.0);
                linearGradientBrush.Freeze();
                SolidColorBrush solidColorBrush = new SolidColorBrush(Color.FromRgb(180, 207, 248));
                solidColorBrush.Freeze();
                Pen pen = new Pen(Brushes.Gray, 0.7);
                pen.Freeze();
                PathGeometry pathGeometry = new PathGeometry();
                PathFigure   pathFigure   = new PathFigure();
                pathFigure.StartPoint = new Point(5.0, 5.0);
                LineSegment lineSegment = new LineSegment(new Point(16.0, 5.0), true);
                lineSegment.Freeze();
                pathFigure.Segments.Add(lineSegment);
                lineSegment = new LineSegment(new Point(26.0, 15.0), true);
                lineSegment.Freeze();
                pathFigure.Segments.Add(lineSegment);
                lineSegment = new LineSegment(new Point(15.0, 15.0), true);
                lineSegment.Freeze();
                pathFigure.Segments.Add(lineSegment);
                lineSegment = new LineSegment(new Point(5.0, 5.0), true);
                lineSegment.Freeze();
                pathFigure.Segments.Add(lineSegment);
                pathFigure.IsClosed = true;
                pathFigure.Freeze();
                pathGeometry.Figures.Add(pathFigure);
                pathFigure            = new PathFigure();
                pathFigure.StartPoint = new Point(5.0, 5.0);
                lineSegment           = new LineSegment(new Point(5.0, 10.0), true);
                lineSegment.Freeze();
                pathFigure.Segments.Add(lineSegment);
                lineSegment = new LineSegment(new Point(15.0, 19.0), true);
                lineSegment.Freeze();
                pathFigure.Segments.Add(lineSegment);
                lineSegment = new LineSegment(new Point(15.0, 15.0), true);
                lineSegment.Freeze();
                pathFigure.Segments.Add(lineSegment);
                lineSegment = new LineSegment(new Point(5.0, 5.0), true);
                lineSegment.Freeze();
                pathFigure.Segments.Add(lineSegment);
                pathFigure.IsClosed = true;
                pathFigure.Freeze();
                pathGeometry.Figures.Add(pathFigure);
                pathGeometry.Freeze();
                PathGeometry pathGeometry2 = new PathGeometry();
                pathFigure            = new PathFigure();
                pathFigure.StartPoint = new Point(15.0, 15.0);
                lineSegment           = new LineSegment(new Point(15.0, 19.0), true);
                lineSegment.Freeze();
                pathFigure.Segments.Add(lineSegment);
                lineSegment = new LineSegment(new Point(26.0, 19.0), true);
                lineSegment.Freeze();
                pathFigure.Segments.Add(lineSegment);
                lineSegment = new LineSegment(new Point(26.0, 15.0), true);
                lineSegment.Freeze();
                pathFigure.Segments.Add(lineSegment);
                lineSegment.Freeze();
                lineSegment = new LineSegment(new Point(15.0, 15.0), true);
                pathFigure.Segments.Add(lineSegment);
                pathFigure.IsClosed = true;
                pathFigure.Freeze();
                pathGeometry2.Figures.Add(pathFigure);
                pathGeometry2.Freeze();
                drawingContext.DrawGeometry(linearGradientBrush, pen, pathGeometry);
                drawingContext.DrawGeometry(solidColorBrush, pen, pathGeometry2);
                drawingContext.DrawLine(pen, new Point(5.0, 5.0), new Point(5.0, 0.0));
                drawingContext.DrawLine(pen, new Point(5.0, 5.0), new Point(0.0, 5.0));
                drawingContext.DrawLine(pen, new Point(5.0, 5.0), new Point(2.0, 2.0));
                drawingContext.DrawLine(pen, new Point(5.0, 5.0), new Point(8.0, 2.0));
                drawingContext.DrawLine(pen, new Point(5.0, 5.0), new Point(2.0, 8.0));
            }
            finally
            {
                if (drawingContext != null)
                {
                    drawingContext.Close();
                }
            }
            return(drawingGroup);
        }
Пример #17
0
        private void ModifyAnnotation(bool isNew)
        {
            Brush RandomBrush()
            {
                var b = new SolidColorBrush(Color.FromRgb((byte)RandomGen.GetInt(0, 255), (byte)RandomGen.GetInt(0, 255), (byte)RandomGen.GetInt(0, 255)));

                b.Freeze();
                return(b);
            }

            if (_annotation == null)
            {
                return;
            }

            IComparable x1, x2, y1, y2;

            var mode = RandomGen.GetDouble() > 0.5 ? AnnotationCoordinateMode.Absolute : AnnotationCoordinateMode.Relative;

            if (_annotationData == null)
            {
                if (mode == AnnotationCoordinateMode.Absolute)
                {
                    GetMiddle(out var x0, out var y0);
                    x1 = x0 - TimeSpan.FromMinutes(RandomGen.GetInt(10, 60));
                    x2 = x0 + TimeSpan.FromMinutes(RandomGen.GetInt(10, 60));
                    y1 = y0 - RandomGen.GetInt(5, 10) * _security.PriceStep ?? 0.01m;
                    y2 = y0 + RandomGen.GetInt(5, 10) * _security.PriceStep ?? 0.01m;
                }
                else
                {
                    x1 = 0.5 - RandomGen.GetDouble() / 10;
                    x2 = 0.5 + RandomGen.GetDouble() / 10;
                    y1 = 0.5 - RandomGen.GetDouble() / 10;
                    y2 = 0.5 - RandomGen.GetDouble() / 10;
                }
            }
            else
            {
                mode = _annotationData.CoordinateMode.Value;

                if (mode == AnnotationCoordinateMode.Absolute)
                {
                    x1 = (DateTimeOffset)_annotationData.X1 - TimeSpan.FromMinutes(1);
                    x2 = (DateTimeOffset)_annotationData.X2 + TimeSpan.FromMinutes(1);
                    y1 = (decimal)_annotationData.Y1 + _security.PriceStep ?? 0.01m;
                    y2 = (decimal)_annotationData.Y2 - _security.PriceStep ?? 0.01m;
                }
                else
                {
                    x1 = ((double)_annotationData.X1) - 0.05;
                    x2 = ((double)_annotationData.X2) + 0.05;
                    y1 = ((double)_annotationData.Y1) - 0.05;
                    y2 = ((double)_annotationData.Y2) + 0.05;
                }
            }

            _dataThreadActions.Add(() =>
            {
                var data = new ChartDrawData.AnnotationData
                {
                    X1         = x1,
                    X2         = x2,
                    Y1         = y1,
                    Y2         = y2,
                    IsVisible  = true,
                    Fill       = RandomBrush(),
                    Stroke     = RandomBrush(),
                    Foreground = RandomBrush(),
                    Thickness  = new Thickness(RandomGen.GetInt(1, 5)),
                };

                if (isNew)
                {
                    data.Text = "random annotation #" + (++_annotationId);
                    data.HorizontalAlignment = HorizontalAlignment.Stretch;
                    data.VerticalAlignment   = VerticalAlignment.Stretch;
                    data.LabelPlacement      = LabelPlacement.Axis;
                    data.ShowLabel           = true;
                    data.CoordinateMode      = mode;
                }

                var dd = new ChartDrawData();
                dd.Add(_annotation, data);

                Chart.Draw(dd);
            });
        }
Пример #18
0
        public void Render()
        {
            try
            {
                double CanvasWidth  = (ActualWidth - 24) * Zoom;
                double CanvasHeight = Height - 14;

                CanvasPlot.Children.Clear();

                if (CanvasWidth <= 0 || CanvasHeight <= 0)
                {
                    return;
                }

                #region Determine axis range

                ValueMin = double.MaxValue;
                ValueMax = -double.MaxValue;

                if (!double.IsNaN(AxisMin))
                {
                    ValueMin = AxisMin;
                }
                else if (Points != null && Points.Count > 0)
                {
                    foreach (var point in Points)
                    {
                        if (!double.IsNaN(point.Value))
                        {
                            ValueMin = Math.Min(ValueMin, point.Value);
                        }
                    }
                }
                else
                {
                    ValueMin = 0;
                }

                if (!double.IsNaN(AxisMax))
                {
                    ValueMax = AxisMax;
                }
                else if (Points != null && Points.Count > 0 && Points.Any(v => !double.IsNaN(v.Value)))
                {
                    foreach (var point in Points)
                    {
                        if (!double.IsNaN(point.Value))
                        {
                            ValueMax = Math.Max(ValueMax, point.Value);
                        }
                    }
                }
                else
                {
                    ValueMax = 1;
                }

                double Range = ValueMax - ValueMin;

                if (ValueMin == ValueMax) // Range = 0, probably only one point
                {
                    ValueMax += 1;
                    ValueMin -= 1;
                }
                else // Make sure there are a few pixels left to draw the points at the extremes
                {
                    if (double.IsNaN(AxisMax))
                    {
                        ValueMax += Range / CanvasHeight * PointRadius;
                    }
                    if (double.IsNaN(AxisMin))
                    {
                        ValueMin -= Range / CanvasHeight * PointRadius;
                    }
                }

                Range = ValueMax - ValueMin;

                Dispatcher.Invoke(() =>
                {
                    string FloatFormat = "F0";
                    if (Math.Max(ValueMax, ValueMin) < 100)
                    {
                        FloatFormat = "F1";
                    }
                    if (Math.Max(ValueMax, ValueMin) < 10)
                    {
                        FloatFormat = "F2";
                    }

                    TextLineBottom.Text = ValueMin.ToString(FloatFormat, CultureInfo.InvariantCulture);
                    TextLineCenter.Text = ((ValueMin + ValueMax) * 0.5).ToString(FloatFormat, CultureInfo.InvariantCulture);
                    TextLineTop.Text    = ValueMax.ToString(FloatFormat, CultureInfo.InvariantCulture);
                });

                #endregion

                #region Adjust range highlight

                double RangeHighlightClampedMin = Math.Max(ValueMin, RangeHighlightMin);
                double RangeHighlightClampedMax = Math.Min(ValueMax, RangeHighlightMax);

                PanelRangeHighlight.Margin = new Thickness(0, 7 + (ValueMax - RangeHighlightClampedMax) / Range * CanvasHeight, 0, 0);
                PanelRangeHighlight.Height = Math.Max(0, RangeHighlightClampedMax - RangeHighlightClampedMin) / Range * CanvasHeight;

                #endregion

                if (Range < 0 || Points == null || Points.Count == 0)
                {
                    ImagePlot.Source = null;
                    return;
                }

                float[] HistogramBins = new float[50];

                DrawingGroup DGroup = new DrawingGroup();
                using (DrawingContext DContext = DGroup.Open())
                {
                    DContext.PushClip(new RectangleGeometry(new Rect(new Size(CanvasWidth, CanvasHeight))));

                    Pen OutlinePen = new Pen(Brushes.Transparent, 0);
                    OutlinePen.Freeze();

                    SolidColorBrush BackgroundBrush = new SolidColorBrush(Colors.Transparent);
                    BackgroundBrush.Freeze();
                    DContext.DrawRectangle(BackgroundBrush, OutlinePen, new Rect(new Size(CanvasWidth, CanvasHeight)));

                    SolidColorBrush[] ColorBrushes = PointColors.Count > 0
                                                         ? PointColors.Select(c =>
                    {
                        SolidColorBrush Brush = new SolidColorBrush(Color.FromArgb(255, c.R, c.G, c.B));
                        Brush.Freeze();
                        return(Brush);
                    }).ToArray()
                                                         : new[] { new SolidColorBrush(Color.FromArgb(150, Colors.DeepSkyBlue.R, Colors.DeepSkyBlue.G, Colors.DeepSkyBlue.B)) };

                    StepX   = (CanvasWidth - PointRadius * 2) / Points.Count;
                    OffsetX = StepX / 2 + PointRadius;
                    StepY   = CanvasHeight / Range;

                    PointCenters = new System.Windows.Point[Points.Count];

                    for (int i = 0; i < Points.Count; i++)
                    {
                        if (double.IsNaN(Points[i].Value))
                        {
                            continue;
                        }

                        double X = i * StepX + OffsetX;
                        double Y = (ValueMax - Points[i].Value) * StepY;

                        DContext.DrawEllipse(ColorBrushes[Points[i].ColorID], OutlinePen, new System.Windows.Point(X, Y), PointRadius, PointRadius);

                        PointCenters[i] = new System.Windows.Point(X, Y);

                        HistogramBins[Math.Max(0, Math.Min(HistogramBins.Length - 1, (int)((Points[i].Value - ValueMin) / Range * (HistogramBins.Length - 1) + 0.5)))]++;
                    }
                }

                DrawingImage Plot = new DrawingImage(DGroup);
                Plot.Freeze();
                Dispatcher.Invoke(() => ImagePlot.Source = Plot);

                Dispatcher.Invoke(() =>
                {
                    float[] HistogramConv = new float[HistogramBins.Length];
                    float[] ConvKernel    = { 0.11f, 0.37f, 0.78f, 1f, 0.78f, 0.37f, 0.11f };
                    for (int i = 0; i < HistogramBins.Length; i++)
                    {
                        float Sum     = 0;
                        float Samples = 0;
                        for (int j = 0; j < ConvKernel.Length; j++)
                        {
                            int ij = i - 3 + j;
                            if (ij < 0 || ij >= HistogramBins.Length)
                            {
                                continue;
                            }
                            Sum     += ConvKernel[j] * HistogramBins[ij];
                            Samples += ConvKernel[j];
                        }
                        HistogramConv[i] = Sum / Samples;
                    }

                    float HistogramMax = MathHelper.Max(HistogramConv);
                    if (HistogramMax > 0)
                    {
                        HistogramConv = HistogramConv.Select(v => v / HistogramMax * 16).ToArray();
                    }

                    Polygon HistogramPolygon = new Polygon()
                    {
                        Stroke  = Brushes.Transparent,
                        Fill    = Brushes.Gray,
                        Opacity = 0.15
                    };
                    PointCollection HistogramPoints = new PointCollection(HistogramConv.Length);

                    HistogramPoints.Add(new System.Windows.Point(16, 0));
                    HistogramPoints.Add(new System.Windows.Point(16, CanvasHeight));
                    for (int i = 0; i < HistogramConv.Length; i++)
                    {
                        double X = 15 - HistogramConv[i];
                        double Y = CanvasHeight - (i / (float)(HistogramConv.Length - 1) * CanvasHeight);
                        HistogramPoints.Add(new System.Windows.Point(X, Y));
                    }

                    HistogramPolygon.Points = HistogramPoints;

                    CanvasHistogram.Children.Clear();
                    CanvasHistogram.Children.Add(HistogramPolygon);
                    Canvas.SetRight(HistogramPolygon, 0);
                });
            }
            catch
            {
            }
        }
Пример #19
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);
            if (CourseFileModel == null)
            {
                return;
            }
#if !true
            var g   = new StreamGeometry();
            var sgc = g.Open();

            Point?point = null;
            foreach (var courseModel in CourseFileModel.Courses)
            {
                point = null;
                if (courseModel.Waypoints.Count <= 1)
                {
                    continue;
                }

                //if (point != null)
                //{
                //    point = courseModel.Waypoints.First().Position;
                //    sgc.BeginFigure(point.Value, false, false);
                //    //pathFigure.Segments.Add(new LineSegment(courseModel.Waypoints.First().Position, false));
                //}
                //point = courseModel.Waypoints.First().Position;
                point = courseModel.Waypoints.First().Position;
                sgc.BeginFigure(point.Value, false, false);

                foreach (var waypointModel in courseModel.Waypoints.Skip(1))
                {
                    sgc.LineTo(waypointModel.Position, true, false);
                    //pathFigure.Segments.Add(new LineSegment(waypointModel.Position, true));
                    //point = waypointModel.Position;
                }
            }
            sgc.Close();
            var pen = new Pen(new SolidColorBrush(Stroke), StrokeThickness);
            drawingContext.DrawGeometry(null, pen, g);
            //Pen seriePen = new Pen(new SolidColorBrush(Stroke), 1.0);
            //bool firstPoint = true;
            //foreach (CurveValuePointVM pointVm in serieVm.Points.Cast<CurveValuePointVM>())
            //{
            //    if (pointVm.XValue < xMin || pointVm.XValue > xMax) continue;

            //    double x = basePoint.X + (pointVm.XValue - xMin) * xSizePerValue;
            //    double y = basePoint.Y - (pointVm.Value - yMin) * ySizePerValue;
            //    Point coord = new Point(x, y);

            //    if (firstPoint)
            //    {
            //        firstPoint = false;
            //        sgc.BeginFigure(coord, false, false);
            //    }
            //    else
            //    {
            //        sgc.LineTo(coord, true, false);
            //    }
            //}

            //sgc.Close();
            //dc.DrawGeometry(null, seriePen, g);
#else
            //Console.WriteLine("{0} OnRender", DateTime.Now);
            var pathGeometry = new PathGeometry();
            var pathFigure   = new PathFigure();
            pathGeometry.Figures.Add(pathFigure);

            Point?point = null;
            foreach (var courseModel in CourseFileModel.Courses)
            {
                if (courseModel.Waypoints.Count <= 1)
                {
                    continue;
                }

                if (point != null)
                {
                    pathFigure.Segments.Add(new LineSegment(courseModel.Waypoints.First().Position, false));
                }
                else
                {
                    pathFigure.StartPoint = courseModel.Waypoints.First().Position;
                }

                point = courseModel.Waypoints.First().Position;

                foreach (var waypointModel in courseModel.Waypoints.Skip(1))
                {
                    var lineSegment = new LineSegment(waypointModel.Position, true);
                    lineSegment.Freeze();
                    pathFigure.Segments.Add(lineSegment);
                    point = waypointModel.Position;
                }
            }

            pathFigure.Freeze();

            var solidColorBrush = new SolidColorBrush(Stroke);
            solidColorBrush.Freeze();

            var pen = new Pen(solidColorBrush, StrokeThickness);
            pen.Freeze();
            pathGeometry.Freeze();

            drawingContext.DrawGeometry(null, pen, pathGeometry);
#endif
        }
Пример #20
0
        private void RenderTheme(DrawingContext dc)
        {
            Size size        = RenderSize;
            bool horizontal  = Orientation == Orientation.Horizontal;
            bool isClickable = IsClickable && IsEnabled;
            bool isHovered   = isClickable && IsHovered;
            bool isPressed   = isClickable && IsPressed;
            ListSortDirection?sortDirection = SortDirection;
            bool isSorted   = sortDirection != null;
            bool isSelected = IsSelected;
            bool hasBevel   = (!isHovered && !isPressed && !isSorted && !isSelected);

            EnsureCache((int)AeroFreezables.NumFreezables);

            if (horizontal)
            {
                // When horizontal, rotate the rendering by -90 degrees
                Matrix m1 = new Matrix();
                m1.RotateAt(-90.0, 0.0, 0.0);
                Matrix m2 = new Matrix();
                m2.Translate(0.0, size.Height);

                MatrixTransform horizontalRotate = new MatrixTransform(m1 * m2);
                horizontalRotate.Freeze();
                dc.PushTransform(horizontalRotate);

                double temp = size.Width;
                size.Width  = size.Height;
                size.Height = temp;
            }

            if (hasBevel)
            {
                // This is a highlight that can be drawn by just filling the background with the color.
                // It will be seen through the gab between the border and the background.
                LinearGradientBrush bevel = (LinearGradientBrush)GetCachedFreezable((int)AeroFreezables.NormalBevel);
                if (bevel == null)
                {
                    bevel            = new LinearGradientBrush();
                    bevel.StartPoint = new Point();
                    bevel.EndPoint   = new Point(0.0, 1.0);
                    bevel.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF), 0.0));
                    bevel.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF), 0.4));
                    bevel.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFC, 0xFC, 0xFD), 0.4));
                    bevel.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFB, 0xFC, 0xFC), 1.0));
                    bevel.Freeze();

                    CacheFreezable(bevel, (int)AeroFreezables.NormalBevel);
                }

                dc.DrawRectangle(bevel, null, new Rect(0.0, 0.0, size.Width, size.Height));
            }

            // Fill the background
            AeroFreezables backgroundType = AeroFreezables.NormalBackground;

            if (isPressed)
            {
                backgroundType = AeroFreezables.PressedBackground;
            }
            else if (isHovered)
            {
                backgroundType = AeroFreezables.HoveredBackground;
            }
            else if (isSorted || isSelected)
            {
                backgroundType = AeroFreezables.SortedBackground;
            }

            LinearGradientBrush background = (LinearGradientBrush)GetCachedFreezable((int)backgroundType);

            if (background == null)
            {
                background            = new LinearGradientBrush();
                background.StartPoint = new Point();
                background.EndPoint   = new Point(0.0, 1.0);

                switch (backgroundType)
                {
                case AeroFreezables.NormalBackground:
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF), 0.0));
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF), 0.4));
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xF7, 0xF8, 0xFA), 0.4));
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xF1, 0xF2, 0xF4), 1.0));
                    break;

                case AeroFreezables.PressedBackground:
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xBC, 0xE4, 0xF9), 0.0));
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xBC, 0xE4, 0xF9), 0.4));
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x8D, 0xD6, 0xF7), 0.4));
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x8A, 0xD1, 0xF5), 1.0));
                    break;

                case AeroFreezables.HoveredBackground:
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xE3, 0xF7, 0xFF), 0.0));
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xE3, 0xF7, 0xFF), 0.4));
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xBD, 0xED, 0xFF), 0.4));
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xB7, 0xE7, 0xFB), 1.0));
                    break;

                case AeroFreezables.SortedBackground:
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xF2, 0xF9, 0xFC), 0.0));
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xF2, 0xF9, 0xFC), 0.4));
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xE1, 0xF1, 0xF9), 0.4));
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xD8, 0xEC, 0xF6), 1.0));
                    break;
                }

                background.Freeze();

                CacheFreezable(background, (int)backgroundType);
            }

            dc.DrawRectangle(background, null, new Rect(0.0, 0.0, size.Width, size.Height));

            if (size.Width >= 2.0)
            {
                // Draw the borders on the sides
                AeroFreezables sideType = AeroFreezables.NormalSides;
                if (isPressed)
                {
                    sideType = AeroFreezables.PressedSides;
                }
                else if (isHovered)
                {
                    sideType = AeroFreezables.HoveredSides;
                }
                else if (isSorted || isSelected)
                {
                    sideType = AeroFreezables.SortedSides;
                }

                if (SeparatorVisibility == Visibility.Visible)
                {
                    Brush sideBrush;
                    if (SeparatorBrush != null)
                    {
                        sideBrush = SeparatorBrush;
                    }
                    else
                    {
                        sideBrush = (Brush)GetCachedFreezable((int)sideType);
                        if (sideBrush == null)
                        {
                            LinearGradientBrush lgBrush = null;
                            if (sideType != AeroFreezables.SortedSides)
                            {
                                lgBrush            = new LinearGradientBrush();
                                lgBrush.StartPoint = new Point();
                                lgBrush.EndPoint   = new Point(0.0, 1.0);
                                sideBrush          = lgBrush;
                            }

                            switch (sideType)
                            {
                            case AeroFreezables.NormalSides:
                                lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xF2, 0xF2, 0xF2), 0.0));
                                lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xEF, 0xEF, 0xEF), 0.4));
                                lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xE7, 0xE8, 0xEA), 0.4));
                                lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xDE, 0xDF, 0xE1), 1.0));
                                break;

                            case AeroFreezables.PressedSides:
                                lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x7A, 0x9E, 0xB1), 0.0));
                                lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x7A, 0x9E, 0xB1), 0.4));
                                lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x50, 0x91, 0xAF), 0.4));
                                lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x4D, 0x8D, 0xAD), 1.0));
                                break;

                            case AeroFreezables.HoveredSides:
                                lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x88, 0xCB, 0xEB), 0.0));
                                lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x88, 0xCB, 0xEB), 0.4));
                                lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x69, 0xBB, 0xE3), 0.4));
                                lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x69, 0xBB, 0xE3), 1.0));
                                break;

                            case AeroFreezables.SortedSides:
                                sideBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0x96, 0xD9, 0xF9));
                                break;
                            }

                            sideBrush.Freeze();

                            CacheFreezable(sideBrush, (int)sideType);
                        }
                    }

                    dc.DrawRectangle(sideBrush, null, new Rect(0.0, 0.0, 1.0, Max0(size.Height - 0.95)));
                    dc.DrawRectangle(sideBrush, null, new Rect(size.Width - 1.0, 0.0, 1.0, Max0(size.Height - 0.95)));
                }
            }

            if (isPressed && (size.Width >= 4.0) && (size.Height >= 4.0))
            {
                // When pressed, there are added borders on the left and top
                LinearGradientBrush topBrush = (LinearGradientBrush)GetCachedFreezable((int)AeroFreezables.PressedTop);
                if (topBrush == null)
                {
                    topBrush            = new LinearGradientBrush();
                    topBrush.StartPoint = new Point();
                    topBrush.EndPoint   = new Point(0.0, 1.0);
                    topBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x86, 0xA3, 0xB2), 0.0));
                    topBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x86, 0xA3, 0xB2), 0.1));
                    topBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xAA, 0xCE, 0xE1), 0.9));
                    topBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xAA, 0xCE, 0xE1), 1.0));
                    topBrush.Freeze();

                    CacheFreezable(topBrush, (int)AeroFreezables.PressedTop);
                }

                dc.DrawRectangle(topBrush, null, new Rect(0.0, 0.0, size.Width, 2.0));

                LinearGradientBrush pressedBevel = (LinearGradientBrush)GetCachedFreezable((int)AeroFreezables.PressedBevel);
                if (pressedBevel == null)
                {
                    pressedBevel            = new LinearGradientBrush();
                    pressedBevel.StartPoint = new Point();
                    pressedBevel.EndPoint   = new Point(0.0, 1.0);
                    pressedBevel.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xA2, 0xCB, 0xE0), 0.0));
                    pressedBevel.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xA2, 0xCB, 0xE0), 0.4));
                    pressedBevel.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x72, 0xBC, 0xDF), 0.4));
                    pressedBevel.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x6E, 0xB8, 0xDC), 1.0));
                    pressedBevel.Freeze();

                    CacheFreezable(pressedBevel, (int)AeroFreezables.PressedBevel);
                }

                dc.DrawRectangle(pressedBevel, null, new Rect(1.0, 0.0, 1.0, size.Height - 0.95));
                dc.DrawRectangle(pressedBevel, null, new Rect(size.Width - 2.0, 0.0, 1.0, size.Height - 0.95));
            }

            if (size.Height >= 2.0)
            {
                // Draw the bottom border
                AeroFreezables bottomType = AeroFreezables.NormalBottom;
                if (isPressed)
                {
                    bottomType = AeroFreezables.PressedOrHoveredBottom;
                }
                else if (isHovered)
                {
                    bottomType = AeroFreezables.PressedOrHoveredBottom;
                }
                else if (isSorted || isSelected)
                {
                    bottomType = AeroFreezables.SortedBottom;
                }

                SolidColorBrush bottomBrush = (SolidColorBrush)GetCachedFreezable((int)bottomType);
                if (bottomBrush == null)
                {
                    switch (bottomType)
                    {
                    case AeroFreezables.NormalBottom:
                        bottomBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0xD5, 0xD5, 0xD5));
                        break;

                    case AeroFreezables.PressedOrHoveredBottom:
                        bottomBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0x93, 0xC9, 0xE3));
                        break;

                    case AeroFreezables.SortedBottom:
                        bottomBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0x96, 0xD9, 0xF9));
                        break;
                    }

                    bottomBrush.Freeze();

                    CacheFreezable(bottomBrush, (int)bottomType);
                }

                dc.DrawRectangle(bottomBrush, null, new Rect(0.0, size.Height - 1.0, size.Width, 1.0));
            }

            if (isSorted && (size.Width > 14.0) && (size.Height > 10.0))
            {
                // Draw the sort arrow
                TranslateTransform positionTransform = new TranslateTransform((size.Width - 8.0) * 0.5, 1.0);
                positionTransform.Freeze();
                dc.PushTransform(positionTransform);

                bool         ascending     = (sortDirection == ListSortDirection.Ascending);
                PathGeometry arrowGeometry = (PathGeometry)GetCachedFreezable(ascending ? (int)AeroFreezables.ArrowUpGeometry : (int)AeroFreezables.ArrowDownGeometry);
                if (arrowGeometry == null)
                {
                    arrowGeometry = new PathGeometry();
                    PathFigure arrowFigure = new PathFigure();

                    if (ascending)
                    {
                        arrowFigure.StartPoint = new Point(0.0, 4.0);

                        LineSegment line = new LineSegment(new Point(4.0, 0.0), false);
                        line.Freeze();
                        arrowFigure.Segments.Add(line);

                        line = new LineSegment(new Point(8.0, 4.0), false);
                        line.Freeze();
                        arrowFigure.Segments.Add(line);
                    }
                    else
                    {
                        arrowFigure.StartPoint = new Point(0.0, 0.0);

                        LineSegment line = new LineSegment(new Point(8.0, 0.0), false);
                        line.Freeze();
                        arrowFigure.Segments.Add(line);

                        line = new LineSegment(new Point(4.0, 4.0), false);
                        line.Freeze();
                        arrowFigure.Segments.Add(line);
                    }

                    arrowFigure.IsClosed = true;
                    arrowFigure.Freeze();

                    arrowGeometry.Figures.Add(arrowFigure);
                    arrowGeometry.Freeze();

                    CacheFreezable(arrowGeometry, ascending ? (int)AeroFreezables.ArrowUpGeometry : (int)AeroFreezables.ArrowDownGeometry);
                }

                // Draw two arrows, one inset in the other. This is to achieve a double gradient over both the border and the fill.
                LinearGradientBrush arrowBorder = (LinearGradientBrush)GetCachedFreezable((int)AeroFreezables.ArrowBorder);
                if (arrowBorder == null)
                {
                    arrowBorder            = new LinearGradientBrush();
                    arrowBorder.StartPoint = new Point();
                    arrowBorder.EndPoint   = new Point(1.0, 1.0);
                    arrowBorder.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x3C, 0x5E, 0x72), 0.0));
                    arrowBorder.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x3C, 0x5E, 0x72), 0.1));
                    arrowBorder.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xC3, 0xE4, 0xF5), 1.0));
                    arrowBorder.Freeze();
                    CacheFreezable(arrowBorder, (int)AeroFreezables.ArrowBorder);
                }

                dc.DrawGeometry(arrowBorder, null, arrowGeometry);

                LinearGradientBrush arrowFill = (LinearGradientBrush)GetCachedFreezable((int)AeroFreezables.ArrowFill);
                if (arrowFill == null)
                {
                    arrowFill            = new LinearGradientBrush();
                    arrowFill.StartPoint = new Point();
                    arrowFill.EndPoint   = new Point(1.0, 1.0);
                    arrowFill.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x61, 0x96, 0xB6), 0.0));
                    arrowFill.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x61, 0x96, 0xB6), 0.1));
                    arrowFill.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xCA, 0xE6, 0xF5), 1.0));
                    arrowFill.Freeze();
                    CacheFreezable(arrowFill, (int)AeroFreezables.ArrowFill);
                }

                // Inset the fill arrow inside the border arrow
                ScaleTransform arrowScale = (ScaleTransform)GetCachedFreezable((int)AeroFreezables.ArrowFillScale);
                if (arrowScale == null)
                {
                    arrowScale = new ScaleTransform(0.75, 0.75, 3.5, 4.0);
                    arrowScale.Freeze();
                    CacheFreezable(arrowScale, (int)AeroFreezables.ArrowFillScale);
                }

                dc.PushTransform(arrowScale);

                dc.DrawGeometry(arrowFill, null, arrowGeometry);

                dc.Pop(); // Scale Transform
                dc.Pop(); // Position Transform
            }

            if (horizontal)
            {
                dc.Pop(); // Horizontal Rotate
            }
        }
Пример #21
0
        /// <summary>
        /// When hit Ctrl+D
        /// </summary>
        internal void SelectNextOcurrence()
        {
            string selectedText;

            // Se já tem algo selecionado
            if (_selectionList.Count <= 0 && !_view.Selection.IsEmpty)
            {
                selectedText = _view.Selection.StreamSelectionSpan.GetText();

                // Coloca o cursor na própria palavra já selecionada
                _lastIndex = (_lastIndex == 0) ? _view.Selection.ActivePoint.Position.Position - selectedText.Length : _lastIndex;
            }
            else if (_selectionList.Count > 0)
            {
                var itemSelecionado = _selectionList[0];

                selectedText = _view.TextViewLines.FormattedSpan.GetText().Substring(itemSelecionado.Start, itemSelecionado.End - itemSelecionado.Start);

                // Coloca o cursor na própria palavra já selecionada
                _lastIndex = (_lastIndex == 0) ? itemSelecionado.End - selectedText.Length : _lastIndex;
            }
            else
            {
                // Se não tinha nada selecionado então retorno pois agora o filtro é este, o comando sempre vem para cá
                return;
            }

            _view.Selection.IsActive = false;
            _view.Selection.Clear();
            _view.Caret.IsHidden = true;

            // Expressão para buscar todas as palavras que forem iguais ao texto selecionado
            Regex todoLineRegex = new Regex(selectedText + @"\b");

            // Executa a expressão buscando as palavras
            MatchCollection matches = todoLineRegex.Matches(_view.TextViewLines.FormattedSpan.GetText());

            // Se encontrou algo igual ao selecionado
            if (matches.Count > 0)
            {
                // Último match que foi encontrado
                Match ultimoMatch = matches[matches.Count - 1];

                // Próximo match depois do último selecionado
                Match match = todoLineRegex.Match(_view.TextViewLines.FormattedSpan.GetText(), _lastIndex);

                // Se selecionou a próxima e é depois da última
                if (match.Success && (_trackPointList.Count < matches.Count))
                {
                    if (match.Index == ultimoMatch.Index)
                    {
                        _lastIndex = 1;
                    }
                    else
                    {
                        _lastIndex = match.Index + match.Length;
                    }

                    SnapshotSpan span = new SnapshotSpan(_view.TextSnapshot, Span.FromBounds(match.Index, match.Index + match.Length));

                    Geometry geometry = _view.TextViewLines.GetMarkerGeometry(span);

                    if (geometry != null)
                    {
                        Brush brush = new SolidColorBrush(Color.FromArgb(0x20, 0x00, 0x00, 0xff));
                        brush.Freeze();

                        SolidColorBrush penBrush = new SolidColorBrush(Colors.Red);
                        penBrush.Freeze();

                        Pen pen = new Pen(penBrush, 0.5);
                        pen.Freeze();

                        GeometryDrawing drawing = new GeometryDrawing(brush, pen, geometry);
                        drawing.Freeze();

                        DrawingImage drawingImage = new DrawingImage(drawing);
                        drawingImage.Freeze();

                        Image image = new Image
                        {
                            Source = drawingImage,
                        };

                        // Align the image with the top of the bounds of the text geometry
                        Canvas.SetLeft(image, geometry.Bounds.Left);
                        Canvas.SetTop(image, geometry.Bounds.Top);

                        // Adiciona o adornment, mas ao fazer o RedrawScreen ele é perdido
                        _layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, null, image, null);

                        // Cria o novo ponto do cursor, neste caso estou colocando ele na frente da palavra, ou seja na direita da palavra
                        ITrackingPoint cursorTrackingPoint = _view.TextSnapshot.CreateTrackingPoint(new SnapshotPoint(_view.TextSnapshot, match.Index + match.Length), PointTrackingMode.Positive);

                        _trackPointList.Add(cursorTrackingPoint);

                        _selectionList.Add(new TextSelection(
                                               new Tuple <ITrackingPoint, ITrackingPoint>
                                               (
                                                   _view.TextSnapshot.CreateTrackingPoint(new SnapshotPoint(_view.TextSnapshot, match.Index), PointTrackingMode.Positive),
                                                   _view.TextSnapshot.CreateTrackingPoint(new SnapshotPoint(_view.TextSnapshot, match.Index + match.Length), PointTrackingMode.Positive)
                                               ),
                                               _view));

                        RedrawScreen();
                    }
                }

                Selecting = true;

                // Diz que está editando
                Editing = true;
            }
        }
Пример #22
0
        public static bool CheckColor(NAME name)
        {
            State.SetCamProp();
            General.cam.ResetFlag();//カメラのフラグを初期化 リトライ時にフラグが初期化できてないとだめ
            //例 NGリトライ時は、General.cam.FlagFrame = trueになっていてNGフレーム表示の無限ループにいる

            int X      = 0;
            int Y      = 0;
            int HueMax = 0;
            int HueMin = 0;



            var ListH = new List <int>();
            //var ListS = new List<int>();
            //var ListV = new List<int>();

            int side = (int)Math.Sqrt(TEST_FRAME);//検査枠の1辺の長さ

            try
            {
                switch (name)
                {
                case NAME.LED1:
                    X      = Int32.Parse(State.camProp.LED1.Split('/').ToArray()[0]);
                    Y      = Int32.Parse(State.camProp.LED1.Split('/').ToArray()[1]);
                    HueMax = State.TestSpec.OrangeHueMax;
                    HueMin = State.TestSpec.OrangeHueMin;
                    break;

                case NAME.LED2:
                    X      = Int32.Parse(State.camProp.LED2.Split('/').ToArray()[0]);
                    Y      = Int32.Parse(State.camProp.LED2.Split('/').ToArray()[1]);
                    HueMax = State.TestSpec.GreenHueMax;
                    HueMin = State.TestSpec.GreenHueMin;
                    break;

                case NAME.LED3:
                    X      = Int32.Parse(State.camProp.LED3.Split('/').ToArray()[0]);
                    Y      = Int32.Parse(State.camProp.LED3.Split('/').ToArray()[1]);
                    HueMax = State.TestSpec.RedHueMax;
                    HueMin = State.TestSpec.RedHueMin;
                    break;
                }

                //cam0の画像を取得する処理
                General.cam.FlagTestPic = true;
                while (General.cam.FlagTestPic)
                {
                }

                source = General.cam.imageForTest;

                //デバッグ用コード(下記コメントを外すと画像を保存します)
                //source.SaveImage(@"C:\OS303\ColorPic.bmp");

                using (IplImage hsv = new IplImage(640, 360, BitDepth.U8, 3)) // グレースケール画像格納用の変数
                {
                    //RGBからHSVに変換
                    Cv.CvtColor(source, hsv, ColorConversion.BgrToHsv);

                    OpenCvSharp.CPlusPlus.Mat mat = new OpenCvSharp.CPlusPlus.Mat(hsv, true);


                    foreach (var i in Enumerable.Range(0, side))
                    {
                        foreach (var j in Enumerable.Range(0, side))
                        {
                            var re = mat.At <OpenCvSharp.CPlusPlus.Vec3b>((int)Y - (side / 2) + i, (int)X - (side / 2) + j);
                            if (re[1] == 255 && re[2] == 255)
                            {
                                ListH.Add(re[0]);
                            }
                        }
                    }

                    switch (name)
                    {
                    case NAME.LED1:    //黄色
                        H_Ave = ListH.Min();
                        break;

                    case NAME.LED2:    //緑色
                        H_Ave = ListH.Max();
                        break;

                    case NAME.LED3:    //赤色
                        H_Ave = ListH.Min();
                        break;
                    }


                    return(H_Ave >= HueMin && H_Ave <= HueMax);
                }
            }
            finally
            {
                string hsvValue = H_Ave.ToString("F0");

                ColorHSV hsv   = new ColorHSV((float)Test_Led.H_Ave / 180, 1, 1);
                var      rgb   = ColorConv.HSV2RGB(hsv);
                var      color = new SolidColorBrush(Color.FromRgb(rgb.R, rgb.G, rgb.B));
                color.Freeze();//これ重要!!!

                switch (name)
                {
                case NAME.LED1:
                    State.VmTestResults.HueLED1   = hsvValue;
                    State.VmTestResults.ColorLED1 = color;
                    break;

                case NAME.LED2:
                    State.VmTestResults.HueLED2   = hsvValue;
                    State.VmTestResults.ColorLED2 = color;
                    break;

                case NAME.LED3:
                    State.VmTestResults.HueLED3   = hsvValue;
                    State.VmTestResults.ColorLED3 = color;
                    break;
                }
            }
        }
Пример #23
0
 static MySimpleLabelStyle()
 {
     fillBrush = new SolidColorBrush(Color.FromArgb(255, 155, 226, 255));
     fillBrush.Freeze();
     editButtonStyle = (Style)Application.Current.Resources["EditLabelButtonStyle"];
 }
Пример #24
0
 static Brushes()
 {
     MissedBackground  = new SolidColorBrush(Color.FromRgb(0xff, 0xdd, 0xdd)); MissedBackground.Freeze();
     HitBackground     = new SolidColorBrush(Color.FromRgb(0xdd, 0xff, 0xdd)); HitBackground.Freeze();
     NotRunBackground  = new SolidColorBrush(Color.FromRgb(0xff, 0xff, 0xE0)); HitBackground.Freeze();
     DefaultBackground = System.Windows.Media.Brushes.Transparent;
 }
Пример #25
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            var view = this.TextView;

            if (view == null || !view.VisualLinesValid)
            {
                return;
            }
            if (!Workspace.CurrentWorkspace.DebugContext.IsDebuggerAttached)
            {
                return;
            }
            if (!Workspace.CurrentWorkspace.DebugContext.IsPaused)
            {
                return;
            }
            if (Workspace.CurrentWorkspace.CurrentDocument != Workspace.CurrentWorkspace.DebugContext.CurrentDocument)
            {
                return;
            }
            var color = new SolidColorBrush(ConfigHost.Coloring.ExecutionMarker.MainColor);

            color.Freeze();
            var pen = new Pen(new SolidColorBrush(ConfigHost.Coloring.ExecutionMarker.BorderColor), 1);

            pen.Freeze();

            var line = view.GetVisualLine(Workspace.CurrentWorkspace.DebugContext.CurrentLine);

            if (line == null)
            {
                return;
            }
            var lineTop = line.GetTextLineVisualYPosition(line.TextLines[0], VisualYPosition.TextTop) - view.VerticalOffset;
            var lineBot = line.GetTextLineVisualYPosition(line.TextLines[0], VisualYPosition.TextBottom) - view.VerticalOffset;
            var geo     = new StreamGeometry();

            using (var context = geo.Open())
            {
                context.BeginFigure(new Point(2, 5), true, true);
                context.LineTo(new Point(6, 5), true, false);
                context.LineTo(new Point(6, 2), true, false);
                context.LineTo(new Point(10, 6.5), true, false);
                context.LineTo(new Point(6, 11), true, false);
                context.LineTo(new Point(6, 8), true, false);
                context.LineTo(new Point(2, 8), true, false);
            }
            var       transgroup = new TransformGroup();
            Transform t;

            t = new TranslateTransform(-14, lineTop - 1);
            t.Freeze();
            transgroup.Children.Add(t);

            t = new ScaleTransform((lineBot - lineTop) / 14, (lineBot - lineTop) / 14);
            t.Freeze();
            transgroup.Children.Add(t);

            transgroup.Freeze();
            geo.Transform = transgroup;
            geo.Freeze();

            drawingContext.DrawGeometry(color, pen, geo);
        }
Пример #26
0
 static EntryBase()
 {
     backgroundBrush.Freeze();
     backgroundBrushSelected.Freeze();
     backgroundBrushHover.Freeze();
 }
            private static Model3D GenerateTreeMap3DModel(int index, int count)
            {
                MeshGeometry3D meshGeometry3D = new MeshGeometry3D();

                Point3DCollection positions = new Point3DCollection();

                positions.Add(new Point3D(0, 0, 1));
                positions.Add(new Point3D(0, 0, 0));
                positions.Add(new Point3D(1, 0, 0));
                positions.Add(new Point3D(1, 0, 1));
                positions.Add(new Point3D(0, 1, 1));
                positions.Add(new Point3D(0, 1, 0));
                positions.Add(new Point3D(1, 1, 0));
                positions.Add(new Point3D(1, 1, 1));
                positions.Freeze();

                Int32Collection triangleIndices = new Int32Collection();

                triangleIndices.Add(0);
                triangleIndices.Add(1);
                triangleIndices.Add(2);

                triangleIndices.Add(2);
                triangleIndices.Add(3);
                triangleIndices.Add(0);

                triangleIndices.Add(4);
                triangleIndices.Add(7);
                triangleIndices.Add(6);

                triangleIndices.Add(6);
                triangleIndices.Add(5);
                triangleIndices.Add(4);

                triangleIndices.Add(0);
                triangleIndices.Add(3);
                triangleIndices.Add(7);

                triangleIndices.Add(7);
                triangleIndices.Add(4);
                triangleIndices.Add(0);

                triangleIndices.Add(1);
                triangleIndices.Add(5);
                triangleIndices.Add(6);

                triangleIndices.Add(6);
                triangleIndices.Add(2);
                triangleIndices.Add(1);

                triangleIndices.Add(3);
                triangleIndices.Add(2);
                triangleIndices.Add(6);

                triangleIndices.Add(6);
                triangleIndices.Add(7);
                triangleIndices.Add(3);

                triangleIndices.Add(0);
                triangleIndices.Add(4);
                triangleIndices.Add(5);

                triangleIndices.Add(5);
                triangleIndices.Add(7);
                triangleIndices.Add(0);

                triangleIndices.Freeze();

                // finally set the data
                meshGeometry3D.TriangleIndices = triangleIndices;
                meshGeometry3D.Positions       = positions;

                // create the geometry model
                GeometryModel3D geom3D = new GeometryModel3D();

                geom3D.Geometry = meshGeometry3D;

                Color           color           = WpfUtil.HsbToRgb(index / (float)count, .9f, 1f);
                SolidColorBrush solidColorBrush = new SolidColorBrush(color);

                solidColorBrush.Freeze();

                geom3D.Material = new DiffuseMaterial(solidColorBrush);

                return(geom3D);
            }
Пример #28
0
 SimpleHighlightingBrush(SerializationInfo info, StreamingContext context)
 {
     brush = new SolidColorBrush((Color)ColorConverter.ConvertFromString(info.GetString("color")));
     brush.Freeze();
 }
Пример #29
0
        private void ApplyStyle(Shape shape, bool fillShape)
        {
            if (_currentState.CurrentPen == null)
            {
                // Stock Pen
                var newBrush = new SolidColorBrush(Colors.Black);
            #if !NETFX_CORE
                newBrush.Freeze();
            #endif
                shape.Stroke = newBrush;
                shape.StrokeThickness = 1;
            }
            else
            {
                LogPen currentPen = _currentState.CurrentPen;

                if (currentPen.Width > 0)
                {
                    shape.StrokeThickness = ScaleWidth(currentPen.Width);
                }

                // Style
                if ((PenStyle)(currentPen.Style & 0x000F) == PenStyle.PS_NULL)
                {
                    // Do nothing, null is the default
                    //shape.Stroke = null;
                }
                else
                {
                    var newBrush = new SolidColorBrush(currentPen.Colour);
            #if !NETFX_CORE
                    newBrush.Freeze();
            #endif
                    shape.Stroke = newBrush;

                    if ((PenStyle)(currentPen.Style & 0x000F) == PenStyle.PS_DASH)
                    {
                        shape.StrokeDashArray.Add(30);
                        shape.StrokeDashArray.Add(10);
                    }
                    else if ((PenStyle)(currentPen.Style & 0x000F) == PenStyle.PS_DASHDOT)
                    {
                        shape.StrokeDashArray.Add(30);
                        shape.StrokeDashArray.Add(10);
                        shape.StrokeDashArray.Add(10);
                        shape.StrokeDashArray.Add(10);
                        shape.StrokeDashArray.Add(10);
                        shape.StrokeDashArray.Add(10);
                    }
                    else if ((PenStyle)(currentPen.Style & 0x000F) == PenStyle.PS_DASHDOTDOT)
                    {

                        shape.StrokeDashArray.Add(30);
                        shape.StrokeDashArray.Add(10);
                        shape.StrokeDashArray.Add(10);
                        shape.StrokeDashArray.Add(10);
                        shape.StrokeDashArray.Add(10);
                        shape.StrokeDashArray.Add(10);
                        shape.StrokeDashArray.Add(10);
                        shape.StrokeDashArray.Add(10);
                    }
                    else if ((PenStyle)(currentPen.Style & 0x000F) == PenStyle.PS_DOT)
                    {
                        shape.StrokeDashArray.Add(10);
                        shape.StrokeDashArray.Add(10);
                        shape.StrokeDashCap = PenLineCap.Round;
                    }
                }

                // Join
                if ((PenStyle)(currentPen.Style & 0xF000) == PenStyle.PS_JOIN_BEVEL)
                {
                    shape.StrokeLineJoin = PenLineJoin.Bevel;
                }
                else if ((PenStyle)(currentPen.Style & 0xF000) == PenStyle.PS_JOIN_MITER)
                {
                    // Do nothing, miter is the default
                    shape.StrokeLineJoin = PenLineJoin.Miter;

                    if (_miterLimit != 0)
                    {
                        shape.StrokeMiterLimit = _miterLimit;
                    }
                }
                else if ((PenStyle)(currentPen.Style & 0xF000) == PenStyle.PS_JOIN_ROUND)
                {
                    shape.StrokeLineJoin = PenLineJoin.Round;
                }

                // End cap
                if ((PenStyle)(currentPen.Style & 0x0F00) == PenStyle.PS_ENDCAP_FLAT)
                {
                    // Do nothing, flat is the default
                    // shape.StrokeEndLineCap = PenLineCap.Flat;
                    // shape.StrokeStartLineCap = PenLineCap.Flat;
                }
                else if ((PenStyle)(currentPen.Style & 0x0F00) == PenStyle.PS_ENDCAP_SQUARE)
                {
                    shape.StrokeEndLineCap = PenLineCap.Square;
                    shape.StrokeStartLineCap = PenLineCap.Square;
                }
                else if ((PenStyle)(currentPen.Style & 0x0F00) == PenStyle.PS_ENDCAP_ROUND)
                {
                    shape.StrokeEndLineCap = PenLineCap.Round;
                    shape.StrokeStartLineCap = PenLineCap.Round;
                }
            }

            if (_currentState.CurrentBrush == null & fillShape)
            {
                // Stock brush
                var newBrush = new SolidColorBrush(Colors.White);
            #if !NETFX_CORE
                newBrush.Freeze();
            #endif
                shape.Fill = newBrush;
            }
            else if (fillShape)
            {
                LogBrush currentBrush = _currentState.CurrentBrush;

                if (currentBrush.Style == BrushStyle.BS_NULL)
                {
                    // Do nothing, null is the default
                    // shape.Fill = null;
                }
                else if (currentBrush.Image != null)
                {
            #if !NETFX_CORE
                    var imgBrush = new ImageBrush
                                       {
                                           ImageSource = currentBrush.Image,
                                           Stretch = Stretch.None,
                                           TileMode = TileMode.Tile,
                                           Viewport =
                                               new Rect(0, 0, ScaleWidth(currentBrush.Image.Width),
                                                        ScaleHeight(currentBrush.Image.Height)),
                                           ViewportUnits = BrushMappingMode.Absolute,
                                           Viewbox =
                                               new Rect(0, 0, ScaleWidth(currentBrush.Image.Width),
                                                        ScaleHeight(currentBrush.Image.Height)),
                                           ViewboxUnits = BrushMappingMode.Absolute
                                       };

                    imgBrush.Freeze();

                    shape.Fill = imgBrush;
            #endif
                    // TODO: Figure out a way to stop the tile anti-aliasing
                }
                else if (currentBrush.Style == BrushStyle.BS_PATTERN
                    | currentBrush.Style == BrushStyle.BS_DIBPATTERN
                    | currentBrush.Style == BrushStyle.BS_DIBPATTERNPT)
                {
                    var newBrush = new SolidColorBrush(Colors.Black);
            #if !NETFX_CORE
                    newBrush.Freeze();
            #endif
                    shape.Fill = newBrush;
                }
                else if (currentBrush.Style == BrushStyle.BS_HATCHED)
                {
            #if !NETFX_CORE
                    var patternBrush = new VisualBrush();
                    var patternTile = new Canvas();
                    var stroke1 = new Path();
                    var stroke2 = new Path();
                    var figure1 = new PathFigure();
                    var figure2 = new PathFigure();
                    var segments1 = new PathSegmentCollection();
                    var segments2 = new PathSegmentCollection();

                    patternBrush.TileMode = TileMode.Tile;
                    patternBrush.Viewport = new Rect(0, 0, 10, 10);
                    patternBrush.ViewportUnits = BrushMappingMode.Absolute;
                    patternBrush.Viewbox = new Rect(0, 0, 10, 10);
                    patternBrush.ViewboxUnits = BrushMappingMode.Absolute;

                    stroke1.Data = new PathGeometry();
                    stroke2.Data = new PathGeometry();

                    switch (currentBrush.Hatch)
                    {
                        case HatchStyle.HS_BDIAGONAL:
                            // A 45-degree upward, left-to-right hatch.
                            figure1.StartPoint = new Point(0, 10);

                            var up45Segment = new LineSegment
                                {
                                    Point = new Point(10, 0)
                                };
                            segments1.Add(up45Segment);
                            figure1.Segments = segments1;

                            ((PathGeometry)stroke1.Data).Figures.Add(figure1);
                            patternTile.Children.Add(stroke1);
                            break;

                        case HatchStyle.HS_CROSS:
                            // A horizontal and vertical cross-hatch.
                            figure1.StartPoint = new Point(5, 0);
                            figure2.StartPoint = new Point(0, 5);

                            var downXSegment = new LineSegment
                                {
                                    Point = new Point(5, 10)
                                };
                            segments1.Add(downXSegment);
                            figure1.Segments = segments1;
                            var rightXSegment = new LineSegment
                                {
                                    Point = new Point(10, 5)
                                };
                            segments2.Add(rightXSegment);
                            figure1.Segments = segments1;
                            figure2.Segments = segments2;

                            ((PathGeometry)stroke1.Data).Figures.Add(figure1);
                            ((PathGeometry)stroke2.Data).Figures.Add(figure2);

                            patternTile.Children.Add(stroke1);
                            patternTile.Children.Add(stroke2);
                            break;

                        case HatchStyle.HS_DIAGCROSS:
                            // A 45-degree crosshatch.
                            figure1.StartPoint = new Point(0, 0);
                            figure2.StartPoint = new Point(0, 10);

                            var downDXSegment = new LineSegment
                                {
                                    Point = new Point(10, 10)
                                };
                            segments1.Add(downDXSegment);
                            figure1.Segments = segments1;
                            var rightDXSegment = new LineSegment
                                {
                                    Point = new Point(10, 0)
                                };
                            segments2.Add(rightDXSegment);
                            figure1.Segments = segments1;
                            figure2.Segments = segments2;

                            ((PathGeometry)stroke1.Data).Figures.Add(figure1);
                            ((PathGeometry)stroke2.Data).Figures.Add(figure2);

                            patternTile.Children.Add(stroke1);
                            patternTile.Children.Add(stroke2);
                            break;

                        case HatchStyle.HS_FDIAGONAL:
                            // A 45-degree downward, left-to-right hatch.
                            figure1.StartPoint = new Point(0, 0);

                            var down45Segment = new LineSegment
                                {
                                    Point = new Point(10, 10)
                                };
                            segments1.Add(down45Segment);
                            figure1.Segments = segments1;

                            ((PathGeometry)stroke1.Data).Figures.Add(figure1);
                            patternTile.Children.Add(stroke1);
                            break;

                        case HatchStyle.HS_HORIZONTAL:
                            // A horizontal hatch.
                            figure1.StartPoint = new Point(0, 10);

                            var bottomSegment = new LineSegment
                                {
                                    Point = new Point(10, 10)
                                };
                            segments1.Add(bottomSegment);
                            figure1.Segments = segments1;

                            ((PathGeometry)stroke1.Data).Figures.Add(figure1);
                            patternTile.Children.Add(stroke1);
                            break;

                        case HatchStyle.HS_VERTICAL:
                            // A vertical hatch.
                            figure1.StartPoint = new Point(10, 0);

                            var verticalSegment = new LineSegment
                                {
                                    Point = new Point(10, 10)
                                };
                            segments1.Add(verticalSegment);
                            figure1.Segments = segments1;

                            ((PathGeometry)stroke1.Data).Figures.Add(figure1);
                            patternTile.Children.Add(stroke1);
                            break;
                    }

                    patternBrush.Visual = patternTile;
                    //patternBrush.Freeze();  // Cant freeze a visual brush
                    shape.Fill = patternBrush;
            #endif
                }
                else
                {
                    var newBrush = new SolidColorBrush(currentBrush.Colour);
            #if !NETFX_CORE
                    newBrush.Freeze();
            #endif
                    shape.Fill = newBrush;
                }
            }
        }
Пример #30
0
        public EditorElement(string filePath)
        {
            InitializeComponent();

            bracketSearcher                     = new SPBracketSearcher();
            bracketHighlightRenderer            = new BracketHighlightRenderer(editor.TextArea.TextView);
            editor.TextArea.IndentationStrategy = new EditorIndetationStrategy();

            FadeJumpGridIn  = (Storyboard)this.Resources["FadeJumpGridIn"];
            FadeJumpGridOut = (Storyboard)this.Resources["FadeJumpGridOut"];

            this.KeyDown += EditorElement_KeyDown;

            editor.TextArea.Caret.PositionChanged += Caret_PositionChanged;
            editor.TextArea.SelectionChanged      += TextArea_SelectionChanged;
            editor.TextArea.PreviewKeyDown        += TextArea_PreviewKeyDown;
            editor.PreviewMouseWheel    += PrevMouseWheel;
            editor.MouseDown            += editor_MouseDown;
            editor.TextArea.TextEntered += TextArea_TextEntered;

            FileInfo fInfo = new FileInfo(filePath);

            if (fInfo.Exists)
            {
                fileWatcher = new FileSystemWatcher(fInfo.DirectoryName)
                {
                    IncludeSubdirectories = false
                };
                fileWatcher.NotifyFilter        = NotifyFilters.Size | NotifyFilters.LastWrite;
                fileWatcher.Filter              = "*" + fInfo.Extension;
                fileWatcher.Changed            += fileWatcher_Changed;
                fileWatcher.EnableRaisingEvents = true;
            }
            else
            {
                fileWatcher = null;
            }
            _FullFilePath = filePath;
            editor.Options.ConvertTabsToSpaces      = false;
            editor.Options.EnableHyperlinks         = false;
            editor.Options.EnableEmailHyperlinks    = false;
            editor.Options.HighlightCurrentLine     = true;
            editor.Options.AllowScrollBelowDocument = true;
            editor.Options.ShowSpaces             = Program.OptionsObject.Editor_ShowSpaces;
            editor.Options.ShowTabs               = Program.OptionsObject.Editor_ShowTabs;
            editor.Options.IndentationSize        = Program.OptionsObject.Editor_IndentationSize;
            editor.TextArea.SelectionCornerRadius = 0.0;
            editor.Options.ConvertTabsToSpaces    = Program.OptionsObject.Editor_ReplaceTabsToWhitespace;

            Brush currentLineBackground = new SolidColorBrush(Color.FromArgb(0x20, 0x88, 0x88, 0x88));
            Brush currentLinePenBrush   = new SolidColorBrush(Color.FromArgb(0x30, 0x88, 0x88, 0x88));

            currentLinePenBrush.Freeze();
            Pen currentLinePen = new Pen(currentLinePenBrush, 1.0);

            currentLineBackground.Freeze();
            currentLinePen.Freeze();
            editor.TextArea.TextView.CurrentLineBackground = currentLineBackground;
            editor.TextArea.TextView.CurrentLineBorder     = currentLinePen;

            editor.FontFamily = new FontFamily(Program.OptionsObject.Editor_FontFamily);
            editor.WordWrap   = Program.OptionsObject.Editor_WordWrap;
            UpdateFontSize(Program.OptionsObject.Editor_FontSize, false);

            colorizeSelection = new ColorizeSelection();
            editor.TextArea.TextView.LineTransformers.Add(colorizeSelection);
            editor.SyntaxHighlighting = new AeonEditorHighlighting();

            LoadAutoCompletes();

            using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                using (StreamReader reader = FileReader.OpenStream(fs, Encoding.UTF8))
                {
                    string source = reader.ReadToEnd();
                    source      = ((source.Replace("\r\n", "\n")).Replace("\r", "\n")).Replace("\n", "\r\n"); //normalize line endings
                    editor.Text = source;
                }
            }
            _NeedsSave = false;

            Language_Translate(true);             //The Fontsize and content must be loaded

            var encoding = new UTF8Encoding(false);

            editor.Encoding = encoding; //let them read in whatever encoding they want - but save in UTF8

            foldingManager  = FoldingManager.Install(editor.TextArea);
            foldingStrategy = new SPFoldingStrategy();
            foldingStrategy.UpdateFoldings(foldingManager, editor.Document);

            regularyTimer          = new Timer(500.0);
            regularyTimer.Elapsed += regularyTimer_Elapsed;
            regularyTimer.Start();

            AutoSaveTimer          = new Timer();
            AutoSaveTimer.Elapsed += AutoSaveTimer_Elapsed;
            StartAutoSaveTimer();

            CompileBox.IsChecked = (bool?)filePath.EndsWith(".sp");
        }
Пример #31
0
        public static SolidColorBrush SolidColorBrushFromUint(uint argb)
        {
            SolidColorBrush scp = null;

            lock(s_solidColorBrushCache)
            {
                // Attempt to retrieve the color.  If it fails create it.
                if (!s_solidColorBrushCache.TryGetValue(argb, out scp))
                {
                    scp = new SolidColorBrush(Color.FromUInt32(argb));
                    scp.Freeze();
                    s_solidColorBrushCache[argb] = scp;
                }
#if DEBUG
                else
                {
                    s_count++;
                }
#endif
            }

            return scp;
        }
Пример #32
0
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            if (textView == null)
            {
                throw new ArgumentNullException("textView");
            }
            if (drawingContext == null)
            {
                throw new ArgumentNullException("drawingContext");
            }
            if (markersMap == null || !textView.VisualLinesValid)
            {
                return;
            }
            var visualLines = textView.VisualLines;

            if (visualLines.Count == 0)
            {
                return;
            }
            int viewStart = visualLines.First().FirstDocumentLine.Offset;
            int viewEnd   = visualLines.Last().LastDocumentLine.Offset + visualLines.Last().LastDocumentLine.Length;

            TextSegmentCollection <TextMarker> markers;

            if (!markersMap.TryGetValue(textView.Document, out markers))
            {
                return;
            }

            foreach (TextMarker marker in markers.FindOverlappingSegments(viewStart, viewEnd - viewStart))
            {
                if (marker.BackgroundColor != null)
                {
                    BackgroundGeometryBuilder geoBuilder = new BackgroundGeometryBuilder();
                    geoBuilder.AlignToWholePixels = true;
                    geoBuilder.CornerRadius       = 3;
                    geoBuilder.AddSegment(textView, marker);
                    Geometry geometry = geoBuilder.CreateGeometry();
                    if (geometry != null)
                    {
                        Color           color = marker.BackgroundColor.Value;
                        SolidColorBrush brush = new SolidColorBrush(color);
                        brush.Freeze();
                        drawingContext.DrawGeometry(brush, null, geometry);
                    }
                }
                if (marker.MarkerType != TextMarkerType.None)
                {
                    foreach (Rect r in BackgroundGeometryBuilder.GetRectsForSegment(textView, marker))
                    {
                        Point startPoint = r.BottomLeft;
                        Point endPoint   = r.BottomRight;

                        Pen usedPen = new Pen(new SolidColorBrush(marker.MarkerColor), 1);
                        usedPen.Freeze();
                        switch (marker.MarkerType)
                        {
                        case TextMarkerType.SquigglyUnderline:
                            double offset = 2.5;

                            int count = Math.Max((int)((endPoint.X - startPoint.X) / offset) + 1, 4);

                            StreamGeometry geometry = new StreamGeometry();

                            using (StreamGeometryContext ctx = geometry.Open())
                            {
                                ctx.BeginFigure(startPoint, false, false);
                                ctx.PolyLineTo(CreatePoints(startPoint, endPoint, offset, count).ToArray(), true, false);
                            }

                            geometry.Freeze();

                            drawingContext.DrawGeometry(Brushes.Transparent, usedPen, geometry);
                            break;
                        }
                    }
                }
            }
        }