Hi Martin.
Thank you very much for your help.
I've been testing your library changes with your TouchImageViewDemo example and does not work as I expected. :BangHead:
Here I copied your sample program and I added some modifications and comments for you to see how I want it to work (green text)
My mistake was to ask that the image does not move when scales = 1, but what I need is not to move when scale is equal that the initials values (XScaleInitial and YScaleInitial in the example below)
'Activity module
Sub Process_Globals
Dim SourceImageRect, TouchImageViewRect As Rect
Dim XScaleInitial ,YScaleInitial As Float
End Sub
Sub Globals
Dim TouchImageView1 As TouchImageView
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.AddMenuItem("Create Log", "CreateLog")
TouchImageView1.Initialize("TouchImageView1")
Activity.AddView(TouchImageView1, 0, 0, 100%x, 100%y)
TouchImageView1.MinScale=0.25 ' default is 0.5
TouchImageView1.MaxScale=2 ' default is 1.5
TouchImageView1.TranslatePadding=128dip ' default is 64dip
TouchImageView1.TouchEnabled=True
TouchImageView1.Gravity=Gravity.FILL
TouchImageView1.SetBackgroundImage(LoadBitmap(File.DirAssets, "b4a_logo.png"))
Dim Bitmap1 As Bitmap
Bitmap1.Initialize(File.DirAssets, "cromer_pier.jpg")
TouchImageView1.SetBitmap(Bitmap1)
If FirstTime Then
' Rect parameters are: left, top, right, bottom
SourceImageRect.Initialize(0, 0, Bitmap1.Width, Bitmap1.Height)
TouchImageViewRect.Initialize(0, 0, TouchImageView1.Width, TouchImageView1.Height)
End If
' if the scaling process scales the image to less than the current MinScale or more than the current MaxScale then MinScale or MaxScale will be adjusted
TouchImageView1.ScaleSrcRectToDestRect(SourceImageRect, TouchImageViewRect, "CENTER") ' make string a static constant in library
XScaleInitial=TouchImageView1.ScaleX
YScaleInitial=TouchImageView1.ScaleY
TouchImageView1.MinScale=XScaleInitial 'I just want to zoom-in
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
TouchImageViewRect=TouchImageView1.GetDestRect
End Sub
Sub CreateLog_Click
TouchImageView1.CreateLog
End Sub
Sub TouchImageView1_Click(X As Int, Y As Int)
Log("Click X="&X&", Y="&Y)
' zoom the image in by 5% on the clicked point
' the new scale factor will be the previous scale factor * 1.05
TouchImageView1.PreScale(1.05, X, Y)
End Sub
Sub TouchImageView1_LongClick(X As Int, Y As Int)
Log("LongClick X="&X&", Y="&Y)
' set the zoom/scale to 100%
' in this demo ScaleX and ScaleY will always be equal
'TouchImageView1.PreScale(1/TouchImageView1.ScaleX, X, Y)
'restore initial scale and position
TouchImageView1.ScaleSrcRectToDestRect(SourceImageRect, TouchImageViewRect, "CENTER")
End Sub
Thanks