Loading ".nib" Files for Customized Interfaces
<< previous | Chapter 9. Graphical User Interface | next >>

## Loading ".nib" Files for Customized Interfaces

### Mac OS X only

This feature is available under Mac OS X only.

breve offers basic support for loading customized ".nib" files to give more customized interfaces to simulations. Users can design a customized window of controls (like buttons, sliders, checkboxes, etc.) and load it when the simulation is run. This feature is only available on the Mac OS X version of breve.

In order to build customized interfaces, the Mac OS X development tools including "Interface Builder", must be installed. A basic understanding of Interface Builder is also very helpful.

To implement a customized interface for your simulation, follow the following steps:

- Make a copy of the interface template file included with the breve distribution.

- Open the new template file with Interface Builder.

- In the Instances tab of the interface window, open the "InterfaceWindow" instance.

- Add interface elements from the included palette to the window.

- For each interface element you add, you should give it a unique "tag" number in it's inspector window (select the object, press command-1).

- Save the file.

- At the top of your simulation file, add a line for the file: `@nib_file "`filename`"`.

- For each interface action you wish to catch, you'll need a method with the corresponding tag number:

      + to catch-interface-id-xxx with-string s (string):

  You can also set the values of interface with the method set-interface-item in the class Control.tz. In both cases—for both catching and setting interface values—note that even though the interface value is expressed as a string, the actual value is often a number. A slider interface element, for example, will actually give (and expect) a number value, but on the breve side, it will be expressed as a string. steve's automatic conversion between `ints`, `floats` and `strings` typically takes care of this automatically.

When the user interface element with the corresponding tag is activated, these methods will be called with the string value of the interface element. In the case of most types of controls, like buttons or sliders, you'll generally want to use the string value as a number to set some parameter.

### Creating ".nib" Files Without Using the Included Template

It is best to use the included template for creating your own custom nib files because the process for creating them from scratch can be a bit confusing. Nevertheless the process is described below for those who are curious:

- Launch interface builder

- Create a new "Cocoa, Empty" nib file

- In the document window, click on the "Classes" tab

- Control-click on "NSObject", select the menu entry "subclass NSObject". A new object called "MyObject" will appear--rename this object to "slBreveNibLoader"

- With the slBreveNibLoader object selected, bring up the info window with Command-1

- In the "Outlet" tab of this window, click add. Name the new outlet "window".

- Click back to the "Instances" tab of the project. Click on "File's Owner", and type Command-5 to bring up the "Custom Class" inspector. Find the object "slBreveNibLoader" from this list and select it.

- Go back to the "Instances" tab of the project. From the "Cocoa Views" palette, drag a "Window" object to the "Instances" area.

- Select the "File's Owner" icon. Control-click and drag from the "File's Owner" icon to the icon of the newly created window.

- In the "File's Owner" info window that appears, select the item "window" and then click on the connect button.

<< previous | Up | next >>
Displaying a Dialog Box | Table of Contents | Chapter 10. Saving Movies and Snapshots