public AutoCompleteTextBox()
        {
            _controls = new VisualCollection(this);
            InitializeComponent();

            _autoCompletionList = new ObservableCollection<AutoCompleteEntry>();
            _searchThreshold = 2;        // default threshold to 2 char

            // set up the key press timer
            _keypressTimer = new System.Timers.Timer();
            _keypressTimer.Elapsed += OnTimedEvent;

            // set up the text box and the combo box
            ComboBox = new ComboBox
            {
                IsSynchronizedWithCurrentItem = true,
                IsTabStop = false
            };

            ComboBox.SelectionChanged += comboBox_SelectionChanged;

            _textBox = new TextBox();
            _textBox.TextChanged += textBox_TextChanged;
            _textBox.VerticalContentAlignment = VerticalAlignment.Center;

            _controls.Add(ComboBox);
            _controls.Add(_textBox);
        }
Exemple #2
0
        public SOMVisual(SOMVisualType type, int size, int width, int height, PictureSOM.SOM s)
        {
            _visualType = type;
            _boardSize = PictureSOM.SOMConstants.NUM_NODES_ACROSS; // assuming that across and down are the same
            _boardWidthFactor = (width - (2 * _border)) / size;
            _boardHeightFactor = (height - (2 * _border)) / size;

            _som = s;

            _children = new VisualCollection(this);
            DrawBoard();
            _children.Add(_boardDrawingVisual); // Render the grid

            if (_visualType == SOMVisualType.COMPETITION_LAYER_MAP)
            {
                CreateDrawingVisual_Text(s);
            }
            else if(_visualType == SOMVisualType.COMPETITION_LAYER_MAP_FIXED)
            {
                CreateDrawingVisual_Text_Fixed(s);
            }
            else if (_visualType == SOMVisualType.ERROR_MAP)
            {
                CreateDrawingVisual_ErrorMap(s);
            }
            _children.Add(_drawingVisual);

            // Add the event handler for MouseLeftButtonUp.
            this.MouseLeftButtonUp += new MouseButtonEventHandler(SOMVisual_MouseLeftButtonUp);
        }
        public AutoCompleteTextBox()
        {
            controls = new VisualCollection(this);
            InitializeComponent();

            searchThreshold = 2;        // default threshold to 2 char

            // set up the key press timer
            keypressTimer = new System.Timers.Timer();
            keypressTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnTimedEvent);

            // set up the text box and the combo box
            comboBox = new ComboBox();
            comboBox.IsSynchronizedWithCurrentItem = true;
            comboBox.IsTabStop = false;
            comboBox.SelectionChanged += new SelectionChangedEventHandler(comboBox_SelectionChanged);

            textBox = new TextBox();
            textBox.TextChanged += new TextChangedEventHandler(textBox_TextChanged);
            textBox.VerticalContentAlignment = VerticalAlignment.Center;

            controls.Add(comboBox);
            controls.Add(textBox);

        }
Exemple #4
0
 public MyCanvasAdorner(UIElement adorned)
     : base(adorned)
 {
     visCollec = new VisualCollection(this);
     visCollec.Add(tl = GetResizeThumb(Cursors.SizeNWSE, HorizontalAlignment.Left, VerticalAlignment.Top));
     visCollec.Add(tr = GetResizeThumb(Cursors.SizeNESW, HorizontalAlignment.Right, VerticalAlignment.Top));
     visCollec.Add(bl = GetResizeThumb(Cursors.SizeNESW, HorizontalAlignment.Left, VerticalAlignment.Bottom));
     visCollec.Add(br = GetResizeThumb(Cursors.SizeNWSE, HorizontalAlignment.Right, VerticalAlignment.Bottom));
     visCollec.Add(mov = GetMoveThumb());
 }
 public ModelOperationAdorner(ModelItem adorned)
     : base(adorned)
 {
     collection = new VisualCollection(this);
     collection.Add(tl = GetResizeThumb("LT"));
     collection.Add(tr = GetResizeThumb("RT"));
     collection.Add(bl = GetResizeThumb("LB"));
     collection.Add(br = GetResizeThumb("RB"));
     collection.Add(handler = GetMoveThumb());
 }
        public CustomVisualFrameworkElement()
        {
            // Fill the VisualCollection with a few DrawingVisual objects.
            theVisuals = new VisualCollection(this);
            theVisuals.Add(AddRect());
            theVisuals.Add(AddCircle());

            // Handle the MouseDown event.
            this.MouseDown += MyVisualHost_MouseDown;
        }
        public MyVisualHost()
        {
            _children = new VisualCollection(this);
            _children.Add(CreateDrawingVisualRectangle());
            _children.Add(CreateDrawingVisualText());
            _children.Add(CreateDrawingVisualEllipses());

            // Add the event handler for MouseLeftButtonUp.
            this.MouseLeftButtonUp += new MouseButtonEventHandler(MyVisualHost_MouseLeftButtonUp);
        }
 public LayoutVisualHost(double width, double height, int curBatch, bool anotherRun)
 {
     this.width = width;
     this.height = height;
     backOffset = (height - 20) / 8.0;
     frontOffset = (height - 20) / 4.0;
     spotHeight = (height - backOffset - frontOffset) / 9.0;
     spotWidth = spotHeight / 3.0;
     _children = new VisualCollection(this);
     _children.Add(CreateDarkSpots());
     _children.Add(CreateRacks(curBatch,anotherRun));
 }
		public VisualAdorner(FrameworkElement adornerElement, UIElement adornedElement)
			: base(adornedElement) {
			children = new VisualCollection(this);
			child = adornerElement;
			children.Add(child);
			AddLogicalChild(child);
		}
        public PasswordBoxHintAdorner(UIElement adornedElement, string hintText, Style hintStyle, VisibilityDelegate visibilityCallback)
          : base(adornedElement)
        {
            _visibilityCallback = visibilityCallback;

            _label = new Label()
            {
                Content = hintText,
                Style = hintStyle,
            };

            IsHitTestVisible = true;
            Visibility = Visibility.Visible;

            adornedElement.GotFocus += Invalidate;
            adornedElement.LostFocus += Invalidate;
            adornedElement.IsVisibleChanged += Invalidate;

            _visualCollection = new VisualCollection(this);
            _contentPresenter = new ContentPresenter();
            _visualCollection.Add(_contentPresenter);
            _contentPresenter.Content = _label;

            AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(adornedElement);
            adornerLayer?.Add(this);

            IsHitTestVisible = false;
        }
        public ResizeAdorner(PanelDesigner panelDesigner, UIElement adornedElement)
            : base(adornedElement)
        {
            m_panelDesigner = panelDesigner;
            m_panelDesigner.SelectedElementChanged += m_panelDesigner_SelectedElementChanged;
            m_visualChildren = new VisualCollection(this);

            m_rectangle = new Rectangle();
            m_rectangle.Stroke = m_panelDesigner.SelectedElement == AdornedElement ? Brushes.CornflowerBlue : Brushes.LightBlue;
            m_rectangle.StrokeThickness = 1;
            m_visualChildren.Add(m_rectangle);

            BuildResizeAdorner(ref m_bottom, Cursors.SizeNS);
            BuildResizeAdorner(ref m_bottomLeft, Cursors.SizeNESW);
            BuildResizeAdorner(ref m_bottomRight, Cursors.SizeNWSE);
            BuildResizeAdorner(ref m_left, Cursors.SizeWE);
            BuildResizeAdorner(ref m_right, Cursors.SizeWE);
            BuildResizeAdorner(ref m_top, Cursors.SizeNS);
            BuildResizeAdorner(ref m_topLeft, Cursors.SizeNWSE);
            BuildResizeAdorner(ref m_topRight, Cursors.SizeNESW);

            m_bottom.DragDelta += new DragDeltaEventHandler(HandleBottom);
            m_bottomLeft.DragDelta += new DragDeltaEventHandler(HandleBottomLeft);
            m_bottomRight.DragDelta += new DragDeltaEventHandler(HandleBottomRight);
            m_left.DragDelta += new DragDeltaEventHandler(HandleLeft);
            m_right.DragDelta += new DragDeltaEventHandler(HandleRight);
            m_top.DragDelta += new DragDeltaEventHandler(HandleTop);
            m_topLeft.DragDelta += new DragDeltaEventHandler(HandleTopLeft);
            m_topRight.DragDelta += new DragDeltaEventHandler(HandleTopRight);
        }
 public AdornerContentPresenter (UIElement adornedElement)
     : base(adornedElement)
 {
     _Visuals = new VisualCollection(this);
     _ContentPresenter = new ContentPresenter();
     _Visuals.Add(_ContentPresenter);
 }
Exemple #13
0
        public ElementAdorner(UIElement adornedElement, IControlBox controlBox)
            : base(adornedElement)
        {
            visualChildren = new VisualCollection(this);

            FrameworkElement box = controlBox as FrameworkElement;
            this.controlBox = box;
            panel.Children.Add(box);
            panel.Orientation = Orientation.Vertical;
            visualChildren.Add(panel);

            // Call a helper method to initialize the Thumbs
            // with a customized cursors.
            BuildAdornerCorner(ref resizeThumb, Cursors.SizeNWSE);

            // Add handlers for resizing.

            resizeThumb.DragDelta += new DragDeltaEventHandler(HandleBottomRight);
            this.ProcessControlBox(controlBox);
            this.MouseEnter += new MouseEventHandler(adornedElement_MouseEnter);
            this.MouseLeave += new MouseEventHandler(adornedElement_MouseLeave);
            this.AdornedElement.MouseEnter += new MouseEventHandler(adornedElement_MouseEnter);
            this.AdornedElement.MouseLeave += new MouseEventHandler(adornedElement_MouseLeave);
            this.Opacity = 0;
        }
Exemple #14
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="adornedElement"></param>
        public ResizingAdorner(UIElement adornedElement)
            : base(adornedElement)
        {
            visualChildren = new VisualCollection(this);
            mainrec = new Rectangle();
            SolidColorBrush brush = new SolidColorBrush(Colors.DimGray);

            mainrec.Stroke = Brushes.Firebrick;
            DoubleCollection col = new DoubleCollection();
            col.Add(5.0);
            col.Add(2.30);
            mainrec.StrokeDashArray = col;
            visualChildren.Add(mainrec);

            // Call a helper method to initialize the Thumbs
            // with a customized cursors.
            BuildAdornerCorner(ref topLeft, Cursors.SizeNWSE);
            BuildAdornerCorner(ref topRight, Cursors.SizeNESW);
            BuildAdornerCorner(ref bottomLeft, Cursors.SizeNESW);
            BuildAdornerCorner(ref bottomRight, Cursors.SizeNWSE);

            // Add handlers for resizing.
            bottomLeft.DragDelta += new DragDeltaEventHandler(HandleBottomLeft);
            bottomRight.DragDelta += new DragDeltaEventHandler(HandleBottomRight);
            topLeft.DragDelta += new DragDeltaEventHandler(HandleTopLeft);
            topRight.DragDelta += new DragDeltaEventHandler(HandleTopRight);

            this.MinWidth = 50;

        }
Exemple #15
0
 public ResizeAdorner(UIElement adornedElement)
     : base(adornedElement)
 {
     _visualChildren = new VisualCollection(this);
     _control = new ResizeControl {DataContext = adornedElement};
     _visualChildren.Add(_control);
 }
 public WaveFormVisual()
 {
     maxPoints = new List<Point>();
     minPoints = new List<Point>();
     _children = new VisualCollection(this);
     _children.Add(CreateWaveFormVisual());            
 }
 /// <summary>
 /// Creates a Bookmarklayer
 /// </summary>
 /// <param name="adornedElement"></param>
 public BookmarkLayer(UIElement adornedElement)
     : base(adornedElement)
 {
     visualChildren = new VisualCollection(this);
     grid = new Grid();
     grid.Margin = new Thickness(0, 1, 0, 0);
     visualChildren.Add(grid);
 }
Exemple #18
0
 public LoadingAdorner(UIElement adornedElement)
     : base(adornedElement)
 {
     _children = new VisualCollection(this);
     _children.Add(_content = new LoadingControl());
     if (adornedElement is Control)
         _content.DataContext = ((Control)adornedElement).DataContext;
 }
        public MyImageAdorner(UIElement adornedElement)
            : base(adornedElement)
        {
            visualChildren = new VisualCollection(this);

            rotateHandle = new Thumb();
            rotateHandle.Cursor = Cursors.SizeWE;
            rotateHandle.Width = 20;
            rotateHandle.Height = 20;
            rotateHandle.Background = Brushes.Blue;

            rotateHandle.DragDelta += new DragDeltaEventHandler(rotateHandle_DragDelta);
            rotateHandle.DragCompleted += new DragCompletedEventHandler(rotateHandle_DragCompleted);

            moveHandle = new Thumb();
            moveHandle.Cursor = Cursors.SizeAll;
            moveHandle.Width = 20;
            moveHandle.Height = 20;
            moveHandle.Background = Brushes.Yellow;

            moveHandle.DragDelta += new DragDeltaEventHandler(moveHandle_DragDelta);
            moveHandle.DragCompleted += new DragCompletedEventHandler(moveHandle_DragCompleted);

            scaleHandle = new Thumb();
            scaleHandle.Cursor = Cursors.SizeNWSE;
            scaleHandle.Width = 20;
            scaleHandle.Height = 20;
            scaleHandle.Background = Brushes.Red;

            scaleHandle.DragDelta += new DragDeltaEventHandler(scaleHandle_DragDelta);
            scaleHandle.DragCompleted += new DragCompletedEventHandler(scaleHandle_DragCompleted);

            outline = new Path();
            outline.Stroke = Brushes.Gray;
            outline.StrokeThickness = 10;

            visualChildren.Add(outline);
            visualChildren.Add(rotateHandle);
            visualChildren.Add(moveHandle);
            visualChildren.Add(scaleHandle);

            rotation = new RotateTransform();
            translate = new TranslateTransform();
            scale = new ScaleTransform();
            transformGroup = new TransformGroup();
        }
Exemple #20
0
 public CounterAdorner(UIElement adornedElement)
     : base(adornedElement)
 {
     ownerElement = adornedElement;
     visualChildren = new VisualCollection(this);
     counter = new Label { Style = (Style)FindResource("CounterStyle"),
     Content=null};
     visualChildren.Add(counter);
 }
        public HexColumnHeader()
        {
            offset = 0;

            _children = new VisualCollection(this);
            _child = new DrawingVisual();

            _children.Add(_child);
        }
        public EditableTextBlockAdorner( EditableTextBlock adornedElement )
            : base(adornedElement)
        {
            myTextBlock = adornedElement;

            myTextBox = CreateTextBox( adornedElement );

            myCollection = new VisualCollection( this );
            myCollection.Add( myTextBox );
        }
Exemple #23
0
        public SizeAdorner(UIElement adornedControl)
            : base(adornedControl)
        {
            SnapsToDevicePixels = true;

            m_Chrome = new SizeChrome();
            m_Chrome.DataContext = adornedControl;
            m_Visuals = new VisualCollection(this);
            m_Visuals.Add(m_Chrome);
        }
Exemple #24
0
        //--------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="TextBoxAdorner"/> class.
        /// </summary>
        /// <param name="adornedElement">The element to bind the adorner to.</param>
        /// <exception cref="ArgumentNullException">
        /// Raised when adornedElement is <see langword="null"/>.
        /// </exception>
        public TextBoxAdorner(UIElement adornedElement)
            : base(adornedElement)
        {
            _visualChildren = new VisualCollection(this);

            _textBox = new TextBox();
            _textBox.LayoutUpdated += OnTextBoxLayoutUpdated;
            _textBox.TextChanged += OnTextBoxTextChanged;
            _visualChildren.Add(_textBox);
        }
        public ResizeRotateAdorner(ContentControl designerItem)
            : base(designerItem)
        {
            SnapsToDevicePixels = true;
            chrome = new ResizeRotateChrome();
            chrome.DataContext = designerItem;

            visuals = new VisualCollection(this);
            visuals.Add(this.chrome);
        }
Exemple #26
0
        public SelectionAdorner(UIElement adornedElement)
            : base(adornedElement)
        {
            _adornedelement = adornedElement;
            _canvas = new Canvas();
            //_canvas.Background = Brushes.Red;

            _visualCollection = new VisualCollection(_adornedelement);
            _visualCollection.Add(_canvas);
        }
        public RectangleSelectionAdorner(UIElement adornedElement)
            : base(adornedElement)
        {
            _adornedelement = adornedElement;
            _canvas = new Canvas();
            //_canvas.Background = new SolidColorBrush(Color.FromArgb(80,0,200,100));

            _visualCollection = new VisualCollection(_adornedelement);
            _visualCollection.Add(_canvas);
        }
Exemple #28
0
        public CroppingAdorner(UIElement adornedElement, Rect rcInit)
            : base(adornedElement)
        {
            if (adornedElement == null) throw new ArgumentNullException("adornedElement");

            if (rcInit == null || rcInit == Rect.Empty)
            {
                rcInit = new Rect(0, 0, adornedElement.RenderSize.Width, adornedElement.RenderSize.Height);
            }

            System.Diagnostics.Debug.WriteLine(String.Format("CroppingAdorner Width={0:N0}, Height={1:N0}", rcInit.Width, rcInit.Height));

            _vc = new VisualCollection(this);
            _prCropMask = new PuncturedRect();
            _prCropMask.IsHitTestVisible = false;
            _prCropMask.RectInterior = rcInit;
            _prCropMask.Fill = Fill;
            _vc.Add(_prCropMask);
            _cnvThumbs = new Canvas();
            _cnvThumbs.HorizontalAlignment = HorizontalAlignment.Stretch;
            _cnvThumbs.VerticalAlignment = VerticalAlignment.Stretch;

            _vc.Add(_cnvThumbs);
            BuildCorner(ref _crtTop, Cursors.SizeNS);
            BuildCorner(ref _crtBottom, Cursors.SizeNS);
            BuildCorner(ref _crtLeft, Cursors.SizeWE);
            BuildCorner(ref _crtRight, Cursors.SizeWE);
            BuildCorner(ref _crtTopLeft, Cursors.SizeNWSE);
            BuildCorner(ref _crtTopRight, Cursors.SizeNESW);
            BuildCorner(ref _crtBottomLeft, Cursors.SizeNESW);
            BuildCorner(ref _crtBottomRight, Cursors.SizeNWSE);

            // Add handlers for Cropping.
            _crtBottomLeft.DragDelta += new DragDeltaEventHandler(HandleBottomLeft);
            _crtBottomRight.DragDelta += new DragDeltaEventHandler(HandleBottomRight);
            _crtTopLeft.DragDelta += new DragDeltaEventHandler(HandleTopLeft);
            _crtTopRight.DragDelta += new DragDeltaEventHandler(HandleTopRight);
            _crtTop.DragDelta += new DragDeltaEventHandler(HandleTop);
            _crtBottom.DragDelta += new DragDeltaEventHandler(HandleBottom);
            _crtRight.DragDelta += new DragDeltaEventHandler(HandleRight);
            _crtLeft.DragDelta += new DragDeltaEventHandler(HandleLeft);

            //add eventhandler to drag and drop
            adornedElement.MouseLeftButtonDown += new MouseButtonEventHandler(HandleMouseLeftButtonDown);
            adornedElement.MouseMove += new MouseEventHandler(HandleMouseMove);
            adornedElement.MouseLeftButtonUp += new MouseButtonEventHandler(HandleMouseLeftButtonUp);

            // We have to keep the clipping interior withing the bounds of the adorned element
            // so we have to track it's size to guarantee that...
            FrameworkElement fel = (adornedElement as FrameworkElement);
            if (fel != null)
            {
                fel.SizeChanged += new SizeChangedEventHandler(AdornedElement_SizeChanged);
            }
        }
Exemple #29
0
        public WallAdorner(UIElement adornedElement)
            : base(adornedElement)
        {
            FrameworkPropertyMetadata meta = new FrameworkPropertyMetadata();
            meta.AffectsMeasure = true;

            element = (WallElement)adornedElement;

            _visualChildren = new VisualCollection(this);

            _startThumb = new Thumb();
            _startThumb.Height = 10;
            _startThumb.Width = 10;
            _startThumb.Background = Brushes.Yellow;

            _startThumb.DragDelta += new DragDeltaEventHandler(_startThumb_DragDelta);
            _startThumb.DragCompleted += new DragCompletedEventHandler(_startThumb_DragCompleted);
            _startThumb.DragStarted += new DragStartedEventHandler(_startThumb_DragStarted);

            _visualChildren.Add(_startThumb);

            _endThumb = new Thumb();
            _endThumb.Height = 10;
            _endThumb.Width = 10;
            _endThumb.Background = Brushes.Green;

            _endThumb.DragCompleted += new DragCompletedEventHandler(_endThumb_DragCompleted);

            _visualChildren.Add(_endThumb);

            previewLine = new Line();
            previewLine.Fill = Brushes.Purple;
            previewLine.Stroke = Brushes.Blue;
            previewLine.StrokeThickness = 3;
            previewLine.Visibility = Visibility.Hidden;
            previewLine.X1 = element.WallElementDetails.StartPoint.X;
            previewLine.Y1 = element.WallElementDetails.StartPoint.Y;
            previewLine.X2 = element.WallElementDetails.EndPoint.X;
            previewLine.Y2 = element.WallElementDetails.EndPoint.Y;

            _visualChildren.Add(previewLine);
        }
Exemple #30
0
 public SizeAdorner(ContentControl designerItem)
     : base(designerItem)
 {
     SnapsToDevicePixels = true;
     this._designerItem = designerItem;
     var angryRectangle = designerItem.DataContext as AnnoyingRectangle;
     chrome = new SizeChrome();
     chrome.DataContext = angryRectangle;
     visuals = new VisualCollection(this);
     visuals.Add(this.chrome);
 }
Exemple #31
0
        public ComposingAdorner(UIElement adornedElement) : base(adornedElement)
        {
            visualChildren = new VisualCollection(this);

            // ---
            rotateHandle            = new Thumb();
            rotateHandle.Cursor     = Cursors.Hand;
            rotateHandle.Width      = 20;
            rotateHandle.Height     = 20;
            rotateHandle.Background = Brushes.Blue;

            rotateHandle.DragDelta     += new DragDeltaEventHandler(rotateHandle_DragDelta);
            rotateHandle.DragCompleted += new DragCompletedEventHandler(rotateHandle_DragCompleted);

            // ---
            flipHandle            = new Thumb();
            flipHandle.Cursor     = Cursors.Hand;
            flipHandle.Width      = 20;
            flipHandle.Height     = 20;
            flipHandle.MinWidth   = 20;
            flipHandle.MinHeight  = 20;
            flipHandle.Background = Brushes.Orange;

            flipHandle.PreviewMouseDown += new MouseButtonEventHandler(flipHandle_MouseDown);

            // ---
            moveHandle            = new Thumb();
            moveHandle.Cursor     = Cursors.SizeAll;
            moveHandle.Width      = double.NaN;         // grande quanto tutta la foto
            moveHandle.Height     = double.NaN;         // grande quanto tutta la foto
            moveHandle.Background = Brushes.Transparent;
            moveHandle.Opacity    = 0;

            moveHandle.DragDelta            += new DragDeltaEventHandler(moveHandle_DragDelta);
            moveHandle.DragStarted          += new DragStartedEventHandler(moveHandle_DragStarted);
            moveHandle.DragCompleted        += new DragCompletedEventHandler(moveHandle_DragCompleted);
            moveHandle.MouseRightButtonDown += new MouseButtonEventHandler(moveHandle_PreviewMouseRightButtonDown);
            moveHandle.PreviewMouseWheel    += moveHandle_PreviewMouseWheel;

            // ---
            scaleHandle            = new Thumb();
            scaleHandle.Cursor     = Cursors.SizeNS;
            scaleHandle.Width      = 20;
            scaleHandle.Height     = 20;
            scaleHandle.MinWidth   = 20;
            scaleHandle.MinHeight  = 20;
            scaleHandle.Background = Brushes.Green;

            scaleHandle.DragDelta     += new DragDeltaEventHandler(scaleHandle_DragDelta);
            scaleHandle.DragCompleted += new DragCompletedEventHandler(scaleHandle_DragCompleted);

            // ---
            outline = new Path();


/* esempio
 *                      Style style = new Style();
 *                      Setter s1 = new Setter( Path.StrokeProperty, Brushes.Green );
 *                      style.Setters.Add( s1 );
 *                      outline.Style = style;
 */

            outline.Stroke          = Brushes.Blue;
            outline.StrokeThickness = 1;


/*  TODO : non funziona. Sistemare
 *                      DataTrigger dt = new DataTrigger();
 *
 *
 *                      Binding tagBinding = new Binding( "Tag" );
 *                      tagBinding.Source = adornedElement;
 * //			outline.SetBinding( Image.TagProperty, tagBinding );
 *
 *                      dt.Value = "!SELEZ!";
 *                      dt.Binding = tagBinding;
 *
 *                      Setter setter = new Setter( Path.StrokeProperty, Brushes.Yellow );
 *                      dt.Setters.Add( setter );
 *
 *                      // Creo lo stile per
 *                      Style style = new Style( outline.GetType() );
 *                      style.Triggers.Add( dt );
 *                      outline.Style = style;
 */
            // ---


            rotation      = new RotateTransform();
            translate     = new TranslateTransform();
            scaleManiglia = new ScaleTransform();
            scaleRotella  = new ScaleTransform();
            flip          = new MatrixTransform();

            transformGroup = adornedElement.RenderTransform as TransformGroup;
            if (transformGroup == null)
            {
                transformGroup = new TransformGroup();
            }

            visualChildren.Add(outline);
            visualChildren.Add(rotateHandle);
            visualChildren.Add(moveHandle);
            visualChildren.Add(scaleHandle);
            visualChildren.Add(flipHandle);
        }
Exemple #32
0
        public ResizeAdorner(UIElement adornedElement, CustomStroke customStroke, CustomInkCanvas actualCanvas)
            : base(adornedElement)
        {
            if (customStroke is LinkStroke)
            {
                WIDTH_LEGER = 1;
            }
            adornedStroke = customStroke;

            visualChildren = new VisualCollection(this);

            if (customStroke is ShapeStroke)
            {
                strokeBounds = customStroke.GetCustomBound();
            }
            else
            {
                strokeBounds = (customStroke as LinkStroke).GetStraightBounds();
            }

            resizePreview                 = new Path();
            resizePreview.Stroke          = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFBBBBBB"));
            resizePreview.StrokeThickness = 1;
            visualChildren.Add(resizePreview);

            this.customStroke = customStroke;
            canvas            = actualCanvas;

            Point center = customStroke.GetCenter();

            if (customStroke is ShapeStroke)
            {
                rotation = new RotateTransform((customStroke as ShapeStroke).shapeStyle.rotation, center.X, center.Y);
            }
            else
            {
                rotation = new RotateTransform(0, center.X, center.Y);
            }
            while (rotation.Angle < 0)
            {
                rotation.Angle += 360;
            }

            outerBoundPath                 = new Path();
            outerBoundPath.Stroke          = Brushes.Black;
            outerBoundPath.StrokeDashArray = new DoubleCollection {
                5, 2
            };
            outerBoundPath.StrokeThickness = 1;
            Rect rect = customStroke.GetCustomBound();

            rect.X             -= MARGIN;
            rect.Y             -= MARGIN;
            rect.Width         += MARGIN * 2;
            rect.Height        += MARGIN * 2;
            outerBoundPath.Data = new RectangleGeometry(rect, 0, 0, rotation);
            visualChildren.Add(outerBoundPath);

            moveThumb                 = new Thumb();
            moveThumb.Cursor          = Cursors.SizeAll;
            moveThumb.Height          = strokeBounds.Height + MARGIN * 2;
            moveThumb.Width           = strokeBounds.Width + MARGIN * 2;
            moveThumb.Background      = Brushes.Transparent;
            moveThumb.DragDelta      += new DragDeltaEventHandler(Move_DragDelta);
            moveThumb.DragCompleted  += new DragCompletedEventHandler(Move_DragCompleted);
            moveThumb.DragStarted    += new DragStartedEventHandler(All_DragStarted);
            moveThumb.PreviewMouseUp += new MouseButtonEventHandler(LeftMouseUp);
            TransformGroup transform = new TransformGroup();

            transform.Children.Add(new RotateTransform(rotation.Angle, moveThumb.Width / 2, moveThumb.Height / 2));
            transform.Children.Add(new TranslateTransform(-canvas.ActualWidth / 2 + strokeBounds.Width / 2 + strokeBounds.X,
                                                          -canvas.ActualHeight / 2 + strokeBounds.Height / 2 + strokeBounds.Y));
            moveThumb.RenderTransform = transform;


            visualChildren.Add(moveThumb);

            unitX = rotation.Value.Transform(unitX);
            unitY = rotation.Value.Transform(unitY);
            // RenderTransform = rotation;

            anchors = new List <Thumb>();
            anchors.Add(new Thumb());
            anchors.Add(new Thumb());
            anchors.Add(new Thumb());
            anchors.Add(new Thumb());
            anchors.Add(new Thumb());
            anchors.Add(new Thumb());
            anchors.Add(new Thumb());
            anchors.Add(new Thumb());

            int index = 0;

            foreach (Thumb anchor in anchors)
            {
                anchor.Width      = 8;
                anchor.Height     = 8;
                anchor.Background = new LinearGradientBrush((Color)ColorConverter.ConvertFromString("#FFc8d4ea"),
                                                            (Color)ColorConverter.ConvertFromString("#FF809dce"), 45);
                anchor.BorderBrush = Brushes.Black;
                if (rotation.Angle % 360 >= 360 - 45 / 2 || rotation.Angle % 360 <= 45 / 2)
                {
                    switch (index)
                    {
                    case 0:
                        anchor.DragDelta += new DragDeltaEventHandler(Top_DragDelta);
                        anchor.Cursor     = Cursors.SizeNS;
                        break;

                    case 1:
                        anchor.DragDelta += new DragDeltaEventHandler(Right_DragDelta);
                        anchor.Cursor     = Cursors.SizeWE;
                        break;

                    case 2:
                        anchor.DragDelta += new DragDeltaEventHandler(Bottom_DragDelta);
                        anchor.Cursor     = Cursors.SizeNS;
                        break;

                    case 3:
                        anchor.DragDelta += new DragDeltaEventHandler(Left_DragDelta);
                        anchor.Cursor     = Cursors.SizeWE;
                        break;

                    case 4:
                        anchor.DragDelta += new DragDeltaEventHandler(TopLeft_DragDelta);
                        anchor.Cursor     = Cursors.SizeNWSE;
                        break;

                    case 5:
                        anchor.DragDelta += new DragDeltaEventHandler(TopRight_DragDelta);
                        anchor.Cursor     = Cursors.SizeNESW;
                        break;

                    case 6:
                        anchor.DragDelta += new DragDeltaEventHandler(BottomLeft_DragDelta);
                        anchor.Cursor     = Cursors.SizeNESW;
                        break;

                    case 7:
                        anchor.DragDelta += new DragDeltaEventHandler(BottomRight_DragDelta);
                        anchor.Cursor     = Cursors.SizeNWSE;
                        break;

                    default:
                        break;
                    }
                }
                else if (rotation.Angle % 360 > 45 / 2 && rotation.Angle % 360 <= 90 - 45 / 2)
                {
                    switch (index)
                    {
                    case 0:
                        anchor.DragDelta += new DragDeltaEventHandler(Top_DragDelta);
                        anchor.Cursor     = Cursors.SizeNESW;
                        break;

                    case 1:
                        anchor.DragDelta += new DragDeltaEventHandler(Right_DragDelta);
                        anchor.Cursor     = Cursors.SizeNWSE;
                        break;

                    case 2:
                        anchor.DragDelta += new DragDeltaEventHandler(Bottom_DragDelta);
                        anchor.Cursor     = Cursors.SizeNESW;
                        break;

                    case 3:
                        anchor.DragDelta += new DragDeltaEventHandler(Left_DragDelta);
                        anchor.Cursor     = Cursors.SizeNWSE;
                        break;

                    case 4:
                        anchor.DragDelta += new DragDeltaEventHandler(TopLeft_DragDelta);
                        anchor.Cursor     = Cursors.SizeNS;
                        break;

                    case 5:
                        anchor.DragDelta += new DragDeltaEventHandler(TopRight_DragDelta);
                        anchor.Cursor     = Cursors.SizeWE;
                        break;

                    case 6:
                        anchor.DragDelta += new DragDeltaEventHandler(BottomLeft_DragDelta);
                        anchor.Cursor     = Cursors.SizeWE;
                        break;

                    case 7:
                        anchor.DragDelta += new DragDeltaEventHandler(BottomRight_DragDelta);
                        anchor.Cursor     = Cursors.SizeNS;
                        break;

                    default:
                        break;
                    }
                }
                else if (rotation.Angle % 360 > 90 - 45 / 2 && rotation.Angle % 360 <= 90 + 45 / 2)
                {
                    switch (index)
                    {
                    case 0:
                        anchor.DragDelta += new DragDeltaEventHandler(Top_DragDelta);
                        anchor.Cursor     = Cursors.SizeWE;
                        break;

                    case 1:
                        anchor.DragDelta += new DragDeltaEventHandler(Right_DragDelta);
                        anchor.Cursor     = Cursors.SizeNS;
                        break;

                    case 2:
                        anchor.DragDelta += new DragDeltaEventHandler(Bottom_DragDelta);
                        anchor.Cursor     = Cursors.SizeWE;
                        break;

                    case 3:
                        anchor.DragDelta += new DragDeltaEventHandler(Left_DragDelta);
                        anchor.Cursor     = Cursors.SizeNS;
                        break;

                    case 4:
                        anchor.DragDelta += new DragDeltaEventHandler(TopLeft_DragDelta);
                        anchor.Cursor     = Cursors.SizeNESW;
                        break;

                    case 5:
                        anchor.DragDelta += new DragDeltaEventHandler(TopRight_DragDelta);
                        anchor.Cursor     = Cursors.SizeNWSE;
                        break;

                    case 6:
                        anchor.DragDelta += new DragDeltaEventHandler(BottomLeft_DragDelta);
                        anchor.Cursor     = Cursors.SizeNWSE;
                        break;

                    case 7:
                        anchor.DragDelta += new DragDeltaEventHandler(BottomRight_DragDelta);
                        anchor.Cursor     = Cursors.SizeNESW;
                        break;

                    default:
                        break;
                    }
                }
                else if (rotation.Angle % 360 > 90 + 45 / 2 && rotation.Angle % 360 <= 135 + 45 / 2)
                {
                    switch (index)
                    {
                    case 0:
                        anchor.DragDelta += new DragDeltaEventHandler(Top_DragDelta);
                        anchor.Cursor     = Cursors.SizeNWSE;
                        break;

                    case 1:
                        anchor.DragDelta += new DragDeltaEventHandler(Right_DragDelta);
                        anchor.Cursor     = Cursors.SizeNESW;
                        break;

                    case 2:
                        anchor.DragDelta += new DragDeltaEventHandler(Bottom_DragDelta);
                        anchor.Cursor     = Cursors.SizeNWSE;
                        break;

                    case 3:
                        anchor.DragDelta += new DragDeltaEventHandler(Left_DragDelta);
                        anchor.Cursor     = Cursors.SizeNESW;
                        break;

                    case 4:
                        anchor.DragDelta += new DragDeltaEventHandler(TopLeft_DragDelta);
                        anchor.Cursor     = Cursors.SizeWE;
                        break;

                    case 5:
                        anchor.DragDelta += new DragDeltaEventHandler(TopRight_DragDelta);
                        anchor.Cursor     = Cursors.SizeNS;
                        break;

                    case 6:
                        anchor.DragDelta += new DragDeltaEventHandler(BottomLeft_DragDelta);
                        anchor.Cursor     = Cursors.SizeNS;
                        break;

                    case 7:
                        anchor.DragDelta += new DragDeltaEventHandler(BottomRight_DragDelta);
                        anchor.Cursor     = Cursors.SizeWE;
                        break;

                    default:
                        break;
                    }
                }
                else if (rotation.Angle % 360 > 180 - 45 / 2 && rotation.Angle % 360 <= 180 + 45 / 2)
                {
                    switch (index)
                    {
                    case 0:
                        anchor.DragDelta += new DragDeltaEventHandler(Top_DragDelta);
                        anchor.Cursor     = Cursors.SizeNS;
                        break;

                    case 1:
                        anchor.DragDelta += new DragDeltaEventHandler(Right_DragDelta);
                        anchor.Cursor     = Cursors.SizeWE;
                        break;

                    case 2:
                        anchor.DragDelta += new DragDeltaEventHandler(Bottom_DragDelta);
                        anchor.Cursor     = Cursors.SizeNS;
                        break;

                    case 3:
                        anchor.DragDelta += new DragDeltaEventHandler(Left_DragDelta);
                        anchor.Cursor     = Cursors.SizeWE;
                        break;

                    case 4:
                        anchor.DragDelta += new DragDeltaEventHandler(TopLeft_DragDelta);
                        anchor.Cursor     = Cursors.SizeNWSE;
                        break;

                    case 5:
                        anchor.DragDelta += new DragDeltaEventHandler(TopRight_DragDelta);
                        anchor.Cursor     = Cursors.SizeNESW;
                        break;

                    case 6:
                        anchor.DragDelta += new DragDeltaEventHandler(BottomLeft_DragDelta);
                        anchor.Cursor     = Cursors.SizeNESW;
                        break;

                    case 7:
                        anchor.DragDelta += new DragDeltaEventHandler(BottomRight_DragDelta);
                        anchor.Cursor     = Cursors.SizeNWSE;
                        break;

                    default:
                        break;
                    }
                }
                else if (rotation.Angle % 360 > 225 - 45 / 2 && rotation.Angle % 360 <= 225 + 45 / 2)
                {
                    switch (index)
                    {
                    case 0:
                        anchor.DragDelta += new DragDeltaEventHandler(Top_DragDelta);
                        anchor.Cursor     = Cursors.SizeNESW;
                        break;

                    case 1:
                        anchor.DragDelta += new DragDeltaEventHandler(Right_DragDelta);
                        anchor.Cursor     = Cursors.SizeNWSE;
                        break;

                    case 2:
                        anchor.DragDelta += new DragDeltaEventHandler(Bottom_DragDelta);
                        anchor.Cursor     = Cursors.SizeNESW;
                        break;

                    case 3:
                        anchor.DragDelta += new DragDeltaEventHandler(Left_DragDelta);
                        anchor.Cursor     = Cursors.SizeNWSE;
                        break;

                    case 4:
                        anchor.DragDelta += new DragDeltaEventHandler(TopLeft_DragDelta);
                        anchor.Cursor     = Cursors.SizeNS;
                        break;

                    case 5:
                        anchor.DragDelta += new DragDeltaEventHandler(TopRight_DragDelta);
                        anchor.Cursor     = Cursors.SizeWE;
                        break;

                    case 6:
                        anchor.DragDelta += new DragDeltaEventHandler(BottomLeft_DragDelta);
                        anchor.Cursor     = Cursors.SizeWE;
                        break;

                    case 7:
                        anchor.DragDelta += new DragDeltaEventHandler(BottomRight_DragDelta);
                        anchor.Cursor     = Cursors.SizeNS;
                        break;

                    default:
                        break;
                    }
                }
                else if (rotation.Angle % 360 > 270 - 45 / 2 && rotation.Angle % 360 <= 270 + 45 / 2)
                {
                    switch (index)
                    {
                    case 0:
                        anchor.DragDelta += new DragDeltaEventHandler(Top_DragDelta);
                        anchor.Cursor     = Cursors.SizeWE;
                        break;

                    case 1:
                        anchor.DragDelta += new DragDeltaEventHandler(Right_DragDelta);
                        anchor.Cursor     = Cursors.SizeNS;
                        break;

                    case 2:
                        anchor.DragDelta += new DragDeltaEventHandler(Bottom_DragDelta);
                        anchor.Cursor     = Cursors.SizeWE;
                        break;

                    case 3:
                        anchor.DragDelta += new DragDeltaEventHandler(Left_DragDelta);
                        anchor.Cursor     = Cursors.SizeNS;
                        break;

                    case 4:
                        anchor.DragDelta += new DragDeltaEventHandler(TopLeft_DragDelta);
                        anchor.Cursor     = Cursors.SizeNESW;
                        break;

                    case 5:
                        anchor.DragDelta += new DragDeltaEventHandler(TopRight_DragDelta);
                        anchor.Cursor     = Cursors.SizeNWSE;
                        break;

                    case 6:
                        anchor.DragDelta += new DragDeltaEventHandler(BottomLeft_DragDelta);
                        anchor.Cursor     = Cursors.SizeNWSE;
                        break;

                    case 7:
                        anchor.DragDelta += new DragDeltaEventHandler(BottomRight_DragDelta);
                        anchor.Cursor     = Cursors.SizeNESW;
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    switch (index)
                    {
                    case 0:
                        anchor.DragDelta += new DragDeltaEventHandler(Top_DragDelta);
                        anchor.Cursor     = Cursors.SizeNWSE;
                        break;

                    case 1:
                        anchor.DragDelta += new DragDeltaEventHandler(Right_DragDelta);
                        anchor.Cursor     = Cursors.SizeNESW;
                        break;

                    case 2:
                        anchor.DragDelta += new DragDeltaEventHandler(Bottom_DragDelta);
                        anchor.Cursor     = Cursors.SizeNWSE;
                        break;

                    case 3:
                        anchor.DragDelta += new DragDeltaEventHandler(Left_DragDelta);
                        anchor.Cursor     = Cursors.SizeNESW;
                        break;

                    case 4:
                        anchor.DragDelta += new DragDeltaEventHandler(TopLeft_DragDelta);
                        anchor.Cursor     = Cursors.SizeWE;
                        break;

                    case 5:
                        anchor.DragDelta += new DragDeltaEventHandler(TopRight_DragDelta);
                        anchor.Cursor     = Cursors.SizeNS;
                        break;

                    case 6:
                        anchor.DragDelta += new DragDeltaEventHandler(BottomLeft_DragDelta);
                        anchor.Cursor     = Cursors.SizeNS;
                        break;

                    case 7:
                        anchor.DragDelta += new DragDeltaEventHandler(BottomRight_DragDelta);
                        anchor.Cursor     = Cursors.SizeWE;
                        break;

                    default:
                        break;
                    }
                }
                anchor.DragStarted   += new DragStartedEventHandler(All_DragStarted);
                anchor.DragCompleted += new DragCompletedEventHandler(All_DragCompleted);
                if (!(customStroke is LinkStroke) || !(customStroke as LinkStroke).isAttached())
                {
                    visualChildren.Add(anchor);
                }
                double xOffset = 0;
                double yOffset = 0;
                switch (index)
                {
                case 0:     //Top
                    xOffset = strokeBounds.Width / 2;
                    yOffset = -MARGIN;
                    break;

                case 1:     //Right
                    xOffset = strokeBounds.Width + MARGIN;
                    yOffset = strokeBounds.Height / 2;
                    break;

                case 2:     //Bottom
                    xOffset = strokeBounds.Width / 2;
                    yOffset = strokeBounds.Height + MARGIN;
                    break;

                case 3:     //Left
                    xOffset = -MARGIN;
                    yOffset = strokeBounds.Height / 2;
                    break;

                case 4:     //TopLeft
                    xOffset = -MARGIN;
                    yOffset = -MARGIN;
                    break;

                case 5:     //TopRight
                    xOffset = strokeBounds.Width + MARGIN;
                    yOffset = -MARGIN;
                    break;

                case 6:     //BottomLeft
                    xOffset = -MARGIN;
                    yOffset = strokeBounds.Height + MARGIN;
                    break;

                case 7:     //BottomRight
                    xOffset = strokeBounds.Width + MARGIN;
                    yOffset = strokeBounds.Height + MARGIN;
                    break;

                default:
                    break;
                }
                ArrangeAnchor(anchor, xOffset, yOffset);
                index++;
            }

            rotationPreview = rotation.Clone();
        }