Skip to content

Commit

Permalink
Improve debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
zsmb13 committed Oct 7, 2023
1 parent 00e2382 commit 3209084
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
26 changes: 22 additions & 4 deletions src/nativeMain/kotlin/BouncingLogo.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import config.Preferences
import config.Preferences.IS_DEBUG
import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.useContents
import platform.AppKit.NSImage
import platform.AppKit.NSImageScaleProportionallyUpOrDown
import platform.AppKit.NSImageView
import platform.AppKit.imageForResource
import platform.AppKit.*
import platform.CoreGraphics.CGColorCreateSRGB
import platform.Foundation.NSBundle
import platform.Foundation.NSMakeRect
Expand Down Expand Up @@ -70,8 +68,25 @@ class BouncingLogo(
view.addSubview(this)
}

private val debugTextView by lazy {
NSTextView().apply {
textColor = NSColor.redColor
drawsBackground = false
view.addSubview(this)
}
}

fun draw() {
imageView.frame = NSMakeRect(x = xPos - logoWidth / 2, y = yPos - logoHeight / 2, w = logoWidth, h = logoHeight)

if (IS_DEBUG) {
debugTextView.frame = NSMakeRect(x = xPos - logoWidth / 2, y = yPos - logoHeight / 2 - 40.0, w = 200.0, h = 40.0)
debugTextView.string = """
${images[index]} (${logoWidth.toInt()}x${logoHeight.toInt()})
x: ${xPos.toInt()} y: ${yPos.toInt()}
speed $speed
""".trimIndent()
}
}

fun animateOneFrame() {
Expand Down Expand Up @@ -133,5 +148,8 @@ class BouncingLogo(

fun dispose() {
imageView.removeFromSuperview()
if (IS_DEBUG) {
debugTextView.removeFromSuperview()
}
}
}
5 changes: 4 additions & 1 deletion src/nativeMain/kotlin/KotlinScreenSaverView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import platform.AppKit.NSWindow
import platform.Foundation.NSBundle
import platform.Foundation.NSRect
import platform.ScreenSaver.ScreenSaverView
import util.debugLog

fun create(): KotlinScreenSaverView = LogoScreenSaverView()
fun create(): KotlinScreenSaverView = LogoScreenSaverView().also {
debugLog { "Created KotlinScreenSaverView" }
}

abstract class KotlinScreenSaverView {
protected lateinit var view: ScreenSaverView
Expand Down
2 changes: 2 additions & 0 deletions src/nativeMain/kotlin/LogoScreenSaverView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import platform.Foundation.NSRect
import platform.Foundation.NSUserDefaultsDidChangeNotification
import platform.ScreenSaver.ScreenSaverView
import util.Debouncer
import util.debugLog

class LogoScreenSaverView : KotlinScreenSaverView() {
private val preferencesController by lazy { KotlinLogosPrefController() }
override val configureSheet: NSWindow?
get() = preferencesController.window

override fun init(screenSaverView: ScreenSaverView, isPreview: Boolean) {
debugLog { "LogoScreenSaverView inited" }
super.init(screenSaverView, isPreview)
screenSaverView.animationTimeInterval = 1 / 60.0
setupUserDefaultsObserver()
Expand Down
9 changes: 6 additions & 3 deletions src/nativeMain/kotlin/config/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ package config

import ImageSet
import imageSets
import kotlinx.cinterop.*
import kotlinx.cinterop.BetaInteropApi
import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.ObjCAction
import kotlinx.cinterop.copy
import platform.AppKit.*
import platform.Foundation.NSMakeRect
import platform.Foundation.NSSelectorFromString
import kotlin.reflect.KFunction
import kotlin.reflect.KMutableProperty0

@OptIn(ExperimentalForeignApi::class)
@OptIn(ExperimentalForeignApi::class, BetaInteropApi::class)
class KotlinLogosPrefController : NSWindowController, NSWindowDelegateProtocol {
public constructor(coder: platform.Foundation.NSCoder) : super(coder)

Expand Down Expand Up @@ -92,7 +95,7 @@ class KotlinLogosPrefController : NSWindowController, NSWindowDelegateProtocol {
private fun createComboBox(
title: String,
comboBoxProp: KMutableProperty0<NSComboBox>,
): NSStackView {
): NSStackView {
val stack = NSStackView()
stack.translatesAutoresizingMaskIntoConstraints = false

Expand Down

0 comments on commit 3209084

Please sign in to comment.