Canvas transparency broken

What problems do you encounter with the listbox ContextualMenu? It’s all a bit vague … “not working as expected” is rarely a useful description …

But maybe open a new thread for that.

So it seems the <https://xojo.com/issue/52178> was Closed BY Design. :frowning:

I can’t really understand how a Canvas can’t be transparent by design, provided it has the Transparent property.
Moreover, a Canvas it’s the first control I expect to be transparent IMHO.

What do you think guys?

From the Feedback case: “we [no] longer have truly Transparent controls (this was the cause of flicker on Windows). So this type of interface where you have overlapping controls is no longer supported.”

That seems pretty final.

I wasn’t asking what’s technically under-the-hood different. I was asking you what you’re expecting, and how it’s actually behaving.

This can be replaced by trapping those events on the window and using a single IF that will only allow the code to trigger if the mouse is over the listbox. There is no need for a canvas sitting over the top of another control.

In Window1.ConstructContextualMenu:

If x >= listbox1.left And x <= Listbox1.left + listbox1.width And y >= listbox1.top And y <= Listbox1.top + listbox1.height Then system.DebugLog("inside listbox") 'build listbox here Return True End If 'pass the context click onto something below Return False

As for canvas transparencies, it can be achieved.

https://www.dropbox.com/s/xlmrbgmawrgg475/TestcanvasTransparencyForMassimo.xojo_binary_project?dl=1

However, a big HOWEVER, there are so many things to deal with to get this to work properly. The flickering on window resize (paints aren’t continually called during a resize) and painting of the canvas in front of controls that are being redrawn (like hovering over a button in windows 10). Some of these things might be impossible, I don’t know as I’ve not spent much time doing low level stuff like this.

It then needs to be optimised, you wouldn’t be doing things like I am by creating the off screen picture every time, that should be reused as its a big performance hit and it should be resized to 2x what it used to be, resizing it by each pixel increase is just crazy bad.

I expect that William has looked into all this and has probably come to the conclusion that either its not possible or the time involved to do it this way just isn’t going to bring the return.

Most things can be worked around, it’s just a design shift that is needed, but that is awkward as a lot of people come from mac where they can do pretty much anything and/or they have an existing app that they now need to re-engineer.

OK, basically the difference I’m seeing is: the CreateContextualMenu event does not fire in my Listbox when I do a context click on Mac, whereas it does get fired under Windows. My expectation is that the context click on the Listbox would fire the CreateContextualMenu event for both platforms.

But this is probably well past the time for a separate thread (sorry to hijack this one @Massimo Valle !). I am going to look into the technique @ mentions (trap the CreateContextualMenu event at the Window level rather than the Listbox control); if that doesn’t work for both Mac & Windows then I’ll create a new thread about it.

I have a project with a contextual-click-aware listbox, in which I put

If IsContextualClick

in the MouseDown event. There’s also a recent note to myself saying “I don’t know why I did it this way rather than using the CreateContextualMenu event” - maybe I ran into the same thing :slight_smile:

Thank you for the elaboration! I try to keep track of known glitches, so when someone finds one I ask about it :slight_smile:

[quote=388912:@]
As for canvas transparencies, it can be achieved.

https://www.dropbox.com/s/xlmrbgmawrgg475/TestcanvasTransparencyForMassimo.xojo_binary_project?dl=1

However, a big HOWEVER, there are so many things to deal with to get this to work properly. The flickering on window resize (paints aren’t continually called during a resize) and painting of the canvas in front of controls that are being redrawn (like hovering over a button in windows 10). Some of these things might be impossible, I don’t know as I’ve not spent much time doing low level stuff like this.

It then needs to be optimised, you wouldn’t be doing things like I am by creating the off screen picture every time, that should be reused as its a big performance hit and it should be resized to 2x what it used to be, resizing it by each pixel increase is just crazy bad.

I expect that William has looked into all this and has probably come to the conclusion that either its not possible or the time involved to do it this way just isn’t going to bring the return.

Most things can be worked around, it’s just a design shift that is needed, but that is awkward as a lot of people come from mac where they can do pretty much anything and/or they have an existing app that they now need to re-engineer.[/quote]

This is awesome Julian!
It doesn’t solve all my problems but it’s a big step forward and a good start to play with.
Just a couple of questions:

  • Why you use &cFF00FF00 (that is Magenta) for the transparency color in TransparentBlt()? Btw, there is a simpler approach to convert a color to an integer: dim i as UInt32 = UInt32(&cFF00FF00)

  • Unfortunately this doesn’t work well with ContainerControls. Have you any idea on how to make this work?

Thanks a lot! :smiley:

TransparentBlt has the ability to mask out pixels when they are painted, so by selecting magenta it means that all values are copied across unless of course that you use magenta somewhere behind the control, in which case you need to change the colour to something else.

I just made a last minute change to some code I left in there which would allow for conversion from colours that have been read in using declares as windows returns colours in a different format (see Eugene’s book), the memoryblock was moving things back into the expected order.

It should work as those controls are based on the same underlying control in windows. Ah yes, things just need a little tweak.

https://www.dropbox.com/s/48cle6r4whz34gg/TestcanvasTransparencyForMassimo2.xojo_binary_project?dl=1

If I get time later I’ll try and tidy all this up and put it into something usable. I might even have a play around getting it to work at a lower level in wndproc, can’t promise anything though.

Sorry Julian I did not explain well: I meant a Canvas drawing OVER a container control. The Container controls always goes to top.

Ah yes, doh. As I mentioned before this isn’t an easy problem to get around and doubly so when I’m working on top of what the framework is doing.

if you really need an image in front of a bunch of controls the easiest thing I can think of right now is to use a transparent window that moves with your main window that you draw onto. There’s an example for windows under platform-specific>windows>customwindowshape, I also think MBS has a crossplatform solution for that too.

That I tried to do, and it works, BUT there is no way to smoothly resize or move the overlaid window when the main window moves or resize. It’s ugly…

Ah doh. Have you tried it in a wndproc during a WM_SIZING and WM_MOVING? It might be less laggy then putting it into the framework window.resizing.

I only slightly understand what you mean… any hint on how to do that?

I was working on a demo for you, I had it working, but I have just found that the transparent window flickers when its resized so I now need to write the demo in another language to prove if its a xojo framework issue with overly aggressive background painting /sigh

I know it flickers on resizing, but for my needs it doesn’t matter that much. I can live with that.

I can’t get rid of the flicker without finding out where its coming from first. I went back to first principles, hows this Massimo?

Try moving and resizing.

https://www.dropbox.com/s/ykgpxkux89eap0y/TestMovingTwoWindowsClean.xojo_binary_project?dl=1

Ahh well sometimes I surprise myself, here you go, no flicker.

https://www.dropbox.com/s/o4ameezkase77v4/TestMovingTwoWindowsClean2.xojo_binary_project?dl=1

[quote=389229:@]Ahh well sometimes I surprise myself, here you go, no flicker.

https://www.dropbox.com/s/o4ameezkase77v4/TestMovingTwoWindowsClean2.xojo_binary_project?dl=1[/quote]

What was the problem, and how did you solve it? Don‘t keep those of us reading with baited breath in suspense …!