Пример #1
0
        private void TouchCancelHandler(TouchEvent <HTMLCanvasElement> evt)
        {
            evt.PreventDefault();

            OngoingTouches.Clear();
            LogMessage("touchcancel.");
        }
Пример #2
0
        public void OnTouchEnd(ElementEvent e)
        {
            TouchEvent ev = (TouchEvent)e;

            ev.PreventDefault();
            mouseDown = false;
        }
Пример #3
0
        public void OnTouchStart(ElementEvent e)
        {
            TouchEvent ev = (TouchEvent)e;

            ev.PreventDefault();
            mouseDown = true;
            lastX     = ev.TargetTouches[0].PageX;
            lastY     = ev.TargetTouches[0].PageY;
        }
Пример #4
0
        static void OnTouchEnd(TouchEvent <HTMLCanvasElement> e)
        {
            e.PreventDefault();
            foreach (var t in e.ChangedTouches)
            {
                _history.Remove(t.Identifier);
            }

            Redraw();
        }
Пример #5
0
        public void OnTouchStart(ElementEvent e)
        {
            TouchEvent ev = (TouchEvent)e;

            ev.PreventDefault();
            mouseDown = true;
            lastX     = ev.TargetTouches[0].PageX;
            lastY     = ev.TargetTouches[0].PageY;

            indexTouchDown = GetItemIndexFromCursor(Vector2d.Create(ev.TargetTouches[0].PageX, ev.TargetTouches[0].PageY));
        }
Пример #6
0
 static void SetTouchDown(TouchEvent <HTMLCanvasElement> e)
 {
     if (e.Touches[0].ClientX < screen.ClientWidth / 2)
     {
         chip8.KeyDown(keyMapping[KeyCode.LeftCursor]);
     }
     else
     {
         chip8.KeyDown(keyMapping[KeyCode.RightCursor]);
     }
     e.PreventDefault();
 }
Пример #7
0
        public void OnTouchMove(ElementEvent e)
        {
            TouchEvent ev = (TouchEvent)e;

            ev.PreventDefault();
            if (mouseDown)
            {
                double curX = ev.TargetTouches[0].PageX - lastX;

                double curY = ev.TargetTouches[0].PageY - lastY;
                if (mouseDown)
                {
                    dragging = true;
                }

                if (!dragging)
                {
                    int newHover = GetItemIndexFromCursor(Vector2d.Create(ev.TargetTouches[0].PageX, ev.TargetTouches[0].PageY));
                    if (hoverItem != newHover)
                    {
                        hoverItem = newHover;
                        //if (ItemHover != null)
                        //{
                        //    if (hoverItem > -1)
                        //    {
                        //        ItemHover.Invoke(this, items[hoverItem]);
                        //    }
                        //    else
                        //    {
                        //        ItemHover.Invoke(this, null);
                        //    }
                        //}
                    }
                }
                else
                {
                    int tiles  = (int)Math.Round(((ev.TargetTouches[0].PageX - lastX) + startOffset) / HorzSpacing);
                    int offset = (int)Math.Round(((ev.TargetTouches[0].PageX - lastX) + startOffset) - (tiles * HorzSpacing));

                    startOffset = offset;
                    startIndex -= tiles;
                    if (startIndex < 0)
                    {
                        startOffset -= (HorzSpacing * startIndex);
                        startIndex   = 0;
                    }
                    lastX = ev.TargetTouches[0].PageX;
                    lastY = ev.TargetTouches[0].PageY;
                }
                Refresh();
            }
        }
Пример #8
0
        static void OnTouchMove(TouchEvent <HTMLCanvasElement> e)
        {
            e.PreventDefault();
            foreach (var t in e.ChangedTouches)
            {
                var th = _history.Find(t.Identifier);
                if (th != null)
                {
                    th.AddEvent(t);
                }
            }

            Redraw();
        }
Пример #9
0
        static void OnTouchStart(TouchEvent <HTMLCanvasElement> e)
        {
            e.PreventDefault();
            foreach (var t in e.ChangedTouches)
            {
                var th = new TouchHistory()
                {
                    Id = t.Identifier
                };
                th.AddEvent(t);
                _history.Add(th);
            }

            Redraw();
        }
Пример #10
0
            /// <summary>
            /// Handles touch events.
            /// </summary>
            /// <param name="e">The browser event.</param>
            private void handleTouchEvent_(TouchEvent e)
            {
                var be = new goog.events.BrowserEvent(e);

                e.PreventDefault();
                var node = this.getNodeFromEvent_(be);

                if (node != null && e.Type == goog.events.EventType.TOUCHSTART)
                {
                    // Fire asynchronously since onMouseDown takes long enough that the browser
                    // would fire the default mouse event before this method returns.
                    Window.SetTimeout(() => {
                        node.onMouseDown(be);                          // Same behaviour for click and touch.
                    }, 1);
                }
            }
Пример #11
0
        public void OnTouchMove(ElementEvent e)
        {
            TouchEvent ev = (TouchEvent)e;

            ev.PreventDefault();
            if (mouseDown)
            {
                double curX = ev.TargetTouches[0].PageX - lastX;

                double curY = ev.TargetTouches[0].PageY - lastY;

                Move(curX, curY);

                lastX = ev.TargetTouches[0].PageX;
                lastY = ev.TargetTouches[0].PageY;
            }
        }
Пример #12
0
        public void OnTouchEnd(ElementEvent e)
        {
            TouchEvent ev = (TouchEvent)e;

            ev.PreventDefault();
            if (dragging)
            {
                dragging    = false;
                ignoreClick = true;
            }
            else if (indexTouchDown > -1 && mouseDown)
            {
                HandleClick(indexTouchDown);
            }
            startOffset = 0;
            mouseDown   = false;
            Refresh();
        }
Пример #13
0
        private void TouchMoveHandler(TouchEvent <HTMLCanvasElement> evt)
        {
            evt.PreventDefault();

            var ctx = this.Context2D;

            var touches = evt.ChangedTouches;

            for (var i = 0; i < touches.Length; i++)
            {
                var t = touches[i];

                var idx = this.OngoingTouchIndexById(t.Identifier);

                if (idx >= 0)
                {
                    this.LogMessage("continuing touch " + idx);

                    var color = this.ColorForTouch(t, t.Identifier + " move idx " + idx + " ");

                    ctx.BeginPath();

                    var ogt = OngoingTouches[idx];

                    this.LogMessage("ctx.moveTo(" + ogt.PageX + ", " + ogt.PageY + ");");
                    ctx.MoveTo(ogt.PageX, ogt.PageY);

                    this.LogMessage("ctx.lineTo(" + t.PageX + ", " + t.PageY + ");");
                    ctx.LineTo(t.PageX, t.PageY);
                    ctx.LineWidth = 4;

                    ctx.StrokeStyle = color;
                    ctx.Stroke();

                    OngoingTouches[idx] = CopyTouch(t);  // swap in the new touch record

                    this.LogMessage("continued .");
                }
                else
                {
                    this.LogMessage("can't figure out which touch to continue");
                }
            }
        }
Пример #14
0
        public static void TouchStart(TouchEvent evt)
        {
            // With JQuery: $(document).bind("touchstart", function(e) {...}
            evt.PreventDefault();
            JsString target_id = evt.target.id;

            if (isMoving == false && movingItems[target_id] == 1)
            {
                isMoving = true;
                //var orig = e.originalEvent;
                TouchEvent orig = evt;
                int        x    = orig.touches[0].pageX - imgOffset;
                int        y    = orig.touches[0].pageY - imgOffset;
                //Set the item to moving, and update the position and zIndex
                movingItems[target_id] = 2;
                HtmlElement.GetById(target_id).style.top  = y + "px";
                HtmlElement.GetById(target_id).style.left = x + "px";
                // With JQuery: $("#dragItem").css({top: y, left: x});
                HtmlElement.GetById(target_id).style.zIndex = "2000";
            }
        }
Пример #15
0
        public static void TouchMove(TouchEvent evt)
        {
            // With JQuery: $(document).bind("touchmove", function(e) {...}
            evt.PreventDefault();
            JsString target_id = evt.target.id;

            //Check that the target element is registered and flagged as moving
            if (movingItems[target_id].As <bool>() && movingItems[target_id] == 2)
            {
                //var orig = e.originalEvent;
                TouchEvent orig = evt;
                if (orig.touches.length > 1)
                {
                    return;
                }
                int x = orig.touches[0].pageX - imgOffset;
                int y = orig.touches[0].pageY - imgOffset;

                HtmlElement.GetById(target_id).style.top  = y + "px";
                HtmlElement.GetById(target_id).style.left = x + "px";
                // With JQuery: $("#dragItem").css({top: y, left: x});
            }
        }
Пример #16
0
        private void TouchEndHandler(TouchEvent <HTMLCanvasElement> evt)
        {
            evt.PreventDefault();
            this.LogMessage("touchend");

            var ctx     = this.Context2D;
            var touches = evt.ChangedTouches;

            for (var i = 0; i < touches.Length; i++)
            {
                var t = touches[i];

                var idx = OngoingTouchIndexById(t.Identifier);

                if (idx >= 0)
                {
                    var color = this.ColorForTouch(t, t.Identifier + " end idx " + idx + " ");

                    ctx.LineWidth = 4;
                    ctx.FillStyle = color;
                    ctx.BeginPath();

                    var ogt = OngoingTouches[idx];

                    ctx.MoveTo(ogt.PageX, ogt.PageY);
                    ctx.LineTo(t.PageX, t.PageY);
                    ctx.FillRect(t.PageX - 4, t.PageY - 4, 8, 8); // and a square at the end

                    OngoingTouches.RemoveAt(idx);                 // remove it; we're done
                }
                else
                {
                    this.LogMessage("can't figure out which touch to end");
                }
            }
        }
Пример #17
0
 static void OnTouchLeave(TouchEvent <HTMLCanvasElement> e)
 {
     e.PreventDefault();
 }
Пример #18
0
 public static void TouchStart(TouchEvent evt)
 {
     // With JQuery: $(document).bind("touchstart", function(e) {...}
     evt.PreventDefault();
     JsString target_id = evt.target.id;
     if (isMoving == false && movingItems[target_id] == 1)
     {
         isMoving = true;
         //var orig = e.originalEvent;
         TouchEvent orig = evt;
         int x = orig.touches[0].pageX - imgOffset;
         int y = orig.touches[0].pageY - imgOffset;
         //Set the item to moving, and update the position and zIndex
         movingItems[target_id] = 2;
         HtmlElement.GetById(target_id).style.top = y + "px";
         HtmlElement.GetById(target_id).style.left = x + "px";
         // With JQuery: $("#dragItem").css({top: y, left: x});
         HtmlElement.GetById(target_id).style.zIndex = "2000";
     }
 }
Пример #19
0
 static void SetTouchUp(TouchEvent <HTMLCanvasElement> e)
 {
     chip8.KeyUp(keyMapping[KeyCode.LeftCursor]);
     chip8.KeyUp(keyMapping[KeyCode.RightCursor]);
     e.PreventDefault();
 }
Пример #20
0
        public static void TouchMove(TouchEvent evt)
        {
            // With JQuery: $(document).bind("touchmove", function(e) {...}
            evt.PreventDefault();
            JsString target_id = evt.target.id;
            //Check that the target element is registered and flagged as moving
            if (movingItems[target_id].As<bool>() && movingItems[target_id] == 2)
            {
                //var orig = e.originalEvent;
                TouchEvent orig = evt;
                if (orig.touches.length > 1)
                    return;
                int x = orig.touches[0].pageX - imgOffset;
                int y = orig.touches[0].pageY - imgOffset;

                HtmlElement.GetById(target_id).style.top = y + "px";
                HtmlElement.GetById(target_id).style.left = x + "px";
                // With JQuery: $("#dragItem").css({top: y, left: x});
            }
        }