コード例 #1
0
        internal void PaintGeometry()
        {
            if (!_visible || RecordCount == 0 || RecordCount < _chartPanel._chartX._startIndex)
            {
                return;
            }

            Brush strokeUpBrush     = new SolidColorBrush(UpColor == null ? _chartPanel._chartX.UpColor : UpColor.Value);
            Brush strokeDownBrush   = new SolidColorBrush(DownColor == null ? _chartPanel._chartX.DownColor : DownColor.Value);
            Brush strokeNormalBrush = new SolidColorBrush(_strokeColor);

            bool isOscillator = !ForceLinearChart && ForceOscilatorPaint;

            if (_pathUp == null)
            {
                var c = _chartPanel._rootCanvas;

                _pathUp = new Path
                {
                    Tag = this
                };
                c.Children.Add(_pathUp);
                Canvas.SetZIndex(_pathUp, ZIndexConstants.Indicators1);

                _pathDown = new Path
                {
                    Tag = this
                };
                c.Children.Add(_pathDown);
                Canvas.SetZIndex(_pathDown, ZIndexConstants.Indicators1);

                _pathNormal = new Path
                {
                    Tag = this,
                };
                c.Children.Add(_pathNormal);
                Canvas.SetZIndex(_pathNormal, ZIndexConstants.Indicators1);

                SolidColorBrush brush = new SolidColorBrush(_strokeColor);
                Paths.ForEach(_ =>
                {
                    _.StrokeThickness = _strokeThickness;
                    _.Stroke          = brush;
                    _.Opacity         = _opacity;
                    Types.SetShapePattern(_, _strokePattern);
                });
            }

            _pathUp.Stroke     = (Brush)strokeUpBrush.GetAsFrozen();
            _pathDown.Stroke   = (Brush)strokeDownBrush.GetAsFrozen();
            _pathNormal.Stroke = (Brush)strokeNormalBrush.GetAsFrozen();

            double?x2    = null;
            double?y2    = null;
            double yZero = GetY(0);

            GeometryGroup groupUp     = new GeometryGroup();
            GeometryGroup groupDown   = new GeometryGroup();
            GeometryGroup groupNormal = new GeometryGroup();

            GeometryGroup currentGroup = groupNormal;

            int cnt = 0;

            for (int i = _chartPanel._chartX._startIndex; i < _chartPanel._chartX._endIndex; i++, cnt++)
            {
                double x1 = _chartPanel._chartX.GetXPixel(cnt);
                double?y1;
                double?value = y1 = this[i].Value;
                if (!y1.HasValue)
                {
                    continue;
                }

                y1 = GetY(y1.Value);
                if (i > 0 && i == _chartPanel._chartX._startIndex)
                {
                    y2 = y1.Value;
                }

                #region brush logic

                if (_chartPanel._chartX._useLineSeriesColors || _upColor.HasValue) // +/- change colors
                {
                    if (!isOscillator)
                    {
                        if (i > 0)
                        {
                            if (this[i].Value > this[i - 1].Value)
                            {
                                currentGroup = groupUp;
                            }
                            else
                            {
                                currentGroup = this[i].Value < this[i - 1].Value ? groupDown : groupNormal;
                            }
                        }
                        else
                        {
                            currentGroup = groupNormal;
                        }
                    }
                    else
                    {
                        if (this[i].Value > 0)
                        {
                            currentGroup = groupUp;
                        }
                        else
                        {
                            currentGroup = this[i].Value < 0 ? groupDown : groupNormal;
                        }
                    }
                }

                #endregion

                switch (_seriesType)
                {
                case SeriesTypeEnum.stVolumeChart:
                    if (this[i].Value.HasValue && y2.HasValue)
                    {
                        //currentSb.AddSegment(x1, (double)y1, x1, GetY(SeriesEntry._min));
                        currentGroup.Children.Add(new LineGeometry
                        {
                            StartPoint = new Point(x1, y1.Value),
                            EndPoint   = new Point(x1, GetY(SeriesEntry._min))
                        });
                    }
                    break;

                case SeriesTypeEnum.stIndicator:
                case SeriesTypeEnum.stLineChart:
                    if (_indicatorType == IndicatorType.MACDHistogram || isOscillator)
                    {
                        if (value > 0)
                        {
                            y1 = GetY(value.Value);
                            y2 = yZero;
                        }
                        else
                        {
                            y1 = yZero;
                            y2 = GetY(value.Value);
                        }

                        if (this[i].Value.HasValue)
                        {
                            currentGroup.Children.Add(new LineGeometry
                            {
                                StartPoint = new Point(x1, y1.Value),
                                EndPoint   = new Point(x1, y2.Value),
                            });
                        }
                    }
                    else
                    {
                        if (i > _chartPanel._chartX._startIndex)
                        {
                            if (/*this[i].Value.HasValue && */ y2.HasValue && x2.HasValue && Math.Abs(x1 - x2.Value) > 1)
                            {
                                currentGroup.Children.Add(new LineGeometry
                                {
                                    StartPoint = new Point(x2.Value, y2.Value),
                                    EndPoint   = new Point(x1, y1.Value),
                                });
                            }
                        }
                    }
                    break;

                default:
                    throw new IndicatorException("Indicator has an unsuported series type.", this);
                }

                //if (linePainted || !y2.HasValue)
                y2 = y1;

                //if (linePainted || (i == _chartPanel._chartX._startIndex))
                x2 = x1;
            }


            _pathUp.Data     = (System.Windows.Media.Geometry)groupUp.GetAsFrozen();
            _pathDown.Data   = (System.Windows.Media.Geometry)groupDown.GetAsFrozen();
            _pathNormal.Data = (System.Windows.Media.Geometry)groupNormal.GetAsFrozen();

            if (_selected)
            {
                ShowSelection();
            }
        }
コード例 #2
0
        private static void ApplyThemeInternal(this FrameworkElement control, Theme?theme, SolidColorBrush accentBrush, SolidColorBrush contrastBrush)
        {
            ValidationHelper.NotNull(control, () => control);

            // Resource dictionaries paths
            var lightBrushesUri = new Uri("/Elysium;component/Themes/LightBrushes.xaml", UriKind.Relative);
            var darkBrushesUri  = new Uri("/Elysium;component/Themes/DarkBrushes.xaml", UriKind.Relative);

            // Resource dictionaries
            var lightBrushesDictionary = new ResourceDictionary {
                Source = lightBrushesUri
            };
            var darkBrushesDictionary = new ResourceDictionary {
                Source = darkBrushesUri
            };

            if (theme == Theme.Light)
            {
                // Add LightBrushes.xaml, if not included
                if (control.Resources.MergedDictionaries.All(dictionary => dictionary.Source != lightBrushesUri))
                {
                    control.Resources.MergedDictionaries.Add(lightBrushesDictionary);
                }

                // Remove DarkBrushes.xaml, if included
                var darkColorsDictionaries = control.Resources.MergedDictionaries.Where(dictionary => dictionary.Source == darkBrushesUri).ToList();
                foreach (var dictionary in darkColorsDictionaries)
                {
                    control.Resources.MergedDictionaries.Remove(dictionary);
                }
            }
            if (theme == Theme.Dark)
            {
                // Add DarkBrushes.xaml, if not included
                if (control.Resources.MergedDictionaries.All(dictionary => dictionary.Source != darkBrushesUri))
                {
                    control.Resources.MergedDictionaries.Add(darkBrushesDictionary);
                }

                // Remove LightBrushes.xaml, if included
                var lightColorsDictionaries = control.Resources.MergedDictionaries.Where(dictionary => dictionary.Source == lightBrushesUri).ToList();
                foreach (var dictionary in lightColorsDictionaries)
                {
                    control.Resources.MergedDictionaries.Remove(dictionary);
                }
            }

            // Bug in WPF 4: http://connect.microsoft.com/VisualStudio/feedback/details/555322/global-wpf-styles-are-not-shown-when-using-2-levels-of-references
            if (control.Resources.Keys.Count == 0)
            {
                control.Resources.Add(typeof(Window), new Style(typeof(Window)));
            }

            if (accentBrush != null)
            {
                var accentBrushFrozen = !accentBrush.IsFrozen && accentBrush.CanFreeze ? accentBrush.GetAsFrozen() : accentBrush;
                if (control.Resources.Contains("AccentBrush"))
                {
                    // Set AccentBrush value, if key exist
                    control.Resources["AccentBrush"] = accentBrushFrozen;
                }
                else
                {
                    // Add AccentBrush key and value, if key doesn't exist
                    control.Resources.Add("AccentBrush", accentBrushFrozen);
                }
            }

            if (contrastBrush != null)
            {
                var contrastBrushFrozen = !contrastBrush.IsFrozen && contrastBrush.CanFreeze ? contrastBrush.GetAsFrozen() : contrastBrush;
                if (control.Resources.Contains("ContrastBrush"))
                {
                    // Set ContrastBrush value, if key exist
                    control.Resources["ContrastBrush"] = contrastBrushFrozen;
                }
                else
                {
                    // Add ContrastBrush key and value, if key doesn't exist
                    control.Resources.Add("ContrastBrush", contrastBrushFrozen);
                }

                var semitransparentContrastBrush = contrastBrush.Clone();
                semitransparentContrastBrush.Opacity = 1d / 8d;
                var semitransparentContrastBrushFrozen = !semitransparentContrastBrush.IsFrozen && semitransparentContrastBrush.CanFreeze
                                                             ? semitransparentContrastBrush.GetAsFrozen()
                                                             : semitransparentContrastBrush;
                if (control.Resources.Contains("SemitransparentContrastBrush"))
                {
                    // Set SemitransparentContrastBrush value, if key exist
                    control.Resources["SemitransparentContrastBrush"] = semitransparentContrastBrushFrozen;
                }
                else
                {
                    // Add SemitransparentContrastBrush key and value, if key doesn't exist
                    control.Resources.Add("SemitransparentContrastBrush", semitransparentContrastBrushFrozen);
                }
            }

            // Add Generic.xaml, if not included
            var genericDictionaryUri = new Uri("/Elysium;component/Themes/Generic.xaml", UriKind.Relative);

            if (control.Resources.MergedDictionaries.All(dictionary => dictionary.Source != genericDictionaryUri))
            {
                control.Resources.MergedDictionaries.Add(new ResourceDictionary {
                    Source = genericDictionaryUri
                });
            }

            OnThemeChanged();
        }