This repository was archived by the owner on Jun 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZenGLShowMeFPS.pas
More file actions
114 lines (95 loc) · 1.87 KB
/
Copy pathZenGLShowMeFPS.pas
File metadata and controls
114 lines (95 loc) · 1.87 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
109
110
111
112
113
unit ZenGLShowMeFPS;
{$mode objfpc}{$H+}
interface
uses
Classes,
SysUtils,
NiceTypes,
NiceExceptions,
zgl_main,
zgl_utils,
zgl_window,
zgl_primitives_2d,
zgl_font,
zgl_text;
type
{ TFPSDrawer }
TFPSDrawer = class
public
constructor Create;
private
fFont: zglPFont;
fOwnsFont: boolean;
procedure Initialize;
procedure Finalize;
public const
Gap = 6;
public
Font: zglPFont;
// default is true
property OwnsFont: boolean read fOwnsFont write fOwnsFont;
procedure Draw;
destructor Destroy; override;
end;
implementation
{ TFPSDrawer }
constructor TFPSDrawer.Create;
begin
Initialize;
end;
procedure TFPSDrawer.Initialize;
begin
fOwnsFont := true;
end;
procedure TFPSDrawer.Finalize;
begin
if OwnsFont then
font_Del(fFont);
end;
procedure TFPSDrawer.Draw;
var
textHeight: single;
textWidth: single;
text: string;
procedure DrawBackgroundRectangle;
begin
pr2d_Rect(
wndWidth - Gap - Gap - textWidth - Gap,
wndHeight - Gap - Gap - textHeight - Gap,
Gap + textWidth + Gap,
Gap + textHeight + Gap,
$FFFFFF,
255
);
pr2d_Rect(
wndWidth - Gap - Gap - textWidth - Gap,
wndHeight - Gap - Gap - textHeight - Gap,
Gap + textWidth + Gap,
Gap + textHeight + Gap,
$FFFFFF,
255 div 2,
PR2D_FILL
);
end;
begin
AssertAssigned(Font, 'Font', TVariableType.Field);
text := u_IntToStr( zgl_Get( RENDER_FPS ) );
textWidth := text_GetWidth(Font, text);
textHeight := text_GetHeight(Font, textWidth, text, 1);
DrawBackgroundRectangle;
text_DrawEx(
Font,
wndWidth - Gap - Gap - textWidth, // X
wndHeight - Gap - Gap - textHeight, // Y
1, 0, // scale, step
text,
255, // Alpha
$000000, // Color
0 // Flags
);
end;
destructor TFPSDrawer.Destroy;
begin
inherited Destroy;
end;
end.