Rotate two overlayed graphic

devjet

Member
Licensed User
Longtime User
Hello,
I have been playing with two graphics on top of each other, trying to turn them accordimng a set value it works more or less, but shifts to the side so that it seems there are 3 graphics.
Could some one have a look at it and let me know how this could be improved is properly done

enter RWY=250 Wdir 20 and click twice, then change Wdir to 30
Thanks!

File-Upload.net - degree.zip

B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   Dim DestRect, DestRect1 As Rect
   Dim iDegrees,iDegrees1, AngleStart,AngleStart1, AngleEnd,AngleEnd1, AngleStep, AngleStep1 As Float
End Sub
Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.

   Dim btnRotate As Button
   Dim edDegrees As EditText
   Dim edtWindDir As EditText
   Dim imgRunway As ImageView
   Dim imgWindDir As ImageView
   Dim Timer1 As Timer
   Dim Canvas1 As Canvas
   Dim Canvas2 As Canvas
   Dim Bitmap1 As Bitmap
   Dim Bitmap2 As Bitmap
   Dim a As Animation
End Sub

Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
   End If
   Activity.LoadLayout("layWind")
   Canvas1.Initialize(imgRunway)
   DestRect.Initialize(0dip, 0dip, 230dip, 230dip)
   Bitmap1.Initialize(File.DirAssets, "Runway.png") 
   iDegrees = 0
   Timer1.Initialize("Timer1",100)
   AngleStep=200
   
   '------ Wind Pointer   ------------------------------------------
   Canvas2.Initialize(imgWindDir)
   DestRect1.Initialize(0dip, 0dip, 256dip, 256dip)
   Bitmap2.Initialize(File.DirAssets, "widdirarrow.png") 
   iDegrees1 = 0
   Timer1.Initialize("Timer1",100)
   AngleStep1=200
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub btnRotate_Click
'   If edDegrees.Text = ""    Then 'edDegrees.Text = "0"
'      ToastMessageShow ("Wrong less than 1°",False)
'      Return
'   End If
'   If edDegrees.Text = >360 Then   
'      ToastMessageShow ("Wrong more than 360°",False)
'      Return
'   End If
   RWY= edDegrees.Text
   AngleEnd=0+RWY
   AngleStep=AngleStep
   Timer1.Enabled=True
   
   '------ Wind Pointer --------------------------------------------
   WD= edtWindDir.Text
   AngleEnd1=0+WD
   AngleStep1=AngleStep1
   Timer1.Enabled=True
   
End Sub

Sub Timer1_Tick
'   If iDegrees>=AngleEnd-AngleStep AND AngleStep=AngleStep1 Then
'      AngleStep=AngleStep1/3
'   End If
   iDegrees=iDegrees+AngleStep
   If iDegrees>=AngleEnd Then
      Timer1.Enabled=False
      iDegrees=AngleEnd
      AngleStart=AngleEnd
   End If
   Canvas1.DrawBitmapRotated(Bitmap1,Null,DestRect,iDegrees)
   imgRunway.Invalidate2(DestRect)
   
   
   iDegrees1=iDegrees1+AngleStep1
   If iDegrees1>=AngleEnd1 Then
      Timer1.Enabled=False
      iDegrees1=AngleEnd1
      AngleStart1=AngleEnd1
   End If
   Canvas1.DrawBitmapRotated(Bitmap2,Null,DestRect1,iDegrees1)
   imgWindDir.Invalidate2(DestRect1)
End Sub
 
Last edited:

klaus

Expert
Licensed User
Longtime User
The problem is that you initialize the bitmap with the arrow to a wrong size.
Replace:
DestRect1.Initialize(0dip, 0dip, 256dip, 256dip)
by
DestRect1.Initialize(0dip, 0dip, 230dip, 230dip)
and it works as you expect it.

You should also set the ImageView to the same values.
Is there a reason why you shrink the runway and arrow bitmp from 240*240 down to 230*230 ?

Be carefull, the arrow in the original image is not centered !?

Best regards.
 
Upvote 0

devjet

Member
Licensed User
Longtime User
Good day Klaus,
I shrinked the overlaying image in order not to hide the degree scale. I guess I have to resize it and keep edges transparent.
Ok I will do that, Thanks!
- Any idea why it only takes the correct angle after clicking twice?
- And would there be a slicker way to to it... less code?
Or is that ok? The reason I am asking is if I add more overlay graphics it gets crowded
Regards
Johannes-U.
 
Upvote 0
Top