diff --git a/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/gui/Visualizer.java b/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/gui/Visualizer.java index 2f0f5b30..faa8c32e 100644 --- a/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/gui/Visualizer.java +++ b/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/gui/Visualizer.java @@ -26,8 +26,10 @@ import com.formdev.flatlaf.FlatLaf; import com.github.serivesmejia.eocvsim.Build; import com.github.serivesmejia.eocvsim.EOCVSim; +import com.github.serivesmejia.eocvsim.gui.component.CollapsiblePanelX; import com.github.serivesmejia.eocvsim.gui.component.visualizer.*; import com.github.serivesmejia.eocvsim.gui.component.visualizer.opmode.OpModeSelectorPanel; +import com.github.serivesmejia.eocvsim.gui.component.visualizer.pipeline.SourceSelectorPanel; import io.github.deltacv.vision.external.gui.SwingOpenCvViewport; import com.github.serivesmejia.eocvsim.gui.component.tuner.ColorPicker; import com.github.serivesmejia.eocvsim.gui.component.tuner.TunableFieldPanel; @@ -64,7 +66,7 @@ public class Visualizer { public SwingOpenCvViewport viewport = null; public TopMenuBar menuBar = null; - public JPanel tunerMenuPanel = new JPanel(); + public JPanel tunerMenuPanel; public JPanel rightContainer = null; @@ -77,6 +79,8 @@ public class Visualizer { public TelemetryPanel telemetryPanel; + public JPanel tunerCollapsible; + private String title = "EasyOpenCV Simulator v" + Build.standardVersionString; private String titleMsg = "No pipeline"; private String beforeTitle = ""; @@ -171,7 +175,14 @@ public void init(Theme theme) { //global frame.getContentPane().setDropTarget(new InputSourceDropTarget(eocvSim)); - //frame.add(tunerMenuPanel, BorderLayout.SOUTH); + tunerCollapsible = new CollapsiblePanelX("Tuner", null); + tunerCollapsible.setLayout(new BoxLayout(tunerCollapsible, BoxLayout.LINE_AXIS)); + tunerCollapsible.setVisible(false); + + JScrollPane tunerScrollPane = new JScrollPane(tunerMenuPanel); + tunerCollapsible.add(tunerScrollPane); + + frame.add(tunerCollapsible, BorderLayout.SOUTH); frame.add(rightContainer, BorderLayout.EAST); //initialize other various stuff of the frame @@ -329,6 +340,8 @@ public void updateTunerFields(List fields) { tunerMenuPanel.add(fieldPanel); fieldPanel.showFieldPanel(); } + + tunerCollapsible.setVisible(!fields.isEmpty()); } public void asyncCompilePipelines() { @@ -349,7 +362,7 @@ public void asyncCompilePipelines() { public void compilingUnsupported() { asyncPleaseWaitDialog( - "Runtime compiling is not supported on this JVM", + "Runtime pipeline builds are not supported on this JVM", "For further info, check the EOCV-Sim GitHub repo", "Close", new Dimension(320, 160), @@ -397,7 +410,7 @@ public void createVSCodeWorkspace() { } public void askOpenVSCode() { - DialogFactory.createYesOrNo(frame, "A new workspace was created. Do you wanna open VS Code?", "", + DialogFactory.createYesOrNo(frame, "A new workspace was created. Do you want to open VS Code?", "", (result) -> { if(result == 0) { VSCodeLauncher.INSTANCE.asyncLaunch(eocvSim.workspaceManager.getWorkspaceFile()); diff --git a/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/gui/component/CollapsiblePanelX.kt b/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/gui/component/CollapsiblePanelX.kt index 58c6c386..d2a00f34 100644 --- a/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/gui/component/CollapsiblePanelX.kt +++ b/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/gui/component/CollapsiblePanelX.kt @@ -1,3 +1,5 @@ +package com.github.serivesmejia.eocvsim.gui.component + import java.awt.Color import java.awt.Dimension import java.awt.event.MouseAdapter @@ -7,13 +9,17 @@ import javax.swing.JPanel import javax.swing.border.LineBorder import javax.swing.border.TitledBorder -class JCollapsiblePanel(title: String?, titleCol: Color?) : JPanel() { +class CollapsiblePanelX(title: String?, titleCol: Color?) : JPanel() { private val border: TitledBorder private var visibleSize: Dimension? = null private var collapsible = true + var isHidden = false + private set + init { border = TitledBorder(title) + border.titleColor = titleCol border.border = LineBorder(Color.white) setBorder(border) @@ -27,17 +33,22 @@ class JCollapsiblePanel(title: String?, titleCol: Color?) : JPanel() { if (!collapsible) { return } - val i = getBorder().getBorderInsets(this@JCollapsiblePanel) + + val i = getBorder().getBorderInsets(this@CollapsiblePanelX) if (e.x < i.left + size.width && e.y < i.bottom + size.height) { - if (visibleSize == null || height > size.height) { - visibleSize = getSize() - } - if (getSize().height < visibleSize!!.height) { - maximumSize = Dimension(visibleSize!!.width, 20000) - minimumSize = visibleSize - } else { - maximumSize = Dimension(visibleSize!!.width, size.height) + + for(e in components) { + e.isVisible = !isHidden + + border.title = if(isHidden) { + "$title (hidden)" + } else { + title + } + + isHidden = !isHidden } + revalidate() e.consume() } diff --git a/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/gui/component/visualizer/PipelineOpModeSwitchablePanel.kt b/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/gui/component/visualizer/PipelineOpModeSwitchablePanel.kt index 516d479f..486eb1d1 100644 --- a/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/gui/component/visualizer/PipelineOpModeSwitchablePanel.kt +++ b/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/gui/component/visualizer/PipelineOpModeSwitchablePanel.kt @@ -4,6 +4,7 @@ import com.github.serivesmejia.eocvsim.EOCVSim import com.github.serivesmejia.eocvsim.gui.component.visualizer.opmode.OpModeControlsPanel import com.github.serivesmejia.eocvsim.gui.component.visualizer.opmode.OpModeSelectorPanel import com.github.serivesmejia.eocvsim.gui.component.visualizer.pipeline.PipelineSelectorPanel +import com.github.serivesmejia.eocvsim.gui.component.visualizer.pipeline.SourceSelectorPanel import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking @@ -31,7 +32,7 @@ class PipelineOpModeSwitchablePanel(val eocvSim: EOCVSim) : JTabbedPane() { init { pipelinePanel.layout = GridBagLayout() - pipelineSelectorPanel.border = EmptyBorder(0, 20, 0, 20) + pipelineSelectorPanel.border = EmptyBorder(20, 20, 0, 20) pipelinePanel.add(pipelineSelectorPanel, GridBagConstraints().apply { gridx = 0 gridy = 0 @@ -41,7 +42,7 @@ class PipelineOpModeSwitchablePanel(val eocvSim: EOCVSim) : JTabbedPane() { fill = GridBagConstraints.BOTH }) - sourceSelectorPanel.border = EmptyBorder(0, 20, 0, 20) + sourceSelectorPanel.border = EmptyBorder(0, 20, -10, 20) pipelinePanel.add(sourceSelectorPanel, GridBagConstraints().apply { gridx = 0 diff --git a/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/gui/component/visualizer/TelemetryPanel.kt b/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/gui/component/visualizer/TelemetryPanel.kt index e489f25e..d95ef6dc 100644 --- a/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/gui/component/visualizer/TelemetryPanel.kt +++ b/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/gui/component/visualizer/TelemetryPanel.kt @@ -27,10 +27,10 @@ class TelemetryPanel : JPanel(), TelemetryTransmissionReceiver { telemetryLabel.font = telemetryLabel.font.deriveFont(20.0f) telemetryLabel.horizontalAlignment = JLabel.CENTER - add(telemetryLabel, GridBagConstraints().apply { - gridy = 0 - ipady = 20 - }) + // add(telemetryLabel, GridBagConstraints().apply { + // gridy = 0 + // ipady = 20 + //}) telemetryScroll.setViewportView(telemetryList) telemetryScroll.verticalScrollBarPolicy = JScrollPane.VERTICAL_SCROLLBAR_ALWAYS @@ -52,7 +52,7 @@ class TelemetryPanel : JPanel(), TelemetryTransmissionReceiver { telemetryList.selectionMode = ListSelectionModel.MULTIPLE_INTERVAL_SELECTION add(telemetryScroll, GridBagConstraints().apply { - gridy = 1 + gridy = 0 weightx = 0.5 weighty = 1.0 diff --git a/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/gui/component/visualizer/TopMenuBar.kt b/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/gui/component/visualizer/TopMenuBar.kt index 0679428e..8159bd8b 100644 --- a/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/gui/component/visualizer/TopMenuBar.kt +++ b/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/gui/component/visualizer/TopMenuBar.kt @@ -49,7 +49,6 @@ class TopMenuBar(visualizer: Visualizer, eocvSim: EOCVSim) : JMenuBar() { @JvmField val mFileMenu = JMenu("File") @JvmField val mWorkspMenu = JMenu("Workspace") - @JvmField val mEditMenu = JMenu("Edit") @JvmField val mHelpMenu = JMenu("Help") @JvmField val workspCompile = JMenuItem("Build java files") @@ -90,6 +89,11 @@ class TopMenuBar(visualizer: Visualizer, eocvSim: EOCVSim) : JMenuBar() { mFileMenu.addSeparator() + val editSettings = JMenuItem("Settings") + editSettings.addActionListener { DialogFactory.createConfigDialog(eocvSim) } + + mFileMenu.add(editSettings) + val fileRestart = JMenuItem("Restart") fileRestart.addActionListener { eocvSim.onMainUpdate.doOnce { eocvSim.restart() } } @@ -137,14 +141,6 @@ class TopMenuBar(visualizer: Visualizer, eocvSim: EOCVSim) : JMenuBar() { add(mWorkspMenu) - // EDIT - - val editSettings = JMenuItem("Settings") - editSettings.addActionListener { DialogFactory.createConfigDialog(eocvSim) } - - mEditMenu.add(editSettings) - add(mEditMenu) - // HELP val helpUsage = JMenuItem("Documentation") diff --git a/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/gui/component/visualizer/pipeline/PipelineSelectorPanel.kt b/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/gui/component/visualizer/pipeline/PipelineSelectorPanel.kt index 593af4be..55d64690 100644 --- a/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/gui/component/visualizer/pipeline/PipelineSelectorPanel.kt +++ b/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/gui/component/visualizer/pipeline/PipelineSelectorPanel.kt @@ -79,10 +79,10 @@ class PipelineSelectorPanel(private val eocvSim: EOCVSim) : JPanel() { pipelineSelectorLabel.horizontalAlignment = JLabel.CENTER - add(pipelineSelectorLabel, GridBagConstraints().apply { - gridy = 0 - ipady = 20 - }) + //add(pipelineSelectorLabel, GridBagConstraints().apply { + // gridy = 0 + // ipady = 20 + //}) pipelineSelector.cellRenderer = PipelineListIconRenderer(eocvSim.pipelineManager) pipelineSelector.selectionMode = ListSelectionModel.SINGLE_SELECTION @@ -92,7 +92,7 @@ class PipelineSelectorPanel(private val eocvSim: EOCVSim) : JPanel() { pipelineSelectorScroll.horizontalScrollBarPolicy = JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED add(pipelineSelectorScroll, GridBagConstraints().apply { - gridy = 1 + gridy = 0 weightx = 0.5 weighty = 1.0 @@ -103,7 +103,7 @@ class PipelineSelectorPanel(private val eocvSim: EOCVSim) : JPanel() { }) add(buttonsPanel, GridBagConstraints().apply { - gridy = 2 + gridy = 1 ipady = 20 }) diff --git a/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/gui/component/visualizer/SourceSelectorPanel.kt b/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/gui/component/visualizer/pipeline/SourceSelectorPanel.kt similarity index 94% rename from EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/gui/component/visualizer/SourceSelectorPanel.kt rename to EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/gui/component/visualizer/pipeline/SourceSelectorPanel.kt index 12830556..cd4d77df 100644 --- a/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/gui/component/visualizer/SourceSelectorPanel.kt +++ b/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/gui/component/visualizer/pipeline/SourceSelectorPanel.kt @@ -1,7 +1,8 @@ -package com.github.serivesmejia.eocvsim.gui.component.visualizer +package com.github.serivesmejia.eocvsim.gui.component.visualizer.pipeline import com.github.serivesmejia.eocvsim.EOCVSim import com.github.serivesmejia.eocvsim.gui.component.PopupX +import com.github.serivesmejia.eocvsim.gui.component.visualizer.CreateSourcePanel import com.github.serivesmejia.eocvsim.gui.util.icon.SourcesListIconRenderer import com.github.serivesmejia.eocvsim.pipeline.PipelineManager import com.github.serivesmejia.eocvsim.util.extension.clipUpperZero @@ -37,10 +38,10 @@ class SourceSelectorPanel(private val eocvSim: EOCVSim) : JPanel() { sourceSelectorLabel.font = sourceSelectorLabel.font.deriveFont(20.0f) sourceSelectorLabel.horizontalAlignment = JLabel.CENTER - add(sourceSelectorLabel, GridBagConstraints().apply { - gridy = 0 - ipady = 20 - }) + // add(sourceSelectorLabel, GridBagConstraints().apply { + // gridy = 0 + // ipady = 20 + //}) sourceSelector.selectionMode = ListSelectionModel.SINGLE_SELECTION @@ -49,7 +50,7 @@ class SourceSelectorPanel(private val eocvSim: EOCVSim) : JPanel() { sourceSelectorScroll.horizontalScrollBarPolicy = JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED add(sourceSelectorScroll, GridBagConstraints().apply { - gridy = 1 + gridy = 0 weightx = 0.5 weighty = 1.0 @@ -82,7 +83,7 @@ class SourceSelectorPanel(private val eocvSim: EOCVSim) : JPanel() { sourceSelectorButtonsContainer.add(sourceSelectorDeleteBtt) add(sourceSelectorButtonsContainer, GridBagConstraints().apply { - gridy = 2 + gridy = 1 ipady = 20 }) diff --git a/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/input/InputSourceManager.java b/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/input/InputSourceManager.java index 5cd65da5..c9cc01df 100644 --- a/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/input/InputSourceManager.java +++ b/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/input/InputSourceManager.java @@ -25,9 +25,8 @@ import com.github.serivesmejia.eocvsim.EOCVSim; import com.github.serivesmejia.eocvsim.gui.Visualizer; -import com.github.serivesmejia.eocvsim.gui.component.visualizer.SourceSelectorPanel; +import com.github.serivesmejia.eocvsim.gui.component.visualizer.pipeline.SourceSelectorPanel; import com.github.serivesmejia.eocvsim.input.source.ImageSource; -import com.github.serivesmejia.eocvsim.input.source.VideoSource; import com.github.serivesmejia.eocvsim.pipeline.PipelineManager; import com.github.serivesmejia.eocvsim.util.SysUtil; import org.opencv.core.Mat; diff --git a/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/pipeline/DefaultPipeline.java b/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/pipeline/DefaultPipeline.java index 121321f2..3ed276ca 100644 --- a/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/pipeline/DefaultPipeline.java +++ b/EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/pipeline/DefaultPipeline.java @@ -23,6 +23,10 @@ package com.github.serivesmejia.eocvsim.pipeline; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.Rect; import org.firstinspires.ftc.robotcore.external.Telemetry; import org.opencv.core.*; import org.opencv.imgproc.Imgproc; @@ -34,8 +38,20 @@ public class DefaultPipeline extends OpenCvPipeline { private Telemetry telemetry; + private Paint boxPaint; + private Paint textPaint; + public DefaultPipeline(Telemetry telemetry) { this.telemetry = telemetry; + + textPaint = new Paint(); + textPaint.setColor(Color.WHITE); + textPaint.setTextSize(30); + textPaint.setAntiAlias(true); + + boxPaint = new Paint(); + boxPaint.setColor(Color.BLACK); + boxPaint.setStyle(Paint.Style.FILL); } @Override @@ -51,32 +67,18 @@ public Mat processFrame(Mat input) { if (blur > 0 && blur % 2 == 1) { Imgproc.GaussianBlur(input, input, new Size(blur, blur), 0); + } else if (blur > 0) { + Imgproc.GaussianBlur(input, input, new Size(blur + 1, blur + 1), 0); } - // Outline - Imgproc.putText( - input, - "Default pipeline selected", - new Point(0, 22 * aspectRatioPercentage), - Imgproc.FONT_HERSHEY_PLAIN, - 2 * aspectRatioPercentage, - new Scalar(255, 255, 255), - (int) Math.round(5 * aspectRatioPercentage) - ); - - //Text - Imgproc.putText( - input, - "Default pipeline selected", - new Point(0, 22 * aspectRatioPercentage), - Imgproc.FONT_HERSHEY_PLAIN, - 2 * aspectRatioPercentage, - new Scalar(0, 0, 0), - (int) Math.round(2 * aspectRatioPercentage) - ); - return input; + } + + @Override + public void onDrawFrame(Canvas canvas, int onscreenWidth, int onscreenHeight, float scaleBmpPxToCanvasPx, float scaleCanvasDensity, Object userContext) { + canvas.drawRect(new Rect(0, 0, 385, 45), boxPaint); + canvas.drawText("Default pipeline selected", 5, 33, textPaint); } } diff --git a/Vision/src/main/java/org/openftc/easyopencv/OpenCvViewRenderer.java b/Vision/src/main/java/org/openftc/easyopencv/OpenCvViewRenderer.java index c93c0588..457d6cfc 100644 --- a/Vision/src/main/java/org/openftc/easyopencv/OpenCvViewRenderer.java +++ b/Vision/src/main/java/org/openftc/easyopencv/OpenCvViewRenderer.java @@ -74,7 +74,7 @@ public OpenCvViewRenderer(boolean renderingOffsceen, String fpsMeterDescriptor) metricsScale = 1.0f; - fpsMeterTextSize = 30 * metricsScale; + fpsMeterTextSize = 26 * metricsScale; statBoxW = (int) (450 * metricsScale); statBoxH = (int) (120 * metricsScale); statBoxTextLineSpacing = (int) (35 * metricsScale);