Skip to content
Snippets Groups Projects
Verified Commit 9adcaad9 authored by v-lafeychine's avatar v-lafeychine
Browse files

SFML: Add conversion for Int/FloatRect + Vector2i/f

parent c7dccad3
No related branches found
No related tags found
1 merge request!22Resolve "Refactor: GameEngine"
Pipeline #9946 failed with stage
in 1 minute and 54 seconds
......@@ -17,12 +17,6 @@ class FloatRect(var left: Float, var top: Float, var width: Float, var height: F
def this(origin: Vector2f, size: Vector2f) =
this(origin.x, origin.y, size.x, size.y)
def :=(rhs: FloatRect) =
left = rhs.left
top = rhs.top
width = rhs.width
height = rhs.height
def bind(implicit z: Zone) =
val floatRect = alloc[sfFloatRect]()
......@@ -32,5 +26,11 @@ class FloatRect(var left: Float, var top: Float, var width: Float, var height: F
floatRect._4 = height
return floatRect
def :=(rhs: FloatRect) =
left = rhs.left
top = rhs.top
width = rhs.width
height = rhs.height
def contains(x: Float, y: Float): Boolean =
Zone { implicit z => sfFloatRect_contains(bind(z), x, y) == SFML.Bindings.Type.sfTrue }
......@@ -26,5 +26,11 @@ class IntRect(var left: Int, var top: Int, var width: Int, var height: Int) exte
intRect._4 = height
return intRect
def :=(rhs: IntRect) =
left = rhs.left
top = rhs.top
width = rhs.width
height = rhs.height
def contains(x: Int, y: Int): Boolean =
Zone { implicit z => sfIntRect_contains(bind(z), x, y) == SFML.Bindings.Type.sfTrue }
......@@ -12,9 +12,12 @@ implicit def tupleFloatToVectorFloat(tuple: (Float, Float)): Vector2f =
implicit def tupleIntToVectorFloat(tuple: (Int, Int)): Vector2f =
return Vector2f(tuple._1, tuple._2)
class Vector2f(val x: Float, val y: Float) extends SFMLBind[SFML.Bindings.System.Vector2.sfVector2f]:
class Vector2f(var x: Float, var y: Float) extends SFMLBind[SFML.Bindings.System.Vector2.sfVector2f]:
import SFML.Bindings.System.Vector2.*
def this() =
this(0, 0)
def bind(implicit z: Zone) =
val vector2f = alloc[sfVector2f]()
......@@ -22,11 +25,15 @@ class Vector2f(val x: Float, val y: Float) extends SFMLBind[SFML.Bindings.System
vector2f._2 = y
return (vector2f)
def :=(rhs: Vector2f) =
x = rhs.x
y = rhs.y
def +(rhs: Vector2f) =
Vector2f(x + rhs.x, y + rhs.y)
def *(rhs: Vector2f) =
Vector2f(x + rhs.x, y + rhs.y)
Vector2f(x * rhs.x, y * rhs.y)
def *(rhs: Float) =
Vector2f(x * rhs, y * rhs)
......@@ -9,9 +9,12 @@ implicit def vectorFloatToInt(vector: Vector2f): Vector2i =
implicit def tupleIntToVectorInt(tuple: (Int, Int)): Vector2i =
return Vector2i(tuple._1, tuple._2)
class Vector2i(val x: Int, val y: Int) extends SFMLBind[SFML.Bindings.System.Vector2.sfVector2i]:
class Vector2i(var x: Int, var y: Int) extends SFMLBind[SFML.Bindings.System.Vector2.sfVector2i]:
import SFML.Bindings.System.Vector2.*
def this() =
this(0, 0)
def bind(implicit z: Zone) =
val vector2i = alloc[sfVector2i]()
......@@ -19,6 +22,10 @@ class Vector2i(val x: Int, val y: Int) extends SFMLBind[SFML.Bindings.System.Vec
vector2i._2 = y
return (vector2i)
def :=(rhs: Vector2i) =
x = rhs.x
y = rhs.y
def +(rhs: Vector2i) =
Vector2i(x + rhs.x, y + rhs.y)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment