Layerbuttons when swapping layer positions

Report any Hollywood bugs here
Post Reply
User avatar
jPV
Posts: 600
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Layerbuttons when swapping layer positions

Post by jPV »

If I have overlapping layer buttons and change layers order, the original layerbutton stays in front even when the layer it's attached into isn't in front anymore. I think this is a bug or is there some explanation or work-around?

Code: Select all

Function p_LayerEvent(msg)
    DebugPrint("Mouse moved over layer:", msg.layer, msg.layername)
EndFunction

Function p_SwapLayers()
    Local id, name$
    SwapLayers(1, 2)
    id, name$ = GetLayerAtPos(10, 10)
    DebugPrint("Mouse clicked,", name$, "is in front.")
EndFunction

EnableLayers()
SetFillStyle(#FILLCOLOR)
Box(10, 10, 100, 100, #RED, {Name="red"})
Box(10, 10, 100, 100, #BLUE, {Name="blue"})
MakeButton(1, #LAYERBUTTON, "red", False, False, {OnMouseOver=p_LayerEvent})
MakeButton(2, #LAYERBUTTON, "blue", False, False, {OnMouseOver=p_LayerEvent})

EscapeQuit(True)

InstallEventHandler({OnMouseUp=p_SwapLayers})

Repeat
    WaitEvent()
Forever
The result looks like this:

Mouse moved over layer: 2 blue
Mouse clicked, red is in front.
Mouse moved over layer: 1 blue
Mouse clicked, blue is in front.
Mouse moved over layer: 2 blue
Mouse clicked, red is in front.
Mouse moved over layer: 1 blue

As you can see, the events will come always from the layer that was in front originally even though it isn't visible anymore. Looks like button order doesn't follow the layer order.
Bugala
Posts: 1168
Joined: Sun Feb 14, 2010 7:11 pm

Re: Layerbuttons when swapping layer positions

Post by Bugala »

I have used "LayerToFront" and it have worked fine so far, but in one thread where i was asking about this, I think Andreas said that there is no guarantee that top most layerbutton actually is topmost button.
User avatar
jPV
Posts: 600
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: Layerbuttons when swapping layer positions

Post by jPV »

Ok... but I need to organize layers without bringing them always to front, but shuffle them in the middle too, so that work-around doesn't work for me.
Bugala
Posts: 1168
Joined: Sun Feb 14, 2010 7:11 pm

Re: Layerbuttons when swapping layer positions

Post by Bugala »

If LayerToFront works, you can reorder several of them. It isnt good, but it can be a workaround.

That let's say we have Layers:

A, B, C, D, E

and now I want E to middle

LayertoFront(C)
LayertoFront(D)

and it looks A, B, E, C, D


Not ideal, but works as long as LayerToFront works with the button placing.
User avatar
jPV
Posts: 600
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: Layerbuttons when swapping layer positions

Post by jPV »

I made a work-around by deleting and recreating all buttons always when the layer order changes, it seems to work so far... but thanks for your suggestion too.
Bugala
Posts: 1168
Joined: Sun Feb 14, 2010 7:11 pm

Re: Layerbuttons when swapping layer positions

Post by Bugala »

I think deleting and recreating is a safer option since basically there is no guarantee that layertofront would work either, could change on the next version or something.
User avatar
airsoftsoftwair
Posts: 5425
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Layerbuttons when swapping layer positions

Post by airsoftsoftwair »

jPV wrote: Mon May 04, 2020 6:40 pm As you can see, the events will come always from the layer that was in front originally even though it isn't visible anymore. Looks like button order doesn't follow the layer order.
Yes, but that's more of a feature instead of a bug because AFAICS layer order currently doesn't have any effect on button order because MakeButton() simply chains the buttons into a list and that list is the sole determiner of the order of handling. That's probably not a very desirable implementation but of course changing this will break compatibility...
User avatar
airsoftsoftwair
Posts: 5425
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Layerbuttons when swapping layer positions

Post by airsoftsoftwair »

Code: Select all

- New: When used with type #LAYERBUTTON, MakeButton() now supports a new table tag named "ZOrder"; if this
  is set to TRUE, the layer button will respect the layer z-order; this is useful for buttons attached to
  overlapping layers; if those buttons have the "ZOrder" tag set, they will trigger in the order defined
  by the layer stack z-order
Post Reply