Skip to content

Commit 0de588c

Browse files
Add translation cheat sheet
1 parent c89b78d commit 0de588c

File tree

2 files changed

+94
-1
lines changed

2 files changed

+94
-1
lines changed

CHEATSHEET.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# SDL2 Translation Cheat Sheet (C to Pascal)
2+
3+
This cheat sheet helps to quickly translate often found C constructs in the
4+
SDL2 package into Pascal according to the Code style guidelines of the
5+
conversion project.
6+
7+
## Defines
8+
9+
C:
10+
11+
```
12+
#define SDL_HAT_CENTERED 0x00
13+
#define SDL_HAT_UP 0x01
14+
#define SDL_HAT_RIGHT 0x02
15+
#define SDL_HAT_DOWN 0x04
16+
#define SDL_HAT_LEFT 0x08
17+
#define SDL_HAT_RIGHTUP (SDL_HAT_RIGHT|SDL_HAT_UP)
18+
#define SDL_HAT_RIGHTDOWN (SDL_HAT_RIGHT|SDL_HAT_DOWN)
19+
#define SDL_HAT_LEFTUP (SDL_HAT_LEFT|SDL_HAT_UP)
20+
#define SDL_HAT_LEFTDOWN (SDL_HAT_LEFT|SDL_HAT_DOWN)
21+
```
22+
23+
Pascal:
24+
25+
```
26+
const
27+
SDL_HAT_CENTERED = $00;
28+
SDL_HAT_UP = $01;
29+
SDL_HAT_RIGHT = $02;
30+
SDL_HAT_DOWN = $04;
31+
SDL_HAT_LEFT = $08;
32+
SDL_HAT_RIGHTUP = SDL_HAT_RIGHT or SDL_HAT_UP;
33+
SDL_HAT_RIGHTDOWN = SDL_HAT_RIGHT or SDL_HAT_DOWN;
34+
SDL_HAT_LEFTUP = SDL_HAT_LEFT or SDL_HAT_UP;
35+
SDL_HAT_LEFTDOWN = SDL_HAT_LEFT or SDL_HAT_DOWN;
36+
```
37+
38+
## Enums
39+
40+
C:
41+
42+
```
43+
typedef enum
44+
{
45+
SDL_JOYSTICK_POWER_UNKNOWN = -1,
46+
SDL_JOYSTICK_POWER_EMPTY, /* <= 5% */
47+
SDL_JOYSTICK_POWER_LOW, /* <= 20% */
48+
SDL_JOYSTICK_POWER_MEDIUM, /* <= 70% */
49+
SDL_JOYSTICK_POWER_FULL, /* <= 100% */
50+
SDL_JOYSTICK_POWER_WIRED,
51+
SDL_JOYSTICK_POWER_MAX
52+
} SDL_JoystickPowerLevel;
53+
```
54+
55+
Pascal:
56+
57+
```
58+
type
59+
TSDL_JoystickPowerLevel = type SInt32;
60+
61+
const
62+
SDL_JOYSTICK_POWER_UNKNOWN = TSDL_JoystickPowerLevel(-1);
63+
SDL_JOYSTICK_POWER_EMPTY = TSDL_JoystickPowerLevel(0); {* <= 5% *}
64+
SDL_JOYSTICK_POWER_LOW = TSDL_JoystickPowerLevel(1); {* <= 20% *}
65+
SDL_JOYSTICK_POWER_MEDIUM = TSDL_JoystickPowerLevel(2); {* <= 70% *}
66+
SDL_JOYSTICK_POWER_FULL = TSDL_JoystickPowerLevel(3); {* <= 100% *}
67+
SDL_JOYSTICK_POWER_WIRED = TSDL_JoystickPowerLevel(4);
68+
SDL_JOYSTICK_POWER_MAX = TSDL_JoystickPowerLevel(5);
69+
```
70+
71+
## Functions
72+
73+
C:
74+
75+
```
76+
extern DECLSPEC void SDLCALL SDL_LockJoysticks(void);
77+
78+
extern DECLSPEC const char *SDLCALL SDL_JoystickNameForIndex(int device_index);
79+
```
80+
81+
Pascal:
82+
83+
```
84+
procedure SDL_LockJoysticks(); cdecl;
85+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_LockJoysticks' {$ENDIF} {$ENDIF};
86+
87+
function SDL_JoystickNameForIndex(device_index: SInt32): PAnsiChar; cdecl;
88+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_JoystickNameForIndex' {$ENDIF} {$ENDIF};
89+
```
90+
91+

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Please use the GitHub issue tracker for bug reports.
3030

3131
- (Continously) Update files by new SDL2 functions and types which are present in more recent SDL2 versions.
3232
- (Continously atm.) Translate integer aliases into typed enums.
33-
See PR [#4](https://github.com/PascalGameDevelopment/SDL2-for-Pascal/pull/4) for reference.
33+
See part Enums on the [Cheat sheet](CHEATSHEET.md) for reference.
3434
- (Continously) Check FPC/Delphi compatibility.
3535

3636
## Code style guidelines
@@ -53,6 +53,8 @@ original code. Do not replace them by Pascal equivalents.
5353
Ex.: Use `UInt32` (if used in
5454
the original code) instead of `Cardinal`, `LongWord` or `DWord` .
5555

56+
4. Have a look at our [Translation Cheat Sheet](CHEATSHEET.md) for reference.
57+
5658
## Versions
5759

5860
The version tag (see [tags](https://github.com/PascalGameDevelopment/SDL2-for-Pascal/tags)) refers to the version of this translation package [SDL2 for Pascal](https://github.com/PascalGameDevelopment/SDL2-for-Pascal), not the `SDL2 library`.

0 commit comments

Comments
 (0)