-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathuUtils.pas
83 lines (73 loc) · 2.87 KB
/
uUtils.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
unit uUtils;
interface
uses FMX.Graphics, System.UITypes, System.SysUtils, System.types, FMX.types, System.IOUtils;
function getTileImage(indiceTile, tilesize, nbTilePerLine : integer; tileset : TBitmap):TBitmap;
function cropImage(originBitmap : TBitmap; Xpos, Ypos, width, height: integer): TBitmap;
function getInterpolation(nomInterpollation: string) : TInterpolationType;
function getAnimationType(typeAnimation: string): TAnimationType;
procedure chargerImage(uneImage : TBitmap; fichier : string);
function GetAppResourcesPath:string;
implementation
function getTileImage(indiceTile, tilesize, nbTilePerLine : integer; tileset : TBitmap):TBitmap;
begin
var imgTile := TBitmap.Create;
imgTile.Width := TileSize;
imgTile.Height := TileSize;
var lg := indiceTile div nbTilePerLine;
var col := indiceTile mod nbTilePerLine -1;
imgTile := cropImage(tileset,col * tileSize, lg * tilesize, tilesize, tilesize);
result := imgTile;
end;
function cropImage(originBitmap : TBitmap; Xpos, Ypos, width, height: integer): TBitmap;
begin
result := TBitmap.Create;
result.Width := Width;
result.Height := Height;
result.CopyFromBitmap(originBitmap, TRect.Create(Xpos, Ypos, Xpos + Width, Ypos + Height), 0, 0);
end;
procedure chargerImage(uneImage : TBitmap; fichier : string);
begin
if fileExists(fichier) then uneImage.LoadFromFile(fichier);
end;
function getInterpolation(nomInterpollation: string): TInterpolationType;
begin
result := TInterpolationType.Linear;
if nomInterpollation = 'sinusoidal' then result := TInterpolationType.Sinusoidal;
if nomInterpollation = 'quadratic' then result := TInterpolationType.Quadratic;
if nomInterpollation = 'cubic' then result := TInterpolationType.Cubic;
if nomInterpollation = 'quartic' then result := TInterpolationType.Quartic;
if nomInterpollation = 'quintic' then result := TInterpolationType.Quintic;
if nomInterpollation = 'exponential' then result := TInterpolationType.Exponential;
if nomInterpollation = 'circular' then result := TInterpolationType.Circular;
if nomInterpollation = 'elastic' then result := TInterpolationType.Elastic;
if nomInterpollation = 'back' then result := TInterpolationType.Back;
if nomInterpollation = 'bounce' then result := TInterpolationType.Bounce;
end;
function getAnimationType(typeAnimation: string): TAnimationType;
begin
result := TAnimationType.In;
if typeAnimation = 'out' then result := TAnimationType.Out;
if typeAnimation = 'inout' then result := TAnimationType.InOut;
end;
function GetAppResourcesPath:string;
{$IFDEF MSWINDOWS}
begin
result := TPath.GetDirectoryName(ParamStr(0));
end;
{$ENDIF MSWINDOWS}
{$IFDEF MACOS}
begin
result := TPath.GetHomePath;
end;
{$ENDIF MACOS}
{$IFDEF LINUX}
begin
result := TPath.GetDirectoryName(ParamStr(0));
end;
{$ENDIF LINUX}
{$IFDEF ANDROID}
begin
result := TPath.GetDocumentsPath;
end;
{$ENDIF ANDROID}
end.