예제 #1
0
        public override bool Think(List <Touch> allTouches, ref Touch stylus, ref Touch mouse, int screenWidth, int screenHeight)
        {
            if (IsMouseDown())
            {
                return(false);
            }
            bool refresh = false;

            PointF?cursorPos = null;
            uint   pointerId = 0;

            if (stylus != null)
            {
                cursorPos = new PointF(stylus.X, stylus.Y); pointerId = stylus.Id;
            }
            else if (mouse != null)
            {
                cursorPos = new PointF(mouse.X, mouse.Y); pointerId = mouse.Id;
            }
            else if (allTouches.Count > 0)
            {
                cursorPos = new PointF(allTouches[0].X, allTouches[0].Y); pointerId = allTouches[0].Id;
            }

            if (cursorPos.HasValue && Collides(cursorPos.Value.X, cursorPos.Value.Y, screenWidth, screenHeight))
            {
                currentTouchId = pointerId;
            }

            if (currentTouchId != uint.MaxValue)
            {
                Touch t = null;
                t = stylus | mouse;
                if (t == null)
                {
                    foreach (Touch touch in allTouches)
                    {
                        if (touch.Id == currentTouchId)
                        {
                            t = touch;
                            break;
                        }
                    }
                }

                if (t != null)
                {
                    float _x = this.x;
                    float _y = this.y;
                    control.GetTransform().Transform(ref _x, ref _y);
                    float dx  = t.X - _x;
                    float dy  = t.Y - _y;
                    float ang = (float)Math.Atan2(dy, dx);

                    if (float.IsNaN(angleStart))
                    {
                        angleStart = ang;
                    }
                    else
                    {
                        float rel = ang - angleStart;
                        angleStart = ang;
                        Matrix3x3 mat = new Matrix3x3();
                        ringRot -= rel;
                        mat.TransformRotateAt(-rel, this.x, this.y);
                        page.TransformCurrentObjects(mat);
                        Console.WriteLine(mat);
                        control.RefreshPage();
                    }
                }
                else
                {
                    currentTouchId = uint.MaxValue;
                    angleStart     = float.NaN;
                    HistoryManager.StoreState(page);
                }
                stylus = null;
                mouse  = null;
                allTouches.Clear();
                refresh = true;
            }

            MouseDown = currentTouchId != uint.MaxValue;
            if (Close)
            {
                refresh = true;
            }
            return(refresh);
        }
예제 #2
0
        public override bool Think(List <Touch> allTouches, ref Touch stylus, ref Touch mouse, int screenWidth, int screenHeight)
        {
            if (IsMouseDown())
            {
                return(false);
            }
            if (page.LineCount != selectedLines.Length)
            {
                Close = true;
            }
            else
            {
                for (int i = 0; i < page.LineCount; i++)
                {
                    if (selectedLines[i] != page.GetLine(i).Selected)
                    {
                        Close = true;
                    }
                }
            }
            if (control.Page != page)
            {
                Close = true;
            }

            bool refresh = false;

            PointF?cursorPos = null;
            uint   pointerId = 0;

            if (stylus != null)
            {
                cursorPos = new PointF(stylus.X, stylus.Y); pointerId = stylus.Id;
            }
            else if (mouse != null)
            {
                cursorPos = new PointF(mouse.X, mouse.Y); pointerId = mouse.Id;
            }
            else if (allTouches.Count > 0)
            {
                cursorPos = new PointF(allTouches[0].X, allTouches[0].Y); pointerId = allTouches[0].Id;
            }

            if (cursorPos.HasValue && Collides(cursorPos.Value.X, cursorPos.Value.Y, screenWidth, screenHeight))
            {
                currentTouchId = pointerId;
            }

            if (currentTouchId != uint.MaxValue)
            {
                Touch t = null;
                t = stylus | mouse;
                if (t == null)
                {
                    foreach (Touch touch in allTouches)
                    {
                        if (touch.Id == currentTouchId)
                        {
                            t = touch;
                            break;
                        }
                    }
                }

                if (t != null)
                {
                    int ox = this.x;
                    int oy = this.y;
                    this.x = t.X;
                    this.y = t.Y;
                    control.GetTransform().GetInverse().Transform(ref this.x, ref this.y);
                    page.TransformCurrentObjects(Matrix3x3.Translation(x - ox, y - oy));
                    foreach (Transformer trans in this.transformer)
                    {
                        trans.SetPosition(x, y);
                    }
                    control.RefreshPage();
                }
                else
                {
                    currentTouchId = uint.MaxValue;
                    HistoryManager.StoreState(page);
                }
                stylus = null;
                mouse  = null;
                allTouches.Clear();
                refresh = true;
            }

            if (Close)
            {
                foreach (Transformer trans in this.transformer)
                {
                    trans.Close = true;
                }
            }
            if (firstcall)
            {
                firstcall = false;
                refresh   = true;
            }

            MouseDown = currentTouchId != uint.MaxValue;
            return(refresh);
        }