Containment
It is not an accident that the components of a Hyperwire title are called modules. Consider what a module is. It is a self-contained piece of functionality that has inputs it can respond to and outputs it can trigger. To use a Hyperwire module, you don't need to know how it implements its functionality or what its internal code looks like. You only have to trust that it does what it is supposed to do, responds to its inputs correctly, and triggers its outputs when their associated events occur.
A Visual Container module is simply a Hyperwire module that you create yourself. There are three basic reasons for using a container:
The more complex your title is, the more modules and wires it has, and the more complicated Wire view becomes. Putting self-contained portions of code into containers simplifies the Wire view of the overall title, and helps clarify how your title works.
Containers let you make a package of Hyperwire modules and logic that you can then reuse in various situations and in different titles.
You can make a container into a reusable, custom module that you add to an application from the Modules menu or the Module panel, just as you do the modules provided with Hyperwire. Custom module's extend the functionality of Hyperwire titles.
Separating the title's logic into containers can make it easier to debug and maintain your title. Once a container works the way you want it to, you don't need to worry about its logic any more.
A container in a title appears as a single module icon.
You connect it to other modules by wiring its input and output ports
as you do other kinds of modules.
To change the logic inside the container, first open it by clicking the Open button on the container's icon. Hyperwire opens a window to display the interior of the container. The open container window looks just like a title window (a title is in fact simply a top-level container). Edit the logic inside the container as needed, and then close the window.
The Run Container button (or the menu choice Container/Run Container) runs the container so you can test it independently of the title as a whole.
There are two ways to create a container in Hyperwire. The following steps describe each way, with what is possibly the easier way first.
To create a container by selecting modules:
Usually the easiest way to do this is to drag a selection box in Wire view.
Wires that connect selected modules become part of the selection. A wire that connects a selected module to an unselected module does not become part of the selection, but Hyperwire creates a custom input or output port for that wire, so the connection between modules is not lost.
Hyperwire creates a Visual Container module and places the selected modules and wires inside it.
If there are connections to unselected modules, Hyperwire creates custom ports for the container so the connections between modules are not lost.
To wire modules in a container to the container's ports, first open the container and then wire the modules to the container ports whose buttons appear along the lower edge of the open container window.
After the wire is connected, the port appears in the Wire view of the open container as a "floating" input or output port icon.
To create a container by filling an empty container:
To wire modules in a container to the container's ports, first open the container and then wire the modules to the container ports whose buttons appear along the lower edge of the open container window.
After the wire is connected, the port appears in the Wire view of the open container as a "floating" input or output port icon.
Exercise 7 demonstrates how to create a container "from scratch," by adding it to the title and then placing modules inside it.
You don't actually have to use a container to create a custom module, but if the custom module requires custom ports, a container is the most straightforward way to do this, as the steps below indicate.
To create a custom module:
This container will become the custom module.
If you created a container, all you have to do is select the closed container.
Hyperwire saves the selected code as a .Ttl file.
If you saved a container, you are now ready to add the module to the Hyperwire interface and begin using it.
If you saved a collection of selected modules and wires, you must open the new title file in Hyperwire, and add custom ports to it as necessary, then save it again before you proceed to the next step.
This adds the new module to the Hyperwire Modules menu and the Module panel.
This dialog also lets you enter comments and version information about the module, and identify yourself as the module's author.
The module is now ready to be used by you or by anyone else you distribute it to. As long as it remains in \Hyperwire\Modules\ or a subdirectory of \Hyperwire\Modules\, Hyperwire makes it available on the menu and panel whenever you start Hyperwire.
Exercise 8 demonstrates how to create a custom module and add custom icons for the Hyperwire interface.