Step Wizard
Posted: Sat Nov 02, 2019 7:52 pm
Here a small code snippet to visualize progress steps
Code: Select all
Global NewMap mgadgets()
Procedure SetWizard(st$,gadget,iSelected,iBackground=$e0e0e0,selected_col=$00cc99,selected_textcol=#White,nonselected_col=$e0e0e0,nonselected_textcol=0, iTriangleWidth=15)
w=GadgetWidth(gadget): h=GadgetHeight(gadget): iBackground=$e0e0e0
iFont=LoadFont(#PB_Any,"Tahoma",10,#PB_Font_HighQuality|#PB_Font_Bold)
ipic=CreateImage(#PB_Any,w,h,24,iBackground)
If IsImage(ipic)
st$=Trim(st$,"|")
iCount=CountString(st$,"|")+1
StartDrawing(ImageOutput(ipic))
DrawingFont(FontID(iFont))
ww.d=w/iCount
For i=0 To icount-1
If iSelected=i+1
col=selected_col
textcol=selected_textcol
Else
col=nonselected_col
textcol=nonselected_textcol
EndIf
If i=iCount-1:
Box(x,0,ww,h,col)
Else
Box(x,0,ww-iTriangleWidth,h,col)
linecol=$ffffff
LineXY(x+ww-iTriangleWidth, 0,x+ww, h/2, linecol)
LineXY(x+ww-iTriangleWidth, 0,x+ww-1, h/2,linecol)
LineXY(x+ww-iTriangleWidth, h,x+ww, h/2, linecol)
LineXY(x+ww-iTriangleWidth, h,x+ww-1, h/2, linecol)
FillArea(x+ww-iTriangleWidth+1, 5, -1, col)
EndIf
FillArea(x-1, 5, -1, col)
FillArea(x-1, h-5, -1, col)
stext$=StringField(st$,i+1,"|")
tw=TextWidth(stext$)
th=TextHeight(stext$)
DrawText(x+((ww-tw)/2),(h-th)/2,stext$,textcol,col)
x+ww
Next
StopDrawing()
FreeFont(ifont)
StartDrawing(CanvasOutput(gadget))
DrawImage(ImageID(ipic),0,0)
StopDrawing()
FreeImage(ipic)
EndIf
EndProcedure
Procedure ShowWin()
Protected mw=800: mh=200
Protected iStepHeight=80;160
mgadgets("main")= OpenWindow(#PB_Any, 0, 0, mw, mh, "TestWizard", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
If IsWindow(mgadgets("main"))
mgadgets("stepwizard")=CanvasGadget(#PB_Any,0,0,mw,50,0)
mgadgets("next")=ButtonGadget(#PB_Any,WindowWidth(mgadgets("main"))-110,mh-40,100,30,"Next")
mgadgets("prev")=ButtonGadget(#PB_Any,GadgetX(mgadgets("next"))-110,mh-40,100,30,"Prev")
iStep=1
st$="Step1|Step2|Step3|Finish"
SetWizard(st$, mgadgets("stepwizard"),iStep)
Repeat
Event = WaitWindowEvent(10)
Select event
Case #PB_Event_CloseWindow ; If the user has pressed on the close button
Quit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case mgadgets("prev")
If iStep>1: iStep-1:EndIf
SetWizard(st$, mgadgets("stepwizard"),iStep)
Case mgadgets("next")
If iStep<=CountString(st$,"|"): iStep+1:EndIf
SetWizard(st$, mgadgets("stepwizard"),iStep)
EndSelect
EndSelect
Until quit=1
CloseWindow(mgadgets("main"))
EndIf
EndProcedure
ShowWin()