Android Question Combine B4XCanvas with BitmapCreator / How to write text in BitmapCreator ?

Oke

Member
Licensed User
Longtime User
How to write text in BitmapCreator
Any sample code combining B4XCanvas with BitmapCreator ?
Thank You
 

klaus

Expert
Licensed User
Longtime User
What exactly do you draw with B4XCanvas and with BitmapCreator.
What do yo do with the BitmapCreator.Bitmap, or where do you copy it ?
I would suggest to use the B4XCanvas, draw all you can onto it and copy the specific BitmapCreator drawings with DrawBitmap onto the B4XCanvas.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I just made one.

B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    
    Private pnlTest As B4XView
    Private cvsTest As B4XCanvas
    Private bmcTest As BitmapCreator
    Private xFont As B4XFont
    Private rctText, rctDest As B4XRect
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    
    cvsTest.Initialize(pnlTest)
    bmcTest.Initialize(pnlTest.Width, pnlTest.Height)

    Draw
End Sub

Private Sub Draw
    xFont = xui.CreateDefaultFont(20)
    cvsTest.DrawRect(cvsTest.TargetRect, xui.Color_Red, True, 1)
    rctText = cvsTest.MeasureText("Test", xFont)
    
    bmcTest.Initialize(rctText.Width, rctText.Height)
    bmcTest.FillGradient(Array As Int(xui.Color_Blue, xui.Color_Magenta, xui.Color_Blue), bmcTest.TargetRect, "LEFT_RIGHT")

    rctDest.Initialize(100dip + rctText.Left, 50dip + rctText.Top , 100dip + rctText.Right, 50dip + rctText.Bottom)
    
    cvsTest.DrawBitmap(bmcTest.Bitmap, rctDest)
    
    cvsTest.DrawText("Test", 100dip, 50dip, xFont, xui.Color_Yellow, "LEFT")
End Sub

The background of the text is drawn with BitmapCreator and then drawn onto the B4XCanvas.
Attached the project as a B4XPages project, but tested only with B4J.


 

Attachments

  • DrawTextOnBitmapCreator.zip
    2.9 KB · Views: 70
Upvote 1

klaus

Expert
Licensed User
Longtime User
Sure !
Add this line
NewAngle = -NewAngle
in the btnRun_Click routine.

B4X:
Private Sub btnRun_Click
    Private NewAngle, Duration As Int
    NewAngle = Rnd(360, 1800)
    Duration = NewAngle * 2
    NewAngle = -NewAngle
    
    Snap = True
    btnRun.Enabled = False
    AnimateTo(Angle + NewAngle, Duration)
End Sub
 
Upvote 0

Oke

Member
Licensed User
Longtime User
Great and thank you.... Mr. Klaus



B4X:
Private Sub SetLocker
    Private a, d As Int
    
    a = Abs(Angle)
    d = Abs(DeltaAngle)
    a = a Mod d
    Select a
        Case 0, 1, 2, 3
            lblReference.Rotation = 0
        Case 4
            lblReference.Rotation = -35 * Direction
        Case 5
            lblReference.Rotation = -55 * Direction
        Case 6, 7, 8, 9
            lblReference.Rotation = -65 * Direction
        Case Else
            lblReference.Rotation = 0
    End Select
End Sub

With this code the pointer will move when it touches a point on each bar, can the pointer movement be slowed down?, because moving from -35 to 0 feels too fast
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
It seems that you want to combine the simple wheel project with the other one from HERE.

Maybe try something like this:

B4X:
Private Sub SetLocker
    Private a, d As Int
   
    a = Abs(Angle)
    d = Abs(DeltaAngle)
    a = a Mod d
    Select a
        Case 0, 1
            lblReference.Rotation = 0
        Case 2
            lblReference.Rotation = -10 * Direction
        Case 3
            lblReference.Rotation = -20 * Direction
        Case 4
            lblReference.Rotation = -35 * Direction
        Case 5
            lblReference.Rotation = -55 * Direction
        Case 6, 7, 8, 9
            lblReference.Rotation = -65 * Direction
        Case Else
            lblReference.Rotation = 0
    End Select
End Sub
 
Upvote 0

Oke

Member
Licensed User
Longtime User
the results are pretty decent, thank you...
 
Upvote 0

Oke

Member
Licensed User
Longtime User
Probably yes.
You have the source code, try it.
Then you need to think about from what condition you want stop and how.
Is related to CurrentSectorIndex or this AnimateTo(New, 500) New = New Mod 360
I still don't understand, can you help me give instructions

B4X:
Private Sub SnapRotation
    If Snap = True Then
        Private New As Int
        
        Select ReferencePosition
            Case "12 o'clock"
                If (90 Mod DeltaAngle) = 0 Then
                    New = (Floor(Angle / DeltaAngle) + 0.5) * DeltaAngle
                Else
                    New = (Floor(Angle / DeltaAngle + 0.5)) * DeltaAngle
                End If
        End Select
        AnimateTo(New, 500)
        New = New Mod 360
        
        CurrentSectorIndex = Angle Mod 360

        Select ReferencePosition
            Case "12 o'clock"
                CurrentSectorIndex =  270 - CurrentSectorIndex
            End Select
        
        If CurrentSectorIndex < 0 Then
            CurrentSectorIndex = CurrentSectorIndex + 360
        End If
        ......
    End Sub
 
Upvote 0

Oke

Member
Licensed User
Longtime User
What exactly do you want to know or understand ?
When the animation is finished, the position of the wheel is not aligned with the center of the sector.
SnapRotation does this alignment.
I want to stop the wheel, according to the number that I have specified, for example I want the wheel to stop exactly at number 8 or number 10
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…