sdl_rect.odin 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package sdl2
  2. import "core:c"
  3. when ODIN_OS == "windows" { foreign import lib "SDL2.lib" }
  4. when ODIN_OS == "linux" { foreign import lib "system:SDL2" }
  5. when ODIN_OS == "darwin" { foreign import lib "system:SDL2" }
  6. when ODIN_OS == "freebsd" { foreign import lib "system:SDL2" }
  7. Point :: struct {
  8. x: c.int,
  9. y: c.int,
  10. }
  11. FPoint :: struct {
  12. x: f32,
  13. y: f32,
  14. }
  15. Rect :: struct {
  16. x, y: c.int,
  17. w, h: c.int,
  18. }
  19. FRect :: struct {
  20. x, y: f32,
  21. w, h: f32,
  22. }
  23. PointInRect :: proc(p: ^Point, r: ^Rect) -> bool {
  24. return bool((p.x >= r.x) && (p.x < (r.x + r.w)) && (p.y >= r.y) && (p.y < (r.y + r.h)))
  25. }
  26. RectEmpty :: proc(r: ^Rect) -> bool {
  27. return bool(r == nil|| r.w <= 0 || r.h <= 0)
  28. }
  29. RectEquals :: proc(a, b: ^Rect) -> bool {
  30. return a != nil && b != nil && a^ == b^
  31. }
  32. @(default_calling_convention="c", link_prefix="SDL_")
  33. foreign lib {
  34. HasIntersection :: proc(A, B: ^Rect) -> bool ---
  35. IntersectRect :: proc(A, B: ^Rect, result: ^Rect) -> bool ---
  36. UnionRect :: proc(A, B: ^Rect, result: ^Rect) ---
  37. EnclosePoints :: proc(points: [^]Point, count: c.int, clip: ^Rect, result: ^Rect) -> bool ---
  38. IntersectRectAndLine :: proc(rect: ^Rect, X1, Y1, X2, Y2: ^c.int) -> bool ---
  39. }