gui buttons will now trigger the action only once per click

This commit is contained in:
minjaesong
2022-12-14 15:58:01 +09:00
parent 86af873bdf
commit 45dd5be3f2
3 changed files with 49 additions and 43 deletions

View File

@@ -71,12 +71,7 @@ class VM(
init {
println("[VM] Creating new VM with ID of $id, memsize $memsize")
peripheralTable[0] = PeripheralEntry(
IOSpace(this),
// HW_RESERVE_SIZE,
// MMIO_SIZE.toInt() - 256,
// 64
)
peripheralTable[0] = PeripheralEntry(IOSpace(this))
}
fun killAllContexts() {

View File

@@ -36,60 +36,68 @@ class ProfilesMenu(parent: VMEmuExecutable, x: Int, y: Int, w: Int, h: Int) : Em
}
private var guiClickLatched = arrayOf(false, false, false, false, false, false, false, false)
override fun update() {
if (Gdx.input.isButtonPressed(Buttons.LEFT)) {
val mx = Gdx.input.x - x
val my = Gdx.input.y - y
if (!guiClickLatched[Buttons.LEFT]) {
val mx = Gdx.input.x - x
val my = Gdx.input.y - y
// make profile list work
if (mx in 10 until 10+228) {
if (my in 11 until 11+446) {
val li = (my - 11) / (2*FONT.H)
// make profile list work
if (mx in 10 until 10 + 228) {
if (my in 11 until 11 + 446) {
val li = (my - 11) / (2 * FONT.H)
if (li < profileNames.size - profilesScroll)
selectedProfileIndex = li + profilesScroll
else
selectedProfileIndex = null
if (li < profileNames.size - profilesScroll)
selectedProfileIndex = li + profilesScroll
else
selectedProfileIndex = null
}
}
}
// make controls for the selected profile work
if (selectedProfileIndex != null) profileNames[selectedProfileIndex!!].let { profileName ->
val theVM = parent.getVMbyProfileName(profileName)
if (theVM != null) {
// viewport selector
if (my in 427..453) {
if (mx in 253..640) {
val oldIndex = parent.getViewportForTheVM(theVM)
val newIndex = ((mx - 253) / 14).let { if (it == 0) null else it - 1 }
// make controls for the selected profile work
if (selectedProfileIndex != null) profileNames[selectedProfileIndex!!].let { profileName ->
val theVM = parent.getVMbyProfileName(profileName)
if (theVM != null) {
// viewport selector
if (my in 427..453) {
if (mx in 253..640) {
val oldIndex = parent.getViewportForTheVM(theVM)
val newIndex = ((mx - 253) / 14).let { if (it == 0) null else it - 1 }
if (newIndex == null || newIndex in 0 until viewportColumns * viewportRows - 1) {
if (oldIndex == null && newIndex != null) {
parent.addVMtoView(theVM, profileName, newIndex)
}
else if (oldIndex != null) {
parent.moveView(oldIndex, newIndex)
if (newIndex == null || newIndex in 0 until viewportColumns * viewportRows - 1) {
if (oldIndex == null && newIndex != null) {
parent.addVMtoView(theVM, profileName, newIndex)
}
else if (oldIndex != null) {
parent.moveView(oldIndex, newIndex)
}
}
}
}
}
// stop and play buttons
else if (my in 375..401) {
// stop and play buttons
else if (my in 375..401) {
println("vm: $profileName; isRunning = ${theVM.isRunning}; mx = $mx")
println("vm: $profileName; isRunning = ${theVM.isRunning}; mx = $mx")
if (mx in 377..390 && theVM.isRunning) {
parent.killVMenv(theVM)
}
else if (mx in 398..412 && !theVM.isRunning) {
parent.initVMenv(theVM)
if (mx in 374..394 && theVM.isRunning) {
parent.killVMenv(theVM)
}
else if (mx in 395..415 && !theVM.isRunning) {
parent.initVMenv(theVM)
}
}
}
}
guiClickLatched[Buttons.LEFT] = true
}
}
else {
guiClickLatched[Buttons.LEFT] = false
}
}

View File

@@ -186,7 +186,7 @@ class VMEmuExecutable(val windowWidth: Int, val windowHeight: Int, var panelsX:
private fun changeActiveSession(index: Int?) {
currentVMselection = index
// TODO somehow implement the inputstream that cares about the currentVMselection
Gdx.input.inputProcessor = if (currentVMselection != null) vms[currentVMselection!!]?.vm?.getIO() else vmEmuInputProcessor
Gdx.input.inputProcessor = if (currentVMselection != null) vms[currentVMselection!!]?.vm?.getIO() ?: null else vmEmuInputProcessor
}
internal fun initVMenv(vm: VM) {
@@ -214,6 +214,9 @@ class VMEmuExecutable(val windowWidth: Int, val windowHeight: Int, var panelsX:
vmRunners[vm.id]?.close()
coroutineJobs[vm.id]?.cancel()
// re-create the IOSpace (peripheral index 0)
vm.peripheralTable[0] = PeripheralEntry(IOSpace(vm))
}
private fun setCameraPosition(newX: Float, newY: Float) {