in reply to Re: Total Newbies TkZinc questions
in thread Total Newbies TkZinc questions

Answering my own questions, indeed it took a few hours to figure out ;-) The dragging issue is solved by the zinc->transform() command, like magic! Here is some pseudocode in case someone else ponders this, I suppose it's obvious to the gurus.. :-\

# -- PSEUDOCODE, DOES NOT WORK -- my ($dx, $dy); sub mobile_start { my $ev = $zinc->XEvent; ($dx, $dy) = $zinc->transform(1, $scaled_group, [$ev->x, $ev->y]); } sub mobile_move { my $ev = $zinc->XEvent; my ($tr_evx, $tr_evy) = $zinc->transform(1, $scaled_group, [$ev->x, +$ev->y]); $zinc->translate($some_group, $tr_evx-$dx, $tr_evy-$dy); ($dx, $dy) = ($tr_evx, $tr_evy); }

Replies are listed 'Best First'.
Re^3: Total Newbies TkZinc questions
by zentara (Cardinal) on Oct 22, 2008 at 13:19 UTC
    Since "I" didn't see your bug before your transform addition, I suspect I will see it after you modify the code. :-) Maybe update your original code, and let me try again. There may be some hidden bug related to versions and platforms, but if you will be the only user, it really dosn't matter.......do whatever works for you.

    I'm not really a human, but I play one on earth Remember How Lucky You Are

      There is a (somewhat subtle) bug in the previous code. Indeed, drag does work at any scale factor, but you'll see it clearly once you understand what I mean:

      1. Start the program and add a media item (no scaling!)
      2. Position pointer in the exact center of the media item, click and drag it somewhere on the stage.
      3. Notice that when you release the item from drag, the pointer is still located in the exact position of the media item that you initiated drag from. In other words the item is translated exactly 1:1 with the mouse pointer.
      4. Hit "+" five times.
      5. Position the pointer in the exact center of media item, and drag it to the far side of the screen. You will notice that, while the item has been dragged, the pointer has offset from the point at which it was located when you first grabbed the item.

      Once I understand why, it's completely logical ;-)

      Try the updated version below, with good text centering, (visually) correct dragging and possibly other minor experiments.

        Yeah, I see it now, it was very subtle. There was some slippage due to the slowness of my computer, and I didn't swing in a wide circle. I was mistaking the slippage as normal, but I can see your bug now. I was also confused because if I added an anchor, not a media, there is no bug !!

        Oh well, thanks for figuring it out, and will save the correction factor for later reference.

        Once I understand why, it's completely logical ;-)

        I'm glad someone knows what they are doing. :-)


        I'm not really a human, but I play one on earth Remember How Lucky You Are