multiple layertofronts behavior?

Discuss any general programming issues here

Re: multiple layertofronts behavior?

Postby airsoftsoftwair » Wed Aug 30, 2017 8:45 pm

Hmm, right, I was wrong about what LayerToFront() and LayerToBack() actually do: Actually, they swap the front/back layer's z-position with the z-position of the specified layer. No idea why I implemented it like that. It certainly doesn't make sense to me now but changing it will break compatibility so please just use SetLayerZPos() instead. This should do the trick:

Code: Select all
Function MultipleLayerToFront()
   If IsLeftMouse() = False Then ClearInterval(1)
   For n = 1 To 5
      SetLayerZPos("layer"..n,0)
   Next
EndFunction
User avatar
airsoftsoftwair
 
Posts: 2240
Joined: Fri Feb 12, 2010 3:33 pm
Location: Germany

Re: multiple layertofronts behavior?

Postby Bugala » Thu Aug 31, 2017 8:07 am

Good the solution is so easy. Didnt know you could use setlayerZpos that way before, although i should have realised it does, since it is like rest of your commands where 0 works as last in queue.

Although LayerToFront is now useless to me, there is no need to change that command since i can simply use that setlayerZpos instead of it, not much of a difference there. Besides, I can overwrite the current layertofront function and change it into using zpos instead.

I do however recommend putting a notice to layertofront documentation that to achieve this is to use setlayerZpos.
Bugala
 
Posts: 645
Joined: Sun Feb 14, 2010 8:11 pm

Re: multiple layertofronts behavior?

Postby Bugala » Thu Aug 31, 2017 9:53 am

Heres the other problem i mentioned with layertofront:
Code: Select all
Function StartLayerToFront()
   SetInterval(1, MultipleLayerToFront, 1)
EndFunction


Function MultipleLayerToFront()
   If IsLeftMouse() = False Then ClearInterval(1)
   For n = 1 To 5
      LayerToFront("layer"..n)
   Next
EndFunction

Function ChangeText(msg)
   n=msg.userdata
   SetLayerStyle("text", {text=n})
EndFunction


EnableLayers

CreateLayer(100, 100, 200, 300, {Color = #RED, name="layer1"})
CreateLayer(200, 100, 200, 300, {Color = #GREEN, name="layer2"})
CreateLayer(300, 100, 200, 300, {Color = #BLUE, name="layer3"})
CreateLayer(400, 100, 200, 300, {Color = #YELLOW, name="layer4"})
CreateLayer(500, 100, 200, 300, {Color = #WHITE, name="layer5"})

TextOut(10, 10, "text", {name="text"})

For n = 1 To 5
   MakeButton(Nil, #LAYERBUTTON, "layer"..n, True, False, {OnMouseDown = StartLayerToFront, OnMouseOver = ChangeText}, n)
Next

Repeat
WaitEvent()
Until quit = True


This code is otherwise same as before, except I am now using textout to create one textobject, and i add to Makebutton this "OnMouseOver" condition which goes to change text.

What ChangeText function does, is to change the text to tell on top of which numbered box the mouse curently is.


To notice the problem, you will first need to left click with mouse on top of boxes in such way that one of the boxes get covered by other boxes (this can be seen by having one vertically double sized big box).

If you now move the mouse over those boxes, you will notice that, I think, it is working wrong.

What I would expect to happen, is for that number to change only when I am moving on top of some new box graphics.

However, in practice when I move on top of that double sized box, it changes number twice.

If I have understood right, then Hollywood should work in such way that if Button A is completely covered by Button B, then there shouldnt be a way to push the A button, but it should be pushing B button instead.

However, in this case it seems to be working in such way that if Layertofront command would work as it should, then the buttonareas are aligned the exact way they should be.

This makes me suspect that this problem with layertofront behavior might be two different problems. That while graphics and graphics z-position go where ever they go, the button itself seems to go to right z-order anyway.
Bugala
 
Posts: 645
Joined: Sun Feb 14, 2010 8:11 pm

Re: multiple layertofronts behavior?

Postby Bugala » Thu Aug 31, 2017 11:56 am

Actually, now that i look, you have already mentioned that to achieve the same, you can use Zpos in documentation.

But it would be good to specifically mention that the behavior is different, since now you cant achieve the same with zpos as with layertofront, since layertofront is basically doing swaplayers.

Also, another idea as you mention is layertofront that it is a convenience function, and you have mentioned this in some other ones too, it might be good idea to somehow mark these convenience functions.

As example, when in document you look at list of commands, it could be:

*LayertoFront
LayerZpos
*SwapLayer
InsertLayer


Most of time it doesnt really matter, but sometimes it can save some time. Like in this case as i was wondering about this LayerToFront problem, i didnt realise i could do the same with LayerZpos function. Had i realised, I could have maybe done it.

Also sometimes you use some function and you start wondering if you could do the almost same, except... In this case when seeing already from big list of commands that it is a convenience function, you would realise to start looking for the original one.

Taking this LayerToFront function as example. As command is so simple, it didnt even come to my mind to read the documentation of it to see that it is a convenience function. There basically was no reason for me to read the documentation of such a simple command, yet, i was having problem with. Had i somehow saw that it is a convenience function, i could have maybe hunted the bug down quicker too by trying to replace it with the original (LayerZpos) function and then having noticed that it works fine with Zpos but not with toFront.

Even better would be if it would show that asterisk or something even in front of when showing the syntax on Hollywood IDE. Since basically even if there is as example asterisk on list of command names, it still requires you to look at the command list. However, what i do keep seeing accidentally all the time is when commands appear on bottom of Hollywood IDE showing the usage of command. So that would be best place to put it.
Bugala
 
Posts: 645
Joined: Sun Feb 14, 2010 8:11 pm

Re: multiple layertofronts behavior?

Postby airsoftsoftwair » Tue Sep 12, 2017 6:24 pm

Code: Select all
- New: LayerToFront() and LayerToBack() accept an optional argument now; if this is set to FALSE, the
  layer isn't brought to front or back by swapping layers but by simply moving the specified layer
  to the front or the back; this is a much more logical behaviour but by default LayerToFront() and
  LayerToBack() will use the old behaviour for compatibility reasons
User avatar
airsoftsoftwair
 
Posts: 2240
Joined: Fri Feb 12, 2010 3:33 pm
Location: Germany

Previous

Return to General programming

Who is online

Users browsing this forum: No registered users and 3 guests