[Android][mojo2]rotating device cuts screen

Holzchopf

Moderator
3rd Party Module Dev
Tutorial Author
Joined
Jul 31, 2017
Messages
496
Hi there

I stumbled across this problem: When I turn my mobile device, the screen "size" doesn't adapt properly. It looks like the output is limited to a window with the same dimension as before. It only happens in mojo2. This code demonstrates the problem
Code:
Strict

' set to false for mojo2
#If False
Import mojo
Const BG_COL:Int = 128
Const FG_COL:Int = 204
#Else
Import mojo2
Const BG_COL:Float = 0.5
Const FG_COL:Float = 0.8
#End

Global WIDTH:Int
Global HEIGHT:Int

' set to false for mojo2
#If False
#Else
    Global canvas:Canvas
#End

Class MyApp Extends App
    Method OnCreate:Int()
        ' set to false for mojo2
        #If False
            SetUpdateRate(60)
        #Else
            canvas = New Canvas
        #End
        Layout()
        Return 0
    End
   
    Method OnResize:Int()
        Layout()
        Return 0
    End
   
    Method Layout:Void()
        WIDTH = DeviceWidth()
        HEIGHT = DeviceHeight()
    End
   
    Method OnRender:Int()
        Local x:Float = (Millisecs() Mod 2000) / 2000.0 * WIDTH * 2
        ' set to false for mojo2
        #If False
            SetScissor(0, 0, WIDTH, HEIGHT)
            Cls(BG_COL, BG_COL, BG_COL)
            SetColor(FG_COL, FG_COL, FG_COL)
            DrawOval(x - WIDTH / 2, 0, WIDTH / 2, HEIGHT / 2)
            SetScissor(0, 0, WIDTH / 2, HEIGHT)
            DrawOval(x - WIDTH / 2, HEIGHT / 2, WIDTH / 2, HEIGHT / 2)
        #Else
            canvas.SetScissor(0, 0, WIDTH, HEIGHT)
            canvas.Clear(BG_COL, BG_COL, BG_COL)
            canvas.SetColor(FG_COL, FG_COL, FG_COL)
            canvas.DrawOval(x - WIDTH / 2, 0, WIDTH / 2, HEIGHT / 2)
            canvas.SetScissor(0, 0, WIDTH / 2, HEIGHT)
            canvas.DrawOval(x - WIDTH / 2, HEIGHT / 2, WIDTH / 2, HEIGHT / 2)
            canvas.Flush()
        #End
        Return 0
    End
End

Function Main:Int()
    New MyApp
    Return 0
End

The few comments help you to quickly switch between mojo and mojo2.

What am I missing? Is there a solution (other than using mojo ;) )?

Greetings
 

Holzchopf

Moderator
3rd Party Module Dev
Tutorial Author
Joined
Jul 31, 2017
Messages
496
I'm currently using this workaround:
In OnResize I create a new Canvas
Code:
canvas = New Canvas

Does anyone know, if this will lead to other problems? Mem leaks, uncontrollable lags..?
 

MikeHart

Administrator
Joined
Jun 19, 2017
Messages
3,168
If you don't keep creating one and reuse revious ones, i can't see why. I could not get Android studio to compile so i can't be of help.
 

Martin

Active member
CX Code Contributor
3rd Party Module Dev
Tutorial Author
Joined
Jun 19, 2017
Messages
334
I think this is the right way to do it. At least I do this for glfw as well. When the size changes the canvas currently doesn't adapt. Not sure if this is intended or a bug. Will check when I'm back. :)
 
Top Bottom