-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathun.Draw.pas
More file actions
108 lines (87 loc) · 2.7 KB
/
un.Draw.pas
File metadata and controls
108 lines (87 loc) · 2.7 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
{*****************************************************************************
Copyright (C) 2026 NormalUser
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*****************************************************************************}
unit un.Draw;
{$Mode objfpc} {$H+}
{$COPERATORS OFF}
// ******************** interface *************************
interface
USES SDL2,
un.Structs;
procedure prepareScene;
procedure presentScene;
procedure blitAtlasImage(atlas : PAtlasImage; x, y, center : Integer);
procedure blitAtlasImageScaled(atlas : PAtlasImage; x, y : Double; w, h : Integer);
// ******************** implementation ********************
implementation
procedure blitAtlasImage(atlas : PAtlasImage; x, y, center : Integer);
VAR dest : TSDL_Rect;
p : TSDL_Point;
begin
dest.x := x;
dest.y := y;
dest.w := atlas^.Rec.w;
dest.h := atlas^.Rec.h;
if atlas^.Rot = 0 then
begin
if center <> 0 then
begin
dest.x := dest.x - (dest.w DIV 2);
dest.y := dest.y - (dest.h DIV 2);
end;
SDL_RenderCopy(app.Renderer, atlas^.Tex, @atlas^.Rec, @dest);
end
else
begin
if center <> 0 then
begin
dest.x := dest.x - (dest.h DIV 2);
dest.y := dest.y - (dest.w DIV 2);
end;
p.x := 0;
p.y := 0;
dest.y := dest.y + atlas^.Rec.w;
SDL_RenderCopyEx(app.Renderer, atlas^.Tex, @atlas^.Rec, @dest, -90, @p, SDL_FLIP_NONE);
end;
end;
procedure blitAtlasImageScaled(atlas : PAtlasImage; x, y : Double; w, h : Integer);
VAR dest : TSDL_Rect;
p : TSDL_Point;
begin
dest.x := TRUNC(x);
dest.y := TRUNC(y);
dest.w := w;
dest.h := h;
if (atlas^.rot = 1) then
begin
p.x := 0;
p.y := 0;
dest.y := dest.y + w;
SDL_RenderCopyEx(app.Renderer, atlas^.tex, @atlas^.Rec, @dest, -90, @p, SDL_FLIP_NONE);
end
else
begin
SDL_RenderCopy(app.Renderer, atlas^.tex, @atlas^.Rec, @dest);
end;
end;
procedure prepareScene;
begin
SDL_SetRenderDrawColor(app.Renderer, 0, 0, 0, 255);
SDL_RenderClear(app.Renderer);
end;
procedure presentScene;
begin
SDL_RenderPresent(app.Renderer);
end;
end.