コード例 #1
0
        public override bool OnGenericMotionEvent(MotionEvent e)
        {
            InputDevice device = e.Device;

            if (device != null && device.Id == current_device_id)
            {
                if (IsGamepad(device))
                {
                    for (int i = 0; i < AxesMapping.size; i++)
                    {
                        axes [i] = GetCenteredAxis(e, device, AxesMapping.OrdinalValueAxis(i));
                    }
                    controller_view.Invalidate();
                    return(true);
                }
            }
            return(base.OnGenericMotionEvent(e));
        }
コード例 #2
0
        protected override void OnDraw(Canvas canvas)
        {
            int offset = Width / 2 - Height / 2;

            //draw background
            canvas.DrawColor(Color.Black);
            canvas.DrawRect(0, 0, Width, Height, background_paint);

            //draw brake/gas indicators
            if (axes [AxesMapping.OrdinalValue(AxesMapping.AXIS_BRAKE)] > 0.0f)
            {
                gradient_paint.Alpha = ((int)(axes[AxesMapping.OrdinalValue(AxesMapping.AXIS_BRAKE)] * 100) + 155);
                canvas.DrawBitmap(gradient_bitmap, offset + left_gradient [0] * Height,
                                  left_gradient [1] * Height, gradient_paint);
            }

            if (axes [AxesMapping.OrdinalValue(AxesMapping.AXIS_GAS)] > 0.0f)
            {
                gradient_paint.Alpha = ((int)(axes[AxesMapping.OrdinalValue(AxesMapping.AXIS_GAS)] * 100) + 155);
                canvas.DrawBitmap(gradient_bitmap, offset + right_gradient [0] * Height,
                                  right_gradient [1] * Height, gradient_paint);
            }

            //draw the paddles
            canvas.DrawColor(Color.Transparent);
            if (buttons [ButtonMapping.OrdinalValue(ButtonMapping.BUTTON_R1)] == 0)
            {
                canvas.DrawBitmap(right_paddle_bitmap, offset + right_paddle [0] * Height,
                                  right_paddle [1] * Height, image_paint);
            }
            else if (buttons [ButtonMapping.OrdinalValue(ButtonMapping.BUTTON_R1)] == 1)
            {
                canvas.DrawBitmap(right_paddle_bitmap, offset + right_paddle_pressed [0] * Height,
                                  right_paddle_pressed [1] * Height, image_paint);
            }
            if (buttons [ButtonMapping.OrdinalValue(ButtonMapping.BUTTON_L1)] == 0)
            {
                canvas.DrawBitmap(left_paddle_bitmap, offset + left_paddle [0] * Height,
                                  left_paddle [1] * Height, image_paint);
            }
            else if (buttons [ButtonMapping.OrdinalValue(ButtonMapping.BUTTON_L1)] == 1)
            {
                canvas.DrawBitmap(left_paddle_bitmap, offset + left_paddle_pressed [0] * Height,
                                  left_paddle_pressed [1] * Height, image_paint);
            }

            //draw the controller body
            canvas.DrawBitmap(controller_bitmap, offset, 0, image_paint);

            //draw axes
            axis_leftX  = offset + left_axis [0] * Height;
            axis_leftY  = left_axis [1] * Height;
            axis_rightX = offset + right_axis [0] * Height;
            axis_rightY = right_axis [1] * Height;
            if (axes [AxesMapping.OrdinalValue(AxesMapping.AXIS_X)] != 0.0f)
            {
                axis_leftX = axis_leftX + left_axis [3] * Height
                             * axes [AxesMapping.OrdinalValue(AxesMapping.AXIS_X)];
            }
            if (axes [AxesMapping.OrdinalValue(AxesMapping.AXIS_Y)] != 0.0f)
            {
                axis_leftY = axis_leftY + left_axis [3] * Height
                             * axes [AxesMapping.OrdinalValue(AxesMapping.AXIS_Y)];
            }

            //Android Gamepad:AXIS_Z and AXIS_RZ respectively
            //Xbox Gamepad:AXIS_RX and AXIX_RZ respectively
            if (axes [AxesMapping.OrdinalValue(AxesMapping.AXIS_RX)] != 0.0f)
            {
                axis_rightX = axis_rightX + right_axis [3] * Height
                              * axes [AxesMapping.OrdinalValue(AxesMapping.AXIS_RX)];
            }
            if (axes [AxesMapping.OrdinalValue(AxesMapping.AXIS_RY)] != 0.0f)
            {
                axis_rightY = axis_rightY + right_axis [3] * Height
                              * axes [AxesMapping.OrdinalValue(AxesMapping.AXIS_RY)];
            }

            canvas.DrawBitmap(axis_bitmap, axis_rightX, axis_rightY, image_paint);
            canvas.DrawBitmap(axis_bitmap, axis_leftX, axis_leftY, image_paint);

            //Draw the LED light
            if (current_controller_number > 0 && current_controller_number <= MAX_CONTROLLERS)
            {
                canvas.DrawBitmap(blue_led_bitmap, offset
                                  + led_buttons [2 * current_controller_number - 2] * Height,
                                  led_buttons [2 * current_controller_number - 1] * Height, led_paint);
            }

            //Draw the directional buttons
            if (axes [AxesMapping.OrdinalValue(AxesMapping.AXIS_HAT_X)] == 1.0f)
            {
                canvas.DrawBitmap(right_directional_bitmap, offset + right_directional_button [0]
                                  * Height, right_directional_button [1] * Height, directional_paint);
            }
            if (axes [AxesMapping.OrdinalValue(AxesMapping.AXIS_HAT_Y)] == -1.0f)
            {
                canvas.DrawBitmap(top_directional_bitmap, offset + top_directional_button [0]
                                  * Height, top_directional_button [1] * Height, directional_paint);
            }
            if (axes [AxesMapping.OrdinalValue(AxesMapping.AXIS_HAT_X)] == -1.0f)
            {
                canvas.DrawBitmap(left_directional_bitmap, offset + left_directional_button [0]
                                  * Height, left_directional_button [1] * Height, directional_paint);
            }
            if (axes [AxesMapping.OrdinalValue(AxesMapping.AXIS_HAT_Y)] == 1.0f)
            {
                canvas.DrawBitmap(bottom_directional_bitmap, offset + bottom_directional_button [0]
                                  * Height, bottom_directional_button [1] * Height, directional_paint);
            }

            //draw the A/B/X/Y buttons
            canvas.DrawColor(Color.Transparent);
            circle_paint.Color = Resources.GetColor(Resource.Color.transparent_black);
            if (buttons [ButtonMapping.OrdinalValue(ButtonMapping.BUTTON_Y)] == 1)
            {
                canvas.DrawCircle(offset + y_button [0] * Height, y_button [1] * Height,
                                  y_button [2] * Height, circle_paint);
            }
            if (buttons [ButtonMapping.OrdinalValue(ButtonMapping.BUTTON_X)] == 1)
            {
                canvas.DrawCircle(offset + x_button [0] * Height, x_button [1] * Height,
                                  x_button [2] * Height, circle_paint);
            }
            if (buttons [ButtonMapping.OrdinalValue(ButtonMapping.BUTTON_B)] == 1)
            {
                canvas.DrawCircle(offset + b_button [0] * Height, b_button [1] * Height,
                                  b_button [2] * Height, circle_paint);
            }
            if (buttons [ButtonMapping.OrdinalValue(ButtonMapping.BUTTON_A)] == 1)
            {
                canvas.DrawCircle(offset + a_button [0] * Height, a_button [1] * Height,
                                  a_button [2] * Height, circle_paint);
            }

            //draw the center buttons
            if (buttons [ButtonMapping.OrdinalValue(ButtonMapping.POWER)] == 1)
            {
                canvas.DrawCircle(offset + power_button [0] * Height,
                                  power_button [1] * Height,
                                  power_button [2] * Height, circle_paint);
            }
            if (buttons [ButtonMapping.OrdinalValue(ButtonMapping.BUTTON_START)] == 1)
            {
                canvas.DrawCircle(offset + home_button [0] * Height,
                                  home_button [1] * Height,
                                  home_button [2] * Height, circle_paint);
            }

            //Android Gamepad: BUTTON_BACK, Xbox Gamepad: BUTTON_SELECT
            if (buttons [ButtonMapping.OrdinalValue(ButtonMapping.BUTTON_SELECT)] == 1)
            {
                canvas.DrawCircle(offset + back_button [0] * Height,
                                  back_button [1] * Height,
                                  back_button [2] * Height, circle_paint);
            }

            // Draw the axes
            if (buttons[ButtonMapping.OrdinalValue(ButtonMapping.BUTTON_THUMBL)] == 1)
            {
                canvas.DrawCircle(left_axis_button[2] * Height + axis_leftX, left_axis_button[2]
                                  * Height + axis_leftY,
                                  left_axis_button[2] * Height, circle_paint);
            }
            if (buttons[ButtonMapping.OrdinalValue(ButtonMapping.BUTTON_THUMBR)] == 1)
            {
                canvas.DrawCircle(right_axis_button[2] * Height + axis_rightX, right_axis_button[2]
                                  * Height + axis_rightY,
                                  right_axis_button[2] * Height, circle_paint);
            }
        }