B4J Question Rotate Application 90 Degress

ElliotHC

Active Member
Licensed User
For ease of coding, I've laid out the App 1080 wide by 1920 tall. (Portrait)

All my references are based on those positions.

Now I need to run the App on a 1920*1080 display so I need to rotate everything to fit the screen, can anyone point me in the right direction?

Thanks
 

ElliotHC

Active Member
Licensed User
So my App is 1920*1080 but the screen is 1080*1920.. I will have the app window at 90 degrees and chopped off right?

How do I rotate it so it fills the screen sideways?
 
Upvote 0

ElliotHC

Active Member
Licensed User
That has rotated everything but now most of it is off screen, after the rotation do I need to re-position it?
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
@ElliotHC Do you mind posting some code how you made this work? I want to understand the way it works so I can implement it in my project.
The idea is to have the panel scroll in in random angles just like when lifting and adjusting a tablet in your hands. I believe it will look very tasteful.
 
Upvote 0

emexes

Expert
Licensed User
Are you thinking of doing something like this:

https://www.b4x.com/android/forum/t...entation-x-starting-point.107004/#post-669583

If you are, then you could try rotating the individual views, but they'll need to be squarish so that they can rotate in-place without disappearing off-screen or clobbering other nearby views.

What might work - and I haven't tried this, but you have above where you encountered "rotated everything but now most of it is off screen" - would be to have a single large background panel, that you resize to be either 1080 horizontal x 1920 vertical if you want portrait orientation, or 1920 horizontal x 1080 vertical if you want landscape orientation, and then load the layout in to it, where the layout file has two variants ie portrait and landscape, and rotate the panel 90 degrees if necessary.

Unless there is some way to override the Project Attributes Support Orientations setting to force portrait or landscape mode.

Hang on, doesn't Android do that already? As in: reload the layout and redo at least the Activity_Resume?

What is/are your Main : Region Project Attributes : #SupportedOrientations?

Do you have portrait and landscape variants in the layout file?
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
What I want is a rotation of the Mainform, since I am developing Athena in B4J so it's related to that. There's an image with buttons on top, to make it look like a tablet.
This scrolls up and down depending on mouse cursor, so that when the cursor touches the bottom of the screen the panel scrolls in, just like the old Sound blaster control panel at the top of the screen that Creative used years ago. I took the concept and turned it into a knowledge framework in B4J :) I remember Scene builder had options for rotating but I'm not sure how this is done through code. Please provide a basic example on how to rotate something. Can this be done from the core library in B4J (v7.51) or is there a library available for this? So my question is about B4J and not Android sorry, but since this post says B4J in the headline I posted it here.
Please take a look at the project I'm working on and you'll get the idea what I want to achieve. The rotation should only be performed when the panel scrolls up. I think that would look really nice. Athena is quite a massive project so it's not going to be released just yet but in a few month I hope to have it ready for release. Find it here
 
Upvote 0

emexes

Expert
Licensed User
since I am developing Athena in B4J
Sorry, sometimes I forget which forum I'm in. On the bright side, you could call my mixedupedness a confirmation of B4X cross-platform effectiveness ;-)

Ignore everything after "Hang on, doesn't Android do that already?"
 
Upvote 0

emexes

Expert
Licensed User
Righto, so as I understand it, you want to rotate the display 90 degrees so that text lines that used to be horizontal are now vertical? Is this the aim?

The actual Java window will remain 1920 tall by 1080 wide (= portrait HD TV) ?
 
Upvote 0

emexes

Expert
Licensed User
If this is the case, then:

- to run your program as it is now, in portrait mode, you would load your layout to a single 1080 wide x 1920 tall XUI panel, with the panel rotation set to 0 degrees.

- to run your program in landscape mode, you would load your layout to a single 1920 wide x 1080 tall XUI panel (should be able to reuse/resize the same panel as used for portrait mode), with the panel rotation set to 90 degrees (or -90 degrees or 270 degrees, depending on which way the user is looking at it).

I have done this in B4A but not B4J, but I'm pretty confident it will do the trick.
 
Upvote 0

emexes

Expert
Licensed User
I've been knocking up a demo for you, and... I know you may not see it as such, but this interim result is actually a good sign:

upload_2019-7-8_21-5-37.png
 
Upvote 0

emexes

Expert
Licensed User
Code attached. The purple panel in the background was to make sure that the layouts were displayed correctly. Curiosities are:

- I thought LoadLayout would select the appropriate variant depending on the the panel it was being loaded into, but that didn't seem to work. So I split Layout1 into two layouts, one with the portrait variant and one with the landscape variant (by Save As'ing the Layout1 master with two variants, into the two separate layouts, and then deleting the unused layout out of each of the two copies).

- The landscape panel has to be offset a bit to get it positioned correctly on the screen. I'll leave that for you to investigate.

For anyone who is interested, but not interested enough to unpack the attached project file and run it locally, the code that loads and rotates the panel looks like:
B4X:
Sub LoadLayoutToLandscape
 
    ScreenPanel.RemoveAllViews
    ScreenPanel.Width = 480
    ScreenPanel.Height = 270
    ScreenPanel.LoadLayout("Landscape") 'Load the layout file.
    ScreenPanel.Top = 105    'I have no idea why these offsets are required
    ScreenPanel.Left = -105    'but a clue is: 105 = half of 480 - 270
    ScreenPanel.Rotation = 90
 
    OrientationLabel.Text = "Landscape"
    OrientationLabel.RequestFocus    'remove focus from first button (set by LoadLayout?)
 
End Sub

Sub LoadLayoutToPortrait
 
    ScreenPanel.RemoveAllViews
    ScreenPanel.Width = 270
    ScreenPanel.Height = 480
    ScreenPanel.LoadLayout("Portrait") 'Load the layout file.
    ScreenPanel.Top = 0
    ScreenPanel.Left = 0
    ScreenPanel.Rotation = 0
 
    OrientationLabel.Text = "Portrait"
    OrientationLabel.RequestFocus    'remove focus from first button (set by LoadLayout?)

End Sub
 

Attachments

  • RotatePanel_B4J.zip
    5.4 KB · Views: 273
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
Thanks, and sorry that I should have been more specific again since it's not easy to read minds, especially mine!! :) What I mean is that, once the panel scrolls into the screen, then panel (mainform) should be turned in a let's say 10-45 degree angle, to either side for variation. So when the scrolling upward starts, the whole form should be turned in an angle and turn back to horizontal default, so that it gives the impression of lifting up a tablet (since it looks like it) to make it more realistic. We don't lift it up like a robot completely static and this is my idea with a bit 'angle animation', because it will look cool and more natural. Just like in a modern FPS game were the weapons and arms move around, it's all a visually animation trick and I want to try to do this with B4J. It works very well without rotation, but I want to see what it will look like.
So please attach a little example source would be cool, that shows a form and rotates it a bit, perhaps to the side 45 degrees and back, something like that we all can play around with and then I'll go from there.
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
MainForm.RootPane.rotation does not exist in B4J. I will check out your example after dinner. Meat pie, food for a Jedi programmer :D
 
Upvote 0

emexes

Expert
Licensed User
MainForm.RootPane.rotation does not exist in B4J.
Yeah, I was a bit surprised that the RootPane could be rotated. I expected it would be firmly bolted to the physical screen.

It seems that the Rotation property is not visible directly, and hence the cast to a temporary B4XView which is a compatible UI class that *does* expose the Rotation property:
B4X:
Dim x As B4XView = MainForm.RootPane
x.Rotation = 90
I haven't tried it but given that Erel suggested it and ElliotHC says it worked, that's good enough for me.

If it's any consolation, I often feel when reading Erel on programming, that I am on the receiving end of the Arthur C. Clarke saying: Any sufficiently advanced technology is indistinguishable from magic.

:)
 
Last edited:
Upvote 0
Top