Kind of Showtoast for non Android devices
Posted: Tue Oct 11, 2016 9:54 am
I like to share my faketoast function I wrote yesterday evening.
It's not as elegant as the Android showtoast() (no fading and blocking while shown), but it's useful to get a better impression of how the programm looks like on Android (needs more parameter polishing, the parameters used here were a quick shot).
Use it like a real toast. Mind that the function does not change font properties back to the properties before calling the function. Radius of the edges can get adjusted as can the thickness of the borders of the toast or the duration of getting it shown (a simple wait). I use a fixed id (1000) for brush and sprite here, probaby a dynamically ID woud be better, but I was too lazy...
It's not as elegant as the Android showtoast() (no fading and blocking while shown), but it's useful to get a better impression of how the programm looks like on Android (needs more parameter polishing, the parameters used here were a quick shot).
Code: Select all
Function p_faketoast(my_ftstring$, Xpos$, Ypos$)
SetFillStyle (#FILLCOLOR)
SetFont(#SANS, 20)
SetFontColor (#WHITE)
CreateTextObject (1000, my_ftstring$)
;DebugPrint(GetAttribute (#TEXTOBJECT,1000, #ATTRHEIGHT))
Local xftoff$=40
Local yftoff$=16
Local ftwidth$=GetAttribute (#TEXTOBJECT,1000, #ATTRWIDTH, #ATTRHEIGHT)
Local ftheight$=GetAttribute (#TEXTOBJECT,1000, #ATTRHEIGHT)
Local ftradius$=18 ;radius of the edges
If ftheight$<ftradius$+5 Then ftheight$=ftradius$+5 ;bis Radius=20
CreateBrush (1000, xftoff$+ftwidth$, yftoff$+ftheight$, #BLACK)
SelectAlphaChannel(1000)
SetAlphaIntensity(0)
Box(1,1,ftwidth$+xftoff$, ftheight$+yftoff$)
SetAlphaIntensity(120)
Arc(ftwidth$-ftradius$+xftoff$-ftradius$,0,ftradius$,ftradius$,270,360);re oben
Arc(0,ftheight$-ftradius$+yftoff$-ftradius$,ftradius$,ftradius$,90,180) ;li unten
Arc(0,0,ftradius$,ftradius$,180,270) ;li oben
Arc(ftwidth$-ftradius$+xftoff$-ftradius$,ftheight$-ftradius$+yftoff$-ftradius$,ftradius$,ftradius$,0,90);re unten
Box(0,ftradius$,xftoff$+ftwidth$+1,ftheight$+yftoff$-ftradius$-ftradius$+1)
Box(ftradius$,0,ftwidth$+xftoff$-ftradius$-ftradius$+1,xftoff$+ftheight$)
EndSelect
SelectBrush(1000)
DisplayTextObject(1000, xftoff$/2,yftoff$/2)
EndSelect
CreateSprite (1000, #BRUSH, 1000, xftoff$+ftwidth$, yftoff$+ftheight$,1,1)
DisplaySprite (1000, Xpos$, Ypos$ )
Wait (150)
DisplaySprite (1000, -1000, -1000 )
EndFunction