spindial: move the widget to gb.base.form
[GB.FORM] * OPT: spindial: move the widget to gb.base.form
This commit is contained in:
parent
1f545a2cdc
commit
e99cbbcccf
4 changed files with 1 additions and 579 deletions
|
@ -1,6 +1,6 @@
|
|||
# Gambas Project File 3.0
|
||||
Title=More controls for graphical components
|
||||
Startup=FSpinDialTest
|
||||
Startup=FSpinBar
|
||||
Icon=.hidden/icon.png
|
||||
Version=3.18.90
|
||||
VersionFile=1
|
||||
|
|
|
@ -1,417 +0,0 @@
|
|||
' Gambas class file
|
||||
|
||||
Export
|
||||
Inherits UserControl
|
||||
|
||||
Public Const _Properties As String = "*,MaxValue=100,MinValue,Value,Step,PageStep,Warp,Notched,Mark=TRUE"
|
||||
Public Const _DefaultSize As String = "50,50"
|
||||
Public Const _Similar As String = "SpinBox"
|
||||
|
||||
'The drawing container
|
||||
Private $hView As New DrawingArea(Me) As "View"
|
||||
Private $tmrDraw As New Timer As "tmrDraw"
|
||||
|
||||
Private $iMaxValue As Integer = 100
|
||||
Private $iMinValue As Integer
|
||||
Private $iStep As Integer = 1
|
||||
Private $iPageStep As Integer
|
||||
Private $bMark As Boolean = True
|
||||
Private $iValue As Integer
|
||||
Private $bWarp As Boolean
|
||||
Private $bNotched As Boolean
|
||||
|
||||
Private $fStartAng As Float
|
||||
Private $fEndAng As Float
|
||||
Private $fHandleAng As Float
|
||||
Private PI2 As Float = 2 * Pi
|
||||
Private ROT90 As Float = Pi / 2
|
||||
|
||||
Property MaxValue As Integer ''Return or Set the maximum value
|
||||
Property MinValue As Integer ''Return or set the minimum value
|
||||
Property Step As Integer ''Return or set the step increment
|
||||
Property PageStep As Integer ''Return or set the page increment
|
||||
Property Mark As Boolean ''Return or set if the marks are showed or hidden
|
||||
Property Value As Integer ''Return or set the current value
|
||||
Property Warp As Boolean ''Return or set if the dial is warpped
|
||||
Property Notched As Boolean ''Return or set if the dial stuck on notch
|
||||
|
||||
Private $iBigMarkCount As Float
|
||||
Private $iSmallMarkCount As Float
|
||||
|
||||
Event Change
|
||||
|
||||
Public Sub _new()
|
||||
|
||||
'$hView.Tracking = True
|
||||
$hView.Focus = True
|
||||
$fStartAng = Pi / 3 / 2
|
||||
$fEndAng = PI2 - $fStartAng
|
||||
Me.Warp = $bWarp
|
||||
Me.Proxy = $hView
|
||||
UpdateIncrements
|
||||
SetValue($iValue)
|
||||
|
||||
End
|
||||
|
||||
Public Sub View_Draw()
|
||||
|
||||
Dim hRect As Rect = GetDrawingRect()
|
||||
Dim hPoint As Point
|
||||
Dim f As Float
|
||||
Dim fMaxRay As Float = hRect.W / 2
|
||||
Dim fCOS, fSIN As Float
|
||||
Dim i As Integer
|
||||
'Sizes
|
||||
Dim fBigTick As Float = hRect.W * 0.08
|
||||
Dim fSmallTick As Float = fBigTick / 2
|
||||
Dim fLineWidth As Float = fBigTick / 15
|
||||
Dim fOuterRay As Float = hRect.W / 2
|
||||
Dim fDialRay As Float = fOuterRay * 0.8
|
||||
Dim fHandleRay As Float = fOuterRay * 0.15
|
||||
Dim fTickStep As Float
|
||||
Dim iDeltaBM As Float
|
||||
Dim j As Integer
|
||||
|
||||
Dim iColorDial As Integer
|
||||
Dim iColorMark As Integer
|
||||
Dim iColorArrow As Integer
|
||||
|
||||
iColorArrow = Color.Gray
|
||||
If Me.Enabled Then
|
||||
iColorMark = Color.DarkGray
|
||||
If $hView.HasFocus Then
|
||||
iColorDial = Color.SelectedBackground
|
||||
Else
|
||||
iColorDial = Color.DarkGray
|
||||
Endif
|
||||
Else
|
||||
iColorMark = Color.LightGray
|
||||
iColorDial = Color.LightGray
|
||||
iColorArrow = Color.LightGray
|
||||
Endif
|
||||
|
||||
'GetCenter
|
||||
hPoint = hRect.Center()
|
||||
|
||||
'Paint Marks
|
||||
If $bMark Then
|
||||
'Paint.LineWidth = fLineWidth
|
||||
|
||||
If $iBigMarkCount Then iDeltaBM = Floor($iSmallMarkCount / $iBigMarkCount)
|
||||
|
||||
fTickStep = ($fEndAng - $fStartAng) / $iSmallMarkCount
|
||||
|
||||
For i = 0 To $iSmallMarkCount
|
||||
f = $fStartAng + ROT90 + i * fTickStep
|
||||
fCOS = Cos(f)
|
||||
fSIN = Sin(f)
|
||||
Paint.MoveTo(fCOS * fMaxRay + hPoint.X, fSIN * fMaxRay + hPoint.Y)
|
||||
If j = 0 Then
|
||||
j = iDeltaBM
|
||||
Paint.Background = iColorDial
|
||||
Paint.LineWidth = fLineWidth * 1.5
|
||||
Paint.LineTo(fCOS * (fOuterRay - fBigTick) + hPoint.X, fSIN * (fOuterRay - fBigTick) + hPoint.Y)
|
||||
Else
|
||||
Paint.LineWidth = fLineWidth
|
||||
Paint.Background = iColorMark
|
||||
Paint.LineTo(fCOS * (fOuterRay - fSmallTick) + hPoint.X, fSIN * (fOuterRay - fSmallTick) + hPoint.Y)
|
||||
Endif
|
||||
Dec j
|
||||
Paint.Stroke
|
||||
|
||||
Next
|
||||
|
||||
Endif
|
||||
|
||||
'Paint Arrow
|
||||
Paint.Background = iColorArrow
|
||||
Paint.LineWidth = fSmallTick / 2
|
||||
Paint.MoveTo(Cos($fHandleAng + ROT90) * fDialRay + hPoint.X, Sin($fHandleAng + ROT90) * fDialRay + hPoint.Y)
|
||||
Paint.LineTo(Cos($fHandleAng + ROT90) * (fDialRay - fSmallTick) + hPoint.X, Sin($fHandleAng + ROT90) * (fDialRay - fSmallTick) + hPoint.Y)
|
||||
Paint.Stroke
|
||||
|
||||
'Paint Dial
|
||||
Paint.Background = iColorDial
|
||||
Paint.LineWidth = Max(2, fLineWidth * 3)
|
||||
Paint.Ellipse(hPoint.X - fDialRay, hPoint.Y - fDialRay, fDialRay * 2, fDialRay * 2)
|
||||
Paint.Stroke
|
||||
|
||||
'Paint Dial Handle
|
||||
Paint.Ellipse(Cos($fHandleAng + ROT90) * (fDialRay - (fHandleRay + fSmallTick)) - fHandleRay + hPoint.X, Sin($fHandleAng + ROT90) * (fDialRay - (fHandleRay + fSmallTick)) - fHandleRay + hPoint.Y, fHandleRay * 2, fHandleRay * 2)
|
||||
Paint.Stroke
|
||||
|
||||
' 'Paint Text
|
||||
' Paint.Text($iValue, hRect.x, hRect.Y, hRect.W, hRect.H, Align.Center)
|
||||
' Paint.Fill
|
||||
|
||||
End
|
||||
|
||||
Private Sub GetDrawingRect() As Rect
|
||||
|
||||
Dim fMinSize As Float = Min($hView.ClientW, $hView.ClientH)
|
||||
|
||||
Return Rect((Me.ClientWidth - fMinSize) / 2, (Me.ClientHeight - fMinSize) / 2, fMinSize, fMinSize)
|
||||
|
||||
End
|
||||
|
||||
Public Sub View_MouseDown()
|
||||
|
||||
View_MouseMove
|
||||
|
||||
End
|
||||
|
||||
Public Sub View_MouseWheel()
|
||||
|
||||
Dim iStep As Integer = IIf($bNotched, $iStep, 1)
|
||||
|
||||
SetValue($iValue + Mouse.Delta * iStep)
|
||||
|
||||
End
|
||||
|
||||
Public Sub View_MouseMove()
|
||||
|
||||
Dim hRect As Rect = GetDrawingRect()
|
||||
Dim fAng As Float
|
||||
Dim MX As Integer = Mouse.X - hRect.X
|
||||
Dim MY As Integer = Mouse.Y - hRect.Y
|
||||
|
||||
|
||||
If Mouse.Left Then
|
||||
'limit the mouse action to the real dial zone
|
||||
If Not hRect.Contains(Mouse.X, Mouse.Y) Then Return
|
||||
'Find the mouse angle
|
||||
fAng = Ang(MX - hRect.W / 2, MY - hRect.H / 2) - ROT90
|
||||
If fAng < 0 Then fAng = Pi + (Pi + fAng)
|
||||
'Manage the wrap
|
||||
If fAng < $fStartAng Or fAng > $fEndAng Then
|
||||
$iValue = IIf(Abs(fAng - $fStartAng) < Abs(fAng - $fEndAng), $iMinValue, $iMaxValue)
|
||||
Raise Change
|
||||
'Stick on the Start or End Tab
|
||||
$fHandleAng = ValueToAngle($iValue)
|
||||
Else
|
||||
$iValue = AngleToValue(fAng)
|
||||
If $bNotched Then $fHandleAng = ValueToAngle($iValue) Else $fHandleAng = fAng
|
||||
Raise Change
|
||||
Endif
|
||||
|
||||
$tmrDraw.Trigger
|
||||
Endif
|
||||
|
||||
End
|
||||
|
||||
Private Sub AngleToValue(fAngle As Float) As Integer
|
||||
|
||||
Dim fNbrStep As Integer
|
||||
Dim iStep As Integer = IIf($bNotched, $iStep, 1)
|
||||
Dim fStepCount As Float = Max(1, ($iMaxValue - $iMinValue) / iStep)
|
||||
Dim fStepAngle As Float = ($fEndAng - $fStartAng) / fStepCount
|
||||
|
||||
'nombre d'increments
|
||||
fNbrStep = (fAngle - $fStartAng) / fStepAngle
|
||||
|
||||
Return $iMinValue + iStep * fNbrStep
|
||||
|
||||
End
|
||||
|
||||
Private Sub ValueToAngle(Value As Integer) As Float
|
||||
|
||||
Dim fStepCount As Float = Max(1, ($iMaxValue - $iMinValue) / $iStep)
|
||||
Dim fStepAngle As Float = ($fEndAng - $fStartAng) / fStepCount
|
||||
|
||||
Return (Value - $iMinValue) / $iStep * fStepAngle + $fStartAng
|
||||
|
||||
End
|
||||
|
||||
Private Sub UpdateIncrements()
|
||||
|
||||
'Compute the global private var for drawing step and compute angle
|
||||
$iSmallMarkCount = Ceil(($iMaxValue - $iMinValue) / ($iStep))
|
||||
|
||||
If $iPageStep Then
|
||||
$iBigMarkCount = Floor($iSmallMarkCount / $iPageStep)
|
||||
Endif
|
||||
|
||||
End
|
||||
|
||||
Public Sub View_KeyPress()
|
||||
|
||||
Select Case Key.Code
|
||||
Case Key.Up, Key.Right
|
||||
$iValue = Min(Max($iValue + $iStep, $iMinValue), $iMaxValue)
|
||||
Case Key.Down, Key.Left
|
||||
$iValue = Min(Max($iValue - $iStep, $iMinValue), $iMaxValue)
|
||||
Case Key.PageUp
|
||||
$iValue = Min(Max($iValue + $iPageStep, $iMinValue), $iMaxValue)
|
||||
Case Key.PageDown
|
||||
$iValue = Min(Max($iValue - $iPageStep, $iMinValue), $iMaxValue)
|
||||
End Select
|
||||
|
||||
$fHandleAng = ValueToAngle($iValue)
|
||||
Raise Change
|
||||
$tmrDraw.Trigger
|
||||
|
||||
End
|
||||
|
||||
Public Sub tmrDraw_Timer()
|
||||
|
||||
$hView.Refresh
|
||||
|
||||
End
|
||||
|
||||
Private Function MaxValue_Read() As Integer
|
||||
|
||||
Return $iMaxValue
|
||||
|
||||
End
|
||||
|
||||
Private Sub MaxValue_Write(Value As Integer)
|
||||
|
||||
Dim iTmpVal As Integer
|
||||
|
||||
$iMaxValue = Max(1, Value)
|
||||
$iMaxValue = Max($iMinValue, $iMaxValue)
|
||||
|
||||
iTmpVal = Min($iMaxValue, $iValue)
|
||||
|
||||
If iTmpVal <> $iValue Then
|
||||
$iValue = iTmpVal
|
||||
'Raise Change
|
||||
Endif
|
||||
|
||||
UpdateIncrements
|
||||
SetValue($iValue)
|
||||
End
|
||||
|
||||
Private Function MinValue_Read() As Integer
|
||||
|
||||
Return $iMinValue
|
||||
|
||||
End
|
||||
|
||||
Private Sub MinValue_Write(Value As Integer)
|
||||
|
||||
Dim iTmpVal As Integer
|
||||
|
||||
$iMinValue = Value
|
||||
$iMinValue = Min($iMinValue, $iMaxValue)
|
||||
iTmpVal = Max($iMinValue, $iValue)
|
||||
|
||||
If iTmpVal <> $iValue Then
|
||||
$iValue = iTmpVal
|
||||
'Raise Change
|
||||
Endif
|
||||
|
||||
UpdateIncrements
|
||||
SetValue($iValue)
|
||||
End
|
||||
|
||||
Private Function Step_Read() As Integer
|
||||
|
||||
Return $iStep
|
||||
|
||||
End
|
||||
|
||||
Private Sub Step_Write(Value As Integer)
|
||||
|
||||
$iStep = Max(1, Value)
|
||||
UpdateIncrements
|
||||
$tmrDraw.Trigger
|
||||
|
||||
End
|
||||
|
||||
Private Function PageStep_Read() As Integer
|
||||
|
||||
Return $iPageStep
|
||||
|
||||
End
|
||||
|
||||
Private Sub PageStep_Write(Value As Integer)
|
||||
|
||||
$iPageStep = Value
|
||||
UpdateIncrements
|
||||
$tmrDraw.Trigger
|
||||
|
||||
End
|
||||
|
||||
Private Function Mark_Read() As Boolean
|
||||
|
||||
Return $bMark
|
||||
|
||||
End
|
||||
|
||||
Private Sub Mark_Write(Value As Boolean)
|
||||
|
||||
$bMark = Value
|
||||
UpdateIncrements
|
||||
$tmrDraw.Trigger
|
||||
|
||||
End
|
||||
|
||||
Private Function Value_Read() As Integer
|
||||
|
||||
Return $iValue
|
||||
|
||||
End
|
||||
|
||||
Private Sub Value_Write(Value As Integer)
|
||||
|
||||
SetValue(Max(Min($iMaxValue, Value), $iMinValue))
|
||||
UpdateIncrements
|
||||
Raise Change
|
||||
|
||||
End
|
||||
|
||||
Private Function Warp_Read() As Boolean
|
||||
|
||||
Return $bWarp
|
||||
|
||||
End
|
||||
|
||||
Private Sub Warp_Write(Value As Boolean)
|
||||
|
||||
$bWarp = Value
|
||||
If $bWarp Then
|
||||
$fEndAng = PI2 - 0.01
|
||||
$fStartAng = 0
|
||||
Else
|
||||
$fStartAng = Pi / 3 / 2
|
||||
$fEndAng = PI2 - $fStartAng
|
||||
Endif
|
||||
UpdateIncrements
|
||||
SetValue($iValue)
|
||||
|
||||
End
|
||||
|
||||
Private Sub SetValue(Value As Integer)
|
||||
|
||||
'Lock the value between defined limits
|
||||
$iValue = Max($iMinValue, Min($iMaxValue, Value))
|
||||
|
||||
'Define the angle for the handle from the value
|
||||
$fHandleAng = ValueToAngle($iValue)
|
||||
|
||||
'Stuck Value on step value like on a notched wheel
|
||||
If $bNotched Then
|
||||
$iValue = AngleToValue($fHandleAng)
|
||||
Endif
|
||||
|
||||
'Dispatch the change event
|
||||
Raise Change
|
||||
|
||||
'update the view
|
||||
$tmrDraw.Trigger
|
||||
|
||||
End
|
||||
|
||||
Private Function Notched_Read() As Boolean
|
||||
|
||||
Return $bNotched
|
||||
|
||||
End
|
||||
|
||||
Private Sub Notched_Write(Value As Boolean)
|
||||
|
||||
$bNotched = value
|
||||
SetValue($iValue)
|
||||
|
||||
End
|
|
@ -1,69 +0,0 @@
|
|||
' Gambas class file
|
||||
|
||||
|
||||
Public Sub SpinDial1_MouseDown()
|
||||
|
||||
|
||||
|
||||
End
|
||||
|
||||
Public Sub Form_Open()
|
||||
|
||||
'Dial21.Notched = True
|
||||
SpinDial1.Value = 40
|
||||
SpinDial1.PageStep = 10
|
||||
End
|
||||
|
||||
Public Sub SpinBox5_Change()
|
||||
|
||||
SpinDial1.MaxValue = Last.value
|
||||
|
||||
End
|
||||
|
||||
Public Sub SpinBox6_Change()
|
||||
|
||||
SpinDial1.MinValue = Last.Value
|
||||
|
||||
End
|
||||
|
||||
Public Sub SpinBox7_Change()
|
||||
|
||||
SpinDial1.Step = Last.Value
|
||||
|
||||
End
|
||||
|
||||
Public Sub SpinBox8_Change()
|
||||
|
||||
SpinDial1.PageStep = Last.Value
|
||||
|
||||
End
|
||||
|
||||
Public Sub SpinDial1_Change()
|
||||
|
||||
Label1.Text = Last.Value
|
||||
|
||||
End
|
||||
|
||||
Public Sub CheckBox1_Click()
|
||||
|
||||
SpinDial1.Warp = CheckBox1.Value = CheckBox.True
|
||||
|
||||
End
|
||||
|
||||
Public Sub CheckBox2_Click()
|
||||
|
||||
SpinDial1.Notched = CheckBox2.Value = CheckBox.True
|
||||
|
||||
End
|
||||
|
||||
Public Sub CheckBox3_Click()
|
||||
|
||||
SpinDial1.Mark = CheckBox3.Value = CheckBox.True
|
||||
|
||||
End
|
||||
|
||||
Public Sub CheckBox4_Click()
|
||||
|
||||
SpinDial1.Enabled = CheckBox4.Value = CheckBox.True
|
||||
|
||||
End
|
|
@ -1,92 +0,0 @@
|
|||
# Gambas Form File 3.0
|
||||
|
||||
{ Form Form
|
||||
MoveScaled(0,0,97,74)
|
||||
Arrangement = Arrange.Horizontal
|
||||
Margin = True
|
||||
{ Panel2 Panel
|
||||
MoveScaled(18,-1,61,64)
|
||||
Expand = True
|
||||
Arrangement = Arrange.Vertical
|
||||
Spacing = True
|
||||
Margin = True
|
||||
{ Label1 Label
|
||||
MoveScaled(3,1,40,4)
|
||||
Background = Color.White
|
||||
Alignment = Align.Center
|
||||
}
|
||||
{ SpinDial1 SpinDial
|
||||
MoveScaled(7,5,51,32)
|
||||
Expand = True
|
||||
}
|
||||
{ Panel1 Panel
|
||||
MoveScaled(2,38,51.8571,4.8571)
|
||||
Arrangement = Arrange.Horizontal
|
||||
{ Label2 Label
|
||||
MoveScaled(0,0,19,3)
|
||||
Text = ("MaxValue")
|
||||
}
|
||||
{ SpinBox5 SpinBox
|
||||
MoveScaled(20,0,31,4)
|
||||
Expand = True
|
||||
Value = 100
|
||||
}
|
||||
}
|
||||
{ Panel3 Panel
|
||||
MoveScaled(2,43,51.8571,4.8571)
|
||||
Arrangement = Arrange.Horizontal
|
||||
{ Label3 Label
|
||||
MoveScaled(0,1,19,3)
|
||||
Text = ("MinValue")
|
||||
}
|
||||
{ SpinBox6 SpinBox
|
||||
MoveScaled(20,0,31,4)
|
||||
Expand = True
|
||||
}
|
||||
}
|
||||
{ Panel4 Panel
|
||||
MoveScaled(3,47,49.8571,4.8571)
|
||||
Arrangement = Arrange.Horizontal
|
||||
{ Label4 Label
|
||||
MoveScaled(0,1,19,3)
|
||||
Text = ("Step")
|
||||
}
|
||||
{ SpinBox7 SpinBox
|
||||
MoveScaled(18,0,31,4)
|
||||
Expand = True
|
||||
Value = 1
|
||||
}
|
||||
}
|
||||
{ Panel5 Panel
|
||||
MoveScaled(2,52,51.8571,4.8571)
|
||||
Arrangement = Arrange.Horizontal
|
||||
{ Label5 Label
|
||||
MoveScaled(0,0,19,3)
|
||||
Text = ("PageStep")
|
||||
}
|
||||
{ SpinBox8 SpinBox
|
||||
MoveScaled(20,0,31,4)
|
||||
Expand = True
|
||||
Value = 10
|
||||
}
|
||||
}
|
||||
{ CheckBox1 CheckBox
|
||||
MoveScaled(5,57,28,3)
|
||||
Text = ("Wrap")
|
||||
}
|
||||
{ CheckBox3 CheckBox
|
||||
MoveScaled(33,57,28,3)
|
||||
Text = ("Mark")
|
||||
Value = CheckBox.True
|
||||
}
|
||||
{ CheckBox4 CheckBox
|
||||
MoveScaled(33,60,18,3)
|
||||
Text = ("Enabled")
|
||||
Value = CheckBox.True
|
||||
}
|
||||
{ CheckBox2 CheckBox
|
||||
MoveScaled(5,60,28,3)
|
||||
Text = ("Notched")
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue