From 013098f885c5e7cb05cb9f362b051b17e867ad29 Mon Sep 17 00:00:00 2001 From: David Khachaturov Date: Tue, 7 Apr 2020 09:43:51 +0100 Subject: [PATCH] - Fixed "reset to default" bug - Added right-click option on mapping buttons to select joycon buttons (does not yet fire them) --- .gitignore | 2 + BetterJoyForCemu/Reassign.Designer.cs | 94 +++++++++++++++++++++------ BetterJoyForCemu/Reassign.cs | 29 ++++++++- 3 files changed, 102 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index c279e3d..f6ccc5c 100644 --- a/.gitignore +++ b/.gitignore @@ -261,3 +261,5 @@ __pycache__/ *.pyc /BetterJoyForCemu/FodyWeavers.xml /BetterJoyForCemu/FodyWeavers.xsd +/title.png +/title.pdn diff --git a/BetterJoyForCemu/Reassign.Designer.cs b/BetterJoyForCemu/Reassign.Designer.cs index 71d24dd..b76b286 100644 --- a/BetterJoyForCemu/Reassign.Designer.cs +++ b/BetterJoyForCemu/Reassign.Designer.cs @@ -1,4 +1,59 @@ -namespace BetterJoyForCemu { +using System.ComponentModel; +using System.Drawing; +using System.Drawing.Drawing2D; +using System.Windows.Forms; + +namespace BetterJoyForCemu { + public class SplitButton : Button { + [DefaultValue(null), Browsable(true), + DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public ContextMenuStrip Menu { get; set; } + + [DefaultValue(20), Browsable(true), + DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public int SplitWidth { get; set; } + + public SplitButton() { + SplitWidth = 20; + } + + protected override void OnMouseDown(MouseEventArgs mevent) { + var splitRect = new Rectangle(this.Width - this.SplitWidth, 0, this.SplitWidth, this.Height); + + // Figure out if the button click was on the button itself or the menu split + if (Menu != null && + ((mevent.Button == MouseButtons.Left && + splitRect.Contains(mevent.Location)) || mevent.Button == MouseButtons.Right)) { + Menu.Tag = this; + Menu.Show(this, 0, this.Height); // Shows menu under button + } else { + base.OnMouseDown(mevent); + } + } + + protected override void OnPaint(PaintEventArgs pevent) { + base.OnPaint(pevent); + + if (this.Menu != null && this.SplitWidth > 0) { + // Draw the arrow glyph on the right side of the button + int arrowX = ClientRectangle.Width - 14; + int arrowY = ClientRectangle.Height / 2 - 1; + + var arrowBrush = Enabled ? SystemBrushes.ControlText : SystemBrushes.ButtonShadow; + var arrows = new[] { new Point(arrowX, arrowY), new Point(arrowX + 7, arrowY), new Point(arrowX + 3, arrowY + 4) }; + pevent.Graphics.FillPolygon(arrowBrush, arrows); + + // Draw a dashed separator on the left of the arrow + int lineX = ClientRectangle.Width - this.SplitWidth; + int lineYFrom = arrowY - 4; + int lineYTo = arrowY + 8; + using (var separatorPen = new Pen(Brushes.DarkGray) { DashStyle = DashStyle.Dot }) { + pevent.Graphics.DrawLine(separatorPen, lineX, lineYFrom, lineX, lineYTo); + } + } + } + } + partial class Reassign { /// /// Required designer variable. @@ -25,23 +80,23 @@ private void InitializeComponent() { this.components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Reassign)); - this.btn_capture = new System.Windows.Forms.Button(); + this.btn_capture = new SplitButton(); this.lbl_capture = new System.Windows.Forms.Label(); this.lbl_home = new System.Windows.Forms.Label(); - this.btn_home = new System.Windows.Forms.Button(); + this.btn_home = new SplitButton(); this.lbl_sl_l = new System.Windows.Forms.Label(); - this.btn_sl_l = new System.Windows.Forms.Button(); + this.btn_sl_l = new SplitButton(); this.lbl_sr_l = new System.Windows.Forms.Label(); - this.btn_sr_l = new System.Windows.Forms.Button(); + this.btn_sr_l = new SplitButton(); this.lbl_sl_r = new System.Windows.Forms.Label(); - this.btn_sl_r = new System.Windows.Forms.Button(); + this.btn_sl_r = new SplitButton(); this.lbl_sr_r = new System.Windows.Forms.Label(); - this.btn_sr_r = new System.Windows.Forms.Button(); - this.btn_close = new System.Windows.Forms.Button(); - this.btn_apply = new System.Windows.Forms.Button(); + this.btn_sr_r = new SplitButton(); + this.btn_close = new SplitButton(); + this.btn_apply = new SplitButton(); this.tip_reassign = new System.Windows.Forms.ToolTip(this.components); this.lbl_reset_mouse = new System.Windows.Forms.Label(); - this.btn_reset_mouse = new System.Windows.Forms.Button(); + this.btn_reset_mouse = new SplitButton(); this.SuspendLayout(); // // btn_capture @@ -184,7 +239,6 @@ // // btn_reset_mouse // - this.btn_reset_mouse.Enabled = false; this.btn_reset_mouse.Location = new System.Drawing.Point(105, 186); this.btn_reset_mouse.Name = "btn_reset_mouse"; this.btn_reset_mouse.Size = new System.Drawing.Size(75, 23); @@ -227,22 +281,22 @@ #endregion - private System.Windows.Forms.Button btn_capture; + private SplitButton btn_capture; private System.Windows.Forms.Label lbl_capture; private System.Windows.Forms.Label lbl_home; - private System.Windows.Forms.Button btn_home; + private SplitButton btn_home; private System.Windows.Forms.Label lbl_sl_l; - private System.Windows.Forms.Button btn_sl_l; + private SplitButton btn_sl_l; private System.Windows.Forms.Label lbl_sr_l; - private System.Windows.Forms.Button btn_sr_l; + private SplitButton btn_sr_l; private System.Windows.Forms.Label lbl_sl_r; - private System.Windows.Forms.Button btn_sl_r; + private SplitButton btn_sl_r; private System.Windows.Forms.Label lbl_sr_r; - private System.Windows.Forms.Button btn_sr_r; - private System.Windows.Forms.Button btn_close; - private System.Windows.Forms.Button btn_apply; + private SplitButton btn_sr_r; + private SplitButton btn_close; + private SplitButton btn_apply; private System.Windows.Forms.ToolTip tip_reassign; private System.Windows.Forms.Label lbl_reset_mouse; - private System.Windows.Forms.Button btn_reset_mouse; + private SplitButton btn_reset_mouse; } } \ No newline at end of file diff --git a/BetterJoyForCemu/Reassign.cs b/BetterJoyForCemu/Reassign.cs index acf1f6c..7e6de89 100644 --- a/BetterJoyForCemu/Reassign.cs +++ b/BetterJoyForCemu/Reassign.cs @@ -14,23 +14,44 @@ namespace BetterJoyForCemu { private WindowsInput.Events.Sources.IKeyboardEventSource keyboard; private WindowsInput.Events.Sources.IMouseEventSource mouse; + ContextMenuStrip menu_joy_buttons = new ContextMenuStrip(); + private Control curAssignment; public Reassign() { InitializeComponent(); - foreach (Control c in new Control[] { btn_capture, btn_home, btn_sl_l, btn_sl_r, btn_sr_l, btn_sr_r, btn_reset_mouse }) { + foreach (int i in Enum.GetValues(typeof(Joycon.Button))) { + ToolStripMenuItem temp = new ToolStripMenuItem(Enum.GetName(typeof(Joycon.Button), i)); + temp.Tag = i; + menu_joy_buttons.Items.Add(temp); + } + + menu_joy_buttons.ItemClicked += Menu_joy_buttons_ItemClicked; + + foreach (SplitButton c in new SplitButton[] { btn_capture, btn_home, btn_sl_l, btn_sl_r, btn_sr_l, btn_sr_r, btn_reset_mouse }) { c.Tag = c.Name.Substring(4); GetPrettyName(c); tip_reassign.SetToolTip(c, "Left-click to detect input.\r\nMiddle-click to clear to default.\r\nRight-click to see more options."); c.MouseDown += Remap; + c.Menu = menu_joy_buttons; + c.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; } } + private void Menu_joy_buttons_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { + Control c = sender as Control; + + ToolStripItem clickedItem = e.ClickedItem; + + SplitButton caller = (SplitButton)c.Tag; + Config.SetValue((string)caller.Tag, "joy_" + (clickedItem.Tag)); + GetPrettyName(caller); + } + private void Remap(object sender, MouseEventArgs e) { - Button c = sender as Button; - Debug.WriteLine(e.Button); + SplitButton c = sender as SplitButton; switch (e.Button) { case MouseButtons.Left: c.Text = "..."; @@ -87,6 +108,8 @@ namespace BetterJoyForCemu { case "0": if (c == btn_home) c.Text = "Guide"; + else + c.Text = ""; break; default: Type t = val.StartsWith("joy_") ? typeof(Joycon.Button) : (val.StartsWith("key_") ? typeof(WindowsInput.Events.KeyCode) : typeof(WindowsInput.Events.ButtonCode));