Skip to content

Commit

Permalink
cairo
Browse files Browse the repository at this point in the history
  • Loading branch information
sechshelme committed Jun 4, 2024
1 parent 70e1927 commit ba5d05f
Show file tree
Hide file tree
Showing 21 changed files with 163 additions and 625 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ Project1
*.so
*.dylib
*.lrs
# *.res
*.compiled
*.dbg
*.ppu
*.o
*.or
*.a
*.res

# Lazarus autogenerated files (duplicated info)
*.rst
Expand Down
6 changes: 3 additions & 3 deletions Cairo/LCL_cairo/unit1.lfm
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
object Form1: TForm1
Left = 424
Left = 120
Height = 657
Top = 144
Top = 295
Width = 911
Caption = 'Form1'
LCLVersion = '3.99.0.0'
OnCreate = FormCreate
OnDestroy = FormDestroy
OnPaint = FormPaint
LCLVersion = '2.2.4.0'
end
1 change: 0 additions & 1 deletion Cairo/LCL_cairo/unit1.pas
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ procedure TForm1.FormCreate(Sender: TObject);
bit.Width := 640;
bit.Height := 480;

// cr_surface := cairo_image_surface_create_for_data(sd_surface^.pixels, CAIRO_FORMAT_RGB24, sd_surface^.w, sd_surface^.h, sd_surface^.pitch);
cr_surface := cairo_image_surface_create_for_data(bit.RawImage.Data, CAIRO_FORMAT_RGB24, bit.Width, bit.Height, 640*4);

cr := cairo_create(cr_surface);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<XPManifest>
<DpiAware Value="True"/>
</XPManifest>
<Icon Value="0"/>
</General>
<BuildModes>
<Item Name="Default" Default="True"/>
Expand All @@ -25,7 +24,7 @@
</RunParams>
<RequiredPackages>
<Item>
<PackageName Value="SDL2_Package"/>
<PackageName Value="LazOpenGLContext"/>
</Item>
<Item>
<PackageName Value="LCL"/>
Expand All @@ -44,11 +43,6 @@
<ResourceBaseClass Value="Form"/>
<UnitName Value="Unit1"/>
</Unit>
<Unit>
<Filename Value="drawcairo.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="DrawCairo"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
Expand All @@ -60,6 +54,9 @@
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<CodeGeneration>
<TargetOS Value="win64"/>
</CodeGeneration>
<Linking>
<Debugging>
<DebugInfoType Value="dsDwarf2Set"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
athreads,
{$ENDIF}
Interfaces, // this includes the LCL widgetset
Forms, Unit1, DrawCairo
Forms, lazopenglcontext, Unit1
{ you can add units after this };

{$R *.res}
Expand Down
24 changes: 24 additions & 0 deletions Cairo/LCL_cairo_OpenGL/unit1.lfm
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
object Form1: TForm1
Left = 120
Height = 697
Top = 322
Width = 966
Caption = 'Form1'
ClientHeight = 697
ClientWidth = 966
LCLVersion = '3.99.0.0'
OnCreate = FormCreate
OnDestroy = FormDestroy
object OpenGLControl1: TOpenGLControl
Left = 40
Height = 592
Top = 32
Width = 848
OnResize = OpenGLControl1Resize
end
object Timer1: TTimer
OnTimer = Timer1Timer
Left = 108
Top = 16
end
end
112 changes: 112 additions & 0 deletions Cairo/LCL_cairo_OpenGL/unit1.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
Cairo, Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls,
GL,
OpenGLContext;

type

{ TForm1 }

TForm1 = class(TForm)
OpenGLControl1: TOpenGLControl;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure OpenGLControl1Resize(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
cr: Pcairo_t;
cr_surface: Pcairo_surface_t;

buffer:array of Byte;
procedure DrawCairo(angele1, angele2: Double);
public

end;

var
Form1: TForm1;

implementation

{$R *.lfm}

procedure TForm1.DrawCairo(angele1, angele2:Double);
var
xc: double;
yc: double;
radius: double = 200;
begin

cr_surface := cairo_image_surface_create_for_data(pbyte(buffer), CAIRO_FORMAT_RGB24, OpenGLControl1.Width, OpenGLControl1.Height, OpenGLControl1.Width * 4);
cr := cairo_create(cr_surface);

xc:=OpenGLControl1.Width / 2;
yc:=OpenGLControl1.Height / 2;

cairo_set_source_rgba(cr, 1, 1, 1, 1.0);
cairo_rectangle(cr, 0, 0, OpenGLControl1.Width, OpenGLControl1.Height);
cairo_fill(cr);

cairo_set_source_rgba(cr, 0., 0, 0, 1.0);
cairo_set_line_width(cr, 10.0);
cairo_arc(cr, xc, yc, radius, angele1, angele2);
cairo_stroke(cr);

cairo_set_source_rgba(cr, 1, 0.2, 0.2, 0.6);
cairo_set_line_width(cr, 6.0);

cairo_arc(cr, xc, yc, 10.0, 0, 2 * pi);
cairo_fill(cr);

cairo_arc(cr, xc, yc, radius, angele1, angele1);
cairo_line_to(cr, xc, yc);
cairo_arc(cr, xc, yc, radius, angele2, angele2);
cairo_line_to(cr, xc, yc);
cairo_stroke(cr);

glDrawPixels(OpenGLControl1.Width, OpenGLControl1.Height, GL_RGBA, GL_UNSIGNED_BYTE, Pointer(buffer));
OpenGLControl1.SwapBuffers;

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Timer1.Enabled:=False;
OpenGLControl1.Align := alClient;
OpenGLControl1.AutoResizeViewport := False;
OpenGLControl1.MakeCurrent();
glClearColor(1, 1, 1, 0);


Timer1.Interval:=10;
Timer1.Enabled:=True;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
cairo_destroy(cr);
cairo_surface_destroy(cr_surface);
end;

procedure TForm1.OpenGLControl1Resize(Sender: TObject);
begin
SetLength(buffer, OpenGLControl1.Width * OpenGLControl1.Height * 4);
end;

procedure TForm1.Timer1Timer(Sender: TObject);
const
an: Double=0.0;
begin
an+=0.03;
if an>2*Pi then an-=2*Pi;
DrawCairo(an, an * 2);
end;

end.
52 changes: 0 additions & 52 deletions Cairo/cairo_benchmark (Kopie)/drawcairo.pas

This file was deleted.

Binary file removed Cairo/cairo_benchmark (Kopie)/project1.ico
Binary file not shown.
62 changes: 0 additions & 62 deletions Cairo/cairo_benchmark (Kopie)/unit1.lfm

This file was deleted.

Loading

0 comments on commit ba5d05f

Please sign in to comment.