TweetFollow Us on Twitter

Customizing AppMaker 2
Volume Number:12
Issue Number:12
Column Tag:Development Environments

Customizing AppMaker 2.0

Making AppMaker add button sounds to PowerPlant

By Andy Dent, Perth, Western Australia

Note: Source code files accompanying article are located on MacTech CD-ROM or source code disks.

A Mixed Bag of Tools

AppMaker is an interface design and code generation tool by Bowers Development. It is incredibly flexible and has a reputation for generating clear code. Many people have learned to program the Mac from studying AppMaker-generated code.

The new version of AppMaker has changed radically and you can look forward to a comprehensive review when 2.0 finally arrives. However, 2.0b4 is already an extremely usable beta. This article shows part of how a real world problem was solved with a mixture of AppMaker and PowerPlant. The main idea is to taste the essence of AppMaker - its ease of extension when you need a little bit more.

Our project was to simulate an interface with pictures, invisible buttons and sounds when the buttons were clicked. The simulation had to be compiled as a Macintosh executable for shipping to clients.

It was easy to draw up the interface in AppMaker and place the buttons, but AppMaker currently lacks support for attached sounds. Because our prototype was changing frequently, it was not feasible to repeatedly re-apply changes to the generated code. So we decided to extend AppMaker to include sounds on buttons. This required changes to AppMaker and writing some additional code:

• Change the AppMaker interface to allow us to type in the name of a ‘snd ’ resource for a button.

• Change the AppMaker definition of a window item, to store the ‘snd ’ name.

• Add logic to the code generation to allow calling the sounds.

• Add PowerPlant classes to play the sounds and attach them to the buttons.

A Brief History of AppMaker v2

Version 2 is a complete rewrite from 1.5 and looks very different. It underwent a redesign for portability, customisability, and extensibility. This included removing the need to choose your target environment up-front, making it purely a generation-time decision.

The new design was implemented with Component Workshop in 1993 and 1994. The first version (AppMaker 2.0b1) had major speed problems and was almost unusable. (Anyone remember Component Workshop, the interpretive Dylan-like environment for C++ that showed so much promise?)

In late 1994 Bowers started converting to real C++ and PowerPlant and had that running in mid 1995. The first PowerPlant version (2.0b2) was rather unstable but around 5 times faster. Versions 2.0b3 and 2.0b4 have improved since in features and stability, and Bowers Development anticipates completion in mid 1996.

Version 2.0b4 adds many crucial layout editing features such as alignment, nudging with arrow keys, etc. Support for Jim’s CDEF’s was also added; these gave very usable tabbed dialog controls. It is almost feature-complete, with very little left to do other than fine-tuning some of the interface.

Bowers Development has followed a very Metrowerks-like path of steadily increasing the features and quality of the product with their regular CD releases. OpenDoc framework generation has been available since version 2.0b3 and all the major Mac frameworks are covered as well as procedural C.

Using AppMaker - a Quick Summary

To get started with AppMaker, you either create a new document or pick up one of the samples and customize it. You can option-drag items between documents to easily copy portions across, like the standard menus. The editing environment is much like a drawing program, with a palette of window items and windoids that let you set styles and coordinates. Drag and drop is used heavily to move items around and to copy items within windows. You edit windows in a visual sense but you can also open a hierarchy much like in Metrowerk’s Constructor.

AppMaker does not let you set text fonts or styles directly, nor play with individual item colors. Instead, you define Text Styles and Drawing Styles. These are akin to the stylesheets of a word processor. This is a little strange at first, but it helps immensely when prototyping - a single style change lets you try totally different fonts or colors throughout several screens.

The basic process of use is design-generate-compile. You can also run a simulation within AppMaker to partly simulate the behavior of your screens, including buttons that open or close other windows. The code generator totally replaces the code each time, unlike v1.5 which let you choose which files to regenerate. More sophisticated regeneration behavior is on the to do list. As well as source, AppMaker generates resource files, including the PowerPlant PPob resources.

When you generate code, you first have to select a Language file. This file implies not only a programming language, but the destination framework. If you are generating straight procedural C, then a substantial number of library functions are included.

AppMaker is (largely) written in AppMaker. The AM Prefs and AM Interface files define all the data it stores, and how you edit that data. This means at any time you can add a new data field, such as to the button class, or change the interface of AppMaker. However, changes won’t affect the behavior of generated code unless you also change the language definition.

Changing the language definition is a more traditional process. A set of Templates are shipped for each language. These are text source files and very similar to C++ with a few macro commands. The templates are compiled with a separate program to create a binary language file. This compiler provides very clear feedback, making it easy to diagnose errors in your changes.

The following example is from a Quadra 700, which is no speed demon.

Build of “PowerPlant.AMMake”
(press Command-Period to cancel)
Creating PowerPlant
Compiling resource templates:
 :Resources:Main
 :Resources:Menus
 :Resources:Windows
 :Resources:Styles
Compiling source templates:
 :Sources:GenWhat
 :Sources:Main
 :Sources:Window
 :Sources:Dialog
file “:Sources:Dialog”; line 279 
// only string or int (not ‘ref’) permitted in a NameStatement
file “:Sources:Dialog”; line 279 
// Assignment, Call, or NameStatement expected
Error(s) encountered-compilation aborted
4797 lines compiled in 49 seconds
Rate = 5873 lines/min
Saving PowerPlant done

AppMaker Changes and Code Written

Changes to AppMaker

The changes can be summarized as adding a data member and an interface to set the data.

In the AM Prefs file, a Property was added to contain the name of the sound. This was simply a matter of selecting the Window Item category and choosing Edit - Add Item to add another to its list of Property Defs such as Item Kind, Command, etc. Think of this first part like changing a C++ class definition. Filling in the objects in your document is like using the classes in a C++ program.

Figure 1. The Prefs browser unwound enough to see Window Item.

When you add an item to an AppMaker definition, it is one of a number of base data types. You can refer to complex data types by creating a new category for them and using a Reference. For this version of sounds, I used just a simple String to record the sound name. A later version would rely on AppMaker being extended to contain ‘snd ’ resources. In that case, a Reference to the Sound category would be used. This is the only area of extension which requires Bowers Development to assist - they have to build in storage for the binary resource types, and functions to handle their input (via pasting) and output (in generated resource files).

Figure 2. Adding the SoundName item as a String.

After adding the data storage for sounds, I needed an interface to specify them. Note that AppMaker doesn’t force you to take this step. For any object in your document, you can always access a properties list which shows every possible property. However, I wanted the default Info dialog to display my sound name. This would let me double-click the button and see the sound with the other few crucial properties.

This interface customizing is one of the great strengths of AppMaker. When designing, you see only a few properties for each item on the screen. However, if you add something or decide that other properties should be easily accessible, it is only a few minutes work to redefine the interface to show those properties.

You edit the AM Interface similarly to editing your own projects. The only difference is, when you double-click an item in the AM Interface screen, you see a dialog letting you set its target property, such as Sound Name.

Figure 3. The Sound Demo project with the Play button double-clicked, showing the final version of the Button Info dialog with the new Sound Name field.

Changes to the AppMaker PowerPlant Templates

Only one file need be changed in the code generation to specify that a CSoundAttachment be applied to buttons that have Sound Names. In the iButton file, two procedures were changed with small additions to output extra information.

iButton changes
procedure Button.genInitMember
// add creation of attachment, if soundName specified
...
 if SoundName != “”
%
   mPlayButton->AddAttachment(
 new CSoundAttachment(“Click”, msg_Click));
%
 end if


procedure Button.getIncludeName
// add include of CSoundAttachment
...
 if SoundName != “”
 includeNames.addString (“\”CSoundAttachment.h\””)
 end if

PowerPlant classes used in the simulation

Éric Forget’s USoundPlayer was used to provide basic sound-playing capabilities from the PowerPlant Contributed Classes archives on the Internet at

<ftp://atlantis.metrowerks.com/pub/powerplant/Util/USoundPlayer.sit.hqx>.

If you haven’t visited the archives, they are well worth a look. Point your browser at www.metrowerks.com and navigate down, or go straight to

<http://www.metrowerks.com/db/powerplant/search.qry?function=form>.

CSoundAttachment was written for this project to provide an LAttachment subclass that can play sounds. It uses USoundPlayer. (Reuseable code off the Internet, what a concept!) It is shown in its entirety below, and may be useful in other circumstances.

CSoundAttachment .h
class CSoundAttachment : public LAttachment {
public:
 CSoundAttachment(const char* inSoundName,
 MessageT inMessage = msg_AnyMessage,
 Boolean inExecuteHost = true);
protected:
 virtual void  ExecuteSelf(MessageT inMessage, void *ioParam);
// data storage
 Str255 mSoundName;
};


CSoundAttachment.cp
#include  “CSoundAttachment.h”
#include“USoundPlayer.h”
#include<string.h>

// use with an entry in FinishCreateSelf, such as:
// bPlay->AddAttachment(new CSoundAttachment(“Click”, msg_Click));

//Plays sound when executed
//Suitable for use with any message

CSoundAttachment::CSoundAttachment(
 const char*inSoundName,
 MessageT inMessage,
 BooleaninExecuteHost)
 : LAttachment(inMessage, inExecuteHost)
{
 mSoundName[0] = strlen(inSoundName);
 memcpy(&mSoundName[1], inSoundName, mSoundName[0]);
}


void
CSoundAttachment::ExecuteSelf(
 MessageT /* inMessage */,
 void*  /* ioParam */)
{
 USoundPlayer::PlaySound(mSoundName);
}

Gettng Attached to your Code

Attachments are used in PowerPlant to extend the behavior of other objects, sometimes changing their behavior (such as attachments that change the background of text fields). They are an example of uncoupling objects. The LAttachment interface provides a high-level abstract interface. The object to which they are attached knows nothing of the attachments other than their presence. For example, an LButton just shouts “hoi, you mob, I was just Clicked” and carries on in ignorance. If the attachments have been created to care about Click messages, then they will react. (Attachments typically react to either all messages or one specific message, such as msg_Click.)

One subtlety is that attachments are synchronous. Thus, the button is not able to carry on with its Clicked behavior until all the attachments have been executed. Another important point to note is when the attachments are called. In the case of a Pane, it sends the Clicked message to attachments when the mouse is pressed. This means our sound is played when the user presses the button (mouse-down). Buttons inherit their attachable behavior from Panes.

If you wanted the sound to play if the user activates the button (mouse-up inside the button) then you are out of luck - there is no broadcasting to attachments when a button is triggered. An alternative to using attachments would be to add a Listener to the button. Listeners listen for results (such as buttons being released). A good exercise would be to take CSoundAttachment and rewrite it as CSoundListener.

The difference between Attachments and Listeners may seem confusing. One key point to remember is that Attachments can modify behavior - they are called before the action and return a Boolean value, so they can actually stop the action. Listeners are even more uncoupled and have no side-effect on the actions at all, being purely a way to react.

For more reading on the design ideas behind attachments, see Design Patterns by Gamma, Helm, Johnson & Vlissides ISBN 0-201-63361-2. More recent work on patterns can be found in Pattern Languages of Program Design edited by James Coplien & Doug Schmidt ISBN 0-201-60734-4. In particular, the ValueModel pattern discussed in chapter 25 seems relevant to our interface customizing and code generation work.

Is it Really so Easy?

My first exploration into customizing AppMaker was adding our OOFILE integration classes which link database fields and views to editing and display panes. This involved a number of changes to dialogs, edit text fields and other classes. A rough version, including coming to terms with the templates, took a weekend. I’ve since written the AppMaker MFC templates, so I have a fair amount of template experience under my belt.

However, small additions like the Sound Name example are relatively easy. If they are also of general benefit consider passing them on - Spec Bowers may roll them into the next release. The hard thing is deciding whether to make a tiny change now or something more generic. These Sound Name changes will probably be thrown away - it makes more sense to allow any kind of attachment to be specified and even to cope with a number of attachments.

My current project is based heavily on AppMaker and we will be experimenting further with using attachments for business rules. Hopefully this is also a good strategy for the re-generation problem. If your user-defined code is attached rather than incorporated, it won’t be trodden on when you change your project’s interface in AppMaker.

Have a good look at AppMaker - the demo’s are usually publicly available and on the CodeWarrior Reference CD’s. Hopefully this article will also have whet your appetite for using Attachments as a flexible way to program. The MacApp readers who stayed to the end may now smirk in the satisfaction of having had them for years as Adorners and Behaviors.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Pixelmator 3.8.1 - Powerful layer-based...
Pixelmator is a beautifully designed, easy-to-use, fast, and powerful image editor for OS X. It has everything you need to create, edit, and enhance your images. Pixelmator is a layer-based image... Read more
Malwarebytes 3.6.21.2055 - Adware remova...
Malwarebytes (was AdwareMedic) helps you get your Mac experience back. Malwarebytes scans for and removes code that degrades system performance or attacks your system. Making your Mac once again your... Read more
iStat Menus 6.31 - Monitor your system r...
iStat Menus lets you monitor your system right from the menubar. Included are 8 menu extras that let you monitor every aspect of your system. Features CPU -- Monitor cpu usage. 7 display modes,... Read more
Unite 2.0 - $9.99
Unite allows you to quickly and easily turn websites into full-featured, native apps on macOS. With Unite 2, we've completely rewritten the backend browser with WebKit 2, enabling support for the... Read more
VueScan 9.6.23 - Scanner software with a...
VueScan is a scanning program that works with most high-quality flatbed and film scanners to produce scans that have excellent color fidelity and color balance. VueScan is easy to use, and has... Read more
Thunderbird 60.3.2 - Email client from M...
As of July 2012, Thunderbird has transitioned to a new governance model, with new features being developed by the broader free software and open source community, and security fixes and improvements... Read more
Apple Security Update 2018-006 - For mac...
Apple Security Update is recommended for all users and improves the security of OS X. For detailed information about the security content of this update, please visit: http://support.apple.com/kb/... Read more
VueScan 9.6.23 - Scanner software with a...
VueScan is a scanning program that works with most high-quality flatbed and film scanners to produce scans that have excellent color fidelity and color balance. VueScan is easy to use, and has... Read more
Apple Security Update 2018-006 - For mac...
Apple Security Update is recommended for all users and improves the security of OS X. For detailed information about the security content of this update, please visit: http://support.apple.com/kb/... Read more
Thunderbird 60.3.2 - Email client from M...
As of July 2012, Thunderbird has transitioned to a new governance model, with new features being developed by the broader free software and open source community, and security fixes and improvements... Read more

Latest Forum Discussions

See All

148Apps year end round-up: These are the...
It's Monday, and our round-up of the best games of 2018 has landed on March. There were some pretty amazing developments in the third month of the year, mainly thanks to the launch of PUBG and the start of the Fortnite beta (technically Fortnite... | Read more »
Twinfold guide
Twinfold may look like a cheap Threes! clone at first glance, but it's so much more than that. It's actually a rather deep roguelite with a really satisfying difficulty curve and almost endless replayability. Since the game's depth does take some... | Read more »
Which of these iPhone and iPad games sho...
On a normal week we like to give you the chance to vote for your game of the week on Thursday. But since this clearly isn't a normal week, we've decided to give you the chance to vote for our game of the week on Friday. You're welcome. [Read more... | Read more »
Munchkin.io ends 2018 in style with a ne...
While it can sometimes seem like we are drowning in a sea of battle royale games, few struggle to actually deliver the kind of fun and frantic experience you’d expect from a refined entry in the genre. Well step aside from those other games because... | Read more »
Choose a side in Rift of Raigard, the ne...
If you’re an RTS player that’s constantly underwhelmed by most genre entries on mobile, or sick of putting up with stingy F2P models and cheaters, Rift of Raigard is the base building game for you. Developed by a team of creators who are equally... | Read more »
148Apps year end round-up: These are the...
Our round up of the best games of the year has rolled along to February. Which makes sense, since we started off with January - click here and you'll be able to read the top 5 in its entirety - and February was definitely a doozy, we can tell you... | Read more »
The top 5 best gifts for mobile gamers t...
Since it's the most wonderful time of the year according to most adverts, and since the most wonderful time of the year is all about the giving and receiving of presents (and probably some other stuff, we guess), we thought it was high time we... | Read more »
Dragalia Lost - Resplendent Refrain Sabn...
Dragalia Lost's latest event, Resplendent Refrain, is an event that favors light Adventurers in an all new raid dungeon. This dungeon has four teams of four face off against the mighty Sabnock, which is probably the toughest raid fight in the game... | Read more »
Dragalia Lost Adventurers' Guide
Want to up your Dragalia Lost game? You've come to the right place. Here at 148Apps, we've been digging deep into Nintendo's latest gacha game to find the best tips, tricks, and strategies to share with all of our future co-op team mates (read: you... | Read more »
148Apps year end round-up: These are the...
We're heading towards the end of the year, which can only mean it's time to start thinking about what games we're going to remember from the last 12 months. And we're going to break it down into a series of top 5s, one for each month. We're... | Read more »

Price Scanner via MacPrices.net

21 Days Left To Avail Apple $29 Battery Repla...
FEATURE: 12.10.18- There are only 21 days left in 2018 before it will be that time once again for making New Year’s resolutions but for a handful of certain iPhone users these next three weeks will... Read more
Get a new 2018 Apple iMac for $100-$220 off M...
B&H Photo has 2018 Apple iMacs on sale for up to $220 off MSRP for Green Monday 2018. Current-generation 21″ models are on sale for $100-$170 off MSRP, and 27″ iMacs are on sale for $200-$220 off... Read more
Amazon offers 9″ 32GB WiFi iPads for $249, $8...
Amazon is offering 9.7″ 32GB & 128GB WiFi iPads with Apple Pencil Support, in Space Gray & Gold, for $80 off MSRP for Green Monday 2018. Silver iPads are on sale for $60 off. These are the... Read more
B&H and Amazon offer 13″ Apple MacBook Pr...
Apple resellers B&H Photo and Amazon are all offering sale prices on new 13″ MacBook Pros ranging up to $200 off MSRP as part of their Green Monday/Holiday 2018 sales. B&H Photo has 13″... Read more
Amazon offers Apple Watch Series 3 GPS + Cell...
Amazon is discounting Apple Watch Series 3 GPS + Cellular models by $50 as part of their Holiday 2018 sales, with 38mm Watches starting at $329. Shipping is free: – 38mm Apple Watch Series 3 GPS +... Read more
Holiday/Green Monday sale: Apple resellers of...
Get a new 2018 15″ Touch Bar MacBook Pro for $300 off MSRP, starting at $2099, at the following Apple resellers today. These are the same models sold by Apple in their retail and online stores: B... Read more
Holiday sale: Get a new 2018 Mac mini for $50...
Apple introduced a new Mac mini in October 2018 with a similar form factor as previous generations but featuring significantly upgraded internals. The new mini comes in a darker Space Gray color and... Read more
Holiday sale! Get a new 2018 13″ MacBook Air...
B&H Photo has new 2018 13″ MacBook Airs on sale for $100-$130 off MSRP, starting at only $1069, as part of their Holiday 2018 sale. Their prices are the lowest available for these new models from... Read more
Holiday 2018 sale: 9.7″ Apple iPads on sale t...
Amazon is offering 9.7″ WiFi iPads with Apple Pencil Support for $60-$80 off MSRP this weekend as part of their Holiday 2018 sale with prices starting at $269. These are the same iPads found in Apple... Read more
Organize Apple Power Adapter Clutter With A F...
FEATURE: 12.07.18- Looking for the perfect gadget to give as a stocking stuffer or gift for the MacBook user in your life that won’t break the bank and can actually help them organize the cable and... Read more

Jobs Board

Geek Squad *Apple* Master Consultation Agen...
**660766BR** **Job Title:** Geek Squad Apple Master Consultation Agent **Job Category:** Services/Installation/Repair **Location Number:** 001021-San Rafael-Store Read more
*Apple* Mobile Master - Best Buy (United Sta...
**659208BR** **Job Title:** Apple Mobile Master **Job Category:** Store Associates **Location Number:** 000806-Seekonk-Store **Job Description:** **What does a Best Read more
*Apple* Mobile Master - Best Buy (United Sta...
**660573BR** **Job Title:** Apple Mobile Master **Job Category:** Store Associates **Location Number:** 000488-Chattanooga-Store **Job Description:** **What does a Read more
*Apple* Mobile Master - Best Buy (United Sta...
**658576BR** **Job Title:** Apple Mobile Master **Job Category:** Store Associates **Location Number:** 001022-Leesburg-Store **Job Description:** **What does a Best Read more
*Apple* Mobile Master - Best Buy (United Sta...
**659661BR** **Job Title:** Apple Mobile Master **Job Category:** Store Associates **Location Number:** 000197-King of Prussia-Store **Job Description:** **What does Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.