Skip to content

Commit

Permalink
added option to emulate click in mouse provider
Browse files Browse the repository at this point in the history
  • Loading branch information
RonenNess committed Mar 22, 2024
1 parent 9720c26 commit 8de5b60
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
13 changes: 11 additions & 2 deletions GeonBit.UI.Examples/GeonBitUI_Examples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
using GeonBit.UI.Entities.TextValidators;
using GeonBit.UI.DataTypes;
using GeonBit.UI.Utils.Forms;
using System.Diagnostics;

namespace GeonBit.UI.Examples
{
Expand Down Expand Up @@ -141,13 +142,21 @@ protected void InitExamplesAndUI()
Button showGitButton = new Button("Git Repo", ButtonSkin.Fancy, Anchor.TopCenter, new Vector2(280, topPanelHeight));
showGitButton.OnClick = (Entity btn) =>
{
var url = "https://github.com/RonenNess/GeonBit.UI";
try
{
System.Diagnostics.Process.Start("https://github.com/RonenNess/GeonBit.UI");
Process.Start(url);
}
catch
{
System.Diagnostics.Process.Start("IExplore", "https://github.com/RonenNess/GeonBit.UI");
try
{
Process.Start("IExplore", url);
}
catch
{
Process.Start(new ProcessStartInfo(url) { UseShellExecute = true });
}
}
};
topPanel.AddChild(showGitButton);
Expand Down
18 changes: 18 additions & 0 deletions GeonBit.UI/Source/Input/DefaultInputProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// Since: 2016.
//-----------------------------------------------------------------------------
#endregion
using GeonBit.UI.Entities;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

Expand Down Expand Up @@ -64,6 +65,9 @@ public class DefaultInputProvider : IMouseInput, IKeyboardInput
/// </summary>
public int MouseWheelChange { get; private set; }

// if true, will perform a click event next update
bool _clickNextUpdate = false;

/// <summary>
/// Create the input helper.
/// </summary>
Expand Down Expand Up @@ -109,6 +113,12 @@ public void Update(GameTime gameTime)
_newMouseState = Mouse.GetState();
_newKeyboardState = Keyboard.GetState();

// perform click emulation
if (_clickNextUpdate) {
_newMouseState = new MouseState(_newMouseState.X, _newMouseState.Y, _newMouseState.ScrollWheelValue, ButtonState.Pressed, _newMouseState.MiddleButton, _newMouseState.RightButton, _newMouseState.XButton1, _newMouseState.XButton2, _newMouseState.HorizontalScrollWheelValue);
_clickNextUpdate = false;
}

// get mouse position
_oldMousePos = _newMousePos;
_newMousePos = new Vector2(_newMouseState.X, _newMouseState.Y);
Expand Down Expand Up @@ -148,6 +158,14 @@ public void Update(GameTime gameTime)
}
}

/// <summary>
/// Perform click next update frame.
/// </summary>
public void DoClick()
{
_clickNextUpdate = true;
}

/// <summary>
/// Move the cursor to be at the center of the screen.
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions GeonBit.UI/Source/Input/IMouseInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ public interface IMouseInput
/// <returns>True if any mouse button was released.</returns>
bool AnyMouseButtonReleased();

/// <summary>
/// Perform click next update frame.
/// </summary>
void DoClick();

/// <summary>
/// Current mouse wheel value.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion GeonBit.UI/Source/UserInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public enum BuiltinThemes
public class UserInterface : System.IDisposable
{
/// <summary>Current GeonBit.UI version identifier.</summary>
public const string VERSION = "4.3.0.2";
public const string VERSION = "4.3.0.3";

/// <summary>
/// The currently active user interface instance.
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2106,6 +2106,11 @@ If you want to use the new files dialog, you must include the new textures that
- Fixed number validators to not allow spaces.
- Added example for text validators.

### 4.3.0.3

- Added option to emulate mouse click via the mouse input provider.
- Fixed repo link in demo project.

## Credits

GeonBit.UI was written by Ronen Ness, but uses some free textures made by awesome people who share their work for free.
Expand Down

0 comments on commit 8de5b60

Please sign in to comment.