After 20+ years of programming unix server software (TCP/IP, pthreads, IPC, etc.) I decided to go back to my roots and play around with graphics on my Apple. Of course my roots involved first BASIC then 6502 assembly in my Apple ][e. Now I'm trying to get my feet wet writing code using Cocoa on my Mac.
I've read through much of "Programming in Objective-C 2.0" and have a grasp of the syntax and structure of Objective-C. Last night, following an example I found online of drawing text in a window, I used Interface Builder to create a window and a custom view inherited off of NSView. I implemented the drawRect: method and created a bunch of NSRect structures (origin.x was iterated over the width of the view and origin.y was a random number up to the height of the view) and used NSRectFill to draw the rectangles. I ended up putting the NSRect structure (encoded in NSValue) into an NSMutableArray.
So here's my question - can anyone give me some pointers to online docs on how to best go about redrawing the rectangles as I swap them in a sort? I'm want to graph out several sorting algorithms starting with the simple bubble sort.
As near as I can tell NSApplicationMain calls into my view's drawRect: method and as soon as drawRect returns the view is rendered on screen. I guess what I'm looking for is a way to get NSApplicationMain to call into my code periodically - maybe through use of an NSTimer? - which will perform sorting of the NSRect structures in the NSMutableArray. I'm also guessing that every time I swap a pair of rectangles I need to call my view's setNeedsDisplay: method and then return so that NSApplicationMain can handle calling my drawRect and then rerendering the screen?
Any help you can give is very much appreciated. As you can tell I'm new to this whole model view controller GUI thing.
I've read through much of "Programming in Objective-C 2.0" and have a grasp of the syntax and structure of Objective-C. Last night, following an example I found online of drawing text in a window, I used Interface Builder to create a window and a custom view inherited off of NSView. I implemented the drawRect: method and created a bunch of NSRect structures (origin.x was iterated over the width of the view and origin.y was a random number up to the height of the view) and used NSRectFill to draw the rectangles. I ended up putting the NSRect structure (encoded in NSValue) into an NSMutableArray.
So here's my question - can anyone give me some pointers to online docs on how to best go about redrawing the rectangles as I swap them in a sort? I'm want to graph out several sorting algorithms starting with the simple bubble sort.
As near as I can tell NSApplicationMain calls into my view's drawRect: method and as soon as drawRect returns the view is rendered on screen. I guess what I'm looking for is a way to get NSApplicationMain to call into my code periodically - maybe through use of an NSTimer? - which will perform sorting of the NSRect structures in the NSMutableArray. I'm also guessing that every time I swap a pair of rectangles I need to call my view's setNeedsDisplay: method and then return so that NSApplicationMain can handle calling my drawRect and then rerendering the screen?
Any help you can give is very much appreciated. As you can tell I'm new to this whole model view controller GUI thing.