Example #1
0
        public Page()
        {
            InitializeComponent();

            // set width / height
            this.Width = Double.Parse(System.Windows.Browser.HtmlPage.Document.Body.GetProperty("clientWidth").ToString());
            this.Height = Double.Parse(System.Windows.Browser.HtmlPage.Document.Body.GetProperty("clientHeight").ToString());

            // we get a reference to the main canvas and add the
            Canvas maincanvas = (Canvas)this.FindName("Main");
            //            myCanvas.Background = new SolidColorBrush(Colors.White);

            // and then we instantiate a new Touch Listener on our main Canvas
            // so that contained objects can receive events from
            // multitouch and/or mouse input
            _wiimotelistener = new Remote(); //maincanvas);
            _wiimotelistener.AccelerationUpdate += new Remote.AccelerationUpdateHandler(_wiimotelistener_AccelerationUpdate);
            //new TouchListener.AccelerationUpdateHandler(multiTouchInput_AccelerationUpdate);
            //
            _migclient = new MIGClient();
            _migclient.ServiceReady += new MIGClient.ServiceReadyHandler(_migclient_ServiceReady);
            _migclient.AddListener("WII0", _wiimotelistener);
            _migclient.Connect();
            //
            _cursor = (Canvas)maincanvas.FindName("cursor");
            _cursortr = new TransformHelper(_cursor); // _cursor.TransformHelper;
            _cursortr.Delay = 2.0;
            _cursortr.Translate = new Point((this.Width / 2) - 100, (this.Height) - 50);

            Point _balldirection = new Point(3, 6);

            Ellipse _ball = (Ellipse)maincanvas.FindName("ball");
            TransformHelper _balltr = new TransformHelper(_ball);
            _balltr.Delay = 0.0;

            TextBlock _scoreText = (TextBlock)maincanvas.FindName("score");
            _scoreText.Width = this.Width;

            int _score = 0;

            DispatcherTimer _timer = new DispatcherTimer();
            _timer.Tick += (sender2, e2) =>
            {

                _balltr.Translate = new Point(_balltr.Translate.X + _balldirection.X, _balltr.Translate.Y + _balldirection.Y);

                if (_balltr.Translate.X <= 0)
                {
                    _balldirection.X = -_balldirection.X;
                }
                else if (_balltr.Translate.X + 50 >= this.Width)
                {
                    _balldirection.X = -_balldirection.X;
                }
                if (_balltr.Translate.Y <= 0)
                {
                    _balldirection.Y = -_balldirection.Y;
                }
                else if (_balltr.Translate.Y + 50 >= this.Height)
                {
                    //_balldirection.Y = -_balldirection.Y;
                    _balltr.Translate = new Point(_balltr.Translate.X, 1);
                    _score = 0;
                    _balldirection = new Point(5, 5);
                }

                IEnumerable<UIElement> hits = VisualTreeHelper.FindElementsInHostCoordinates(new Point(_balltr.Translate.X + 25, _balltr.Translate.Y + 50), this);
                foreach (UIElement uiel in hits)
                {
                    if (uiel.Equals(_cursor))
                    {
                        _balltr.Translate = new Point(_balltr.Translate.X + _balldirection.X, _balltr.Translate.Y - _balldirection.Y);
                        _balldirection = new Point(_balldirection.X * 1.025, _balldirection.Y * 1.025);
                        _balldirection.Y = -_balldirection.Y;
                        _score += 10;
                    }
                }

                _scoreText.Text = _score + "";

            };
            _timer.Interval = new TimeSpan(0, 0, 0, 0, 5);
            _timer.Start();
        }
Example #2
0
        private void _init()
        {
            this.Projection = new PlaneProjection() { };
            this.Background = new SolidColorBrush(Colors.Transparent);
            //
            _backgroundcanvas = new TCanvas();
            _backgroundcanvas.Width = this.Width;
            _backgroundcanvas.Height = this.Height;
            _backgroundcanvas.Background = new SolidColorBrush(Colors.Transparent);
            _backgroundcanvas.FingerAdded += new TCanvas.FingerAdddedHandler(_backgroundcanvas_FingerAdd);
            _backgroundcanvas.FingerRemoved += new TCanvas.FingerRemovedHandler(_backgroundcanvas_FingerRemove);
            _backgroundcanvas.FingerUpdated += new TCanvas.FingerUpdatedHandler(_backgroundcanvas_FingerUpdate);
            (this.Parent as Panel).Children.Insert((this.Parent as Panel).Children.IndexOf(this), _backgroundcanvas);
            //
            _dispatchertimer = new DispatcherTimer();
            _dispatchertimer.Interval = new TimeSpan(0, 0, 0, 0, 20);
            _dispatchertimer.Tick += (sender, e) => {
                if (_currentaction == 1 && _currentitem < _itemscount && _ticks == 2)
                    _folditem();
                else if (_currentaction == 0 && _currentitem != -1 && _ticks == 2)
                    _unfolditem();
                else
                    _animate();
                if (_ticks == 2)
                    _ticks = 0;
                else
                    _ticks++;
            };
            _dispatchertimer.Start();

            _transformhelper = new TransformHelper(this);

            _gesturesinterpreter = new TouchGestures(_backgroundcanvas);
            _gesturesinterpreter.GestureDetected += new TouchGestures.GestureDetectedHandler(_gesturesinterpreter_GestureDetected);
            _gesturesinterpreter.Scale += new TouchGestures.GestureScaleHandler(_gesturesinterpreter_Scale);
            _gesturesinterpreter.Tap += new TouchGestures.GestureTapHandler(_gesturesinterpreter_Tap);
        }
Example #3
0
 private void LayoutRoot_LayoutUpdated(object sender, EventArgs e)
 {
     // TransformHelpers for animating menus
     if (_appmenutrhelper == null)
     {
         _appmenutrhelper = new TransformHelper(MainMenu);
         _devmenutrhelper = new TransformHelper(DevicesMenu);
         _devmenutrhelper.Delay = 0;
         _devmenutrhelper.Translate = new Point(this.ActualWidth + ((this.ActualWidth - DevicesMenu.ActualWidth) / 2), 0);
     }
 }