package net.shadowfacts.cacao.view import net.shadowfacts.cacao.Window import net.shadowfacts.cacao.geometry.Point import net.shadowfacts.cacao.geometry.Rect 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 { lateinit var window: Window companion object { @BeforeAll @JvmStatic fun setupAll() { System.setProperty("cacao.drawing.disabled", "true") } } @BeforeEach fun setup() { window = Window() } @Test fun testHoverRootView() { val point = CompletableFuture() window.addView(object: View(Rect(50.0, 50.0, 100.0, 100.0)) { 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() val root = window.addView(View(Rect(50.0, 50.0, 100.0, 100.0))) root.addSubview(object: View(Rect(25.0, 25.0, 50.0, 50.0)) { 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)) } }