Harry Potter's magic button - a solution to another tricky group bug

Wilhelm Sanke sanke at hrz.uni-kassel.de
Tue Aug 3 15:55:23 EDT 2010


I was so intrigued by the various effects of the workaround that I 
included "magic" in the subject line. Bringing Harry Potter into play 
may also help to start  the process of improvements for Revolution 
announced by Kevin last week, namely - among them - better communication 
with users and the total overhaul of the Revolution bug management 
system along with quicker bug fixes (after all,. the "Hogwarts School of 
Witchcraft and Wizardry" is located not far from Edinburgh, which will 
facilitate the exchange of ideas).
Once the Revolution programmers responsible for bug fixes will have 
analysed and understood what is going on behind the scenes - in the 
engine - concerning this bug and the workaround, they will be much 
better equipped to tackle the 9 remaining bugs associated with groups, too.

A sample stack that demonstrates bug and workaround can be downloaded 
from here:

<http://www.sanke.org/Software/Magic Button.zip>

There are basically four aspects to this magic:

1. The magic button - as a workaround - resolves the group bug that

YOU CANNOT SET THE LOC OF AN IMAGE IN A GROUP IF THE IMAGE IS SMALLER 
THAN THE GROUP.

In the case of a smaller image the scriptline "set the loc of image "x" 
to the loc of group "y"" will place the image at the topleft corner of 
the group instead (unless the loc of the image is already exactly 
identical with the group loc).

Now, after you put Harry Potter's button into the upperleft corner of 
the group, the above scriptline with "set the loc" will now work as it 
should. It is essential here that the magic button is visible in the 
sense that its visibility is set to true. But you could shove the button 
under the topleft corner of the group so that it actually becomes 
invisible and it will nevertheless continue to exert its spell.

The moment you hide the button, i.e. with "hide" or "set the vis to 
false", the image will snap again to a topleft position in the group.

2. The magic button can be moved across the visible part of the group 
area by script - diagonally, horizontally, vertically - without being 
addressed with its name or any other identifier. One precondition for 
this to happen is that the image is at least 1 pixel off the loc of the 
group.

  Place the button anywhere in the group, press button "center image 
using "set the loc"" repeatedly, and the magic button will move in steps 
until it reaches the upperleft corner of the group. The first time you 
press the button the image will be also be placed at the topleft of the 
group with only one step.

The distance the magic button will move vertically and horizontally with 
a step is different with image size and dependent on the height and 
width of the image, e.g. with a broader image the horizontal steps will 
be much smaller, with a smaller height the steps will be bigger. You can 
see this best with image "Steve and friend" (Steve Jobs, the iPhone, and 
Medwedjew), but I recommend to try out the options of the sample stack 
with image "Red Square" first.

3. An interesting variant of 2. is the "split button":

Place the magic button at the bottomleft corner of the group. Make sure 
the image is at least 1 pixel off the loc of the group (Both the button 
and the image have a "grab me" script, so you can do this manually with 
mousedown).

Now, as above in "2." press button "center image using "set the loc"" . 
The magic button will move upwards in steps. When it has reached the 
area of the image the button will "split". The part of the button 
intersecting with the image will continue to move upwards. The left part 
of the button will remain in place until the right part of the button 
has reached the top of the group. At that moment the two separate parts 
of the magic button will re-unite.

If you place the button to the right of the group, the splitting of the 
button will occur horizontally.--

There are three special buttons in the sample stack that demonstrate 
these effects (2. and 3.) automated with repeat loops.
At the top of these scripts for the automated demonstrations I make use 
of the move command (which is not broken)  to make sure image and magic 
button are placed at the appropriate places, but for creating the 
effects the broken "set" command is used inside the repeat loops.


4. Button "reset image" will restore the original imagedata stored in a 
custom property and center the image using the "move" command.

When you have placed the magic button somewhere on the group area like 
above in points 2. and 3. and you then press the "reset image" button 
repeatedly the magic button will also move in steps towards the topleft 
of the group, but without producing the "split" effect.

================================

A few more particulars and peculiarities for those interested in getting 
a broader picture:

If the magic button is absent or hidden and you have managed to center 
the image (either by using the "move" command or by dragging the image 
manually), there are now several additional conditions under which the 
smaller image within the group again snaps to a topleft position - 
although the lockloc of the image and that of the group are set to true.

- when you go to another card and then navigate back
- when you change the imagedata and set the image to the new imagedata
- when you import a new image
- when you close the stack (even after having saved it again) and then 
reopen it.

Another peculiarity is that this snapping to the topleft may happen in 
*two" steps - especially when you change the imagedata with button 
"duplicate colors":

  - at first only the overlapping parts between the image area at the 
original position and the area of the image at the topleft position are 
displayed
  - then when you again change the imagedata - or click on the image - 
the full image is shown at the topleft position of the group.

The easiest way to demonstrate this is to drag the smaller-than-group 
image with mousedown nearer to the bottomright of the group and then 
apply the "duplicate colors" filter twice.

If an image so small  that there are no overlapping parts of the image 
at the start position and its position at the topleft corner, then the 
image will vanish completely. It is "virtually" there and you can revive 
it by clicking near the topleft corner of the group.

When you use the alternate filter "duplicate colors + lock screen" the 
image is set to the topleft of the group in only one step - and remains 
fully visible..

By the way, when you apply filter "duplicate colors" 9 times then the 
original colors of the image will be restored, but this is the normal 
process when using this filter - without any magic.--

I will file a bug report soon and also add the sample stack.

Regards,

Wilhelm Sanke
<http://www.sanke.org/MetaMedia>




More information about the Use-livecode mailing list