Canvas transparency broken

  1. ‹ Older
  2. last year

    Julian S

    23 May 2018 Pre-Release Testers, Xojo Pro UK

    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.

  3. Massimo V

    23 May 2018 Pre-Release Testers, Xojo Pro Europe (Germany, Würzburg)

    @Julian S 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....

  4. Julian S

    23 May 2018 Pre-Release Testers, Xojo Pro UK

    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.

  5. Massimo V

    23 May 2018 Pre-Release Testers, Xojo Pro Europe (Germany, Würzburg)

    @Julian S 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?

  6. Julian S

    24 May 2018 Pre-Release Testers, Xojo Pro UK

    @Massimo V 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

  7. Massimo V

    24 May 2018 Pre-Release Testers, Xojo Pro Europe (Germany, Würzburg)

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

  8. Julian S

    24 May 2018 Pre-Release Testers, Xojo Pro UK

    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

  9. Julian S

    24 May 2018 Pre-Release Testers, Xojo Pro UK

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

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

  10. Markus W

    24 May 2018 Pre-Release Testers #JeSuisHuman New Zealand, Auc...

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

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

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

  11. Markus W

    24 May 2018 Pre-Release Testers #JeSuisHuman New Zealand, Auc...

    Btw it probably should be

    Public Function SetWindowPos(hWnd As Integer, hWndInsertAfter As Integer, X as Int32, Y as Int32, cx As Int32, cy As Int32, uFlags As UInt32) as Integer
      #If TargetWindows
        'https://msdn.microsoft.com/en-us/library/windows/desktop/ms633545%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
        Declare Function SetWindowPos Lib "User32.dll" (hWnd As Integer, hWndInsertAfter As Integer, X as Int32, Y as Int32, cx As Int32, cy As Int32, uFlags As UInt32) As Integer
        Return SetWindowPos(hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags)
      #Endif
    End Function
  12. Julian S

    24 May 2018 Pre-Release Testers, Xojo Pro UK

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

    Sorry I don't mean to tease, I forget that I know where I do things but others don't when I post a whole test project :)

    Inside Window1.Resizing I added the Refresh(false) line to the end after the width and height changes. I guess the framework is then told to perform a refresh with without blanking the background which stops the flicker (so it was a framework issue after all). I use this "hack" a lot since the framework windows update to do things like correcting the rendering of containers while scrolling etc.

    @Markus W Btw it probably should be

    Public Function SetWindowPos(hWnd As Integer, hWndInsertAfter As Integer, X as Int32, Y as Int32, cx As Int32, cy As Int32, uFlags As UInt32) as Integer #If TargetWindows 'https://msdn.microsoft.com/en-us/library/windows/desktop/ms633545%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396 Declare Function SetWindowPos Lib "User32.dll" (hWnd As Integer, hWndInsertAfter As Integer, X as Int32, Y as Int32, cx As Int32, cy As Int32, uFlags As UInt32) As Integer Return SetWindowPos(hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags) #Endif End Function

    Oh crikey, if you're running this on mac then lookout ;) I've done zero crossplatform testing of this code as its just thrown together mainly from code that I've worked on in the past which might not even not cope with 64bit :) Test test test, don't just cut and paste :) ;)

  13. Julian S

    24 May 2018 Pre-Release Testers, Xojo Pro UK
    Edited last year

    Ah it worked on 64bit, bonus! That was totally planned *shiftyeyes*

  14. Julian S

    24 May 2018 Pre-Release Testers, Xojo Pro UK

    There might even be code/constants in there that aren't used as I just cut out huge portions to negate the need for wndproc so it can probably be tidied up even more.

  15. Markus W

    24 May 2018 Pre-Release Testers #JeSuisHuman New Zealand, Auc...
    Edited last year

    @Julian S Sorry I don't mean to tease, I forget that I know where I do things but others don't when I post a whole test project :)

    It‘s an OPC* problem …

    * other people‘s code

    Inside Window1.Resizing I added the Refresh(false) line to the end after the width and height changes. I guess the framework is then told to perform a refresh with without blanking the background which stops the flicker (so it was a framework issue after all). I use this "hack" a lot since the framework windows update to do things like correcting the rendering of containers while scrolling etc.

    Now that’s interesting! Thanks for sharing!

  16. Julian S

    24 May 2018 Pre-Release Testers, Xojo Pro UK
    Edited last year

    @Markus W It‘s an OPC* problem …

    * other people‘s code
    ...

    Now that’s interesting! Thanks for sharing!

    :D

    No problem, I just hope it works for Massimo ;)

    Oh by the way, the canvas is in there to trick the framework into not refreshing the background when you resize, if you take the contents of the paint event from the canvas and put it into the window2.paint and change window2.canvas1.refresh(false) inside window1.resizing and remove the canvas then you will see flicker, confusing no. Hacky hack hack :D

    PS. More smileys just for the :)

  17. Julian S

    24 May 2018 Pre-Release Testers, Xojo Pro UK
    Edited last year

    @Julian S Inside Window1.Resizing I added the Refresh(false) line to the end after the width and height changes. I guess the framework is then told to perform a refresh with without blanking the background which stops the flicker (so it was a framework issue after all). I use this "hack" a lot since the framework windows update to do things like correcting the rendering of containers while scrolling etc.

    Oops, that's not quite correct. This is what it should have read:

    I added the canvas to stop the flickering as adding the canvas over the window causes the framework to behave differently and not cause an extra paint in standard windows grey (probably related to Feedback Case #51879). I then had to add the Refresh as mentioned above to get around the "lagy/gloopy" rendering of the canvas control when its resized. I use this "hack" a lot since the framework windows update to do things like correcting the rendering of containers while scrolling etc.

    You also don't need the transparency on the canvas unless you want to draw controls on the canvas that are infront of the painted image from canvas1.paint. Window2 has a custom background colour so that all controls that are placed onto the canvas have white as their background which is they keyed out with the window transparency.

    Clear as mud ;) Let me know if there's something that needs more explanation.

  18. Markus W

    24 May 2018 Pre-Release Testers #JeSuisHuman New Zealand, Auc...

    @Julian S Clear as mud ;) Let me know if there's something that needs more explanation.

    Thanks, but my head hurts plenty enough, thank you very much ! ;)

  19. Massimo V

    28 May 2018 Pre-Release Testers, Xojo Pro Europe (Germany, Würzburg)

    Julian, you made an awesome job! :D

    Maybe I need some tweaks for my particular situation but this does work for me.
    Thanks again for the invaluable help and the efforts you put into this.

  20. 7 weeks ago

    Sorry for the necro-bump, but is there now a work-around to allow Canvases (and other controls) to be transparent/semi-transparent on Windows?
    I looked at the demo app posted above, but that's WAY over my head.
    I'm wondering if there's a way to have a Canvas "capture" what's behind it and use it as a background picture to "emulate" transparency?

  21. Greg O

    Sep 7 Xojo Inc

    @Andy B Sorry for the necro-bump, but is there now a work-around to allow Canvases (and other controls) to be transparent/semi-transparent on Windows?
    I looked at the demo app posted above, but that's WAY over my head.
    I'm wondering if there's a way to have a Canvas "capture" what's behind it and use it as a background picture to "emulate" transparency?

    You might be able to hide the canvas, use DrawInto to draw the window into a picture and then show the canvas with the correct portion of the picture drawn in the paint event.

or Sign Up to reply!