Tk Library Source Code

View Ticket
Login
Ticket UUID: 3603562
Title: confine crosshair::crosshair to a canvas area
Type: RFE Version: None
Submitter: franktx Created on: 2013-02-06 14:07:50
Subsystem: tklib: crosshair Assigned To: andreas_kupries
Priority: 7 High Severity:
Status: Closed Last Modified: 2013-04-04 10:39:58
Resolution: Closed By: andreas_kupries
    Closed on: 2013-04-04 03:39:58
Description:
Hi,

Sorry but I could not find a crosshair category.

Currently the Tklib crosshair::crosshair  creates the crosshair in the whole canvas. To make this more flexible it would be better to have the ability to confine the crosshair to a location in the canvas (or a series of locations in a canvas).

In my case I am using PlotChart to create a series of plots. I would like to confine the crosshair in the plot area only. In other words I do not want the cross hairs to extend pass the axis of the graph and running over the plot labels and titles.

This enhancement can easily be done by passing the BBox (llx lly urx ury) to crosshair. Store the bbox in a crosshair name space variable and when drawing the lines in the move procedure use the bbox boundary as the start and end points of the lines drawn.

In the case of a series of locations in a canvas, the user can pass a list of BBoxes when the mouse pointer enters one of those areas the same approach will be done with the move procedure but in that case using the BBox associated with that area. Plotchart allows the user to put more than one plot in a canvas. Therefore this will be an even more versatil implementation of crosshair.

Thanks in advance,
Frank
User Comments: andreas_kupries added on 2013-04-04 10:39:58:

allow_comments - 1

This is in Tklib 0.6

andreas_kupries added on 2013-02-14 12:41:30:
Committed variant code handling multiple boxes.
See  http://core.tcl.tk/tklib/info/9382d1e073
Branch:  crosshair-bboxes-3603562

Notes: New flag hidden to explicitly track un/hide state.
Crosshairs which are out of bounds are destroyed (like it was done for hide only, before).
They are re-created on unhide and entering a visible area.

Visible area is the area of all of the bounding boxes.
Overlapping boxes are allowed as are nested boxes.

Crosshairs extend the largest amount they can based on all the boxes they are currently inside of.

Please test. (I already did, using examples/canvas/citygrid.tcl, see the new statements it has).
After it passes muster I will merge to trunk and release branches.

franktx added on 2013-02-08 09:30:48:
Hi Andreas,

I made the changes to the version from the SVN repository (uploaded here). The Crosshairs are confined to a bbox and they are hidden when the pointer moves out of the bbox. It seems to be working fine.

Handling more than one Bbox is not there but can be easily implemented. I think in place of passing a single BBox I will make it to pass a list of BBoxes. Then iterate through them. I don't think it should affect the performace too much. 

Regards,
Frank Gover

andreas_kupries added on 2013-02-08 00:33:27:
The slow-down might be an issue with the canvas itself getting sluggish for lots of items to display. Without having re-read the code I seem to remember that the cross-hair creates only 2 lines and then just moves them (i.e. changes coordinates). I do not believe that this can be made faster. Slower, yes, simply destroy and create the lines for each movement. I.e. new items for every change.

franktx added on 2013-02-07 13:36:19:
Hi Andreas,

I played a little with the original crosshair.tcl code. I added the crosshair::bbox proc and made a few changes. I'll try to get the latest code and make the changes there and I'll upload it too. 

At this time the code only works for one area of the canvas. I have some problems with the hide to work good as it gets triggered by the bind when it leaves the canvas versus the area. It looks pretty good just a little awkward. I may place the  Xhair in the lower left of the Bbox to hide it. 

The performance of the code slows down (the lines can not keep up with the mouse pointer) when there is a big number of points in the canvas. This is independent of the code that I added. I am not sure if there is a way to improve the performance.

Regards,
Frank Gover

franktx added on 2013-02-07 13:29:54:

File Added - 460241: crosshair.tcl

andreas_kupries added on 2013-02-07 00:34:57:
An interesting idea. Sensible also, given the use case.

Attachments: