Transparent windows like XCode

Does anyone know how to make such kind of windows or which kind of control is that ?

I’ve tried it but could get only a sort of imitation. I made up a rounded window w/o borders (flat box), clear color,
fillroundrect (color about 85% black) and made it a bit transparent. That was acceptable but the text or any other
controls inside getting the opacity too and aren’t crisp anymore. The white color for the text gets sortof grayed.

Any leads or suggestions to accomplish that ?

[quote=153609:@Rob Egal]Does anyone know how to make such kind of windows or which kind of control is that ?

I’ve tried it but could get only a sort of imitation. I made up a rounded window w/o borders (flat box), clear color,
fillroundrect (color about 85% black) and made it a bit transparent. That was acceptable but the text or any other
controls inside getting the opacity too and aren’t crisp anymore. The white color for the text gets sortof grayed.

Any leads or suggestions to accomplish that ?

[/quote]

I would use a canvas instead.

e.g. OverlayMBS class to have a real window.

or for inside a normal Xojo window, simply draw it in a canvas.

Tried your suggestions and it works although I think there’s a little shadow beneath the frame.

So adding a soft shadow to the canvas would make the result perfect but I don’t
think it’s possible wiht cocoa declares.

You can actually make the window completely transparent and then draw it yourself in Window.Paint. This only works for the content region, the titlebar still gets drawn, so you’ll need to make the window frame as Plain Box. It also looks like there’s no drop shadow in that picture which can be turned off, and I added dragging by background since there’s no titlebar.

[code]//Make the Window Plain Box and add these events to it

Sub Open()

const Cocoa = “Cocoa”
declare sub setOpaque lib Cocoa selector “setOpaque:” (id As integer, b As boolean)
declare function NSClassFromString lib Cocoa (aClassName as CFStringRef) as Ptr
declare function clearColor lib Cocoa selector “clearColor” (NSColorClass As Ptr) As Ptr
declare sub setBackgroundColor lib Cocoa selector “setBackgroundColor:” (NSWindow As integer, backgroundColor As Ptr)

//allow for transparency by setting opaqueness false
setOpaque(self.Handle, false)

//set the background completely transparent
setBackgroundColor(self.Handle, clearColor(NSClassFromString(“NSColor”)))

//don’t add shadow
declare sub hasShadow lib Cocoa selector “setHasShadow:” (id As integer, b As Boolean)
hasShadow(self.Handle, false)

//allow dragging by background
declare sub setMovable lib Cocoa selector “setMovableByWindowBackground:” (id As integer, b As Boolean)
setMovable(self.Handle, true)

End Sub

Sub Paint(g As Graphics, areas() As REALbasic.Rect)

//Whatever you draw here constitutes the background, including transparencies.

//black transparent base
g.ForeColor = &c00000099
g.FillRoundRect(0, 0, g.Width, g.Height, 50, 50)

//solid white stuff
g.ForeColor = &cFFFFFF
g.FillOval( 50, 50, 50, 50 )

g.PenWidth = 10
g.PenHeight = 10
g.DrawOval( 10, 10, 130, 130 )

End Sub[/code]

With this the window is draggable even from areas not drawn over. I’m not sure why but setting the ‘style’ to 0 (which is a titleless window, what I thought Plain Box did) allows clicks to fall through, as if your window really isn’t there. Actually the click though happens when the alpha is F3 or above.

Add these lines to Open and try different black fill colors, &c000000F2 is draggable but &c000000F3 isn’t, yet the white opaque part still is.

//somehow allows very mostly transparent areas to not be clickable declare sub setStyle lib cocoa selector "setStyleMask:" (id As integer, mask As UInt32) setStyle(self.Handle, 0)

Hi Will.

Thank you very much for your code. This resembles what I’ve done before but I disregarded the color transparency
in the paint event:
g.ForeColor = &c000000->99

and so I had a different restult.

Anyway, I think I almost reach what I wanted to get except that a Text I put in the Box ( via Label or DrawString)
have distortion effects:

As little cure for that I made a shadow shadow beneath in pure black but it’s so-so and isn’t not consistent:

Any advice ?

Disable font smoothing, don’t have declare to hand, but it makes text much more legible.

FYI those will look ugly in Yosemite.

Looks perfect. Thx!

  soft declare sub CGContextSetShouldSmoothFonts lib CarbonLib (context as integer, shouldSmoothFonts as Boolean)

or

soft declare sub CGContextSetAllowsFontSmoothing lib CarbonLib (context as integer, flag as Boolean)

The top one.

Except it should be “Cocoa” and not “CarbonLib”, also being Cocoa you don’t need the “soft” in front.

declare sub CGContextSetShouldSmoothFonts lib "Cocoa" ( CGContextRef as integer, shouldSmoothFonts as Boolean)

The top affect that instance of the context, while the bottom affects the context overall. You only want to modify that instance of the context, otherwise it can have detrimental effects on other elements. I accidentally disabled anti-aliasing for the entire display with the wrong declare!

[quote=153896:@Sam Rowlands]The top one.
Except it should be “Cocoa” and not “CarbonLib”, also being Cocoa you don’t need the “soft” in front.
[/quote]
copied from MacOSLib and it works so why I assume it is right.

Thanks for your explaination

[quote=153842:@Rob Egal]Looks perfect. Thx!

  soft declare sub CGContextSetShouldSmoothFonts lib CarbonLib (context as integer, shouldSmoothFonts as Boolean)

or

soft declare sub CGContextSetAllowsFontSmoothing lib CarbonLib (context as integer, flag as Boolean) [/quote]

I just looked at MacOSLib which does contain that, but I have two issues :

[code]Sub SetShouldSmoothFonts(shouldSmoothFonts as Boolean)
#if targetMacOS
soft declare sub CGContextSetShouldSmoothFonts lib CarbonLib (context as Ptr, shouldSmoothFonts as Boolean)

CGContextSetShouldSmoothFonts me, shouldSmoothFonts

#endif
End Sub
[/code]

  • In what you post, you use an Integer, while MacOSLib uses a pointer
  • How in hell is me supposed to report anything but a control ?

It looks as though the thing in MacOSLib is not even used.

If you got this to work, a snippet will be most welcome. TIA.

declare sub CGContextSetShouldSmoothFonts lib "Cocoa" ( CGContextRef as integer, shouldSmoothFonts as Boolean) CGContextSetShouldSmoothFonts( g.handle( graphics.HandleTypeCGContextRef ), false )

I use an integer, quite simply because it’s what Xojo returns from a graphics object, laziness inside

[quote=154271:@Sam Rowlands]declare sub CGContextSetShouldSmoothFonts lib "Cocoa" ( CGContextRef as integer, shouldSmoothFonts as Boolean) CGContextSetShouldSmoothFonts( g.handle( graphics.HandleTypeCGContextRef ), false )

I use an integer, quite simply because it’s what Xojo returns from a graphics object, laziness inside[/quote]

I needed to see the actual code. Thank you, Sam :slight_smile: