summary refs log tree commit diff stats
path: root/tests/manyloc/keineschweine/lib/sfml_stuff.nim
blob: 5ff80b295ee0024457b38fba4c1660b9a72d0918 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import
  math, strutils,
  sfml, input_helpers
when not defined(NoChipmunk):
  import chipmunk
  proc floor*(a: TVector): TVector2f {.inline.} =
    result.x = a.x.floor
    result.y = a.y.floor
  proc sfml2cp*(a: TVector2f): TVector {.inline.} =
    result.x = a.x
    result.y = a.y
  proc cp2sfml*(a: TVector): TVector2f {.inline.} =
    result.x = a.x
    result.y = a.y

proc vec2f*(a: TVector2i): TVector2f =
  result.x = a.x.cfloat
  result.y = a.y.cfloat
proc vec2i*(a: TVector2f): TVector2i =
  result.x = a.x.cint
  result.y = a.y.cint
proc vec3f*(x, y, z: float): TVector3f =
  result.x = x.cfloat
  result.y = y.cfloat
  result.z = z.cfloat

proc `$`*(a: var TIntRect): string =
  result = "[TIntRect $1,$2 $3x$4]".format($a.left, $a.top, $a.width, $a.height)
proc `$`*(a: TKeyEvent): string =
  return "KeyEvent: code=$1 alt=$2 control=$3 shift=$4 system=$5".format(
    $a.code, $a.alt, $a.control, $a.shift, $a.system)

proc `wmod`*(x, y: float): float = return x - y * (x/y).floor
proc move*(a: var TIntRect, left, top: cint): bool =
  if a.left != left or a.top != top: result = true
  a.left = left
  a.top  = top