A powerful feature of MUI Royale is that it allows you to embed complete Hollywood displays inside your MUI GUIs using Hollywood class. Whenever you draw something to a Hollywood display that is attached to Hollywood class, it will automatically be drawn to your MUI GUI as well. You can even hide the Hollywood display so that the user does not even notice that Hollywood is running in the background. Furthermore, all mouse clicks and key strokes that happen inside Hollywood class will be forwarded to the corresponding Hollywood display as normal Hollywood events. Thus, Hollywood class allows you to use almost all of Hollywood's powerful features inside a MUI GUI as well.
Let's have a look at an example. The following code uses Hollywood class to embed a playing animation of size 320x200 inside a MUI GUI. For this, the Hollywood display's size is changed to 320x200 and then it is embedded in the MUI GUI using a MUI object of type Hollywood class. Here is the XML GUI declaration first:
<?xml version="1.0" encoding="iso-8859-1"?>
<application base="HOLIBRIDGE">
<window title="Hollywood bridge" muiid="MAIN" notify="closerequest">
<vgroup>
<hgroup>
<rectangle/>
<hollywood display="1"/>
<rectangle/>
</hgroup>
<hgroup>
<button id="play" notify="pressed">Play</button>
<button id="stop" notify="pressed">Stop</button>
</hgroup>
</vgroup>
</window>
</application>
|
Note that we use MUI objects of Rectangle class to pad the non-resizable Hollywood object. This is necessary for the GUI to stay resizable. Here is the code now that shows you to connect MUI and Hollywood:
@ANIM 1, "amy_walks.anim"
@DISPLAY {Width = 320, Height = 200, Hidden = True}
Function p_AnimFunc()
Local numframes = GetAttribute(#ANIM, 1, #ATTRNUMFRAMES)
curframe = Wrap(curframe + 1, 1, numframes + 1)
DisplayAnimFrame(1, 0, 0, curframe)
EndFunction
Function p_EventFunc(msg)
Switch msg.Class
Case "Window":
Switch msg.Attribute
Case "CloseRequest":
End
EndSwitch
Case "Button":
Switch msg.Attribute
Case "Pressed":
Switch msg.ID
Case "play":
SetInterval(1, p_AnimFunc, 50)
Case "stop":
ClearInterval(1)
EndSwitch
EndSwitch
EndSwitch
EndFunction
InstallEventHandler({MUIRoyale = p_EventFunc})
mui.CreateGUI(FileToString("GUI.xml"))
Repeat
WaitEvent
Forever
|
With a little bit more work we can also make the anim movable with the mouse. The user can then click into the Hollywood object and drag the anim around using his mouse. Here is the code for that:
@ANIM 1, "amy_walks.anim"
@DISPLAY {Width = 320, Height = 200, Hidden = True}
Function p_AnimFunc()
Local numframes = GetAttribute(#ANIM, 1, #ATTRNUMFRAMES)
curframe = Wrap(curframe + 1, 1, numframes + 1)
SelectBrush(1)
Cls
DisplayAnimFrame(1, offx, offy, curframe)
EndSelect
DisplayBrush(1, 0, 0)
EndFunction
Function p_MouseFunc()
If IsLeftMouse() = True
Local mx, my = MouseX(), MouseY()
If (grabx = -1) And (graby = -1) Then
grabx, graby = mx - offx, my - offy
offx = mx - grabx
offy = my - graby
Else
grabx, graby = -1, -1
EndIf
EndFunction
Function p_EventFunc(msg)
Switch msg.Class
Case "Window":
Switch msg.Attribute
Case "CloseRequest":
End
EndSwitch
Case "Button":
Switch msg.Attribute
Case "Pressed":
Switch msg.ID
Case "play":
SetInterval(1, p_AnimFunc, 50)
SetInterval(2, p_MouseFunc, 20)
Case "stop":
ClearInterval(1)
ClearInterval(2)
EndSwitch
EndSwitch
EndSwitch
EndFunction
CreateBrush(1, 320, 200)
InstallEventHandler({MUIRoyale = p_EventFunc})
mui.CreateGUI(FileToString("GUI8.xml"))
Repeat
WaitEvent
Forever
|
Finally, it is also possible to make the Hollywood object resizable by
specifying the attributes Hollywood.MinWidth, Hollywood.MinHeight,
Hollywood.MaxWidth, and Hollywood.MaxHeight.
Whenever the user resizes the MUI window, your Hollywood display will
receive a SizeWindow event that you can listen to using the
InstallEventHandler() Hollywood function. When using a resizable
Hollywood object, we can remove the two <rectangle> objects
used solely as padding space. The XML code looks like this then:
<?xml version="1.0" encoding="iso-8859-1"?>
<application base="HOLIBRIDGE">
<window title="Hollywood bridge" muiid="MAIN" notify="closerequest">
<vgroup>
<hollywood display="1" minwidth="32" minheight="32"
maxwidth="16384" maxheight="16384"/>
<hgroup>
<button id="play" notify="pressed">Play</button>
<button id="stop" notify="pressed">Stop</button>
</hgroup>
</vgroup>
</window>
</application>
|
Note that we specify 16384 for both Hollywood.MaxWidth and Hollywood.MaxHeight. This is to indicate that our Hollywood object doesn't really have a maximum size. That is why we set these two attribute to the maximum allowable size of 16384 pixels. This should be sufficiently large enough for most purposes.
Our code is pretty much the same as before with the exception that we
now have to handle the SizeWindow event to take care of
GUI resize events. Here is the adapted code from above:
@ANIM 1, "amy_walks.anim"
@DISPLAY {Width = 320, Height = 200, Hidden = True}
Function p_AnimFunc()
Local numframes = GetAttribute(#ANIM, 1, #ATTRNUMFRAMES)
curframe = Wrap(curframe + 1, 1, numframes + 1)
SelectBrush(1)
Cls
DisplayAnimFrame(1, offx, offy, curframe,
{Width = swidth, Height = sheight})
EndSelect
DisplayBrush(1, 0, 0)
EndFunction
Function p_MouseFunc()
If IsLeftMouse() = True
Local mx, my = MouseX(), MouseY()
If (grabx = -1) And (graby = -1) Then
grabx, graby = mx - offx, my - offy
offx = mx - grabx
offy = my - graby
Else
grabx, graby = -1, -1
EndIf
EndFunction
Function p_EventFunc(msg)
If msg.Action = "SizeWindow"
swidth = msg.Width
sheight = msg.Height
CreateBrush(1, swidth, sheight)
Return
EndIf
Switch msg.Class
Case "Window":
Switch msg.Attribute
Case "CloseRequest":
End
EndSwitch
Case "Button":
Switch msg.Attribute
Case "Pressed":
Switch msg.ID
Case "play":
SetInterval(1, p_AnimFunc, 50)
SetInterval(2, p_MouseFunc, 20)
Case "stop":
ClearInterval(1)
ClearInterval(2)
EndSwitch
EndSwitch
EndSwitch
EndFunction
swidth, sheight = 320, 200
CreateBrush(1, swidth, sheight)
InstallEventHandler({MUIRoyale = p_EventFunc, SizeWindow = p_EventFunc})
mui.CreateGUI(FileToString("GUI8.xml"))
Repeat
WaitEvent
Forever
|
From this example you can see that Hollywood class is really
quite powerful and can be used to achieve lots of innovative GUI ideas only limited
by your creativity. By the way, the example above is also included in the MUI Royale
distribution. You can find it in the drawer Examples/Hollywood.