Inheritance: HeliosVisual
Exemplo n.º 1
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            RotarySwitch rotarySwitch = Visual as RotarySwitch;

            if (rotarySwitch != null)
            {
                if (rotarySwitch.DrawLines)
                {
                    drawingContext.DrawDrawing(_lines);
                }
                foreach (SwitchPositionLabel label in _labels)
                {
                    drawingContext.DrawText(label.Text, label.Location);
                }

                drawingContext.PushTransform(new RotateTransform(rotarySwitch.KnobRotation, _center.X, _center.Y));
                drawingContext.DrawRectangle(_imageBrush, null, _imageRect);
                if (rotarySwitch.VisualizeDragging)
                {
                    double length = (rotarySwitch.DragPoint - _center).Length;
                    drawingContext.DrawLine(HeadingPen, _center, _center + new Vector(0d, -length));
                }
                drawingContext.Pop();

                if (rotarySwitch.VisualizeDragging)
                {
                    drawingContext.DrawLine(DragPen, _center, rotarySwitch.DragPoint);
                }
            }
        }
Exemplo n.º 2
0
        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            RotarySwitch rotary = Control as RotarySwitch;

            if (rotary != null)
            {
                rotary.DefaultPosition = DefaultPositionCombo.SelectedIndex + 1;
            }
        }
Exemplo n.º 3
0
        private void SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            RotarySwitch rotary = Control as RotarySwitch;

            if (rotary != null)
            {
                rotary.CurrentPosition = PositionList.SelectedIndex + 1;
            }
        }
Exemplo n.º 4
0
        private void Add_Position_Click(object sender, RoutedEventArgs e)
        {
            RotarySwitch rotary = Control as RotarySwitch;

            if (rotary != null)
            {
                RotarySwitchPosition position = new RotarySwitchPosition(rotary, rotary.Positions.Count + 1, rotary.Positions.Count.ToString(CultureInfo.InvariantCulture), 0d);
                rotary.Positions.Add(position);
                ConfigManager.UndoManager.AddUndoItem(new RotarySwitchAddPositionUndoEvent(rotary, position));
            }
        }
Exemplo n.º 5
0
        private void Position_GotFocus(object sender, RoutedEventArgs e)
        {
            RotarySwitch     rotary        = Control as RotarySwitch;
            FrameworkElement senderControl = sender as FrameworkElement;

            if (senderControl != null && rotary != null)
            {
                int index = rotary.Positions.IndexOf((RotarySwitchPosition)senderControl.Tag);
                rotary.CurrentPosition = index + 1;
            }
        }
Exemplo n.º 6
0
        private void DeletePosition_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            RotarySwitch rotary = Control as RotarySwitch;

            if (rotary != null && rotary.Positions.Contains((RotarySwitchPosition)PositionList.SelectedItem))
            {
                RotarySwitchPosition removedPosition = (RotarySwitchPosition)PositionList.SelectedItem;
                int index = rotary.Positions.IndexOf(removedPosition);
                rotary.Positions.Remove(removedPosition);
                ConfigManager.UndoManager.AddUndoItem(new RotarySwitchDeletePositionUndoEvent(rotary, removedPosition, index));
            }
        }
Exemplo n.º 7
0
 protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
 {
     if (e.Property == ControlProperty)
     {
         RotarySwitch rotary = Control as RotarySwitch;
         if (rotary != null && rotary.DefaultPosition > 0)
         {
             DefaultPositionCombo.SelectedIndex = rotary.DefaultPosition - 1;
         }
     }
     base.OnPropertyChanged(e);
 }
Exemplo n.º 8
0
        private void DeletePosition_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            RotarySwitch rotary = Control as RotarySwitch;

            if (rotary != null)
            {
                e.CanExecute = (rotary.Positions.Count > 2);
            }
            else
            {
                e.CanExecute = false;
            }
        }
Exemplo n.º 9
0
        private void Delete_Position_Click(object sender, RoutedEventArgs e)
        {
            RotarySwitch     rotary        = Control as RotarySwitch;
            FrameworkElement senderControl = sender as FrameworkElement;

            if (senderControl != null && rotary != null)
            {
                RotarySwitchPosition position = senderControl.Tag as RotarySwitchPosition;
                if (position != null && rotary.Positions.Contains(position))
                {
                    rotary.Positions.Remove(position);
                }
            }
        }
Exemplo n.º 10
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            RotarySwitch rotarySwitch = Visual as RotarySwitch;

            if (rotarySwitch != null)
            {
                if (rotarySwitch.DrawLines)
                {
                    drawingContext.DrawDrawing(_lines);
                }
                foreach (SwitchPositionLabel label in _labels)
                {
                    drawingContext.DrawText(label.Text, label.Location);
                }
                _imageBrush.RelativeTransform = new RotateTransform(rotarySwitch.KnobRotation, 0.5d, 0.5d);
                drawingContext.DrawRectangle(_imageBrush, null, _imageRect);
            }
        }
Exemplo n.º 11
0
        protected override void OnRefresh()
        {
            RotarySwitch rotarySwitch = Visual as RotarySwitch;

            if (rotarySwitch != null)
            {
                _imageRect.Width  = rotarySwitch.Width;
                _imageRect.Height = rotarySwitch.Height;
                _image            = ConfigManager.ImageManager.LoadImage(rotarySwitch.KnobImage);
                _imageBrush       = new ImageBrush(_image);
                _center           = new Point(rotarySwitch.Width / 2d, rotarySwitch.Height / 2d);

                _lines     = new GeometryDrawing();
                _lines.Pen = new Pen(new SolidColorBrush(rotarySwitch.LineColor), rotarySwitch.LineThickness);

                _labels.Clear();

                Vector v1            = new Point(_center.X, 0) - _center;
                double lineLength    = v1.Length * rotarySwitch.LineLength;
                double labelDistance = v1.Length * rotarySwitch.LabelDistance;
                v1.Normalize();
                GeometryGroup lineGroup  = new GeometryGroup();
                Brush         labelBrush = new SolidColorBrush(rotarySwitch.LabelColor);
                foreach (RotarySwitchPosition position in rotarySwitch.Positions)
                {
                    Matrix m1 = new Matrix();
                    m1.Rotate(position.Rotation);

                    if (rotarySwitch.DrawLines)
                    {
                        Vector v2 = v1 * m1;

                        Point startPoint = _center;
                        Point endPoint   = startPoint + (v2 * lineLength);

                        lineGroup.Children.Add(new LineGeometry(startPoint, endPoint));
                    }

                    if (rotarySwitch.DrawLabels)
                    {
                        FormattedText labelText = rotarySwitch.LabelFormat.GetFormattedText(labelBrush, position.Name);
                        labelText.TextAlignment = TextAlignment.Center;
                        labelText.MaxTextWidth  = rotarySwitch.Width;
                        labelText.MaxTextHeight = rotarySwitch.Height;

                        if (rotarySwitch.MaxLabelHeight > 0d && rotarySwitch.MaxLabelHeight < rotarySwitch.Height)
                        {
                            labelText.MaxTextHeight = rotarySwitch.MaxLabelHeight;
                        }
                        if (rotarySwitch.MaxLabelWidth > 0d && rotarySwitch.MaxLabelWidth < rotarySwitch.Width)
                        {
                            labelText.MaxTextWidth = rotarySwitch.MaxLabelWidth;
                        }

                        Point location = _center + (v1 * m1 * labelDistance);
                        if (position.Rotation <= 10d || position.Rotation >= 350d)
                        {
                            location.X -= labelText.MaxTextWidth / 2d;
                            location.Y -= labelText.Height;
                        }
                        else if (position.Rotation < 170d)
                        {
                            location.X -= (labelText.MaxTextWidth - labelText.Width) / 2d;
                            location.Y -= labelText.Height / 2d;
                        }
                        else if (position.Rotation <= 190d)
                        {
                            location.X -= labelText.MaxTextWidth / 2d;
                        }
                        else
                        {
                            location.X -= (labelText.MaxTextWidth + labelText.Width) / 2d;
                            location.Y -= labelText.Height / 2d;
                        }

                        _labels.Add(new SwitchPositionLabel(labelText, location));
                    }
                }
                _lines.Geometry = lineGroup;
                _lines.Freeze();
            }
            else
            {
                _image      = null;
                _imageBrush = null;
                _lines      = null;
                _labels.Clear();
            }
        }