Android Oscillator Application Using Basic4Android - Tutorial Part 2
Submitted by donbermoy on Friday, January 17, 2014 - 10:34.
This is the 2nd part of my tutorial in creating an Oscillator Application in Android.
Note that in the first part we haven't initialized to make a grid as a background to our curves. So here is the code for that.
After initializing our grid as the background of our curves. We will also initialize a cursor in the panel that can be touched. Follow the code below:
Then, we shall code for our spinners in the Scale, TimeScale, and the SignalScale for the change of values to our curves. Type the code below:
Next we will code for our RadiobuttonScale. Here's the code below:
We will code also for our textbox if the curves will change its scale for the offset. Type this one:
Next, we will now put an Event Name in our three buttons for the btnStart, btnStop, and btnSingleShot. In the btnStart, once the user will click this button, it will automatically start the curves to cast signal. This is the code for that:
Then this is the code for the stopping the curves to move:
And this one is for the single shot to make the only one curves showed in the Oscillator:
And to fully end this tutorial, we will have our Activity_Create code:
So here is now our complete code for this tutorial:
Best regards,
Engr. Lyndon R. Bermoy
IT Instructor/System Developer/Android Developer
STI College - Surigao City
09126450702
[email protected]
Follow and add me in my Facebook Account: https://www.facebook.com/donzzsky
Visit my page on Facebook at: https://www.facebook.com/BermzISware
- Sub InitGrid
- Dim i As Int
- Dim x, y As Float
- cvsScreen.DrawRect(rectScreen, ScreenCol, True, 1)
- For i = 0 To NbDivY
- y = GridX0 + i * Div
- cvsScreen.DrawLine(GridX0, y, GridX1, y, GridLineCol, 1dip)
- Next
- For i = 0 To NbDivX
- x = GridY0 + i * Div
- cvsScreen.DrawLine(x, GridY0, x, GridY1, GridLineCol, 1dip)
- Next
- pnlScreen.Invalidate
- cvsGraph.DrawRect(rectGrid, Colors.Transparent, True, 1)
- pnlGraph.Invalidate
- cvsCursor.DrawRect(rectGrid, Colors.Transparent, True, 1)
- pnlCursor.Invalidate
- End Sub
- Sub pnlCursor_Touch (Action As Int, X As Float, Y As Float) As Boolean 'Return True to consume the event
- If Stopped = False Then
- Return
- End If
- Select Action
- Case Activity.ACTION_DOWN
- pnlDispValues.Visible = True
- cx = X
- If X >= 0 AND X <= GridW Then
- DrawCursor(X)
- DispValues(X)
- End If
- Case Activity.ACTION_MOVE
- If X >= 0 AND X <= GridW Then
- DrawCursor(X)
- DispValues(X)
- End If
- Case Activity.ACTION_UP
- cvsCursor.DrawLine(cx, 0, cx, GridH, Colors.Transparent, 1)
- pnlCursor.Invalidate
- pnlDispValues.Visible = False
- End Select
- Return True
- End Sub
- Sub spnTimeScale_ItemClick (Position As Int, Value As Object)
- dt = Value / 10
- t = 0
- Timer1.Initialize("Timer1", dt * 1000)
- End Sub
- Sub spnScale_ItemClick (Position As Int, Value As Object)
- Dim spn As Spinner
- spn = Sender
- Curve(spn.Tag).Scale = Div / Value
- End Sub
- Sub rbtScope_CheckedChange(Checked As Boolean)
- Dim rbt As RadioButton
- btnStop_Click
- rbt = Sender
- ScopeMode = rbt.Tag
- btnStart_Click
- End Sub
- Sub edtOffset_FocusChanged (HasFocus As Boolean)
- Dim edt As EditText
- Dim val As Double
- If HasFocus = False Then
- edt = Sender
- Curve(edt.Tag).Offset = edt.Text
- End If
- End Sub
- Sub btnStart_Click
- Timer1.Enabled = True
- SingleShot = False
- Stopped = False
- ii = -1
- xx = -dx
- EraseCurves
- End Sub
- Sub btnStop_Click
- Timer1.Enabled = False
- SingleShot = False
- Stopped = True
- End Sub
- Sub btnSingleShot_Click
- Timer1.Enabled = True
- SingleShot = True
- Stopped = False
- ii = -1
- xx = -dx
- EraseCurves
- End Sub
- Sub Activity_Create(FirstTime As Boolean)
- dt = 0.01
- t = 0
- Timer1.Initialize("Timer1", dt * 1000)
- NbDivX = 10
- NbDivY = 8
- Div = Floor(80%y / NbDivY)
- xx = 0
- dx = Div / 10
- GridW = Div * NbDivX
- GridH = Div * NbDivY
- Border = 6dip
- ScreenY0 = 0
- ScreenH = GridH + 2 * Border
- ScreenY1 = ScreenY0 + ScreenH
- ScreenX0 = 0
- ScreenW = GridW + 2 * Border
- ScreenX1 = ScreenX0 + ScreenW
- GridY0 = Border
- GridY1 = GridY0 + GridH
- GridX0 = Border
- GridX1 = GridX0 + GridW
- GridYm = GridH / 2
- rectGrid.Initialize(0, 0, GridW, GridH)
- rectScreen.Initialize(0, 0, ScreenW, ScreenH)
- ScreenCol = Colors.White
- GridLineCol = Colors.Gray
- pnlOcilloscope.Initialize("")
- Activity.AddView(pnlOcilloscope, 0, 0, 100%x, 100%y)
- pnlScreen.Initialize("")
- pnlOcilloscope.AddView(pnlScreen, ScreenX0, ScreenY0, ScreenW, ScreenH)
- cvsScreen.Initialize(pnlScreen)
- pnlGraph.Initialize("")
- pnlOcilloscope.AddView(pnlGraph, GridX0, GridY0, GridW, GridH)
- cvsGraph.Initialize(pnlGraph)
- pnlCursor.Initialize("pnlCursor")
- pnlOcilloscope.AddView(pnlCursor, GridX0, GridY0, GridW, GridH)
- cvsCursor.Initialize(pnlCursor)
- pnlControl.Initialize("")
- Activity.AddView(pnlControl, ScreenX1, 0, 100%x - ScreenX1, 54dip)
- Dim cbg As ColorDrawable
- cbg.Initialize(Colors.RGB(255, 196, 196), 0)
- pnlControl.Background = cbg
- Dim w1, w2, w3, t1, h1 As Int
- w1 = 4dip
- w2 = (pnlControl.Width - 4 * w1) / 3
- w3 = w1 + w2
- t1 = 4dip
- h1 = 52dip
- btnStart.Initialize("btnStart")
- pnlControl.AddView(btnStart, w1, t1, w2, h1)
- btnStart.Text = "Start"
- btnStop.Initialize("btnStop")
- pnlControl.AddView(btnStop, w1 + w3, t1, w2, h1)
- btnStop.Text = "Stop"
- btnSingleShot.Initialize("btnSingleShot")
- pnlControl.AddView(btnSingleShot, w1 + 2 * w3, t1, w2, h1)
- btnSingleShot.Text = "Single Shot"
- scvControl.Initialize(480dip)
- pnlOcilloscope.AddView(scvControl, ScreenX1, pnlControl.Height, 100%x - ScreenX1, 100%y - pnlControl.Height)
- scvControl.Panel.LoadLayout("controls")
- scvControl.Panel.Width = scvControl.Width
- Dim cbg As ColorDrawable
- cbg.Initialize(Colors.RGB(196, 196, 255), 0)
- scvControl.Panel.Background = cbg
- scvControl.Color = Colors.RGB(196, 196, 255)
- pnlCurveTools.Initialize("")
- pnlOcilloscope.AddView(pnlCurveTools, 0, ScreenY1, ScreenX1, 100%y - ScreenY1)
- Dim cbg As ColorDrawable
- cbg.Initialize(Colors.RGB(255, 196, 196), 0)
- pnlCurveTools.Background = cbg
- pnlDispValues.Initialize("")
- pnlOcilloscope.AddView(pnlDispValues, 0, ScreenY1, ScreenX1, 100%y - ScreenY1)
- Dim cbg As ColorDrawable
- cbg.Initialize(Colors.RGB(255, 236, 153), 0)
- pnlDispValues.Background = cbg
- pnlDispValues.Visible = False
- InitCurves
- InitCalcCurves
- InitSpinners
- Dim ww As Float
- ww = pnlDispValues.Width / 4
- lblValue0.Initialize("")
- pnlDispValues.AddView(lblValue0, 0, 0, ww, pnlDispValues.Height)
- lblValue0.TextColor = Curve(0).Color
- lblValue0.Gravity = Gravity.CENTER_HORIZONTAL + Gravity.CENTER_VERTICAL
- lblValue1.Initialize("")
- pnlDispValues.AddView(lblValue1, ww, 0, ww, pnlDispValues.Height)
- lblValue1.TextColor = Curve(1).Color
- lblValue1.Gravity = Gravity.CENTER_HORIZONTAL + Gravity.CENTER_VERTICAL
- lblValue2.Initialize("")
- pnlDispValues.AddView(lblValue2, 2 * ww, 0, ww, pnlDispValues.Height)
- lblValue2.TextColor = Curve(2).Color
- lblValue2.Gravity = Gravity.CENTER_HORIZONTAL + Gravity.CENTER_VERTICAL
- lblValue3.Initialize("")
- pnlDispValues.AddView(lblValue3, 3 * ww, 0, ww, pnlDispValues.Height)
- lblValue3.TextColor = Curve(3).Color
- lblValue3.Gravity = Gravity.CENTER_HORIZONTAL + Gravity.CENTER_VERTICAL
- For i = 0 To 3
- Dim cbx As CheckBox
- cbx.Initialize("cbxDrawCurve")
- pnlCurveTools.AddView(cbx, 6dip + i * 66dip, 0, 60dip, 50dip)
- cbx.Tag = i
- cbx.Text = " " & (i + 1)
- cbx.Typeface = Typeface.DEFAULT_BOLD
- cbx.Color = Curve(i).Color
- cbx.Checked = True
- Next
- lblScale0.Color = Curve(0).Color
- lblScale1.Color = Curve(1).Color
- lblScale2.Color = Curve(2).Color
- lblScale3.Color = Curve(3).Color
- lblOffset0.Color = Curve(0).Color
- lblOffset1.Color = Curve(1).Color
- lblOffset2.Color = Curve(2).Color
- lblOffset3.Color = Curve(3).Color
- edtOffset0.Text = Curve(0).Offset
- edtOffset1.Text = Curve(1).Offset
- edtOffset2.Text = Curve(2).Offset
- edtOffset3.Text = Curve(3).Offset
- Select ScopeMode
- Case "SCOPE"
- rbtScopeScope.Checked = True
- Case "MEM"
- rbtScopeMEM.Checked = True
- Case "ROLL"
- rbtScopeROLL.Checked = True
- End Select
- End Sub
- '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 Timer1 As Timer
- Type Curves (Name As String, Color As Int, Width As Float, Scale As Double, Offset As Double, Draw As Boolean)
- Dim CurveVal(4, 101) As Double
- Dim ScreenX0, ScreenX1, ScreenY0, ScreenY1, ScreenW, ScreenH, Border As Int
- Dim GridX0, GridX1, GridY0, GridY1, GridYm, GridW, GridH, Div As Int
- Dim NbDivX, NbDivY As Int
- Dim ScreenCol, GridLineCol As Int
- Dim t, dt As Double
- Dim dx, xx, cx As Float
- Dim ii As Int
- Dim CurveI As Int ' curve index
- Dim Curve(4) As Curves
- Dim CurvesI(4) As Int
- Dim CurvesNb As Int : CurvesNb = 3
- Dim CurvesNbDisp As Int
- Dim y1(4) As Float
- Dim y2(4) As Float
- Dim SingleShot As Boolean : SingleShot = False
- Dim Stopped As Boolean : Stopped = True
- Dim ScopeMode As String : ScopeMode = "ROLL"
- Dim ScopeRolling As Boolean : ScopeRolling = False
- Dim w(4) As Double
- Dim a(4) As Double
- Dim TimeScale(10) As Double
- Dim SignalScale(10) As Double
- 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 btnStart, btnStop, btnSingleShot As Button
- Dim pnlOcilloscope, pnlScreen, pnlGraph, pnlCursor, pnlControl As Panel
- Dim pnlCurveTools, pnlDispValues As Panel
- Dim cvsScreen, cvsGraph, cvsCursor As Canvas
- Dim rectScreen, rectGrid As Rect
- Dim spnTimeScale As Spinner
- Dim spnScale0, spnScale1, spnScale2, spnScale3 As Spinner
- Dim lblScale0, lblScale1, lblScale2, lblScale3 As Label
- Dim lblValue0, lblValue1, lblValue2, lblValue3 As Label
- Dim lblOffset0, lblOffset1, lblOffset2, lblOffset3 As Label
- Dim edtOffset0, edtOffset1, edtOffset2, edtOffset3 As EditText
- Dim rbtScopeScope, rbtScopeMEM, rbtScopeROLL As RadioButton
- Dim scvControl As ScrollView
- Dim bmpRoll As Bitmap
- End Sub
- Sub Activity_Create(FirstTime As Boolean)
- dt = 0.01
- t = 0
- Timer1.Initialize("Timer1", dt * 1000)
- NbDivX = 10
- NbDivY = 8
- Div = Floor(80%y / NbDivY)
- xx = 0
- dx = Div / 10
- GridW = Div * NbDivX
- GridH = Div * NbDivY
- Border = 6dip
- ScreenY0 = 0
- ScreenH = GridH + 2 * Border
- ScreenY1 = ScreenY0 + ScreenH
- ScreenX0 = 0
- ScreenW = GridW + 2 * Border
- ScreenX1 = ScreenX0 + ScreenW
- GridY0 = Border
- GridY1 = GridY0 + GridH
- GridX0 = Border
- GridX1 = GridX0 + GridW
- GridYm = GridH / 2
- rectGrid.Initialize(0, 0, GridW, GridH)
- rectScreen.Initialize(0, 0, ScreenW, ScreenH)
- ScreenCol = Colors.White
- GridLineCol = Colors.Gray
- pnlOcilloscope.Initialize("")
- Activity.AddView(pnlOcilloscope, 0, 0, 100%x, 100%y)
- pnlScreen.Initialize("")
- pnlOcilloscope.AddView(pnlScreen, ScreenX0, ScreenY0, ScreenW, ScreenH)
- cvsScreen.Initialize(pnlScreen)
- pnlGraph.Initialize("")
- pnlOcilloscope.AddView(pnlGraph, GridX0, GridY0, GridW, GridH)
- cvsGraph.Initialize(pnlGraph)
- pnlCursor.Initialize("pnlCursor")
- pnlOcilloscope.AddView(pnlCursor, GridX0, GridY0, GridW, GridH)
- cvsCursor.Initialize(pnlCursor)
- pnlControl.Initialize("")
- Activity.AddView(pnlControl, ScreenX1, 0, 100%x - ScreenX1, 54dip)
- Dim cbg As ColorDrawable
- cbg.Initialize(Colors.RGB(255, 196, 196), 0)
- pnlControl.Background = cbg
- Dim w1, w2, w3, t1, h1 As Int
- w1 = 4dip
- w2 = (pnlControl.Width - 4 * w1) / 3
- w3 = w1 + w2
- t1 = 4dip
- h1 = 52dip
- btnStart.Initialize("btnStart")
- pnlControl.AddView(btnStart, w1, t1, w2, h1)
- btnStart.Text = "Start"
- btnStop.Initialize("btnStop")
- pnlControl.AddView(btnStop, w1 + w3, t1, w2, h1)
- btnStop.Text = "Stop"
- btnSingleShot.Initialize("btnSingleShot")
- pnlControl.AddView(btnSingleShot, w1 + 2 * w3, t1, w2, h1)
- btnSingleShot.Text = "Single Shot"
- scvControl.Initialize(480dip)
- pnlOcilloscope.AddView(scvControl, ScreenX1, pnlControl.Height, 100%x - ScreenX1, 100%y - pnlControl.Height)
- scvControl.Panel.LoadLayout("controls")
- scvControl.Panel.Width = scvControl.Width
- Dim cbg As ColorDrawable
- cbg.Initialize(Colors.RGB(196, 196, 255), 0)
- scvControl.Panel.Background = cbg
- scvControl.Color = Colors.RGB(196, 196, 255)
- pnlCurveTools.Initialize("")
- pnlOcilloscope.AddView(pnlCurveTools, 0, ScreenY1, ScreenX1, 100%y - ScreenY1)
- Dim cbg As ColorDrawable
- cbg.Initialize(Colors.RGB(255, 196, 196), 0)
- pnlCurveTools.Background = cbg
- pnlDispValues.Initialize("")
- pnlOcilloscope.AddView(pnlDispValues, 0, ScreenY1, ScreenX1, 100%y - ScreenY1)
- Dim cbg As ColorDrawable
- cbg.Initialize(Colors.RGB(255, 236, 153), 0)
- pnlDispValues.Background = cbg
- pnlDispValues.Visible = False
- InitCurves
- InitCalcCurves
- InitSpinners
- Dim ww As Float
- ww = pnlDispValues.Width / 4
- lblValue0.Initialize("")
- pnlDispValues.AddView(lblValue0, 0, 0, ww, pnlDispValues.Height)
- lblValue0.TextColor = Curve(0).Color
- lblValue0.Gravity = Gravity.CENTER_HORIZONTAL + Gravity.CENTER_VERTICAL
- lblValue1.Initialize("")
- pnlDispValues.AddView(lblValue1, ww, 0, ww, pnlDispValues.Height)
- lblValue1.TextColor = Curve(1).Color
- lblValue1.Gravity = Gravity.CENTER_HORIZONTAL + Gravity.CENTER_VERTICAL
- lblValue2.Initialize("")
- pnlDispValues.AddView(lblValue2, 2 * ww, 0, ww, pnlDispValues.Height)
- lblValue2.TextColor = Curve(2).Color
- lblValue2.Gravity = Gravity.CENTER_HORIZONTAL + Gravity.CENTER_VERTICAL
- lblValue3.Initialize("")
- pnlDispValues.AddView(lblValue3, 3 * ww, 0, ww, pnlDispValues.Height)
- lblValue3.TextColor = Curve(3).Color
- lblValue3.Gravity = Gravity.CENTER_HORIZONTAL + Gravity.CENTER_VERTICAL
- For i = 0 To 3
- Dim cbx As CheckBox
- cbx.Initialize("cbxDrawCurve")
- pnlCurveTools.AddView(cbx, 6dip + i * 66dip, 0, 60dip, 50dip)
- cbx.Tag = i
- cbx.Text = " " & (i + 1)
- cbx.Typeface = Typeface.DEFAULT_BOLD
- cbx.Color = Curve(i).Color
- cbx.Checked = True
- Next
- lblScale0.Color = Curve(0).Color
- lblScale1.Color = Curve(1).Color
- lblScale2.Color = Curve(2).Color
- lblScale3.Color = Curve(3).Color
- lblOffset0.Color = Curve(0).Color
- lblOffset1.Color = Curve(1).Color
- lblOffset2.Color = Curve(2).Color
- lblOffset3.Color = Curve(3).Color
- edtOffset0.Text = Curve(0).Offset
- edtOffset1.Text = Curve(1).Offset
- edtOffset2.Text = Curve(2).Offset
- edtOffset3.Text = Curve(3).Offset
- Select ScopeMode
- Case "SCOPE"
- rbtScopeScope.Checked = True
- Case "MEM"
- rbtScopeMEM.Checked = True
- Case "ROLL"
- rbtScopeROLL.Checked = True
- End Select
- End Sub
- Sub Activity_Resume
- InitGrid
- End Sub
- Sub Activity_Pause (UserClosed As Boolean)
- btnStop_Click
- End Sub
- Sub InitGrid
- Dim i As Int
- Dim x, y As Float
- cvsScreen.DrawRect(rectScreen, ScreenCol, True, 1)
- For i = 0 To NbDivY
- y = GridX0 + i * Div
- cvsScreen.DrawLine(GridX0, y, GridX1, y, GridLineCol, 1dip)
- Next
- For i = 0 To NbDivX
- x = GridY0 + i * Div
- cvsScreen.DrawLine(x, GridY0, x, GridY1, GridLineCol, 1dip)
- Next
- pnlScreen.Invalidate
- cvsGraph.DrawRect(rectGrid, Colors.Transparent, True, 1)
- pnlGraph.Invalidate
- cvsCursor.DrawRect(rectGrid, Colors.Transparent, True, 1)
- pnlCursor.Invalidate
- End Sub
- Sub btnStart_Click
- Timer1.Enabled = True
- SingleShot = False
- Stopped = False
- ii = -1
- xx = -dx
- EraseCurves
- End Sub
- Sub btnStop_Click
- Timer1.Enabled = False
- SingleShot = False
- Stopped = True
- End Sub
- Sub btnSingleShot_Click
- Timer1.Enabled = True
- SingleShot = True
- Stopped = False
- ii = -1
- xx = -dx
- EraseCurves
- End Sub
- Sub spnTimeScale_ItemClick (Position As Int, Value As Object)
- dt = Value / 10
- t = 0
- Timer1.Initialize("Timer1", dt * 1000)
- End Sub
- Sub spnScale_ItemClick (Position As Int, Value As Object)
- Dim spn As Spinner
- spn = Sender
- Curve(spn.Tag).Scale = Div / Value
- End Sub
- Sub edtOffset_FocusChanged (HasFocus As Boolean)
- Dim edt As EditText
- Dim val As Double
- If HasFocus = False Then
- edt = Sender
- Curve(edt.Tag).Offset = edt.Text
- End If
- End Sub
- Sub rbtScope_CheckedChange(Checked As Boolean)
- Dim rbt As RadioButton
- btnStop_Click
- rbt = Sender
- ScopeMode = rbt.Tag
- btnStart_Click
- End Sub
- Sub Timer1_Tick
- Dim i, j As Int
- t = t + dt
- xx = xx + dx
- ii = ii + 1
- If ii > 100 Then
- If SingleShot = True Then
- Timer1.Enabled = False
- SingleShot = False
- Stopped = True
- Return
- Else
- Select ScopeMode
- Case "MEM"
- xx = 0
- ii = 0
- GetValues
- DrawCurves
- Case "SCOPE"
- EraseCurves
- xx = 0
- ii = 0
- GetValues
- DrawCurves
- Case "ROLL"
- ii = 100
- xx = 100 * dx
- For i = 0 To 3
- For j = 0 To 99
- CurveVal(i, j) = CurveVal(i, j + 1)
- Next
- Next
- ScopeRolling = True
- GetValues
- DrawCurves
- End Select
- Return
- End If
- End If
- GetValues
- DrawCurves
- End Sub
- Sub DrawCurves
- Dim i, j As Int
- Dim r1, r2 As Rect
- Dim x, yy1(4), yy2(4) As Float
- If SingleShot = False Then
- Select ScopeMode
- Case "MEM"
- r1.Initialize(xx, 0, xx + dx, GridH)
- cvsGraph.DrawRect(r1, Colors.Transparent, True, 1)
- Case "ROLL"
- If ScopeRolling = True Then
- cvsGraph.DrawRect(rectGrid, Colors.Transparent, True, 1)
- For i = 0 To CurvesNb
- If Curve(i).Draw = True Then
- yy1(i) = GridYm + (-Curve(i).Offset - CurveVal(i, 0)) * Curve(i).Scale
- For j = 1 To 99
- x = j * dx
- yy2(i) = GridYm + (-Curve(i).Offset - CurveVal(i, j)) * Curve(i).Scale
- cvsGraph.DrawLine(x - dx, yy1(i), x, yy2(i), Curve(i).Color, Curve(i).Width)
- yy1(i) = yy2(i)
- Next
- End If
- Next
- End If
- End Select
- End If
- For i = 0 To CurvesNb
- If Curve(i).Draw = True Then
- y2(i) = GridYm + (-Curve(i).Offset - CurveVal(i, ii)) * Curve(i).Scale
- If ii > 0 Then
- cvsGraph.DrawLine(xx - dx, y1(i), xx, y2(i), Curve(i).Color, Curve(i).Width)
- End If
- y1(i) = y2(i)
- End If
- Next
- pnlGraph.Invalidate
- DoEvents
- End Sub
- Sub GetValues
- Dim i As Int
- For i = 0 To CurvesNb
- CurveVal(i, ii) = a(i) * Sin(w(i) * t)
- Next
- End Sub
- Sub EraseCurves
- cvsGraph.DrawRect(rectGrid, Colors.Transparent, True, 1)
- End Sub
- Sub cbxDrawCurve_CheckedChange(Checked As Boolean)
- Dim cbx As CheckBox
- cbx = Sender
- Curve(cbx.Tag).Draw = Checked
- End Sub
- Sub pnlCursor_Touch (Action As Int, X As Float, Y As Float) As Boolean 'Return True to consume the event
- If Stopped = False Then
- Return
- End If
- Select Action
- Case Activity.ACTION_DOWN
- pnlDispValues.Visible = True
- cx = X
- If X >= 0 AND X <= GridW Then
- DrawCursor(X)
- DispValues(X)
- End If
- Case Activity.ACTION_MOVE
- If X >= 0 AND X <= GridW Then
- DrawCursor(X)
- DispValues(X)
- End If
- Case Activity.ACTION_UP
- cvsCursor.DrawLine(cx, 0, cx, GridH, Colors.Transparent, 1)
- pnlCursor.Invalidate
- pnlDispValues.Visible = False
- End Select
- Return True
- End Sub
- Sub DrawCursor(x As Float)
- cvsCursor.DrawLine(cx, 0, cx, GridH, Colors.Transparent, 1)
- cx = x
- cvsCursor.DrawLine(cx, 0, cx, GridH, Colors.Red, 1)
- pnlCursor.Invalidate
- End Sub
- Sub DispValues(x As Int)
- Dim i As Int
- i = 100 / GridW * x
- lblValue0.Text = NumberFormat(CurveVal(0, i), 1, 6)
- lblValue1.Text = NumberFormat(CurveVal(1, i), 1, 6)
- lblValue2.Text = NumberFormat(CurveVal(2, i), 1, 6)
- lblValue3.Text = NumberFormat(CurveVal(3, i), 1, 6)
- End Sub
- Sub InitCurves
- Curve(0).Color = Colors.Red
- Curve(1).Color = Colors.Blue
- Curve(2).Color = Colors.Black
- Curve(3).Color = Colors.RGB(64, 192, 0)
- Curve(0).Width = 1dip
- Curve(1).Width = 1dip
- Curve(2).Width = 1dip
- Curve(3).Width = 1dip
- Curve(0).Scale = 20
- Curve(1).Scale = 20
- Curve(2).Scale = 20
- Curve(3).Scale = 20
- Curve(0).Offset = 0
- Curve(1).Offset = 1
- Curve(2).Offset = -1
- Curve(3).Offset = 2
- Curve(0).Draw = True
- Curve(1).Draw = True
- Curve(2).Draw = True
- Curve(3).Draw = True
- End Sub
- Sub InitCalcCurves
- w(0) = 2 * cPI * 2.1
- w(1) = 2 * cPI * 3.7
- w(2) = 2 * cPI * 4.3
- w(3) = 2 * cPI * 5.7
- a(0) = 1.0
- a(1) = 2.0
- a(2) = -1.0
- a(3) = 1.5
- End Sub
- Sub InitSpinners
- Dim i As Int
- TimeScale(0) = 10
- TimeScale(1) = 5
- TimeScale(2) = 2
- TimeScale(3) = 1
- TimeScale(4) = 0.5
- TimeScale(5) = 0.2
- TimeScale(6) = 0.1
- TimeScale(7) = 0.05
- TimeScale(8) = 0.02
- TimeScale(9) = 0.01
- SignalScale(0) = 10
- SignalScale(1) = 5
- SignalScale(2) = 2
- SignalScale(3) = 1
- SignalScale(4) = .5
- SignalScale(5) = .2
- SignalScale(6) = .1
- SignalScale(7) = .05
- SignalScale(8) = .02
- SignalScale(9) = .01
- For i = 0 To 9
- spnTimeScale.Add(TimeScale(i))
- spnScale0.Add(SignalScale(i))
- spnScale1.Add(SignalScale(i))
- spnScale2.Add(SignalScale(i))
- spnScale3.Add(SignalScale(i))
- Next
- spnTimeScale.SelectedIndex = 6
- spnScale0.SelectedIndex = 3
- spnScale1.SelectedIndex = 3
- spnScale2.SelectedIndex = 3
- spnScale3.SelectedIndex = 3
- Curve(0).Scale = Div / spnScale0.SelectedItem
- Curve(1).Scale = Div / spnScale1.SelectedItem
- Curve(2).Scale = Div / spnScale2.SelectedItem
- Curve(3).Scale = Div / spnScale3.SelectedItem
- End Sub
Add new comment
- 47 views