sdl_rect.odin 1.1 KB

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