sfml_stuff.nim 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import
  2. math, strutils,
  3. sfml, input_helpers
  4. when not defined(NoChipmunk):
  5. import chipmunk
  6. proc floor*(a: TVector): TVector2f {.inline.} =
  7. result.x = a.x.floor
  8. result.y = a.y.floor
  9. proc sfml2cp*(a: TVector2f): TVector {.inline.} =
  10. result.x = a.x
  11. result.y = a.y
  12. proc cp2sfml*(a: TVector): TVector2f {.inline.} =
  13. result.x = a.x
  14. result.y = a.y
  15. proc vec2f*(a: TVector2i): TVector2f =
  16. result.x = a.x.cfloat
  17. result.y = a.y.cfloat
  18. proc vec2i*(a: TVector2f): TVector2i =
  19. result.x = a.x.cint
  20. result.y = a.y.cint
  21. proc vec3f*(x, y, z: float): TVector3f =
  22. result.x = x.cfloat
  23. result.y = y.cfloat
  24. result.z = z.cfloat
  25. proc `$`*(a: var TIntRect): string =
  26. result = "[TIntRect $1,$2 $3x$4]".format($a.left, $a.top, $a.width, $a.height)
  27. proc `$`*(a: TKeyEvent): string =
  28. return "KeyEvent: code=$1 alt=$2 control=$3 shift=$4 system=$5".format(
  29. $a.code, $a.alt, $a.control, $a.shift, $a.system)
  30. proc `wmod`*(x, y: float): float = return x - y * (x/y).floor
  31. proc move*(a: var TIntRect, left, top: cint): bool =
  32. if a.left != left or a.top != top: result = true
  33. a.left = left
  34. a.top = top