Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Professional XNA Game Programming: For Xbox 360 and Windows ISBN: 978-0-470-12677-6
This is the forum to discuss the Wrox book Professional XNA Game Programming: For Xbox 360 and Windows by Benjamin Nitschke; ISBN: 9780470126776
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional XNA Game Programming: For Xbox 360 and Windows ISBN: 978-0-470-12677-6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old May 14th, 2007, 06:42 AM
Registered User
 
Join Date: May 2007
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Simulating Double Click...

I don't have the book yet ( though it's due to arrive today ), so appologies if this is covered in there )

I'm in the process of writing yet another XNA Input Manager that aggregates access to the GamePad, Keyboard and Mouse.
The classes fire off Down, Up and Clicked events respectively.

I'm in the process of completing the Mouse class and the only thing left is to handle double clicks. How have others coded this?


I've kept a variable that stores the last click and the time it was clicked then perform the following every time Update is called...

Code:
DoubleClicked = ( ( PreviousClicked && (CurrentState.LeftButton == ButtonState.Released && PreviousState.LeftButton == ButtonState.Pressed) ) && ( aGameTime.TotalGameTime.Milliseconds - PreviousGameTime < 100 ) );

if (DoubleClicked)
{
  // Fire off those events
  DoMouseDoubleClick();
}
else if (FCurrentState.LeftButton == ButtonState.Released && FPreviousState.LeftButton == ButtonState.Pressed)
{
  PreviousGameTime = aGameTime.TotalGameTime.Milliseconds;
  PreviousClicked = (FCurrentState.LeftButton == ButtonState.Released && FPreviousState.LeftButton == ButtonState.Pressed);
  // Fire off those events
  DoMouseClick();
}

but DoubleClicked is always false. Can anyone spot the flaw in my logic?


  #2 (permalink)  
Old May 14th, 2007, 10:41 AM
Registered User
 
Join Date: May 2007
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The code that seems to work for me is :
Code:
DoubleClicked = ( ( PreviousClicked && (CurrentState.LeftButton == ButtonState.Released && PreviousState.LeftButton == ButtonState.Pressed) ) && ( aGameTime.TotalGameTime.Milliseconds - PreviousGameTime < 250 ) );

if (DoubleClicked)
{
  // Fire off those events
  PreviousClicked = false;                        
  DoMouseDoubleClick();                   
}
else if (CurrentState.LeftButton == ButtonState.Released && PreviousState.LeftButton == ButtonState.Pressed)
{
  PreviousGameTime = aGameTime.TotalGameTime.Milliseconds;
  PreviousClicked = (CurrentState.LeftButton == ButtonState.Released && PreviousState.LeftButton == ButtonState.Pressed);       

  // Fire off those events
  DoMouseClick();
}
I hope this helps someone.



Similar Threads
Thread Thread Starter Forum Replies Last Post
Simulating button click using Win32 API in .NET debsoft C# 10 February 19th, 2008 11:06 AM
Simulate a double click? chobo2 C# 5 November 10th, 2007 06:15 AM
Right-Click or Double-Click Combobox? panuvin C# 2005 3 June 15th, 2006 04:30 PM
simulating click event simmohall BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 0 March 13th, 2005 06:28 PM
Double Click problem Merlin Java GUI 1 March 31st, 2004 10:15 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.