B4A Library SD: ScratchCard

I created a new view / panel that simulates the effect of scratch cards.
Create a panel from code that design and you can hook other views that will be visible after the user has passed the finger on the surface.

It has all the properties of a panel and also returns the native panel.

SD_Scratchcard

Author:
Star-Dust
Version: 0.03
  • PanelScratchCard
    • Events:
      • Click
      • LongClick
      • Touch (Action As Int, Coordinate As String)
    • Fields:
      • ACTION_DOWN As Int
      • ACTION_MOVE As Int
      • ACTION_UP As Int
      • thickness As Int
    • Functions:
      • AddToParent (Parent As Panel, Left As Int, Top As Int, Width As Int, Height As Int) As String
      • AddView (View As View, Left As Int, Top As Int, Width As Int, Height As Int) As String
      • BringToFront As String
      • Class_Globals As String
      • Clear As String
      • DesignerCreateView (Base As Panel, Lbl As Label, Props As Map) As String
      • FillingPercentage As Double
        Value -> 0.0 to 100.0
      • Initialize (Callback As Object, EventName As String) As String
      • Invalidate As String
      • IsInitialized As Boolean
        Verifica se l'oggetto sia stato inizializzato.
      • LoadLayout (layoutFile As String) As String
      • Panel As Panel
      • RemoveAllViews As String
      • RemoveView As String
      • RemoviewAt (Index As Int) As String
      • RequestFocus As String
      • SendToBack As String
      • SetBackgroundImage (Bitmap As Bitmap) As String
      • SetColorAnimated (Duration As Int, FromColor As Int, ToColor As Int) As String
      • SetLayout (Left As Int, Top As Int, Width As Int, Height As Int) As String
      • SetLayoutAnimated (Duration As Int, Left As Int, Top As Int, Width As Int, Height As Int) As String
      • Scratch (Enabled As Boolean)
        Default is Enabled
    • Properties:
      • Color
      • Elevation As Float
      • enabled As Boolean
      • Height As Int
      • Left As Int
      • Parent As Panel [read only]
      • Tag As Object
      • Top As Int
      • Visible As Boolean
      • Width As Int
Video1.gif


----------------------------
Rel. 0.02 - Added Clear method
Rel. 0.03 - Added FillingPercentage method
--------------------------

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 PA As PanelScratchCard
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")
    PA.Initialize(Me,"Pa")
    PA.AddToParent(Activity,0,0,100%x,100%y)
    PA.LoadLayout("Layout2")
    PA.SetBackgroundImage(LoadBitmap(File.DirAssets,"b4a_bubble.png"))
End Sub

Private Sub ButtonVerify_Click
    Log(PA.FillingPercentage)
End Sub
 

Attachments

  • sample1.zip
    15.8 KB · Views: 662
  • SD_Scratchcard.zip
    6.6 KB · Views: 156
Last edited:

EduardoElias

Active Member
Licensed User
Longtime User
@Star-Dust good work! can you tell me when using your library how i find out when the user have already scratched most of the image?

Idea is to give the prize when the user already can see the image scratched no need to scratch 100%. Anyways I cant see how to detect from your library if the user completed everything.

Thank you for any cluet !
 

Star-Dust

Expert
Licensed User
Longtime User
@Star-Dust good work! can you tell me when using your library how i find out when the user have already scratched most of the image?

Idea is to give the prize when the user already can see the image scratched no need to scratch 100%. Anyways I cant see how to detect from your library if the user completed everything.

Thank you for any cluet !
At the moment there is no such function, I will see in the future if it can be possible to achieve it
 

Theera

Expert
Licensed User
Longtime User
I have seen Donmamfred's library like yours, but I always forgot to ask what the projects are used.Would you mind give the advise forme.I have a little of experience about projects.(How is it useful?)
 

Star-Dust

Expert
Licensed User
Longtime User
I give you direct advice, @DonManfred 's is better.
 

LucaMs

Expert
Licensed User
Longtime User
Italian, sorry, but this is just a curiosity for my friend @Star-Dust (also you are surely using Chrome and it will be easy to have it translate this post 😊).

L'ho visto adesso; circa un migliaio di anni fa lo feci anch'io (non come custom view), per divertimento. Chissà se riuscirei a ritrovare quel progetto 😁

La tua view, comunque, può essere utile; potresti farne una versione B4X - crossplatform, magari solo per iOS, è difficile che possa servire per applicazioni desktop.
 

Star-Dust

Expert
Licensed User
Longtime User
Italian, sorry, but this is just a curiosity for my friend @Star-Dust (also you are surely using Chrome and it will be easy to have it translate this post 😊).

L'ho visto adesso; circa un migliaio di anni fa lo feci anch'io (non come custom view), per divertimento. Chissà se riuscirei a ritrovare quel progetto 😁

La tua view, comunque, può essere utile; potresti farne una versione B4X - crossplatform, magari solo per iOS, è difficile che possa servire per applicazioni desktop.
I made it many years ago and at the time I was not developing b4x. I will not translate it because it is not very requested
 

Theera

Expert
Licensed User
Longtime User
I give you direct advice, @DonManfred 's is better.
Your Library is good as the same as Donmamfred's. But I don't know how to apply for the project.I'm sorry If my English is teribled.
 

LucaMs

Expert
Licensed User
Longtime User
.I'm sorry If my English is teribled.
Use some software translator (Google Translate).
Look how good my Thai is:

ใช้ซอฟต์แวร์แปลบางตัว (Google Translate)
ดูสิว่าภาษาไทยของฉันดีแค่ไหน:

Chı̂ sxft̒wær̒ pæl bāng tạw (Google Translate)
dū s̄i ẁā p̣hās̄ʹā thịy k̄hxng c̄hạn dī khæ̀ h̄ịn:

😁
 

Star-Dust

Expert
Licensed User
Longtime User
Your Library is good as the same as Donmamfred's. But I don't know how to apply for the project.I'm sorry If my English is teribled.
you have to know how to use it. If you don't have how to use it, you obviously don't need it. It doesn't have a professional application, more of a recreational purpose
 
Top