Implement 'pan-with-cursor' for relative action mode
This commit is contained in:
parent
ce2736ed20
commit
c6b28ea6f1
4 changed files with 48 additions and 0 deletions
|
|
@ -266,6 +266,7 @@ class Dispatcher(private val activity: VncActivity) {
|
||||||
y = y.coerceIn(0f, viewModel.frameState.fbHeight - 1)
|
y = y.coerceIn(0f, viewModel.frameState.fbHeight - 1)
|
||||||
}
|
}
|
||||||
doButtonDown(PointerButton.None, pointerPosition)
|
doButtonDown(PointerButton.None, pointerPosition)
|
||||||
|
viewModel.showFbPoint(pointerPosition)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun doDrag(p: PointF, dx: Float, dy: Float) {
|
override fun doDrag(p: PointF, dx: Float, dy: Float) {
|
||||||
|
|
|
||||||
|
|
@ -194,6 +194,24 @@ class FrameState(private val minZoomScale: Float = 0.5F, private val maxZoomScal
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Makes sure that framebuffer point [fbX],[fbY] is visible.
|
||||||
|
* If point is outside of visible area, frame is panned to make the it visible.
|
||||||
|
*/
|
||||||
|
fun showFbPoint(fbX: Float, fbY: Float) {
|
||||||
|
val vpX = fbX * scale + frameX
|
||||||
|
val vpY = fbY * scale + frameY
|
||||||
|
var dx = 0f
|
||||||
|
var dy = 0f
|
||||||
|
|
||||||
|
if (vpX < 0) dx = -vpX
|
||||||
|
if (vpX >= vpWidth) dx = vpWidth - vpX - 1
|
||||||
|
if (vpY < 0) dy = -vpY
|
||||||
|
if (vpY >= vpHeight) dy = vpHeight - vpY - 1
|
||||||
|
|
||||||
|
pan(dx, dy)
|
||||||
|
}
|
||||||
|
|
||||||
private fun calculateBaseScale() {
|
private fun calculateBaseScale() {
|
||||||
if (fbHeight == 0F || fbWidth == 0F || windowHeight == 0F)
|
if (fbHeight == 0F || fbWidth == 0F || windowHeight == 0F)
|
||||||
return //Not enough info yet
|
return //Not enough info yet
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
package com.gaurav.avnc.viewmodel
|
package com.gaurav.avnc.viewmodel
|
||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
|
import android.graphics.PointF
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
|
|
@ -277,6 +278,11 @@ class VncViewModel(app: Application) : BaseViewModel(app), VncClient.Observer {
|
||||||
frameViewRef.get()?.requestRender()
|
frameViewRef.get()?.requestRender()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun showFbPoint(fbPoint: PointF) {
|
||||||
|
frameState.showFbPoint(fbPoint.x, fbPoint.y)
|
||||||
|
frameViewRef.get()?.requestRender()
|
||||||
|
}
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Clipboard Sync
|
* Clipboard Sync
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
|
||||||
|
|
@ -156,4 +156,27 @@ class FrameStateTest {
|
||||||
assertEquals(-100f, state.frameX) //Right side of frame and Viewport are aligned
|
assertEquals(-100f, state.frameX) //Right side of frame and Viewport are aligned
|
||||||
assertEquals(-100f, state.frameY) //Bottom side of frame and Viewport are aligned
|
assertEquals(-100f, state.frameY) //Bottom side of frame and Viewport are aligned
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun showFbPointTest() {
|
||||||
|
val state = FrameState()
|
||||||
|
state.setViewportSize(50f, 50f)
|
||||||
|
state.setFramebufferSize(100f, 100f)
|
||||||
|
|
||||||
|
state.showFbPoint(49f, 49f)
|
||||||
|
assertEquals(0f, state.frameX)
|
||||||
|
assertEquals(0f, state.frameY)
|
||||||
|
|
||||||
|
state.showFbPoint(50f, 50f)
|
||||||
|
assertEquals(-1f, state.frameX)
|
||||||
|
assertEquals(-1f, state.frameY)
|
||||||
|
|
||||||
|
state.showFbPoint(0f, 0f)
|
||||||
|
assertEquals(0f, state.frameX)
|
||||||
|
assertEquals(0f, state.frameY)
|
||||||
|
|
||||||
|
state.showFbPoint(99f, 99f)
|
||||||
|
assertEquals(-50f, state.frameX)
|
||||||
|
assertEquals(-50f, state.frameY)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Reference in a new issue