in reply to Perl Tk Canvas and buckets of items

You could just draw a suitable image that displays the grid of "cells" properly (draw a bunch of rectangles all having the desired width and height, with different colors depending on their initial states), and then use arithmetic on the mouse position to identify which cell was under the mouse when there was a click (or, more carefully, to determine whether the button-down and button-up events were within the same cell, and which cell that was).

You wouldn't need to use tags at all, if the column and row dimensions are fixed (or at least, a fixed proportion relative to the actual size of the canvas). Just grab the mouse coordinates on the button-down and button-up events, and quantize these wrt the cell width and height to determine which row and column holds the cell. Keep a separate 2-D data array to hold the current state of each cell, and as you update that array according to mouse actions, simply redraw the given rectangle with some suitable color to illustrate the change of state on that cell.

If you prefer to use images to illustrate the various states of cells (could get a bit noisy, visually, but you can be the judge of that), then presumably the set of states/images is fairly small, and copying a small rectangular image to a given x,y position is not that different from drawing a solid color rectangle at that position.

update: this made me think about "well, what are tags good for, then?" I think what they are good for are cases where the canvas may contain overlapping objects, and when someone clicks a position occupied by two or more objects, you get to see how many objects are involved, and which ones. But that doesn't seem to apply in your case, so you shouldn't bother with tags.

  • Comment on Re: Perl Tk Canvas and buckets of items

Replies are listed 'Best First'.
Re: Re: Perl Tk Canvas and buckets of items
by herveus (Prior) on Aug 22, 2003 at 14:27 UTC
    Howdy!

    Tags let me refer to all the items in a column at once (by giving them a "colX" tag for various values of X). Tags also let me logically group items that are scattered about the canvas.

    In my particular application, the column dimensions are stable (may be user adjustable, but all the same size). The cells will not be all the same height, so "rows" do not exist as a concept (or at best, weakly).

    The set of states/images is fairly small. The display is all visual, so the "noise" is not an issue.

    Thanks for the thoughts, even if I cruelly reject them *grin*

    yours,
    Michael