Italian [Classe][B4J] Stick

ivanomonti

Expert
Licensed User
Longtime User
Semplice classe stick solo imbastita, servono molte altre funzioni che mi piacerebbe che venissero proposte o migliorate da tutti noi, non ricordando come si creano librerie e moduli la lascio libera per dare il via al dibattito collettivo. ripeto non è definitiva e di sicuro va corretta.



Class:
Sub Class_Globals
    Private fx As JFX
    Private listapane, listpanenew As List
    Private ParentStick As Pane
    Private MScroll As Boolean = True
    Private MAnimation, MDragger As Boolean = False
    Private l,t,w,h As Int
    Private y,x As Double
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
    listapane.Initialize
    listpanenew.Initialize
End Sub

Public Sub AddStick(stickParent As Pane, Left As Int, Top As Int, Width As Int, Height As Int, Title As String, TypeColor As Int)
    
    If ParentStick.IsInitialized = False Then
        ParentStick=stickParent
    End If
    
    l=Left
    t=Top
    w=Width
    h=Height
    
    Dim miapane    As Pane
    miapane.Initialize("MIAPane")
    miapane.Tag = "MiaPane_UI_07032023"
    CSSUtils.SetStyleProperty(miapane, "-fx-rotate",Rnd(-20,20))
    
    Dim R As Reflector
    R.Target = miapane
    R.AddEventFilter("RPScroll","javafx.scene.input.ScrollEvent.SCROLL")
    
    Dim lb As Label
    lb.Initialize("lb")
    lb.Alignment="TOP_LEFT"
    lb.Text = Title
    lb.WrapText= True
    miapane.AddNode(lb,30,30,w-60,h-65)
            
    If TypeColor = 0 Then
        CSSUtils.SetBackgroundImage(miapane,File.DirAssets,"sticky-note-verde.png")
    Else if TypeColor = 1 Then
        CSSUtils.SetBackgroundImage(miapane,File.DirAssets,"sticky-note-blu.png")
    else if TypeColor = 2 Then
        CSSUtils.SetBackgroundImage(miapane,File.DirAssets,"sticky-note-marrone.png")
    End If
    
    listapane.Add(miapane)
    ParentStick.AddNode(miapane,l,t,w,h)
    
    l=ParentStick.Left
    t=ParentStick.Top
    
End Sub

Private Sub RPScroll_Filter (E As Event)
    
    Dim MouseEvent As JavaObject = E
    Dim p As Pane = Sender
    
    If MouseEvent.RunMethod("getDeltaY", Null) > 0 Then
    Else if MouseEvent.RunMethod("getDeltaY", Null) < 0 Then
        If movestickDown(p) Then
            Dim p As Pane = Sender
            p.SetAlphaAnimated(1000,1)
        End If
    End If
        
End Sub

Private Sub movestickDown(p As Pane) As Boolean
    
    If MScroll = False Then Return False
    
    listpanenew.Clear
    listpanenew.Add(p)
    
    For i=0  To listapane.Size-2
        listpanenew.Add(listapane.Get(i))
    Next
    
    For Each n As Node In ParentStick.GetAllViewsRecursive
        If n Is Pane Then
            Dim p As Pane = n
            If p.Tag = "MiaPane_UI_07032023" Then
                p.RemoveNodeFromParent
            End If
        End If
    Next
    
    listapane.Clear
    listapane.AddAll(listpanenew)
    listpanenew.Clear

    For i=0 To listapane.Size-1
        Dim pp As Pane = listapane.Get(i)
        Try
            ParentStick.AddNode(pp,pp.Left,pp.Top,pp.Width,pp.Height)
        Catch
            Log(LastException)
        End Try
    Next
    
    Return True
    
End Sub

Private Sub MIAPane_MouseClicked (EventData As MouseEvent)
    Dim p As Pane = Sender
    If movestickDown(p) Then
        If MAnimation = True Then
            p = listapane.Get(listapane.Size-1)
            p.Alpha=1
            p.SetAlphaAnimated(1000,0)
        End If
    End If
End Sub

Public Sub TrasparentParent(Parent As Pane)
    CSSUtils.SetBackgroundColor(Parent,fx.Colors.Transparent)
End Sub

Public Sub MouseScroll(Value As Boolean)
    MScroll=Value
End Sub

Public Sub AnimationAlpha(value As Boolean)
    MAnimation = value
End Sub

Private Sub MIAPane_MouseReleased (EventData As MouseEvent)
    Dim p As Pane = Sender
    p.SetAlphaAnimated(1000,1)
    If MDragger= True Then
'        ParentStick.Left = (l+y)/2
'        ParentStick.Top = (t-x)/2
'        MDragger=False
    End If
End Sub

Private Sub MIAPane_MouseDragged (EventData As MouseEvent)
    MDragger=True
'    y=EventData.Y
'    x=EventData.x
End Sub
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…