1B MicroScript Thorough Primer, No. 10

Toshihisa Muto

Personal Media Corporation


As the fifth convenient part for user interfaces in 1B MicroScript, we will take up the pop-up selector, and realize this.

MicroScript is a language suited to the creation of user interface systems. Similar ones, such as Visual Basic in Windows, HyperCard in Macintosh, are known. However, on the points of supporting multitasking and hypertext, MicroScript is equipped features that cannot be seen elsewhere.

In this series, so that user interfaces can be created more easily, we took up a parts library over four installments up to here. The individual parts of "selectors," "switches," "volume controls," "numerical value boxes," and "heading tabs" can be easily realized by just calling up several procedures.

TRONWARE Vol. 27 selectors, switches
TRONWARE Vol. 28 volume control
TRONWARE Vol. 29 numerical values box
TRONWARE Vol. 31 heading tab

Because these parts libraries are described with the MicroScript language itself, it is also possible to customize them by adding changes to the source programs in accordance with need.

On this occasion, as the fifth part in parts libraries, we will take up the "pop-up selector" part.

What Is a Pop-Up Selector?

A pop-up selector, as the name selector implies, is a part for selecting one from among several choices. The external appearance is similar to a switch, but we distinguish it by doing such things as attaching shade in the lower right direction. This selector ordinarily displays only current setting values. When we press there, a menu appears (pops up). When we drag up to the choice we would like to select and release, the setting value is modified (Fig. 1).

Figure 1. Pop-up selector operations

The selector we took up in Vol. 27, all the choices are the type that are visible on top of the panel. In TRON, we call this an alternate selector, and we distinguish it from a pop-up selector [Note 1] (Fig. 2).

Figure 2. Alternate selector

The characteristic of a pop-up selector is that the area the part occupies is small. In a case where there are lots of choices, things will become confusing if we line those all up on top of a panel. By using a pop-up selector, we can make the panel surface much neater. Moreover, a pop-up selector is suitable also in a case where the number of choices changes dynamically. This is difficult to realize with an alternate selector, where the display of the choices ends up being fixed.

The parts (switch, volume control, heading tab) we have dealt with up to now in this series are ones where we have brought onto the screen of the computer physical parts that actually exist in the world. However, with this pop-up selector, we are realizing something on the screen that cannot exist in the real world. Without doubt, it is a part only of the graphical user interface (GUI).

Using Heading Tab Parts

Well then, we will now without delay make it our business to create the pop-up selector that caries out the actions in Fig. 1. We carry out the definitions of the segments in the manner of Fig. 3 using the figure editor.

Figure 3. Segment definitions of "Pop-Up Selector Sample"

The segment plate is the base with shadow attached to it, the segment pop is the menu that appears when the user has pressed, the segments sel0~sel2 are the choices, the segment fr is the frame that appears inside the dragging of the pointer, the segments off0 and on0 are indicators inside the menu. It is necessary to arrange the segment pop in the location where the pop-up menu will appear.

On top of the segment pop, the segments sel0~sel2 are mounted. When we disassemble these, they become as in Fig. 4. I want you to pay attention to the fact that the characters of the choices are included also inside the pop segment. They are arranged so that the characters of sel0~sel2 overlap exactly on top of pop.

Figure 4. Segment pop and segments sel0~sel2

The Organization of the Scripts

Scripts are described in text real objects that begin with "SCRIPT." It is necessary for "SCRIPT: Common" to be arranged inner (back) most, and for "SCRIPT: Main" in front of it.

SCRIPT: Common

Definitions of integers necessary for utilization in various parts libraries including pop-up selectors are carried out with this. If we make modifications here, then we can adjust the number of parts that can be registered.

SCRIPT: Pop-Up Selector

This is the script that realizes the pop-up selector library. By just entering this script real object beforehand, it comes about that the pop-up selector library can be used. If you understand just the method of calling up the library, then it is not necessary to understand the contents of the script.

SCRIPT: Sample

This is the script for making this pop-up selector operate. Actually, this alone is fine for user programming.

Realizing Heading Tabs

In that case, let's try doing the programming that calls up the pop-up selector library. I would like you to take a look at Program 3 "SCRIPT: Sample."

Procedure "Initialize_PopUp"

As always, we will follow through this one by one in the order in which things are executed. When we open this MicroScript window, the very first thing that is executed is the part enclosed by PROLOGUE and END on the 19th to 23rd lines. On the 21st line, we are displaying only the segment plate with the SCENE statement. Next, on the 22nd line, we call up the procedure "Prepare_PopUp," and then we call up

8 CALL Initialize_PopUp

on the 8th line.

Before we use the pop-up selector library, it is necessary without fail to call up "Initialize_PopUp" only once.

Procedure "Register_PopUp1"

On the 9th line, we call up the procedure "Register_PopUp1."

9 CALL Register_PopUp1 on0 off0 (-17) (5) plate 7 10

The respective arguments possess the following meanings.

No. 0 argument: <ON indicator segment>
No. 1 argument: <OFF indicator segment>
No. 2 argument <indicator relative position: x coordinate>
No. 3 argument <indicator relative position: y coordinate>
No. 4 argument <pop-up selector segment>
No. 5 argument <settings panel relative position: x coordinate>
No. 6 argument <settings panel relative position: y coordinate>

It comes about that we give the segments on0 and off0 in the no. 0 to no. 1 arguments <ON/OFF indicator segments>, and with the no. 4 argument <pop-up selector segment> we give plate.

The meanings of the other arguments are shown in Fig. 5. These are used in the fine adjustment of the display positions of the indicators and the setting values.

Figure 5. Meaning of each argument

Procedure "Register_PopUp2"

In the procedure "Register_PopUp1," we made settings concerning the pop-up overall. "Register_PopUp2" also is the same [Note 2].

11 CALL Register_PopUp2 popid pop pop.X pop.Y (-1) (-2) fr

The respective arguments possess the following meanings.

No. 0 argument: <pop-up ID>pid (0~)
No. 1 argument: <pop-up menu segment>
No. 2 argument <pop-up menu segment X coordinate>
No. 3 argument <pop-up menu segment Y coordinate>
No. 4 argument <relative position of frame: x coordinate>
No. 5 argument <relative position of frame: y coordinate>
No. 6 argument <frame segment that appears at the time of dragging>

In the no. 0 argument <pop-up ID>, we give the ID that returns when we have called procedure "Register_PopUp1," and in the no. 1 argument <pop-up menu segment>, we give the segment pop. In the final argument, we give the segment fr.

The meanings of the arguments outside of these are show in Fig. 5. These also are employed for adjustment use in display positions.

Procedure "Register_PopUp3"

Procedures "Register_PopUp1" and "Register_PopUp2" made settings concerning the pop-up overall. In "Register_PopUp3," we carrying out settings concerning the individual choices.

12 CALL Register_PopUp3 popid sel0 sel0.X sel0.Y sel0.W sel0.H

13 CALL Register_PopUp3 popid sel1 sel1.X sel1.Y sel1.W sel1.H

14 CALL Register_PopUp3 popid sel2 sel2.X sel2.Y sel2.W sel2.H

No. 0 argument: <pop-up ID>pid (0~)
No. 1 argument: <choice segments>
No. 2 argument <x coordinate of choice>
No. 3 argument <y coordinate of choice>
No. 4 argument <width of choice>
No. 5 argument <height of choice>

In the no. 1 argument <choice segments>, we give the segments sel0~sel2 themselves. From the no. 2 argument to the no. 5 argument, we give the coordinate values and sizes of those segments.

Procedure "Set_PopUp"

We give the initial value ("Soft Lighting") of the pop-up selector as

16 CALL Set_PopUp popid 1

on the 16th line.

"Set_PopUp" takes the arguments below.

No. 0 argument: <pop-up ID>
No. 1 argument: <setting value 0~>

Processing When the Pop-Up Selector Has Been Pressed (3rd to 5th Lines)

In the 3rd to the 5th lines, I have described the processing for when the pop-up selector has been pressed. In using the pop-up selector, outside of registering, the description of this type of procedure becomes necessary.

The library procedure we call up is "Drag_Inside_PopUp_Menu."

4 CALL Drag_Inside_PopUp_Menu popid

This procedure does all the processing during dragging inside the pop-up menu.

"SCRIPT: Common" and "SCRIPT: Pop-Up Selector"

As of up to here, the explanation of "SCRIPT: Sample" stored in Fig. 3 is finished." In "SCRIPT: Common" and "SCRIPT: Pop-Up Selector," the pop-up library below that was used has been programmed.

Procedure "Initialize_PopUp"
Procedure "Register_PopUp1"
Procedure "Register_PopUp2"
Procedure "Register_PopUp3"
Procedure "Set_PopUp"
Procedure "Acquire_PopUp" [Note 3]

In Closing

In this article, I have created a pop-up selector library that uses MicroScript, and I have explained its method of use. Using figures in the choices and freely arranging the choices in a menu are also possible. It serves as a pop-up selector library that can be used in a wide range of applications.

____________________

Program 1 "SCRIPT: Common"
 1 DEFINE MAXVOL 4  
 2 DEFINE MAXSEL 4  
 3 DEFINE MAXBOX 4  
 4 DEFINE MAXTAB 4  
 5 DEFINE MAXPOP 4
 6 DEFINE MAXPOPCHOICE 8
 7 DEFINE MAXSELELM 24 # MAXSEL*MAXSELCHOICE (=6)
 8 DEFINE MAXPOPELM 32 # MAXPOP*MAXPOPCHOICE
 9
10 DEFINE _pid $ARG [0]
11
12 DEFINE Fill_Left_Zero 1
13
14 VARIABLE ret

Program 2 "SCRIPT: Pop-Up"
  1 DEFINE MAXCHOICE 6 # Maximum number of choices
  2 DEFINE ON (1)
  3 DEFINE OFF (0)
  4 DEFINE NONE -2
  5
  6 # Variables used in pop-up parts
  7 # We attach _ at the beginning to variables in which we store segments
  8 VARIABLE _p_I # Counter
  9 VARIABLE _p_npop # Number of pop-ups that have been registered
 10 # Below "_p_choice [XIYIWIH]" is utilized as a two-dimensional array
 11 VARIABLE __p_choice [MAXPOPELEM]
 12 VARIABLE _p_choiceX1 [MAXPOPELEM]
             # Upper left coordinate of choice inside menu
 13 VARIABLE _p_choiceY1 [MAXPOPELEM] 
 14 VARIABLE _p_choiceX2 [MAXPOPELEM]
             # Lower right coordinate of choice inside menu
 15 VARIABLE _p_choiceY2 [MAXPOPELEM]
 16
 17
 18 VARIABLE _p_nchoice {MAXPOP] # Number of choices
 19 VARIABLE _p_popval [MAXPOP]  # Pop-up current value
 20 VARIABLE __p_on [MAXPOP]
             # ON indicator segment
 21 VARIABLE __p_off [MAXPOP]
             # OFF indicator segment
 22 VARIABLE _p_ixofs [MAXPOP]
             # Relative position of indicator: x coordinate
 23 VARIABLE _p_iyofs [MAXPOP]
             # Relative position of indicator: y coordinate
 24 VARIABLE _p_vxofs [MAXPOP]
             # Relative position of settings display: x coordinate
 25 VARIABLE _p_vyofs [MAXPOP]
             # Relative position of settings display: y coordinate
 26 VARIABLE _p_fxofs [MAXPOP]
             # Relative position of frame display: x coordinate
 27 VARIABLE _p_fyofs [MAXPOP]
             # Relative position of frame display: y coordinate
 28 VARIABLE __p_sel [MAXPOP]
             # Pop-up selector segment
 29 VARIABLE __p_menu [MAXPOP] # Menu segment
 30 VARIABLE _p_menuX [MAXPOP] # X coordinate of menu segment
 31 VARIABLE _p_menuY [MAXPOP] # Y coordinate of menu segment
 32 VARIABLE __p_frame [MAXPOP]
 33 VARIABLE _p_sno
 34
 35
 36 #--------------------------------------------------------------------
 37 ACTION Initialize_PopUp
 38 SET _p_npop 0
 39 SET _p_nchoice [_pid] 0
 40 END
 41
 42 #--------------------------------------------------------------------
 43 # Pop-up Registration Part 1
 44 #  Register_PopUp1
 45 #    $ARG[0]: <ON indicator segment>
 46 #    $ARG[1]: <OFF indicator segment>
 47 #    $ARG[2]: <relative position of indicator: x coordinate>
 48 #    $ARG[3]: <relative position of indicator: y coordinate>
 49 #    $ARG[4]: <pop-up selector segment>
 50 #    $ARG[5]: <relative position of settings display: x coordinate>
 51 #    $ARG[6]: <relative position of settings display: y coordinate>
 52 #  Return value < 0 error
 53 #               >= 0 pop-up ID (0~)
 54 #
 55 ACTION Register_PopUp1
 56 IF _p_npop >= MAXPOP
 57  SET ret -1
 58  EXIT
 59 ENDIF
 60 SET __p_on [_p_npop] $ARG[0]
 61 SET __p_off [_p_npop] $ARG[1]
 62 SET _p_ixofs [_p_npop] $ARG[2]
 63 SET _p_iyofs [_p_npop] $ARG[3]
 64 SET __p_sel [_p_npop] $ARG[4]
 65 SET _p_vxofs [_p_npop] $ARG[5]
 66 SET _p_vyofs [_p_npop] $ARG[6]
 67 SET __p_menu [_p_npop] $ARG[7]
 68 SET _p_popval [_p_npop] 0
 69 SET _p_nchoice [_p_npop] 0
 70 SET ret _p_npop
 71 SET _p_npop _p_npop + 1
 72 END
 73 
 74 #--------------------------------------------------------------------
 75 # Pop-up Registration Part 2
 76 #  Register_PopUp2
 77 #    $ARG[0]: <pop-up ID> pid (0~)
 78 #    $ARG[1]: <pop-up menu segment>
 79 #    $ARG[2]: <x coordinate of pop-up menu segment>
 80 #    $ARG[3]: <y coordinate of pop-up menu segment>
 81 #    $ARG[4]: <relative position of frame: x coordinate>
 82 #    $ARG[5]: <relative position of frame: y coordinate>
 83 #    $ARG[6]: <frame segment that appears at time of dragging>
 84 #  Return value < 0 error
 85 #               >= 0 pop-up ID (0~)
 86 ACTION Register_PopUp2
 87 SET __p_menu [_pid] $ARG[1]
 88 SET _p_menuX [_pid] $ARG[2]
 89 SET _p_menuY [_pid] $ARG[3]
 90 SET _p_fxofs [_pid] $ARG[4]
 91 SET _p_fyofs [_pid] $ARG[5]
 92 SET __p_frame [_pid] $ARG[6]
 93 END
 94 #--------------------------------------------------------------------
 95 # Pop-up Registration Part 3
 96 #  Register_PopUp3
 97 #    $ARG[0]: <pop-up ID> pid (0~)
 98 #    $ARG[1]: <choice segment>
 99 #    $ARG[2]: <x coordinate of choice>
100 #    $ARG[3]: <y coordinate of choice>
101 #    $ARG[4]: <width of choice>
102 #    $ARG[5]: <height of choice>
103 #
104 #
105 #  Store position data of choice inside pop-up menu
106 #  Return value < 0 error
107 #               = 0 registration completed
108 #
109 ACTION Register_PopUp3
110 IF _p_nchoice [_pid] >= MAXPOPCHOICE
111 # Exceeds the maximum registration number
112  SET ret -1
113  EXIT
114 ENDIF
115 SET _p_I _pid*MAXCHOICE+_p_nchoice [_pid]
116 SET __p_choice [_p_I] $ARG[1]
117 # Relative coordinate values from the upper left hand corner of the
    # menu of the choices segment in X1/X2/Y1/Y2
118 SET _p_choiceX1 [_p_I] $ARG[2] -_p_menuX [_pid]
119 SET _p_choiceY1 [_p_I] $ARG[3] -_p_menuY [_pid]
120 SET _p_choiceX2 [_p_I] $ARG[2] + $ARG[4] -_p_menuX [_pid]
121 SET _p_choiceY2 [_p_I] $ARG[3] + $ARG[5] -_p_menuY [_pid]
123 SET _p_nchoice [_pid] _p_nchoice [_pid] + 1
124 # Move settings values segment to display position
125 MOVE $ARG[1] :_p_vxofs [_pid] _p_vyofs [_pid] __p_sel [_pid]
126 SET ret 0
127 END
128
129 #--------------------------------------------------------------------
130 #
131 # Displaying ON/OFF Indicator at the Side of the Choices
132 #
133 DEFINE __ind $ARG[7]
134 DEFINE _ndx  $ARG[6]
135 ACTION _p_showIndicators
136 SET _p_I 0;
137 APPEAR __p_off [_pid] __p_on [_pid];
138 MOVE __p_off [_pid] __p_on [_pid];
139 REPEAT _p_nchoice [_pid]
140  # Show ON/OFF indicator in a position where only _p_ixofs, _p_iyofs
141  # are shifted from the upper left hand corner of the choices segment
142  IF _p_I==_p_popval [_pid]
143   SET __ind __p_on [_pid] # ON indicator
144  ELSE
145   SET __ind __p_off [_pid] # OFF indicator
146  ENDIF;
147  SET _ndx _pid*MAXPOPCHOICE+_p_I
148  MOVE __ind :_p_menuX [_pid]+_p_choiceX1 [_ndx] +
          _p_ixofs [_pid] _p_menuY [_pid] + 
          _p_choiceY1 [_ndx] +_p_iyofs [_pid] @ :DUP;
149  SET _p_I _p_I + 1;  
150 ENDREPEAT
151 END
152 #--------------------------------------------------------------------
153 # From the coordinate values of the pointer ($ARG[1}, $ARG[2]),
154 # we find the corresponding choice number, and return it to _p_sno;
155 # if there is no corresponding thing, we return NONE.
156 #
157 DEFINE _p_ndx $ARG[7]
158 ACTION _p_findChoice
159 SET _p_I 0
160 REPEAT _p_nchoice [_pid]
161  SET _p_ndx _pid*MAXCHOICE+_p_I
162  # If we summarize the IF statements into one, it causes an error
163  IF $ARG[1] > _p_choiceX1 [_p_ndx] &$ARG[1] < _p_choiceX2 [_p_ndx]
164  IF $ARG[2] > _p_choiceY1 [_p_ndx] &$ARG[2] < _p_choiceY2 [_p_ndx]
165   SET _p_sno _p_I
166   EXIT
167  ENDIF
168  ENDIF
169  SET _p_I _p_I + 1
170 ENDREPEAT
171 SET _p_sno NONE
172 END
173 #--------------------------------------------------------------------
174 # Call up if pop-up selector is pressed
175 # Drag processing inside menu/indicator display/frame display
176 #  Drag_Inside_PopUp_Menu
177 #   $ARG[0]:<pop-up ID>:pid(0~)
178 #  No return value
179
180 DEFINE _p_oldsno $ARG[7]
181 DEFINE _p_oldI $ARG[6]
182 ACTION Drag_Inside_PopUp_Menu
183 SET _p_oldsno -1
184 APPEAR __p_menu [_pid];
185 CALL _p_showIndicators _pid
186 REPEAT
187  IF    $PDB==0
188   # Because it has been released, escape the loop
189   DISAPPEAR __p_menu [_pid] __p_frame [_pid]
                __p_on [pid] __p_off [_pid]
190   MOVE __p_off [_pid] __p_on [_pid]
191   IF _p_sno != NONE # Setting values changed
192    CALL Set_PopUp _pid _p_sno
193   ENDIF
194   BREAK
195  ENDIF
196  CALL _p_findChoice _pid $PDX-_p_menuX [_pid]
          $PDY-_p_menuY [_pid]
197  SET _p_I _pid*MAXPOPCHOICE+_p_sno
198 IF _p_sno != _p_oldsno
199  # Only when changed from the location of the previous selection
200  IF _p_sno == NONE # No choice below the pointer
201   # Return frame to original
202   MOVE __p_frame [_pid]
203  ELSE
204   # Show frame at periphery of choice
205   MOVE __p_frame [_pid];
206   APPEAR __p_frame [_pid];
207   MOVE __p_frame [_pid]: _p_menuX [_pid]+
           _p_choiceX1 [_p_I] +_p_fxofs [_pid]
           _p_menuY [_pid] +_p_choiceY1 [_p_I]+
           _p_fyofs [_pid] @
208   ENDIF
209   SET _p_oldsno _p_sno
210   SET _p_oldI _p_I
211  ENDIF
212 ENDREPEAT
213
214 END
215 #--------------------------------------------------------------------
216 # Setting value in pop-up
217 #  Set_PopUp
218 #   $ARG[0]:<pop-up ID>:pid (0~)
219 #   $ARG[1]:<setting value>
220 #  No return value
221 ACTION Set_PopUp
222 DISAPPEAR __p_choice [_p_popval [_pid]];
223 APPEAR __p_choice [$ARG [1]]
224 SET _p_popval [_pid] $ARG [1]
225 END
226
227 #--------------------------------------------------------------------
228 # Acquiring pop-up current value
229 #  Acquire_PopUp
230 #    $ARG[0] :<pop-up ID>pid (0~)
231 #  Return value 0~
232 ACTION Acquire_PopUp
233 SET ret _p_popval [_pid]
234 END

Program 3 "SCRIPT: Sample"
 1 VARIABLE popid
 2
#########################################################################
 3 ACTION PopUp_ Selector_Pressed PRESS plate
 4 CALL Drag_Inside_PopUp_Menu popid
 5 END
 6 
#########################################################################
 7 ACTION Prepare_PopUp
 8 CALL Initialize_PopUp
 9 CALL Register_PopUp1 on0 off0 (-17) (5) plate 7 10
10 SET popid ret
11 CALL Register_PopUp2 popid pop pop.X pop.Y (-1) (-2) fr
12 CALL Register_PopUp3 popid sel0 sel0.X sel0.Y sel0.W sel0.H
13 CALL Register_PopUp3 popid sel1 sel1.X sel1.Y sel1.W sel1.H
14 CALL Register_PopUp3 popid sel2 sel2.X sel2.Y sel2.W sel2.H
15 # Set initial values
16 CALL Set_PopUp popid 1
17 END
18
#########################################################################
19 PROLOGUE
20 DEFINE PopUp plate
21 SCENE scene PopUp
22 CALL Prepare_PopUp
23 END

____________________

[Note 1] Alternate Selector: What we call an alternate means mutually substituted for.

[Note 2] "Register_PopUp1" and "Register_PopUp2": That it was necessary to divide the procedure in two is because in MicroScript at present the number of arguments is up to eight. In the new version currently under development, limitations of this kind will become fewer.

[Note 3] Procedure "Acquire_PopUp": This is not used in "SCRIPT: Sample"; by giving the <pop-up ID> to the no. 0 argument, the current pop-up value (0~) returns to the variable ret.


The above article on MicroScript appeared on pages 64-71 in Vol. 32 of TRONWARE. It was translated and loaded onto this Web page with the permission of Personal Media Corporation.

Copyright © 1995 Personal Media Corporation

Copyright © 2008 Sakamura Laboratory, University Museum, University of Tokyo