コード例 #1
0
        public void RunForever()
        {
            _leftY  = new VerticalGauge(_displayModule, 5, 5, 30, 10, DisplayModule.Color.Cyan, DisplayModule.Color.Blue);
            _rightY = new VerticalGauge(_displayModule, 135, 5, 30, 10, DisplayModule.Color.Yellow, DisplayModule.Color.Red);


            _leftX  = new HorizGauge(_displayModule, 35, 30, 10, 30, DisplayModule.Color.Green, DisplayModule.Color.Magenta);
            _rightX = new HorizGauge(_displayModule, 85, 30, 10, 30, DisplayModule.Color.Blue, DisplayModule.Color.Orange);

            _leftCrossHair = _displayModule.AddResourceImageSprite(
                DisplayModule_Example.Properties.Resources.ResourceManager,
                DisplayModule_Example.Properties.Resources.BinaryResources.ch2,
                Bitmap.BitmapImageType.Jpeg,
                30, 100);

            _rightCrossHair = _displayModule.AddResourceImageSprite(
                DisplayModule_Example.Properties.Resources.ResourceManager,
                DisplayModule_Example.Properties.Resources.BinaryResources.ch2,
                Bitmap.BitmapImageType.Jpeg,
                100, 100);

            _labelTitle = _displayModule.AddLabelSprite(_bigFont, DisplayModule.Color.White, 40, 0, 80, 16);

            _labelBtn = _displayModule.AddLabelSprite(_smallFont, DisplayModule.Color.White, 30, 50, 100, 15);

            while (true)
            {
                UpdateGauge(_leftX, _gamepad.GetAxis(0));
                UpdateGauge(_leftY, _gamepad.GetAxis(1));
                UpdateGauge(_rightX, _gamepad.GetAxis(2));
                UpdateGauge(_rightY, _gamepad.GetAxis(5));

                _leftCrossHair.SetPosition((int)(30 + 15 * _gamepad.GetAxis(0)), 100 + (int)(15 * _gamepad.GetAxis(1)));
                _rightCrossHair.SetPosition((int)(100 + 15 * _gamepad.GetAxis(2)), 100 + (int)(15 * _gamepad.GetAxis(5)));

                if (_gamepad.GetConnectionStatus() == UsbDeviceConnection.Connected)
                {
                    _labelTitle.SetText("Connected");
                    _labelTitle.SetColor(DisplayModule.Color.Green);
                }
                else
                {
                    _labelTitle.SetText("No Gamepad");
                    _labelTitle.SetColor(DisplayModule.Color.Red);
                }

                int idx = GetFirstButton(_gamepad);
                if (idx < 0)
                {
                    _labelBtn.SetColor((DisplayModule.Color) 0xA0A0A0); // gray RGB
                    _labelBtn.SetText("No Buttons");
                }
                else
                {
                    switch (idx % 4)
                    {
                    case 0: _labelBtn.SetColor(DisplayModule.Color.Cyan); break;

                    case 1: _labelBtn.SetColor(DisplayModule.Color.Green); break;

                    case 2: _labelBtn.SetColor(DisplayModule.Color.Red); break;

                    case 3: _labelBtn.SetColor(DisplayModule.Color.Yellow); break;
                    }
                    _labelBtn.SetText("Pressed Button " + idx);
                }

                Thread.Sleep(10);
            }
        }
コード例 #2
0
 public void UpdateGauge(VerticalGauge gauge, float axis)
 {
     axis       += 1.0f; // [0,2]
     axis       *= 0.5f; // [0,1]
     gauge.Value = (int)(axis * gauge.MaxValue);
 }