using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using C1.Silverlight.Chart;

namespace ChartSamples
{
  [System.ComponentModel.Description("Chart wih visual effects(border and shadow)")]
  public partial class Effects : UserControl
  {
      List<C1Chart> _charts = new List<C1Chart>();

      ShadowEffect se = new ShadowEffect();
      BorderEffect be = new BorderEffect();

      public Effects()
      {
        InitializeComponent();

        VisualEffectGroup vg = new VisualEffectGroup();
        vg.Children.Add(se); vg.Children.Add(be);

        _charts.Add(chart0);
        _charts.Add(chart1);
        _charts.Add(chart2);
        _charts.Add(chart3);

        foreach (C1Chart chart in _charts)
        {
          chart.Tag = new SampleData();
          chart.Data = ((SampleData)chart.Tag).GetData(chart.ChartType);
          chart.VisualEffect = vg;
        }

        vfxOptions.StateChanged += new EventHandler(vfxOptions_StateChanged);
        vfxOptions_StateChanged(this, EventArgs.Empty);
      }

      void vfxOptions_StateChanged(object sender, EventArgs e)
      {
        VisualEffectsState state = vfxOptions.State;

        foreach (C1Chart chart in _charts)
          chart.BeginUpdate();

        se.Color = state.ShadowColor;
        se.Depth = state.ShadowDepth;
        se.Opacity = state.ShadowOpacity;
        se.Softness = state.IsSoftShadow ? 1.0 : 0.0;
        se.LightAngle = be.LightAngle = state.LightAngle;

        be.Thickness = state.BorderThickness;
        be.BorderStyle = state.BorderStyle;

        foreach (C1Chart chart in _charts)
          chart.EndUpdate();
      }

      private void C1Chart_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
      {
        C1Chart chart = (C1Chart)sender;

        if (Keyboard.Modifiers == ModifierKeys.Control)
        {
          int i = (int)chart.Theme + 1;
          foreach (C1Chart cctl in _charts)
          {
            cctl.BeginUpdate();

          if (Enum.IsDefined(typeof(ChartTheme), i))
              cctl.Theme = (ChartTheme)Enum.ToObject(typeof(ChartTheme), i);
          else
              cctl.Theme = (ChartTheme)0;
            cctl.Palette = Palette.Default;

            cctl.EndUpdate();
          }
        }
        else if (Keyboard.Modifiers == ModifierKeys.Alt)
        {
          chart.BeginUpdate();
          int i = (int)chart.ChartType + 1;
          if (Enum.IsDefined(typeof(ChartType), i))
            chart.ChartType = (ChartType)Enum.ToObject(typeof(ChartType), i);
          else
            chart.ChartType = (ChartType)0;
          chart.Data = ((SampleData)chart.Tag).GetData(chart.ChartType);
          chart.EndUpdate();
        }
        else
        {
          chart.BeginUpdate();
          int i = (int)chart.Palette + 1;
          if (Enum.IsDefined(typeof(Palette), i))
            chart.Palette = (Palette)Enum.ToObject(typeof(Palette), i);
          else
            chart.Palette = (Palette)0;
          chart.EndUpdate();
        }
      }

      private void vfxOptions_Loaded(object sender, RoutedEventArgs e)
      {
        vfxOptions.Foreground = Foreground;
      }
    }
}
