I wanted to create a custom window, but NSBorderlessWindow is ugly, because you have to implement most of the functionality yourself. Taking a page from Uli, I extended that functionality a little bit.

I present you with my hacky box:

A super hacked Cocoa window

UPDATE:

Anyone who has tried to use the code below, would get this result: A not-so-nice hacked Cocoa window

A method went missing. I've added it to the code below.

Notable things:

  1. This is just a textured window. All usual functionality (resizing, exposé, shortcuts) is there.
  2. Notice the location of the close/miniaturize/zoom buttons. They are moved to the right.
  3. The resize handle is also moved to a better location.
  4. The window title (aptly named, "Window") is the usual one, set in IB.
  5. No borders are drawn.
  6. When resized, the image scales with the window.
  7. I can't draw :)

To do this, download the above mentioned class, and add the following methods:

- (struct _NSPoint)_closeButtonOrigin
{
    NSPoint point =  [super _closeButtonOrigin];
    point.x += 35.0;
    point.y -= 5.0;
    return point;
}
- (struct _NSRect)_titlebarTitleRect
{
    NSRect res = [super _titlebarTitleRect];
    res.origin.y-=6.0;
    return res;
}
- (struct _NSRect)_maxXminYResizeRect
{
    NSRect res = [super _maxXminYResizeRect];
    res.origin.x-=13;
    return res;
}
// to make the borders disappear
+ (void)drawBevel:(struct _NSRect)fp8
          inFrame:(struct _NSRect)fp24
 topCornerRounded:(char)fp40
bottomCornerRounded:(char)fp44
{
    return;
}

Can't help with the drawing skills, sorry. You have to be born with them.

Of course, all this is undocumented and will probably break tomorrow... But still, it's fun and a much better way than reimplementing everything in a borderless window!

September 24, 2007, 10:22 p.m. More (268 words) 3 comments Feed
Previous entry: Προσοχή στη Viva phone!
Next entry: Leopard Calendar Store

Comments

1

Comment by Uli Kusterer , 2 years, 11 months ago :

Oooo. Nice hack! :-)

Instead of struct _NSRect, you can just say NSRect. The latter is typedefed to be equivalent to the former. Same for struct _NSPoint.

Oh, and that's not a drawing, that looks more like a painting :-p

2

Comment by Orestis Markou , 2 years, 11 months ago :

I just copied the methods over from the Secret Headers you supplied :) While I can't use NSRect in the code, _NSRect seems to work in the method signature.

I'm still very new to Cocoa & Objective-C, my MacBook is about 1 month old...

Well, I can't paint either :)

3

Comment by Mark Hilley , 2 years, 11 months ago :

Cool trick! I just started learning cocoa last week, but this is definitely on my list of things to try. Thanks for posting.


This post is older than 30 days and comments have been turned off.