|
| 1 | +unit SDL3; |
| 2 | + |
| 3 | +{ |
| 4 | + SDL3-for-Pascal |
| 5 | + ================= |
| 6 | + Pascal units for SDL3 - Simple Direct MediaLayer, Version 3 |
| 7 | +
|
| 8 | + (to be extended - todo) |
| 9 | +
|
| 10 | +} |
| 11 | + |
| 12 | +{$I sdl.inc} |
| 13 | + |
| 14 | +interface |
| 15 | + |
| 16 | + {$IFDEF WINDOWS} |
| 17 | + uses |
| 18 | + {$IFDEF FPC} |
| 19 | + ctypes, |
| 20 | + {$ENDIF} |
| 21 | + Windows; |
| 22 | + {$ENDIF} |
| 23 | + |
| 24 | + {$IF DEFINED(UNIX) AND NOT DEFINED(ANDROID)} |
| 25 | + uses |
| 26 | + {$IFDEF FPC} |
| 27 | + ctypes, |
| 28 | + UnixType, |
| 29 | + {$ENDIF} |
| 30 | + {$IFDEF DARWIN} |
| 31 | + CocoaAll; |
| 32 | + {$ELSE} |
| 33 | + X, |
| 34 | + XLib; |
| 35 | + {$ENDIF} |
| 36 | + {$ENDIF} |
| 37 | + |
| 38 | + {$IF DEFINED(UNIX) AND DEFINED(ANDROID) AND DEFINED(FPC)} |
| 39 | + uses |
| 40 | + ctypes, |
| 41 | + UnixType; |
| 42 | + {$ENDIF} |
| 43 | + |
| 44 | +const |
| 45 | + |
| 46 | + {$IFDEF WINDOWS} |
| 47 | + SDL_LibName = 'SDL3.dll'; |
| 48 | + {$ENDIF} |
| 49 | + |
| 50 | + {$IFDEF UNIX} |
| 51 | + {$IFDEF DARWIN} |
| 52 | + SDL_LibName = 'libSDL3.dylib'; |
| 53 | + {$IFDEF FPC} |
| 54 | + {$LINKLIB libSDL2} |
| 55 | + {$ENDIF} |
| 56 | + {$ELSE} |
| 57 | + {$IFDEF FPC} |
| 58 | + SDL_LibName = 'libSDL3.so'; |
| 59 | + {$ELSE} |
| 60 | + SDL_LibName = 'libSDL3.so.0'; |
| 61 | + {$ENDIF} |
| 62 | + {$ENDIF} |
| 63 | + {$ENDIF} |
| 64 | + |
| 65 | + {$IFDEF MACOS} |
| 66 | + SDL_LibName = 'SDL3'; |
| 67 | + {$IFDEF FPC} |
| 68 | + {$linklib libSDL3} |
| 69 | + {$ENDIF} |
| 70 | + {$ENDIF} |
| 71 | + |
| 72 | +{$I ctypes.inc} // C data types |
| 73 | + |
| 74 | +{ The include file translates |
| 75 | + corresponding C header file. |
| 76 | + Inc file was updated against |
| 77 | + SDL_init.inc --> SDL_init.h this version of the header file: } |
| 78 | +{$I SDL_init.inc} // 3.1.6-prev |
| 79 | +{$I SDL_log.inc} // 3.1.6-prev |
| 80 | +{$I SDL_version.inc} // 3.1.6-prev |
| 81 | +{$I SDL_revision.inc} // 3.1.6-prev |
| 82 | +{$I SDL_stdinc.inc} // 3.1.6-prev (unfinished) |
| 83 | +{$I SDL_rect.inc} // 3.1.6-prev |
| 84 | +{$I SDL_properties.inc} // 3.1.6-prev |
| 85 | +{$I SDL_pixels.inc} // 3.1.6-prev |
| 86 | +{$I SDL_blendmode.inc} // 3.1.6-prev |
| 87 | +{$I SDL_iostream.inc} // 3.1.6-prev (unfinished) |
| 88 | +{$I SDL_surface.inc} // 3.1.6-prev |
| 89 | +{$I SDL_video.inc} // 3.1.6-prev |
| 90 | +{$I SDL_render.inc} // 3.1.6-prev |
| 91 | +{$I SDL_timer.inc} // 3.1.6-prev |
| 92 | +{$I SDL_error.inc} // 3.1.6-prev |
| 93 | + |
| 94 | + |
| 95 | +implementation |
| 96 | + |
| 97 | +{ Macros from SDL_version.h } |
| 98 | +function SDL_VERSIONNUM(major, minor, patch: Integer): Integer; |
| 99 | +begin |
| 100 | + Result:=(major*1000000)+(minor*1000)+patch; |
| 101 | +end; |
| 102 | + |
| 103 | +function SDL_VERSIONNUM_MAJOR(version: Integer): Integer; |
| 104 | +begin |
| 105 | + Result:=version div 1000000; |
| 106 | +end; |
| 107 | + |
| 108 | +function SDL_VERSIONNUM_MINOR(version: Integer): Integer; |
| 109 | +begin |
| 110 | + Result:=(version div 1000) mod 1000; |
| 111 | +end; |
| 112 | + |
| 113 | +function SDL_VERSIONNUM_MICRO(version: Integer): Integer; |
| 114 | +begin |
| 115 | + Result:=version mod 1000; |
| 116 | +end; |
| 117 | + |
| 118 | +function SDL_VERSION: Integer; |
| 119 | +begin |
| 120 | + Result:=SDL_VERSIONNUM(SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_MICRO_VERSION); |
| 121 | +end; |
| 122 | + |
| 123 | +function SDL_VERSION_ATLEAST(X, Y, Z: Integer): Boolean; |
| 124 | +begin |
| 125 | + if (SDL_VERSION >= SDL_VERSIONNUM(X, Y, Z)) then |
| 126 | + Result:=True |
| 127 | + else |
| 128 | + Result:=False; |
| 129 | +end; |
| 130 | + |
| 131 | +{ Macros from SDL_rect.h } |
| 132 | +procedure SDL_RectToFRect(const rect: PSDL_Rect; frect: PSDL_FRect); |
| 133 | +begin |
| 134 | + frect^.x:=cfloat(rect^.x); |
| 135 | + frect^.y:=cfloat(rect^.y); |
| 136 | + frect^.w:=cfloat(rect^.w); |
| 137 | + frect^.h:=cfloat(rect^.h); |
| 138 | +end; |
| 139 | + |
| 140 | +function SDL_PointInRect(const p: PSDL_Point; const r: PSDL_Rect): cbool; |
| 141 | +begin |
| 142 | + Result := |
| 143 | + (p <> nil) and (r <> nil) and (p^.x >= r^.x) and (p^.x < (r^.x + r^.w)) and |
| 144 | + (p^.y >= r^.y) and (p^.y < (r^.y + r^.h)); |
| 145 | +end; |
| 146 | + |
| 147 | +function SDL_RectEmpty(const r: PSDL_Rect): cbool; |
| 148 | +begin |
| 149 | + Result := (r = nil) or (r^.w <= 0) or (r^.h <= 0); |
| 150 | +end; |
| 151 | + |
| 152 | +function SDL_RectsEqual(const a: PSDL_Rect; const b: PSDL_Rect): cbool; |
| 153 | +begin |
| 154 | + Result := (a <> nil) and (b <> nil) and (a^.x = b^.x) and (a^.y = b^.y) and |
| 155 | + (a^.w = b^.w) and (a^.h = b^.h); |
| 156 | +end; |
| 157 | + |
| 158 | +function SDL_PointInRectFloat(const p: PSDL_FPoint; const r: PSDL_FRect): cbool; |
| 159 | +begin |
| 160 | + Result := |
| 161 | + (p <> nil) and (r <> nil) and (p^.x >= r^.x) and (p^.x <= (r^.x + r^.w)) and |
| 162 | + (p^.y >= r^.y) and (p^.y <= (r^.y + r^.h)); |
| 163 | +end; |
| 164 | + |
| 165 | +function SDL_RectEmptyFloat(const r: PSDL_FRect): cbool; |
| 166 | +begin |
| 167 | + Result := (r = nil) or (r^.w < cfloat(0.0)) or (r^.h < cfloat(0.0)); |
| 168 | +end; |
| 169 | + |
| 170 | +function SDL_RectsEqualEpsilon(const a: PSDL_Frect; const b: PSDL_FRect; |
| 171 | + const epsilon: cfloat): cbool; |
| 172 | +begin |
| 173 | + Result := |
| 174 | + (a <> nil) and (b <> nil) and ((a = b) or |
| 175 | + ((SDL_fabsf(a^.x - b^.x) <= epsilon) and |
| 176 | + (SDL_fabsf(a^.y - b^.y) <= epsilon) and |
| 177 | + (SDL_fabsf(a^.w - b^.w) <= epsilon) and |
| 178 | + (SDL_fabsf(a^.h - b^.h) <= epsilon))); |
| 179 | +end; |
| 180 | + |
| 181 | +function SDL_RectsEqualFloat(const a: PSDL_FRect; b: PSDL_FRect): cbool; |
| 182 | +begin |
| 183 | + Result := SDL_RectsEqualEpsilon(a, b, SDL_FLT_EPSILON); |
| 184 | +end; |
| 185 | + |
| 186 | +{ Macros from SDL_timer.h } |
| 187 | +function SDL_SECONDS_TO_NS(S: Integer): Integer; |
| 188 | +begin |
| 189 | + SDL_SECONDS_TO_NS:=(cuint64(S))*SDL_NS_PER_SECOND; |
| 190 | +end; |
| 191 | + |
| 192 | +function SDL_NS_TO_SECONDS(NS: Integer): Integer; |
| 193 | +begin |
| 194 | + SDL_NS_TO_SECONDS:=NS div SDL_NS_PER_SECOND; |
| 195 | +end; |
| 196 | + |
| 197 | +function SDL_MS_TO_NS(MS: Integer): Integer; |
| 198 | +begin |
| 199 | + SDL_MS_TO_NS:=(cuint64(MS))*SDL_NS_PER_MS; |
| 200 | +end; |
| 201 | + |
| 202 | +function SDL_NS_TO_MS(NS: Integer): Integer; |
| 203 | +begin |
| 204 | + SDL_NS_TO_MS:=NS div SDL_NS_PER_MS; |
| 205 | +end; |
| 206 | + |
| 207 | +function SDL_US_TO_NS(US: Integer): Integer; |
| 208 | +begin |
| 209 | + SDL_US_TO_NS:=(cuint64(US))*SDL_NS_PER_US; |
| 210 | +end; |
| 211 | + |
| 212 | +function SDL_NS_TO_US(NS: Integer): Integer; |
| 213 | +begin |
| 214 | + SDL_NS_TO_US:=NS div SDL_NS_PER_US; |
| 215 | +end; |
| 216 | + |
| 217 | +{ Macros from SDL_video.h } |
| 218 | +function SDL_WINDOWPOS_UNDEFINED_DISPLAY(X: Integer): Integer; |
| 219 | +begin |
| 220 | + Result := (SDL_WINDOWPOS_CENTERED_MASK or X); |
| 221 | +end; |
| 222 | + |
| 223 | +function SDL_WINDOWPOS_ISUNDEFINED(X: Integer): Boolean; |
| 224 | +begin |
| 225 | + Result := (X and $FFFF0000) = SDL_WINDOWPOS_UNDEFINED_MASK; |
| 226 | +end; |
| 227 | + |
| 228 | +function SDL_WINDOWPOS_CENTERED_DISPLAY(X: Integer): Integer; |
| 229 | +begin |
| 230 | + Result := (SDL_WINDOWPOS_CENTERED_MASK or X); |
| 231 | +end; |
| 232 | + |
| 233 | +function SDL_WINDOWPOS_ISCENTERED(X: Integer): Boolean; |
| 234 | +begin |
| 235 | + Result := (X and $FFFF0000) = SDL_WINDOWPOS_CENTERED_MASK; |
| 236 | +end; |
| 237 | + |
| 238 | +end. |
| 239 | + |
0 commit comments