Recent

Author Topic: Androids Relative Position/Dimension  (Read 7233 times)

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: Androids Relative Position/Dimension
« Reply #15 on: November 03, 2017, 11:18:08 am »
Can your CustomDrawn Android app run correctly on devices using Android 5 and above?
Hello Handoko,
thats a good question! I didn't know about that issue. And searching through the forum for that topic doesn't bring up an hint that it is solved or even worked on. I couldn't test as I don't have any Android 5 device by hands.

Quote from: Handoko
Have the CustomDrawn Android 5/+ issue been solved?
@all: Does someone know about it?

You can try to make a hello world demo and send the apk file file to this forum. Or you can email the apk file to me, I have an Android 5 phone.

About the screen issue, my module does not use scroll bars but it will scale it down. I will consider scrolling as an option, I started to write the module to solve screen output issue on different computer screen resolutions and aspect ratios.

So far the module now already has these working components:
- TgsRectangle
- TgsLabel
- TgsButton
- TgsEdit

All the visual components are inherited from TgsItem. On the object creation, it will automatically calculate its actual x, y positions:
Code: Pascal  [Select][+][-]
  1. constructor TgsItem.Create(const Screen: TGraphicsScreen; const X, Y, W, H: integer);
  2. begin
  3.   with Screen do
  4.   begin
  5.     FXint := X;
  6.     FXreal := X * FRatioX;
  7.     FYint := Y;
  8.     FYreal := Y * FRatioY;
  9.     FWint := W;
  10.     FWreal := W * FRatioX;
  11.     FHint := H;
  12.     FHreal := H * FRatioY;
  13.   end;
  14.   FFocusAllowed := False;
  15.   FFocusSupported := False;
  16.   FGraphicsScreen := Screen;
  17. end;

And to start using the module programmer has to call TGraphicsScreen.Create to initialize the position, size and resolution:
Code: Pascal  [Select][+][-]
  1. constructor TGraphicsScreen.Create(const Form: TForm;
  2.   const X, Y, W, H, ResolutionX, ResolutionY: integer);
  3. begin
  4.  
  5.   // Strict private data
  6.   //  FBackgroundR, FBackgroundG, FBackgroundB initialized by -> SetBackgroundColor
  7.   FCurrentFocus := nil;
  8.   FForm := Form;
  9.   with FForm do
  10.   begin
  11.     KeyPreview := True;
  12.     FSavedFormKeyDown := OnKeyDown;
  13.     FSavedFormKeyPress := OnKeyPress;
  14.     OnKeyDown := @EventFormKeyDown;
  15.     OnKeyPress := @EventFormKeyPress;
  16.   end;
  17.   FItems := TFPObjectList.Create(False);
  18.   FPainting := False;
  19.   FSavedApplicationUserInput := Application.OnUserInput;
  20.   FScreenHeight := ResolutionX;
  21.   FScreenWidth := ResolutionY;
  22.   FTargetTime := Now;
  23.  
  24.   // For items uniformity
  25.   FgsBorderThickness := 3;
  26.   FgsColorBackground := GetAllowedColor(clForm);
  27.   FgsColorBorder := GetAllowedColor(clWindowText);
  28.   FgsColorBorderFocus := GetAllowedColor(clHighlight);
  29.   FgsColorText := GetAllowedColor(clWindowText);
  30.  
  31.   // Main data
  32.   FOutput := TOpenGLControl.Create(Form);
  33.   with FOutput do
  34.   begin
  35.     ;
  36.     Left := X;
  37.     Top := Y;
  38.     Width := W;
  39.     Height := H;
  40.     Anchors := [akBottom] + [akLeft] + [akRight] + [akTop];
  41.     AutoResizeViewport := True;
  42.     MultiSampling := 4;
  43.     Parent := Form;
  44.     OnPaint := @EvenOpenGLControlPaint;
  45.     OnResize := @EvenOpenGLControl1Resize;
  46.   end;
  47.   FOutputAspect := W / H;
  48.   FRatioX := 2 / ResolutionX;
  49.   FRatioY := 2 / ResolutionY;
  50.  
  51.   // Additionals
  52.   SetBackgroundColor(FgsColorBackground);
  53.  
  54. end;

The code was actually originally written to run on Windows and Linux. But because it uses OpenGL for drawing and I already tried and know some basic of OpenGL ES2 drawing using LAMW, I'm sure with some modifications it can support Android too.
« Last Edit: November 03, 2017, 11:55:07 am by Handoko »

kupferstecher

  • Hero Member
  • *****
  • Posts: 583
Re: Androids Relative Position/Dimension
« Reply #16 on: November 03, 2017, 02:26:16 pm »
An interesting approach would be to use LAMW's jView+jcanvas instance as the form surface and implement a rendering engine  to draw the controls on this canvas. Plus creating event handling for the controls drawn there.
I guess thats not an easy task...

Quote from: CC
The android way of layouting makes sense,
In my opinion it should be distinguished between two app-types, one is the standard android app with relative layout, where the app is designed especially for smartphones. The other one is the LCL-approach for easy porting of Lazarus projects. Also for many hobbyist in my opinion it would be enough to use an absolut layout for an easier start, especially if the app only addresses the own hardware where screen dimensions are known. Tablets e.g. can be used as hardware for special applications and an absolute layout is quite well then.
Thats also the reason why I chose the CustomDrawn approach first.


You can try to make a hello world demo and send the apk file file to this forum. Or you can email the apk file to me, I have an Android 5 phone.
I'll send you a demo. More later, I'm busy now.

Part2:
uses OpenGL for drawing
Thanks for the code. I thought you use LAMW directly.
How I understand your project is that you somehow realize the smartphone layout on the desktop. I think it'd be great to compile the same GUI programm for desktop and smartphone. So keep us updated~
« Last Edit: November 03, 2017, 08:20:51 pm by kupferstecher »

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: Androids Relative Position/Dimension
« Reply #17 on: November 03, 2017, 09:38:33 pm »
I tested the code you sent me. It can't run on my Android 5 Intel-based phone. Almost ARM apps can run correctly on my phone (but suffer some performance penalty).
Here is the screenshot running the app after installed the apk you sent me:

kupferstecher

  • Hero Member
  • *****
  • Posts: 583
Re: Androids Relative Position/Dimension
« Reply #18 on: November 04, 2017, 10:36:18 am »
Thanks for testing! So seems that issue isn't solved. Good to know.


 

TinyPortal © 2005-2018