Пример #1
0
        private void OnSliderClick(object sender, MouseButtonEventArgs e)
        {
            PatternPoint pp1 = null;
            if (e.ClickCount == 2)      // DoubleClick
            {
                System.Windows.Point pt = e.GetPosition((UIElement)sender);
                //Console.WriteLine("X: {0} Y: {1}", pt.X, pt.Y);
                //Console.WriteLine("ActualWidth: {0}", sliderArea.ActualWidth);
                int ledPos = (int)(pt.X * Maximum / sliderArea.ActualWidth);
                if (ledPos < 1)
                    ledPos = 1;
                //Console.WriteLine("LedPos: {0}", ledPos);
                //PatternPoint leftPoint = null;
                //PatternPoint rightPoint = null;

                //foreach (PatternPoint pp in Pattern)
                //{
                //    if (ledPos > pp.LedPos)
                //        leftPoint = pp;
                //}

                //for (int i = Pattern.Count - 1; i >= 0; i--)
                //{
                //    if (ledPos < Pattern[i].LedPos)
                //        rightPoint = Pattern[i];
                //}

                // если первая точка в Pattern
                if (ledPos < sliders[0].Value)
                {
                    switch (workMode)
                    {
                        case Mode.Range:
                            if ((sliders[0].Value - ledPos) >= 2)
                            {
                                pp1 = new PatternPoint(Pattern[0].PointColor, ledPos) { LedCount = 2, Variant = PointVariant.Range };
                            }
                            else
                                return;
                            break;
                        case Mode.Lightness:
                            return;
                        default:
                            pp1 = new PatternPoint(Pattern[0].PointColor, ledPos) { LedCount = 1 };
                            break;
                    }
                    
                    Pattern.Insert(0, pp1);
                    if (selectedSliderItem != null)
                        selectedSliderItem = null;
                    InsertSliders();
                    UpdateModel();
                    SelectedPoint = pp1;
                    return;
                }

                // если последняя точка в Pattern
                if (ledPos > sliders[sliders.Count - 1].Value)
                {
                    switch (workMode)
                    {
                        case Mode.Range:
                            if ((Maximum - ledPos) >= 2)
                            {
                                pp1 = new PatternPoint(Pattern[Pattern.Count - 1].PointColor, ledPos) { LedCount = 2, Variant = PointVariant.Range };
                            }
                            else
                                return;
                            break;
                        case Mode.Lightness:
                            return;
                        default:
                            pp1 = new PatternPoint(Pattern[Pattern.Count - 1].PointColor, ledPos) { LedCount = 1 };
                            break;
                    }
                    Pattern.Add(pp1);
                    if (selectedSliderItem != null)
                        selectedSliderItem = null;
                    InsertSliders();
                    UpdateModel();
                    SelectedPoint = pp1;
                    return;
                }

                // между PatternPoint
                PatternPoint before;
                PatternPoint after;
                for ( int i = 0; i < sliders.Count - 1; i++)
                {
                    if (ledPos > sliders[i].Value && ledPos < sliders[i + 1].Value)
                    {
                        if ((sliders[i].Variant == SliderVariant.RangeLeftLimit) &&
                            (sliders[i + 1].Variant == SliderVariant.RangeRightLimit))
                            // внутри Range не может быть точек
                            return;

                        before = Pattern[sliders[i].PatternIx];
                        after = Pattern[sliders[i + 1].PatternIx];
                        switch (workMode)
                        {
                            case Mode.Range:
                                if ((sliders[i + 1].Value - ledPos) > 2)
                                {
                                    //pp1 = new PatternPoint(before.PointColor, ledPos) { LedCount = 2, Variant = PointVariant.Range };
                                    pp1 = new PatternPoint(StripModel[ledPos - 1].PointColor, ledPos) { LedCount = 2, Variant = PointVariant.Range };
                                }
                                else
                                    return;
                                break;
                            case Mode.Lightness:
                                pp1 = new PatternPoint(StripModel[ledPos - 1].PointColor, ledPos) { LedCount = 1, Variant = PointVariant.Lightness };
                                break;
                            default:
                                pp1 = new PatternPoint(StripModel[ledPos - 1].PointColor, ledPos) { LedCount = 1 };
                                break;
                        }
                        Pattern.Insert(Pattern.IndexOf(after), pp1);
                        if (selectedSliderItem != null)
                            selectedSliderItem = null;
                        InsertSliders();
                        UpdateModel();
                        SelectedPoint = pp1;
                        return;
                    }
                }
                

                // между точками
                //Color c = (display.Items[ledPos] as PatternPoint).PointColor;
                //int ix = Pattern.IndexOf(rightPoint);
                //pp1 = new PatternPoint(c, ledPos) { LedCount = 1 };
                //Pattern.Insert(ix, pp1);

                //InsertSliders();
                //SelectedPoint = pp1;
            }
        }
Пример #2
0
        /// <summary>
        /// Inserts the sliders into the template. 
        /// </summary>
        private void InsertSliders()
        {
            
            if ((sliderGridDown == null) || (sliderGridUp == null)) return;
            sliderGridDown.Children.Clear();
            sliderGridUp.Children.Clear();
            if (sliders.Count != 0)
            {
                for (int k = 0; k < sliders.Count; k++)
                {
                    sliders[k].GotMouseCapture -= new MouseEventHandler(SliderItemGotMouseCapture);
                    sliders[k].ValueChanged -= new RoutedPropertyChangedEventHandler<double>(OnSliderItemValueChanged);
                }
                sliders.Clear();
            }

            int i = 0;
            SliderItem s = null;

            foreach (PatternPoint pp in Pattern)
            {
                if (pp.Variant == PointVariant.Range)
                {
                    s = new SliderItem(this, i, SliderVariant.RangeLeftLimit, pp.LedPos, Pattern.IndexOf(pp));
                    sliders.Add(s);
                    i++;
                    s = new SliderItem(this, i, SliderVariant.RangeRightLimit, pp.LedPos + pp.LedCount - 1, Pattern.IndexOf(pp));
                    goto M1;
                }
                if (pp.Variant == PointVariant.Gradient)
                {
                    s = new SliderItem(this, i, SliderVariant.Gradient, pp.LedPos, Pattern.IndexOf(pp));
                    goto M1;
                }
                if (pp.Variant == PointVariant.Lightness)
                {
                    s = new SliderItem(this, i, SliderVariant.Lightness, pp.LedPos, Pattern.IndexOf(pp));
                    goto M1;
                }
                M1:
                sliders.Add(s);
                i++;
            }

            for (int k = 0; k < sliders.Count; k++)
            {
                sliders[k].Maximum = Maximum;
                sliders[k].GotMouseCapture += new MouseEventHandler(SliderItemGotMouseCapture);
                sliders[k].ValueChanged += new RoutedPropertyChangedEventHandler<double>(OnSliderItemValueChanged);
                if (k % 2 == 0)
                    // чётный 
                    sliderGridUp.Children.Add(sliders[k]);
                else
                    // нечётный
                    sliderGridDown.Children.Add(sliders[k]);
            }
        }
Пример #3
0
        /************************************************************************/

        #region Input Handlers

        protected override void OnKeyDown(KeyEventArgs e)
        {
            PatternPoint pp;
            base.OnKeyDown(e);
            if (e.Key == Key.Delete)
            {
                if (SelectedPoint != null)
                {
                    pp = Pattern.FirstOrDefault(p => p.LedPos == SelectedPoint.LedPos);
                    Pattern.Remove(pp);
                    if (selectedSliderItem != null)
                        selectedSliderItem = null;
                    InsertSliders();
                    UpdateModel();
                    SelectedPoint = Pattern[0];
                }
            }
        }
Пример #4
0
        /************************************************************************/

        #region Other Methods (private)


        private void SliderItemGotMouseCapture(object sender, MouseEventArgs e)
        {
            if (selectedSliderItem != null)
                selectedSliderItem.IsSelected = false;
            SliderItem si = sender as SliderItem;
            clickedIx = si.Position;
            selectedSliderItem = si;
            selectedSliderItem.IsSelected = true;
            SelectedPoint = Pattern[si.PatternIx];
            valueLabel.Text = ((int)selectedSliderItem.Value).ToString();
            //SelectedPoint.LedPos = (int)selectedSliderItem.Value;
        }