From f756b4a453912ba6b281b62d4fb45f4f88393821 Mon Sep 17 00:00:00 2001 From: Ivan Kupriyanov Date: Fri, 23 Jul 2021 22:50:23 +0300 Subject: [PATCH] Fix regions rendering in AWT via reordering drawing operations - moveTo/lineTo functions rendered with latest transform, not with a transform that was active on invocation. --- .../kotlin/jetbrains/livemap/Diagnostics.kt | 9 ++++--- .../jetbrains/livemap/core/MetricsService.kt | 4 ++-- .../livemap/regions/RegionRenderer.kt | 24 ++++++++----------- .../jetbrains/livemap/rendering/Utils.kt | 6 ----- 4 files changed, 18 insertions(+), 25 deletions(-) diff --git a/livemap/src/commonMain/kotlin/jetbrains/livemap/Diagnostics.kt b/livemap/src/commonMain/kotlin/jetbrains/livemap/Diagnostics.kt index 11b3ead9ef0..6e962cc0936 100644 --- a/livemap/src/commonMain/kotlin/jetbrains/livemap/Diagnostics.kt +++ b/livemap/src/commonMain/kotlin/jetbrains/livemap/Diagnostics.kt @@ -34,7 +34,7 @@ open class Diagnostics { private val dirtyLayers: List, private val schedulerSystem: SchedulerSystem, private val debugService: MetricsService, - uiService: UiService, + private val uiService: UiService, private val registry: EcsComponentManager ) : Diagnostics() { @@ -100,13 +100,16 @@ open class Diagnostics { debugService.setValue(TIMER_TICK, "Timer tick: $deltaTime") debugService.setValue( SYSTEMS_UPDATE_TIME, - "Systems update: ${formatDouble(debugService.totalUpdateTime, 1)}" + "Systems update: ${debugService.totalUpdateTime}" ) debugService.setValue(ENTITIES_COUNT, "Entities count: ${registry.entitiesCount}") diagnostics.forEach(Diagnostic::update) - metrics.text = debugService.values + if (metrics.text != debugService.values) { + metrics.text = debugService.values + uiService.repaint() + } } internal inner class FreezingSystemDiagnostic : Diagnostic { diff --git a/livemap/src/commonMain/kotlin/jetbrains/livemap/core/MetricsService.kt b/livemap/src/commonMain/kotlin/jetbrains/livemap/core/MetricsService.kt index c88fc237ac5..ebd325c352e 100644 --- a/livemap/src/commonMain/kotlin/jetbrains/livemap/core/MetricsService.kt +++ b/livemap/src/commonMain/kotlin/jetbrains/livemap/core/MetricsService.kt @@ -13,7 +13,7 @@ class MetricsService (private val mySystemTime: SystemTime) { private var myBeginTime: Long = 0 - var totalUpdateTime = 0.0 + var totalUpdateTime = 0L private set private val myValuesMap = HashMap() @@ -38,7 +38,7 @@ class MetricsService (private val mySystemTime: SystemTime) { fun reset() { myMeasures.clear() - totalUpdateTime = 0.0 + totalUpdateTime = 0L } fun slowestSystem(): Pair? { diff --git a/livemap/src/commonMain/kotlin/jetbrains/livemap/regions/RegionRenderer.kt b/livemap/src/commonMain/kotlin/jetbrains/livemap/regions/RegionRenderer.kt index 2597271a1b3..d82f095840f 100644 --- a/livemap/src/commonMain/kotlin/jetbrains/livemap/regions/RegionRenderer.kt +++ b/livemap/src/commonMain/kotlin/jetbrains/livemap/regions/RegionRenderer.kt @@ -10,8 +10,8 @@ import jetbrains.livemap.core.ecs.EcsEntity import jetbrains.livemap.geometry.ScreenGeometryComponent import jetbrains.livemap.placement.ScreenLoopComponent import jetbrains.livemap.rendering.Renderer -import jetbrains.livemap.rendering.Renderers -import jetbrains.livemap.rendering.Utils +import jetbrains.livemap.rendering.Renderers.drawLines +import jetbrains.livemap.rendering.StyleComponent import jetbrains.livemap.scaling.ScaleComponent class RegionRenderer : Renderer { @@ -28,9 +28,11 @@ class RegionRenderer : Renderer { } } - Utils.apply(entity.get(), ctx) - - ctx.beginPath() + entity.get().apply { + ctx.setFillStyle(fillColor) + ctx.setStrokeStyle(strokeColor) + ctx.setLineWidth(strokeWidth) + } val scale = fragments.first().get().scale @@ -42,16 +44,10 @@ class RegionRenderer : Renderer { ctx.save() ctx.translate(origin.x, origin.y) ctx.scale(scale, scale) - Renderers.drawLines( - screenGeometry.geometry, - ctx - ) { nop() } + ctx.beginPath() + drawLines(screenGeometry.geometry, ctx, afterPolygon = Context2d::fill) ctx.restore() } } - - ctx.fill() } - - private fun nop() {} -} \ No newline at end of file +} diff --git a/livemap/src/commonMain/kotlin/jetbrains/livemap/rendering/Utils.kt b/livemap/src/commonMain/kotlin/jetbrains/livemap/rendering/Utils.kt index 77511e501ad..62edc99d6c2 100644 --- a/livemap/src/commonMain/kotlin/jetbrains/livemap/rendering/Utils.kt +++ b/livemap/src/commonMain/kotlin/jetbrains/livemap/rendering/Utils.kt @@ -11,12 +11,6 @@ import kotlin.math.sqrt object Utils { - fun apply(styleComponent: StyleComponent, ctx: Context2d) { - ctx.setFillStyle(styleComponent.fillColor) - ctx.setStrokeStyle(styleComponent.strokeColor) - ctx.setLineWidth(styleComponent.strokeWidth) - } - internal fun drawPath(ctx: Context2d, radius: Double, shape: Int) { when (shape) { 0 -> square(ctx, radius)