Erm... okay...
I opted to use this code because I tested its speed against netmaestro's version, and this one was faster on my computer. Netmaestro's code was "neater" however, in the sense that it doesn't have to keep redrawing to keep the drawn items on the screen if other window overlaps, or when the window is moved "off screen". This once does.
But for my purpose, I simply need it to show the progress flicker free, and once it's done, disappear.
This is how I'm doing it now, but I have a funny feeling there's a better way to accomplish this. Maybe someone can help?
Code: Select all
Enumeration
#Window
#Text
#StatusBar
EndEnumeration
Global xStart.I
Global yStart.I
Global xChar.I
Global yChar.I
Procedure LoadCharMap()
Protected I.I ; Iteration
Protected A.S ; Ascii char
Protected W.I ; char Width
Protected H.I ; char Height
Protected Font.I
Font = FontID(LoadFont(#PB_Any, "Verdana", 10))
CreateImage(256, 16, 16)
For I = 32 To 255
A = Chr(I)
StartDrawing(ImageOutput(256) )
DrawingFont(Font)
W = TextWidth(A)
H = TextHeight(A)
StopDrawing()
CreateImage(I, W, H)
StartDrawing(ImageOutput(I) )
Box(0, 0, W, H, GetSysColor_(#COLOR_BTNFACE) )
DrawingFont(Font)
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(0, 0, A, RGB(255,50,50))
StopDrawing()
Next I
EndProcedure
Procedure SetDisplayStart(x.I, y.I)
xStart = x
yStart = y
EndProcedure
Procedure DisplayHome()
xChar = xStart
yChar = yStart
EndProcedure
Procedure DisplayCarriageReturn()
xChar = xStart
EndProcedure
Procedure DisplayLineFeed()
yChar + ImageHeight(32)
EndProcedure
Procedure DisplayString(StringContent.S)
Protected I.I
Protected A.I
For I = 1 To Len(StringContent)
A = Asc(Mid(StringContent, I, 1) )
If A > 31
DrawImage(ImageID(A), xChar, yChar)
xChar + ImageWidth(A)
Else
Select A
Case 13
DisplayCarriageReturn()
Case 10
DisplayLineFeed()
EndSelect
EndIf
Next I
EndProcedure
Procedure DisplayText(X.I, Y.I, Text.S)
SetDisplayStart(X, Y)
DisplayHome()
DisplayCarriageReturn()
DisplayString(Text)
EndProcedure
Procedure DrawThisBaby(void)
#Maxx = 999
For x = 1 To #Maxx
N + 1
StartDrawing(WindowOutput(#Window) )
DisplayText(5, 5, Str(N) )
DisplayText(500, 5, Str(#Maxx-N) )
DisplayText(5, 30, "This is a long text to test if it flickers")
DisplayText(5, 80, Str(N) )
StopDrawing()
Next
;*******************************************************
; This is how I clear it now. Is there a "better" way?
;*******************************************************
; StartDrawing(WindowOutput(#Window) )
; DisplayText(5, 5, " " )
; DisplayText(500, 5, " " )
; DisplayText(5, 30, " ")
; DisplayText(5, 80, " " )
; StopDrawing()
EndProcedure
If OpenWindow(#Window, #PB_Ignore, 0, 600, 100, "Test")
CreateStatusBar(#StatusBar, WindowID(#Window))
LoadCharMap()
ButtonGadget(0, 200, 5, 200, 25, "MyButton")
CreateThread(@DrawThisBaby(),0)
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
Thanks y'all!
