<commit_before>package com.soywiz.korge.view

import com.soywiz.kds.*
import com.soywiz.klock.*
import com.soywiz.klogger.*
import com.soywiz.korag.*
import com.soywiz.korag.log.*
import com.soywiz.korev.*
import com.soywiz.korge.*
import com.soywiz.korge.component.*
import com.soywiz.korge.input.*
import com.soywiz.korge.internal.*
import com.soywiz.korge.render.*
import com.soywiz.korge.stat.*
import com.soywiz.korgw.*
import com.soywiz.korim.bitmap.*
import com.soywiz.korim.color.*
import com.soywiz.korim.format.*
import com.soywiz.korinject.*
import com.soywiz.korio.*
import com.soywiz.korio.async.*
import com.soywiz.korio.file.*
import com.soywiz.korio.lang.Closeable
import com.soywiz.korio.stream.*
import com.soywiz.korma.geom.*
import kotlinx.coroutines.*
import kotlin.coroutines.*
import kotlin.math.*
import kotlin.reflect.*

//@Singleton
/**
 * Heavyweight singleton object within the application that contains information about the Views.
 * It contains information about the [coroutineContext], the [gameWindow], the [injector], the [input]
 * and contains a reference to the [root] [Stage] view.
 */
class Views constructor(
	override val coroutineContext: CoroutineContext,
	val ag: AG,
	val injector: AsyncInjector,
	val input: Input,
	val timeProvider: TimeProvider,
	val stats: Stats,
	val gameWindow: GameWindow
) : Updatable, Extra by Extra.Mixin(), EventDispatcher by EventDispatcher.Mixin(), CoroutineScope, ViewsScope,
	BoundsProvider, DialogInterface by gameWindow, AsyncCloseable {

	var imageFormats = RegisteredImageFormats
	val renderContext = RenderContext(ag, this, stats, coroutineContext)
	val agBitmapTextureManager = renderContext.agBitmapTextureManager
	var clearEachFrame = true
	var clearColor: RGBA = Colors.BLACK
	override val views = this
	val propsTriggers = hashMapOf<String, (View, String, String) -> Unit>()
	var clampElapsedTimeTo = 100

	val nativeWidth get() = ag.mainRenderBuffer.width
	val nativeHeight get() = ag.mainRenderBuffer.height

    // Later updated
	var virtualWidth = DefaultViewport.WIDTH; internal set
	var virtualHeight = DefaultViewport.HEIGHT; internal set

	var actualVirtualLeft = 0; private set
	var actualVirtualTop = 0; private set

	var actualVirtualWidth = DefaultViewport.WIDTH; private set
	var actualVirtualHeight = DefaultViewport.HEIGHT; private set

	override val virtualLeft get() = -actualVirtualLeft * views.stage.scaleX
	override val virtualTop get() = -actualVirtualTop * views.stage.scaleY
	override val virtualRight get() = virtualLeft + virtualWidth * views.stage.scaleX
	override val virtualBottom get() = virtualTop + virtualHeight * views.stage.scaleY

	private val closeables = arrayListOf<AsyncCloseable>()

	fun onClose(callback: suspend () -> Unit) {
		closeables += object : AsyncCloseable {
			override suspend fun close() {
				callback()
			}
		}
	}

	override suspend fun close() {
		closeables.fastForEach { it.close() }
		closeables.clear()
		coroutineContext.cancel()
		gameWindow.close()
	}

	val actualVirtualRight get() = actualVirtualWidth
	val actualVirtualBottom get() = actualVirtualHeight

	val nativeMouseX: Double get() = input.mouse.x
	val nativeMouseY: Double get() = input.mouse.y

	var scaleMode: ScaleMode = ScaleMode.SHOW_ALL
	var scaleAnchor = Anchor.MIDDLE_CENTER
	var clipBorders = true

	private val resizedEvent = ReshapeEvent(0, 0)

    /** Reference to the root node [Stage] */
	val stage = Stage(this)

    /** Reference to the root node [Stage] (alias) */
	val root = stage

    var supportTogglingDebug = true
	var debugViews = false
	val debugHandlers = arrayListOf<Views.(RenderContext) -> Unit>()

	var lastTime = timeProvider.now()

	private val tempComponents: ArrayList<Component> = arrayListOf()

	private val virtualSize = SizeInt()
	private val actualSize = SizeInt()
	private val targetSize = SizeInt()

    val onBeforeRender = Signal<Unit>()
    val onAfterRender = Signal<Unit>()

    var targetFps: Double = -1.0

	init {
		injector.mapInstance(CoroutineContext::class, coroutineContext)
		injector.mapInstance(AG::class, ag)
		injector.mapInstance(Views::class, this)
        onAfterRender {
            renderContext.flush()
            renderContext.finish()
            agBitmapTextureManager.afterRender()
        }
    }

	fun dumpStats() {
		stats.dump()
	}

	fun registerPropertyTrigger(propName: String, gen: (View, String, String) -> Unit) {
		propsTriggers[propName] = gen
	}

	fun registerPropertyTriggerSuspend(propName: String, gen: suspend (View, String, String) -> Unit) {<commit_msg>Expose Views.actualWidth and Views.actualHeight<commit_after>package com.soywiz.korge.view

import com.soywiz.kds.*
import com.soywiz.klock.*
import com.soywiz.klogger.*
import com.soywiz.korag.*
import com.soywiz.korag.log.*
import com.soywiz.korev.*
import com.soywiz.korge.*
import com.soywiz.korge.component.*
import com.soywiz.korge.input.*
import com.soywiz.korge.internal.*
import com.soywiz.korge.render.*
import com.soywiz.korge.stat.*
import com.soywiz.korgw.*
import com.soywiz.korim.bitmap.*
import com.soywiz.korim.color.*
import com.soywiz.korim.format.*
import com.soywiz.korinject.*
import com.soywiz.korio.*
import com.soywiz.korio.async.*
import com.soywiz.korio.file.*
import com.soywiz.korio.lang.Closeable
import com.soywiz.korio.stream.*
import com.soywiz.korma.geom.*
import kotlinx.coroutines.*
import kotlin.coroutines.*
import kotlin.math.*
import kotlin.reflect.*

//@Singleton
/**
 * Heavyweight singleton object within the application that contains information about the Views.
 * It contains information about the [coroutineContext], the [gameWindow], the [injector], the [input]
 * and contains a reference to the [root] [Stage] view.
 */
class Views constructor(
	override val coroutineContext: CoroutineContext,
	val ag: AG,
	val injector: AsyncInjector,
	val input: Input,
	val timeProvider: TimeProvider,
	val stats: Stats,
	val gameWindow: GameWindow
) : Updatable, Extra by Extra.Mixin(), EventDispatcher by EventDispatcher.Mixin(), CoroutineScope, ViewsScope,
	BoundsProvider, DialogInterface by gameWindow, AsyncCloseable {

	var imageFormats = RegisteredImageFormats
	val renderContext = RenderContext(ag, this, stats, coroutineContext)
	val agBitmapTextureManager = renderContext.agBitmapTextureManager
	var clearEachFrame = true
	var clearColor: RGBA = Colors.BLACK
	override val views = this
	val propsTriggers = hashMapOf<String, (View, String, String) -> Unit>()
	var clampElapsedTimeTo = 100

	val nativeWidth get() = ag.mainRenderBuffer.width
	val nativeHeight get() = ag.mainRenderBuffer.height

    // Later updated
	var virtualWidth = DefaultViewport.WIDTH; internal set
	var virtualHeight = DefaultViewport.HEIGHT; internal set

	var actualVirtualLeft = 0; private set
	var actualVirtualTop = 0; private set

	var actualVirtualWidth = DefaultViewport.WIDTH; private set
	var actualVirtualHeight = DefaultViewport.HEIGHT; private set

	override val virtualLeft get() = -actualVirtualLeft * views.stage.scaleX
	override val virtualTop get() = -actualVirtualTop * views.stage.scaleY
	override val virtualRight get() = virtualLeft + virtualWidth * views.stage.scaleX
	override val virtualBottom get() = virtualTop + virtualHeight * views.stage.scaleY

	private val closeables = arrayListOf<AsyncCloseable>()

	fun onClose(callback: suspend () -> Unit) {
		closeables += object : AsyncCloseable {
			override suspend fun close() {
				callback()
			}
		}
	}

	override suspend fun close() {
		closeables.fastForEach { it.close() }
		closeables.clear()
		coroutineContext.cancel()
		gameWindow.close()
	}

	val actualVirtualRight get() = actualVirtualWidth
	val actualVirtualBottom get() = actualVirtualHeight

	val nativeMouseX: Double get() = input.mouse.x
	val nativeMouseY: Double get() = input.mouse.y

	var scaleMode: ScaleMode = ScaleMode.SHOW_ALL
	var scaleAnchor = Anchor.MIDDLE_CENTER
	var clipBorders = true

	private val resizedEvent = ReshapeEvent(0, 0)

    /** Reference to the root node [Stage] */
	val stage = Stage(this)

    /** Reference to the root node [Stage] (alias) */
	val root = stage

    var supportTogglingDebug = true
	var debugViews = false
	val debugHandlers = arrayListOf<Views.(RenderContext) -> Unit>()

	var lastTime = timeProvider.now()

	private val tempComponents: ArrayList<Component> = arrayListOf()

	private val virtualSize = SizeInt()
	private val actualSize = SizeInt()
	private val targetSize = SizeInt()

    val actualWidth get() = actualSize.width
    val actualHeight get() = actualSize.height

    val onBeforeRender = Signal<Unit>()
    val onAfterRender = Signal<Unit>()

    var targetFps: Double = -1.0

	init {
		injector.mapInstance(CoroutineContext::class, coroutineContext)
		injector.mapInstance(AG::class, ag)
		injector.mapInstance(Views::class, this)
        onAfterRender {
            renderContext.flush()
            renderContext.finish()
            agBitmapTextureManager.afterRender()
        }
    }

	fun dumpStats() {
		stats.dump()
	}

	fun registerPropertyTrigger(propName: String, gen: (View, String, String) -> Unit) {
		propsTriggers[propName] = gen
	}

	fun registerPropertyTriggerSuspend(propName: String, gen: suspend (View, String, String) -> Unit) {
{'fraction_non_alphanumeric': 0.10226411006391507, 'fraction_numerical': 0.0019499512512187196, 'mean_word_length': 4.511641791044776, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6124963', 'n_tokens_mistral': 2988, 'n_tokens_neox': 2900, 'n_words': 767}