Code: Alles auswählen
EnableExplicit
;ImageDecoder
UsePNGImageDecoder()
;- Enumerations / DataSections
;- Windows
Enumeration
#Window_0
EndEnumeration
;- Gadgets
Enumeration
#Image_spritz
EndEnumeration
;- Images
Enumeration
#Image_BG
EndEnumeration
;- Fonts
Enumeration
#Arial24
EndEnumeration
;- Global
Global quit.i, q1, spritzTH.i
;- Define
Define Event.i, EventWindow.i, EventGadget.i, EventType.i, EventMenu.i
Define a$
If CreateImage(#Image_BG, 359, 112, 24) = 0
End
EndIf
LoadFont(#Arial24, "Arial", 24, #PB_Font_HighQuality)
Procedure OpenWindow_Window_0()
Protected res.i
res = #False
If OpenWindow(#Window_0, #PB_Ignore, #PB_Ignore, 359, 112, "Spritz", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar)
ImageGadget(#Image_spritz, 0, 0, 359, 112, 0)
res = #True
EndIf
ProcedureReturn res
EndProcedure
Procedure findBestLetter(word.s)
Protected wordLength.i, bestLetter.i
If word <> ""
wordLength = Len(word)
Select wordLength
Case 1
bestLetter = 0 ;first
Case 2, 3, 4, 5
bestLetter = 1 ;second
Case 6, 7, 8, 9
bestLetter = 2 ;third
Case 10, 11, 12, 13
bestLetter = 3 ;fourth
Default
bestLetter = 4 ;fifth
EndSelect
If (Mid(word, bestLetter + 1, 1) = " ")
bestLetter - 1
EndIf
EndIf
ProcedureReturn bestLetter
EndProcedure
Procedure spritz(temp.i)
Protected word.s, bestLetter.i, leftWidth.i, n.i, redWidth.i, wordWidth.i, wordX.i, offs.i
NewList words.s()
If ReadFile(0, "spritz.txt")
While Eof(0) = 0
word = ReadString(0)
AddElement(words())
words() = word
Wend
CloseFile(0)
EndIf
ResetList(words())
Repeat
If NextElement(words())
word = words()
Else
ResetList(words())
EndIf
bestLetter = findBestLetter(word)
If StartDrawing(ImageOutput(#Image_BG))
Box(0, 0, 359, 112, RGB(219, 220, 221))
RoundBox(11, 11, 337, 69, 3, 3, RGB(255, 255, 255))
Box(21, 18, 317, 2, RGB(0, 0, 0))
Box(21, 71, 317, 2, RGB(0, 0, 0))
Box(128, 18, 2, 8, RGB(0, 0, 0))
Box(128, 65, 2, 8, RGB(0, 0, 0))
If word <> ""
DrawingFont(FontID(#Arial24))
DrawingMode(#PB_2DDrawing_Transparent)
wordWidth = TextWidth(word)
leftWidth = 0
For n = 1 To bestLetter + 1
leftWidth = leftWidth + TextWidth(Mid(word, n, 1))
Next
redWidth = TextWidth(Mid(word, bestletter + 1, 1))
wordX = 128 - (leftWidth - (redWidth / 2))
offs = 0
For n = 1 To Len(word)
If n = bestLetter + 1
DrawText(wordX + offs, 30, Mid(word, n, 1), RGB(255, 0, 0))
Else
DrawText(wordX + offs, 30, Mid(word, n, 1), RGB(0, 0, 0))
EndIf
offs = offs + TextWidth(Mid(word, n, 1))
Next n
EndIf
StopDrawing()
SetGadgetState(#Image_spritz, ImageID(#Image_BG))
EndIf
Delay(250)
Until quit = 1
EndProcedure
If OpenWindow_Window_0()
spritzTH = CreateThread(@spritz(), 0)
;- Event loop
Repeat
Event = WaitWindowEvent(100)
EventGadget = EventGadget()
EventType = EventType()
EventWindow = EventWindow()
Select Event
Case #PB_Event_Gadget
If EventGadget = #Image_spritz
EndIf
Case #PB_Event_CloseWindow
quit = 1
EndSelect
q1 = IsThread(spritzTH)
Until quit = 1 And q1 = 0
EndIf
End