Round Transparent Window?

  1. 4 years ago

    Payam A

    4 Sep 2013 Pre-Release Testers

    I thought it would be nice to have a round splash screen when the user launches an application.

    In Xojo I can't do that, because if I write the code for transparent windows, everything on the window gets transparent.

    So I wrote the code with another IDE product for Macintosh which does the work. But instead of having one app, I have two apps now. I want to get rid of the splash screen app...

    How can I have a round or oval window in Xojo? Is there a way?

    Can you help?

    For a transparent background you set Opaque off and the background color clear. This is the method I use. If calling from the Windows open event just pass in self. If calling at some later time also pass in true and it'll fix the shadows. Then for a custom background draw in the Windows paint event and you can even use semi-transparent colors and it's see through with corresponding shadow.

    Shared Sub makeWindowTransparent(aWindow As Window, forceDisplay As boolean = false)
      if aWindow = nil then return
      
      const CocoaLib = "Cocoa.framework"
      soft declare function NSClassFromString lib CocoaLib (aClassName as CFStringRef) as Ptr
      soft declare function colorMaker lib CocoaLib selector "colorWithCalibratedWhite:alpha:" (NSColorClass As Ptr, white As Single, alpha As Single) As Ptr
      soft declare sub      setBGColor lib CocoaLib selector "setBackgroundColor:" (NSWindow As Ptr, backgroundColor As Ptr)
      soft declare sub      setOpaque  lib CocoaLib selector "setOpaque:" (NSWindow As Ptr, flag As Byte)
      
      dim w As Ptr = Ptr(aWindow.Handle)
      
      setOpaque(w, 0)   //0 = off, 1 = on
      
      setBGColor(w, colorMaker(NSClassFromString("NSColor"), 1, 0))
      
      if forceDisplay then 
        soft declare sub invalidateShadow lib CocoaLib selector "invalidateShadow" (NSWindow As Ptr)
        soft declare sub disp lib "AppKit" selector "display" (windRef As Ptr)
        disp(w)
        invalidateShadow(w)
      end
    End Sub
  2. Roger C

    4 Sep 2013 Lewis Center, OH

    I only know that this is not trivial. Perhaps you want to have a look at the MBS Plugins which, I think, can do this.

  3. Payam A

    4 Sep 2013 Pre-Release Testers

    Haha :) That's a very good idea. I already have more than half a dozen MBS plugins. Before I have more plugins, I wanted to know if there is a native solution to it :)

  4. Roger C

    4 Sep 2013 Lewis Center, OH

    If you decide to do it yourself, you'll need to use declares. There is no native Xojo way.

  5. Payam A

    4 Sep 2013 Pre-Release Testers

    Yes, I tried this, but it makes everything invisible, even the controls inside the window are affected:

    #if TargetCocoa
    declare sub setAlphaValue lib "Cocoa" selector "setAlphaValue:" (windowRef as integer, windowAlpha as Single)
    setAlphaValue(MainWindow.handle, .6)
    #endif

    I don't know how to apply only for the window frame.

  6. Will S

    4 Sep 2013 Answer Santa Cruz 

    For a transparent background you set Opaque off and the background color clear. This is the method I use. If calling from the Windows open event just pass in self. If calling at some later time also pass in true and it'll fix the shadows. Then for a custom background draw in the Windows paint event and you can even use semi-transparent colors and it's see through with corresponding shadow.

    Shared Sub makeWindowTransparent(aWindow As Window, forceDisplay As boolean = false)
      if aWindow = nil then return
      
      const CocoaLib = "Cocoa.framework"
      soft declare function NSClassFromString lib CocoaLib (aClassName as CFStringRef) as Ptr
      soft declare function colorMaker lib CocoaLib selector "colorWithCalibratedWhite:alpha:" (NSColorClass As Ptr, white As Single, alpha As Single) As Ptr
      soft declare sub      setBGColor lib CocoaLib selector "setBackgroundColor:" (NSWindow As Ptr, backgroundColor As Ptr)
      soft declare sub      setOpaque  lib CocoaLib selector "setOpaque:" (NSWindow As Ptr, flag As Byte)
      
      dim w As Ptr = Ptr(aWindow.Handle)
      
      setOpaque(w, 0)   //0 = off, 1 = on
      
      setBGColor(w, colorMaker(NSClassFromString("NSColor"), 1, 0))
      
      if forceDisplay then 
        soft declare sub invalidateShadow lib CocoaLib selector "invalidateShadow" (NSWindow As Ptr)
        soft declare sub disp lib "AppKit" selector "display" (windRef As Ptr)
        disp(w)
        invalidateShadow(w)
      end
    End Sub
  7. Payam A

    4 Sep 2013 Pre-Release Testers

    Thank you.

  8. Karen A

    4 Sep 2013 Pre-Release Testers

    In 10.6.8 that leaves the title bar visible

  9. Payam A

    4 Sep 2013 Pre-Release Testers

    Why then not use a plain window? :)

  10. Karen A

    5 Sep 2013 Pre-Release Testers

    @Payam A Why then not use a plain window? :)

    using document, rounded or plain box did not work ... using metal window did!

  11. Anyone have a solution for the same thing on Windows?

  12. Andrew L

    5 Oct 2013 San Francisco, CA, USA

    @Sean H Anyone have a solution for the same thing on Windows?

    There's an example that comes with Xojo (in Example Projects\Platform-Specific\Windows\CustomWindowShape) that demonstrates masking a window to a shape defined in a Picture; and the Windows Functionality Suite has code to set the alpha/transparency of a window .

  13. Thanks Andrew

  14. Christian S

    6 Oct 2013 Pre-Release Testers, Xojo Pro Germany

    Well, we have OverlayMBS class in our plugins to do this...

  15. Oliver O

    6 Oct 2013 Pre-Release Testers, Xojo Pro https://seminar.pro

    @ChristianSchmitz Well, we have OverlayMBS class in our plugins to do this...

    I'm using MakeTransparentMBS for a SplashScreen on OSX, but it does not seem to work on Windows, the window is not becoming transparent …

    https://forum.xojo.com/1874-the-easiest-way-i-ve-found-to-make-a-splash-screen/p1#p18183

  16. Christian S

    6 Oct 2013 Pre-Release Testers, Xojo Pro Germany

    Of course not. MakeTransparentMBS on Windows first enables the use of the TransparencyMBS property.

  17. Oliver O

    6 Oct 2013 Pre-Release Testers, Xojo Pro https://seminar.pro

    @ChristianSchmitz Of course not. MakeTransparentMBS on Windows first enables the use of the TransparencyMBS property.

    I'm not able to find TransparencyMBS in your docu (just tons of listarchive entries). I obviously am missing something here, because I don't know on how to make my example (splash.zip ) work on Windows, using your plugins.

    Could you help with a link to a Windows example and/or a link to the specific docu?

  18. Christian S

    6 Oct 2013 Pre-Release Testers, Xojo Pro Germany

    I'm sorry, but on Windows things are different.
    You would need to use OverlayMBS class and not a Xojo window.

  19. Shared Sub makeWindowTransparent(aWindow As Window, forceDisplay As boolean = false)
    if aWindow = nil then return

    const CocoaLib = "Cocoa.framework"
    soft declare function NSClassFromString lib CocoaLib (aClassName as CFStringRef) as Ptr
    soft declare function colorMaker lib CocoaLib selector "colorWithCalibratedWhite:alpha:" (NSColorClass As Ptr, white As Single, alpha As Single) As Ptr
    soft declare sub setBGColor lib CocoaLib selector "setBackgroundColor:" (NSWindow As Ptr, backgroundColor As Ptr)
    soft declare sub setOpaque lib CocoaLib selector "setOpaque:" (NSWindow As Ptr, flag As Byte)

    dim w As Ptr = Ptr(aWindow.Handle)

    setOpaque(w, 0) //0 = off, 1 = on

    setBGColor(w, colorMaker(NSClassFromString("NSColor"), 1, 0))

    if forceDisplay then
    soft declare sub invalidateShadow lib CocoaLib selector "invalidateShadow" (NSWindow As Ptr)
    soft declare sub disp lib "AppKit" selector "display" (windRef As Ptr)
    disp(w)
    invalidateShadow(w)
    end
    End Sub

    Hello,

    how do i use it for a window?
    I tested this 3 variants but nothing works (getting errors of wrong calls)

    self.makeWindowTransparent
    self.makeWindowTransparent aWindow
    self.makeWindowTransparent forceDisplay As boolean = false

    Thanks

  20. Beatrix W

    20 Nov 2013 Pre-Release Testers Europe (Germany)

    Can you try makeWindowTransparent(self, false)?

  21. Newer ›

or Sign Up to reply!