Drawing on the title bar

Discussion in 'Mac Programming' started by titaniumdecoy, Dec 13, 2007.

  1. titaniumdecoy macrumors member

    Joined:
    Oct 13, 2005
    #1
    Hi all,

    I need to get rid of the line which separates a window's title bar from its contents. A textured window would be perfect for this task, except that its bottom corners are rounded, which is unacceptable for my purposes. So, is there any way to draw over a window's title bar? NSWindow has no -drawRect: method to override, so--how is this possible?

    Thanks.
     
  2. unknown.exe macrumors member

    unknown.exe

    Joined:
    Sep 22, 2007
    Location:
    Somewhere on Earth
    #2
    Well, what are you using to make your interface? Are you using the one that came with Xcode? Reply and I can help...:apple:
     
  3. titaniumdecoy thread starter macrumors member

    Joined:
    Oct 13, 2005
    #3
    Thanks, unknown.exe. I'm using Interface Builder on Leopard, if that's what you mean.
     
  4. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    Do a search for StyledWindow. It's an NSWindow subclass that gives windows the unified appearance for Tiger that Leopard now uses natively. You could use the method that it uses.
     
  5. titaniumdecoy thread starter macrumors member

    Joined:
    Oct 13, 2005
    #5
    @kainjow: Thanks for the suggestion, but! StyledWindow has the rounded corners which I hate.
     
  6. antibact1 macrumors 6502

    Joined:
    Jun 1, 2006
    #6
    A function has been added for this in the WebKit Libraries:

    void WKNSWindowMakeBottomCornersSquare(NSWindow *);

    Unfortunately, its part of the closed source libWebKitSystemInterfaceLeopard.a. Good to know it is possible though.
     
  7. antibact1 macrumors 6502

    Joined:
    Jun 1, 2006
    #7
    Alright, here is the solution! NSWindow has a private method

    -setBottomCornerRounded

    You can use a textured window and insert this code in the appropriate place (likely awakeFromNib)

    Code:
    if ([window respondsToSelector:@selector(setBottomCornerRounded:)])
    		[window setBottomCornerRounded:NO];
     
  8. titaniumdecoy thread starter macrumors member

    Joined:
    Oct 13, 2005
    #8
    Holy crap! Thanks man, I didn't think this would be possible.
     
  9. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #9
    I would not use private methods. If you want full control over your window's appearance, I'd subclass NSWindow, set the style mask to NSBorderlessWindowMask, and then put all your drawing in the window's content view.
     
  10. Eraserhead macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #10
    If it doesn't respond to the selector nothing happens, so what could actually go wrong (apart from having rounded edges to the window).
     
  11. antibact1 macrumors 6502

    Joined:
    Jun 1, 2006
    #11
    I wouldn't worry about using that method. The WebKit Library I previously mentioned is making use of it, so it is likely to remain around for a while.
     
  12. titaniumdecoy thread starter macrumors member

    Joined:
    Oct 13, 2005
    #12
    Well, if I did that I would have to recreate the title bar and the resizer, which would not be much fun at all.

    Also, since the method is accessible in an NSWindow subclass, wouldn't that make it protected rather than private?
     
  13. Sijmen macrumors 6502a

    Joined:
    Sep 7, 2005
    #13
    Technically speaking, there aren't any private methods. Either the object responds to the selector, or it does not. The method here is just not being publicized, and not officially supported. It might disappear or start doing something completely different without any warning.
     
  14. swearbymac07 macrumors member

    Joined:
    Dec 13, 2007
    #14
    Drawing over Title Bar...

    Do a search for Matt Gemmell, and download RoundedFloatingPanel. In the source folder is a .h file called Transparent Window which makes the entire window transparent and removes the title bar. All you need to do is create your own controls (Close, Minimize, Zoom) if u are using Tiger, otherwise they should still be there in Leopard. This allows you to create Modal-like windows in Cocoa.
     
  15. titaniumdecoy thread starter macrumors member

    Joined:
    Oct 13, 2005
    #15
    Although that would be possible I believe it would be more likely to break than simply calling the setBottomCornerRounded: method. And I don't feel much like building a title bar from scratch. But thanks for the suggestion.
     

Share This Page