[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: Patch : cursor follow the mouse



Le 25/03/2014 10:03, Adam H a Ãcrit :
This might relate in some small way, but I also play Go (a 3k-4k year old board game of Chinese origins (Go is the Japanese name)), and miss-clicking is a common-problem when playing on the internet.

One program I play on solved this problem by applying the "click" when the mouse button is released instead of when it's pressed. If a player simply released the button, the action was completed, but if a player accidentally clicked the button, they had the opportunity of moving the mouse away from the area of operation thereby cancelling the action before releasing the button.

Something similar could be adapted if the problem is miss-clicking. However, if it's not, please treat this information as trivia.


Hello,

I've taken you'r idea and change the patch :

- the cursor postion is not updated if the user press left mouse button during the move.
- the action is no longer triggered on mouse down but mouse up. Then the code check if the cursor is still at is initial position, and cancel the action if not.

Tell me if it is satisfing for you.

--
SÃbastien

diff -urNp crimson-0.5.3_orig/src/cf/game.cpp crimson-0.5.3_patch/src/cf/game.cpp
--- crimson-0.5.3_orig/src/cf/game.cpp	2007-06-24 17:30:18.000000000 +0200
+++ crimson-0.5.3_patch/src/cf/game.cpp	2014-03-25 22:23:20.000000000 +0100
@@ -1459,11 +1459,22 @@ GUI_Status Game::HandleEvent( const SDL_
       break;
     }
 
-  } else if ( event.type == SDL_MOUSEBUTTONDOWN ) {
+  } else if (event.type == SDL_MOUSEMOTION ) {
+    if(!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1)) {
+      Point pos;
+      if ( !mv->Pixel2Hex( event.button.x - mwin->x, event.button.y - mwin->y, pos ) ) {
+        // Update the cursor position if the mouse has moved.
+        if (mv->Cursor() != pos) SetCursor( pos );
+      }
+    }
+  } else if ( event.type == SDL_MOUSEBUTTONUP) {
     Point pos;
     if ( event.button.button == SDL_BUTTON_LEFT ) {
       if ( !mv->Pixel2Hex( event.button.x - mwin->x, event.button.y - mwin->y, pos ) ) {
-        HandleLMB( pos );
+        // If the mouse didn't moved during the click, do the appropriate 
+        // action, otherwise just update the cursor position.
+        if (mv->Cursor() == pos) HandleLMB( pos );
+        else SetCursor( pos );
       }
     } else if ( !mv->Pixel2Hex( event.button.x - mwin->x, event.button.y - mwin->y, pos ) ) {
       Unit *u = map.GetUnit( pos );