[Solved] How to add a new procedure to LAMW lazarus / 43-Android ---------------------------------------------------------------------- loaded · 2019-02-11 15:24 Hi everyone. I'm using the drawLine method below to draw lines on canvas in Lamw. But I want to draw the polygon shapes at once. I think the drawLines method is necessary for this. I have never been able to write a procedure that has worked in countless trials. How do I add the Drawlines method to Lamw? Thanks in advance to the friends who responded. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit And_jni_Bridge;   ....Procedure jCanvas_drawLine             (env:PJNIEnv;                                        Canv : jObject; x1,y1,x2,y2 : single); .... Procedure jCanvas_drawLine(env:PJNIEnv; Canv : jObject; x1,y1,x2,y2 : single);var _jMethod: jMethodID = nil; _jParams: Array[0..3] of jValue; cls: jClass;begin _jParams[0].F := x1; _jParams[1].F := y1; _jParams[2].F := x2; _jParams[3].F := y2; cls := env^.GetObjectClass(env, Canv); _jMethod:= env^.GetMethodID(env, cls, 'drawLine', '(FFFF)V'); env^.CallVoidMethod A(env,Canv,_jMethod,@_jParams); env^.DeleteLocalRef(env, cls);end; ---------------------------------------------------------------------- Handoko · 2019-02-11 18:25 You can see my glTest example code here: http://forum.lazarus.freepascal.org/index.php/topic,38777.msg264878.ht ml#msg264878 It draws rectangles with empty rectangle in the center of it. ---------------------------------------------------------------------- loaded · 2019-02-11 18:43 Handoko, thank you so much for answering. Health in your hands. I've reviewed the codes, too complex for the process I want to do, my goal is to easily draw polygons with 4 ~ 100 edges at one time. I think I can do this in a simple way with the drawLines command. I'd appreciate it if you could help me with that. ---------------------------------------------------------------------- Handoko · 2019-02-11 18:47 Currently I do not have LAMW properly installed. Hopefully you can get helps from others. I will check it back some days later. If you get no answer I will try JCanvas, which I haven't used before. ---------------------------------------------------------------------- balazsszekely · 2019-02-11 18:52 Maybe something similar works with LAMW too, you should give it a try: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  ATP : array of TPoint; procedure TForm1.FormCreate(Sender: TObject);begin  SetLength(ATP, 4);  ATP[0].X := 115; ATP[0].Y := 55;  ATP[1].X := 225; ATP[1].Y := 20;  ATP[2].X := 275; ATP[2].Y := 175;  ATP[3].X := 55;  ATP[3].Y := 130;end; procedure TForm1.FormPaint(Sender: TObject);begin  Canvas.Pen.Width := 2;  Canvas.Pen.Color := clBlack;  Canvas.Brush.Color := clRed;  Canvas.Polygon(ATP); end; ---------------------------------------------------------------------- loaded · 2019-02-11 19:16 GetMem, thank you very much for your reply. But as far as I know, the polygon method in LAMW does not have any unfortunately, the only way is the drawLines method. Quote from: Handoko on February 11, 2019, 07:47:55 pmCurrently I do not have LAMW properly installed. Hopefully you can get helps from others. I will check it back some days later. If you get no answer I will try JCanvas, which I haven't used before. Handoko brother, I am waiting for your reply. ---------------------------------------------------------------------- Handoko · 2019-02-12 08:23 I wrote a simple polygon with animation using JCanvas demo: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {Hint: save all files to location: /home/handoko/Desktop/JCanvasPolygon/LamwGUIProject1/jni }unit unit1; {$mode delphi} interface uses  Classes, SysUtils, AndroidWidget, Laz_And_Controls;  type   TPolygon = array of TPoint;   { TAndroidModule1 }   TAndroidModule1 = class(jForm)    jButton1: jButton;    jCanvas1: jCanvas;    jTimer1: jTimer;    jView1: jView;  procedure AndroidModule1Destroy(Sender: TObject);    procedure AndroidModule1JNIPrompt(Sender: TObject);    procedure jButton1Click(Sender: TObject);    procedure jTimer1Timer(Sender: TObject);    procedure jView1Draw(Sender: TObject);  private    FSquareX: Integer;    FSquareY: Integer;    FSquareS: Integer;    FSquareVeloX: Integer;    FSquareVeloY: Integer;    FTriangleX: Integer;    FTriangleY: Integer;    FTriangleVeloX: Integer;    FTriangleVeloY: Integer;    procedure DrawPoly(BorderColor: TARGBColorBridge; BorderWidth: Integer;      Points: TPolygon);  end; var  AndroidModule1: TAndroidModule1; implementation {$R *.lfm} { TAndroidModule1 } procedure TAndroidModule1.jView1Draw(Sender: TObject);var  Polygon: TPolygon;begin   // Draw Square  Polygon := TPolygon.Create(    Point(FSquareX-FSquareS, FSquareY-FSquareS),    Point(FSquareX+FSquareS, FSquareY-FSquareS),    Point(FSquareX+FSquareS, FSquareY+FSquareS),    Point(FSquareX- FSquareS, FSquareY+FSquareS));  DrawPoly(colbrGreen, 3, Polygon);   // Draw Triangle  Polygon := TPolygon.Create(    Point(FTriangleX,     FTriangleY-80),    Point(FTriangleX+100, FTriangleY+80),    Point(FTriangleX-100, FTriangleY+80));  DrawPoly(colbrRed, 3, Polygon); end; procedure TAndroidModule1.jButton1Click(Sender: TObject);begin  jTimer1.Enabled := not(jTimer1.Enabled);  case jTimer1.Enabled of    True  : jButton1.Text := 'Disable';    False : jButton1.Text := 'Animate';  end;end; procedure TAndroidModule1.jTimer1Timer(Sender: TObject);begin   // Animate Square  Inc(FSquareS);  if FSquareS > 200 then            FSquareS := 50;  if FSquareX <= 0  then            FSquareVeloX := abs(FSquareVeloX);  if FSquareX >= jView1.Width then  FSquareVeloX := -(abs(FSquareVeloX));  if FSquareY <= 0  then            FSquareVeloY := abs(FSquareVeloY);  if FSquareY >= jView1.Height then FSquareVeloY := -(abs(FSquareVeloY));  Inc(FSquareX, FSquareVeloX);  Inc(FSquareY, FSquareVeloY);   // Animate Triangle  if FTriangleX <= 0  then          FTriangleVeloX := Random(8)  +1;  if FTriangleX >= jView1.Width  then FTriangleVeloX := -Random(8) -1;  if FTriangleY <= 0  then          FTriangleVeloY := Random(8)  +1;  if FTriangleY >= jView1.Height then FTriangleVeloY := -Random(8) -1;  Inc(FTriangleX, FTriangleVeloX);  Inc(FTriangleY, FTriangleVeloY);   // Update the canvas  jView1.Refresh; end; procedure TAndroidModule1.AndroidModule1Destroy(Sender: TObject);begin  jTimer1.Enabled := False;end; procedure TAndroidModule1.AndroidModule1JNIPrompt(Sender: TObject);begin   // Initialize Square  FSquareX     := (jView1.Width div 2) -100;  FSquareY     := jView1.Height div 2;  FSquareS     := 50;  FSquareVeloX := Random(8) +1;  FSquareVeloY := Random(8) +1;   // Initialize Triangle  FTriangleX     := (jView1.Width div 2) +100;  FTriangleY     := jView1.Height div 2;  FTriangleVeloX := Random(8) +1;  FTriangleVeloY := Random(8) +1; end; procedure TAndroidModule1.DrawPoly(BorderColor: TARGBColorBridge;  BorderWidth: Integer; Points: TPolygon);var  i: Integer;begin  jView1.Canvas.PaintColor       := BorderColor;  jView1.Canvas.PaintStrokeWidth := BorderWidth;  // Connect all the points from first to last  for i := Low(Points) to High(Points)-1 do  jCanvas1.drawLine(Points[i].x, Points[i].y, Points[i+1].x, Points[i+1].y);  // Connect last point with first point  i := High(Points);  jView1.Canvas.drawLine(Points[i].X, Points[i].Y, Points[0].X, Points[0].Y);end; end. I created a procedure to do polygon drawing, see DrawPoly see line #130. To use DrawPoly, see lines #55..#68. Due to the limitation of maximum total post size, the apk file can be found on the next post. ---------------------------------------------------------------------- Handoko · 2019-02-12 08:27 This is the install-able apk file: ---------------------------------------------------------------------- loaded · 2019-02-12 15:50 Handoko, thank you so much for your answer. Health in your hands, the program you wrote is very good. But, the solution is available, I'm already using a similar solution. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var   pol_coor:array of TPoint;  ans:integer; begin       .....          for ans:=low(pol_coor) to High(pol_coor)-1 do          begin               jView1.Canvas.drawLine(pol_coor[ans].X,pol_coor[ans].Y,pol_coor[ans+ 1].X,pol_coor[ans+1].Y);          end;         jView1.Canvas.drawLine( pol_coor[High(pol_coor)].X,pol_coor[High(pol_coor)].Y,pol_coor[0].X,po l_coor[0].Y);....  But what I want, instead of drawing the edges one by one, is the direct drawing method which is much faster than the above. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i jview1.canvas.drawlines (pol_coor); That is, polygon object with direct operating system boot. my experience on windows canvas is that drawing polygons at once is much simpler and faster than drawing their edges one at a time. I want, accessing the Java Local Interface, with Lazarus Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i _jMethod: = env ^ .GetMethodID (env, cls, 'drawLines', '????????');use the method ---------------------------------------------------------------------- Handoko · 2019-02-12 15:55 I'm not familiar with Java things. Be patient, the developer of LAMW checks this forum regularly. He will answer your question. ---------------------------------------------------------------------- loaded · 2019-02-12 16:30 Yes, you're right. I hope the precious developer will add this feature. ---------------------------------------------------------------------- jmpessoa · 2019-02-13 10:23 Done!! Added to jCanvas:     function GetNewPath(var _points: TDynArrayOfSingle): jObject; overload;     function GetNewPath(_points: array of single): jObject;  overload;     procedure DrawPath(var _points: TDynArrayOfSingle);  overload;     procedure DrawPath(_points: array of single);  overload;     procedure DrawPath(_path: jObject);  overload;     Edited: +1     procedure DrawArc(_leftRectF: single; _topRectF: single; _rightRectF: single; _bottomRectF: single; _startAngle: single; _sweepAngle: single; _useCenter: boolean); how to use: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  path: jObjectRef;  w1, h1: integer;begin     w1:= jMyView.Width;   h1:= jMyView.Height;    //Frame   path:= jDrawingView1.GetNewPath([                              0,0,               //p1                              0,h1-1,         //p2                                w1-1,h1-1, //p3                                w1-1,0,         //p4                              0,0                 //p1                              ]);    jDrawingView1.DrawPath(path); end;  But,  "jDrawingView"  is much better supported! Please,  go to demo "AppDrawingViewDemo1" ---------------------------------------------------------------------- loaded · 2019-02-13 12:35 jmpessoa, thank you very much.