2019-06-23 15:41:32 +00:00
|
|
|
package net.shadowfacts.cacao.view
|
|
|
|
|
|
|
|
import net.shadowfacts.cacao.Window
|
|
|
|
import net.shadowfacts.cacao.geometry.Point
|
|
|
|
import net.shadowfacts.cacao.geometry.Rect
|
2019-08-08 23:17:14 +00:00
|
|
|
import net.shadowfacts.cacao.viewcontroller.ViewController
|
2019-06-23 15:41:32 +00:00
|
|
|
import org.junit.jupiter.api.Assertions.assertEquals
|
|
|
|
import org.junit.jupiter.api.BeforeAll
|
|
|
|
import org.junit.jupiter.api.BeforeEach
|
|
|
|
import org.junit.jupiter.api.Test
|
|
|
|
import java.util.concurrent.CompletableFuture
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author shadowfacts
|
|
|
|
*/
|
|
|
|
class ViewHoverTests {
|
|
|
|
|
2019-08-08 23:17:14 +00:00
|
|
|
lateinit var viewController: ViewController
|
2019-06-23 15:41:32 +00:00
|
|
|
lateinit var window: Window
|
2019-08-08 23:17:14 +00:00
|
|
|
|
|
|
|
val view: View
|
|
|
|
get() = viewController.view
|
2019-06-23 15:41:32 +00:00
|
|
|
|
|
|
|
companion object {
|
|
|
|
@BeforeAll
|
|
|
|
@JvmStatic
|
|
|
|
fun setupAll() {
|
|
|
|
System.setProperty("cacao.drawing.disabled", "true")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@BeforeEach
|
|
|
|
fun setup() {
|
2019-08-08 23:17:14 +00:00
|
|
|
viewController = object: ViewController() {
|
|
|
|
override fun loadView() {
|
|
|
|
view = View()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
window = Window(viewController)
|
2019-06-23 15:41:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun testHoverRootView() {
|
|
|
|
val point = CompletableFuture<Point>()
|
2019-08-08 23:17:14 +00:00
|
|
|
view.addSubview(object: View(Rect(50.0, 50.0, 100.0, 100.0)) {
|
2019-06-23 15:41:32 +00:00
|
|
|
override fun drawContent(mouse: Point, delta: Float) {
|
|
|
|
point.complete(mouse)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
window.draw(Point(75.0, 75.0), 0f)
|
|
|
|
|
|
|
|
assertEquals(Point(25.0, 25.0), point.getNow(null))
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun testHoverNestedView() {
|
|
|
|
val point = CompletableFuture<Point>()
|
2019-08-08 23:17:14 +00:00
|
|
|
val root = view.addSubview(View(Rect(50.0, 50.0, 100.0, 100.0)))
|
2019-06-23 20:53:25 +00:00
|
|
|
root.addSubview(object: View(Rect(25.0, 25.0, 50.0, 50.0)) {
|
2019-06-23 15:41:32 +00:00
|
|
|
override fun drawContent(mouse: Point, delta: Float) {
|
|
|
|
point.complete(mouse)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
window.draw(Point(100.0, 100.0), 0f)
|
|
|
|
|
|
|
|
assertEquals(Point(25.0, 25.0), point.getNow(null))
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|