in reply to Re: Masking Tk Canvas
in thread Masking Tk Canvas

Ok, I agree. I wasn't quite clear. So.. let me explain it in more details. Imagine you have a canvas, on which you just create a pattern of PNG files with Alpha transparency (ei. background is transparent). Then you want to create a second pattern that is like - a second layer with another PNG. But you want to mask it (ie crop the layer with an rectangular shape) so you can move the contents of it inside the mask. Perhaps because my English is not great, I just created a small Flash demonstration that will give you an idea... I am not sure whether a normal canvas can mask like this.... have a look here

Replies are listed 'Best First'.
Re^3: Masking Tk Canvas
by zentara (Cardinal) on Sep 18, 2005 at 10:51 UTC
    I looked at your flash, and wasn't sure exactly what it was supposed to do, different from what I suggested earlier. Also the text in the "floater" seemed to move around inside the rectangle as the rectangle moved. I don't know if that was one of the things you want to accomplish, probably not. Also, I did not see any "transparency effects" in your flash.

    But setting aside the transparency and alpha-layering stuff, which I'm not sure about in Tk, you could simulate your flash in Tk, by just creating an a new 'image' on your existing canvas, and setting tags on it, to make it "draggable".

    Perhaps, if you told us what this is supposed to perform, it would be easier. Are you trying to "custom-drag" images to positions on a canvas, to build a new composite image?

    I have seen one other thing which may be what you are looking for. It's in the TkZinc demo, and is called the "magic lens", (it is #6 under Small Applications).


    I'm not really a human, but I play one on earth. flash japh
      Yeah. Basicaly I need the internal movement. I just want to create a layer in the same canvas with rectangular shape which contains much more than the rectangle and then move the contents in the second layer. 1st the contents itself that has been masked and second- the whole layer - which consists of this rectangle masking. I agree about Zinc, I've seen the zooming glass. The idea is the following, I am trying to make a single canvas in which I want to have sort of a background pattern and then a second (may be canvas) layer that has image items which must be scrolled in pages (like a list). I don't think this can be acheived trough the ordinary canvas (Tk::Canvas) using only one canvas widget, that's why I am thinking that the best is to create a second widget and use ->place geometry manager to possition it relatively from the 0,0 of the background canvas... The problem that comes with this is that there is no way to make the background of the second canvas transparent so the user can see trought the top widget wherever there is no content - the bottom widget. I am not showing this in the flash sample... Anyway... Thanks a lot for the reply. I've been just wandering whether something like canvas in canvas can be acheived using the standard Tk canvas. :) Thanks again!!!
        I understand better now, what you want to do. In the Tk widgets demo, there is an example called "tiles and transparent images". That should give you a start.

        You are probably really pushing the limits of what the ordinary Canvas can do, if you start moving things around, and expect the transparency to update itself without distortions. I would switch to Zinc. It has better 'group' support and many other improvements over Canvas, that would make your job easier.

        And forget the second canvas idea. You won't be able to see thru it, without faking it, by taking what is currently below it, and mirroring it above. You can check out Zinc - Star Wars Scrolling Text for an idea of what Zinc can do, you can add images to the background(or scroll) if you wanted, or make everything draggable.


        I'm not really a human, but I play one on earth. flash japh