diff --git a/src/jvmMain/kotlin/dev/romainguy/kotlin/explorer/CodeTextArea.kt b/src/jvmMain/kotlin/dev/romainguy/kotlin/explorer/CodeTextArea.kt index 0fb8f8d6..9026fa67 100644 --- a/src/jvmMain/kotlin/dev/romainguy/kotlin/explorer/CodeTextArea.kt +++ b/src/jvmMain/kotlin/dev/romainguy/kotlin/explorer/CodeTextArea.kt @@ -18,8 +18,12 @@ package dev.romainguy.kotlin.explorer import dev.romainguy.kotlin.explorer.jump.JumpDetector import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea +import java.awt.BasicStroke import java.awt.Graphics import java.awt.Graphics2D +import java.awt.Polygon +import java.awt.RenderingHints +import java.awt.geom.GeneralPath import javax.swing.event.CaretEvent import javax.swing.event.CaretListener @@ -31,6 +35,7 @@ open class CodeTextArea( private var jumpOffsets: JumpOffsets? = null private var fullText = "" + var presentationMode: Boolean = false init { addCaretListener(::caretUpdate) @@ -54,7 +59,9 @@ open class CodeTextArea( override fun paintComponent(g: Graphics?) { super.paintComponent(g) jumpOffsets?.let { jump -> - val padding = 6 + val scale = if (presentationMode) 2 else 1 + val padding = 6 * scale + val triangleSize = 8 * scale val bounds1 = modelToView2D(jump.src) val bounds2 = modelToView2D(jump.dst) @@ -65,11 +72,23 @@ open class CodeTextArea( val x2 = bounds2.x.toInt() - padding val y2 = (bounds2.y + lineHeight / 2).toInt() - val x0 = modelToView2D(2).x.toInt() + val x0 = modelToView2D(4).x.toInt() + val g2 = g as Graphics2D + g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON) + g2.stroke = BasicStroke(scale.toFloat()) g2.drawLine(x1, y1, x0, y1) g2.drawLine(x0, y1, x0, y2) - g2.drawLine(x0, y2, x2, y2) + g2.drawLine(x0, y2, x2 - triangleSize / 2, y2) + + g2.fill(GeneralPath().apply { + val fx = x2.toFloat() + val fy = y2.toFloat() + 0.5f + val fs = triangleSize.toFloat() + moveTo(fx, fy) + lineTo(fx - fs, fy - fs / 2.0f) + lineTo(fx - fs, fy + fs / 2.0f) + }) } } diff --git a/src/jvmMain/kotlin/dev/romainguy/kotlin/explorer/KotlinExplorer.kt b/src/jvmMain/kotlin/dev/romainguy/kotlin/explorer/KotlinExplorer.kt index 659bdd3f..079620c9 100644 --- a/src/jvmMain/kotlin/dev/romainguy/kotlin/explorer/KotlinExplorer.kt +++ b/src/jvmMain/kotlin/dev/romainguy/kotlin/explorer/KotlinExplorer.kt @@ -55,10 +55,7 @@ import org.jetbrains.jewel.intui.window.decoratedWindow import org.jetbrains.jewel.intui.window.styling.dark import org.jetbrains.jewel.intui.window.styling.light import org.jetbrains.jewel.ui.ComponentStyling -import org.jetbrains.jewel.ui.component.DefaultButton -import org.jetbrains.jewel.ui.component.Icon -import org.jetbrains.jewel.ui.component.Text -import org.jetbrains.jewel.ui.component.TextField +import org.jetbrains.jewel.ui.component.* import org.jetbrains.jewel.window.DecoratedWindow import org.jetbrains.jewel.window.TitleBar import org.jetbrains.jewel.window.newFullscreenControls @@ -197,7 +194,7 @@ private fun SourcePanel(sourceTextArea: RSyntaxTextArea, explorerState: Explorer }, update = { sourceTextArea.text = explorerState.sourceCode - sourceTextArea.setFont(explorerState) + sourceTextArea.updateStyle(explorerState) } ) } @@ -210,7 +207,7 @@ private fun TextPanel(title: String, textArea: RSyntaxTextArea, explorerState: E SwingPanel( modifier = Modifier.fillMaxSize(), factory = { RTextScrollPane(textArea) }, - update = { textArea.setFont(explorerState) }) + update = { textArea.updateStyle(explorerState) }) } } @@ -286,10 +283,11 @@ private fun FrameWindowScope.MainMenu( val onShowPanelChanged: (Boolean) -> Unit = { onPanelsUpdated() } MenuCheckboxItem("Show DEX", Ctrl(D), explorerState::showDex, onShowPanelChanged) MenuCheckboxItem("Show OAT", Ctrl(O), explorerState::showOat, onShowPanelChanged) - MenuCheckboxItem("Presentation Mode", CtrlShift(P), explorerState::presentationMode) MenuCheckboxItem("Show Line Numbers", CtrlShift(L), explorerState::showLineNumbers) { onDexUpdate(null) } + Separator() + MenuCheckboxItem("Presentation Mode", CtrlShift(P), explorerState::presentationMode) } Menu("Compilation") { MenuCheckboxItem("Optimize with R8", CtrlShift(O), explorerState::optimize) @@ -402,9 +400,12 @@ private fun Settings( } } -private fun RSyntaxTextArea.setFont(explorerState: ExplorerState) { +private fun RSyntaxTextArea.updateStyle(explorerState: ExplorerState) { val presentation = explorerState.presentationMode font = font.deriveFont(if (presentation) FontSizePresentationMode else FontSizeEditingMode) + if (this is CodeTextArea) { + presentationMode = presentation + } } private fun updateTextArea(textArea: RSyntaxTextArea, text: String) {