Esempio n. 1
0
 public SlotOverlay(VirtualController.Button b, Rectangle m, Color c, SlotShape shape) :
     base(b)
 {
     Metrics = m;
     Color   = c;
     Shape   = shape;
 }
Esempio n. 2
0
            public override string ToString()
            {
                if (Mapping.Source.StartsWith("button:"))
                {
                    VirtualController.Button btn = (VirtualController.Button)Enum.Parse(typeof(VirtualController.Button),
                                                                                        Mapping.Destination);
                    string btnName = Util.GetButtonDisplayName(btn);
                    string src     = Mapping.Source.Substring("button:".Length);

                    if (Mapping.Gesture != "Link" && Mapping.Gesture != "" && Mapping.Gesture != null)
                    {
                        src += string.Format(" ({0})", (Mapping.Gesture == "DoubleTap" ? "Double Tap" : Mapping.Gesture));
                    }

                    return(string.Format("Button {0} -> {1}", src, btnName));
                }
                else
                {
                    VirtualController.Axis axis = (VirtualController.Axis)Enum.Parse(typeof(VirtualController.Axis),
                                                                                     Mapping.Destination);
                    string axisName = Util.GetAxisDisplayName(axis);

                    return(string.Format("Axis {0} -> {1}", Mapping.Source.Substring("axis:".Length), axisName));
                }
            }
Esempio n. 3
0
        public ButtonActionsConfig GetButton(VirtualController.Button button)
        {
            switch (button)
            {
            case VirtualController.Button.A: return(this.A);

            case VirtualController.Button.B: return(this.B);

            case VirtualController.Button.X: return(this.X);

            case VirtualController.Button.Y: return(this.Y);

            case VirtualController.Button.Bl: return(this.Bl);

            case VirtualController.Button.Br: return(this.Br);

            case VirtualController.Button.Tl: return(this.Tl);

            case VirtualController.Button.Tr: return(this.Tr);

            case VirtualController.Button.Start: return(this.Start);

            case VirtualController.Button.Back: return(this.Back);

            case VirtualController.Button.System: return(this.System);

            case VirtualController.Button.LeftAnalog: return(this.LeftAnalogButton);

            case VirtualController.Button.RightAnalog: return(this.RightAnalogButton);
            }

            return(null);
        }
Esempio n. 4
0
        public void SetOverlay(VirtualController.Button b, bool visible)
        {
            var o = FindOverlay(b);

            if (o != null)
            {
                o.Visible = visible;
            }
            else
            {
                Console.WriteLine("Error: could not find overlay for button " + b);
            }

            Render();
        }
Esempio n. 5
0
        private void SetupButton(VirtualController.Button button, Panel panel)
        {
            string    name  = button.ToString();
            SlotShape shape = SlotShape.Rounded;

            if (panel.Tag is string)
            {
                try {
                    shape = (SlotShape)Enum.Parse(typeof(SlotShape), panel.Tag as string);
                } catch (FormatException) { }
            }
            RegisterOverlay(button, panel.Bounds, panel.BackColor, shape);
            panel.Tag = button;
            panel.Hide();
        }
Esempio n. 6
0
        public SlotOverlay FindOverlay(VirtualController.Button b)
        {
            foreach (var o in slotOverlays)
            {
                if (o.IsAxisGesture)
                {
                    continue;
                }
                if (o.Button == b)
                {
                    return(o);
                }
            }

            return(null);
        }
Esempio n. 7
0
 public ButtonSpot(VirtualController.Button button, int x, int y)
 {
     Button = button;
     X = x;
     Y = y;
 }
Esempio n. 8
0
        private void SetupButton(VirtualController.Button button)
        {
            string name = button.ToString();

            if (button == VirtualController.Button.Bl)
            {
                name = "Left Bumper";
            }
            else if (button == VirtualController.Button.Br)
            {
                name = "Right Bumper";
            }
            else if (button == VirtualController.Button.Tl)
            {
                name = "Left Trigger";
            }
            else if (button == VirtualController.Button.Tr)
            {
                name = "Right Trigger";
            }

            TreeNode n;

            if (button == VirtualController.Button.LeftAnalog)
            {
                TreeNode root;
                if (axisPortNodes.ContainsKey(VirtualController.Axis.LeftX))
                {
                    root = axisPortNodes[VirtualController.Axis.LeftX];
                }
                else
                {
                    root = axisPortNodes[VirtualController.Axis.LeftX] =
                        buttonMapNodes["left-analog"] = currentMappings.Nodes.Add("Left Analog");
                }

                buttonMapNodes["left-analog/button"] = n = root.Nodes.Add("Push");
            }
            else if (button == VirtualController.Button.RightAnalog)
            {
                TreeNode root;
                if (axisPortNodes.ContainsKey(VirtualController.Axis.RightX))
                {
                    root = axisPortNodes[VirtualController.Axis.RightX];
                }
                else
                {
                    root = axisPortNodes[VirtualController.Axis.RightX] =
                        buttonMapNodes["right-analog"] = currentMappings.Nodes.Add("Right Analog");
                }

                buttonMapNodes["right-analog/button"] = n = root.Nodes.Add("Push");
            }
            else
            {
                n = currentMappings.Nodes.Add(name);
            }

            buttonMapNodes[button.ToString()]           = n;
            buttonMapNodes[button.ToString() + "/link"] = n.Nodes.Add("Link");
            buttonMapNodes[button.ToString() + "/tap"]  = n.Nodes.Add("Tap");
            buttonMapNodes[button.ToString() + "/dtap"] = n.Nodes.Add("Double Tap");
            buttonMapNodes[button.ToString() + "/hold"] = n.Nodes.Add("Hold");
        }
Esempio n. 9
0
        private void changeBtn_Click(object sender, EventArgs e)
        {
            if (buttonMappings.SelectedItem == null)
            {
                return;
            }

            var item = buttonMappings.SelectedItem as DeviceMappingItem;
            var cmf  = new ChangeMappingDialog(mainForm, item.Mapping.Pad, item.Mapping.Source, item.Mapping.Gesture, item.Mapping.Destination);

            cmf.ShowDialog(this);

            if (cmf.DialogResult == DialogResult.OK)
            {
                bool isButton = item.Mapping.Source.StartsWith("button:");

                item.Mapping.Destination = cmf.Destination;
                if (isButton)
                {
                    item.Mapping.Gesture = cmf.Gesture;
                }
                else
                {
                    item.Mapping.Gesture = "";
                }

                if (isButton)
                {
                    int btn = int.Parse(item.Mapping.Source.Substring("button:".Length));
                    VirtualController.Button b = (VirtualController.Button)Enum.Parse(typeof(VirtualController.Button), cmf.Destination);
                    var ba = new VirtualController.ButtonAction(controller.Virtual, b);

                    if (cmf.Gesture != "Link" && cmf.Gesture != "" && cmf.Gesture != null)
                    {
                        // We need to enable gesture support at the device level for this button
                        controller.Device.Buttons[btn].EnableGestures = true;
                    }

                    switch (cmf.Gesture)
                    {
                    case "Link":
                    case null:
                    case "":
                        controller.Device.Buttons[btn].Link = ba;
                        break;

                    case "Tap":
                        controller.Device.Buttons[btn].Tap = ba;
                        break;

                    case "DoubleTap":
                        controller.Device.Buttons[btn].DoubleTap = ba;
                        break;

                    case "Hold":
                        controller.Device.Buttons[btn].Hold = ba;
                        break;
                    }
                }
                else
                {
                    int axis = int.Parse(item.Mapping.Source.Substring("axis:".Length));
                    VirtualController.Axis a = (VirtualController.Axis)Enum.Parse(typeof(VirtualController.Axis), cmf.Destination);
                    controller.Device.Axes[axis].Analog = new VirtualController.AxisAction(controller.Virtual, a);
                }

                mainForm.GlobalConfig.Save();
                RefreshDeviceMappings();
            }
        }
Esempio n. 10
0
 public ButtonOptionItem(VirtualController.Button b)
 {
     Button = b;
     Name   = Util.GetButtonDisplayName(b);
 }
Esempio n. 11
0
 public ButtonOptionItem(VirtualController.Button b)
 {
     Button = b;
     Name = Util.GetButtonDisplayName(b);
 }
Esempio n. 12
0
 public void RegisterOverlay(VirtualController.Button b, Rectangle m, Color c, SlotShape shape)
 {
     slotOverlays.Add(new SlotOverlay(b, m, c, shape));
 }
Esempio n. 13
0
 public ButtonSpot(VirtualController.Button button, int x, int y)
 {
     Button = button;
     X      = x;
     Y      = y;
 }
Esempio n. 14
0
        public ChangeMappingDialog(PadTieForm form, int pad, string source, string gesture, string dest)
        {
            InitializeComponent();

            if (pad == -1)
            {
                sendDefault.Checked = true;
            }
            else
            {
                sendToOther.Checked = true;
                padSelector.Value   = pad;
            }

            if (source.StartsWith("button:"))
            {
                lblSource.Text = "Button: " + source.Substring("button:".Length);
                isAxis         = false;

                options.Items.Clear();
                options.Items.Add(new ButtonOptionItem(VirtualController.Button.A));
                options.Items.Add(new ButtonOptionItem(VirtualController.Button.B));
                options.Items.Add(new ButtonOptionItem(VirtualController.Button.X));
                options.Items.Add(new ButtonOptionItem(VirtualController.Button.Y));
                options.Items.Add(new ButtonOptionItem(VirtualController.Button.Bl));
                options.Items.Add(new ButtonOptionItem(VirtualController.Button.Br));
                options.Items.Add(new ButtonOptionItem(VirtualController.Button.Tl));
                options.Items.Add(new ButtonOptionItem(VirtualController.Button.Tr));
                options.Items.Add(new ButtonOptionItem(VirtualController.Button.Back));
                options.Items.Add(new ButtonOptionItem(VirtualController.Button.Start));
                options.Items.Add(new ButtonOptionItem(VirtualController.Button.System));
                options.Items.Add(new ButtonOptionItem(VirtualController.Button.LeftAnalog));
                options.Items.Add(new ButtonOptionItem(VirtualController.Button.RightAnalog));

                VirtualController.Button b = (VirtualController.Button)Enum.Parse(typeof(VirtualController.Button), dest);
                foreach (var o in options.Items)
                {
                    if ((o as ButtonOptionItem).Button == b)
                    {
                        options.SelectedItem = o;
                        break;
                    }
                }

                gestureOptions.Show();
                lblGesture.Show();

                int gestureID = -1;

                if (gesture == "" || gesture == null || gesture == "Link")
                {
                    gestureID = 0;
                }
                else if (gesture == "Tap")
                {
                    gestureID = 1;
                }
                else if (gesture == "DoubleTap")
                {
                    gestureID = 2;
                }
                else if (gesture == "Hold")
                {
                    gestureID = 3;
                }

                gestureOptions.SelectedIndex = gestureID;
            }
            else
            {
                lblSource.Text = "Axis: " + source.Substring("axis:".Length);
                isAxis         = true;

                options.Items.Add(new AxisOptionItem(VirtualController.Axis.LeftX));
                options.Items.Add(new AxisOptionItem(VirtualController.Axis.LeftY));
                options.Items.Add(new AxisOptionItem(VirtualController.Axis.RightX));
                options.Items.Add(new AxisOptionItem(VirtualController.Axis.RightY));
                options.Items.Add(new AxisOptionItem(VirtualController.Axis.DigitalX));
                options.Items.Add(new AxisOptionItem(VirtualController.Axis.DigitalY));
                options.Items.Add(new AxisOptionItem(VirtualController.Axis.Trigger));

                VirtualController.Axis a = (VirtualController.Axis)Enum.Parse(typeof(VirtualController.Axis), dest);
                foreach (var o in options.Items)
                {
                    if ((o as AxisOptionItem).Axis == a)
                    {
                        options.SelectedItem = o;
                        break;
                    }
                }
                gestureOptions.Hide();
                lblGesture.Hide();
            }
        }
Esempio n. 15
0
 public CapturedInput(VirtualController.Button button)
 {
     Button = button;
 }
Esempio n. 16
0
 public CapturedInput(VirtualController.Button button, ButtonActions.Gesture gesture)
 {
     Button        = button;
     ButtonGesture = gesture;
 }
Esempio n. 17
0
 public CapturedInput(VirtualController.Button button, ButtonActions.Gesture gesture)
 {
     Button = button;
     ButtonGesture = gesture;
 }
Esempio n. 18
0
 public CapturedInput(VirtualController.Button button)
 {
     Button = button;
 }
Esempio n. 19
0
        private void startBtn_Click(object sender, EventArgs e)
        {
            if (page == 1)
            {
                page = 2;
                page2.BringToFront();
                pbar.Visible     = true;
                startBtn.Enabled = false;
                startBtn.Text    = "Finish";
                ButtonSpot[] buttonSpots = new[] {
                    new ButtonSpot(VirtualController.Button.Bl, 70, 119),
                    new ButtonSpot(VirtualController.Button.Br, 199, 119),
                    new ButtonSpot(VirtualController.Button.Tl, 70, 91),
                    new ButtonSpot(VirtualController.Button.Tr, 199, 91),
                    new ButtonSpot(VirtualController.Button.A, 204, 86),
                    new ButtonSpot(VirtualController.Button.B, 222, 67),
                    new ButtonSpot(VirtualController.Button.X, 185, 67),
                    new ButtonSpot(VirtualController.Button.Y, 204, 49),
                    new ButtonSpot(VirtualController.Button.Start, 160, 69),
                    new ButtonSpot(VirtualController.Button.Back, 110, 69),
                    new ButtonSpot(VirtualController.Button.System, 135, 69),
                    new ButtonSpot(VirtualController.Button.LeftAnalog, 67, 67),
                    new ButtonSpot(VirtualController.Button.RightAnalog, 167, 107),
                };

                AxisSpot[] axisSpots = new[] {
                    new AxisSpot(VirtualController.Axis.Trigger, 70, 91),
                    new AxisSpot(VirtualController.Axis.LeftY, 67, 53),
                    new AxisSpot(VirtualController.Axis.LeftX, 52, 65),
                    new AxisSpot(VirtualController.Axis.DigitalY, 99, 94),
                    new AxisSpot(VirtualController.Axis.DigitalX, 85, 108),
                    new AxisSpot(VirtualController.Axis.RightY, 167, 94),
                    new AxisSpot(VirtualController.Axis.RightX, 154, 107),
                };

                // Adjust by the design-time location of the image...
                var pos = new Point(13, 25);

                foreach (var spot in buttonSpots)
                {
                    spot.X -= pos.X;
                    spot.Y -= pos.Y;
                }

                foreach (var spot in axisSpots)
                {
                    spot.X -= pos.X;
                    spot.Y -= pos.Y;
                }

                front.Hide();
                remainingBtnSpots = new List <ButtonSpot>();
                remainingBtnSpots.AddRange(buttonSpots);
                remainingAxisSpots = new List <AxisSpot>();
                remainingAxisSpots.AddRange(axisSpots);

                foreach (var btn in Controller.Device.Buttons)
                {
                    btn.PressReceived += buttonPressed;
                }

                foreach (var axis in Controller.Device.Axes)
                {
                    axis.EnableGestures = true;
                    axis.PositivePress += axisPressed;
                    axis.NegativePress += axisPressed;
                }

                Controller.Virtual.Enabled = false;

                indicator.Tag      = "on";
                indicator.Location = new Point(front.Left + remainingBtnSpots[0].X, front.Top + remainingBtnSpots[0].Y);

                progress.Text    += " - Product: " + Controller.Device.ProductName + "\n";
                noHaveBtn.Enabled = true;
            }
            else
            {
                Controller.Virtual.Enabled = true;

                foreach (var btn in Controller.Device.Buttons)
                {
                    btn.PressReceived -= buttonPressed;
                }

                foreach (var axis in Controller.Device.Axes)
                {
                    axis.EnableGestures = false;
                    axis.PositivePress -= axisPressed;
                    axis.NegativePress -= axisPressed;
                }

                GamepadConfig gpc      = new GamepadConfig();
                string        deviceID = Controller.Device.VendorID.ToString("X4") + Controller.Device.ProductID.ToString("X4");
                gpc.DeviceID = "0x" + deviceID.ToLower();
                gpc.Mappings = mappings;
                gpc.Notes    = "Created by Pad Tie's Mapping Wizard!";
                gpc.Product  = Controller.Device.ProductName;
                gpc.Vendor   = "";
                var    myModcumentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                var    gpcFolder          = Path.Combine("Pad Tie", "gamepads");
                string fileName           = Path.Combine(Path.Combine(myModcumentsFolder, gpcFolder), gpc.DeviceID + ".xml");

                if (!Directory.Exists(Path.GetDirectoryName(fileName)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(fileName));
                }

                if (File.Exists(fileName))
                {
                    fileName = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "gamepads");
                    fileName = Path.Combine(fileName, gpc.DeviceID + "-autogen.xml");
                }

                try {
                    gpc.Save(fileName);
                } catch (UnauthorizedAccessException e2) {
                    MessageBox.Show("Failed to save mapping for later use. Your gamepad will still work. Message: " + e2.Message);
                }

                if (sendPermission.Checked)
                {
                    SendConfig(gpc, fileName);
                }


                Controller.DeviceConfig.Mappings = gpc.Mappings;
                //Controller.Device.Reset();

                foreach (var dm in gpc.Mappings)
                {
                    if (dm.Source.StartsWith("button:"))
                    {
                        int btn = int.Parse(dm.Source.Substring("button:".Length));
                        VirtualController.Button b = (VirtualController.Button)Enum.Parse(typeof(VirtualController.Button), dm.Destination);
                        var ba = new VirtualController.ButtonAction(Controller.Virtual, b);

                        if (dm.Gesture != "Link" && dm.Gesture != "" && dm.Gesture != null)
                        {
                            // We need to enable gesture support at the device level for this button
                            Controller.Device.Buttons[btn].EnableGestures = true;
                        }

                        switch (dm.Gesture)
                        {
                        case "Link":
                        case null:
                        case "":
                            Controller.Device.Buttons[btn].Link = ba;
                            break;

                        case "Tap":
                            Controller.Device.Buttons[btn].Tap = ba;
                            break;

                        case "DoubleTap":
                            Controller.Device.Buttons[btn].DoubleTap = ba;
                            break;

                        case "Hold":
                            Controller.Device.Buttons[btn].Hold = ba;
                            break;
                        }
                    }
                    else
                    {
                        int axis = int.Parse(dm.Source.Substring("axis:".Length));
                        VirtualController.Axis a = (VirtualController.Axis)Enum.Parse(typeof(VirtualController.Axis), dm.Destination);
                        Controller.Device.Axes[axis].Analog = new VirtualController.AxisAction(Controller.Virtual, a);
                    }
                }
                MainForm.GlobalConfig.Save();
                this.Close();
            }
        }