Recent

Author Topic: NoGUIGraphicsBridge  (Read 2919 times)

jmpessoa

  • Hero Member
  • *****
  • Posts: 2301
NoGUIGraphicsBridge
« on: April 19, 2015, 03:56:55 am »
Hi All,

I am sharing some news components/packages:

TFPNoGuiGraphicsBridge ver.  0.1 - 18 April - 2015

https://github.com/jmpessoa/tfpnoguigraphicsbridge

Quote
   "A wrapper over Free Pascal fcl-image ref. http://wiki.freepascal.org/fcl-image"

   "FPImage (fcl-image) draw images which won't be displayed in the screen [NoGUI !!!].
   A program, for example, running on a webserver without X11 could benefit from
   not having a visual library as a dependency." ref. http://wiki.freepascal.org/Developing_with_Graphics

TFPDxfBridge - ver. 0.1 - 18 April - 2015

https://github.com/jmpessoa/tfpdxfbridge

Quote
   "TFPDxfWriterBridge is an DXF format writer for Free Pascal"

You can know more reading the "readme.txt"

At the moment there are two very basic Apps demos:

AppTFPNoGUIGraphicsBridgeDemo1 [Android/Lamw project] 

and

tfpnoguigraphicsbridge_demo1 [Windows]

You can  see in Attachments the Screenshots [android and win]...

Thanks to All!
« Last Edit: April 20, 2015, 12:06:08 am by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: TFPNoGUIGraphicsBridge
« Reply #1 on: April 19, 2015, 05:07:47 pm »
Wooohooo!!! A cartesian graph on Android! :D

jmpessoa

  • Hero Member
  • *****
  • Posts: 2301
Re: TFPNoGUIGraphicsBridge
« Reply #2 on: April 19, 2015, 05:55:23 pm »
Quote
Wooohooo!!! A cartesian graph on Android! :D

Yes, my favorite "hello world" for graphics applications...  :D

Just for curiosity .... some code:

Android:
Code: [Select]

procedure TAndroidModule1.ViewPort1ChangeFontColor(Sender: TObject);
begin
   FPNoGUIGraphicsBridge1.SetFontColor(ViewPort1.FontColor);
end;

function GenericFunction1(x: real): real;
begin
 Result:= x*x*x;
end;

function GenericFunction2(x: real): real;
begin
 Result:= 4*x*x*x*x - 5*x*x*x - x*x + x -1;
end;

procedure TAndroidModule1.jButton1Click(Sender: TObject);
var
 jGraphicsBuffer: jObject;
 w, h: integer;
begin

   w:= jPanel2.Width;
   h:= jPanel2.Height;

   ViewPort1.Width:= w;
   ViewPort1.Height:= h;
   ViewPort1.DrawAxis:= True;
   ViewPort1.DrawGrid:= True;

   //ViewPort1.FontColor:= colbrGreen;

   ViewPort1.SetScaleXY(-1.6 {xmin},1.6{xmax}, -2.0{ymin}, 6.0{ymax}); //real world!!!

   FPNoGUIGraphicsBridge1.SetSize(w,h);
                                                              //DroidSerif-Bold.ttf
   FPNoGUIGraphicsBridge1.PathToFontFile:= '/system/fonts/Roboto-Regular.ttf';

   FPNoGUIGraphicsBridge1.AddEntity('blue_layer','Circle',[Point(0.0,1.0){left/top},
                                                           Point(1.0,0.0){right/botom}],'This is a Circle!','foo');

   FPNoGUIGraphicsBridge1.AddEntity('blue_layer','Line',[Point(0.0,1.5),Point(1.0, 3.6)],'','foo');
   FPNoGUIGraphicsBridge1.AddEntity('blue_layer','Polyline',[Point(0.0,1.5),Point(0.5,1),
                                                             Point(1.0,1.5), Point(0.5,2)],'','');

   FPNoGUIGraphicsBridge1.AddEntity('blue_layer','Text',[Point(0.0,0.5)],'Hello World!','');

   FPNoGUIGraphicsBridge1.AddFunction(@GenericFunction1,-1.6,1.6);
   FPNoGUIGraphicsBridge1.AddFunction(@GenericFunction2,-1.6,1.6);

   FPNoGUIGraphicsBridge1.PaintViewPort;
   FPNoGUIGraphicsBridge1.PaintGrid(True);

   ViewPort1.PenColor:= colbrBlue;
   FPNoGUIGraphicsBridge1.DrawEntities('blue_layer');

   //ViewPort1.PenColor:= colbrGreen;
   //FPNoGUIGraphicsBridge1.DrawEntities('green_layer');   //from "datagraph.txt"

   ViewPort1.PenColor:= colbrRed;
   FPNoGUIGraphicsBridge1.DrawFunction(False, 0);
   FPNoGUIGraphicsBridge1.DrawFunction(False, 1);

   jGraphicsBuffer:= jBitmap1.GetByteBuffer(w,h);

   PGlobalDirectImagePixel:= jBitmap1.GetDirectBufferAddress(jGraphicsBuffer);

   FPNoGUIGraphicsBridge1.Surface.GetRGBAGraphics(PGlobalDirectImagePixel);

   jImageView1.SetImageBitmap(jBitmap1.GetBitmapFromByteBuffer(jGraphicsBuffer, w, h));
end;   

Windows:

Code: [Select]

procedure TForm1.FPDxfWriteBridge1ProduceEntity(out entityDXF: string);
var
   i: integer;
   strList: TStringList;
begin
   strList:= TStringList.Create;
   entityDXF:='';
   for i:= 0 to FPNoGUIGraphicsBridge1.EntityList.Count - 1 do
   begin
      if FPNoGUIGraphicsBridge1.DXFWriteBridge.RestrictedLayer <> '' then
      begin
        if Pos(FPNoGUIGraphicsBridge1.DXFWriteBridge.RestrictedLayer,
               FPNoGUIGraphicsBridge1.GetEntity(i).EntityData.Layer) > 0 then
        begin
           strList.Add(FPNoGUIGraphicsBridge1.GetEntity(i).DataToDXF);
        end;
      end
      else
      begin
        strList.Add(FPNoGUIGraphicsBridge1.GetEntity(i).DataToDXF);
      end;
   end;
   entityDXF:= Trim(strList.Text);
   strList.Free;
end;

function GenericFunction1(x: real): real;
begin
   Result:= x*x*x;
end;

function GenericFunction2(x: real): real;
begin
    Result:= 4*x*x*x*x - 5*x*x*x - x*x + x -1;
end;

procedure TForm1.FormActivate(Sender: TObject);
begin

   ViewPort1.Height:= PaintBox1.Height;
   ViewPort1.Width:= PaintBox1.Width;

   ViewPort1.DrawAxis:= True;
   ViewPort1.DrawGrid:= True;
   ViewPort1.SetScaleXY(-1.6 {xmin}, 1.6 {xmax}, -2.0 {ymin}, 6.0 {ymax});

   FPNoGUIGraphicsBridge1.AddFunction(@GenericFunction1,-1.6,1.6);
   FPNoGUIGraphicsBridge1.AddFunction(@GenericFunction2,-1.6,1.6);

   FPNoGUIGraphicsBridge1.SetSize(ViewPort1.Width, ViewPort1.Height);
   FPNoGUIGraphicsBridge1.PathToFontFile:= 'C:\Windows\Fonts\Arial.ttf';
   //hint [android]  FPNoGUIGraphicsBridge1.PathToFontFile:= '/system/fonts/Roboto-Regular.ttf';
   //hint [linux]    FPNoGUIGraphicsBridge1.PathToFontFile:= '/usr/share/fonts/TTF/Arial.ttf';

   FPNoGUIGraphicsBridge1.AddEntity('blue_layer','Circle',[Point(0,1.0){left/top},
                                                           Point(1.0,0){right/botom}],'This is a Circle!','foo');

   FPNoGUIGraphicsBridge1.AddEntity('blue_layer','Line',[Point(0.0,1.5),Point(1.0, 3.6)],'','foo');
   FPNoGUIGraphicsBridge1.AddEntity('blue_layer','Polyline',[Point(0,1.5),Point(0.5,1),
                                                    Point(1,1.5), Point(0.5,2)],'','');
   FPNoGUIGraphicsBridge1.AddEntity('blue_layer','Text',[Point(0,0.5)],'Hello World!','');


   (* "datagraph.txt" data format:
   id#circle;layer#green_layer;title#;x#0.50 1.50;y#1.00 0.00
   id#line;layer#green_layer;title#;x#0.30 1.00;y#3.60 2.00
   id#polygon;layer#green_layer;title#;x#0.50 1.00 1.50 1.00;y#1.50 1.00 1.50 2.00
   id#text;layer#green_layer;title#This is Pascal!;x#1.00;y#1.00
   id#point;layer#green_layer;title#;x#-0.30;y#2.00
   *)
   FPNoGUIGraphicsBridge1.LoadEntitiesFromFile('datagraph.txt');  //layer_green

   FPNoGUIGraphicsBridge1.PaintViewPort;
   FPNoGUIGraphicsBridge1.PaintGrid(True);

   ViewPort1.PenColor:= colbrBlue;
   FPNoGUIGraphicsBridge1.DrawEntities('blue_layer');

   ViewPort1.PenColor:= colbrGreen;
   FPNoGUIGraphicsBridge1.DrawEntities('green_layer');   //from "datagraph.txt"

   ViewPort1.PenColor:= colbrRed;
   FPNoGUIGraphicsBridge1.DrawFunction(False {not clear screen}, 0 {index});
   FPNoGUIGraphicsBridge1.DrawFunction(False {not clear screen}, 1 {index});

   //Prepare DXF                      {1-red} {3-green} {5-blue}
   FPNoGUIGraphicsBridge1.DXFWriteBridge.AddLayer('blue_layer', 'CONTINUOUS', 5 );
   FPNoGUIGraphicsBridge1.DXFWriteBridge.AddLayer('green_layer', 'CONTINUOUS', 3 );

   FPNoGUIGraphicsBridge1.DXFWriteBridge.ProduceEntity('blue_layer'); //restricted layer... event OnProduceEntity
   FPNoGUIGraphicsBridge1.DXFWriteBridge.SaveToFile('blue_layer.dxf');

   FPNoGUIGraphicsBridge1.DXFWriteBridge.ProduceEntity('green_layer'); //restricted layer... event OnProduceEntity
   FPNoGUIGraphicsBridge1.DXFWriteBridge.SaveToFile('green_layer.dxf');

   FPNoGUIGraphicsBridge1.DXFWriteBridge.ProduceEntity(''); //not restricted layer... event OnProduceEntity
   FPNoGUIGraphicsBridge1.DXFWriteBridge.SaveToFile('all_layer.dxf');

end;

procedure TForm1.PaintBox1Paint(Sender: TObject);
begin
  FPNoGUIGraphicsBridge1.Surface.CopyToCanvas(0,0,PaintBox1.Canvas);
end;
« Last Edit: April 19, 2015, 06:12:23 pm by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

 

TinyPortal © 2005-2018