On Tue, Feb 11, 2014 at 06:05:30PM -0800, gettimothy wrote:
To reverse a MorphicEvent into an primitive event I need to unmap the buttons and modifiers. In a primitive event, the fifth element (buttons) can be 1,2 or 4 and the sixth element (modifiers) 1,2,4 or 8.
HandMorph >> generateMouseEvent combines them into one field as such:
buttons := evtBuf fifth. modifiers := evtBuf sixth. buttons := buttons bitOr: (modifiers bitShift: 3).
I need to reverse that "buttons bitOr: (modifiers bitShift: 3)" back into the original values to recreate the primitive event. Here are the possible values of B(uttons) and M(odifiers) under that operation:
B M MAP 1 bitOr:(1 bitShift:3 ) 9 1 bitOr:(2 bitShift:3 ) 17 1 bitOr:(4 bitShift:3 ) 33 1 bitOr:(8 bitShift:3 ) 65
2 bitOr:(1 bitShift:3 ) 10 2 bitOr:(2 bitShift:3 ) 18 2 bitOr:(4 bitShift:3 ) 34 2 bitOr:(8 bitShift:3 ) 66
4 bitOr:(1 bitShift:3 ) 12 4 bitOr:(2 bitShift:3 ) 20 4 bitOr:(4 bitShift:3 ) 36 4 bitOr:(8 bitShift:3 ) 68
So, given a MAP on the right, I need to derive a B and a M.
I can figure something out, but it will probably be ugly. Hence, this email to the list. Any bit-fiddlers on the board who know an elegant method?
M is (MAP >> 3) and B is (MAP bitAnd: 7).
MAP M := MAP >> 3 B := MAP bitAnd: 7 9 1 1 17 2 1 33 4 1 65 8 1
10 1 2 18 2 2 34 4 2 66 8 2
12 1 4 20 2 4 36 4 4 68 8 4