Canvas / Drawcircle

Xawtor

Member
Licensed User
Longtime User
Hi everybody,

I try to understand why I can't erase circle by this way:

B4X:
c.DrawCircle(Activity.Width/3,h,5dip,Colors.Transparent,True,0)

And this one can:

B4X:
c.DrawColor(Colors.Black)

Because I found Erel's gamepad exemple here:

http://www.b4x.com/forum/additional-libraries-classes-official-updates/19483-class-gamepad-multitouch-gamepad.html#post112295

And he did as well by this way:

B4X:
c.DrawCircle(Activity.Width/3,h,5dip,Colors.Transparent,True,0)

:sign0089:Cheers,
My test code:

B4X:
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

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 c As Canvas
   Dim rl As Rect
   Dim rr As Rect
   Dim l As Int: l = 5dip
   Dim SeekBar1 As SeekBar
End Sub

Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   'Activity.LoadLayout("Layout1")
   Activity.LoadLayout("a")
   c.Initialize(Activity)
   c.DrawCircle(Activity.Width/3,Activity.Height/2,5dip,Colors.Green,True,1dip)
   c.DrawCircle((2*Activity.Width/3),Activity.Height/2,5dip,Colors.Red,True,1dip)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub SeekBar1_ValueChanged (Value As Int, UserChanged As Boolean)
   Dim h As Int
   h = (Activity.Height*(Value+120))/240
   
   c.DrawCircle(Activity.Width/3,h,5dip,Colors.Transparent,True,0)       'Doesn't work
   c.DrawCircle((2*Activity.Width/3),h,5dip,Colors.Transparent,True,0) 'Doesn't work
   'c.DrawCircle(Activity.Width/3,h,5dip,Colors.Black,True,0)          'Doesn't work
   'c.DrawCircle((2*Activity.Width/3),h,5dip,Colors.Black,True,0)      'Doesn't work
   'c.DrawColor(Colors.Black)                                 'Works
   c.DrawCircle(Activity.Width/3,h,5dip,Colors.Green,True,0)
   c.DrawCircle((2*Activity.Width/3),h,5dip,Colors.Red,True,0)
   Activity.Invalidate
End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You should erase the old circle not the new one:
B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim c As Canvas
    Dim rl As Rect
    Dim rr As Rect
    Dim l As Int: l = 5dip
    Dim SeekBar1 As SeekBar
   Dim oldValue As Int
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
   SeekBar1.Initialize("Seekbar1")
   Activity.AddView(SeekBar1, 0, 0, 200dip, 50dip)
    c.Initialize(Activity)
   oldValue = Activity.Height/2
    c.DrawCircle(Activity.Width/3,Activity.Height/2,5dip,Colors.Green,True,1dip)
    c.DrawCircle((2*Activity.Width/3),Activity.Height/2,5dip,Colors.Red,True,1dip)
End Sub

Sub Activity_Resume

End Sub


Sub SeekBar1_ValueChanged (Value As Int, UserChanged As Boolean)
    Dim h As Int
    h = (Activity.Height*(Value+120))/240
    If oldValue > 0 Then
       c.DrawCircle(Activity.Width/3,oldValue,5dip,Colors.Transparent,True,0)         'Doesn't work
       c.DrawCircle((2*Activity.Width/3),oldValue,5dip,Colors.Transparent,True,0) 'Doesn't work
   End If
    'c.DrawCircle(Activity.Width/3,h,5dip,Colors.Black,True,0)          'Doesn't work
    'c.DrawCircle((2*Activity.Width/3),h,5dip,Colors.Black,True,0)        'Doesn't work
    'c.DrawColor(Colors.Black)                                            'Works
    c.DrawCircle(Activity.Width/3,h,5dip,Colors.Green,True,0)
    c.DrawCircle((2*Activity.Width/3),h,5dip,Colors.Red,True,0)
   oldValue = h
    Activity.Invalidate
End Sub
 
Upvote 0
Top