Archive for May, 2009

Animated NSWindow resizing in 10.3 or later

Sunday, May 31st, 2009

I recently expanded a custom class I have to provide animated window resizing under 10.4. This is to provide a smooth change during style changes in the new 4.0 version of Lotus Meditation Timer (coming soon!).

I thought it might be fun to chop that class down even further into a simple, all-in-one method that provides animated window resizing without requiring 10.5 or 10.4, and has no need for callbacks or animation delegates.

A couple quick caveats:

  • The animation is blocking, no events in your app are processed while the window resizes
  • When providing a new rect for the window, pass the desired content size, do not adjust for the NSWindow’s titlebar, as this is handled automatically
  • To adjust framerate & speed, just change the appropriate variables inside the method
  • The BBWA_ prefixes are arbitrary and can be ignored or renamed
  • To avoid requiring 10.5, NSThread’s -sleepForTimeInterval is replaced with a simple usleep call, which requires that you #include <unistd.h> in your project, if it is not already. Or, you can use NSThread’s -sleepUntilDate, if you don’t want to use usleep
  • This method will ignore your target rect’s origin, and focus only on the window’s new size, keeping the window centered where it was on the screen
  • I wrote this up pretty quickly to post here so please forgive any mistakes or sloppy coding practices. I have tested this method, however, and it works quite well (for me), but if anyone has a problem with it let me know and I’ll be sure to update it

Easy as A-B-C. Here’s the code:

-(void)resizeWindow:(NSWindow*)theWnd toRect: (NSRect)r
{
    NSRect BBWA_startRect = [[theWnd contentView] frame];
    BBWA_startRect.origin = [theWnd frame].origin;
    //grab the center point
    NSPoint cp = NSMakePoint(BBWA_startRect.origin.x +
                             (BBWA_startRect.size.width / 2.0),
                            BBWA_startRect.origin.y +
                             (BBWA_startRect.size.height / 2.0));
    NSSize ts = r.size; //target size
    NSSize ss = BBWA_startRect.size;
    //for controlling speed of animation:
    float timeDur = .5; //in secs
    int frames = 30; //number of updates
    //
    float progress;
    int i;
    float pauseTime = (timeDur / (float)frames);
    NSRect frameRect;
    NSRect adjusted;
    NSSize dif = NSMakeSize( ts.width - ss.width,
                            ts.height - ss.height);
    NSSize adjSize;
    for(i=1;i<=frames;i++)
    {
        progress = ((float)i/(float)frames);
        adjSize = NSMakeSize(dif.width * progress, dif.height * progress);
        frameRect = NSMakeRect(cp.x - ((adjSize.width + ss.width) / 2.0),
                               cp.y - ((adjSize.height + ss.height) / 2.0),
                               adjSize.width + ss.width,
                               adjSize.height + ss.height);
        adjusted = [theWnd frameRectForContentRect: frameRect];
        [theWnd setFrame: adjusted display: YES];
        usleep((pauseTime * 1000000));
    }
}

And that’s all there is to it! Using that method you can quickly and easily resize an NSWindow and do it in a nice, animated, Mac-friendly way. And you don’t even need Tiger.

Cheers~

It’s BravoBug’s Birthday!

Friday, May 29th, 2009

BravoBug Software is 1 year old today. Thank you for making the last year a successful and fun one.

EasyBatch 1.3 Notes

Wednesday, May 27th, 2009

Several people have emailed me regarding EasyBatch’s EXIF preservation, specifically that they had trouble preserving things such as GPS data or orientation metadata while batch processing. Just wanted to post a quick note here to let EasyBatch users know that I am working on fixing this in the upcoming release of EasyBatch 1.3.

Thanks to those of you who pointed this out. A fix for this is on the way.

Coming soon, Lotus 4

Sunday, May 24th, 2009

Along with the other updates announced earlier this month, expect to see a new release of Lotus Meditation Timer. Lotus 4 will have several cool new features including quote sets and timer sessions to save and instantly restore frequently used meditation settings. More info to come.

Vimeo account blown-up…

Wednesday, May 20th, 2009

I received this in my Inbox today:

Dear BravoBug Software: Your account has been removed by the Vimeo Staff for violating the Rules of Vimeo.com. Reason: Uploading advertisements, commercials, infomercials, or videos that actively sell a product or service.

This is really unfortunate, since the few videos I uploaded were not meant to be commercials or advertisements, but were there for entertainment or demonstrative purposes. In fact, if I remember correctly, only one of the videos even relates to a Shareware app. The rest are screencasts of my freeware apps, simply to show how they work.

I’ve emailed Vimeo. Perhaps they’ll restore my account. But either way I apologize for the broken video links you’ll find on the website and the blog. I am aware of them, and at some point soon I’ll have this fixed, either (hopefully, fingers crossed) if Vimeo restores my account, or if I can find the original video files and move them to my own server and host them there.

Thanks for visiting~

Cocoa Quickies: Shake a window

Wednesday, May 20th, 2009

This is something I recently implemented, you’ll see it in BravoTunes when you try clicking the NSStatusBar item while the preferences window is open. The preferences window will ’shake’ quickly as a visual indicator that it needs to be dealt with first.

This is the same visual cue you can see when you enter an incorrect password in the Mac OS X login window. Enter a wrong code and the window visibly shakes ‘No’.

Anyways, this code is pretty elementary and just about any Cocoa newcomer would have no problem writing this, but nonetheless I really like little visual things like this so I thought it would be fun to post it up anyways.

(Thanks to Keith Bauer for pointing out the Cocoa-friendly NSThread alternative to my original usleep call).

Here’s the code:

-(void)shakeWindow:(NSWindow*)w
{
    NSRect f = [w frame];
    int c = 0; //counter variable
    int off = -5; //shake amount (offset)

    while(c<5) //shake 5 times
    {
        [w setFrame: NSMakeRect(f.origin.x + off,
                                f.origin.y,
                                f.size.width,
                                f.size.height) display: NO];
        [NSThread sleepForTimeInterval: .04]; //slight pause
        off *= -1; //back and forth
        c++; //inc counter
    }
    [w setFrame:f display: NO]; //return window to original frame
}

So there you go. Just drop that method in whatever controller or subclass you want, and you can shake and shimmy your windows all over the place.

A word on Brimstone

Monday, May 18th, 2009

I thought I would post a quick message up here about Brimstone, the epic fantasy RPG I’ve been working on for… well, quite a while. It’s largely been on hiatus despite being at a fairly mature stage in development, with a significant portion of the code base, graphics, sounds, music, and gameplay completed and functioning. The reason for this is simply all the other smaller projects which have taken precedence (ie, the updates for Blackout, MiLife, and some of the smaller new apps that have been released like BravoTunes).

But for those keeping an eye out, I wanted to put up a quick note to proclaim that Brimstone is not vaporware! And although the ’summer of 2009′ release estimate may not come true, the game is still in the works. So stay tuned!

New! BravoTunes 1.0

Monday, May 18th, 2009

BravoBug Software is proud to announce the release of BravoTunes 1.0, a free add-on utility for Apple’s iTunes software which displays scrolling track information in your Mac OS X status bar. BravoTunes can be fully customized with unique colors, fonts, scroll speeds, and more. It can display track info (title, artist, album) for the current and upcoming tracks and can display the elapsed time as a bar or pie chart style icon.

BravoTunes does more than that, however. Click the scrolling text and you’ll find a handy drop-down menu with easy access to basic iTunes controls: pause, play, skip tracks, or adjust your shuffle and repeat settings.

BravoTunes can be fully customized and even includes optimization options for the CPU-conscious. You can adjust syncing time, animation framerate, and graphics effects to ensure BravoTunes uses up the minimum amount of CPU, letting you focus on your heavy-duty Mac OS X apps while still enjoying iTunes track info at a glance.

Best of all, BravoTunes is free! Download your copy here, and enjoy.

Cocoa Quickies: Save an NSCursor as a .PNG image

Sunday, May 17th, 2009

Recently I needed to grab a pixel-for-pixel image (with transparency) of the normal Mac OS X system cursor (the standard ‘arrow’ cursor). I actually did not know where to find this resource, so I wrote up this Cocoa quickie which grabs the standard arrow cursor and saves its PNG out to an image file. (Granted, I’m sure there are easier ways to just grab the resource itself on disk, but since I didn’t know where it was, this seemed like a fun experiment.)

Best of all, like many things with Cocoa, it is surprisingly straightforward. The entire operation takes only 4 lines of code! Here’s the code:

NSImage *img = [[NSCursor arrowCursor] image];
NSBitmapImageRep *ir = [[img representations] objectAtIndex: 0];
NSData *data = [ir representationUsingType: NSPNGFileType
                            properties: nil];
[data writeToFile: @"/Users/matt/Desktop/myCursor.png" atomically: NO];

All done! (That was easy, wasn’t it?) And of course this works for any valid NSCursor you can get your hands on.

PS: Stay tuned for the official release of BravoTunes, planned for tomorrow!

Edit: Oh, a quick footnote just for technical accuracy, the above code could of course be crunched into a single line of code. But it reads a bit nicer in the 4 lines as written above. Cheers~

Coming soon… BravoTunes

Wednesday, May 13th, 2009

BravoBug Software is happy to announce the upcoming release of BravoTunes, an iTunes add-on utility which displays scrolling track information for the current and upcoming track in your menubar. It also offers a global menu to control iTunes, plus lots of customization options as well. Best of all, it’s free!

BravoTunes is in its final stages of testing right now and is due for release shortly, so please stay tuned for the official announcement!

Thanks for visiting~