drag-selection in kfm

I didn’t get anything done on KFM over the weekend (was concentrating on figuring out that IMAP problem), so I felt a bit guilty and did some work today.

I wrote a drag-selection method, which allows you to select files by dragging a rectangle around them.

It’s surprising how many different variables need to be considered, to decide whether a file is selected or not!

For instance, here is the if block which decides whether a file is contained in a selection area, or is touched by it:


In the above, [x1,y1] and [x2,y2] are the top-left and bottom-right of the selection area, and [x3,y3] and [x4,y4] are the top-left and bottom-right of the file icons.

I’m sure there must be a more efficient way than that!

Actually, the code I wrote can easily be made more efficient by applying a binary tree algorithm to find the first and last icons which should be considered at all (if the selection starts at [100,343] for example, then all icons with y4<343 can be confidently pruned).

That’s the visible work for today. I’m going to take a short break, then get onto a bit of files house-keeping.

Oh – demo (use Firefox for best effect), and source.

Comments are closed.

%d bloggers like this: