Example #1
0
        public static SelectionAdorner Create(UIElement element)
        {
            var result = new SelectionAdorner(element);

            AdornerLayer.GetAdornerLayer(element).Add(result);
            return(result);
        }
Example #2
0
        protected override void OnMouseUp(MouseButtonEventArgs e)
        {
            //if (!Keyboard.IsKeyDown(Key.LeftCtrl))
            //{
            //    foreach (var particle in model.Particles)
            //        particle.Fixed = false;
            //}
            switch (toolKind)
            {
            case ToolKind.MoveSelectedParticles:
                foreach (var particle in model.Particles)
                {
                    var drawData = particle.Tag as DrawData;
                    if (drawData.Selected && !drawData.Pinned)
                    {
                        particle.Fixed = false;
                    }
                }
                break;

            case ToolKind.ScrollView:
                break;

            case ToolKind.SelectRectangle:
                var r = new Rect(mouseDownPosition, e.GetPosition(this));
                foreach (var particle in model.Particles)
                {
                    if (r.Contains(transform.ToScreen(particle.Position)))
                    {
                        (particle.Tag as DrawData).Selected = true;
                    }
                }
                selectionAdorner.Destroy();
                selectionAdorner = null;
                break;
            }
            InvalidateVisual();
            toolKind = ToolKind.None;
            ReleaseMouseCapture();
        }
Example #3
0
 protected override void OnMouseDown(MouseButtonEventArgs e)
 {
     switch (e.ChangedButton)
     {
     case MouseButton.Left:
         Point p = e.GetPosition(this);
         mouseDownPosition = p;
         var hitParticle = ParticleAtPoint(p);
         if (Keyboard.IsKeyDown(Key.LeftCtrl))
         {
             if (hitParticle == null)
             {
                 var newParticle = new Particle(model.Dimension);
                 newParticle.Position  = transform.ToWorld(mouseDownPosition);
                 newParticle.FillColor = getRandomColor();
                 model.AddParticle(newParticle);
                 InvalidateVisual();
             }
             else
             {
                 model.RemoveParticle(hitParticle);
                 InvalidateVisual();
             }
         }
         else if (Keyboard.IsKeyDown(Key.LeftShift))
         {
             if (hitParticle != null)
             {
                 toolKind = ToolKind.None;
                 var drawData = hitParticle.Tag as DrawData;
                 drawData.Selected = !drawData.Selected;
                 InvalidateVisual();
             }
             else
             {
                 toolKind              = ToolKind.SelectRectangle;
                 selectionAdorner      = SelectionAdorner.Create(this);
                 selectionAdorner.From = mouseDownPosition;
                 selectionAdorner.To   = mouseDownPosition;
             }
         }
         else
         {
             if (hitParticle != null)
             {
                 toolKind = ToolKind.MoveSelectedParticles;
                 var drawData = hitParticle.Tag as DrawData;
                 if (drawData.Selected)
                 {
                     foreach (var particle in model.Particles)
                     {
                         DrawData dd = particle.Tag as DrawData;
                         if (dd.Selected)
                         {
                             particle.Fixed = true;
                         }
                     }
                 }
                 else
                 {
                     foreach (var particle in model.Particles)
                     {
                         (particle.Tag as DrawData).Selected = false;
                     }
                     (hitParticle.Tag as DrawData).Selected = true;
                     hitParticle.Fixed = true;
                 }
                 InvalidateVisual();
             }
             else
             {
                 toolKind = ToolKind.ScrollView;
             }
         }
         if (toolKind != ToolKind.None)
         {
             CaptureMouse();
         }
         break;
     }
 }