• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

[Android][mojo2]rotating device cuts screen

Holzchopf

Well-known member
3rd Party Module Dev
Tutorial Author
Joined
Jul 31, 2017
Messages
500
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
 
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..?
 
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.
 
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. :)
 
Back
Top Bottom