From eb6676e0ba9de6cdbf9938732953a0620b0f4618 Mon Sep 17 00:00:00 2001 From: Trivial-Man Date: Thu, 29 Jun 2017 19:59:27 -0600 Subject: [PATCH] EmuLuaLibrary.Forms: add more PictureBox functions Adds the functions for getting the mouse x and y coordinates from PictureBox components. --- .../Lua/Libraries/EmuLuaLibrary.Forms.cs | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Forms.cs b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Forms.cs index 337802fa49..3dce8ffc63 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Forms.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Forms.cs @@ -1136,6 +1136,75 @@ namespace BizHawk.Client.EmuHawk } } + // It'd be great if these were simplified into 1 function, but I cannot figure out how to return a LuaTable from this class + [LuaMethodAttributes( + "GetMouseX", + "Returns an integer representation of the mouse X coordinate relative to the PictureBox.")] + public int GetMouseX(int componentHandle) + { + try + { + var ptr = new IntPtr(componentHandle); + foreach (var form in _luaForms) + { + if (form.Handle == ptr) + { + ConsoleLuaLibrary.Log("Drawing functions cannot be used on forms directly. Use them on a PictureBox component."); + return 0; + } + + foreach (Control control in form.Controls) + { + if (control is LuaPictureBox) + { + var position = (control as LuaPictureBox).GetMouse(); + return position.X; + } + } + } + } + catch (Exception ex) + { + ConsoleLuaLibrary.Log(ex.Message); + } + + return 0; + } + + [LuaMethodAttributes( + "GetMouseY", + "Returns an integer representation of the mouse Y coordinate relative to the PictureBox.")] + public int GetMouseY(int componentHandle) + { + try + { + var ptr = new IntPtr(componentHandle); + foreach (var form in _luaForms) + { + if (form.Handle == ptr) + { + ConsoleLuaLibrary.Log("Drawing functions cannot be used on forms directly. Use them on a PictureBox component."); + return 0; + } + + foreach (Control control in form.Controls) + { + if (control is LuaPictureBox) + { + var position = (control as LuaPictureBox).GetMouse(); + return position.Y; + } + } + } + } + catch (Exception ex) + { + ConsoleLuaLibrary.Log(ex.Message); + } + + return 0; + } + #endregion [LuaMethodAttributes("setdropdownitems", "Sets the items for a given dropdown box")]