I am working on a project that plotting the mouse tracking. The MouseInfo
class is defined like:
public class MouseInfo {
public readonly long TimeStamp;
public readonly int PosX;
public readonly int PosY;
public int ButtonsDownFlag;
}
I need to find a way to extract the mouse positions from a List<MouseInfo>
which ButtonsDownFlag
has at least 2 continuous 1
s and group them together, so that I can distinguish clicks and draggings, which will then being used for plotting.
The current way I am doing is to iterate through the list, and add the found values one by one to other lists, which is very slow, expensive and the code looks messy. I wonder if there is any more elegant way to do it? Will Linq
help?
For example, I have the recording of below:
(t1, x1, y1, 0)
(t2, x2, y2, 1)
(t3, x3, y3, 1)
(t4, x4, y4, 0)
(t5, x5, y5, 1)
(t6, x6, y6, 0)
(t7, x7, y7, 1)
(t8, x8, y8, 1)
(t9, x9, y9, 1)
(ta, xa, ya, 0)
(tb, xb, yb, 2) <- Yes, ButtonDownFlag can be 2 for RightClicks or even 3 for both buttons are down
(tc, xc, yc, 0)
(td, xd, yd, 2)
(te, xe, ye, 2)
I want two Lists (or similiar presentation) which are
((t2, x2, y2), (t2, x3, y3), (t7, x7, y7), (t7, x8, y8), (t7, x9, y9))
and
((x5, y5, 1), (xb, yb, 2), (xd, yd, 2), (xe, ye, 2))
Note:
- In the first list, I need
TimeStamp
in the subsequence elements being altered to the first element'sTimeStamp
, so that I can group in later plotting. - In the second list, I don't care
TimeStamp
but I do care theButtonDownFlag
- I don't mind if
ButtonDownFlag
exists in the first list, norTimeStamp
exists in the second list. - Continuous "Right Clicks" are treated as separate "Right Clicks" rather than "Right dragging".