Re: Dynamically update drawRect
I'm still don't know how to do it. As solution i see programmically create MyView class and call drawRect function as i needed. Because now MyView(NSView) is created by nib. And i can't call MyView class instance methods. How to programmically add Custom View and set MyView class ? On Sun, Dec 27, 2009 at 12:33 AM, Quincey Morris quinceymor...@earthlink.net wrote: On Dec 26, 2009, at 13:58, Gideon King wrote: DrawRect is not called directly by you - instead, you use setNeedsDisplayInRect: and setNeedsDisplay: to tell the system the dirty rect to redraw, and those rects are combined before the system locks focus on your view and calls drawRect:/ You therefore can't pass information to your drawing method - you have to use the state information you set in your program to work out how to draw the rects you need to draw. HTH Gideon I have two classes. One for internet connection(program logic) and one to display graphics(i posted code). And i want to call drawRect from another class and pass some data to drawRect method. Seems like drawRect method is just for static graphics. Does there's any possibility to do it ? Any examples ? In any case, it seems like short-sighted design to have a view's drawing methods called directly by another class (even if the concept made sense in the Cocoa scheme of things). Rather, provide a method for other classes to call that specifies their rect of interest and other parameters, and have that method decide how to get things drawn accordingly. This might be as simple as stashing the parameters in instance variables and invoking '[self setNeedsDisplayInRect: suppliedRect]', but might also get more sophisticated if there might be *multiple* invocations before drawing actually occurs, in which case you'd have to decide how to resolve the various sets of possibly conflicting parameters, right? ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/pproger1%40gmail.com This email sent to pprog...@gmail.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Dynamically update drawRect
So now i don't see how to solve this problem. I thought it's not very hard problem - get data and paint it. Maybe i need to use other tools ? I think with libSDL framework it's very simple to solve such thing. I'm wanted to learn more about CG but seems even simple problem is too hard for me. Maybe i need to MyView constructor add my program logic and invoke '[self setNeedsDisplayInRect: suppliedRect]' ? On Sun, Dec 27, 2009 at 11:37 AM, Andrew Farmer andf...@gmail.com wrote: On 27 Dec 2009, at 01:18, proger proger wrote: I'm still don't know how to do it. As solution i see programmically create MyView class and call drawRect function as i needed. There is rarely any good reason to call drawRect yourself. It should only be called by the AppKit drawing internals. Because now MyView(NSView) is created by nib. And i can't call MyView class instance methods. Why not? This is the basis of most (non-KVO) view programming. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Dynamically update drawRect
Hello, Sorry for such newbie questions. With IB i added NSView Custom Object: http://grab.by/1peO . And i made IBOutlet: @interface testViewAppDelegate : NSObject NSApplicationDelegate { NSWindow *window; IBOutlet NSView *customView ; } I wrote such code for make NSRect and change color: (void)applicationDidFinishLaunching:(NSNotification *)aNotification { // Insert code here to initialize your application NSRect frame = NSMakeRect(10, 10, 100, 100) ; [[NSColor blueColor] set]; [NSBezierPath fillRect:frame]; [customView setNeedsDisplayInRect:frame]; } But the problem is that NSRect is added to Window and not to my Custum View http://grab.by/1peS . How to solve that NSRect would be added to my Custom View. I think i doing something wrong, because NSWindow and Custom View is different contexts. Thanks On Sun, Dec 27, 2009 at 2:10 PM, Quincey Morris quinceymor...@earthlink.net wrote: On Dec 27, 2009, at 01:18, proger proger wrote: I'm still don't know how to do it. As solution i see programmically create MyView class and call drawRect function as i needed. Because now MyView(NSView) is created by nib. And i can't call MyView class instance methods. How to programmically add Custom View and set MyView class ? I think the piece of information you're missing is that, in Interface Builder, when you drag a custom view object into a window, you can then set the *class* of the custom view to any NSView subclass that's defined in your project (such as MyView, if that's what you've called it). Then, since your custom view is in a nib, you'll need a way of referring to it. Normally, you'd add an outlet to the nib's File's Owner object, and connect that to your view. That gives you what you need: a custom view created automatically when the nib is loaded, plus a reference to the custom view that you can use for sending messages to. Further references: http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CocoaViewsGuide/SubclassingNSView/SubclassingNSView.html#//apple_ref/doc/uid/TP40002978-CH7-SW4 http://developer.apple.com/mac/library/documentation/DeveloperTools/Conceptual/IB_UserGuide/EditingNibFileObjects/EditingNibFileObjects.html#//apple_ref/doc/uid/TP40005344-CH12-SW31 http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/LoadingResources/CocoaNibs/CocoaNibs.html#//apple_ref/doc/uid/1051i-CH4-SW19 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/pproger1%40gmail.com This email sent to pprog...@gmail.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Dynamically update drawRect
Hello, I'm trying to write simple application with Core Graphics. My code: @implementation MyView - (id)initWithFrame:(NSRect)frameRect { self = [super initWithFrame:frameRect]; return self; } - (void)drawRect:(NSRect)rect { myContext = [[NSGraphicsContext currentContext]graphicsPort]; CGContextSetRGBFillColor (myContext, 1, 0, 0, 1);// 3 CGContextFillRect (myContext, CGRectMake (0, 0, 200, 100 ));// 4 } - (void) dealloc { [super dealloc]; } I have two classes. One for internet connection(program logic) and one to display graphics(i posted code). And i want to call drawRect from another class and pass some data to drawRect method. Seems like drawRect method is just for static graphics. Does there's any possibility to do it ? Any examples ? ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: applicationShouldTerminate problem
Thanks for point. Now I'm experimenting with document based cocoa application. I'm added NSTextView to my application interface, but after i load file i didn't see anything. My code: - (void)windowControllerDidLoadNib:(NSWindowController *) aController { [super windowControllerDidLoadNib:aController]; // if i add [textView setString: @test] i can see this text on the first window. } - (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError { NSData *data = [textView RTFFromRange:NSMakeRange(0, [[textView textStorage] length])]; if (!data outError) { *outError = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileWriteUnknownError userInfo:nil]; } return data; } - (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError { BOOL readSuccess = NO; NSAttributedString *fileContents = [[NSAttributedString alloc] initWithData:data options:NULL documentAttributes:NULL error:outError]; if ( outError != NULL ) { *outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL]; } if (fileContents) { readSuccess = YES; [[textView textStorage] setAttributedString:fileContents]; NSLog(@%@, fileContents) ; // I can see output in console, but not on textView [fileContents release]; } return readSuccess; } and my mydocument.h #import Cocoa/Cocoa.h @interface MyDocument : NSDocument { IBOutlet id textView ; NSData * dataFromFile; } @end Seems like i need to make additional connections in Interface Builder ? Thanks ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Fwd: applicationShouldTerminate problem
Hello, I'm making little cocoa application. After the application will be closed i need to show alert. So i created applicationShouldTerminate delegate: - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)app { if (textChanged == 1) { int ret = NSRunAlertPanel(@Save the work?, @Do you want save the work?, @Yes, @Cancel, @No ) ; if (ret == NSAlertDefaultReturn) { if (save == 0) { NSSavePanel *saveDlg = [NSSavePanel savePanel] ; if ([saveDlg runModal] == NSOKButton) { NSString *filename = [saveDlg filename] ; save = 1 ; NSString *saveFileName = filename ; NSError *error; NSString *text = [[textView textStorage] string] ; BOOL ok = [text writeToFile:saveFileName atomically:YES encoding:NSUnicodeStringEncoding error:error]; if (!ok) { NSRunAlertPanel(@File haven't saved, @File haven't saved, @OK, nil, nil) ; NSLog(@Can't save file %@, saveFileName) ; } } } return NSTerminateNow ; } if (ret == NSAlertAlternateReturn) { return NSTerminateCancel ; } if (ret == NSAlertOtherReturn) { return NSTerminateNow ; } } return NSTerminateNow ; } I used Interface Builder to delegate NSApplication with my delegate controller. But don't see any results. But i investigated if i'm also add this delegate method: -(BOOL) applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication { return YES; } So applicationShouldTerminate is called. But i'm still have problem because then NSAlert is shown(i don't see my application window, it hides) and if i press Cancel button NSAlert still shown again. I want to see my application window then i see NSAlert and Cancel NSAlert button is needed to to work correctly. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com