Sviluppatori Basic (e non) per Mobile e Desktop

Forum dedicato agli sviluppatori di B4X, Delphi, Xamarin


Non sei connesso Connettiti o registrati

ViewAnimation

Andare in basso  Messaggio [Pagina 1 di 1]

1 ViewAnimation il Dom Apr 22, 2018 5:08 pm

Dust

avatar
Admin
Admin
Per animare l'immagine di backgroud di una vista.
Animazione circolare ovviamente Razz Very Happy

Questa é la base della Classe

Codice:
Sub Class_Globals
 Private Vw As View
 Private cvs As Canvas
 Private x, y, radius As Float
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(V As View)
 Dim left As Int = V.Left
 Dim top As Int = V.Top

 Dim Btmp As Bitmap = DrawBitmap(V)
 Dim cvs As Canvas = CreateBitmap(Btmp.Width,Btmp.Height)
 cvs.AntiAlias=True
 V.Left=left
 V.Top=top
 Vw=V

 x = Btmp.Width/2
 y = Btmp.Height/2
 radius = Min(x,y)

 DrawRoundBitmap(Btmp)

 Vw.SetBackgroundImage(cvs.Bitmap)
End Sub

private Sub CreateBitmap(Width As Int, Heigth As Int) As Canvas
   Dim bmp As Bitmap
   bmp.InitializeMutable(Width, Heigth)
   Dim canv As Canvas
   canv.Initialize2(bmp)
   Dim r As Rect
   r.Initialize(0, 0, bmp.Width, bmp.Height)
   canv.DrawRect(r, Colors.Transparent, True, 0)
   Dim p As Path
   p.Initialize(0, 0)
   Dim jo As JavaObject = p
   Dim x = Width/2, y = Heigth/2, radius As Float = Min(x,y)
   jo.RunMethod("addCircle", Array As Object(x, y, radius, "CW"))
   canv.ClipPath(p)
   Return canv
End Sub

private Sub DrawRoundBitmap (bmp As Bitmap)
   Dim r As Rect
   r.Initialize(0, 0, cvs.Bitmap.Width, cvs.Bitmap.Height)
   cvs.DrawBitmap(bmp, Null, r)
End Sub

private Sub DrawBitmap(V As View) As Bitmap
   Dim XUI As B4XView = V
   Dim bmp As Bitmap = XUI.Snapshot
   Return bmp
End Sub



Ultima modifica di Dust il Dom Apr 22, 2018 5:13 pm, modificato 2 volte

Visualizza il profilo dell'utente http://basic4x.forumattivo.com

2 Stella ruotante il Dom Apr 22, 2018 5:09 pm

Dust

avatar
Admin
Admin



Codice:

public Sub ProgressStar(PerCent As Int,StarSize As Int)
   Dim bmp As Bitmap
   bmp.InitializeMutable(cvs.Bitmap.Width, cvs.Bitmap.Height)
   
   PerCent=PerCent Mod 100
   
   Dim canv As Canvas
   canv.Initialize2(bmp)
   canv.AntiAlias=True
   
   Dim r As Rect
   r.Initialize(StarSize/2, StarSize/2, bmp.Width-StarSize, bmp.Height-StarSize)
   canv.DrawBitmap(cvs.Bitmap,Null,r)
   
   Dim CoX As Int = x-(radius-StarSize)*Cos((2*cPI)*((PerCent+25)/100))
   Dim CoY As Int = y-(radius-StarSize)*Sin((2*cPI)*((PerCent+25)/100))
   
   canv.DrawCircle(x,y,radius-StarSize,Colors.White,False,1dip)

   canv.DrawCircle(CoX,CoY,StarSize,Colors.White,True,1dip)
   canv.DrawLine(CoX-StarSize-Rnd(1dip,3dip),CoY,CoX+StarSize+Rnd(1dip,3dip),CoY,Colors.White,1DiP)
   canv.DrawLine(CoX,CoY-StarSize-Rnd(1dip,3dip),CoX,CoY+StarSize+Rnd(1dip,3dip),Colors.White,1dip)   
   'canv.DrawLine(x,y,CoX,Coy,Colors.White,1dip)
   
   Vw.SetBackgroundImage(canv.Bitmap)
End Sub

Visualizza il profilo dell'utente http://basic4x.forumattivo.com

3 VELA il Dom Apr 22, 2018 5:10 pm

Dust

avatar
Admin
Admin
Codice:

Public Sub ProgressVeil(PerCent As Int, Color As Int)
   If PerCent>=0 And PerCent<=100 Then
      Dim bmp As Bitmap
      bmp.InitializeMutable(cvs.Bitmap.Width, cvs.Bitmap.Height)
   
      Dim canv As Canvas
      canv.Initialize2(bmp)
      canv.AntiAlias=True
      
      Dim CoX As Int = x-((radius*1.2)-1dip)*Cos((2*cPI)*((PerCent+25)/100))
      Dim CoY As Int = y-((radius*1.2)-1dip)*Sin((2*cPI)*((PerCent+25)/100))
      
      Dim P As Path
      P.Initialize(x,y)
      P.LineTo(x,0)
      If PerCent>12 Then P.LineTo(cvs.Bitmap.Width,0)
      If PerCent>=25 Then P.LineTo(cvs.Bitmap.Width,y)
      If PerCent>37 Then P.LineTo(cvs.Bitmap.Width,cvs.Bitmap.Height)
      If PerCent>=50 Then P.LineTo(x,cvs.Bitmap.Height)
      If PerCent>62 Then P.LineTo(0,cvs.Bitmap.Height)
      If PerCent>=75 Then P.LineTo(0,y)
      If PerCent>87 Then P.LineTo(0,0)
      If PerCent<100 Then P.LineTo(CoX,CoY) Else P.LineTo(x,0)
      'P.LineTo(x,y)
      
      canv.ClipPath(P)
      canv.DrawCircle(x,y,radius,Bit.And(Color,0x00FFFFFF)+0x55000000,True,1dip)
      
      Dim bmp2 As Bitmap
      bmp2.InitializeMutable(cvs.Bitmap.Width, cvs.Bitmap.Height)
   
      Dim canv2 As Canvas
      canv2.Initialize2(bmp2)
      canv2.AntiAlias=True
      
      Dim r As Rect
      r.Initialize(0, 0, cvs.Bitmap.Width, cvs.Bitmap.Height)
      canv2.DrawBitmap(cvs.Bitmap,Null,r)
      canv2.DrawBitmap(canv.Bitmap,Null,r)

      CoX = x-(radius)*Cos((2*cPI)*((PerCent+25)/100))
      CoY = y-(radius)*Sin((2*cPI)*((PerCent+25)/100))
      canv2.DrawLine(x,y,CoX,CoY,Color,1dip)

      Vw.SetBackgroundImage(canv2.Bitmap)
   End If
End Sub

Visualizza il profilo dell'utente http://basic4x.forumattivo.com

4 Progress Bar & Scorrimento laterale il Dom Apr 22, 2018 5:12 pm

Dust

avatar
Admin
Admin


Codice:

Public Sub ProgressBall2(PerCent As Int,Color As Int)
   Dim Raggio As Int = Min(Vw.Width,Vw.Height)/2
   
   If PerCent>=0 And PerCent<=100 Then
      Dim bmp As Bitmap
      bmp.InitializeMutable(cvs.Bitmap.Width, cvs.Bitmap.Height)
   
      Dim canv As Canvas
      canv.Initialize2(bmp)
      canv.AntiAlias=True
      
      Dim r As Rect
      r.Initialize(0, 0, cvs.Bitmap.Width, cvs.Bitmap.Height)
      canv.DrawBitmap(cvs.Bitmap,Null,r)
      canv.DrawCircle(cvs.Bitmap.Width/2,cvs.Bitmap.Height/2,Raggio*((100-PerCent)/100),Color,True,1)
      Vw.SetBackgroundImage(canv.Bitmap)
   End If
End Sub

Public Sub ProgressBall(PerCent As Int,Color As Int)
   Dim Raggio As Int = (Min(Vw.Width,Vw.Height)/2)
   
   If PerCent>=0 And PerCent<=100 Then
      Dim bmp As Bitmap
      bmp.InitializeMutable(cvs.Bitmap.Width, cvs.Bitmap.Height)
   
      Dim canv As Canvas
      canv.Initialize2(bmp)
      canv.AntiAlias=True
      
      Dim r As Rect
      r.Initialize(0, 0, cvs.Bitmap.Width, cvs.Bitmap.Height)
      canv.DrawBitmap(cvs.Bitmap,Null,r)
      canv.DrawCircle(cvs.Bitmap.Width/2,cvs.Bitmap.Height/2,Raggio*(1-(PerCent/200)),Color,False,Raggio*(PerCent/100))
      Vw.SetBackgroundImage(canv.Bitmap)
   End If
End Sub

Scorrimento laterale

Codice:

Public Sub ProgressAppears(PerCent As Int)
   If PerCent>=0 And PerCent<=100 Then
      Dim bmp As Bitmap
      bmp.InitializeMutable(cvs.Bitmap.Width, cvs.Bitmap.Height)
   
      Dim canv As Canvas
      canv.Initialize2(bmp)
      canv.AntiAlias=True
      
      Dim CoX As Int = x-((radius*1.2)-1dip)*Cos((2*cPI)*((PerCent+25)/100))
      Dim CoY As Int = y-((radius*1.2)-1dip)*Sin((2*cPI)*((PerCent+25)/100))
      
      Dim P As Path
      P.Initialize(x,y)
      P.LineTo(x,0)
      If PerCent>12 Then P.LineTo(cvs.Bitmap.Width,0)
      If PerCent>=25 Then P.LineTo(cvs.Bitmap.Width,y)
      If PerCent>37 Then P.LineTo(cvs.Bitmap.Width,cvs.Bitmap.Height)
      If PerCent>=50 Then P.LineTo(x,cvs.Bitmap.Height)
      If PerCent>62 Then P.LineTo(0,cvs.Bitmap.Height)
      If PerCent>=75 Then P.LineTo(0,y)
      If PerCent>87 Then P.LineTo(0,0)
      If PerCent<100 Then P.LineTo(CoX,CoY) Else P.LineTo(x,0)
      'P.LineTo(x,y)
      
      canv.ClipPath(P)
      'canv.DrawCircle(x,y,radius,Bit.And(Color,0x00FFFFFF)+0x55000000,True,1dip)
      Dim r As Rect
      r.Initialize(0, 0, cvs.Bitmap.Width, cvs.Bitmap.Height)
      canv.DrawBitmap(cvs.Bitmap,Null,r)
      
      Vw.SetBackgroundImage(canv.Bitmap)
   End If
End Sub

Visualizza il profilo dell'utente http://basic4x.forumattivo.com

5 Arco e Riempimento il Dom Apr 22, 2018 5:13 pm

Dust

avatar
Admin
Admin
Arco
Codice:

Public Sub ProgressArc(PerCent As Int,Color As Int,ArcPen As Int)
   If PerCent>=0 And PerCent<=100 Then
      Dim bmp As Bitmap
      bmp.InitializeMutable(cvs.Bitmap.Width, cvs.Bitmap.Height)
   
      Dim canv As Canvas
      canv.Initialize2(bmp)
      canv.AntiAlias=True
      
      Dim CoX As Int = x-((radius*1.2)-1dip)*Cos((2*cPI)*((PerCent+25)/100))
      Dim CoY As Int = y-((radius*1.2)-1dip)*Sin((2*cPI)*((PerCent+25)/100))
      
      Dim P As Path
      P.Initialize(x,y)
      P.LineTo(x,0)
      If PerCent>12 Then P.LineTo(cvs.Bitmap.Width,0)
      If PerCent>=25 Then P.LineTo(cvs.Bitmap.Width,y)
      If PerCent>37 Then P.LineTo(cvs.Bitmap.Width,cvs.Bitmap.Height)
      If PerCent>=50 Then P.LineTo(x,cvs.Bitmap.Height)
      If PerCent>62 Then P.LineTo(0,cvs.Bitmap.Height)
      If PerCent>=75 Then P.LineTo(0,y)
      If PerCent>87 Then P.LineTo(0,0)
      If PerCent<100 Then P.LineTo(CoX,CoY) Else P.LineTo(x,0)
      'P.LineTo(x,y)
      
      canv.ClipPath(P)
      canv.DrawCircle(x,y,radius-(ArcPen/2),Color,False,ArcPen)
            
      Dim bmp2 As Bitmap
      bmp2.InitializeMutable(cvs.Bitmap.Width, cvs.Bitmap.Height)
   
      Dim canv2 As Canvas
      canv2.Initialize2(bmp2)
      canv2.AntiAlias=True
      
      Dim r As Rect
      r.Initialize(0, 0, cvs.Bitmap.Width, cvs.Bitmap.Height)
      canv2.DrawBitmap(cvs.Bitmap,Null,r)
      canv2.DrawBitmap(canv.Bitmap,Null,r)
      
      CoX = x-(radius-3dip)*Cos((2*cPI)*((PerCent+25)/100))
      CoY = y-(radius-3dip)*Sin((2*cPI)*((PerCent+25)/100))
      canv2.Drawcircle(x,(ArcPen/2),(ArcPen/2),Color,True,1dip)
      canv2.Drawcircle(CoX,CoY,(ArcPen/2),Color,True,1dip)
      
      Vw.SetBackgroundImage(canv2.Bitmap)
   End If
End Sub

Riempimento
Codice:

Public Sub ProgressFill(PerCent As Int,Color As Int)
   If PerCent>=0 And PerCent<=100 Then
         
      Dim canv As Canvas = CreateBitmap(cvs.Bitmap.Width, cvs.Bitmap.Height)
      canv.AntiAlias=True
      
      Dim r As Rect
      r.Initialize(0, 0, cvs.Bitmap.Width, cvs.Bitmap.Height)
      canv.DrawBitmap(cvs.Bitmap,Null,r)
      r.Initialize(0, cvs.Bitmap.Height, cvs.Bitmap.Width, cvs.Bitmap.Height*(1-(PerCent/100)))
      canv.DrawRect(r,Color,True,1dip)
      Vw.SetBackgroundImage(canv.Bitmap)
   End If
End Sub

Public Sub ProgressSwipe(PerCent As Int,Color As Int)
   If PerCent>=0 And PerCent<=100 Then
         
      Dim canv As Canvas = CreateBitmap(cvs.Bitmap.Width, cvs.Bitmap.Height)
      canv.AntiAlias=True
      
      Dim r As Rect
      r.Initialize(0, 0, cvs.Bitmap.Width, cvs.Bitmap.Height)
      canv.DrawRect(r,Color,True,1dip)
      Dim Col As Int =0xFFFFFFFF-Bit.And(Color,0x00FFFFFF)
      Dim MaxLine As Int = Min(10,cvs.Bitmap.Width/5dip)
      For i=1 To MaxLine-1
         canv.DrawLine((cvs.Bitmap.Width/MaxLine)*i,y-5dip,(cvs.Bitmap.Width/MaxLine)*i,y+5dip,Col,1dip)
      Next
      
      Dim K As Int =cvs.Bitmap.Width*(100-PerCent)/100
      r.Initialize(k, 0, cvs.Bitmap.Width+k, cvs.Bitmap.Height)
      canv.DrawBitmap(cvs.Bitmap,Null,r)
      Vw.SetBackgroundImage(canv.Bitmap)
   End If
End Sub

Visualizza il profilo dell'utente http://basic4x.forumattivo.com

Contenuto sponsorizzato


Tornare in alto  Messaggio [Pagina 1 di 1]

Permessi di questa sezione del forum:
Non puoi rispondere agli argomenti in questo forum