TweetFollow Us on Twitter

Split Button
Volume Number:7
Issue Number:6
Column Tag:HyperChat

Splitting Your Sides

By Carl J. Manaster, Globe, AZ

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

[Carl is a mining engineer and programmer whose appreciation for environments such as HyperCard and THINK Pascal is enhanced by painful memories of dBase and FORTRAN.]


It’s endemic among HyperCard fans to try to “fill in” the gaps left by Apple. Such supplements often take the form of XCMDs and XFCNs, offering everything from standard file calls to color windows. Occasionally, the purists among us like to write these extensions in HyperTalk itself, keeping it “all in the family,” as it were. (Also, having once used TCL or MacApp, it’s hard to imagine going back to writing Pascal without such crutches - and they don’t help with code resources!)

One thing missing from HyperCard is polygonal buttons - arbitrary shapes that behave like a button. The need for these has been apparent since the first release and its Clip Art stack, where the user clicks on certain parts of the pictures to travel to related cards. Since it’s all done with transparent (rectangular) buttons, there’s a great deal of “slop” space, where a click that ought to be on a hat (for instance) is really in the rectangle of the man.

There are doubtless XCMDs available that solve this problem, and I’ve seen at least one article describing a HyperTalk-based solution; here is another.

The Basic Solution

My solution is to place buttons over each side of the polygon, and split the message chain along each button’s diagonal. The message to do this is in the stack’s script:


--message split
--syntax: split(orientation,¬
--where: orientation is “/” or “\”
--topMessage is message to be called if click
------------------was in top half of target
--bottomMessage is message to be called if click
--------------------was in bottom half of target

on split
  put param(2) into topMessage
  put param(3) into bottomMessage
  put (the bottom of the target) - ¬
 (the clickV) into vDiff
  if param(1) is “/”
  then put (the clickH) - (the left of¬
 the target) into hDiff
  else put (the right of the target) - ¬
 (the clickH) into hDiff
  put vDiff * (the width of the target)¬
 > hDiff * (the height of the target)¬
 into doTop
  if doTop
  then send topMessage to target
  else send bottomMessage to target
end split

Each button’s mouseUp script calls split with the appropriate orientation and messages, thereby simulating two adjacent triangular buttons with differing mouseUp messages. With this script and the button tool, buttons can be placed around a polygon to simulate polygonal buttons.

Figure 1 - How a Split Button Simulates a Pair of Triangular Buttons

Getting Fancy

The obvious next step is to make it easier to generate polygonal buttons. The script in Listing #1, makePolyButton, does this. It tracks and records clicks until one is close to the first vertex, outlining the polygon as it is defined.

Figure 2 - Original Image with Polygonal Outline

Once all the vertices of the polygon have been entered, the maximum and minimum horizontal and vertical coördinates are determined, as well as the next-to-maximum and next-to-minimum.

A button is created whose sides are the next-to-extreme coördinates of the polygon’s vertices; most mouseUp messages reaching it will be within the polygon but not within any of the buttons around its edge.

Figure 3 - Polygon with Interior Button

Lastly, for each side of the polygon, a button is created whose mouseUp handler uses the split message to choose between the two messages that are passed to makePolyButton as parameters.

Figure 4 - Polygon with Border Buttons

Limitations and Flaws

Like most solutions, this one is imperfect; here are some of the problems associated with my implementation of polygonal buttons:

No AutoHilite or Outline

Because polygonal buttons have no single data structure where they are defined, autoHiliting is out of the question. Outlining is not impossible - a script could be written that included:


choose line tool
if the script of the target¬
contains “split” and the script of¬
the target contains “/” then drag 

but it would not behave like normal outlining: painting would obscure it; moving the button would neither erase the old outline nor draw the new one; even if this were solved, erasing the old could mess up the paint layer with traces of white It is best to accept that outlining is not a feature of these polygonal buttons.

Sharp Corners Confuse

It is possible to generate polygons that are not modelled well with this technique. Indeed, the polygon used in Figures 2-4 shows some space that will report an “inside” message when certain “outside” areas are clicked (the upper right corner of the interior button, whose message is “inside”, extends beyond where border buttons cover it.) Similar mis-routing of the message chain can occur when the angles of a polygon are too sharp, and one border button overlaps another. This problem can be overcome by tweaking with the button tool, but even without such tweaking there is much less slop space than with plain, rectangular buttons.


The Spectrum of Solutions

There are countless ways in which a polygon may be made to act as a button in HyperCard; the methods differ in degree of resolution. The trade-off is between accuracy of representation on the one hand and programming demands, memory, and speed on the other. The roughest solution is to use rectangular buttons that more-or-less cover the polygon. At the fine end of the spectrum lie solutions such as pixel-sized buttons to fill the polygon, XCMDs, and complex scripts that rely on globals or fields to keep track of the polygon’s vertices.

Split buttons fall somewhere in the middle of the spectrum. The marginal costs over using rectangular buttons (a little programming, slightly more difficulty creating, moving, and deleting, and one more handler in the message chain) are relatively small, and the gains are significant. The accuracy is not as good as the pixel-perfect solutions (both HyperCard- and XCMD- based), but much less programming is required, and split buttons should be much faster than the HyperCard-based solutions.

This via media is realized by using each button to focus information, like relying on an airplane to get across the country and then getting to your house by car. The rough end of the spectrum relies on HyperCard to do all of the work (flying home on a 747); the fine end solutions do all of the work themselves (driving cross-country); split buttons rely on HyperCard for what it’s good at - the rough determination of which rectangular button contained the click - and concentrate on further distilling the information.

Because split buttons represent a compromise, they will not be appropriate for every stack calling for polygonal buttons. Because they represent a good compromise, however, they may find many applications.

LISTING #1 - makePolyButton script
--message makePolyButton
--syntax: makePolyButton(inMessage,outMessage)
----------inMessage is message to be called by 
----------------clicks within the polyButton
----------outMessage is message to be called by 
----------------clicks outside the polyButton

on makePolyButton inMessage,outMessage
 put empty into pointList
 choose line tool
 set the cursor to cross
 wait until the mouseClick
 put the clickLoc into pointList

 wait until the mouseClick
 put return & the clickLoc after pointList
 put the number of lines of pointList¬
 into count
 drag from (line count-1 of pointList)¬
 to (line count of pointList)
 if abs(item 1 of last line of pointList¬
 - item 1 of first line of pointList)<2¬
 and abs(item 2 of last line of pointList¬
 - item 2 of first line of pointList)<2¬
 then exit repeat
 end repeat

 put line 1 of pointList into¬
 last line of pointList
 put the number of card buttons into cbCount
 set lockScreen to true
 doMenu revert
 choose button tool

 put item 1 of line 1 of pointList into maxV
 put item 1 of line 2 of pointList into maxPenV
 put item 1 of line 1 of pointList into minV
 put item 1 of line 2 of pointList into minPenV

 put item 2 of line 1 of pointList into maxH
 put item 2 of line 2 of pointList into maxPenH
 put item 2 of line 1 of pointList into minH
 put item 2 of line 2 of pointList into minPenH

 repeat with i=2 to count

 get item 1 of line i of pointList
 if it > maxPenV then--find the largest
 if it > maxV then --and second largest v
 put maxV into maxPenV
 put it into maxV
 put it into maxPenV
 end if
 end if

 if it < minPenV then   --find the smallest
 if it < minV then --and second smallest v
 put minV into minPenV
 put it into minV
 put it into minPenV
 end if
 end if

 get item 2 of line i of pointList
 if it > maxPenH then--find the largest
 if it > maxH then --and second largest h
 put maxH into maxPenH
 put it into maxH
 put it into maxPenH
 end if
 end if

 if it < minPenH then--find the smallest
 if it < minH then --and second smallest h
 put minH into minPenH
 put it into minH
 put it into minPenH
 end if
 end if

 end repeat

 add 1 to cbCount--create the interior button
 doMenu “new button”
 set the style of card button cbCount¬
 to transparent
 set the showName of card button cbCount¬
 to false
 set the autoHilite of card button cbCount¬
 to false
 set the rect of card button cbCount¬
 to minPenV,minPenH,maxPenV,maxPenH
 put “on mouseUp” into theScript
 put return & inMessage after theScript
 put return & “end mouseUp” after theScript
 set the script of card button cbCount¬
 to theScript
 repeat with i=1 to count-1
 add 1 to cbCount--create the edge buttons
 set the cursor to busy
 put line i of pointList into firstPoint
 put line (i+1) of pointList into secondPoint
 doMenu “new button”
 set the name of card button cbCount¬
 to “split” && i

 --determine the coördinates of the button:
 if (item 1 of firstPoint) < (item 1¬
 of secondPoint) then
 put item 1 of firstPoint into top
 put item 1 of secondPoint into bottom
 put item 1 of secondPoint into top
 put item 1 of firstPoint into bottom
 end if
 if (item 2 of firstPoint) > (item 2¬
 of secondPoint) then
 put item 2 of firstPoint into right
 put item 2 of secondPoint into left
 put item 2 of secondPoint into right
 put item 2 of firstPoint into left
 end if

 set the rect of card button cbCount¬
 to top,left,bottom,right
 set the style of card button cbCount¬
 to transparent
 set the showName of card button cbCount¬
 to false
 set the autoHilite of card button cbCount¬
 to false

 --determine the orientation of the
 --”split” of the button:

 put “on mouseUp” into theScript

 if (item 1 of firstPoint) > (item 1¬
 of secondPoint) then
 if (item 2 of firstPoint) > (item 2¬
 of secondPoint) then
 put return & “split “ & quote & “\”¬
 & quote & “,” & inMessage & “,” &¬
 outMessage after theScript
 put return & “split “ & quote & “/”¬
 & quote & “,” & inMessage & “,” &¬
 outMessage after theScript
 end if
 if (item 2 of firstPoint) > (item 2¬
 of secondPoint) then
 put return & “split “ & quote & “/”¬
 & quote & “,” & outMessage & “,” &¬
 inMessage after theScript
 put return & “split “ & quote & “\”¬
 & quote & “,” & outMessage & “,” &¬
 inMessage after theScript
 end if
 end if

 put return & “end mouseUp” after theScript

 set the script of card button cbCount¬
 to theScript
 end repeat

 choose browse tool
end makePolyButton

Community Search:
MacTech Search:

Software Updates via MacUpdate

Microsoft Remote Desktop 8.0.16 - Connec...
With Microsoft Remote Desktop, you can connect to a remote PC and your work resources from almost anywhere. Experience the power of Windows with RemoteFX in a Remote Desktop client designed to help... Read more
Spotify - Stream music, create...
Spotify is a streaming music service that gives you on-demand access to millions of songs. Whether you like driving rock, silky R&B, or grandiose classical music, Spotify's massive catalogue puts... Read more
djay Pro 1.1 - Transform your Mac into a...
djay Pro provides a complete toolkit for performing DJs. Its unique modern interface is built around a sophisticated integration with iTunes and Spotify, giving you instant access to millions of... Read more
Vivaldi - Lightweight browser...
Vivaldi browser. In 1994, two programmers started working on a web browser. Our idea was to make a really fast browser, capable of running on limited hardware, keeping in mind that users are... Read more
Stacks 2.6.11 - New way to create pages...
Stacks is a new way to create pages in RapidWeaver. It's a plugin designed to combine drag-and-drop simplicity with the power of fluid layout. Features: Fluid Layout: Stacks lets you build pages... Read more
xScope 4.1.3 - Onscreen graphic measurem...
xScope is powerful set of tools that are ideal for measuring, inspecting, and testing on-screen graphics and layouts. Its tools float above your desktop windows and can be accessed via a toolbar,... Read more
Cyberduck 4.7 - FTP and SFTP browser. (F...
Cyberduck is a robust FTP/FTP-TLS/SFTP browser for the Mac whose lack of visual clutter and cleverly intuitive features make it easy to use. Support for external editors and system technologies such... Read more
Labels & Addresses 1.7 - Powerful la...
Labels & Addresses is a home and office tool for printing all sorts of labels, envelopes, inventory labels, and price tags. Merge-printing capability makes the program a great tool for holiday... Read more
teleport 1.2.1 - Use one mouse/keyboard...
teleport is a simple utility to let you use one single mouse and keyboard to control several of your Macs. Simply reach the edge of your screen, and your mouse teleports to your other Mac! The... Read more
Apple iMovie 10.0.8 - Edit personal vide...
With an all-new design, Apple iMovie lets you enjoy your videos like never before. Browse your clips more easily, instantly share your favorite moments, and create beautiful HD movies and Hollywood-... Read more

Use Batting Average and the Apple Watch...
Batting Average, by Pixolini, is designed to help you manage your statistics. Every time you go to bat, you can use your Apple Watch to track  your swings, strikes, and hits. [Read more] | Read more »
Celebrate Studio Pango's 3rd Annive...
It is time to party, Pangoland pals! Studio Pango is celebrating their 3rd birthday and their gift to you is a new update to Pangoland. [Read more] | Read more »
Become the World's Most Important D...
Must Deliver, by cherrypick games, is a top-down endless-runner witha healthy dose of the living dead. [Read more] | Read more »
SoundHound + LiveLyrics is Making its De...
SoundHound Inc. has announced that SoundHound + LiveLyrics, will be one of the first third-party apps to hit the Apple Watch. With  SoundHound you'll be able to tap on your watch and have the app recognize the music you are listening to, then have... | Read more »
Adobe Joins the Apple Watch Lineup With...
A whole tidal wave of apps are headed for the Apple Watch, and Adobe has joined in with 3 new ways to enhance your creativity and collaborate with others. The watch apps pair with iPad/iPhone apps to give you total control over your Adobe projects... | Read more »
Z Steel Soldiers, Sequel to Kavcom'...
Kavcom has released Z Steel Soldiers, which continues the story of the comedic RTS originally created by the Bitmap Brothers. [Read more] | Read more »
Seene Lets You Create 3D Images With You...
Seene, by Obvious Engineering, is a 3D capture app that's meant to allow you to create visually stunning 3D images with a tap of your finger, and then share them as a 3D photo, video or gif. [Read more] | Read more »
Lost Within - Tips, Tricks, and Strategi...
Have you just downloaded Lost Within and are you in need of a guiding hand? While it’s not the toughest of games out there you might still want some helpful tips to get you started. [Read more] | Read more »
Entertain Your Pet With Your Watch With...
The Petcube Camera is a device that lets you use live video to check in on your pet, talk to them, and play with them using a laser pointer - all while you're away. And the Petcube app is coming to the Apple Watch, so you'll be able to hang out with... | Read more »
Now You Can Manage Your Line2 Calls With...
You'll be able to get your Line2 cloud phone service on the Apple Watch very soon. The watch app can send and receive messages using hands-free voice dictation, or by selecting from a list of provided responses. [Read more] | Read more »

Price Scanner via

Intel Compute Stick: A New Mini-Computing For...
The Intel Compute Stick, a new pocket-sized computer based on a quad-core Intel Atom processor running Windows 8.1 with Bing, is available now through Intel Authorized Dealers across much of the... Read more
Heal to Launch First One-Touch House Call Doc...
Santa Monica, California based Heal, a pioneer in on-demand personal health care services — will offer the first one-touch, on-demand house call doctor app for the Apple Watch. Heal’s Watch app,... Read more
Mac Notebooks: Avoiding MagSafe Power Adapter...
Apple Support says proper usage, care, and maintenance of Your Mac notebook’s MagSafe power adapter can substantially increase the the adapter’s service life. Of course, MagSafe itself is an Apple... Read more
12″ Retina MacBook In Shootout With Air And P...
BareFeats’ rob-ART morgan has posted another comparison of the 12″ MacBook with other Mac laptops, noting that the general goodness of all Mac laptops can make which one to purchase a tough decision... Read more
FileMaker Go for iPad and iPhone: Over 1.5 Mi...
FileMaker has announced that its FileMaker Go for iPad and iPhone app has surpassed 1.5 million downloads from the iTunes App Store. The milestone confirms the continued popularity of the FileMaker... Read more
Sale! 13-inch 2.7GHz Retina MacBook Pro for $...
 Best Buy has the new 2015 13″ 2.7GHz/128GB Retina MacBook Pro on sale for $1099 – $200 off MSRP. Choose free shipping or free local store pickup (if available). Price for online orders only, in-... Read more
Minimalist MacBook Confirms Death of Steve Jo...
ReadWrite’s Adriana Lee has posted a eulogy for the “Digital Hub” concept Steve Jobs first proposed back in 2001, declaring the new 12-inch MacBook with its single, over-subscribed USB-C port to be... Read more
13-inch 2.7GHz Retina MacBook Pro for $1234 w...
Adorama has the 13″ 2.7GHz/128GB Retina MacBook Pro in stock for $1234.99 ($65 off MSRP) including free shipping plus a free LG external DVD/CD optical drive. Adorama charges sales tax in NY & NJ... Read more
13-inch 2.5GHz MacBook Pro available for $999...
 Adorama has the 13-inch 2.5GHz MacBook Pro on sale for $999 including free shipping plus NY & NJ sales tax only. Their price is $100 off MSRP. Read more
Save up to $600 with Apple refurbished Mac Pr...
The Apple Store is offering Apple Certified Refurbished Mac Pros for up to $600 off the cost of new models. An Apple one-year warranty is included with each Mac Pro, and shipping is free. The... Read more

Jobs Board

*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
*Apple* Support Technician IV - Jack Henry a...
Job Description Jack Henry & Associates is seeking an Apple Support Technician. This position while acting independently, ensures the proper day-to-day control of Read more
*Apple* Client Systems Solution Specialist -...
…drive revenue and profit in assigned sales segment and/or region specific to the Apple brand and product sets. This person will work directly with CDW Account Managers Read more
*Apple* Software Support - Casper (Can work...
…experience . Full knowledge of Mac OS X and prior . Mac OSX / Server . Apple Remote Desktop . Process Documentation . Ability to prioritize multiple tasks in a fast pace Read more
*Apple* Software Support - Xerox Corporation...
…Imaging experience Full knowledge of Mac OS X and prior Mac OSX / Server Apple Remote Desktop Process Documentation Ability to prioritize multiple tasks in a fast pace Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.