Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private xui As XUI
Private pnl As B4XView
Private mask As B4XView
Private bc As BitmapCreator
Private scale As Float
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.Show
MainForm.RootPane.LoadLayout("1")
scale = xui.Scale * 2
pnl = xui.CreatePanel("pnl")
MainForm.RootPane.AddNode(pnl, 10dip, 10dip, 400dip, 200dip)
Dim img As B4XView = CreateImageView
pnl.AddView(img, 0, 0, pnl.Width, pnl.Height)
img.SetBitmap(xui.LoadBitmapResize(File.DirAssets, "grattami.jpg", img.Width, img.Height, False))
mask = CreateImageView
pnl.AddView(mask, 0, 0, pnl.Width, pnl.Height)
bc.Initialize(mask.Width / scale, mask.Height / scale)
bc.DrawRect(bc.TargetRect, xui.Color_Black, True, 0)
bc.SetBitmapToImageView(bc.Bitmap, mask)
End Sub
Sub pnl_Touch (Action As Int, X As Float, Y As Float)
If Action = pnl.TOUCH_ACTION_MOVE Then
Dim r As B4XRect
r.Initialize(Max(0, x / scale - 10), Max(0, y / scale - 10), 0, 0)
r.Right = Min(bc.mWidth, r.Left + 20)
r.Bottom = Min(bc.mHeight, r.Top + 20)
MakeMoreTransparent(r)
bc.SetBitmapToImageView(bc.Bitmap, mask)
End If
End Sub
Sub MakeMoreTransparent(rect As B4XRect)
Dim pm As PremultipliedColor
For y = rect.Top To rect.Bottom - 1
For x = rect.Left To rect.Right - 1
bc.GetPremultipliedColor(x, y, pm)
pm.a = Bit.And(pm.a, 0xff) * 0.9
bc.SetPremultipliedColor(x, y, pm)
Next
Next
End Sub
Sub CreateImageView As B4XView
Dim iv1 As ImageView
iv1.Initialize("")
Return iv1
End Sub