Beispiel #1
0
        public int Interact(PointingDevice pd)
        {
            if (pointingDevice == null)
            {
                if (pd.LeftButton == ButtonState.Pressed && pd.oldLeftButton == ButtonState.Released)
                {
                    if (!IsClosed)
                    {
                        state = (int)StrokeState.NOTHING;
                        return state;
                    }
                    Vector2 ndist = Vector2.One * float.MaxValue;
                    for (int k = 0, klen = Strokes.Count - 1; k < klen; ++k)
                    {
                        Vector2 dist = Strokes[k] - pd.GamePosition;
                        if (dist.LengthSquared() < ndist.LengthSquared())
                        {
                            //dragSIndexes_[i][j] = k;
                            enlargeIndex = k;
                            ndist = dist;
                            //s[j].BeginMove();
                        }
                    }
                    if (ndist.Length() > dragTh_ && IsInternal(pd.GamePosition))
                    {
                        BeginMove();
                        state = (int)Stroke.StrokeState.DragStroke;
                        pointingDevice = pd;
                    }
                    else if (ndist.Length() <= dragTh_)
                    {
                        state = (int)Stroke.StrokeState.ExpansionStroke;
                        pointingDevice = pd;
                    }
                }
            }
            else if (pointingDevice == pd)
            {
                // 左键移动锚点
                if (pd.LeftButton == ButtonState.Pressed)
                {
                    Vector2 mov = pd.GamePosition - pd.OldGamePosition;
                    if (state == (int)Stroke.StrokeState.DragStroke)
                    {

                        MoveStroke(mov);

                    }
                    else if (state == (int)Stroke.StrokeState.ExpansionStroke)
                    {
                        EnlargeStroke(enlargeIndex, mov);

                    }
                }
                else if (pd.LeftButton == ButtonState.Released && pd.oldLeftButton == ButtonState.Pressed)
                {
                    // 拖动结束
                    if (state == (int)Stroke.StrokeState.DragStroke)
                        EndMove();
                    pointingDevice = null;
                    state = (int)Stroke.StrokeState.NOTHING;
                }
            }
            return state;
        }
Beispiel #2
0
 public bool touchDelete(PointingDevice pd)
 {
     Vector2 ndist = Vector2.One * float.MaxValue;
     for (int k = 0, klen = Strokes.Count - 1; k < klen; ++k)
     {
         Vector2 dist = Strokes[k] - pd.GamePosition;
         if (dist.LengthSquared() < ndist.LengthSquared())
         {
             enlargeIndex = k;
             ndist = dist;
         }
     }
     if (ndist.Length() <= dragTh_)
     {
         return true;
     }
     return false;
 }
Beispiel #3
0
 public void _touchHandler_TouchDown(object sender, TouchEventArgs e)
 {
     if (touchMap.ContainsKey(e.Id))
     {
         return;
     }
     PointingDevice p = new PointingDevice(e.Id, new Vector2(e.Location.X, e.Location.Y));
     touchMap[e.Id] = p;
     p.Type = PointingDevice.DeviceType.Touch;
     pdCollection.add(p);
     p.LeftButton = Microsoft.Xna.Framework.Input.ButtonState.Pressed;
     p.oldLeftButton = Microsoft.Xna.Framework.Input.ButtonState.Released;
     p.Position = new Vector2(e.Location.X, e.Location.Y);
     //Debug.WriteLine(p.Position);
 }
 public bool underMouse(PointingDevice pd)
 {
     foreach (var tb in StrokeBox.Values)
     {
         if (tb != null && tb.boundingBox.Contains(pd.GamePosition) == ContainmentType.Contains && tb.IsShown)
         {
             return true;
         }
     }
     foreach (var s in StrokeBox.Keys)
     {
         var box = s.boundingbox;
         if (box.Contains(pd.GamePosition) == ContainmentType.Contains)
         {
             if (pd.oldLeftButton == Microsoft.Xna.Framework.Input.ButtonState.Released && pd.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                 StrokeBox[s].showAgain(s.Strokes[s.Strokes.Count - 2]);
             return true;
         }
     }
     return false;
 }
        private void mousePhoto(PointingDevice pd)
        {
            //Console.WriteLine(pd.MiddleValue);
            //if (mousePhotoConnection.ContainsKey(pd.Header))
                //Debug.WriteLine(mousePhotoConnection[pd.Header].FileName);
            if (pd.MiddleValue != 0 && mousePhotoConnection.ContainsKey(pd.Header))
            {
                Photo photo = mousePhotoConnection[pd.Header];
                if (photo.BoundingBoxDisplay.Contains(pd.GamePosition) == ContainmentType.Contains)
                {
                    photo.KeepGazed();
                    photo.Position = photo.PositionDisplay;
                    photo.Scale *= 1f + 0.001f * (pd.MiddleValue);
                    pd.MiddleValue = 0;
                }
                else
                {
                    photo.SetDisplayTarget();
                    mousePhotoConnection.Remove(pd.Header);
                }

            }

            if (pd.LeftButton == ButtonState.Released && pd.oldLeftButton == ButtonState.Pressed)
            {
                //Console.WriteLine("ds");
                if (mousePhotoConnection.ContainsKey(pd.Header))
                {
                    //Console.WriteLine(pd.oldLeftButton + i++);
                    Photo photo = mousePhotoConnection[pd.Header];
                    photo.underMouse = true;
                    photo.PositionDisplay = pd.GamePosition + photo.StartDragPosition * photo.ScaleDisplay;
                    photo.Position = photo.PositionDisplay;
                    //Console.WriteLine(photo.Position);
                    photo.SetDisplayTarget();
                    mousePhotoConnection.Remove(pd.Header);
                }
            }
            else if (pd.LeftButton == ButtonState.Pressed && mousePhotoConnection.ContainsKey(pd.Header))
            {
                Photo photo = mousePhotoConnection[pd.Header];

                if (pd.oldLeftButton == ButtonState.Released)
                {
                    photo.ClickedPoint = photo.BoundingBoxDisplay.Offset(pd.GamePosition);
                    photo.StartDragPosition = (photo.PositionDisplay - pd.GamePosition) / photo.ScaleDisplay;
                }
                photo.underMouse = true;
                photo.IsClicked = true;
                photo.PositionDisplay = pd.GamePosition + photo.StartDragPosition * photo.ScaleDisplay;
                photo.Position = photo.PositionDisplay;
                //Console.WriteLine(photo.Position);
                photo.SetDisplayTarget();
                if(pd.Type == PointingDevice.DeviceType.Touch)
                    photo.touchCount = 1;
            }

            //指点到图像上并拽动鼠标
            else
            foreach (Photo photo in photos)
            {
                if (photo.BoundingBoxDisplay.Contains(pd.GamePosition) == ContainmentType.Contains)
                {
                    photo.underMouse = true;
                    photo.Position = photo.PositionDisplay;
                    //Console.WriteLine(pd.GamePosition - photo.Position) ;
                    //Console.WriteLine(photo.IsGazeds);
                    if (pd.LeftButton == ButtonState.Pressed && pd.oldLeftButton == ButtonState.Released)
                    {
                        photo.KeepGazed();
                        photo.IsClicked = true;
                        photo.ClickedPoint = photo.BoundingBoxDisplay.Offset(pd.GamePosition);
                        photo.StartDragPosition = (photo.PositionDisplay - pd.GamePosition)/photo.ScaleDisplay;
                        //Console.WriteLine(photo.StartDragPosition);
                        //photo.Position = photo.PositionDisplay;
                        //photo.tagClickedCheck(pd.GamePosition);
                            //systemState.SwapColor();
                        mousePhotoConnection[pd.Header] = photo;
                        if (pd.Type == PointingDevice.DeviceType.Touch)
                        {
                            photo.touchCount = 1;
                        }
                    }
                    else if (pd.MiddleValue != 0)
                    {
                        photo.KeepGazed();
                        //Console.WriteLine(pd.MiddleValue);
                        //photo.Position = photo.PositionDisplay;
                        photo.Scale *= 1f + 0.001f * (pd.MiddleValue);
                        pd.MiddleValue = 0;
                        mousePhotoConnection[pd.Header] = photo;
                    }
                    break;
                }

            }
        }
 void moveLine(PointingDevice pd)
 {
     if (pd.RightButton == ButtonState.Pressed && pd.oldRightButton == ButtonState.Released && keyboard.ctrlKey)
     {
         pd.state = (int)PointingDevice.State.Cross;
         List<Stroke> s = strokeGroup.strokeList;
         for (int j = 0; j < s.Count; ++j)
         {
             if (s[j].IsInternal(pd.GamePosition))
             {
                 strokeGroup.remove(s[j]);
             }
         }
         return;
     }
     if (pd.RightButton == ButtonState.Released && pd.oldRightButton == ButtonState.Pressed)
     {
         pd.state = (int)PointingDevice.State.Curosr;
         return;
     }
     if (strokeMouse.ContainsKey(pd.Header))
     {
         if (strokeMouse[pd.Header].Interact(pd) == (int)Stroke.StrokeState.NOTHING)
         {
             strokeMouse.Remove(pd.Header);
         }
     }
     else
     {
         List<Stroke> s = strokeGroup.strokeList;
         for (int j = 0; j < s.Count; ++j)
         {
             if (s[j].Interact(pd) != (int)Stroke.StrokeState.NOTHING)
             {
                 strokeMouse[pd.Header] = s[j];
                 break;
             }
         }
     }
 }
        private void mouseBar(PointingDevice pd)
        {
            if (pd.LeftButton == ButtonState.Pressed)
            {
                Vector2 pos = pd.GamePosition;
                Vector2 posOld = pd.OldGamePosition;
                Vector2 v = pos - posOld;

                if (pd.oldLeftButton == ButtonState.Released)
                {
                    if (sBar.LeftContains(pos) == ContainmentType.Contains)
                    {
                        barDrag[pd.Header] = ScrollBar.DragRegion.LEFT;

                    }
                    else if (sBar.RightContains(pos) == ContainmentType.Contains)
                    {
                        barDrag[pd.Header] = ScrollBar.DragRegion.RIGHT;

                    }
                    else if (sBar.CenterContains(pos) == ContainmentType.Contains)
                    {
                        barDrag[pd.Header] = ScrollBar.DragRegion.CENTER;

                    }
                    else
                    {
                        barDrag[pd.Header] = ScrollBar.DragRegion.NONE;
                    }
                }
                else
                {
                    if(barDrag.ContainsKey(pd.Header))
                    {
                        ScrollBar.DragRegion region = barDrag[pd.Header];
                        if(region == ScrollBar.DragRegion.LEFT)
                            sBar.MoveBar((int)pos.X, sBar.Max);
                        else if(region == ScrollBar.DragRegion.RIGHT)
                            sBar.MoveBar(sBar.Min, (int)pos.X);
                        else if (region == ScrollBar.DragRegion.CENTER)
                        {
                            if ((pos.X > sBar.Min && pos.X < sBar.Max) || (posOld.X > sBar.Min && posOld.X < sBar.Max))
                            {
                                sBar.MoveBar(sBar.Min + (int)v.X, sBar.Max + (int)v.X);
                            }
                        }
                    }
                }

            }
            else barDrag[pd.Header] = ScrollBar.DragRegion.NONE;
        }
        bool mouseOnMenu(PointingDevice pd)
        {
            // icon, piemenu, controlpanel, tagform 这些, 鼠标是否在其上
            foreach (Icon icon in dock.Icons)
            {
                icon.tooltip.IsDel = true;
                if (icon.BoundingBox.Contains(pd.GamePosition) == ContainmentType.Contains)
                {
                    iconMouse(icon, pd);
                    return true;
                }
            }

            if (systemState.curState == SystemState.ATTRACTOR_TIME)
            {
                if ((barDrag.ContainsKey(pd.Header) && barDrag[pd.Header] != ScrollBar.DragRegion.NONE) || sBar.BoundingBox.Contains(pd.GamePosition) == ContainmentType.Contains)
                {
                    mouseBar(pd);
                    return true;
                }
            }

            if(strokeGroup.underMouse(pd))
                return true;
            //foreach (var tb in ftBoxes)
            //{
            //    if (tb.boundingBox.Contains(pd.GamePosition) == ContainmentType.Contains)
            //    {
            //        return true;
            //    }
            //}
            return false;
        }
        void iconMouse(Icon icon, PointingDevice pd)
        {
            //show tips
            icon.tooltip.IsDel = false;

            if (pd.LeftButton == ButtonState.Pressed && pd.oldLeftButton == ButtonState.Released)
            {
                if (icon.Attractor == SystemState.ATTRACTOR_BOUND)
                {
                    systemState.SwapBound();
                    icon.IsOn = !icon.IsOn;
                }
                else if (icon.Attractor == SystemState.ATTRACTOR_TIME)
                {
                    if (systemState.curState == SystemState.ATTRACTOR_GEOGRAPH)
                    {
                        systemState.SwapGeograph();
                        systemState.SwapScaleUp();
                        foreach (Icon ic in dock.Icons)
                        {
                            if (ic.Attractor == SystemState.ATTRACTOR_GEOGRAPH)
                            {
                                ic.IsOn = !ic.IsOn;
                                break;
                            }
                        }

                    }
                    systemState.SwapTime();
                    icon.IsOn = !icon.IsOn;
                }
                else if (icon.Attractor == SystemState.ATTRACTOR_GEOGRAPH)
                {
                    if (systemState.curState == SystemState.ATTRACTOR_TIME)
                    {
                        systemState.SwapTime();
                        foreach (Icon ic in dock.Icons)
                        {
                            if (ic.Attractor == SystemState.ATTRACTOR_TIME)
                            {
                                ic.IsOn = !ic.IsOn;
                                break;
                            }
                        }
                    }
                    systemState.SwapGeograph();
                    systemState.SwapScaleUp();
                    icon.IsOn = !icon.IsOn;
                }
                else if (icon.Attractor == SystemState.FILE_OPEN)
                {
                    FileOpenDialog dialog = new FileOpenDialog();
                    if (dialog.fileNames.Count > 0)
                    {
                        //photos_.Clear();
                        createPhoto.createPhoto(dialog.fileNames);
                        //foreach(Photo p in createPhoto.photos)
                        //    photos[p.ID] = p;
                        photos = createPhoto.photos;
                        strokeGroup.photos = photos;
                        photoDisplayManager.PhotosToShow(photos);
                    }
                    //icon.IsOn = !icon.IsOn;

                }
            }
        }
        void drawLine(PointingDevice pd)
        {
            if (pd.RightButton == ButtonState.Pressed && pd.oldRightButton == ButtonState.Released && keyboard.ctrlKey)
            {
                pd.state = (int)PointingDevice.State.Cross;
                List<Stroke> s = strokeGroup.strokeList;
                for (int j = 0; j < s.Count; ++j)
                {
                    if (s[j].IsInternal(pd.GamePosition))
                    {
                        strokeGroup.remove(s[j]);
                    }
                }
                return;
            }
            if (pd.RightButton == ButtonState.Released && pd.oldRightButton == ButtonState.Pressed)
            {
                pd.state = (int)PointingDevice.State.Curosr;
                return;

            }
            if (pd.LeftButton == ButtonState.Pressed && pd.oldLeftButton == ButtonState.Released)
            {
                // 左键按下后,添加stroke
                if (strokeUnderDrawing.ContainsKey(pd))
                {
                    strokeGroup.remove(strokeUnderDrawing[pd]);
                    strokeUnderDrawing.Remove(pd);
                }
                strokeUnderDrawing[pd] = strokeGroup.createStroke(pd.GamePosition);
                //Console.WriteLine("draw start!");
            }
            else if (pd.LeftButton == ButtonState.Pressed && strokeUnderDrawing.ContainsKey(pd))
            {
                Stroke s = strokeUnderDrawing[pd];
                if ((s.Last - pd.GamePosition).Length() > Stroke.StrokeTh)
                {
                    // drag and draw
                    s.AddStroke(pd.GamePosition);
                }
            }

            else if(pd.LeftButton == ButtonState.Released && pd.oldLeftButton == ButtonState.Pressed)
            {
                if (strokeUnderDrawing.ContainsKey(pd))
                {
                    Stroke s = strokeUnderDrawing[pd];
                    if (!s.IsClosed)
                    {
                        if (s.Strokes.Count > 2)
                        {
                            // 如果大于或等于3个点
                            s.End();
                            //create text box
                            strokeGroup.createTextBox(pd.GamePosition, s);
                        }
                        else
                        {
                            // 必须少于2个锚点
                            strokeGroup.remove(strokeUnderDrawing[pd]);
                        }
                    }
                    strokeUnderDrawing.Remove(pd);
                }

            }
        }
 private void deletePhoto(PointingDevice pd)
 {
     if (pd.LeftButton == ButtonState.Pressed && pd.oldLeftButton == ButtonState.Released)
     {
         foreach (Photo p in photos)
         {
             if (p.boundingBox_.Contains(pd.GamePosition) == ContainmentType.Contains)
             {
                 p.IsDel = true;
                 break;
             }
         }
     }
     if (pd.Type == PointingDevice.DeviceType.Touch)
     {
         List<Stroke> s = strokeGroup.strokeList;
         for (int j = 0; j < s.Count; ++j)
         {
             if (s[j].touchDelete(pd))
             {
                 pd.state = (int)PointingDevice.State.Cross;
                 strokeGroup.remove(s[j]);
             }
             else
             {
                 pd.state = (int)PointingDevice.State.Curosr;
             }
         }
     }
 }
 public void add(PointingDevice pd)
 {
     pointingDevices.Add(pd);
     //mouseMenu[pd] = new PieMenu();
 }
        public bool remove(PointingDevice pd)
        {
            if (pd.Type == PointingDevice.DeviceType.Touch)
            {
                PieMenu pm = pd.getPieMenu();
                if (pm.IsShown)
                {
                    pd.RightButton = Microsoft.Xna.Framework.Input.ButtonState.Released;
                    return false;
                }
            }

            pointingDevices.Remove(pd);
            return true;
        }