Skip to content

Commit c9ff348

Browse files
Add SDL_power.inc
1 parent 6070019 commit c9ff348

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

units/SDL_power.inc

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
This file is part of:
3+
4+
SDL3 for Pascal
5+
(https://github.com/PascalGameDevelopment/SDL3-for-Pascal)
6+
SPDX-License-Identifier: Zlib
7+
}
8+
9+
{*
10+
* # CategoryPower
11+
*
12+
* SDL power management routines.
13+
}
14+
15+
{*
16+
* The basic state for the system's power supply.
17+
*
18+
* These are results returned by SDL_GetPowerInfo().
19+
*
20+
* \since This enum is available since SDL 3.1.3
21+
}
22+
type
23+
PPSDL_PowerState = ^PSDL_PowerState;
24+
PSDL_PowerState = ^TSDL_PowerState;
25+
TSDL_PowerState = type Integer;
26+
const
27+
SDL_POWERSTATE_ERROR = -1; {*< error determining power status }
28+
SDL_POWERSTATE_UNKNOWN = TSDL_PowerState(0); {*< cannot determine power status }
29+
SDL_POWERSTATE_ON_BATTERY = TSDL_PowerState(1); {*< Not plugged in, running on the battery }
30+
SDL_POWERSTATE_NO_BATTERY = TSDL_PowerState(2); {*< Plugged in, no battery available }
31+
SDL_POWERSTATE_CHARGING = TSDL_PowerState(3); {*< Plugged in, charging battery }
32+
SDL_POWERSTATE_CHARGED = TSDL_PowerState(4); {*< Plugged in, battery charged }
33+
34+
{*
35+
* Get the current power supply details.
36+
*
37+
* You should never take a battery status as absolute truth. Batteries
38+
* (especially failing batteries) are delicate hardware, and the values
39+
* reported here are best estimates based on what that hardware reports. It's
40+
* not uncommon for older batteries to lose stored power much faster than it
41+
* reports, or completely drain when reporting it has 20 percent left, etc.
42+
*
43+
* Battery status can change at any time; if you are concerned with power
44+
* state, you should call this function frequently, and perhaps ignore changes
45+
* until they seem to be stable for a few seconds.
46+
*
47+
* It's possible a platform can only report battery percentage or time left
48+
* but not both.
49+
*
50+
* \param seconds a Pointer filled in with the seconds of battery life left,
51+
* or nil to ignore. This will be filled in with -1 if we
52+
* can't determine a value or there is no battery.
53+
* \param percent a Pointer filled in with the percentage of battery life
54+
* left, between 0 and 100, or nil to ignore. This will be
55+
* filled in with -1 we can't determine a value or there is no
56+
* battery.
57+
* \returns the current battery state or `SDL_POWERSTATE_ERROR` on failure;
58+
* call SDL_GetError() for more information.
59+
*
60+
* \since This function is available since SDL 3.1.3.
61+
}
62+
function SDL_GetPowerInfo(seconds: pcint; percent: pcint): TSDL_PowerState; cdecl;
63+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetPowerInfo' {$ENDIF} {$ENDIF};
64+

0 commit comments

Comments
 (0)