Fixed off-by-one error in mouse button bit-masking#177
Merged
chrisdone merged 1 commit intohaskell-game:masterfrom Apr 26, 2018
Merged
Fixed off-by-one error in mouse button bit-masking#177chrisdone merged 1 commit intohaskell-game:masterfrom
chrisdone merged 1 commit intohaskell-game:masterfrom
Conversation
Member
|
Pity it's hard to make a test suite for this! |
Member
|
Thanks! |
Author
|
Thanks for pulling this. When will it be on Hackage? There is no workaround for detecting the left mouse button with the current version. I either have to distribute my own version or use a different, much less popular button. |
Member
|
I'll try and cut a release soon - I'll add a reminder. |
Author
|
What's the status of this? |
Member
|
Just to update others, this is released as 2.4.1.0. |
Member
|
Cheers Ollie
…On Thu, 5 Jul 2018 at 11:19, Oliver Charles ***@***.***> wrote:
Just to update others, this is released as 2.4.1.0.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#177 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAArC5lnhyrS7Cz4Cz_t9NGtLY2TBPSfks5uDegYgaJpZM4TZTba>
.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
getMouseButtonsdetects the wrong buttons because its bit mask doesn't match SDL's convention. For example, it's impossible to detect the left mouse button being held.getMouseState, likeSDL_GetMouseState, produces a set of Boolean flags encoded as the bits of an integer. We test the nth flag by AND-ing that integer with a bit mask: the integer 1 bit-shifted by n places.The state of the left mouse button resides in the lowest-order bit—0 places away from the lowest place. So, to test that button we have to bit-shift by 0 places.
SDL provides the macro definitions
SDL_BUTTON(X)andSDL_BUTTON_LEFTto do that bit-shifting. It definesSDL_BUTTON_LEFTto be 1, not 0, and it definesSDL_BUTTON(X)to subtract 1 from its argument before using it to construct the bit mask (see lines 203-204 in SDL_mouse.h):So,
&& SDL_BUTTON( SDL_BUTTON_LEFT )=&& (1 << (1 - 1))=&& (1 << 0), which is what we want.However, the corresponding Haskell provisions don't match that convention.
Raw.SDL_BUTTON_LEFT(and hencetoNumber ButtonLeft) is defined to be 1, butgetMouseButtonsdoesn't do the same subtraction asSDL_BUTTON(X):Here,
(`testBit` fromIntegral (toNumber ButtonLeft))=(`testBit` 1), but that doesn't test the left button. We want(`testBit` 0).