AutoHyperEdit
Volume Number: | | 4
|
Issue Number: | | 7
|
Column Tag: | | HyperChat
|
Auto Hyper Edit Moves in Groups
By Fred Stauder, HyperChat Editor, Zurich, Switzerland
AutoHyperEdit
Over the last few months we have seen the evolution of Hypercard Stacks. We have also been evolving AutoScriptEdit by showing you how to increase the functionality while retaining simplicity. I have had a lot of feedback about ASE and most people prefer it to the inbuilt shortcuts in Hypercard 1.2.
So what was I to do for an encore, well I always wanted to group and move buttons etc. Souix Lacey did a great job with Groupies, and I wondered if I could make Hypercard act more in a Mac way. I decided to write AutoHyperEdit.
Well I started experimenting and I was thoroughly addicted to solving the problem. Even half way throug writing it I thought it would be impossible to get around some obstacles that would make it work. The script basically allows the user to shift and click on objects to group them. The problem was if you clicked on a button for example after my stack had done its stuff it would then execute the button that was clicked on. So I couldnt use nice things like target. The way I got around that was to check what objects were under the mouse at the time of the shiftKey.
After I had the scripting finished I decided I would make a model Installer and Demo Stack. I will first take you through the Stack and then get into how and what was done.
figure 1. AutoHyperEdit
The opening card shows what a little shading can do to add depth to your stack. The buttons I created to give as much feedback as possible. When you click on a button it appears to move in and the center black square turns to white. This is done by switching icons. Also to implement more feedback a click sound is heard.
I cant stress the importance of a good user interface particularly in Hypercard. At least half of my time in this project was spent on the interface. Apple is spending a lot of dollars on interface technology and have recognised the need for using it to aid in the smooth information flow between computer and machine. There is a group at Apple called the Human Interface Group, their sole job is to work on interface ideas and guidelines. If you have not read the Human Interface Guidelines do so immediately. It is a must. The guidlines are available through APDA and in some Bookshops and Computer Stores.
If you go to the examples card you will see three new buttons; Script Tools, Object Tools and Aligning Tools.
figure 2.
The Script Tools are the tools found in AutoScriptEdit-III. I use an interesting way to demo how the tools are to be used. There is part of a keyboard and part of a mouse pad and a mouse in the bottom left of the card, see figure 3.
figure 3.
When you click on a selection, you also get visual and auditory feedback, a field pops up along with two buttons; Close and Show Me.
figure 4.
Clicking on Show Me Starts the demo. First the cursor dissapears and an icon that is identical to the cursor is shown at the point of interest. To attract the attention to the moving parts I flash (hilite/unhilite) both the cursor and the the mouse icon. now I play the tune:
play harpsichord tempo 1200 c5 c6 c7
This signifies the start of what you should do. I then play the word mousedown which has been digitized. The icon changes showing a mouse with the button down. I showed the original demos to non Mac users and they could follow how to do it easily. My previous tests where I didnt have all the feedback the user was a bit lost and did not know where to focus his attention. The rest of the demo shows the mouse and the cursor moving up above a field. The script editor is then evoked.
The Object Tools shows buttons; Grouping, Moving, Copying, and Clearing see figure 5.
figure 5.
The action of the buttons remain consistent even though the location is slightly different. One of the things to watch out for in your stacks is to keep consistency and simplicity at the forefront of your mind when you are designing.
The demo of grouping shows the tool window first to show that you must be in the browse tool mode. You then click on an object with the shift key down. This will hilite a button.
figure 6
There was a problem of not being able to hilite a field, so as well as a hilite I use a click tone. To select more objects just shift click again and to de-select you also shift click. Once you have finished selection you must double click not on an object. This will bring you to the button tool where you can choose a menu item such as copy button. Or simply type command-C. I used a feature of Hypercard 1.2 to show the card picture. I have a menu as a card picture and I show it and drag a hilited transperent button to act as a regular menu, see figure 7. Now go to the card you want to paste to and do a command-V and the objects will appear.
figure 7.
Clearing objects works in the same way, first selection then, double click, then menu command.
The next section is Aligning Tools. This allows you to select objects as before and then to hold down the mouse where you want the objects to be aligned, press the arrow key which corresponds to the alignment i.e. left arrow align left.
figure 8.
I also created an installer that puts the script into your home stack and adds a checkbox in the preferences card to allow you to turn AHE on and off. I do this in an interesting way. As well as the checkbox I add a hidden field to the card. I put the home stack into the field and search for specific comment strings that are on the same line as the handlers and I comment out the begining and end of the handlers.
{1}
on mouseUp
if the hilite of me is false
then
put the script of this stack into cd fld TempAHE
lock screen
show cd fld TempAHE
repeat 8 times
set cursor to busy
find --**AutoHyperEdit**--
put the foundline into temp
select temp
put -- before the selection
put the selection into temp
end repeat
set script of this stack to cd fld TempAHE
put empty into cd fld TempAHE
hide cd fld TempAHE
unlock screen
else
put the script of this stack into cd fld TempAHE
lock screen
show cd fld TempAHE
repeat 8 times
set cursor to busy
find --**AutoHyperEdit**--
put the foundline into temp
select temp
put the selectedtext into stext
delete char 1 to 2 of stext
put stext into the selection
put stext into temp
end repeat
set script of this stack to cd fld TempAHE
put empty into cd fld TempAHE
hide cd fld TempAHE
unlock screen
end if
end mouseUp
The Remove card simply removes all traces of AHE.
Here is the script I will go through the important parts and tell you what they do.
{2}
---- AutoHyperEdit 1.0 by Fred Stauder June 1988 ----
-- Put this Script into your Home Stack
-- To use keep mouse btn down over Button or Field and move mouse up
-- To edit Bkgnd Script keep mouse btn down move mouse to -left of card
-- Card Script - move right
-- Stack Script - move up
-- Now works with unlocked fields
-- To lock and unlock fields option click in them
-- To show/hide tools/patterns at cursor
-- hold option click on non-field areas
-- click in top left to hide cd window botom right to show
--Group objects by shift clicking in browse tool
--Move objects by holding mouse down and draging
--Copy and Clear groups of objects after selecting by using menus
-- Align objects after selecting, hold mouse down at align loc and press
-- the arrow key i.e. align left use left arrow key
-- Turn AHE on and Off using the Checkbox installed in the Pref Card
of Home
The globals are CWSlist is where the selected objects ids are cwloc is the card window location to hide the card and selectcomp is a flag for when the selections are compleated.
Gobo resets the hilites and puts empty into CWSList. The first section is AutoScriptedit Stuff.
{3}
on mouseStillDown --**AutoHyperEdit**--
Global cwslist,cwLoc,selectcomp
if selectcomp is true then gobo
put empty into CWSList
if the optionkey is down
then
if the target contains field then set locktext of target to false
else
if the optionkey is down then
set the visible of pattern window to not the visible of pattern
window
set the loc of pattern window to the mouseloc
set the visible of tool window to not the visible of tool window
set the loc of tool window to the mouseloc
exit mouseStillDown --------
end if
end if
end if
if the mouseloc is within 0,0,10,10
then
put the loc of card window into CWLoc
set loc of card window to -504,-315
exit mousestilldown
end if
if the mouseloc is within 500,333,512,346
then
set loc of card window to CWLoc
exit mouseStillDown
end if
put char 6 of the target into C6
if C6 is quote then AutoScriptEdit
if C6 is i then AutoScriptEdit
if C6 is quote then exit mousestilldown
if C6 is i then exit mousestilldown
if the mouseV <item 2 of rect of target then edit script of target
else
------------------CWS
put empty into foundit
put false into offdetected
if cwslist is empty
then
if the shiftkey is down
then
repeat until offdetected is true
if the shiftkey is down
then
shiftselect
Here we go to the routine that selects objects.
{4}
put false into foundit
else
movegroup
wait until the mouse is down
repeat with y = the number of items in CWSlist down to 1
if the mouseloc is within the rect of item y of cwslist
then
put false into foundit
exit repeat
else
put true into foundit
end if
end repeat
end if
if foundit is true
then if the shiftkey is up then put true into offdetected
end repeat
choose btn tool
select item 1 of cwslist
put true into selectcomp
end if
end if
end if
--pass mouseStillDown
end mouseStillDown --**AutoHyperEdit**--
on AutoScriptEdit
if the mouseH < 2 then edit script of this bkgnd
if the mouseH > 510 then edit script of this card
if the mouseV < 2 then edit script of this stack
end AutoScriptEdit
on openfield --**AutoHyperEdit**--
if the optionkey is down
then
if the mouseV <item 2 of rect of target
then
edit script of target
set locktext of target to false
exit openfield
end if
set locktext of target to true
end if
pass openfield
end openfield --**AutoHyperEdit**--
This traps the menu selections so that copy buttons etc will work on groups of objects
{5}
on domenu stuff --**AutoHyperEdit**--
global WhatsMyCardName,CWSList,selectcomp
if selectcomp is true
then
if stuff is clear button
then
clrobj
exit domenu
else if stuff is Copy Button then
put the long name of this card into WhatsMyCardName
pass domenu
else if stuff is cut button then put tip into top
else if stuff is paste button then
pasteobj
exit domenu
else if stuff is Copy fieldthen
put the name of this card into WhatsMyCardName
pass domenu
else if stuff is paste field then pasteobj
else if stuff is clear field then clrobj
pass domenu
exit domenu
end if
pass domenu
end domenu --**AutoHyperEdit**--
This is the Object clearing routine.
{6}
on clrobj
global CWSList
lock screen
repeat with p= the number of items in CWSlist down to 1
set cursor to busy
put item p of CWSlist into it
select it
type x with commandkey
end repeat
choose browse tool
unlock screen
put empty into Cwslist
end clrobj
This is the object pasting routine
{7}
on pasteobj
global CWSList,WhatsMyCardName,selectcomp
put false into selectcomp
set lockscreen to true
set lockmessages to true
repeat with x= the number of items in CWSlist down to 1
if second word of item x of CWSList ¬
is field then choose field tool else choose btn tool
set cursor to busy
push card
go to WhatsMyCardName
put item x of CWSlist into it
if second word of it is btn then set hilite of it to false
if first word of it is btn then set hilite of it to false
select it
type c with commandkey
pop card
if first word of it is Bkgnd then type b with cmdkey
type v with commandkey
if first word of it is Bkgnd then type b with cmdkey
end repeat
choose browse tool
set lockscreen to false
set lockmessages to false
put empty into CWSlist
put empty into WhatsMyCardName
put false into selectcomp
choose browse tool
end pasteobj
on gobo
global CWSList,turnoff,selectcomp
repeat with x= the number of items in CWSlist down to 1
if second word of item x of CWSList is btn then set the hilite
of item x of CWSlist to not the hilite of item x of CWSlist
if first word of item x of CWSList is btn then set the hilite of
item x of CWSlist to not the hilite of item x of CWSlist
end repeat
put empty into CWSList
end gobo
Here I had to test for different objects. I tried to put if the mouseloc is within the rect of a variable then.... where the variable contained an objuct such as btn and another variable. This did not work it is a pity I could have cut the script down considerably. Because of this I have to handle the object types seperately.
{8}
on shiftselect
global CWSlist,w,x,y,z
repeat until the shiftkey is up
repeat while the mouse is down
repeat with w = the number of cd btns down to 1
if the mouseloc is within the rect of btn w then HITCBtn
end repeat
repeat with x = the number of bkgnd btns down to 1
if the mouseloc is within the rect of bkgnd btn x then HITBBtn
end repeat
repeat with y = the number of cd flds down to 1
if the mouseloc is within the rect of cd fld y then HITCFld
end repeat
repeat with z = the number of bkgnd flds down to 1
if the mouseloc is within the rect of bkgnd fld z then HITBFld
end repeat
end repeat
end repeat
end shiftselect
on HitBFld
global CWSlist,z
put false into foundit
if the commandkey is down then set the visible of bkgnd fld z to not
the visible of bkgnd fld z
if the number of items in CWSlist =0
then
put Bkgnd field id & the id of Bkgnd fld z & ,after CWSList
play harpsichord tempo 100 b#x7
exit HitBFld
end if
repeat with p = the number of items in CWSlist down to 1
put item p of CWSList into it
if it = Bkgnd field id & the id of Bkgnd fld z
then
delete item p of CWSList
play harpsichord tempo 100 b#x7
exit HitBFld
end if
end repeat
put Bkgnd field id & the id of bkgnd fld z & ,after CWSList
play harpsichord tempo 100 b#x7
end HitBFld
on HitCFld
global CWSlist,y
put false into foundit
if the commandkey is down then set the visible of cd fld y to not the
visible of cd fld y
if the number of items in CWSlist =0
then
put Card field id & the id of cd fld y & ,after CWSList
play harpsichord tempo 100 b#x7
exit HitCFld
end if
repeat with p = the number of items in CWSlist down to 1
put item p of CWSList into it
if it = Card field id & the id of cd fld y
then
delete item p of CWSList
play harpsichord tempo 100 b#x7
exit HitCFld
end if
end repeat
put Card field id & the id of cd fld y & ,after CWSList
play harpsichord tempo 100 b#x7
end HitCFld
on HitBBtn
global CWSlist,x
put false into foundit
if the commandkey is down then set the visible of bkgnd btn x to not
the visible of bkgnd btn x
set the hilite of bkgnd btn x to not the hilite of bkgnd btn x
if the number of items in CWSlist =0
then
put bkgnd btn id & the id of bkgnd btn x & ,after CWSList
play harpsichord tempo 100 b#x7
exit hitBBtn
end if
repeat with p = the number of items in CWSlist down to 1
put item p of CWSList into it
if it = bkgnd btn id & the id of bkgnd btn x
then
delete item p of CWSList
play harpsichord tempo 100 b#x7
exit hitBBtn
end if
end repeat
put bkgnd btn id & the id of bkgnd btn x & ,after CWSList
play harpsichord tempo 100 b#x7
end HitBBtn
on HitCBtn
global CWSlist,w
put false into foundit
if the commandkey is down then set the visible of btn w to not the
visible of btn w
set the hilite of btn w to not the hilite of btn w
if the number of items in CWSlist =0
then
put btn id & the id of btn w & ,after CWSList
play harpsichord tempo 100 b#x7
exit hitCBtn
end if
repeat with p = the number of items in CWSlist down to 1
put item p of CWSList into it
if it = btn id & the id of btn w
then
delete item p of CWSList
play harpsichord tempo 100 b#x7
exit hitCBtn
end if
end repeat
put btn id & the id of btn w & ,after CWSList
play harpsichord tempo 100 b#x7
end HitCBtn
This section moves the objects.
{9}
on movegroup
global CWSList
wait until the mouse is down
put the mouseLoc into mLoc
put empty into mH
put empty into mV
repeat with i = 1 to the number of items in CWSList
put item i of CWSList into iList
put item 1 of the loc of iList - item 1 of mLoc & , after mH
put item 2 of the loc of iList - item 2 of mLoc & , after mV
end repeat
repeat while the mouse is down
get the mouseLoc
lock screen
repeat with i = 1 to the number of items in CWSList
put it into iList
add item i of mH to item 1 of iList
add item i of mV to item 2 of iList
set loc of item i of CWSList to iList
end repeat
unlock screen
end repeat
end movegroup
I added this section very quickly because I already had the underlying selection and moving structures. As you can see it is very simple.
{10}
on arrowkey whichkey
global CWSList
if the mouse is down then
if whichkey = left then
put the mouseH into L
repeat with i = 1 to the number of items in CWSList
put the width of item i of Cwslist into w
set the left of item i of Cwslist to L
set the width of item i of Cwslist to w
end repeat
end if
if whichkey = right then
put the mouseH into R
repeat with i = 1 to the number of items in CWSList
put the width of item i of Cwslist into w
set the right of item i of Cwslist to R
set the width of item i of Cwslist to w
end repeat
end if
if whichkey = up then
put the mouseV into T
repeat with i = 1 to the number of items in CWSList
put the height of item i of Cwslist into h
set the top of item i of Cwslist to T
set the height of item i of Cwslist to h
end repeat
end if
if whichkey = down then
put the MouseV into B
repeat with i = 1 to the number of items in CWSList
put the height of item i of Cwslist into h
set the bottom of item i of Cwslist to B
set the height of item i of Cwslist to h
end repeat
end if
exit arrowkey
end if
pass arrowkey
end arrowkey --**AutoHyperEdit**--
Non-Comercial use only - All Rights Reserved
Fred Stauder, Hypercard Editor, (HyperChat) MacTutor
---- AutoHyperEdit by Fred Stauder, June 1988 ---
You should get the stack because of the animation and sound ideas it contains. The key thing is to plan your stacks keep them modular so that they can be added to and be polite and use the pass statement so that other peoples scripts will work. For example a stack that uses on mouseStillDown and does not pass it will stop AutoHyperEdit working in that Stack.
Send your Articles, ScriptTips, SpeedTips, etc. to:
Fred Stauder, AppleLink D0280
Ecofin Reseach and Consulting
Lavaterstrasse 45
Zurich 8002
Switzerland
or
To the MacTutor Office