Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to extend NSView, overwrite drawRect #33

Closed
matths opened this issue Apr 10, 2014 · 5 comments
Closed

How to extend NSView, overwrite drawRect #33

matths opened this issue Apr 10, 2014 · 5 comments

Comments

@matths
Copy link

matths commented Apr 10, 2014

This is not really a bug, but more of a question:

I'm just not able to find out, how to correctly inherit from NSView and overwrite the drawRect method, getting the rect parameter and call drawRect of super. Any help or hint would be welcome!

I extended the basic example by this:

var RedRectView = ObjC.NSView.extend('RedRectView');
RedRectView.addMethod('drawRect:', 'v@:@', function (self, _cmd, rect) {
//  console.log(rect); // already crashes
//  ObjC.NSColor('yellowColor')('set');
//  ObjC.NSRectFill(ObjC.NSRectMake(0,0,100,100));

    // [super drawRect:rect]; // how to call super?
//  RedRectView.getSuperclass()('drawRect', self);
});
RedRectView.register();

var redRectView = RedRectView('alloc')('initWithFrame', ObjC.NSMakeRect(0,0,100,100));
window('contentView')('addSubview', redRectView);
window('makeKeyAndOrderFront', null);

But as soon as I try some of these, the App crashes with a "Segmentation fault: 11".

@TooTallNate
Copy link
Owner

Can you give a full example to try? Specifically defining ObjC (though I can guess what that one is) and the window variable in particular. Thanks!

@matths
Copy link
Author

matths commented Aug 12, 2014

I've put together a gist:
https://gist.github.com/matths/fe075e431781dc933471

I probably do something stupid, so you can hopefully help within minutes. :P ;)

@trevorlinton
Copy link
Collaborator

@matths

See the comment I left on your gist, there were only some minor changes but it worked fine for me.

@trevorlinton
Copy link
Collaborator

@matths nevermind, it seems its intermittently failing and succeeding, i'll take a closer look.

#42

Creating this as a separate bug that's specific to the unit test, there may be more than one.

@TooTallNate
Copy link
Owner

Gonna close this one I think, now that #42 is tracking the seg fault. @trevorlinton's updated gist does indeed work for me (periodically).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants