MHEG_tutorial 
MHEG Tutorial Examples
Revision: 6.0 Last Edit: 12 June 1999 15:51. © S&T 1997-1998
Introduction
This booklet is designed to give a quick and practical start to coding in MHEG-5. It is issued in conjunction with S&T’s One Day Tutorial and gives detailed explanation of the code used as examples in the Tutorial. The objective of both the Tutorial and these examples is to demonstrate the functionality of MHEG-5 within the UKEngineProfile1 and the relative simplicity of the MHEG-5 language. This booklet includes examples of numerous MHEG-5 Object Types and Actions, however, it is not an exhaustive manual, the UKEngineProfile1 and MHEG-5 ISO/IEC 13522-5 documentation combine to form that.
Format
Each example introduces new elements from the MHEG-5 language. For each example a copy of the MHEG-5 code is included, along with a screen shot of the resultant screen and explanation of the relevant parts of the application. Line numbers have been included in print out of code examples for ease of reference, they do not exist in the MHEG code. Most examples consist of an application program (startup) and a single scene program. The code examples show the application code and scene code continuously with contiguous line numbering, this too is for ease of reference. The terminology used to explain the fragments of MHEG-5 should be considered colloquial and intending to inform rather than be completely definitive.
MHEG-5 Engine
The examples in this booklet are all executable on the dts MHEG-5 engine version 0.9a.
Syntax
There are two encoding forms for MHEG-5 applications: textual notation and ASN.1 DER. The textual form is used in these lessons (as its easy to read and write). Looking briefly at a fragment of MHEG:
{:Application (“/startup” 0) :Items ( {:Link 1 :EventSource 0 :EventType IsRunning :LinkEffect ( :TransitionTo ((“/scene.mheg” 0)) ) } ) }
Words that start with a colon (:) such as :Application, :Link and :TransitionTo are termed tags. These are in effect the “keywords” of the MHEG-5 language. A tag preceded by a curly bracket ({) indicates the start of an MHEG-5 object. The tags that follow are the attributes of the enclosing object.
1
© S&T 1997-1998 In real embodiments the ASN.1 DER form would most likely be used as it leads to smaller files and lower broadcast bandwidths. The ASN.1 definition of the MHEG-5 syntax is an alternative (but equivalent) representation to that provided by the textual notation. The Distinguished Encoding Rules (DER) define the process for encoding the syntax into byte streams. In effect, the ASN.1 DER form is a compressed representation of the textual notation. The ASN.1 DER form is not described further in this edition.
2
© S&T 1997-1998
1 Text - 1
An MHEG-5 application comprises an “application” object and one or more “scene” objects. The application object is used to set default parameters, introduce global objects and pass control to the first scene. At any one time, only one application object and one scene can be active. This chapter introduces perhaps the most simple MHEG-5 application. There is just one scene which displays the text “Hello world...”.
Introduces...
• • • • • • •
Application Scene Object references Text Object Events Links InputEventReg 3
Text - 1
3
© S&T 1997-1998
1.1 Code example
1| 2| 3| 4| 5| 6| 7| 8| 9| 10| 11| 12| 13| 14| 15| 16| 17| 18| 19| 20| 21| 22| 23| 24| 25| 26| 27| 28| 29| 30| 31| 32| 33| 34| 35| 36| {:Application (“/startup” 0) :Items ( {:Link 1 :EventSource 0 :EventType IsRunning :LinkEffect ( :TransitionTo ((“/scene.mheg” 0)) ) } ) } {:Scene (“/scene.mheg” 0) :Items ( {:Text 1 :CHook 10 :OrigContent “Hello world...” :OrigBoxSize 200 50 :OrigPosition 200 100 } {:Link 2 :EventSource 0 :EventType UserInput :EventData 104 :LinkEffect ( :Quit ( ( “/startup” 0 ) ) ) } ) :InputEventReg 3 :SceneCS 720 576 }
4
Text - 1
© S&T 1997-1998
1.2 Analysis
Table 1. Text - 1 - Application (/lesson1/startup)
{:Application (“/startup” 0)
Application objects are always named ‘startup’. In applications and scenes, the object number is always zero. (“/startup”0) is the reference of the object. The full or relative path may be specified. 'startup' is the group identifier, and the zero is the object number.
:Items ( {:Link 1
Objects contained in an Application are listed within the Items clause. A Link includes one or more Actions that will be performed when the specified Event occurs. The object identifying number must not be zero and each object number within an Application object must be unique. The number has no significance other than as an identifier.
:EventSource 0
An Event happens to a specific object, in this case object 0 which is the Application object. The Event that will spark the Action(s) is an IsRunning Event, this is fired when the Application and its Items have been prepared and activated as specified. The Action(s) to perform are specified in this clause. An Application does not display to the screen, here control is passed to a scene which can display to screen. End of the Items list. End of the application object.
:EventType IsRunning
:LinkEffect ( :TransitionTo ((“/scene.mheg” 0)) ) } ) }
Table 2. Text - 1 - Scene (/lesson1/scene.mheg)
{:Scene (“/scene.mheg” 0)
Scene objects can be given any name. In applications and scenes, the object number is always zero. (“/scene.mheg” 0) is the reference of the object. As this is a scene, the object number is set to zero. The ‘mheg’ file extension is not compulsory but a convention used in these examples.
:Items ( {:Text 1
Objects contained in the scene are listed within the Items clause. A Text object is defined. The object identifying number must not be zero and each object number within a scene must be unique. The number has no significance other than as an identifier
:CHook 10
The Content Hook value informs the MHEG engine of the type of text to expect. There is, at time of writing, only one Text type in the UK Profile and therefore only one Content Hook value, which is 10. N.B. This is not the most efficient place to code CHook, a better alternative is introduced later in the booklet.
Text - 1
5
© S&T 1997-1998 Table 2. Text - 1 - Scene (/lesson1/scene.mheg)
:OrigContent “Hello world...”
The initial content of the text object is defined. Text content can be included content, as in this example, or referenced, as in the next example. Here the content is enclosed in the double-quote marks which indicates a string of printable characters. Other string formats can be used such as Quoted-Printable or BASE64 and are introduced using different styles of quotation mark. NOTE that in the MHEG-5 language, ‘Orig’ signifies that the attribute may be changed during run time.
:OrigBoxsize 200 50
This is the display area (rectangle) that will include the text. The box size co-ordinates are x and y in pixels. The x and y pixel co-ordinates specifying the position within the scene of the top left corner of the text display area. A link associated with the scene object, as in Table 1 on page 5. The Event will be fired by pressing one of the UserInput keys.
:OrigPosition 200 100
} {:Link 2 :EventSource 0 :EventType UserInput :EventData 104 :LinkEffect ( :Quit ((“/startup”0)) ) } ) :InputEventReg 3
EventData 104 is the ‘TEXT’ key on remote control. (‘T’ or ‘t’ on PC).
The actions to perform, as in Table 1 on page 5 The result of the event will be the termination of the Application. Input Event Register 3 includes the remote control colour and ‘Text’ keys. The size of the co-ordinate system of the scene is defined. The valid co-ordinates for the current UK profile are 720 wide by 576.
:SceneCS 720 576
6
Text - 1
© S&T 1997-1998
2 Text - 2
In the previous example the engine’s default values were used for formatting the text. In this example attributes are set to control the appearance of the text. Attributes can either be specified as default for the application or can be specified for individual text objects. This example also introduces ‘included’ text in different formats and ‘referenced’ text.
Introduces...
• • •
Referenced text content Text colour Mark Up language Text colour
Text - 2
7
© S&T 1997-1998
2.1 Code Example
0 1| 2| 3| 4| 5| 6| 7| 8| 9| 10| 11| 12| 13| 14| 15| 16| 17| 18| 19| 20| 21| 22| 23| 24| 25| 26| 27| 28| 29| 30| 31| 32| 33| 34| 35| 36| 37| 38| 39| 40| 41| 42| 43| 44| 45| 46| 47| 48| 49| 50| 51| 52| 53| 54| {:Application (‘/startup’ 0) :Items ( {:Link 1 :EventSource 0 :EventType IsRunning :LinkEffect ( :TransitionTo ((‘/scene.mheg’ 0)) ) } ) } {:Scene (“/scene.mheg” 0) :Items ( {:Text 1 :CHook 10 :OrigContent “Hello world...” :OrigBoxSize 200 50 :OrigPosition 200 100 :TextColour ‘=FF=00=00=00’ :BackgroundColour ‘=00=00=F0=00’ } {:Text 2 :CHook 10 :OrigContent ‘Hello =1BC=04=FF=FF=00@world=1Bc...’ :OrigBoxSize 200 50 :OrigPosition 200 200 :TextColour ‘=FF=00=00=00’ :BackgroundColour ‘=00=00=F0=00’ } {:Text 3 :CHook 10 :OrigContent :ContentRef (“/hello.txt”) :OrigBoxSize 200 50 :OrigPosition 200 300 :TextColour ‘=FF=00=00=00’ :BackgroundColour ‘=00=00=F0=00’ } {:Link 100 :EventSource 0 :EventType UserInput :EventData 104 :LinkEffect ( :Quit ( ( “/startup” 0 ) ) ) } ) :InputEventReg 3 :SceneCS 720 576 }
8
Text - 2
© S&T 1997-1998
2.2 Analysis
Table 3. Text - 2 (/lesson2/startup and scene.mheg)
Lines 1 to 13 Lines 14 to 18
:OrigContent “Hello world...”
As in Table 1 on page 5 As in Table 2 on page 5. Here the initial text is an included string; any characters included within the double quotes will be printed to screen. As in Table 2 on page 5. The colour with which to fill the text display rectangle is defined. The values are hex Red, Green, Blue and Transparency. If no background colour is defined then the rectangle will be transparent.
Lines 20 to 21
:BackGroundColour ‘=00=00=f0=00’
:TextColour ‘=ff=00=00=00’
The text colour is defined, using hex values for Red, Green, Blue and Transparency. As in Table 2 on page 5 Here the text is included ‘Q Printable’; text within the single quotes can include hex codes to add non alpha characters or to change text colour . As above and in Table 2 on page 5 Here the text is referenced; the name of the file containing the text is defined, not the text itself. As above and in Table 2 on page 5
Lines 24 to 26
:OrigContent ‘Hello =1b=43=04=ff=ff=00=40world=1b=63...’
Lines 28 to 34
:OrigContent :ContentRef (“/hello.txt”)
Lines 36 to 53
Text - 2
9
© S&T 1997-1998
3 Global Objects
Ingredient objects can be defined within a scene or within an application. When defined in a scene the object is only available to that scene, however, when defined in an application it is potentially global, i.e. available to all scenes associated with the application. In this example both approaches are used.
Introduces...
• • • •
Global objects Object Font Attributes Application Default Font Attributes Text Wrapping and Justification
10
Global Objects
© S&T 1997-1998
3.1 Code Example
0 1| 2| 3| 4| 5| 6| 7| 8| 9| 10| 11| 12| 13| 14| 15| 16| 17| 18| 19| 20| 21| 22| 23| 24| 25| 26| 27| 28| 29| 30| 31| 32| 33| 34| 35| 36| 37| 38| 39| 40| 41| 42| 43| 44| 45| 46| 47| 48| 49| 50| 51| 52| 53| 54| 55| 56| 57| 58| 59| 60| 61| 62| 63| 64| 65| 66| {:Application (“/startup” 0) :Items ( {:Link 1 :EventSource 0 :EventType IsRunning :LinkEffect ( :TransitionTo ((“/scene.mheg” 0)) ) } {:Text 2 :Origcontent “MHEG tutorial” :Shared True :Origboxsize 250 50 :Origposition 235 5 :FontAttributes ‘=00=24=24=00=80’ :TextColour ‘=FF=FF=FF=00’ :BackgroundColour ‘=FF=00=00=00’ :HJustification centre :VJustification centre } ) :TextCHook 10 :FontAttributes ‘=00=1a=1a=00=00’ } {:Scene (“/scene.mheg” 0) :Items ( {:Text 1 :OrigContent “Chapter 2” :OrigBoxSize 200 35 :OrigPosition 22 60 :FontAttributes ‘=00=1F=1F=00=00’ :TextColour ‘=00=00=FF=00’ :HJustification start :VJustification start } {:Text 3 :OrigContent “Part of MHEG tutorial” :OrigBoxSize 370 35 :OrigPosition 200 400 :FontAttributes “plain.24.24.0” :HJustification end :VJustification centre } {:Link 100 :EventSource 0 :EventType UserInput :EventData 104 :LinkEffect ( :Quit ( ( “/startup” 0 ) ) ) } {:Text 101 :OrigContent :ContentRef (“/assets/1.txt”) :OrigBoxSize 654 291 :OrigPosition 24 103 :TextWrapping true } ) :InputEventReg 3 :SceneCS 720 576 }
Global Objects
11
© S&T 1997-1998
3.2 Analysis
Table 4. Global Objects (/lesson3/startup and scene.mheg)
Lines 1 to 11
{:Text 2 :Origcontent “MHEG tutorial” :Origboxsize 250 50 :Origposition 235 5 :Shared True
As inTable 1 on page 5 A text object is defined in the Application Object Items list in the same way as it would be in a Scene Object. Objects defined within the Application object are potentially available to all scenes in the application. This technique is useful for visible objects that are to be displayed in many scenes and for non visibles, for example a variable holding a score counter in a game.
Shared True must be coded if the object is required in more than one scene, in this example it is not strictly needed but it is good practice to include it.
:FontAttributes ‘plain.36.36.500’ :TextColour ‘=FF=FF=FF=00’ :BackgroundColour ‘=FF=00=00=00’
FontAttributes are used to override the default font size of 24. The Font for UK Profile is RNIB Tiresias ScreenFont. The 1st parameter is style which can currently only be ‘plain’. The 2nd parameter is font size which can be 24, 26, 31 or 36. The 3rd parameter is the distance between text lines. The 4th parameter is the difference to the default kerning pair values.
The Horizontal and Vertical justification is set to Centre. In previous examples the TextContentHook has been defined within the Text Objects. By defining the TextContentHook in the Application the hook value will be inherited by any Text objects in the Application or its scenes where the value has not been set. As there is currently only one TextContentHook value it makes sense to define it always per application and not per Text object. N.B. If no TextContentHook value is set then the text will not display! The FontAttributes defined for the Application, rather than a specific text object, will be inherited by any Text objects within the Application or its scenes where the attributes have not been set. N.B. If FontAttributes are not set then the default size of 26 is used, however, the line distance will vary with Set Top Box and it is therefore recommended that the default attributes be encoded in the application.
:HJustification centre :VJustification centre } ) :TextCHook 10
:FontAttributes ‘plain.26.26.0’ }
Lines 28 to 46
:TextWrapping true
As in Table 3 on page 9 This will cause the text to wrap automatically within the display rectangle. As in Table 2 on page 5
Lines 48 to 69
12
Global Objects
© S&T 1997-1998
4 User Interaction - 1
MHEG-5 provides powerful features for implementing interaction with the user. The lessons that follow show how to build up user interaction based on the remote control colour keys. In this first lesson ‘pressing’ a colour key will fire an event that changes a text object attribute to display which colour was pressed. (For the dts MHEG-5 v.0.9a engine use ‘r’/’R’ for Red, ‘y’/’Y’ for yellow, ‘g’/’G’ for green and ‘b’/’B’ for blue)
Introduces..
• • •
Rectangle Object Set Data (changing included content of text object) InputEventReg 4
User Interaction - 1
13
© S&T 1997-1998
4.1 Code Example
0 1| 2| 3| 4| 5| 6| 7| 8| 9| 10| 11| 12| 13| 14| 15| 16| 17| 18| 19| 20| 21| 22| 23| 24| 25| 26| 27| 28| 29| 30| 31| 32| 33| 34| 35| 36| 37| 38| 39| 40| 41| 42| 43| 44| 45| 46| 47| 48| 49| 50| 51| 52| 53| 54| 55| 56| 57| 58| 59| 60| 61| 62| 63| 64| 65| 66| 67| 68| 69| 70| 71| 72| 73| 74| 75| 76| 77| 78| 79| 80| 81| 82| {:Application (“/startup” 0) :Items ( {:Link 1 :EventSource 0 :EventType IsRunning :LinkEffect ( :TransitionTo ((“/scene.mheg” 0)) ) } ) :TextChook 10 } {:Scene (“/scene.mheg” 0) :Items ( {:Rectangle 1 :OrigBoxSize 335 263 :OrigPosition 10 10 :OrigRefFillColour ‘=00=00=FF=00’ } {:Rectangle 2 :OrigBoxSize 335 263 :OrigPosition 370 10 :OrigRefFillColour ‘=FF=00=00=00’ } {:Rectangle 3 :OrigBoxSize 335 263 :OrigPosition 10 298 :OrigRefFillColour ‘=FF=FF=00=00’ } {:Rectangle 4 :OrigBoxSize 335 263 :OrigPosition 370 298 :OrigRefFillColour ‘=00=FF=00=00’ } {:Text 5 :OrigContent ““ :OrigBoxSize 120 100 :OrigPosition 300 238 :FontAttributes “plain.26.26.0” :HJustification Centre :VJustification Centre } {:Link 6 :EventSource 0 :EventType UserInput :EventData 100 :LinkEffect ( :SetData ( 5 “Red” ) ) } {:Link 7 :EventSource 0 :EventType UserInput :EventData 101 :LinkEffect ( :SetData ( 5 “Green” ) ) } {:Link 8 :EventSource 0 :EventType UserInput :EventData 102 :LinkEffect ( :SetData ( 5 “Yellow” ) ) } {:Link 9 :EventSource 0 :EventType UserInput :EventData 103 :LinkEffect ( :SetData ( 5 “Blue” ) ) }
14
User Interaction - 1
© S&T 1997-1998
83| 84| 85| 86| 87| 88| 89| 90| 91| 92| 93| 94| 95| 96| 97| 98| 99| 100| 101| 102| 103| 104|
{:Link 10 :EventSource 0 :EventType UserInput :EventData 16 :LinkEffect ( :Quit ( ( “/startup” 0 ) ) ) } {:Link 11 :EventSource 0 :EventType UserInput :EventData 104 :LinkEffect ( :Quit ( ( “/startup” 0 ) ) ) } ) :InputEventReg 4 :SceneCS 720 576 }
User Interaction - 1
15
© S&T 1997-1998
4.2 Analysis
Table 5. User Interaction - 1 (/lesson4/startup and scene.mheg)
Lines 1 to 17
{:Rectangle 1 :Origboxsize 335 263 :Origposition 10 10 :OrigRefFillcolour ‘=00=00=FF=00’ }
As in Table 4 on page 12
Four Rectangles are created with fill colours blue, red, yellow and green.
And Lines 23 to 36
{:Text 5 :OrigContent ““ :OrigBoxSize 120 100 :OrigPosition 300 238 :FontAttributes ‘plain.26.26.0’ :HJustification Centre :VJustification Centre } {:Link 6 :EventSource 0 :EventType UserInput :EventData 100 :LinkEffect ( :SetData (5 “Red”) ) }
The content of this text will later be set to hold the name of the colour key pressed.
Links 6 to 9 are created to set the data of the text object to reflect the colour key pressed.
EventData values for the remote control colour keys are
100=Red 101=Green 102=Yellow 103=Blue
And Lines 55 to 81
{:Link 10 :EventSource 0 :EventType UserInput :EventData 16 :LinkEffect ( :Quit((“/startup”0)) ) }
EventData 16 (escape/cancel key) is pressed.
Lines 91 to 100
:InputEventReg 4 :SceneCS 720 576 }
As in Table 2 on page 5 Register 4 is required to enable the escape/cancel key to be recognised by the engine.
16
User Interaction - 1
© S&T 1997-1998
5 User Interaction - 2
The behaviour of this application is identical to the previous example, however, the underlying code is different and introduces a useful programming device, the TokenGroupManager. The partial use of the TokenGroupManager in this lesson is built upon over the next few lessons.
Introduces..
•
Token Group Manager
User Interaction - 2
17
© S&T 1997-1998
5.1 Code Example
0 1| 2| 3| 4| 5| 6| 7| 8| 9| 10| 11| 12| 13| 14| 15| 16| 17| 18| 19| 20| 21| 22| 23| 24| 25| 26| 27| 28| 29| 30| 31| 32| 33| 34| 35| 36| 37| 38| 39| 40| 41| 42| 43| 44| 45| 46| 47| 48| 49| 50| 51| 52| 53| 54| 55| 56| 57| 58| 59| 60| 61| 62| 63| 64| 65| 66| 67| 68| 69| 70| 71| 72| 73| 74| 75| 76| 77| 78| 79| 80| 81| 82| {:Application (“/startup” 0) :Items ( {:Link 1 :EventSource 0 :EventType IsRunning :LinkEffect ( :TransitionTo ((“/scene.mheg” 0)) ) } ) :TextCHook 10 } {:Scene (“/scene.mheg” 0) :Items ( {:Rectangle 1 :OrigBoxSize 335 263 :OrigPosition 10 10 :OrigRefFillColour ‘=00=00=FF=00’ } {:Rectangle 2 :OrigBoxSize 335 263 :OrigPosition 370 10 :OrigRefFillColour ‘=FF=00=00=00’ } {:Rectangle 3 :OrigBoxSize 335 263 :OrigPosition 10 298 :OrigRefFillColour ‘=FF=FF=00=00’ } {:Rectangle 4 :OrigBoxSize 335 263 :OrigPosition 370 298 :OrigRefFillColour ‘=00=FF=00=00’ } {:Text 5 :OrigContent ““ :OrigBoxSize 120 100 :OrigPosition 300 238 :FontAttributes ‘=00=1A=1A=00=00’ :HJustification Centre :VJustification Centre } {:TokenGroup 6 :TokenGroupItems ( (5 :ActionSlots ( ( :SetData ( 5 “Red” ) ) ( :SetData ( 5 “Green” ) ) ( :SetData ( 5 “Yellow” ) ) ( :SetData ( 5 “Blue” ) ) ) ) ) } {:Link 7 :EventSource 0 :EventType UserInput :EventData 100 :LinkEffect ( :CallActionSlot ( 6 1 ) ) } {:Link 8 :EventSource 0 :EventType UserInput :EventData 101 :LinkEffect
18
User Interaction - 2
© S&T 1997-1998
83| 84| 85| 86| 87| 88| 89| 90| 91| 92| 93| 94| 95| 96| 97| 98| 99| 100| 101| 102| 103| 104| 105| 106| 107| 108| 109| 110| 111| 112| 113| 114| 115| 116| 117| 118| 119| 120| 121| 122| 123| 124| 125| 126|
( :CallActionSlot ( 6 2 ) ) } {:Link 9 :EventSource 0 :EventType UserInput :EventData 102 :LinkEffect ( :CallActionSlot ( 6 3 ) ) } {:Link 10 :EventSource 0 :EventType UserInput :EventData 103 :LinkEffect ( :CallActionSlot ( 6 4 ) ) } {:Link 11 :EventSource 0 :EventType UserInput :EventData 16 :LinkEffect ( :Quit ( ( “/startup” 0 ) ) ) } {:Link 12 :EventSource 0 :EventType UserInput :EventData 104 :LinkEffect ( :Quit ( ( “/startup” 0 ) ) ) } ) :InputEventReg 4 :SceneCS 720 576 }
User Interaction - 2
19
© S&T 1997-1998
5.2 Analysis
Table 6. User Interaction - 2 (/lesson5/startup & scene.mheg)
Lines 1 to 45
{:TokenGroup 6 :TokenGroupItems ( (5 :ActionSlots ( (:SetData (5 “Red”)) (:SetData (5 “Green”)) (:SetData (5 “Yellow”)) (:SetData (5 “Blue”)) ) ) ) }
As in Table 5 on page 16. The TokenGroup is used to control which scene objects have focus and what actions will be carried out depending on which visible object currently has focus. However, in this example only very little of the TokenGroup functionality is used, the main difference between this example and the previous one is that the actions (e.g. SetData (5 “Red”)) are specified in the TokenGroup and called from the link using CallActionSlot. There must be at least one item in the TokenGroup Items list, here it is object number 5. There are 4 distinct ActionSlots, each contained within brackets. Any number of actions may be coded in an actionslot, here it is the single SetData Action.
{:Link 7 :EventSource 0 :EventType UserInput :EventData 100 :LinkEffect ( :CallActionSlot(6 1) ) } {:Link 8 :EventSource 0 :EventType UserInput :EventData 101 :LinkEffect ( :CallActionSlot(6 2) ) } {:Link 9 :EventSource 0 :EventType UserInput :EventData 102 :LinkEffect ( :CallActionSlot(6 3) ) } {:Link 10 :EventSource 0 :EventType UserInput :EventData 103 :LinkEffect ( :CallActionSlot(6 4) ) }
:CallActionSlot (6 1) will activate the code from object 6 (the TokenGroup) actionslot line 1 (it will set the text of text object 5 to “Red”).
:CallActionSlot (6 2) will activate the code from object 6 (the TokenGroup) actionslot line 2 (it will set the text of text object 5 to “Green”).
:CallActionSlot (6 3) will activate the code from object 6 (the TokenGroup) actionslot line 3 (it will set the text of text object 5 to “Yellow”).
:CallActionSlot (6 4) will activate the code from object 6 (the TokenGroup) actionslot line 4 (it will set the text of text object 5 to “Blue”).
Lines 95 to 116
See Table 5 on page 16.
20
User Interaction - 2
© S&T 1997-1998
6 User Interaction - 3
In this lesson the TokenGroup MovementTable is introduced and is used to prescribe navigation responses to User Input.
Introduces..
• • •
TokenGroup Movement Table Cursor Key User Input Move and MoveTo Actions
User Interaction - 3
21
© S&T 1997-1998
6.1 Code Example
0 1| 2| 3| 4| 5| 6| 7| 8| 9| 10| 11| 12| 13| 14| 15| 16| 17| 18| 19| 20| 21| 22| 23| 24| 25| 26| 27| 28| 29| 30| 31| 32| 33| 34| 35| 36| 37| 38| 39| 40| 41| 42| 43| 44| 45| 46| 47| 48| 49| 50| 51| 52| 53| 54| 55| 56| 57| 58| 59| 60| 61| 62| 63| 64| 65| 66| 67| 68| 69| 70| 71| 72| 73| 74| 75| 76| 77| 78| 79| 80| 81| 82| {:Application (“/startup” 0) :Items ( {:Link 1 :EventSource 0 :EventType IsRunning :LinkEffect ( :TransitionTo ((“/scene.mheg” 0)) ) } ) :TextCHook 10 } {:Scene (“/scene.mheg” 0) :Items ( {:Rectangle 1 :OrigBoxSize 335 263 :OrigPosition 10 10 :OrigRefFillColour ‘=00=00=FF=00’ } {:Rectangle 2 :OrigBoxSize 335 263 :OrigPosition 370 10 :OrigRefFillColour ‘=FF=00=00=00’ } {:Rectangle 3 :OrigBoxSize 335 263 :OrigPosition 10 298 :OrigRefFillColour ‘=FF=FF=00=00’ } {:Rectangle 4 :OrigBoxSize 335 263 :OrigPosition 370 298 :OrigRefFillColour ‘=00=FF=00=00’ } {:Text 5 :OrigContent ““ :OrigBoxSize 120 100 :OrigPosition 300 238 :FontAttributes ‘=00=1A=1A=00=00’ :HJustification Centre :VJustification Centre } {:TokenGroup 6 // 1st 2nd 3rd 4th //up //down //left //right :MovementTable ( ( 1 2 1 2) ( 3 4 3 4) ( 1 1 3 3) ( 2 2 4 4) ) :TokenGroupItems ( (1 :ActionSlots ( ( :SetData ( 5 “Blue” ) ) ) ) (2 :ActionSlots ( ( :SetData ( 5 “Red” ) ) ) ) (3 :ActionSlots ( ( :SetData ( 5 “Yellow” )
22
User Interaction - 3
© S&T 1997-1998
83| 84| 85| 86| 87| 88| 89| 90| 91| 92| 93| 94| 95| 96| 97| 98| 99| 100| 101| 102| 103| 104| 105| 106| 107| 108| 109| 110| 111| 112| 113| 114| 115| 116| 117| 118| 119| 120| 121| 122| 123| 124| 125| 126| 127| 128| 129| 130| 131| 132| 133| 134| 135| 136| 137| 138| 139| 140| 141| 142| 143| 144| 145| 146| 147| 148| 149| 150| 151| 152| 153| 154| 155| 156| 157| 158| 159| 160| 161| 162| 163| 164| 165| 166| 167|
) ) ) (4 :ActionSlots ( ( :SetData ( 5 “Green” ) ) ) ) ) :NoTokenActionSlots ( null ) } {:Link 7 :EventSource 0 :EventType UserInput :EventData 100 :LinkEffect ( :MoveTo ( 6 2 ) :CallActionSlot ( 6 ) } {:Link 8 :EventSource 0 :EventType UserInput :EventData 101 :LinkEffect ( :MoveTo ( 6 4 ) :CallActionSlot ( 6 ) } {:Link 9 :EventSource 0 :EventType UserInput :EventData 102 :LinkEffect ( :MoveTo ( 6 3 ) :CallActionSlot ( 6 ) } {:Link 10 :EventSource 0 :EventType UserInput :EventData 103 :LinkEffect ( :MoveTo ( 6 1 ) :CallActionSlot ( 6 ) } {:Link 11 :EventSource 0 :EventType UserInput :EventData 1 :LinkEffect ( :Move ( 6 1 ) ) } {:Link 12 :EventSource 0 :EventType UserInput :EventData 2 :LinkEffect ( :Move ( 6 2 ) ) } {:Link 13 :EventSource 0 :EventType UserInput :EventData 3 :LinkEffect ( :Move ( 6 3 ) ) } {:Link 14
1 )
1 )
1 )
1 )
User Interaction - 3
23
© S&T 1997-1998
168| 169| 170| 171| 172| 173| 174| 175| 176| 177| 178| 179| 180| 181| 182| 183| 184| 185| 186| 187| 188| 189| 190| 191| 192| 193| 194| 195| 196| 197| 198| 199| 200| 201| 202| 203| 204| 205| 206|
:EventSource 0 :EventType UserInput :EventData 4 :LinkEffect ( :Move ( 6 4 ) ) } {:Link 15 :EventSource 0 :EventType UserInput :EventData 15 :LinkEffect ( :CallActionSlot ( 6 1 ) ) } {:Link 16 :EventSource 0 :EventType UserInput :EventData 16 :LinkEffect ( :Quit ( ( “/startup” 0 ) ) ) } {:Link 17 :EventSource 0 :EventType UserInput :EventData 104 :LinkEffect ( :Quit ( ( “/startup” 0 ) ) ) } ) :InputEventReg 4 :SceneCS 720 576 }
24
User Interaction - 3
© S&T 1997-1998
6.2 Analysis
Table 7. User Interaction - 3 (/lesson6/startup & scene.mheg)
Lines 1 to 45
{:TokenGroup 6 :MovementTable // 1st 2nd 3rd 4th ( (1 2 1 2)//up (3 4 3 4)//down (1 1 3 3)//left (2 2 4 4)//right )
See Table 5 on page 16. Token Position 1 2 3 4 Movement The movement table defines how the token should move between the 4 buttons. For example, if the token is with button ‘3’ and the movement direction is ‘up’ the token moves to button ‘1’. The column positions come from the order of items in the list of token group items. The association of the rows with directions results from the :Move values in the link effects.
:TokenGroupItems ( (1 :ActionSlots ( (:SetData (5 “Blue”)) ) ) (2 :ActionSlots ( (:SetData (5 “Red”)) ) ) (3 :ActionSlots ( (:SetData (5 “Yellow”)) ) ) (4 :ActionSlots ( (:SetData (5 “Green”)) ) ) ) :NoTokenActionSlots (Null) }
Define the action according to which Visible object the token is currently associated with. For example, if the token is associated with object 3 then the CallActionSlots command will cause the Text object data to be “Yellow”.
Define the actions if the token is not with one of the listed token group items (i.e. the token is at position 0). In this case the action is to do nothing.
{:Link 7 :EventSource 0 :EventType UserInput :EventData 100 :LinkEffect ( :MoveTo (6 2) :CallActionSlot(6 1) ) } {:Link 8 :EventSource 0 :EventType UserInput :EventData 101 :LinkEffect ( :MoveTo (6 4) :CallActionSlot(6 1) ) }
MoveTo (6 2) causes the token to be associated with the second item in the TokenGroupItems list (of object 6). CallActionSlot (6 1) will action the first code option in the TokenGroup (object 6) for the ActionSlots object currently associated with the token.
i.e. the token is moved to the Red Rectangle 2 and the text field is set to “Red”
MoveTo (6 4) causes the token to be associated with the fourth item in the TokenGroupItems list (of object 6). CallActionSlot (6 1) will action the first code option in the TokenGroup (object 6) for the ActionSlots object currently associated with the token.
i.e. the token is moved to the Green Rectangle 4 and the text field is set to “Green”
User Interaction - 3
25
© S&T 1997-1998 Table 7. User Interaction - 3 (/lesson6/startup & scene.mheg)
{:Link 9 :EventSource 0 :EventType UserInput :EventData 102 :LinkEffect ( :MoveTo (6 3) :CallActionSlot(6 1) ) } {:Link 10 :EventSource 0 :EventType UserInput :EventData 103 :LinkEffect ( :MoveTo (6 1) :CallActionSlot(6 1) ) } {:Link 11 :EventSource 0 :EventType UserInput :EventData 1 :LinkEffect ( :Move (6 1) ) } {:Link 12 :EventSource 0 :EventType UserInput :EventData 2 :LinkEffect ( :Move (6 2) ) } {:Link 13 :EventSource 0 :EventType UserInput :EventData 3 :LinkEffect ( :Move (6 3) ) } {:Link 14 :EventSource 0 :EventType UserInput :EventData 4 :LinkEffect ( :Move (6 4) ) } {:Link 15 :EventSource 0 :EventType UserInput :EventData 15 :LinkEffect ( :CallActionSlot(6 1) ) }
MoveTo (6 3) causes the token to be associated with the third item in the TokenGroupItems list (of object 6). CallActionSlot (6 1) will action the first code option in the TokenGroup (object 6) for the ActionSlots object currently associated with the token.
i.e. the token is moved to the Yellow Rectangle 2 and the text field is set to “Yellow”
MoveTo (6 1) causes the token to be associated with the first item in the TokenGroupItems list (of object 6). CallActionSlot (6 1) will action the first code option in the TokenGroup (object 6) for the ActionSlots object currently associated with the token.
i.e. the token is moved to the Blue Rectangle 2 and the text field is set to “Blue”
EventData 1 is the up arrow Move (6 1) will move the token to the position defined in line 1 of the MovementTable, for the column associated with the current token position. For example, if the token is currently on the 4th object in the TokenGroup (the blue rectangle), it will move to the 2nd object as specified by line 1 column 4 of the Movement Table.
EventData 2 is the down arrow Move (6 2) will move the token to the position defined in line 2 of the MovementTable, for the column associated with the current token position.
EventData 3 is the left arrow Move (6 3) will move the token to the position defined in line 3 of the MovementTable, for the column associated with the current token position.
EventData 4 is the right arrow Move (6 4) will move the token to the position defined in line 4 of the MovementTable, for the column associated with the current token position. EventData 15 is the enter/return key. CallActionSlot (6 1) will action the first code option in the TokenGroup (object 6) for the ActionSlots object currently associated with the token.
i.e. the text field is set to which ever colour rectangle the token is currently associated with.
Lines 165 to 186
As in Table 5 on page 16.
26
User Interaction - 3
© S&T 1997-1998
7 User Interaction - 4
This example is identical to the previous one but also includes a hollow rectangle to highlight the currently selected coloured rectangle.
Introduces..
• •
Changing position of a rectangle, using SetPosition Rectangle Line Width and Line Colour
User Interaction - 4
27
© S&T 1997-1998
7.1 Code Example
0 1| 2| 3| 4| 5| 6| 7| 8| 9| 10| 11| 12| 13| 14| 15| 16| 17| 18| 19| 20| 21| 22| 23| 24| 25| 26| 27| 28| 29| 30| 31| 32| 33| 34| 35| 36| 37| 38| 39| 40| 41| 42| 43| 44| 45| 46| 47| 48| 49| 50| 51| 52| 53| 54| 55| 56| 57| 58| 59| 60| 61| 62| 63| 64| 65| 66| 67| 68| 69| 70| 71| 72| 73| 74| 75| 76| 77| 78| 79| 80| 81| 82| {:Application (“/startup” 0) :Items ( {:Link 1 :EventSource 0 :EventType IsRunning :LinkEffect ( :TransitionTo ((“/scene.mheg” 0)) ) } ) :TextCHook 10 } {:Scene (“/scene.mheg” 0) :Items ( {:Rectangle 10 :OrigBoxSize 335 263 :OrigPosition 10 10 :OrigRefFillColour ‘=00=00=FF=00’ } {:Rectangle 20 :OrigBoxSize 335 263 :OrigPosition 370 10 :OrigRefFillColour ‘=FF=00=00=00’ } {:Rectangle 30 :OrigBoxSize 335 263 :OrigPosition 10 298 :OrigRefFillColour ‘=FF=FF=00=00’ } {:Rectangle 40 :OrigBoxSize 335 263 :OrigPosition 370 298 :OrigRefFillColour ‘=00=FF=00=00’ } {:Rectangle 17 :OrigBoxSize 325 253 :OrigPosition 15 15 :OrigLineWidth 3 :OrigRefLineColour ‘=BB=BB=BB=00’ } {:Text 5 :OrigContent ““ :OrigBoxSize 120 100 :OrigPosition 300 238 :FontAttributes ‘=00=1A=1A=00=00’ :TextColour ‘=FF=FF=FF=00’ :HJustification Centre :VJustification Centre } {:TokenGroup 6 // 1st 2nd 3rd 4th //up //down //left //right :MovementTable ( ( 1 2 1 2) ( 3 4 3 4) ( 1 1 3 3) ( 2 2 4 4) ) :TokenGroupItems ( (10 :ActionSlots ( ( :SetData ( 5 “Blue” ) ) ( :SetPosition ( 17 15 15 ) ) ) ) (20 :ActionSlots (
28
User Interaction - 4
© S&T 1997-1998
83| 84| 85| 86| 87| 88| 89| 90| 91| 92| 93| 94| 95| 96| 97| 98| 99| 100| 101| 102| 103| 104| 105| 106| 107| 108| 109| 110| 111| 112| 113| 114| 115| 116| 117| 118| 119| 120| 121| 122| 123| 124| 125| 126| 127| 128| 129| 130| 131| 132| 133| 134| 135| 136| 137| 138| 139| 140| 141| 142| 143| 144| 145| 146| 147| 148| 149| 150| 151| 152| 153| 154| 155| 156| 157| 158| 159| 160| 161| 162| 163| 164| 165| 166| 167|
( :SetData ( 5 “Red” ) ) ( :SetPosition ( 17 375 15 ) ) ) ) (30 :ActionSlots ( ( :SetData ( 5 ) ( :SetPosition ) ) ) (40 :ActionSlots ( ( :SetData ( 5 ) ( :SetPosition ) ) ) ) } {:Link 7 :EventSource 0 :EventType UserInput :EventData 100 :LinkEffect ( :MoveTo ( 6 2 ) :CallActionSlot ( 6 :CallActionSlot ( 6 ) } {:Link 8 :EventSource 0 :EventType UserInput :EventData 101 :LinkEffect ( :MoveTo ( 6 4 ) :CallActionSlot ( 6 :CallActionSlot ( 6 ) } {:Link 9 :EventSource 0 :EventType UserInput :EventData 102 :LinkEffect ( :MoveTo ( 6 3 ) :CallActionSlot ( 6 :CallActionSlot ( 6 ) } {:Link 100 :EventSource 0 :EventType UserInput :EventData 103 :LinkEffect ( :MoveTo ( 6 1 ) :CallActionSlot ( 6 :CallActionSlot ( 6 ) } {:Link 11 :EventSource 0 :EventType UserInput :EventData 1 :LinkEffect ( :Move ( 6 1 ) :CallActionSlot ( 6 )
“Yellow” ) ( 17 15 303 )
“Green” ) ( 17 375 303 )
1 ) 2 )
1 ) 2 )
1 ) 2 )
1 ) 2 )
2 )
User Interaction - 4
29
© S&T 1997-1998
168| 169| 170| 171| 172| 173| 174| 175| 176| 177| 178| 179| 180| 181| 182| 183| 184| 185| 186| 187| 188| 189| 190| 191| 192| 193| 194| 195| 196| 197| 198| 199| 200| 201| 202| 203| 204| 205| 206| 207| 208| 209| 210| 211| 212| 213| 214| 215| 216| 217| 218| 219| 220| 221| 222| 223| 224| 225| 226| 227| 228| 229|
} {:Link 12 :EventSource 0 :EventType UserInput :EventData 2 :LinkEffect ( :Move ( 6 2 ) :CallActionSlot ( 6 2 ) ) } {:Link 13 :EventSource 0 :EventType UserInput :EventData 3 :LinkEffect ( :Move ( 6 3 ) :CallActionSlot ( 6 2 ) ) } {:Link 14 :EventSource 0 :EventType UserInput :EventData 4 :LinkEffect ( :Move ( 6 4 ) :CallActionSlot ( 6 2 ) ) } {:Link 15 :EventSource 0 :EventType UserInput :EventData 15 :LinkEffect ( :CallActionSlot ( 6 1 ) ) } {:Link 16 :EventSource 0 :EventType UserInput :EventData 16 :LinkEffect ( :Quit ( ( “/startup” 0 ) ) ) } {:Link 18 :EventSource 0 :EventType UserInput :EventData 104 :LinkEffect ( :Quit ( ( “/startup” 0 ) ) ) } ) :InputEventReg 4 :SceneCS 720 576 }
30
User Interaction - 4
© S&T 1997-1998
7.2 Analysis
Table 8. User Interaction - 4 (/lesson7/startup & scene.mheg)
Lines 1 to 37
{:Rectangle 17 :Origboxsize 325 253 :Origposition 15 15 :OrigLineWidth 3 :OrigRefLinecolour ‘=BB=BB=BB=00’ }
As in Table 5 on page 16 This is the ‘highlighter’, the default fill colour is transparent. Here initial the line width and initial outline colour are defined. As in Table 5 on page 16
Lines 44 to 52
:TokenGroupItems ( (10 :ActionSlots ( (:SetData (5 “Blue”)) (:SetPosition (17 15 15)) ) ) (20 :ActionSlots ( (:SetData (5 “Red”)) (:SetPosition (17 375 15)) ) ) (30 :ActionSlots ( (:SetData (5 “Yellow”)) (:SetPosition (17 15 303)) ) ) (40 :ActionSlots ( (:SetData (5 “Green”)) (:SetPosition (17 375 303)) ) ) ) } {:Link 7 :EventSource 0 :EventType UserInput :EventData 100 :LinkEffect ( :MoveTo (6 2) :CallActionSlot(6 1) :CallActionSlot(6 2) ) }
A second ActionSlot is coded for each coloured rectangle. The ‘highlighter’, object 17 is given x and y positions in pixels according to which coloured rectangle currently holds the token,
The Links fired by User Input Events for colour keys are similar to those in Table 7 on page 25 but have and additional call to the second ActionSlot (which moves the highlight rectangle).
And Lines 101 to 133
{:Link 11 :EventSource 0 :EventType UserInput :EventData 1 :LinkEffect ( :Move (6 1) :CallActionSlot(6 2) ) }
The Links fired by User Input Events for cursor keys are similar to those in Table 7 on page 25 but have and additional call to the second ActionSlot (which moves the highlight rectangle).
And Lines 144 to 173 Lines 174 to 204 As in Table 7 on page 25
User Interaction - 4
31
© S&T 1997-1998
8 Push Buttons - 1
This example is very similar in structure to the previous one but uses numeric input instead of colour keys and uses push button objects and their built in highlight attribute instead of rectangles.
Introduces..
• • •
Numeric User Input Push Buttons Highlight Status
32
Push Buttons - 1
© S&T 1997-1998
8.1 Code Example
0 1| 2| 3| 4| 5| 6| 7| 8| 9| 10| 11| 12| 13| 14| 15| 16| 17| 18| 19| 20| 21| 22| 23| 24| 25| 26| 27| 28| 29| 30| 31| 32| 33| 34| 35| 36| 37| 38| 39| 40| 41| 42| 43| 44| 45| 46| 47| 48| 49| 50| 51| 52| 53| 54| 55| 56| 57| 58| 59| 60| 61| 62| 63| 64| 65| 66| 67| 68| 69| 70| 71| 72| 73| 74| 75| 76| 77| 78| 79| 80| 81| 82| {:Application (“/startup” 0) :Items ( {:Link 1 :EventSource 0 :EventType IsRunning :LinkEffect ( :TransitionTo ((“/scene.mheg” 0)) ) } ) :TextChook 10 :HighlightRefColour ‘=FF=FF=00=00’ :ButtonRefColour ‘=00=F0=F0=00’ :FontAttributes ‘=00=36=36=00=00’ } {:Scene (“/scene.mheg” 0) // a set of 4 pushbuttons // a text field for the result // cursor key driven events // number key driven events // key 1 :Items ( {:Link 1 //highlight default pushbutton :EventSource 0 :EventType IsRunning :LinkEffect ( :CallActionSlot ( 5 2 ) ) } {:PushButton 10 :OrigBoxSize 150 150 :OrigPosition 100 50 :OrigLabel “1” } {:PushButton 20 :OrigBoxSize 150 150 :OrigPosition 350 50 :OrigLabel “2” } {:PushButton 30 :OrigBoxSize 150 150 :OrigPosition 100 250 :OrigLabel “3” } {:PushButton 40 :OrigBoxSize 150 150 :OrigPosition 350 250 :OrigLabel “4” } {:Text 50 :OrigContent “-” :OrigBoxSize 100 100 :OrigPosition 10 150 } {:TokenGroup 5 :MovementTable ( ( 1 2 1 2) ( 2 2 4 4) ( 3 4 3 4) ( 1 1 3 3) ) :TokenGroupItems ( (10 :ActionSlots ( ( :SetHighlightStatus ( 10 false ) ) ( :SetHighlightStatus ( 10 true ) ) ( :SetData ( 50 “1” ) )
Push Buttons - 1
33
© S&T 1997-1998
83| 84| 85| 86| 87| 88| 89| 90| 91| 92| 93| 94| 95| 96| 97| 98| 99| 100| 101| 102| 103| 104| 105| 106| 107| 108| 109| 110| 111| 112| 113| 114| 115| 116| 117| 118| 119| 120| 121| 122| 123| 124| 125| 126| 127| 128| 129| 130| 131| 132| 133| 134| 135| 136| 137| 138| 139| 140| 141| 142| 143| 144| 145| 146| 147| 148| 149| 150| 151| 152| 153| 154| 155| 156| 157| 158| 159| 160| 161| 162| 163| 164| 165| 166| 167|
) ) (20 :ActionSlots ( ( :SetHighlightStatus ) ( :SetHighlightStatus ) ( :SetData ( 50 “2” ) ) ) ) (30 :ActionSlots ( ( :SetHighlightStatus ) ( :SetHighlightStatus ) ( :SetData ( 50 “3” ) ) ) ) (40 :ActionSlots ( ( :SetHighlightStatus ) ( :SetHighlightStatus ) ( :SetData ( 50 “4” ) ) ) ) ) :NoTokenActionSlots ( null null null ) } {:Link 60 //up :EventSource 0 :EventType UserInput :EventData 1 :LinkEffect ( :CallActionSlot ( 5 :Move ( 5 1 ) :CallActionSlot ( 5 ) } {:Link 70 //down :EventSource 0 :EventType UserInput :EventData 2 :LinkEffect ( :CallActionSlot ( 5 :Move ( 5 3 ) :CallActionSlot ( 5 ) } {:Link 80 //left :EventSource 0 :EventType UserInput :EventData 3 :LinkEffect ( :CallActionSlot ( 5 :Move ( 5 4 )
( 20 false ) ( 20 true )
( 30 false ) ( 30 true )
( 40 false ) ( 40 true )
1 ) 2 )
1 ) 2 )
1 )
34
Push Buttons - 1
© S&T 1997-1998
168| 169| 170| 171| 172| 173| 174| 175| 176| 177| 178| 179| 180| 181| 182| 183| 184| 185| 186| 187| 188| 189| 190| 191| 192| 193| 194| 195| 196| 197| 198| 199| 200| 201| 202| 203| 204| 205| 206| 207| 208| 209| 210| 211| 212| 213| 214| 215| 216| 217| 218| 219| 220| 221| 222| 223| 224| 225| 226| 227| 228| 229| 230| 231| 232| 233| 234| 235| 236| 237| 238| 239| 240| 241| 242| 243| 244| 245| 246| 247| 248| 249| 250| 251| 252|
:CallActionSlot ( 5 2 ) ) } {:Link 90 //right :EventSource 0 :EventType UserInput :EventData 4 :LinkEffect ( :CallActionSlot ( 5 1 ) :Move ( 5 2 ) :CallActionSlot ( 5 2 ) ) } {:Link 61 //key 1 :EventSource 0 :EventType UserInput :EventData 6 :LinkEffect ( :CallActionSlot ( 5 1 ) :MoveTo ( 5 1 ) :CallActionSlot ( 5 2 ) ) } {:Link 71 //key 2 :EventSource 0 :EventType UserInput :EventData 7 :LinkEffect ( :CallActionSlot ( 5 1 ) :MoveTo ( 5 2 ) :CallActionSlot ( 5 2 ) ) } {:Link 81 //key 3 :EventSource 0 :EventType UserInput :EventData 8 :LinkEffect ( :CallActionSlot ( 5 1 ) :MoveTo ( 5 3 ) :CallActionSlot ( 5 2 ) ) } {:Link 91 //key 4 :EventSource 0 :EventType UserInput :EventData 9 :LinkEffect ( :CallActionSlot ( 5 1 ) :MoveTo ( 5 4 ) :CallActionSlot ( 5 2 ) ) } {:Link 51 :EventSource 0 :EventType UserInput :EventData 15 :LinkEffect ( :CallActionSlot ( 5 3 ) ) } {:Link 52 :EventSource 0 :EventType UserInput :EventData 16 :LinkEffect ( :Quit ( ( “/startup” 0 ) ) ) } ) :InputEventReg 4 :SceneCS 720 576 }
Push Buttons - 1
35
© S&T 1997-1998
36
Push Buttons - 1
© S&T 1997-1998
8.2 Analysis
Table 9. Push Buttons - 1 (/lesson8/startup & scene.mheg)
Lines 1 to 13
:HighlightRefColour ‘=FF=FF=00=00’ :ButtonRefColour ‘=00=F0=F0=00’
As in Table 4 on page 12 These are the default highlight and fill colours for Push Buttons. As with font attributes, they can be defined in the Application object to become defaults and can also be defined within the Push Button object and thereby override defaults. As in Table 4 on page 12 The IsRunning event is fired when the scene and all contained objects have been prepared and activated. ActionSlot (5 2) causes the button object currently associated with the token to be highlighted.
Lines 16 to 21
{:Link 1 //highlight default pushbutton :EventSource 0 :EventType IsRunning :LinkEffect ( :CallActionSlot (5 2) ) } {:PushButton 10 :OrigBoxSize 150 150 :OrigPosition 100 50 :OrigLabel “1” } {:PushButton 20 :OrigBoxSize 150 150 :OrigPosition 350 50 :OrigLabel “2” } {:PushButton 30 :OrigBoxSize 150 150 :OrigPosition 100 250 :OrigLabel “3” } {:PushButton 40 :OrigBoxSize 150 150 :OrigPosition 350 250 :OrigLabel “4” } {:Text 50 :OrigContent “-” :OrigBoxSize 100 100 :OrigPosition 10 150 }
Define 4 push buttons and label them 1,2, 3 and 4.
This text object initially holds the string “-” but is overwritten with the value of the button that has been ‘pressed’.
Lines 56 to 65
(10 :ActionSlots ( (:SetHighlightStatus ( 10 false ) ) (:SetHighlightStatus ( 10 true ) ) (:SetData (50 “1”)) ) ) )
As in Table 7 on page 25
The logical values of highlight status will automatically display or hide a highlighter as defined by the engine.
And Lines 73 to 96
// cursor key driven events {:Link 60 :EventSource 0 :EventType UserInput :EventData 1 //up :LinkEffect ( :CallActionSlot (5 1) :Move (5 1) :CallActionSlot (5 2) ) } }
When the user inputs a cursor key three actions are performed: • action slot 1 is invoked to set the highlight status of the current button to ‘false’, • the token is moved according to the first row of the movement table, • action slot 2 is invoked to set the high light status of the current button to ‘true’ .
And Lines 109 to 141
Push Buttons - 1
37
© S&T 1997-1998 Table 9. Push Buttons - 1 (Continued)(/lesson8/startup & scene.mheg)
// number key driven events // key 1 {:Link 61 :EventSource 0 :EventType UserInput :EventData 6 //key 1 :LinkEffect ( :CallActionSlot (5 1) :MoveTo (5 1) :CallActionSlot (5 2) ) }
For the UK Profile, eventdata 5 to 14 signify number keys 0 to 9 respectively. When the user inputs a numeric key three actions are performed: • action slot 1 is invoked to set the highlight status of the current button to ‘false’, • the token is moved to the Push Button according to its position in the Token Group Items list, • action slot 2 is invoked to set the high light status of the current button to ‘true’ As in Table 7 on page 25
Lines 188 to 209
38
Push Buttons - 1
© S&T 1997-1998
9 Push Buttons - 2
This example introduces two new button styles and the code required to transition between scenes within an application. One scene is derived from the simple text scene of example 3, the other scene introduces the radio button and the check box styles of push button. Both scenes display the Global Text Object (MHEG Tutorial) defined in the application object. Radio buttons and check boxes are descended from the pushbutton that has been used previously. There is no difference in the functionality of these different styles of button - this has to be implemented in the MHEG-5 application. I.e. the application can allow check boxes to be toggled individually but must ensure that radio buttons are mutually exclusive. The MHEG-5 engine is responsible only for the appearance of the different button styles.
Introduces..
• •
Check Boxes and Radio Buttons Multi-scene Application
Push Buttons - 2
39
© S&T 1997-1998
9.1 Code Example
0 1| 2| 3| 4| 5| 6| 7| 8| 9| 10| 11| 12| 13| 14| 15| 16| 17| 18| 19| 20| 21| 22| 23| 24| 25| 26| 27| 28| 29| 30| 31| 32| 33| 34| 35| 36| 37| 38| 39| 40| 41| 42| 43| 44| 45| 46| 47| 48| 49| 50| 51| 52| 53| 54| 55| 56| 57| 58| 59| 60| 61| 62| 63| 64| 65| 66| 67| 68| 69| 70| 71| 72| 73| 74| 75| 76| 77| 78| 79| 80| 81| 82| {:Application (“/startup” 0) :Items ( {:Link 1 :EventSource 0 :EventType IsRunning :LinkEffect ( :TransitionTo ((“/scene1.mheg” 0)) ) } {:Text 2 :Origcontent “MHEG tutorial” :Shared True :Origboxsize 250 50 :Origposition 235 5 :FontAttributes ‘plain.36.36.500’ :TextColour ‘=FF=FF=FF=00’ :BackgroundColour ‘=FF=00=00=00’ :HJustification centre :VJustification centre } ) :TextCHook 10 :FontAttributes ‘plain.26.26.0’ :HighlightRefColour’=FF=FF=00=00’ } {:Scene (“/scene1.mheg” 0) // a button to go to the next page :Items ( {:Link 52 //highlight default tokengroup item :EventSource 0 :EventType IsRunning :LinkEffect ( :CallActionSlot ( 4 1 ) ) } {:Text 1 :OrigContent “Chapter 2” :OrigBoxSize 200 35 :OrigPosition 20 60 :FontAttributes “plain.31.31.0” :TextColour ‘=00=00=FF=00’ :HJustification start :VJustification start } {:Text 2 :OrigContent :ContentRef (“/Assets/1”) :OrigBoxSize 600 355 :OrigPosition 20 95 :FontAttributes “plain.26.26.0” :HJustification justified :VJustification start :TextWrapping true } {:Text 3 :OrigContent “Part of MHEG tutorial” :OrigBoxSize 370 35 :OrigPosition 200 400 :FontAttributes “plain.24.24.0” :HJustification end :VJustification centre } {:PushButton 10 :OrigBoxSize 150 40 :OrigPosition 20 400 :ButtonRefColour ‘=80=80=80=00’ :OrigLabel “Next page” } {:TokenGroup 4 :TokenGroupItems ( (10 :ActionSlots ( ( :SetHighlightStatus ( 10 true ) )
40
Push Buttons - 2
© S&T 1997-1998
83| 84| 85| 86| 87| 88| 89| 90| 91| 92| 93| 94| 95| 96| 97| 98| 99| 100| 101| 102| 103| 104| 105| 106| 107| 108| 109| 110| 111| 112| 113| 114| 115| 116| 117| 118| 119| 120| 121| 122| 123| 124| 125| 126| 127| 128| 129| 130| 131| 132| 133| 134| 135| 136| 137| 138| 139| 140| 141| 142| 143| 144| 145| 146| 147| 148| 149| 150| 151| 152| 153| 154| 155| 156| 157| 158| 159| 160| 161| 162| 163| 164| 165| 166| 167|
( :SetHighlightStatus ( 10 false ) ) ( :TransitionTo ( ( “/scene2.mheg” 0 ) ) ) ) ) ) } {:Link 100 //’select’ :EventSource 0 :EventType UserInput :EventData 15 :LinkEffect ( :CallActionSlot ( 4 3 ) ) } {:Link 51 :EventSource 0 :EventType UserInput :EventData 16 :LinkEffect ( :Quit ( ( “/startup” 0 ) ) ) } ) :InputEventReg 4 :SceneCS 720 576 } {:Scene (“/scene2.mheg” 0) // set of 3 radio buttons // set of 3 check boxes // button to change page // arrow events // do something when the ‘select’ is clicked :Items ( {:Link 52 // highlight default tokengroup item :EventSource 0 :EventType IsRunning :LinkEffect ( :CallActionSlot ( 8 1 ) ) } {:SwitchButton 1 :OrigBoxSize 150 25 :OrigPosition 50 120 :HighlightRefColour ‘=00=00=FF=00’ :ButtonRefColour ‘=FF=FF=00=00’ :OrigLabel “Radio Button 1” :ButtonStyle RadioButton } {:SwitchButton 2 :OrigBoxSize 150 25 :OrigPosition 50 170 :HighlightRefColour ‘=00=00=FF=00’ :ButtonRefColour ‘=FF=FF=00=00’ :OrigLabel “Radio Button 2” :ButtonStyle RadioButton } {:SwitchButton 3 :OrigBoxSize 150 25 :OrigPosition 50 220 :HighlightRefColour ‘=00=00=FF=00’ :ButtonRefColour ‘=FF=FF=00=00’ :OrigLabel “Radio Button 3” :ButtonStyle RadioButton } {:SwitchButton 4 :OrigBoxSize 150 25 :OrigPosition 250 120 :HighlightRefColour ‘=FF=00=00=00’ :ButtonRefColour ‘=00=FF=00=00’ :OrigLabel “Checkbox 1” :ButtonStyle checkbox } {:SwitchButton 5 :OrigBoxSize 150 25 :OrigPosition 250 170
Push Buttons - 2
41
© S&T 1997-1998
168| 169| 170| 171| 172| 173| 174| 175| 176| 177| 178| 179| 180| 181| 182| 183| 184| 185| 186| 187| 188| 189| 190| 191| 192| 193| 194| 195| 196| 197| 198| 199| 200| 201| 202| 203| 204| 205| 206| 207| 208| 209| 210| 211| 212| 213| 214| 215| 216| 217| 218| 219| 220| 221| 222| 223| 224| 225| 226| 227| 228| 229| 230| 231| 232| 233| 234| 235| 236| 237| 238| 239| 240| 241| 242| 243| 244| 245| 246| 247| 248| 249| 250| 251| 252|
:HighlightRefColour ‘=FF=00=00=00’ :ButtonRefColour ‘=00=FF=00=00’ :OrigLabel “Checkbox 2” :ButtonStyle checkbox } {:SwitchButton 6 :OrigBoxSize 150 25 :OrigPosition 250 220 :HighlightRefColour ‘=FF=00=00=00’ :ButtonRefColour ‘=00=FF=00=00’ :OrigLabel “Checkbox 3” :ButtonStyle checkbox } {:PushButton 7 :OrigBoxSize 150 40 :OrigPosition 20 400 :ButtonRefColour ‘=80=80=80=00’ :OrigLabel “Previous page” } {:TokenGroup 8 // 1 2 3 4 5 6 7 // up // down // left // right :MovementTable ( ( 3 1 2 6 4 5 ( 2 3 1 5 6 4 ( 7 7 7 1 2 3 ( 4 5 6 7 7 7 ) :TokenGroupItems ( (1 :ActionSlots ( ( :SetHighlightStatus ( 1 true ) ) ( :SetHighlightStatus ( 1 false ) ) ( :Select ( 1 ) :Deselect ( 2 ) :Deselect ( 3 ) ) ) ) (2 :ActionSlots ( ( :SetHighlightStatus ( 2 true ) ) ( :SetHighlightStatus ( 2 false ) ) ( :Select ( 2 ) :Deselect ( 3 ) :Deselect ( 1 ) ) ) ) (3 :ActionSlots ( ( :SetHighlightStatus ( 3 true ) ) ( :SetHighlightStatus ( 3 false ) ) ( :Select ( 3 ) :Deselect ( 1 ) :Deselect ( 2 ) ) ) ) (4 :ActionSlots (
7) 7) 1) 4)
42
Push Buttons - 2
© S&T 1997-1998
253| 254| 255| 256| 257| 258| 259| 260| 261| 262| 263| 264| 265| 266| 267| 268| 269| 270| 271| 272| 273| 274| 275| 276| 277| 278| 279| 280| 281| 282| 283| 284| 285| 286| 287| 288| 289| 290| 291| 292| 293| 294| 295| 296| 297| 298| 299| 300| 301| 302| 303| 304| 305| 306| 307| 308| 309| 310| 311| 312| 313| 314| 315| 316| 317| 318| 319| 320| 321| 322| 323| 324| 325| 326| 327| 328| 329| 330| 331| 332| 333| 334| 335| 336| 337|
( :SetHighlightStatus ( 4 true ) ) ( :SetHighlightStatus ( 4 false ) ) ( :Toggle ( 4 ) ) ) ) (5 :ActionSlots ( ( :SetHighlightStatus ( 5 true ) ) ( :SetHighlightStatus ( 5 false ) ) ( :Toggle ( 5 ) ) ) ) (6 :ActionSlots ( ( :SetHighlightStatus ( 6 true ) ) ( :SetHighlightStatus ( 6 false ) ) ( :Toggle ( 6 ) ) ) ) (7 :ActionSlots ( ( :SetHighlightStatus ( 7 true ) ) ( :SetHighlightStatus ( 7 false ) ) ( :TransitionTo ( ( “/scene1.mheg” 0 ) ) ) ) ) ) } {:Link 10 //up :EventSource 0 :EventType UserInput :EventData 1 :LinkEffect ( :CallActionSlot ( 8 :Move ( 8 1 ) :CallActionSlot ( 8 ) } {:Link 20 //down :EventSource 0 :EventType UserInput :EventData 2 :LinkEffect ( :CallActionSlot ( 8 :Move ( 8 2 ) :CallActionSlot ( 8 ) } {:Link 30 //left :EventSource 0 :EventType UserInput :EventData 3 :LinkEffect
2 ) 1 )
2 ) 1 )
Push Buttons - 2
43
© S&T 1997-1998
338| 339| 340| 341| 342| 343| 344| 345| 346| 347| 348| 349| 350| 351| 352| 353| 354| 355| 356| 357| 358| 359| 360| 361| 362| 363| 364| 365| 366| 367| 368| 369| 370| 371| 372| 373| 374| 375| 376| 377|
( :CallActionSlot ( 8 2 ) :Move ( 8 3 ) :CallActionSlot ( 8 1 ) ) } {:Link 40 //right :EventSource 0 :EventType UserInput :EventData 4 :LinkEffect ( :CallActionSlot ( 8 2 ) :Move ( 8 4 ) :CallActionSlot ( 8 1 ) ) } {:Link 50 :EventSource 0 :EventType UserInput :EventData 15 :LinkEffect ( :CallActionSlot ( 8 3 ) ) } {:Link 51 :EventSource 0 :EventType UserInput :EventData 16 :LinkEffect ( :Quit ( ( “/startup” 0 ) ) ) } ) :InputEventReg 4 :SceneCS 720 576 }
44
Push Buttons - 2
© S&T 1997-1998
9.2 Analysis
Table 10. Push Buttons - 2 (/lesson9/startup, scene1.mheg & scene2.mheg)
Lines 1 to 64
// a button to go to the next page {:PushButton 10 :OrigBoxSize 150 40 :OrigPosition 20 400 :ButtonRefColour ‘=80=80=80=00’ :OrigLabel “Next page” } {:TokenGroup 4 :TokenGroupItems ( (10 :ActionSlots ( (:SetHighlightStatus( 10 true )) (:SetHighlightStatus( 10 false )) (:TransitionTo ((“/scene2.mheg” 0))) ) ) ) } {:Link 100 :EventSource 0 :EventType UserInput :EventData 15 //’select’ :LinkEffect ( :CallActionSlot (4 3) ) }
As in Table 4 on page 12
Push button to access the other scene.
Three actions are associated with the push button; highlight, dehighlight and change scene.
Change scene when the select (enter/return) key is pressed.
Lines 93 to 116
{:SwitchButton 1 :OrigBoxSize 150 25 :OrigPosition 50 120 :OrigLabel “Radio Button 1” :HighlightRefColour’=00=00=FF=00’ :ButtonRefColour ‘=FF=FF=00=00’ :ButtonStyle RadioButton }
As in Table 9 on page 37
A set of three radio buttons arranged in a vertical line
And Lines 126 to 141
{:SwitchButton 4 :OrigBoxSize 150 25 :OrigPosition 250 120 :OrigLabel “Checkbox 1” :HighlightRefColour’=FF=00=00=00’ :ButtonRefColour ‘=00=FF=00=00’ :ButtonStyle checkbox }
A set of 3 checkboxes arranged in a vertical line.
And Lines 151 to 166
// button to change page {:PushButton 7 :OrigBoxSize 150 40 :OrigPosition 20 400 :ButtonRefColour ‘=80=80=80=00’ :OrigLabel “Previous page” }
Push button to access the other scene.
Lines 174 to 182
As in Table 7 on page 25
Push Buttons - 2
45
© S&T 1997-1998 Table 10. Push Buttons - 2 (/lesson9/startup, scene1.mheg & scene2.mheg)
:TokenGroupItems ( (1 :ActionSlots( (:SetHighlightStatus ( (:SetHighlightStatus ( (:Select (1) :Deselect (3)))) (2 :ActionSlots( (:SetHighlightStatus ( (:SetHighlightStatus ( (:Select (2) :Deselect (1)))) (3 :ActionSlots( (:SetHighlightStatus ( (:SetHighlightStatus ( (:Select (3) :Deselect (2))))
1 true) ) 1 false) ) (2) :Deselect 2 true) ) 2 false) ) (3) :Deselect 3 true) ) 3 false) ) (1) :Deselect
For each of the 7 token positions 3 actions are defined; • token arrives • token departs • user selects The token arrive/depart actions are in the same in each case (changing the high light status of the object so that the user can see where the token is). The select behaviour for a radiobutton is to deselect the other two buttons when one button becomes selected.
(4 :ActionSlots( (:SetHighlightStatus ( 4 true) ) (:SetHighlightStatus ( 4 false) ) (:Toggle (4)) ) )
The select behaviour for a checkbox is to toggle the selection status.
And Lines 151 to 166
(7 :Actionslots( (:SetHighlightStatus ( 7 true) ) (:SetHighlightStatus ( 7 false) ) (:TransitionTo ((“/scene1.mheg” 0))) ) ) ) }
The push button causes a transition to a different scene.
Lines 236 to 303
As in Table 6 on page 20
46
Push Buttons - 2
© S&T 1997-1998
10 Bitmaps - 1
This example demonstrates using bitmaps as custom buttons.
Introduces
• •
Bitmap Objects Changing Referenced Content
Bitmaps - 1
47
© S&T 1997-1998
10.1 Code example
0 1| 2| 3| 4| 5| 6| 7| 8| 9| 10| 11| 12| 13| 14| 15| 16| 17| 18| 19| 20| 21| 22| 23| 24| 25| 26| 27| 28| 29| 30| 31| 32| 33| 34| 35| 36| 37| 38| 39| 40| 41| 42| 43| 44| 45| 46| 47| 48| 49| 50| 51| 52| 53| 54| 55| 56| 57| 58| 59| 60| 61| 62| 63| 64| 65| 66| 67| 68| 69| 70| 71| 72| 73| 74| 75| 76| 77| 78| 79| 80| 81| 82| {:Application (“/startup” 0) :Items ( {:Link 1 :EventSource 0 :EventType IsRunning :LinkEffect ( :TransitionTo ((“/scene.mheg” 0)) ) } ) :TextCHook 10 } {:Scene (“/scene.mheg” 0) // a pair of bitmaps :Items ( {:Rectangle 8 :OrigBoxSize 720 576 :OrigPosition 1 0 :OrigRefFillColour ‘=80=80=80=00’ } {:Bitmap 1 :CHook 4 :OrigContent :ContentRef (“/assets/left_out.png”) :OrigBoxSize 92 112 :OrigPosition 50 50 } {:Bitmap 2 :CHook 4 :OrigContent :ContentRef (“/assets/right_out.png”) :OrigBoxSize 92 112 :OrigPosition 200 50 } {:TokenGroup 3 // 1st 2nd //left //right :MovementTable ( ( 1 1) ( 2 2) ) :TokenGroupItems ( (1 :ActionSlots ( ( :SetData ( 1 :NewRefContent ( “/assets/left_in.png” ) ) :SetData ( 1 :NewRefContent ( “/assets/left_out.png” ) ) ) ) ) (2 :ActionSlots ( ( :SetData ( 2 :NewRefContent ( “/assets/right_in.png” ) ) :SetData ( 2 :NewRefContent ( “/assets/right_out.png” ) ) ) ) ) ) } {:Link 4 //left :EventSource 0 :EventType UserInput :EventData 3 :LinkEffect ( :Move ( 3 1 ) ) } {:Link 5 //right :EventSource 0 :EventType UserInput :EventData 4
48
Bitmaps - 1
© S&T 1997-1998
83| 84| 85| 86| 87| 88| 89| 90| 91| 92| 93| 94| 95| 96| 97| 98| 99| 100| 101| 102| 103| 104| 105| 106| 107| 108| 109| 110| 111| 112| 113| 114| 115| 116| 117| 118| 119| 120|
:LinkEffect ( :Move ( 3 2 ) ) } {:Link 6 //enter :EventSource 0 :EventType UserInput :EventData 15 :LinkEffect ( :CallActionSlot ( 3 1 ) ) } {:Link 7 :EventSource 0 :EventType UserInput :EventData 16 :LinkEffect ( :Quit ( ( “/startup” 0 ) ) ) } {:Link 9 :EventSource 0 :EventType UserInput :EventData 104 :LinkEffect ( :Quit ( ( “/startup” 0 ) ) ) } ) :InputEventReg 4 :SceneCS 720 576 }
Bitmaps - 1
49
© S&T 1997-1998
10.2 Analysis
. Table 11. Bitmaps - 1 (/lesson10/startup & scene.mheg)
Lines 1 to 22
{:Bitmap 1 :CHook 4 :OrigContent :ContentRef (“/assets/left_out.png”) :OrigBoxSize 92 112 :OrigPosition 50 50 } {:Bitmap 2 :CHook 4 :OrigContent :ContentRef (“/assets/right_out.png”) :OrigBoxSize 92 112 :OrigPosition 200 50 }
As in Table 4 on page 12.
Bitmaps can be png or iFrame for UK Profile. The Content Hook value for png is 4.
Lines 36 to 42
:TokenGroupItems( (1 :ActionSlots( (:SetData (1 :NewRefContent (“/assets/left_in.png”)) :SetData (1 :NewRefContent (“/assets/left_out.png”))) ) ) (2 :ActionSlots( ( :SetData (2 :NewRefContent (“/assets/right_in.png”)) :SetData (2 :NewRefContent (“/assets/right_out.png”))) ) ) ) }
As in Table 4 on page 12
The referenced content will be changed when the user ‘presses’ the button.
Lines 63 to 111
As in Table 4 on page 12
50
Bitmaps - 1
© S&T 1997-1998
11 Bitmaps - 2
Png and i-Frame bitmaps have different capabilities in MHEG-5. i-Frames can be shown at full or 1/4 screen size, pngs cannot be scaled but can be temporarily ‘cropped’ by positioning and box size. Here a png is ‘cropped’ when the user presses the Switch Button.
Introduces..
• •
Changing Box Size of a Bitmap Switch Button
Bitmaps - 2
51
© S&T 1997-1998
11.1 Code Example
0 1| 2| 3| 4| 5| 6| 7| 8| 9| 10| 11| 12| 13| 14| 15| 16| 17| 18| 19| 20| 21| 22| 23| 24| 25| 26| 27| 28| 29| 30| 31| 32| 33| 34| 35| 36| 37| 38| 39| 40| 41| 42| 43| 44| 45| 46| 47| 48| 49| 50| 51| 52| 53| 54| 55| 56| 57| 58| 59| 60| 61| 62| 63| 64| 65| 66| 67| 68| 69| 70| 71| 72| 73| 74| 75| 76| 77| 78| 79| 80| 81| 82| {:Application (“/startup” 0) :Items ( {:Link 1 :EventSource 0 :EventType IsRunning :LinkEffect ( :TransitionTo ((“/scene.mheg” 0)) ) } ) :ButtonRefColour ‘=00=00=FF=00’ :HighLightRefColour ‘=FF=FF=00=00’ } {:Scene (“/scene.mheg” 0) // click button // effect of toggling button - changes display area of bitmap :Items ( {:Bitmap 1 :CHook 4 :OrigContent :ContentRef (“/ASSETS/Artist.png”) :OrigBoxSize 720 576 :OrigPosition 0 0 } {:SwitchButton 2 :OrigBoxSize 150 150 :OrigPosition 285 208 :OrigLabel “Part of Picture” :ButtonStyle pushbutton } {:Link 6 :EventSource 0 :EventType UserInput :EventData 15 :LinkEffect ( :Toggle ( 2 ) ) } {:Link 7 :EventSource 2 :EventType IsSelected :LinkEffect ( :SetLabel ( 2 “Big Picture” ) :SetBoxSize ( 1 300 225 ) ) } {:Link 8 :EventSource 2 :EventType IsDeselected :LinkEffect ( :SetLabel ( 2 “Part of Picture” ) :SetBoxSize ( 1 600 450 ) ) } {:Link 9 :EventSource 0 :EventType UserInput :EventData 16 :LinkEffect ( :Quit ( ( “/startup” 0 ) ) ) } {:Link 10 :EventSource 0 :EventType UserInput :EventData 104 :LinkEffect ( :Quit ( ( “/startup” 0 ) ) ) } ) :InputEventReg 4 :SceneCS 720 576 }
52
Bitmaps - 2
© S&T 1997-1998
11.2 Analysis
Table 12. Bitmaps - 2 (/lesson11/startup & scene.mheg)
Lines 1 to 18
{:Bitmap 1 :CHook 4 :OrigContent :ContentRef (“/assets/artist.png”) :OrigBoxSize 720 576 :OrigPosition 0 0 } {:SwitchButton 2 :OrigBoxsize 150 150 :OrigPosition 285 208 :OrigLabel “Part of Picture” :ButtonStyle pushbutton }
As in Table 9 on page 37
Display the file “artist.png” in a box with its upper-left corner being at (0, 0).
Create a switchbutton in the style of a pushbutton just below the bitmap, containing the text “Part of Picture”. Note that a SwitchButton in pushbutton style is different from a Pushbutton; the SwitchButton has a toggled ‘on’ /‘off’ state where as the PushButton might fire an action when selected but then returns to its previous, neutral state.
{:Link 6 :EventSource 0 :EventType UserInput :EventData 15 :LinkEffect ( :Toggle (2) ) } {:link 7 :EventSource 2 :EventType IsSelected :LinkEffect ( :SetLabel (2 “Big Picture”) :SetBoxSize (1 300 225) ) } {:Link 8 :EventSource 2 :EventType IsDeselected :LinkEffect ( :SetLabel (2 “Part of Picture”) :SetBoxSize (1 600 450) ) }
Respond to the ‘enter’/’return’ key by toggling the selection status of the pushbutton.
When the pushbutton toggles to selected then change the label on the pushbutton and the display area of the bitmap.
When the pushbutton toggles to deselected then change the label on the pushbutton and the display area of the bitmap.
Lines 60 to 81
As in Table 5 on page 16
Bitmaps - 2
53
© S&T 1997-1998
12 Bitmaps - 3
This example is not necessarily a recommended method for emulating animations, the bitmaps should be replaced in conjunction with timed events.
Introduces..
• • •
Timer Object Using Time for Eternal Loop Changing bitmap content to emulate an animation
54
Bitmaps - 3
© S&T 1997-1998
12.1 Code Example
0 1| 2| 3| 4| 5| 6| 7| 8| 9| 10| 11| 12| 13| 14| 15| 16| 17| 18| 19| 20| 21| 22| 23| 24| 25| 26| 27| 28| 29| 30| 31| 32| 33| 34| 35| 36| 37| 38| 39| 40| 41| 42| 43| 44| 45| 46| 47| 48| 49| 50| 51| 52| 53| 54| 55| 56| 57| 58| 59| 60| 61| 62| 63| 64| 65| 66| 67| 68| 69| 70| 71| 72| 73| 74| 75| 76| 77| 78| 79| 80| 81| 82| {:Application (“/startup” 0 ) :Items ( {:Link 1 :EventSource 0 :EventType IsRunning :LinkEffect ( :TransitionTo((“/scene.mheg”0)) ) } ) :TextCHook 10 } {:Scene (“/scene.mheg” 0) :Items ( {:Text 1 :OrigContent “MHEG-5 does not support animations Press Enter for more....” :OrigBoxSize 625 200 :OrigPosition 50 150 :FontAttributes “plain.36.38.0” :TextColour ‘=00=00=B0=00’ :BackgroundColour ‘=F0=F0=F0=00’ :TextWrapping true } {:Bitmap 2 :CHook 4 :OrigContent :ContentRef (“/assets/bfly1.png”) :OrigBoxSize 50 50 :OrigPosition 20 20 } {:Link 3 //enter :EventSource 0 :EventType UserInput :EventData 15 :LinkEffect ( :SetPosition ( 2 240 145 ) :SetTimer ( 0 9 100 ) ) } {:Link 6 //esc :EventSource 0 :EventType UserInput :EventData 16 :LinkEffect ( :Quit ( ( “/startup” 0 ) ) ) } {:Link 10 //TEXT :EventSource 0 :EventType UserInput :EventData 104 :LinkEffect ( :Quit ( ( “/startup” 0 ) ) ) } {:Link 8 :EventSource 0 :EventType TimerFired :EventData 9 :LinkEffect ( :SetTimer ( 0 9 500 ) :SetData ( 2 :NewRefContent ( “/assets/bfly2.png” ) ) :SetData ( 2 :NewRefContent ( “/assets/bfly3.png” ) ) :SetData ( 2 :NewRefContent ( “/assets/bfly4.png” ) ) :SetData ( 2 :NewRefContent ( “/assets/bfly5.png” ) ) :SetData ( 2 :NewRefContent ( “/assets/bfly6.png” ) ) :SetData ( 2 :NewRefContent ( “/assets/bfly7.png” ) ) :SetData ( 2 :NewRefContent ( “/assets/bfly8.png” ) ) :SetData ( 2 :NewRefContent ( “/assets/bfly1.png” ) ) ) } )
Bitmaps - 3
55
© S&T 1997-1998
83| 84| 85|
:InputEventReg 4 :SceneCS 720 576 }
56
Bitmaps - 3
© S&T 1997-1998
12.2 Analysis
Table 13. Bitmaps - 3 (/lesson12/startup & scene.mheg)
Lines 1 to 32
{:Bitmap 2 :CHook 4 :OrigContent :ContentRef (“/assets/bfly1.png”) :OrigBoxSize 50 50 :OrigPosition 20 20 } {:Link3 :EventSource0 :EventTypeUserInput :EventData15//enter :LinkEffect ( :SetPosition(2 240 145) :SetTimer (0 9 100) ) }
As in Table 4 on page 12
A bitmap is created, initially holding butterfly no. 1
When the user presses ‘enter’ the animation will start. A Timer created for the scene (0), given object number 9, and set to fire after 100 milliseconds.
Lines 43 to 60
{:Link 8 :EventSource 0 :EventType TimerFired :EventData 9 :LinkEffect ( :SetTimer (0 9 500 ) :SetData (2 :NewRefContent (“/assets/bfly2.png”)) :SetData (2 :NewRefContent (“/assets/bfly3.png”)) :SetData (2 :NewRefContent (“/assets/bfly4.png”)) :SetData (2 :NewRefContent (“/assets/bfly5.png”)) :SetData (2 :NewRefContent (“/assets/bfly6.png”)) :SetData (2 :NewRefContent (“/assets/bfly7.png”)) :SetData (2 :NewRefContent (“/assets/bfly8.png”)) :SetData (2 :NewRefContent (“/assets/bfly1.png”)) ) } )
As in Table 5 on page 16
When the timer fires set it to go off again, here it is set to fire after 500 milliseconds. Then change the content of the bitmaps in sequence. This link will be actioned every 500 (if the engine is capable!)
Lines 79 to 81
As in Table 5 on page 16
Bitmaps - 3
57
© S&T 1997-1998
13 Slider - 1
Sliders are a method for allowing the user to make “analogue” input. For example, this might be used to control the difficulty level of questions in a quiz or (when the UK Profile is extended to enable it) to provide viewer feedback when voting for a contestant.
Introduces..
• •
Interaction Status Slider Object
58
Slider - 1
© S&T 1997-1998
13.1 Code Example
0 1| {:Application (“/startup” 0) 2| :Items 3| ( 4| {:Link 1 5| :EventSource 0 6| :EventType IsRunning 7| :LinkEffect 8| ( 9| :TransitionTo ((“/scene.mheg” 0)) 10| ) 11| } 12| ) 13| :FontAttributes ‘=00=31=31=00=00’ 14| :TextCHook 10 15| } 16| 17| {:Scene (“/scene.mheg” 0) 18| :Items 19| ( 20| {:Slider 1 21| :OrigBoxSize 400 100 22| :OrigPosition 50 50 23| :Orientation left 24| :MaxValue 10 25| :MinValue 1 26| :InitialValue 5 27| :StepSize 1 28| :SliderStyle normal 29| :SliderRefColour ‘=80=80=80=00’ 30| } 31| {:Text 2 32| :OrigContent “Green key is coded in the application to set interaction status ON” 33| :OrigBoxSize 620 100 34| :OrigPosition 10 190 35| :TextColour ‘=00=FF=00=00’ 36| :TextWrapping true 37| } 38| {:Text 3 39| :OrigContent “The Engine defines what input will set interaction status OFF (e.g. Enter/Esc.)” 40| :OrigBoxSize 620 100 41| :OrigPosition 10 310 42| :TextWrapping true 43| } 44| {:Text 4 45| :OrigContent “UserInput events are ignored when the interaction status is ON” 46| :OrigBoxSize 620 100 47| :OrigPosition 10 430 48| :TextColour ‘=FF=00=00=00’ 49| :TextWrapping true 50| } 51| {:Link 5 52| //green 53| :EventSource 0 54| :EventType UserInput 55| :EventData 101 56| :LinkEffect 57| ( 58| :SetInteractionStatus ( 1 true ) 59| ) 60| } 61| {:Link 6 62| //red 63| // this never happens! 64| :EventSource 0 65| :EventType UserInput 66| :EventData 100 67| :LinkEffect 68| ( 69| :SetInteractionStatus ( 1 false ) 70| ) 71| } 72| {:Link 7 73| //Text toggle 74| :EventSource 0 75| :EventType UserInput 76| :EventData 104 77| :LinkEffect 78| ( 79| :Quit ( ( “/startup” 0 ) ) 80| ) 81| }
Slider - 1
59
© S&T 1997-1998
82| 83| 84| 85|
) :InputEventReg 3 :SceneCS 720 576 }
60
Slider - 1
© S&T 1997-1998
13.2 Analysis
Table 14. Slider - 1 (/lesson13/startup & scene.mheg)
Lines 1 to 18
{:Slider 1 :OrigBoxSize 400 100 :OrigPosition 50 50 :Orientation left :MaxValue 10 :MinValue 1 :InitialValue 5 :StepSize 1 :SliderStyle normal :SliderRefColour ‘=80=80=80=00’ }
As in Table 4 on page 12 Create a horizontal slider ranging over the values 1 to 10. The :Orientation direction defines the Minimum to Maximum values direction, i.e. when the slider is fully to the left it will have a value of 10, when fully to the right will have a value of 1. The :SliderStyle defines whether the slider value will be represented as a marker on the slide (normal), the slider appears filled to the value (thermometer) or the marker is given a specified width (proportional). The precise rendering of the slider is handled by the engine. Three text objects are defined, these are simply prompts and reminders.
Lines 30 to 49
{:Link 5 :EventSource 0 :EventType UserInput :EventData 101 //green :LinkEffect ( :SetInteractionStatus (1 true) ) } {:Link 6 :EventSource 0 :EventType UserInput :EventData 100 //red :LinkEffect ( :SetInteractionStatus (1 false) // this never happens! ) }
Make the slider “able to interact” when the ‘green’ key is pressed. This has no visible effect, but the slider will now respond to the left/right cursor keys.
This code will never be actioned; it is syntactically correct but all UserInput events are ignored while the InteractionStatus is true. The engine is responsible for toggling the InteractionStatus to false, this may be done using the escape key or the enter/ return key.
Lines 68 to 80
As in Table 2 on page 5
Slider - 1
61
© S&T 1997-1998
14 Slider - 2
In this example the value from the slider is used to set a global variable which is then displayed. Here the variables serve two purposes: they are used to convert numbers into textual information to allow them to be displayed, and, of more strategic importance, they hold state which can be acted on later, potentially changing the behaviour of the whole application.
Introduces..
• • •
Getting a value from a slider Using local variables Using global variables
62
Slider - 2
© S&T 1997-1998
14.1 Code Example
0 1| 2| 3| 4| 5| 6| 7| 8| 9| 10| 11| 12| 13| 14| 15| 16| 17| 18| 19| 20| 21| 22| 23| 24| 25| 26| 27| 28| 29| 30| 31| 32| 33| 34| 35| 36| 37| 38| 39| 40| 41| 42| 43| 44| 45| 46| 47| 48| 49| 50| 51| 52| 53| 54| 55| 56| 57| 58| 59| 60| 61| 62| 63| 64| 65| 66| 67| 68| 69| 70| 71| 72| 73| 74| 75| 76| 77| 78| 79| 80| 81| 82| {:Application (“/startup” 0) :Items ( {:Link 1 :EventSource 0 :EventType IsRunning :LinkEffect ( :TransitionTo ((“/scene.mheg” 0)) ) } {:IntegerVar 5 :OrigValue 23 } {:OstringVar 6 :OrigValue ‘23’ } ) :TextColour ‘=00=00=00=00’ :BackgroundColour ‘=00=00=FF=00’ :TextCHook 10 } {:Scene (“/scene.mheg” 0) :Items ( {:Slider 1 :OrigBoxSize 400 100 :OrigPosition 50 50 :Orientation right :MaxValue 92 :MinValue 1 :InitialValue 23 :InitialPortion 10 :StepSize 1 :SliderStyle proportional :SliderRefColour ‘=80=80=80=00’ } {:Link 2 :EventSource 0 :EventType IsRunning :LinkEffect ( :setinteractionstatus ( 1 true ) ) } {:Link 4 :EventSource 1 :EventType InteractionCompleted :LinkEffect ( :GetSliderValue ( 1 ( “/startup” 5 ) ) :SetVariable ( ( “/startup” 6 ) :GInteger :IndirectRef ( “/startup” 5 ) ) :SetData ( 7 :IndirectRef ( “/startup” 6 ) ) ) } {:Text 7 :OrigContent “23” :OrigBoxSize 100 100 :OrigPosition 500 52 :FontAttributes “plain.36.36.0” :BackgroundColour ‘=FF=FF=FF=00’ :HJustification centre :VJustification centre } {:Link 9 :EventSource 0 :EventType UserInput :EventData 16 :LinkEffect ( :Quit ( ( “/startup” 0 ) ) ) } {:Link 10 //TEXT :EventSource 0 :EventType UserInput :EventData 104 :LinkEffect ( :Quit ( ( “/startup” 0 ) )
Slider - 2
63
© S&T 1997-1998
83| 84| 85| 86| 87| 88|
) } ) :InputEventReg 4 :SceneCS 720 576 }
64
Slider - 2
© S&T 1997-1998
14.2 Analysis
Table 15. Slider - 2 (/lesson14/startup & scene.mheg)
Lines 1 to 42
{:Link 4 :EventSource 1 :EventType InteractionCompleted :LinkEffect ( :GetSliderValue ( 1 (“/startup” 5) ) :SetVariable ((“/startup” 6):GInteger :IndirectRef (“/startup” 5))
As in Table 14 on page 61. This link fires each time the user finishes interacting with the slider. 3 action are performed when the link fires: • The value on the slider is read into the global integer variable ‘5’ • The value in the global integer variable ‘5’ is copied into the global string variable ‘6’. This in effect “prints” the integer into the string variable. • The content data of the displayed text is updated to the value in the string variable. Note how there are two different forms of object reference. For objects within the same scene a short form is sufficient. For global objects held in the application object a long form of the reference is required that indicates where the object is. Hence :getslidervalue (1 (“~/startup” 5) ) means get the slider value from local object ‘1’ and place it in object ‘5’ in the object named ‘startup’.
:SetData (7 :IndirectRef (“/startup” 6)) ) }
A text object initialised to the value “23” and updated each time link 4 fires As in Table 4 on page 12
Lines 53 to 83
Slider - 2
65
© S&T 1997-1998
15 Dynamic Line Art
This example builds on the slider, using the value read from the slider to control the size of a piece of dynamic lineart. Whilst many Visible objects have limited “dynamic” facilities, for example, their size and position can be changed. Dynamic lineart provides a drawing area into which simple line graphics can be drawn at run-time. For example, arcs, ovals, polygons, rectangles and lines can be drawn where the parameters for these shapes are determined at run-time.
Introduces..
•
Dynamic Line Art
66
Dynamic Line Art
© S&T 1997-1998
15.1 Code Example
0 1| 2| 3| 4| 5| 6| 7| 8| 9| 10| 11| 12| 13| 14| 15| 16| 17| 18| 19| 20| 21| 22| 23| 24| 25| 26| 27| 28| 29| 30| 31| 32| 33| 34| 35| 36| 37| 38| 39| 40| 41| 42| 43| 44| 45| 46| 47| 48| 49| 50| 51| 52| 53| 54| 55| 56| 57| 58| 59| 60| 61| 62| 63| 64| 65| 66| 67| 68| 69| 70| 71| 72| 73| 74| 75| 76| 77| 78| 79| 80| 81| 82| {:Application (“/startup” 0) :Items ( {:Link 1 :EventSource 0 :EventType IsRunning :LinkEffect ( :TransitionTo ((“/scene.mheg” 0)) ) } ) :TextColour ‘=00=00=00=00’ :BackgroundColour ‘=FF=FF=FF=00’ :SliderRefColour ‘=80=80=80=00’ :TextCHook 10 } {:Scene (“/scene.mheg” 0) :Items ( {:Slider 1 :OrigBoxSize 250 100 :OrigPosition 50 300 :Orientation right :MaxValue 250 :MinValue 1 :InitialValue 23 :InitialPortion 10 :SliderStyle proportional } {:IntegerVar 55 :OrigValue 23 } {:OStringVar 66 :OrigValue “23” } {:Text 4 :OrigContent “23” :OrigBoxSize 200 100 :OrigPosition 350 300 :FontAttributes “plain.36.38.0” :BackgroundColour ‘=FF=FF=FF=00’ :HJustification centre :VJustification centre } {:DynamicLineArt 5 :OrigBoxSize 250 250 :OrigPosition 50 10 :BBBox false :OrigLineWidth 3 :OrigRefLineColour ‘=00=00=FF=00’ :OrigRefFillColour ‘=FF=FF=00=00’ } {:Link 2 :EventSource 0 :EventType IsRunning :LinkEffect ( :DrawOval ( 5 0 0 :IndirectRef 55 :IndirectRef 55 ) ) } {:Link 33 //left :EventSource 0 :EventType UserInput :EventData 3 :LinkEffect ( :Step ( 1 -10 ) :GetSliderValue ( 1 55 ) :SetVariable ( 66 :GInteger :IndirectRef 55 ) :SetData ( 4 :IndirectRef 66 ) :Clear ( 5 ) :DrawOval ( 5 0 0 :IndirectRef 55 :IndirectRef 55 ) ) } {:Link 3 //right :EventSource 0 :EventType UserInput :EventData 4
Dynamic Line Art
67
© S&T 1997-1998
83| 84| 85| 86| 87| 88| 89| 90| 91| 92| 93| 94| 95| 96| 97| 98| 99| 100| 101| 102| 103| 104| 105| 106| 107| 108| 109| 110| 111| 112| 113| 114| 115|
:LinkEffect ( :Step ( 1 10 ) :GetSliderValue ( 1 55 ) :SetVariable ( 66 :GInteger :IndirectRef 55 ) :SetData ( 4 :IndirectRef 66 ) :Clear ( 5 ) :DrawOval ( 5 0 0 :IndirectRef 55 :IndirectRef 55 ) ) } {:Link 6 :EventSource 0 :EventType UserInput :EventData 16 :LinkEffect ( :Quit ( ( “/startup” 0 ) ) ) } {:Link 7 //Text toggle :EventSource 0 :EventType UserInput :EventData 104 :LinkEffect ( :Quit ( ( “/startup” 0 ) ) ) } ) :InputEventReg 4 :SceneCS 720 576 }
68
Dynamic Line Art
© S&T 1997-1998
15.2 Analysis
Table 16. Dynamic Line Art (/lesson15/startup & scene.mheg)
Lines 1 to 45
{:DynamicLineArt 5 :BBBox false :OrigBoxSize 250 250 :Origposition 50 10 :OrigLineWidth 3 :OrigRefLineColour ‘=00=00=FF=00’ :OrigRefFillColour ‘=FF=FF=00=00’ } {:Link 2 :EventSource 0 :EventType IsRunning :LinkEffect ( :DrawOval(5 0 0 :IndirectRef 55 :IndirectRef 55) ) }
As in Table 15 on page 65
A Dynamic Line Art drawing area is defined. A Bounding Box (frame) is drawn by default unless set to false.
When the :IsRunning event is fired for the scene, draw an oval in the dynamic line art area specified as object number 5. The :DrawOval action will start the drawing at position 0 0 within the dynamic line art object. The width and the height of the oval are the value held in the integer variable object (no. 5) in the startup (application object). When the oval has been drawn set the interaction status ‘on’ for the slider.
{:Link 33 :EventSource 0 :EventType UserInput :EventData 3 //left :LinkEffect ( :Step (1 -10) :GetSliderValue ( 1 55) :SetVariable(66:GInteger :IndirectRef 55) :SetData(4 :IndirectRef 66) :Clear (5) :DrawOval (5 0 0 :IndirectRef 55 :IndirectRef 55) ) }
This link fires when the user presses the left arrow. The value of the slider is reduced by 10 and the slider value then read into the integer variable no. 55. This value is then transposed to a string variable and finally used to set the value of text object no. 4 in order to display the slider value.
Clear fills the drawing area with the fill colour. DrawOval will start the drawing at position 0 0 within the dynamic line art object.
The width and the height of the oval are the value held in the integer variable object (no. 5) in the startup (application object).
And Lines 76 to 89 Lines 90 to 101
{:Link 3 :EventSource 0 :EventType UserInput :EventData 4 //right :LinkEffect ( :Step (1 10) :GetSliderValue ( 1 55 ) :SetVariable(66:GInteger :IndirectRef 55) :SetData(4 :IndirectRef 66) :Clear (5) :DrawOval (5 0 0 :IndirectRef 55 :IndirectRef 55) ) }
As in Table 5 on page 16
As in Table 14 on page 61 and earlier in this except the additional :Clear and :DrawOval actions.
:Clear will remove any drawing in the dynamic lineart object area and refill the area with the :RefFillColour.
(:DrawOval described earlier in this table)
Lines 58 to 68
End of Dynamic Line art ???
As in Table 14 on page 61. This is a set of 7 buttons to navigate between 7 pages of text This is a text object initialised to show the first file of text The usual token mechanism
Lines 1to 66 Lines 68 to 75 Lines 76 to 83
Dynamic Line Art
69
© S&T 1997-1998
16 Paging in Assets - 1
The next two examples look at ways that one scene can present several different items of data to the user. This approach is an alternative to using several different scenes each delivering a single item of information. It has merits as the overhead for delivering the code required to manage the scene is only incurred once rather than N times. This approach also offers opportunities to improve page to page transition times.
Introduces..
70
Paging in Assets - 1
© S&T 1997-1998
16.1 Code Example
0 1| 2| 3| 4| 5| 6| 7| 8| 9| 10| 11| 12| 13| 14| 15| 16| 17| 18| 19| 20| 21| 22| 23| 24| 25| 26| 27| 28| 29| 30| 31| 32| 33| 34| 35| 36| 37| 38| 39| 40| 41| 42| 43| 44| 45| 46| 47| 48| 49| 50| 51| 52| 53| 54| 55| 56| 57| 58| 59| 60| 61| 62| 63| 64| 65| 66| 67| 68| 69| 70| 71| 72| 73| 74| 75| 76| 77| 78| 79| 80| 81| 82| {:Application (“/startup” 0) :Items ( {:Link 1 :EventSource 0 :EventType IsRunning :LinkEffect ( :TransitionTo ((“/scene.mheg” 0)) ) } ) :TextCHook 10 :FontAttributes ‘plain.26.26.0’ :ButtonRefColour ‘=FF=80=80=00’ :HighlightRefColour ‘=FF=FF=00=00’ } {:Scene (“/scene.mheg” 0) // a set of 7 pushbuttons // a text fields for the text to be displayed // cursor key driven events // left // right :Items ( {:Link 1 //highlight active button :EventSource 0 :EventType IsRunning :LinkEffect ( :CallActionSlot ( 5 2 ) ) } {:PushButton 10 :OrigBoxSize 40 40 :OrigPosition 35 10 :OrigLabel “1” } {:PushButton 20 :OrigBoxSize 40 40 :OrigPosition 85 10 :OrigLabel “2” } {:PushButton 30 :OrigBoxSize 40 40 :OrigPosition 135 10 :OrigLabel “3” } {:PushButton 40 :OrigBoxSize 40 40 :OrigPosition 185 10 :OrigLabel “4” } {:PushButton 50 :OrigBoxSize 40 40 :OrigPosition 235 10 :OrigLabel “5” } {:PushButton 60 :OrigBoxSize 40 40 :OrigPosition 285 10 :OrigLabel “6” } {:PushButton 70 :OrigBoxSize 40 40 :OrigPosition 335 10 :OrigLabel “7” } {:Text 110 :OrigContent :ContentRef (“/assets/1”) :OrigBoxSize 590 410 :OrigPosition 35 60 :HJustification justified :VJustification start :TextWrapping true } {:TokenGroup 5 :MovementTable ( ( 2 3 4 5 6 7
1)
Paging in Assets - 1
71
© S&T 1997-1998
83| 84| 85| 86| 87| 88| 89| 90| 91| 92| 93| 94| 95| 96| 97| 98| 99| 100| 101| 102| 103| 104| 105| 106| 107| 108| 109| 110| 111| 112| 113| 114| 115| 116| 117| 118| 119| 120| 121| 122| 123| 124| 125| 126| 127| 128| 129| 130| 131| 132| 133| 134| 135| 136| 137| 138| 139| 140| 141| 142| 143| 144| 145| 146| 147| 148| 149| 150| 151| 152| 153| 154| 155| 156| 157| 158| 159| 160| 161| 162| 163| 164| 165| 166| 167|
( 7 1 2 3 4 5 6) ) :TokenGroupItems ( (10 :ActionSlots ( ( :SetHighlightStatus ( 10 false ) ) ( :SetHighlightStatus ( 10 true ) :SetData ( 110 :NewRefContent ( “/assets/1” ) ) ) (20 :ActionSlots ( ( :SetHighlightStatus ( 20 false ) ) ( :SetHighlightStatus ( 20 true ) :SetData ( 110 :NewRefContent ( “/assets/2” ) ) ) (30 :ActionSlots ( ( :SetHighlightStatus ( 30 false ) ) ( :SetHighlightStatus ( 30 true ) :SetData ( 110 :NewRefContent ( “/assets/3” ) ) ) (40 :ActionSlots ( ( :SetHighlightStatus ( 40 false ) ) ( :SetHighlightStatus ( 40 true ) :SetData ( 110 :NewRefContent ( “/assets/4” ) ) ) (50 :ActionSlots ( ( :SetHighlightStatus ( 50 false ) ) ( :SetHighlightStatus ( 50 true ) :SetData ( 110 :NewRefContent ( “/assets/5” ) ) ) (60 :ActionSlots ( ( :SetHighlightStatus ( 60 false ) ) ( :SetHighlightStatus ( 60 true ) :SetData ( 110 :NewRefContent ( “/assets/6” ) ) ) (70 :ActionSlots ( ( :SetHighlightStatus ( 70 false ) ) ( :SetHighlightStatus ( 70 true ) :SetData ( 110 :NewRefContent ( “/assets/7”
) )
) )
) )
) )
) )
) )
) )
72
Paging in Assets - 1
© S&T 1997-1998
168| 169| 170| 171| 172| 173| 174| 175| 176| 177| 178| 179| 180| 181| 182| 183| 184| 185| 186| 187| 188| 189| 190| 191| 192| 193| 194| 195| 196| 197| 198| 199| 200| 201| 202| 203| 204| 205| 206| 207| 208| 209| 210| 211| 212| 213| 214| 215| 216| 217| 218| 219| 220| 221| 222|
) ) ) ) :NoTokenActionSlots ( null null ) } {:Link 80 :EventSource 0 :EventType UserInput :EventData 3 :LinkEffect ( :CallActionSlot ( 5 1 ) :Move ( 5 2 ) :CallActionSlot ( 5 2 ) ) } {:Link 90 :EventSource 0 :EventType UserInput :EventData 4 :LinkEffect ( :CallActionSlot ( 5 1 ) :Move ( 5 1 ) :CallActionSlot ( 5 2 ) ) } {:Link 100 :EventSource 0 :EventType UserInput :EventData 16 :LinkEffect ( :Quit ( ( “/startup” 0 ) ) ) } {:Link 1110 //TEXT :EventSource 0 :EventType UserInput :EventData 104 :LinkEffect ( :Quit ( ( “/startup” 0 ) ) ) } ) :InputEventReg 4 :SceneCS 720 576 }
Paging in Assets - 1
73
© S&T 1997-1998
16.2 Analysis
Table 17. Paging in Assets - 1 (/lesson16/startup & scene.mheg)
Lines 1 to 28
:TokenGroupItems ( (10 :ActionSlots ( (:SetHighlightStatus ( 10 false ) ) ( :SetHighlightStatus ( 10 true ) :SetData( 110 :NewRefContent ( “/assets/1” ) ) ) ) )
As in Table 9 on page 37
A Push Button is created for each page of assets and included in the Token Group List. For each different Push Button ‘pressed’, different text content will be referenced.
74
Paging in Assets - 1
© S&T 1997-1998
17 Paging in Assets - 2
This example has apparently the same visual appearance as the previous one. However, it encourages the engine to get all the text pages into memory and then shows them one at a time. In a broadcast environment this should give much faster responses if the receiver has sufficient memory and the broadcast file carousel is appropriately structured.
Introduces..
• •
Preload Running and Stopping Object
Paging in Assets - 2
75
© S&T 1997-1998
17.1 Code Example
0 1| 2| 3| 4| 5| 6| 7| 8| 9| 10| 11| 12| 13| 14| 15| 16| 17| 18| 19| 20| 21| 22| 23| 24| 25| 26| 27| 28| 29| 30| 31| 32| 33| 34| 35| 36| 37| 38| 39| 40| 41| 42| 43| 44| 45| 46| 47| 48| 49| 50| 51| 52| 53| 54| 55| 56| 57| 58| 59| 60| 61| 62| 63| 64| 65| 66| 67| 68| 69| 70| 71| 72| 73| 74| 75| 76| 77| 78| 79| 80| 81| 82| {:Application (“/startup” 0) :Items ( {:Link 1 :EventSource 0 :EventType IsRunning :LinkEffect ( :TransitionTo ((“/scene.mheg” 0)) ) } ) :TextCHook 10 :FontAttributes ‘=00=26=26=00’ :ButtonRefColour ‘=FF=80=80=00’ :HighlightRefColour ‘=FF=FF=00=00’ } {:Scene (“/scene.mheg” 0) :Items ( {:Link 1 :EventSource 0 :EventType IsRunning :LinkEffect ( :Preload ( 120 )// instruct receiver to start loading the :Preload ( 130 )// assets into memory ready for use :Preload ( 140 ) :Preload ( 150 ) :Preload ( 160 ) :Preload ( 170 ) :CallActionSlot (5 2)// make the default one of the buttons active ) } // a set of 7 pushbuttons {:PushButton 10 :OrigBoxSize 40 40 :OrigPosition 35 10 :OrigLabel “1” } {:PushButton 20 :OrigBoxSize 40 40 :OrigPosition 85 10 :OrigLabel “2” } {:PushButton 30 :OrigBoxSize 40 40 :OrigPosition 135 10 :OrigLabel “3” } {:PushButton 40 :OrigBoxSize 40 40 :OrigPosition 185 10 :OrigLabel “4” } {:PushButton 50 :OrigBoxSize 40 40 :OrigPosition 235 10 :OrigLabel “5” } {:PushButton 60 :OrigBoxSize 40 40 :OrigPosition 285 10 :OrigLabel “6” } {:PushButton 70 :OrigBoxSize 40 40 :OrigPosition 335 10 :OrigLabel “7” } // 7 co-located text fields for the text to be displayed // this text is displayed when the scene first appears // so must be prepared straight away {:Text 110 :InitiallyActive true :OrigContent :ContentRef (“/assets/1”) :OrigBoxSize 590 410 :OrigPosition 35 60 :HJustification justified :VJustification start :TextWrapping true }
76
Paging in Assets - 2
© S&T 1997-1998
83| 84| 85| 86| 87| 88| 89| 90| 91| 92| 93| 94| 95| 96| 97| 98| 99| 100| 101| 102| 103| 104| 105| 106| 107| 108| 109| 110| 111| 112| 113| 114| 115| 116| 117| 118| 119| 120| 121| 122| 123| 124| 125| 126| 127| 128| 129| 130| 131| 132| 133| 134| 135| 136| 137| 138| 139| 140| 141| 142| 143| 144| 145| 146| 147| 148| 149| 150| 151| 152| 153| 154| 155| 156| 157| 158| 159| 160| 161| 162| 163| 164| 165| 166| 167|
// these other text items are for display later // so can be prepared as we go along {:Text 120 :InitiallyActive false :OrigContent :ContentRef (“/assets/2”) :OrigBoxSize 500 300 :OrigPosition 50 100 :HJustification justified :VJustification start :TextWrapping true } {:Text 130 :InitiallyActive false :OrigContent :ContentRef (“/assets/3”) :OrigBoxSize 500 300 :OrigPosition 50 100 :HJustification justified :VJustification start :TextWrapping true } {:Text 140 :InitiallyActive false :OrigContent :ContentRef (“/assets/4”) :OrigBoxSize 500 300 :OrigPosition 50 100 :HJustification justified :VJustification start :TextWrapping true } {:Text 150 :InitiallyActive false :OrigContent :ContentRef (“/assets/5”) :OrigBoxSize 500 300 :OrigPosition 50 100 :HJustification justified :VJustification start :TextWrapping true } {:Text 160 :InitiallyActive false :OrigContent :ContentRef (“/assets/6”) :Origboxsize 500 300 :origposition 50 100 :hjustification justified :vjustification start :textwrapping true } {:Text 170 :InitiallyActive false :OrigContent :ContentRef (“/assets/7”) :OrigBoxSize 500 300 :OrigPosition 50 100 :HJustification justified :VJustification start :TextWrapping true } {:TokenGroup 5 :MovementTable ( ( 2 3 4 5 6 7 1 ) ( 7 1 2 3 4 5 6 ) ) :TokenGroupItems ( (10 :ActionSlots ( (:SetHighlightStatus ( 10 false ) :LockScreen((“/startup”0)) :Stop ( 110 )) (:SetHighlightStatus ( 10 true ) :Run ( 110 ) :UnLockScreen((“/startup”0))) ) ) (20 :ActionSlots ( (:SetHighlightStatus ( 20 false ) :LockScreen((“/startup”0)) :Stop ( 120 )) (:SetHighlightStatus ( 20 true ) :Run ( 120 ) :UnLockScreen((“/startup”0))) ) ) (30 :ActionSlots ( (:SetHighlightStatus ( 30 false ) :LockScreen((“/startup”0)):Stop ( 130 )) (:SetHighlightStatus ( 30 true ) :Run ( 130 ) :UnLockScreen((“/startup”0))) ) ) (40 :ActionSlots ( (:SetHighlightStatus ( 40 false ) :LockScreen((“/startup”0)):Stop ( 140 ))
Paging in Assets - 2
77
© S&T 1997-1998
168| 169| 170| 171| 172| 173| 174| 175| 176| 177| 178| 179| 180| 181| 182| 183| 184| 185| 186| 187| 188| 189| 190| 191| 192| 193| 194| 195| 196| 197| 198| 199| 200| 201| 202| 203| 204| 205| 206| 207| 208| 209| 210| 211| 212| 213| 214| 215| 216| 217| 218| 219| 220| 221| 222| 223| 224| 225| 226| 227| 228| 229| 230| 231| 232| 233| 234| 235| 236| 237|
(:SetHighlightStatus ( 40 true ) :Run ( 140 ) :UnLockScreen((“/startup”0))) ) ) (50 :ActionSlots ( (:SetHighlightStatus (:SetHighlightStatus ) ) (60 :ActionSlots ( (:SetHighlightStatus (:SetHighlightStatus ) ) (70 :ActionSlots ( (:SetHighlightStatus (:SetHighlightStatus ) ) ) :NoToKenActionSlots ( NULL NULL ) } // cursor key driven events {:Link 80 :EventSource 0 :EventType UserInput :EventData 3 //left :LinkEffect ( :CallActionSlot (5 1) :Move (5 2) :CallActionSlot (5 2) ) } {:Link 90 :EventSource 0 :EventType UserInput :EventData 4 //right :LinkEffect ( :CallActionSlot (5 1) :Move (5 1) :CallActionSlot (5 2) ) } {:Link 100 :EventSource 0 :EventType UserInput :EventData 16 :LinkEffect ( :Quit ((“/startup”0)) ) } {:Link 1111 :EventSource 0 :EventType UserInput :EventData 104 //TEXT :LinkEffect ( :Quit((“/startup”0)) ) } ) :InputEventReg 4 :SceneCS 720 576 }
( 50 false ) :LockScreen((“/startup”0)) :Stop ( 150 )) ( 50 true ) :Run ( 150 ) :UnLockScreen((“/startup”0)))
( 60 false ) :LockScreen((“/startup”0)):Stop ( 160 )) ( 60 true ) :Run ( 160 ) :UnLockScreen((“/startup”0)))
( 70 false ) :LockScreen((“/startup”0)):Stop ( 170 )) ( 70 true ) :Run ( 170 ) :UnLockScreen((“/startup”0)))
78
Paging in Assets - 2
© S&T 1997-1998
17.2 Analysis
Table 18. Paging in Assets - 2 (/lesson17/startup & scene.mheg)
Lines 1 to 26 As in Table 9 on page 37
:PreLoad requests the receiver to start loading the text files that might be required later.
Lines 27 to 35
:ActionSlot (5 2) causes the button object currently associated with the token to be highlighted.
7 pushbuttons 7 co-located text objects numbered 110 to 170. Only object 110 is initially visible. The token group mechanism Runs (makes visible for text objects) and Stops (makes invisible) objects as the token moves along the set of buttons.
Lines 36 to 70 Lines 71 to 138
Lines 141 to 229
Paging in Assets - 2
79
© S&T 1997-1998
18 Entry Field and Maths
This example introduces the Entry Field and simple maths to enable minutes and seconds to be calculated from elapsed time.
Introduces..
• •
Entry Field for typing in numbers Simple maths
80
Entry Field and Maths
© S&T 1997-1998
18.1 Code Example
0 1| 2| 3| 4| 5| 6| 7| 8| 9| 10| 11| 12| 13| 14| 15| 16| 17| 18| 19| 20| 21| 22| 23| 24| 25| 26| 27| 28| 29| 30| 31| 32| 33| 34| 35| 36| 37| 38| 39| 40| 41| 42| 43| 44| 45| 46| 47| 48| 49| 50| 51| 52| 53| 54| 55| 56| 57| 58| 59| 60| 61| 62| 63| 64| 65| 66| 67| 68| 69| 70| 71| 72| 73| 74| 75| 76| 77| 78| 79| 80| 81| 82| {:Application (“/startup” 0) :Items ( {:Link 1 :EventSource 0 :EventType IsRunning :LinkEffect ( :TransitionTo ((“/scene.mheg” 0)) ) } ) :FontAttributes ‘plain.31.33.0’ :TextCHook 10 } {:Scene (“/scene.mheg” 0) :Items ( {:EntryField 900 :CHook 10 :OrigContent ‘0’ :OrigBoxSize 150 75 :OrigPosition 95 50 :FontAttributes ‘plain.36.38.0’ :TextColour ‘=00=00=00=00’ :BackgroundColour ‘=FF=FF=00=00’ :EngineResp True :HighlightRefColour ‘=90=90=90=00’ :InputType Numeric } {:OStringVar 400 :OrigValue ““ } {:IntegerVar 20 // time :OrigValue 0 } {:IntegerVar 21 // seconds :OrigValue 0 } {:IntegerVar 22 // minutes :OrigValue 0 } {:OStringVar 31 :OrigValue ‘0’ } {:OStringVar 32 :OrigValue ‘0’ } {:Text 41 // seconds :OrigContent “0” :OrigBoxSize 200 350 :OrigPosition 320 50 :FontAttributes ‘plain.36.38.’ :HJustification end :VJustification centre } {:Text 42 // minutes :OrigContent “0” :OrigBoxSize 200 350 :OrigPosition 75 50 :FontAttributes ‘plain.36.38.0’ :HJustification end :VJustification centre } {:Text 43 :OrigContent “:” :OrigBoxSize 45 350 :OrigPosition 275 50 :FontAttributes ‘plain.36.38.0’ :HJustification centre :VJustification centre } {:Link 50 :EventSource 0 :EventType IsRunning :LinkEffect ( :SetTimer (0 1 1000 :AbsoluteTime True) :SetHighlightStatus(900 true) :SetInteractionStatus (900 true) :SetOverWriteMode (900 false) )
Entry Field and Maths
81
© S&T 1997-1998
83| 84| 85| 86| 87| 88| 89| 90| 91| 92| 93| 94| 95| 96| 97| 98| 99| 100| 101| 102| 103| 104| 105| 106| 107| 108| 109| 110| 111| 112| 113| 114| 115| 116| 117| 118| 119| 120| 121| 122| 123| 124| 125| 126| 127| 128| 129| 130| 131| 132| 133| 134| 135|
} {:Link 901 :EventSource 900 :EventType InteractionCompleted :LinkEffect ( :GetTextData (900 400) :SetVariable (20 :GInteger :IndirectRef 400) ) } {:Link 51 :EventSource 0 :EventType TimerFired :EventData 1 :LinkEffect ( :SetTimer (0 1 500 ) :Add ( 20 1 ) // seconds :SetVariable ( 21 :GInteger :IndirectRef 20 ) :Modulo ( 21 60 ) :SetVariable ( 31 :GInteger :IndirectRef 21 ) :SetData ( 41 :IndirectRef 31 ) // minutes :SetVariable ( 22 :GInteger :IndirectRef 20 ) :Divide ( 22 60 ) :SetVariable ( 32 :GInteger :IndirectRef 22 ) :SetData ( 42 :IndirectRef 32 ) ) } {:Link 52 :EventSource 0 :EventType UserInput :EventData 16 :LinkEffect ( :Quit((“/startup”0)) ) } {:Link 7 :EventSource 0 :EventType UserInput :EventData 104 //TEXT :LinkEffect ( :Quit((“/startup”0)) ) } ) :InputEventReg 4 :SceneCS 720 576 }
82
Entry Field and Maths
© S&T 1997-1998
18.2 Analysis
Table 19. Entry Field and Maths (/lesson18/startup & scene.mheg)
As in Table 1 on page 5 Integer variables to store the elapsed time, the number of seconds within the current minute and the number of minutes. Lines 1 to 18 Variables to hold the textual representation of the seconds and minutes. Text objects to display minutes, :, seconds
{:EntryField 900 :CHook 10 :OrigContent ‘0’ :OrigBoxSize 150 75 :OrigPosition 95 50 :TextColour ‘=00=00=00=00’ :BackgroundColour ‘=FF=FF=00=00’ :EngineResp True :HighlightRefColour ‘=90=90=90=00’ :InputType Numeric :FontAttributes ‘plain.36.38.0’ } {:Link 50 :EventSource 0 :EventType IsRunning :LinkEffect ( :SetTimer (0 1 1000 :AbsoluteTime True) :SetHighlightStatus(900 true) :SetInteractionStatus (900 true) :SetOverWriteMode (900 false) ) } {:Link 901 :EventSource 900 :EventType InteractionCompleted :LinkEffect ( :GetTextData (900 400) :SetVariable (20 :GInteger :IndirectRef 400) ) } {:Link 51 :EventSource 0 :EventType TimerFired :EventData 1 :LinkEffect ( :SetTimer (0 1 500 )
In UK Profile only numbers may be typed into an Entry Field.
Set a timer (number 1) to interrupt in 1000 ms
GetTextData is used to extract data from the entry field into a string so that it can be manipulated.
The value input in the entry field is now sent to the variable holding accumulated time.
Detect timer ‘1’ firing
Set the timer to go off again in 500 ms (should be 1000 ms, this runs clock at double speed for purpose of demonstration). Increment the recorded elapsed time
:Add ( 20 1 ) // seconds :SetVariable ( 21 :GInteger :IndirectRef 20 ) :Modulo ( 21 60 ) :SetVariable ( 31 :GInteger :IndirectRef 21 ) :SetData ( 41 :IndirectRef 31 ) // minutes :SetVariable ( 22 :GInteger :IndirectRef 20 ) :Divide ( 22 60 ) :SetVariable ( 32 :GInteger :IndirectRef 22 ) :SetData ( 42 :IndirectRef 32 ) ) }
Find the fractional minutes, convert to text then display. Find the number of whole minutes, convert to text then display.
Entry Field and Maths
83
© S&T 1997-1998
19 Testing Values
This example will display different bitmaps according to the content of a referenced text file.
Introduces..
• •
TestVariable Tiling Bitmaps
84
Testing Values
© S&T 1997-1998
19.1 Code Example
0 1| 2| 3| 4| 5| 6| 7| 8| 9| 10| 11| 12| 13| 14| 15| 16| 17| 18| 19| 20| 21| 22| 23| 24| 25| 26| 27| 28| 29| 30| 31| 32| 33| 34| 35| 36| 37| 38| 39| 40| 41| 42| 43| 44| 45| 46| 47| 48| 49| 50| 51| 52| 53| 54| 55| 56| 57| 58| 59| 60| 61| 62| 63| 64| 65| 66| 67| 68| 69| 70| 71| 72| 73| 74| 75| 76| 77| 78| 79| 80| 81| 82| {:Application (“/startup” 0) :Items ( {:Link 1 :EventSource 0 :EventType IsRunning :LinkEffect ( :TransitionTo ((“/scene.mheg” 0)) ) } ) :FontAttributes ‘plain.31.33.0’ :TextCHook 10 } {:Scene (“/scene.mheg” 0) :Items ( {:Text 1 :OrigContent “Today’s Weather “ :OrigBoxSize 600 100 :OrigPosition 60 10 :FontAttributes ‘plain.36.36.0’ :TextColour ‘=FF=FF=00=00’ :BackGroundColour ‘=80=00=80=00’ } {:Bitmap 2 :CHook 4 :OrigContent :ContentRef (“/assets/wet.png”) :OrigBoxSize 600 400 :OrigPosition 60 110 :Tiling True } {:Text 3 :OrigContent :ContentRef (“/assets/today.txt”) :OrigBoxSize 0 0 :OrigPosition 0 0 } {:OStringVar 4 :OrigValue ““ } {:Link 5 :EventSource 0 :EventType UserInput :EventData 15 //enter :LinkEffect ( :GetTextData(3 4) :TestVariable(4 1 :GOctetString “Sunny”) ) } {:Link 6 :EventSource 4 :EventType TestEvent :EventData True :LinkEffect ( :SetData (2 :NewRefContent (“/assets/sun.png”)) ) } {:Link 7 :EventSource 4 :EventType TestEvent :EventData False :LinkEffect ( :SetData (2 :NewRefContent (“/assets/wet.png”)) ) } {:Link 8 :EventSource 0 :EventType UserInput :EventData 16 :LinkEffect ( :Quit((“/startup”0)) ) } {:Link 777 :EventSource 0 :EventType UserInput :EventData 104 //Text toggle
Testing Values
85
© S&T 1997-1998
83| 84| 85| 86| 87| 88| 89| 90| 91| 92|
:LinkEffect ( :Quit((“/startup”0)) ) } ) :InputEventReg 4 :SceneCS 720 576 }
86
Testing Values
© S&T 1997-1998
19.2 Analysis
Table 20. Testing Values (lesson19/startup & scene.mheg)
{:Bitmap 2 :OrigBoxSize 600 400 :OrigPosition 60 110 :OrigContent :ContentRef (“/assets/wet.png”) :CHook 4 :Tiling True } {:Link 5 :EventSource 0 :EventType UserInput :EventData 15 //enter :LinkEffect ( :GetTextData(3 4) :TestVariable(4 1 :GOctetString “Sunny”) ) } {:Link 6 :EventType TestEvent :EventSource 4 :EventData True :LinkEffect ( :SetData (2 :NewRefContent (“/assets/sun.png”)) ) } {:Link 7 :EventType TestEvent :EventSource 4 :EventData False :LinkEffect ( :SetData (2 :NewRefContent (“/assets/wet.png”)) ) }
Tiling True will cause the bitmap image to be repeated within the declared Box size.
When the user presses ‘enter’ the text in the referenced text file is read into string variable no. 4. The test ‘4 = “Sunny”’ is carried out.
If the test on variable 4 was true then the bitmap content remains/ becomes ‘sun.png’
If the test on variable 4 was false then the bitmap content remains / becomes ‘rain.png’
Testing Values
87
© S&T 1997-1998
20 Substring Functions
There are a number of MHEG-5 functions (know as Resident Programs) that can be used to manipulate strings. In this example ‘Get SubString’ is used to extract a specific part of a string which is then used to control which bitmaps to display.
Introduces
• •
Resident Program Get SubString Append
88
Substring Functions
© S&T 1997-1998
20.1 Code Example
0 1| {:Application (“/startup” 0) 2| :Items 3| ( 4| {:Link 1 5| :EventSource 0 6| :EventType IsRunning 7| :LinkEffect 8| ( 9| :TransitionTo ((“/scene.mheg” 0)) 10| ) 11| } 12| ) 13| :FontAttributes ‘plain.31.33.0’ 14| :TextCHook 10 15| } 16| {:Scene (“/scene.mheg” 0) 17| :Items 18| ( 19| {:Text 1 20| :OrigContent “Today’s Weather “ 21| :OrigBoxSize 600 100 22| :OrigPosition 60 10 23| :FontAttributes ‘plain.36.36.0’ 24| :TextColour ‘=FF=FF=00=00’ 25| :BackGroundColour ‘=80=00=80=00’ 26| } 27| {:Bitmap 2 28| :CHook 4 29| :OrigContent :ContentRef (“/assets/wet.png”) 30| :OrigBoxSize 600 400 31| :OrigPosition 60 110 32| :Tiling True 33| } 34| {:Text 3 35| :OrigContent :ContentRef (“/assets/today.txt”) 36| :OrigBoxSize 0 0 37| :OrigPosition 0 0 38| } 39| {:OStringVar 4 //to hold contents of ‘today.txt’ 40| :OrigValue ““ 41| } 42| {:ResidentPrg 100 43| :Name “GSS” 44| } 45| {:BooleanVar 101 46| :OrigValue False 47| } 48| {:OStringVar 102 //to hold first return string 49| :OrigValue ““ 50| } 51| {:OStringVar 103 //to hold second return string 52| :OrigValue ““ 53| } 54| {:Link 5 55| :EventSource 0 56| :EventType UserInput 57| :EventData 15 //enter 58| :LinkEffect 59| ( 60| :LockScreen ((“/startup”0)) 61| :GetTextData(3 4) 62| :Call(100 101 :GOctetString :IndirectRef 4 :GInteger 1 :GInteger 13 :GOctetString :IndirectRef 102) 63| :GetTextData(1 103) 64| :Append (103 :IndirectRef 102) 65| :SetData(1 :IndirectRef 103) 66| 67| :Call(100 101 :GOctetString :IndirectRef 4 :GInteger 9 :GInteger 13 :GOctetString :IndirectRef 102) 68| :TestVariable(102 1 :GOctetString “Sunny”) 69| :UnlockScreen ((“/startup”0)) 70| ) 71| } 72| {:Link 6 73| :EventSource 102 74| :EventType TestEvent 75| :EventData True 76| :LinkEffect 77| ( 78| :SetData (2 :NewRefContent (“/assets/sun.png”)) 79| ) 80| }
Substring Functions
89
© S&T 1997-1998
81| 82| 83| 84| 85| 86| 87| 88| 89| 90| 91| 92| 93| 94| 95| 96| 97| 98| 99| 100| 101| 102| 103| 104| 105| 106| 107| 108| 109| 110| 111| 112|
{:Link 7 :EventSource 102 :EventType TestEvent :EventData False :LinkEffect ( :SetData (2 :NewRefContent (“/assets/wet.png”)) ) } {:Link 8 :EventSource 0 :EventType UserInput :EventData 16 :LinkEffect ( :Quit((“/startup”0)) ) } {:Link 777 :EventSource 0 :EventType UserInput :EventData 104 //Text toggle :LinkEffect ( :Quit((“/startup”0)) ) } ) :InputEventReg 4 :SceneCS 720 576 }
90
Substring Functions
© S&T 1997-1998
20.2 Analysis
Table 21. Substring Functions (lesson20/startup) (/lesson20/scene.mheg)
{:ResidentPrg 100 :Name “GSS” } {:BooleanVar 101 :OrigValue False } :LockScreen ((“/startup”0))
The GetSubstring function
Resident programs are always sent a boolean variable which will return whether running the program was successful or not This will freeze the screen so that the bitmaps to not flash of and on when changing. Call the ‘Get substring’ function, returning true/ false in var 101 depending on whether the function was successfully carried out or not. The string to search is held in variable no. 4. Substring from 1st char. to 13th char and return the selection in variable 102. The returned string value is appended to the orignal string ‘Today’s weather’ As above
:Call(100 101 :GOctetString :IndirectRef 4 :GInteger 1 :GInteger 13 :GOctetString :IndirectRef 102)
:Append (103 :IndirectRef 102) :Call(100 101 :GOctetString :IndirectRef 4 :GInteger 9 :GInteger 13 :GOctetString :IndirectRef 102)
Substring Functions
91
© S&T 1997-1998
21 String To Content Reference
In this example the file name of a bitmap to display is read in from a text file. In order to change the Type from string to Content Reference the Resident Program ‘Cast To Content Reference’ is invoked.
Introduces..
• •
Content Reference Variable Cast to Content Reference
92
String To Content Reference
© S&T 1997-1998
21.1 Code Example
0 1| {:Application (“/startup” 0) 2| :Items 3| ( 4| {:Link 1 5| :EventSource 0 6| :EventType IsRunning 7| :LinkEffect 8| ( 9| :TransitionTo ((“/scene.mheg” 0)) 10| ) 11| } 12| ) 13| :FontAttributes ‘plain.31.33.0’ 14| :TextCHook 10 15| } 16| // This intros CSC 17| {:Scene (“/scene.mheg” 0) 18| :Items 19| ( 20| //Constants 21| {:ResidentPrg 100 22| :Name “GSS” 23| } 24| {:ResidentPrg 104 25| :Name “CTC” 26| } 27| //Variables 28| {:OStringVar 4 //to hold contents of ‘today.txt’ 29| :OrigValue ““ 30| } 31| {:BooleanVar 101 32| :OrigValue False 33| } 34| {:OStringVar 102 //to hold first return string 35| :OrigValue ““ 36| } 37| {:OStringVar 103 //to hold second return string 38| :OrigValue ““ 39| } 40| {:ContentRefVar 105 41| :OrigValue :ContentRef “/assets/wet.png” 42| } 43| {:Text 1 44| :OrigContent “Today’s Weather “ 45| :OrigBoxSize 600 100 46| :OrigPosition 60 10 47| :FontAttributes ‘plain.36.36.0’ 48| :TextColour ‘=FF=FF=00=00’ 49| :BackGroundColour ‘=80=00=80=00’ 50| } 51| {:Bitmap 2 52| :CHook 4 53| :OrigContent :ContentRef (“/assets/wet.png”) 54| :OrigBoxSize 600 400 55| :OrigPosition 60 110 56| :Tiling True 57| } 58| {:Text 3 59| :OrigContent :ContentRef (“/assets/today.txt”) 60| :OrigBoxSize 0 0 61| :OrigPosition 0 0 62| } 63| {:Link 5 64| :EventSource 0 65| :EventType UserInput 66| :EventData 15 //enter 67| :LinkEffect 68| ( 69| :LockScreen ((“/startup”0)) 70| :GetTextData(3 4) 71| :Call(100 101 :GOctetString :IndirectRef 4 :GInteger 1 :GInteger 13 :GOctetString :IndirectRef 102) 72| :GetTextData(1 103) 73| :Append (103 :IndirectRef 102) 74| :SetData(1 :IndirectRef 103) 75| 76| :SetVariable(103 :GOctetstring “/assets/”) 77| :Call(100 101 :GOctetString :IndirectRef 4 :GInteger 14 :GInteger 20 :GOctetString :IndirectRef 102) 78| :Append(103 :IndirectRef 102) 79| :Call(104 101 :GOctetString :IndirectRef 103 :GContentRef :IndirectRef 105) 80| :SetData (2 :NewRefContent (:IndirectRef 105))
String To Content Reference
93
© S&T 1997-1998
81| 82| 83| 84| 85| 86| 87| 88| 89| 90| 91| 92| 93| 94| 95| 96| 97| 98| 99| 100| 101|
:UnlockScreen ((“/startup”0)) ) } {:Link 8 :EventSource 0 :EventType UserInput :EventData 16 :LinkEffect ( :Quit((“/startup”0)) ) } ) :InputEventReg 4 :SceneCS 720 576 }
94
String To Content Reference
© S&T 1997-1998
21.2 Analysis
Table 22. Cast to Content Ref (lesson21/startup & scene.mheg)
{:ResidentPrg 104 :Name “CTC” }
The CastToContentRef function
{:ContentRefVar 105 :OrigValue :ContentRef “/assets/wet.png” A variable designed to hold the path and name of a referenced } content object. :Call(100 101 :GOctetString :IndirectRef 4 :GInteger 1 :GInteger 13 :GObjectRef 102) :GetTextData(1 103)
Substring the portion that describes the weather, e.g. ‘Will be Sunny’ Put “Todays Weather “ into an OctetString Variable so the Append action can be performed on it. The substringed portion is append to form, e.g. “Todays Weather Will be Sunny” Put the string back into the Text object for display. Begin to build up a string that can become a Content Reference. Substring the portion that names the appropriate bitmap file. Add it to the path. Change the string to a content reference Use the newly created content reference to change to bitmap
:Append (103 :IndirectRef 102) :SetData(1 :IndirectRef 103) :SetVariable(103 :GOctetstring “/assets/”) :Call(100 101 :GOctetString :IndirectRef 4 :GInteger 14 :GInteger 20 :GObjectRef 102) :Append(103 :IndirectRef 102) :Call(104 101 :GOctetString :IndirectRef 103 :GObjectRef 105) :SetData (2 :NewRefContent (:IndirectRef 105))
String To Content Reference
95
© S&T 1997-1998
22 Topics not covered by these tutorials
Many but not all of the features of MHEG-5 have been included in these examples. This section presents a brief summary of other features that are available.
Objects
• HotSpots These can be described as invisible push buttons (they would normally be used in conjunction with a mouse). • ListGroups These can be used to present the user with a list of options. • Audio and Video
MHEG-5 scenes can include video as a background or scaled into a window within the scene. Similarly a broadcast audio stream can be played with its volume under control of an MHEG-5 scene. Streams can generate MHEG-5 events. This allows the behaviour of the MHEG content to be synchronised to AV media.
Actions
Activate, Add, AddItem, Append, BringToFront, Call, CallActionSlot, Clear, Clone, CloseConnection, Deactivate, DelItem, Deselect, DeselectItem, Divide, DrawArc, DrawLine, DrawOval, DrawPolygon, DrawPolyline, DrawRectangle, DrawSector, Fork, GetAvailabilityStatus, GetBoxSize, GetCellItem, GetCursorPosition, GetEngineSupport, GetEntryPoint, GetFillColour, GetFirstItem, GetHighlightStatus, GetInteractionStatus, GetItemStatus, GetLabel, GetLineColour, GetLineStyle, GetLineWidth, GetListItem, GetListSize, GetOverwriteMode, GetPortion, GetPosition, GetRunningStatus, GetSelectionStatus, GetSliderValue, GetTextContent, GetTextData, GetTokenPosition, GetVolume, Launch, LockScreen, Modulo, Move, MoveTo, Multiply, OpenConnection, Preload, PutBefore, PutBehind, Quit, ReadPersistent, Run, ScaleBitmap, ScaleVideo, ScrollItems, Select, SelectItem, SendEvent, SendToBack, SetBoxSize, SetCachePriority, SetCounterEndPosition, SetCounterPosition, SetCounterTrigger, SetCursorPosition, SetCursorShape, SetData, SetEntryPoint, SetFillColour, SetFirstItem, SetFontRef, SetHighlightStatus, SetInteractionStatus, SetLabel, SetLineColour, SetLineStyle, SetLineWidth, SetOverwriteMode, SetPaletteRef, SetPortion, SetPosition, SetSliderValue, SetSpeed, SetTimer, SetVariable, SetVolume, Spawn, Step, Stop, StorePersistent, Subtract, TestVariable, Toggle, ToggleItem, TransitionTo, Unload, UnlockScreen
96
Topics not covered by these tutorials