Cocoa: drop down menu buttons
Sunday, January 29th, 2006[[mybutton cell] sendActionOn:NSLeftMouseDownMask];
Cool!
January, 2006 ArchivesCategories
Recent Posts
Archives
Admin |
Archive for January, 2006Cocoa: drop down menu buttonsSunday, January 29th, 2006
In Cocoa, it is pretty easy to use an NSButton that creates a drop down menu. One of the key-tricks to making it appear to be an NSPopUpButton is to set the [NSCell sendActionOn:]. Generally, menus are displayed on mouse down, not up. Normally, the action for a button is sent on mouse up. To get around this, you can simply access the cell of your button and tell it to send the action on mouse down:
[[mybutton cell] sendActionOn:NSLeftMouseDownMask]; Cool! Uniplex: Episode 2Sunday, January 29th, 2006
Uniplex Episode 2 is out!
Download the w4v file and play it with QuickTime 7 or subscribe to the podcast in iTunes. This episode has Trevor Blackwell and his self-balancing electric unicycle. Plus, some interviews with the bunch of coker-addicts who are going on a uni tour through Laos! One year at Apple.Tuesday, January 17th, 2006
Today is my one year anniversary at Apple! Apple is a great company, and I have been having a great time working on the AppKit framework and I’m looking forward to all the cool new things in Leopard that I get to work on.
Woodworking: Box #3Sunday, January 15th, 2006
Today, I finished box #3. It is a simple box, with a slight pyramid shape. The edges slant upwards at a 5 degree angle. It is made of redwood (home depot junk redwood!) that I resized to 1/2“ on my crappy table saw. The top fits on the base via a rabbet on underneath the lid. The finish is Danish oil.
Check out the four pictures in my gallery: Corbin’s Pictures – Box #3 Proteas. Macro Photography.Saturday, January 14th, 2006
Today, I went to the UCSC Arboretum with Chris Bensen and took some great pictures in between some pouring rain downfalls. I used my 100mm macro lens, and I got a few good shots. Take a look at my favorites here at Corbin’s Pictures – Proteas – UCSC Arboretum.
Here’s an oversight. Here is a gorgeous protea, glistening in the rain: A really cool depth of field in this photo of a Bansky (sp): Cool droplets, falling off the flower: My dad used to grow proteas at our house in Corralitos. I have always had an interest in flowers, and proteas are some of my favorites. Tango lessons!Friday, January 13th, 2006
On last Tuesday night, I took my first tango lesson. It is really cool! Check out Steppin’ Out Productions.
synergy on Intel MacOS XFriday, January 13th, 2006
Hi All. I use synergy to share my keyboard/mouse on my computers. I recompiled the server for Intel MacOS. Feel free to grab it and use it:
synergyc_synergys_mac_intel.zip. It is an Intel ONLY binary. It will not work on PPC. MacBook Pro: I want one!Tuesday, January 10th, 2006
If you haven’t heard, Apple has new laptops, the MacBook Pro. I want one!
Photography: Great tree pictures from Castle RockTuesday, January 10th, 2006
Last weekend, I took a trip up to Castle Rock state park. It is a popular climbing destination, and there is some gorgeous scenery. I went by myself, and brought my camera along with my climbing shoes strapped to my waist. I put up a gallery for some of the best photos here: Corbin’s Pictures – Castle Rock – January 2005. I’ll highlight a few of my favorites.
Here is a cool picture of a very mossy branch: In the gallery, you can see a few pictures before and after it giving different perspectives. I was quite happy with this one, and the full size image looks pretty good. This picture displays some of the gorgeous green moss that exists at Castle Rock: The photo almost looks fake, and the greens are so vibrant. This photo is another good picture: I really like mossy tree tops! There are several other good pictures in the gallery. Be sure to take a look! Cocoa: Creating a custom Color Picker in Cocoa. Part 1.Sunday, January 8th, 2006
It is pretty easy to create a custom Color Picker that is available in any application, or for just your particular app. It isn’t difficult to do, but there are some caveats that you must be aware of.
I’m going to go over this as a step-by-step tutorial; we need more Cocoa tutorials out there, so this will be one of them! Start by creating a new Cocoa Bundle inside of Xcode (File | New Project…)
Now, be careful what you name your bundle — the name must correspond to the main color picker’s classname. Once you have your project created, double click on the project in Xcode and set the output directory to be ~/Library/ColorPickers :
Note that in order for this to work correctly in Xcode 2.0, you must have Xcode’s user default UsePerConfigurationBuildLocations set to NO. You can do this from the command line with: defaults write com.apple.xcode UsePerConfigurationBuildLocations NO Read the Xcode Expert Preferences Notes for more information on this option. Next, double click on the bundle target to bring up its options
In the build options, set the Wrapper Extension to be colorPicker and the Installation Directory to $(HOME)/Library/ColorPickers.
Then, on the Properties tab, set the Principal Class to be your new Color Picker (which we actually haven’t made yet):
Once you have your project setup, you can then start creating your UI in Interface Builder by creating a new empty nib:
Then, you can drag a new view into the nib (note: you must have Tiger to do this!):
Next, you can setup the UI to look the way you want, save the nib, and add it to the Xcode project (I called it “MyPicker.nibâ€):
Now we want to jump back to XCode and create a controller for the nib file, and the main color picker class. A long time ago, we decided to call it “RadiantColorPickerâ€. In XCode, select “File | New…†and create an Objective C Class named RadiantColorPicker:
Change the class to inherit from NSColorPicker and declare that it is going to implement the NSColorPickingCustom formal protocol. Some important things to note here: In Tiger and Panther, you MUST descend from NSColorPicker. The documentation incorrectly states that you can implement NSColorPickingDefault or descend from NSColorPicker (note that this will be fixed). @interface RadiantColorPicker : NSColorPicker <NSColorPickingCustom> { @private   // Add two outlets to access things in the nib file we will load   IBOutlet NSView *mainView;   IBOutlet NSTextField *textField; } @end The “mainView†will be the view that is placed in the Color Picker, and the textField will give us access to our TextField. To set those things up in the nib file, drag the RadiantColorPicker.h file from Xcode and drop it into the nib file in Interface Builder. Click on the “File’s Owner†in the Instances of the nib file, and set the custom class to be it:
Then, hook up the outlets. It is important to drag the mainView outlet to the actual view itself:
(okay…this is just a start. I’ll eventually finish this). |
(c) 2008-2012 Corbin Dunn
Corbin's Treehouse is powered by WordPress. Made on a Mac.
Subscribe to RSS feeds for entries and comments.
14 queries. 0.356 seconds.