Rotate NSImage in an NSImageView
As soon as I implemented this I realised how much of a pain it would be to copy out the arrow images, rotate them in an external program, then copy them back in. So I put some buttons next to the arrow image wells that allow the user to rotate the arrows within Slider itself.
Drag and Drop Reordering of NSTableView’s Rows
I just had to re-implement drag-and-drop-reordering of Slider cells. I was lucky enough to find my post on the Cocoa-dev list – I just had to copy-paste the code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | #define MyPrivateTableViewDataType @"NSMutableDictionary" - (void)awakeFromNib { [table registerForDraggedTypes:[NSArray arrayWithObject:MyPrivateTableViewDataType]]; } - (BOOL)tableView:(NSTableView *)tv writeRowsWithIndexes:(NSIndexSet *)rowIndexestoPasteboard:(NSPasteboard*)pboard{ // Copy the row numbers to the pasteboard. NSData *data = [NSKeyedArchiver archivedDataWithRootObject:rowIndexes]; [pboard declareTypes:[NSArray arrayWithObject:MyPrivateTableViewDataType] owner:controller]; [pboard setData:data forType:MyPrivateTableViewDataType]; return YES; } - (NSDragOperation)tableView:(NSTableView*)tv validateDrop:(id <NSDraggingInfo>)info proposedRow:(int)row proposedDropOperation:(NSTableViewDropOperation)op{ // Add code here to validate the drop NSLog(@"validate Drop"); return NSDragOperationEvery; } - (BOOL)tableView:(NSTableView *)aTableView acceptDrop:(id <NSDraggingInfo>)info row:(int)to dropOperation:(NSTableViewDropOperation)operation{ //this is the code that handles dnd ordering - my table doesn't need to accept drops from outside! Hooray! NSPasteboard* pboard = [info draggingPasteboard]; NSData* rowData = [pboard dataForType:MyPrivateTableViewDataType]; NSIndexSet* rowIndexes = [NSKeyedUnarchiver unarchiveObjectWithData:rowData]; int from = [rowIndexes firstIndex]; NSMutableDictionary *traveller = [[controller arrangedObjects] objectAtIndex:from]; [traveller retain]; int length = [[controller arrangedObjects] count]; NSMutableArray *replacement = [NSMutableArray new]; int i; for (i = 0; i <= length; i++){ if(i == to){ if(from > to){ [controller insertObject:traveller atArrangedObjectIndex:to]; [controller removeObjectAtArrangedObjectIndex:from+1]; } else{ [controller insertObject:traveller atArrangedObjectIndex:to]; [controller removeObjectAtArrangedObjectIndex:from]; } } } } |
Posting replies to the lists helps more than just the receiver – keep in mind that source code can be lost. Time is saved when tedious sections can be copy-pasted in during rewriting!
Eclipse Negative Colour Scheme
Moving from XCode to Eclipse, I miss the simplicity of switching colour schemes in XCode. My eyes have become accustomed to light text on black, and the reverse shocks them.
After some googling I found this eclipse negative colour scheme preferences file: Inkpot. If you don’t like that one, there are more at the Eclipse Colour Scheme page.
Prepare your eyes for a feast, for I have included a screenshot of Inkpot below:
Slider Update – Tab Feature Coming Together
As I finally reached a programming goal I had set – the tab hover javascript was working fairly well – I realised that users would want the option of positioning the tabs in the middle or corners of Slider’s four sides. Initially I had assumed it would be OK for users to have tabs positioned only in the center of either of the four sides.
Great, I thought. This shouldn’t be too bad – just increase the number of radio buttons available and position the tabs accordingly.
Four hours later, I “achieve” a build of Slider that exports without the dreaded Uncaught Exception 10.
None of the Javascript works, turns out that was where the final erroneous lines were. Not in the 6 other class files I combed through. Duh.
The radio buttons for selecting tab position changed from:

Ugh, these are so yesterday
to:

Positioning Radios as they should be.
Here is an example of the type of thing you’ll be able to do with Slider, when the rewrite is finally done:

It's getting there!
Finally, I feel like the hours I’ve spent mashing my hands on my keyboard are starting to show results.
Not working, releasable results, but results all the same.
Still not working: arrows, timer, content (!), table row repositioning, titles, text shadow, effects (or any sliding at all, come to think of it), cell links.
I have another project that I will soon have to devote serious time to, but I’ll continue plugging away at Slider, I’m excited about the new version!
How to Prevent Noisy NSBitmapImageReps

Images generated for Slider’s background and tabs contained a lot of noise – random ugly pixels throughout the images.
I was unsure why this was happening, so I asked the Cocoa-Dev mailing list.
Rob Keniger kindly replied with the following solution:
“An NSBitmapImageRep is not guaranteed to be empty when you create it and in general it’s just full of random bits. You need to clear it explicitly if you are drawing non-opaque content”
He included the following snippet that solved my problem nicely:
1 2 3 4 5 6 7 | - (void) clearBitmapImageRep:(NSBitmapImageRep *)bitmap { unsigned char* bitmapData = [bitmap bitmapData]; if (bitmapData != NULL) { bzero(bitmapData, [bitmap bytesPerRow] * [bitmap pixelsHigh]); } } |
I call it as soon as I’ve created a new NSBitmapImageRep, like so:
1 2 3 4 5 | NSBitmapImageRep *theImage = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL pixelsWide:imageSize.width pixelsHigh:imageSize.height bitsPerSample:8 samplesPerPixel:4 hasAlpha:YES isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace bytesPerRow:0 bitsPerPixel:0]; [self clearBitmapImageRep:theImage]; |
This results in noise-free images.

Thanks Rob!


