sdl_rect.odin 1.0 KB

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