With the newest RapaGUI (and Hollywood Player for Android), the code that worked before has a couple problems now.
I found a workaround for one of the problems by delaying the first scaling using
SetTimeout(), though there's probably a better way of handling that. (See code below.)
However, the scaling isn't correct anymore after the screen is rotated. On my phone, the display in landscape becomes too short and the display in portrait becomes too long.
Code: Select all
@REQUIRE "RapaGUI", {ScaleHollywood = False}
@DISPLAY {Title="Test", Color=#WHITE, Layers=True, Width=600, Height=1920, ScaleMode=#SCALEMODE_LAYER, SmoothScale=True, Hidden=True, SingleMenu=True}
DesiredWidth=600
DesiredHeight=1920
CreateBrush(1, 600, 1920, #BLUE)
SetLineWidth(50)
SelectBrush(1)
Box(0, 0, 600, 1920, #RED)
Box(#CENTER, #CENTER, 400, 400, #RED)
EndSelect
DisplayBrush(1, 0, 0)
AppGUI$=[[<application id="app">
<window id="Main" notify="orientation">
<vgroup frame="true">
<hollywood id="HWDisplay" FixWidth="false" FixHeight="false" display="1"/>
</vgroup>
</window>
</application>]]
moai.CreateApp(AppGUI$)
Function p_RapaGUIEvents(msg)
Switch msg.attribute
Case "Orientation":
If moai.get("Main", "Orientation")="Portrait"
Local ScreenWidth, ScreenHeight
Repeat
ScreenWidth = moai.get("Main", "Width")
ScreenHeight = moai.get("Main", "Height")
VWait
Until ScreenHeight>ScreenWidth
ScreenHeight = ScreenHeight*ScaleFactor-DisplayScreenDiff
SetDisplayAttributes({ScaleWidth=100*(ScreenHeight/DesiredHeight) .. "%", ScaleHeight=100*(ScreenHeight/DesiredHeight) .. "%"})
ElseIf moai.get("Main", "Orientation")="Landscape"
Local ScreenWidth, ScreenHeight
Repeat
ScreenWidth = moai.get("Main", "Width")
ScreenHeight = moai.get("Main", "Height")
VWait
Until ScreenWidth>ScreenHeight
ScreenHeight = ScreenHeight*ScaleFactor-DisplayScreenDiff
SetDisplayAttributes({ScaleWidth=100*(ScreenHeight/DesiredHeight) .. "%", ScaleHeight=100*(ScreenHeight/DesiredHeight) .. "%"})
EndIf
EndSwitch
EndFunction
InstallEventHandler({RapaGUI=p_RapaGUIEvents})
Function p_FirstScale()
ScaleFactor=GetAttribute(#DISPLAY, 1, #ATTRHOSTSCALE)
Local TempVar=moai.get("Main", "Height")*ScaleFactor
Local ScreenHeight=GetAttribute(#DISPLAY, 1, #ATTRSCALEHEIGHT)
DisplayScreenDiff=TempVar-ScreenHeight
SetDisplayAttributes({ScaleWidth=100*(ScreenHeight/DesiredHeight) .. "%", ScaleHeight=100*(ScreenHeight/DesiredHeight) .. "%"})
EndFunction
SetTimeout(1, p_FirstScale, 100)
Repeat
WaitEvent
Forever