Step Wizard

Share your advanced PureBasic knowledge/code with the community.
Oliver13
User
User
Posts: 82
Joined: Thu Sep 30, 2010 6:40 am

Step Wizard

Post by Oliver13 »

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()
User avatar
skywalk
Addict
Addict
Posts: 3960
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Step Wizard

Post by skywalk »

Beautiful 8)
Even better if you drop the buttons and act directly on user clicks of canvasgadget individual steps. :wink:
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
minimy
Enthusiast
Enthusiast
Posts: 336
Joined: Mon Jul 08, 2013 8:43 pm

Re: Step Wizard

Post by minimy »

Really good!! thanks for share. Nice job!
If translation=Error: reply="Sorry, Im Spanish": Endif
BarryG
Addict
Addict
Posts: 3267
Joined: Thu Apr 18, 2019 8:17 am

Re: Step Wizard

Post by BarryG »

skywalk wrote:drop the buttons
I disagree. The buttons are expected, so keep them. But maybe allow clicking the arrow steps as well?
User avatar
skywalk
Addict
Addict
Posts: 3960
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Step Wizard

Post by skywalk »

Less is always more. :wink:
My real estate is precious.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: Step Wizard

Post by Thorsten1867 »

Nice idea.
I made a module with a gadget (GradualProgress-Module) out of it.
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Step Wizard

Post by Kwai chang caine »

The simple idea is always the best :wink:
Very nice and surprising effect too, thanks for sharing 8)
ImageThe happiness is a road...
Not a destination
User avatar
StarBootics
Addict
Addict
Posts: 984
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: Step Wizard

Post by StarBootics »

Hello everyone,

This is my take for a Step Wizard Gadget

Code: Select all

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Project name : StepWizardGadget
; File Name : StepWizardGadget - Module.pb
; File version: 1.0.0
; Programming : OK
; Programmed by : StarBootics
; Date : 15-11-2019
; Last Update : 15-11-2019
; PureBasic code : V5.71 LTS
; Platform : Windows, Linux, MacOS X
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Programming notes
;
; Based on Olivier13 (English forum) original source code. 
; See here : https://www.purebasic.fr/english/viewtopic.php?f=12&t=73926
;
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

DeclareModule StepWizard
  
  Declare Gadget(GadgetID.i, x.l, y.l, Width.l, Height.l, Steps.s)
  Declare SetSteps(GadgetID.i, Steps.s)
  Declare SetSelectedColor(GadgetID.i, BackColor.l, TextColor.l)
  Declare SetNonSelectedColor(GadgetID.i, BackColor.l, TextColor.l)
  Declare SetStepID(GadgetID.i, StepID.l)
  Declare.l GetStepID(GadgetID.i)
  Declare PreviousStep(GadgetID.i)
  Declare NextStep(GadgetID.i)
  Declare SetUserData(GadgetID.i, P_UserData.i)
  Declare.i GetUserData(GadgetID.i)
  Declare Free(GadgetID.i)
  
EndDeclareModule

Module StepWizard
 
  Structure StepWizard
    
    Steps.s
    StepID.l
    SelectedColor.l
    SelectedTextColor.l
    NonSelectedColor.l
    NonSelectedTextColor.l  
    TriangleWidth.l
    ImageHandle.i
    UserData.i
    
  EndStructure
  
  Macro IsBetween(Value, Lower, Upper)
    
    ((Value) >= (Lower) And (Value) <= (Upper))
    
  EndMacro
  
  Procedure.i CreateNewStepWizard()
    
    *StepWizardA.StepWizard = AllocateMemory(SizeOf(StepWizard))
    
    If *StepWizardA = #Null
      MessageRequester("Fatal Error", "CreateNewStepWizard() - Impossible to Allocate Memory !")
      End
    EndIf
    
    ProcedureReturn *StepWizardA
  EndProcedure
  
  Procedure Draw(GadgetID.i)
    
    If IsGadget(GadgetID)
  
      *StepWizardA.StepWizard = GetGadgetData(GadgetID)
      
      If *StepWizardA <> #Null

        StepCount = CountString(*StepWizardA\Steps, "|") + 1
        w.l = GadgetWidth(GadgetID)
        h.l = GadgetHeight(GadgetID)
        ww.d = w / StepCount
        
        If StartDrawing(ImageOutput(*StepWizardA\ImageHandle))
          
          For Index = 0 To StepCount - 1
            
            If *StepWizardA\StepID = Index + 1
              col = *StepWizardA\SelectedColor
              textcol = *StepWizardA\SelectedTextColor
            Else
              col = *StepWizardA\NonSelectedColor
              textcol = *StepWizardA\NonSelectedTextColor
            EndIf
            
            If Index = StepCount - 1
              Box(x, 0, ww, h, col) 
            Else
              Box(x, 0, ww - *StepWizardA\TriangleWidth, h, col) 
              LineXY(x+ww-*StepWizardA\TriangleWidth, 0, x + ww, h/2, $ffffff)
              LineXY(x+ww-*StepWizardA\TriangleWidth, 0, x + ww - 1, h/2, $ffffff)
              LineXY(x+ww-*StepWizardA\TriangleWidth, h, x + ww, h/2, $ffffff)
              LineXY(x+ww-*StepWizardA\TriangleWidth, h, x + ww - 1, h/2, $ffffff)
              FillArea(x + ww - *StepWizardA\TriangleWidth + 1, 5, -1, col)
              
            EndIf
            
            FillArea(x-1, 5, -1, col)
            FillArea(x-1, h-5, -1, col)
            
            
            
            StepName.s = StringField(*StepWizardA\Steps, Index + 1, "|")
            tw = TextWidth(StepName)
            th = TextHeight(StepName)
 
            DrawText(x+((ww-tw)/2), (h-th)/2, StepName, textcol, col)
            
            x + ww
            
          Next
          
          StopDrawing()
          
        EndIf
        
        SetGadgetState(GadgetID, ImageID(*StepWizardA\ImageHandle))
        
      EndIf
      
    EndIf
    
  EndProcedure
  
  Procedure Gadget(GadgetID.i, x.l, y.l, Width.l, Height.l, Steps.s)
    
    *StepWizardA.StepWizard = CreateNewStepWizard()
    
    GadgetHandle = ImageGadget(GadgetID, x, y, Width, Height, 0)
    
    If GadgetID = #PB_Any
      GadgetID = GadgetHandle
    EndIf
    
    *StepWizardA\Steps = Steps
    *StepWizardA\StepID = 1
    *StepWizardA\SelectedColor = $00cc99
    *StepWizardA\SelectedTextColor = $ffffff
    *StepWizardA\NonSelectedColor = $e0e0e0
    *StepWizardA\NonSelectedTextColor = $000000  
    *StepWizardA\TriangleWidth = 15
    *StepWizardA\ImageHandle = CreateImage(#PB_Any, Width, Height)

    SetGadgetData(GadgetID, *StepWizardA)
    Draw(GadgetID)
    
    ProcedureReturn GadgetID
  EndProcedure
  
  Procedure SetSteps(GadgetID.i, Steps.s)
    
    If IsGadget(GadgetID)
      
      *StepWizardA.StepWizard = GetGadgetData(GadgetID)
      
      If *StepWizardA <> #Null
        
        *StepWizardA\Steps = Steps
        
        Draw(GadgetID)
        
      EndIf
      
    EndIf
    
  EndProcedure 
  
  Procedure SetSelectedColor(GadgetID.i, BackColor.l, TextColor.l)
    
    If IsGadget(GadgetID)
      
      *StepWizardA.StepWizard = GetGadgetData(GadgetID)
      
      If *StepWizardA <> #Null
        
        *StepWizardA\SelectedColor = BackColor
        *StepWizardA\SelectedTextColor = TextColor
        
        Draw(GadgetID)
        
      EndIf
      
    EndIf
    
  EndProcedure 
  
  Procedure SetNonSelectedColor(GadgetID.i, BackColor.l, TextColor.l)
    
    If IsGadget(GadgetID)
      
      *StepWizardA.StepWizard = GetGadgetData(GadgetID)
      
      If *StepWizardA <> #Null
        
        *StepWizardA\NonSelectedColor = BackColor
        *StepWizardA\NonSelectedTextColor = TextColor
        
        Draw(GadgetID)
        
      EndIf
      
    EndIf
    
  EndProcedure 
  
  Procedure SetStepID(GadgetID.i, StepID.l)
    
    If IsGadget(GadgetID)
      
      *StepWizardA.StepWizard = GetGadgetData(GadgetID)
      
      If *StepWizardA <> #Null

        If IsBetween(StepID, 1, CountString(*StepWizardA\Steps, "|") + 1)
          *StepWizardA\StepID = StepID
          Draw(GadgetID)
        EndIf
        
      EndIf
      
    EndIf
    
  EndProcedure
  
  Procedure.l GetStepID(GadgetID.i)
    
    CurrentStepID = -1
    
    If IsGadget(GadgetID)
      
      *StepWizardA.StepWizard = GetGadgetData(GadgetID)
      
      If *StepWizardA <> #Null
        CurrentStepID = *StepWizardA\StepID
      EndIf
      
    EndIf
    
    ProcedureReturn CurrentStepID
  EndProcedure
 
  Procedure PreviousStep(GadgetID.i)
    
    If IsGadget(GadgetID)
      
      *StepWizardA.StepWizard = GetGadgetData(GadgetID)
      
      If *StepWizardA <> #Null
        
        *StepWizardA\StepID = *StepWizardA\StepID - 1
        
        If *StepWizardA\StepID < 1
          *StepWizardA\StepID = 1
        EndIf
      
        Draw(GadgetID)
        
      EndIf
      
    EndIf
    
  EndProcedure

  Procedure NextStep(GadgetID.i)
    
    If IsGadget(GadgetID)
      
      *StepWizardA.StepWizard = GetGadgetData(GadgetID)
      
      If *StepWizardA <> #Null
        
        *StepWizardA\StepID = *StepWizardA\StepID + 1
        
        If *StepWizardA\StepID > CountString(*StepWizardA\Steps, "|") + 1
          *StepWizardA\StepID = CountString(*StepWizardA\Steps, "|") + 1
        EndIf
        
        Draw(GadgetID)
        
      EndIf
      
    EndIf
    
  EndProcedure
  
  Procedure SetUserData(GadgetID.i, P_UserData.i)
    
    If IsGadget(GadgetID)
      
      *StepWizardA.StepWizard = GetGadgetData(GadgetID)
      
      If *StepWizardA <> #Null
        *StepWizardA\UserData = P_UserData
      EndIf
      
    EndIf
    
  EndProcedure
  
  Procedure.i GetUserData(GadgetID.i)
    
    If IsGadget(GadgetID)
      
      *StepWizardA.StepWizard = GetGadgetData(GadgetID)
      
      If *StepWizardA <> #Null
        P_UserData.i = *StepWizardA\UserData
      EndIf
      
    EndIf
    
    ProcedureReturn P_UserData
  EndProcedure
  
  Procedure Free(GadgetID.i)
    
    If IsGadget(GadgetID)
      
      *StepWizardA.StepWizard = GetGadgetData(GadgetID)
      
      If *StepWizardA <> #Null
        
        If IsImage(*StepWizardA\ImageHandle)
          FreeImage(*StepWizardA\ImageHandle)
        EndIf
        
        FreeMemory(*StepWizardA)
        FreeGadget(GadgetID)
        
      EndIf
      
    EndIf
    
  EndProcedure
  
EndModule

CompilerIf #PB_Compiler_IsMainFile
  
  If OpenWindow(0, 0, 0, 800, 200, "Step Wizard", #PB_Window_ScreenCentered)
    
    StepWizard::Gadget(0, 0, 0, 800, 50, "Step 1|Step 2|Step 3|Step 4|Finish")
    StepWizard::Gadget(1, 0, 55, 800, 50, "Step 1|Step 2|Step 3|Step 4|Finish")
    StepWizard::SetSelectedColor(1, RGB(000, 000, 255), RGB(255, 255, 255))
    
    ButtonGadget(2, WindowWidth(0)-110, 160,100,30,"Next")
    ButtonGadget(3, GadgetX(2)-110,160,100,30,"Prev")
    
    
    Repeat
      
      Select WaitWindowEvent()
          
        Case #PB_Event_Menu
          
          Select EventMenu()
              
          EndSelect
          
        Case #PB_Event_Gadget
          
          Select EventGadget()
              
            Case 2
              StepWizard::NextStep(0)
              StepWizard::NextStep(1)
              
            Case 3
              StepWizard::PreviousStep(0)
              StepWizard::PreviousStep(1)
              
          EndSelect
          
        Case #PB_Event_CloseWindow
          
          Select EventWindow()
              
            Case 0
              Break
              
          EndSelect
          
      EndSelect
      
    ForEver

  EndIf
  
CompilerEndIf

; <<<<<<<<<<<<<<<<<<<<<<<
; <<<<< END OF FILE <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<
Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
User avatar
skywalk
Addict
Addict
Posts: 3960
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Step Wizard

Post by skywalk »

Nice, but...
Your example window cannot be closed.
The drawing is jagged. The vector lib supports anti-aliasing out of the box.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
StarBootics
Addict
Addict
Posts: 984
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: Step Wizard

Post by StarBootics »

skywalk wrote:Your example window cannot be closed.
I don't understand, it work fine here on Linux.
skywalk wrote:The drawing is jagged. The vector lib supports anti-aliasing out of the box.
Maybe if I have a chance I will upgrade the Draw procedure to use the Vector lib but not now I'm too busy with my game project for now.

Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: Step Wizard

Post by Thorsten1867 »

StarBootics wrote:Maybe if I have a chance I will upgrade the Draw procedure to use the Vector lib but not now I'm too busy with my game project for now.
If you're gonna save yourself a lot of work. I'm already using the vector library.

viewtopic.php?f=27&t=73943
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
User avatar
StarBootics
Addict
Addict
Posts: 984
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: Step Wizard

Post by StarBootics »

Hello everyone,

Two years later I have finally updated my code to use VectorDrawing to draw the shapes of the steps. I also added a Left click handler procedure to change the current step by clicking on it or use previous and Next button as you see fit. Finally I have added an instruction to resize the gadget.

I'm going to use this gadget in the Tutorial Manager for my game model editor program.

Best regards
StarBootics

Code: Select all

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Nom du projet : StepWizardGadget
; Nom du fichier : StepWizardGadget - Module.pb
; Version du fichier : 1.1.1
; Programmation : OK
; Alias : StarBootics
; Date : 15-11-2019
; Mise à jour : 07-10-2021
; Code PureBasic : V5.73 LTS
; Plateforme : Windows, Linux, MacOS X
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Programming notes
;
; Based on Olivier13 (English forum) original source code. 
; See here : https://www.purebasic.fr/english/viewtopic.php?f=12&t=73926
;
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

DeclareModule StepWizard
  
  Declare Gadget(GadgetID.i, x.l, y.l, Width.l, Height.l, Steps.s)
  Declare SetSteps(GadgetID.i, Steps.s)
  Declare SetSelectedColor(GadgetID.i, BackColor.l, TextColor.l)
  Declare SetNonSelectedColor(GadgetID.i, BackColor.l, TextColor.l)
  Declare SetStepID(GadgetID.i, StepID.l)
  Declare.l GetStepID(GadgetID.i)
  Declare PreviousStep(GadgetID.i)
  Declare NextStep(GadgetID.i)
  Declare Resize(GadgetID.i, x.l, y.l, Width.l, Height.l)
  Declare SetUserData(GadgetID.i, P_UserData.i)
  Declare.i GetUserData(GadgetID.i)
  Declare Free(GadgetID.i)
  
EndDeclareModule

Module StepWizard
 
  Structure StepWizard
    
    Steps.s
    StepID.l
    SelectedColor.l
    SelectedTextColor.l
    NonSelectedColor.l
    NonSelectedTextColor.l  
    TriangleWidth.d
    UserData.i
    
  EndStructure
  
  Macro IsBetween(Value, Lower, Upper)
    
    ((Value) >= (Lower) And (Value) <= (Upper))
    
  EndMacro
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< Le Constructeur (Private) <<<<<
  
  Procedure.i CreateNewStepWizard()
    
    *StepWizardA.StepWizard = AllocateStructure(StepWizard)
    
    If *StepWizardA = #Null
      MessageRequester("Fatal Error", "CreateNewStepWizard() - Impossible to Allocate Structure !")
      End
    EndIf
    
    ProcedureReturn *StepWizardA
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< L'opérateur Draw (Private) <<<<<
  
	Procedure Private_Triangle(X.f, Y.f, Width.f, Height.f, Reverse.i=#False)
	  
	  If Reverse
	    AddPathLine(X + Width, Y + Round(Height / 2, #PB_Round_Nearest))
      AddPathLine(X, Y)
	  Else
      AddPathLine(X + Width, Y + Round(Height / 2, #PB_Round_Nearest))
      AddPathLine(X, Y + Height)
    EndIf
    
  EndProcedure
  
  Procedure Private_Draw(GadgetID.i)
    
    If IsGadget(GadgetID)
  
      *StepWizardA.StepWizard = GetGadgetData(GadgetID)
      
      If *StepWizardA <> #Null

        StepCount = CountString(*StepWizardA\Steps, "|") + 1
        Width.l = GadgetWidth(GadgetID)
        Height.l = GadgetHeight(GadgetID)
        StepWidth.d = Width / StepCount

        If StartVectorDrawing(CanvasVectorOutput(GadgetID))
          
          For Index = 0 To StepCount - 1
            
            If *StepWizardA\StepID = Index + 1
              Color = *StepWizardA\SelectedColor | $FF000000
            Else
              Color = *StepWizardA\NonSelectedColor | $FF000000
            EndIf
            
            If Index = 0
              
              X.d = 1.0
              Y.d = 1.0
              
              MovePathCursor(X, Y + Height - 2)
              AddPathLine(X, Y)
              AddPathLine(X + StepWidth, Y)
              Private_Triangle(X + StepWidth, Y, *StepWizardA\TriangleWidth, Height - 2)
              ClosePath()
              
              X + StepWidth
              
            ElseIf IsBetween(Index, 1, StepCount - 2)
              
              MovePathCursor(X, Y + Height - 2)
              Private_Triangle(X, Y, *StepWizardA\TriangleWidth, Height - 2, #True)
              
              x + StepWidth
              
              AddPathLine(X, Y)
              Private_Triangle(X, Y, *StepWizardA\TriangleWidth, Height - 2)
              ClosePath()
              
            ElseIf Index = StepCount - 1
              
              StepWidth = Width - StepWidth * (StepCount - 1)
              
              MovePathCursor(X, Y + Height - 2)
              Private_Triangle(X, Y, *StepWizardA\TriangleWidth, Height - 2, #True)
              
              AddPathLine(X + StepWidth-2, Y)
              AddPathLine(X + StepWidth-2, Y + Height - 2)
              ClosePath()
              
            EndIf
            
            VectorSourceColor(Color)
            FillPath(#PB_Path_Preserve)
            VectorSourceColor(RGBA(000, 000, 000, 255))
            StrokePath(2, #PB_Path_RoundCorner) 
            
          Next

          StopVectorDrawing()
          
        EndIf
        
        StepWidth.d = Width / StepCount
        X = 1.0
        
        If StartDrawing(CanvasOutput(GadgetID))
          
          DrawingMode(#PB_2DDrawing_Transparent)
          
          For Index = 0 To StepCount - 1
            
            If *StepWizardA\StepID = Index + 1
              Color = *StepWizardA\SelectedColor
              TextColor = *StepWizardA\SelectedTextColor
            Else
              Color = *StepWizardA\NonSelectedColor
              TextColor = *StepWizardA\NonSelectedTextColor
            EndIf
            
            StepName.s = StringField(*StepWizardA\Steps, Index + 1, "|")
            
            TextWidth = TextWidth(StepName)
            TextHeight = TextHeight(StepName)
            
            If IsBetween(Index, 1, StepCount - 2)
              DrawText(x+((StepWidth-TextWidth)/2) + *StepWizardA\TriangleWidth/2, (Height - TextHeight)/2, StepName, TextColor, Color)
            Else
              DrawText(x+((StepWidth-TextWidth)/2), (Height - TextHeight)/2, StepName, TextColor, Color)
            EndIf
            
            X + StepWidth
            
          Next
          
          StopDrawing()
          
        EndIf
        
      EndIf
      
    EndIf
    
  EndProcedure
  
  Procedure Private_LeftClickHandler()
    
    GadgetID.i = EventGadget()
    *StepWizardA.StepWizard = GetGadgetData(GadgetID)
    
    If *StepWizardA <> #Null
      
      StepCount = CountString(*StepWizardA\Steps, "|") + 1
      Width.l = GadgetWidth(GadgetID)
      StepWidth.d = Width / StepCount
      
      X = GetGadgetAttribute(GadgetID, #PB_Canvas_MouseX)
      xx.d = 1
      
      For StepID = 0 To StepCount - 1
        
        If X > xx And X < xx + StepWidth + *StepWizardA\TriangleWidth
          *StepWizardA\StepID = StepID + 1
          Private_Draw(GadgetID)
          Break
        EndIf 
        
        xx + StepWidth
        
      Next
      
    EndIf
    
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< L'opérateur Gadget <<<<<
  
  Procedure Gadget(GadgetID.i, x.l, y.l, Width.l, Height.l, Steps.s)
    
    *StepWizardA.StepWizard = CreateNewStepWizard()
    
    GadgetHandle = CanvasGadget(GadgetID, x, y, Width, Height)
    
    If GadgetID = #PB_Any
      GadgetID = GadgetHandle
    EndIf
    
    *StepWizardA\Steps = Steps
    *StepWizardA\StepID = 1
    *StepWizardA\SelectedColor = $00cc99
    *StepWizardA\SelectedTextColor = $ffffff
    *StepWizardA\NonSelectedColor = $e0e0e0
    *StepWizardA\NonSelectedTextColor = $000000  
    *StepWizardA\TriangleWidth = 15.0
    
    BindGadgetEvent(GadgetID, @Private_LeftClickHandler(), #PB_EventType_LeftClick)
    
    SetGadgetData(GadgetID, *StepWizardA)
    Private_Draw(GadgetID)
    
    ProcedureReturn GadgetID
  EndProcedure
  
  Procedure SetSteps(GadgetID.i, Steps.s)
    
    If IsGadget(GadgetID)
      
      *StepWizardA.StepWizard = GetGadgetData(GadgetID)
      
      If *StepWizardA <> #Null
        
        *StepWizardA\Steps = Steps
        
        Private_Draw(GadgetID)
        
      EndIf
      
    EndIf
    
  EndProcedure 
  
  Procedure SetSelectedColor(GadgetID.i, BackColor.l, TextColor.l)
    
    If IsGadget(GadgetID)
      
      *StepWizardA.StepWizard = GetGadgetData(GadgetID)
      
      If *StepWizardA <> #Null
        
        *StepWizardA\SelectedColor = BackColor
        *StepWizardA\SelectedTextColor = TextColor
        
        Private_Draw(GadgetID)
        
      EndIf
      
    EndIf
    
  EndProcedure 
  
  Procedure SetNonSelectedColor(GadgetID.i, BackColor.l, TextColor.l)
    
    If IsGadget(GadgetID)
      
      *StepWizardA.StepWizard = GetGadgetData(GadgetID)
      
      If *StepWizardA <> #Null
        
        *StepWizardA\NonSelectedColor = BackColor
        *StepWizardA\NonSelectedTextColor = TextColor
        
        Private_Draw(GadgetID)
        
      EndIf
      
    EndIf
    
  EndProcedure 
  
  Procedure SetStepID(GadgetID.i, StepID.l)
    
    If IsGadget(GadgetID)
      
      *StepWizardA.StepWizard = GetGadgetData(GadgetID)
      
      If *StepWizardA <> #Null

        If IsBetween(StepID, 1, CountString(*StepWizardA\Steps, "|") + 1)
          *StepWizardA\StepID = StepID
          Private_Draw(GadgetID)
        EndIf
        
      EndIf
      
    EndIf
    
  EndProcedure
  
  Procedure.l GetStepID(GadgetID.i)
    
    CurrentStepID = -1
    
    If IsGadget(GadgetID)
      
      *StepWizardA.StepWizard = GetGadgetData(GadgetID)
      
      If *StepWizardA <> #Null
        CurrentStepID = *StepWizardA\StepID
      EndIf
      
    EndIf
    
    ProcedureReturn CurrentStepID
  EndProcedure
 
  Procedure PreviousStep(GadgetID.i)
    
    If IsGadget(GadgetID)
      
      *StepWizardA.StepWizard = GetGadgetData(GadgetID)
      
      If *StepWizardA <> #Null
        
        *StepWizardA\StepID = *StepWizardA\StepID - 1
        
        If *StepWizardA\StepID < 1
          *StepWizardA\StepID = 1
        EndIf
      
        Private_Draw(GadgetID)
        
      EndIf
      
    EndIf
    
  EndProcedure
  
  Procedure NextStep(GadgetID.i)
    
    If IsGadget(GadgetID)
      
      *StepWizardA.StepWizard = GetGadgetData(GadgetID)
      
      If *StepWizardA <> #Null
        
        *StepWizardA\StepID = *StepWizardA\StepID + 1
        
        If *StepWizardA\StepID > CountString(*StepWizardA\Steps, "|") + 1
          *StepWizardA\StepID = CountString(*StepWizardA\Steps, "|") + 1
        EndIf
        
        Private_Draw(GadgetID)
        
      EndIf
      
    EndIf
    
  EndProcedure
  
  Procedure Resize(GadgetID.i, x.l, y.l, Width.l, Height.l)
    
    ResizeGadget(GadgetID, x, y, Width, Height)
    Private_Draw(GadgetID)
    
  EndProcedure
  
  Procedure SetUserData(GadgetID.i, P_UserData.i)
    
    If IsGadget(GadgetID)
      
      *StepWizardA.StepWizard = GetGadgetData(GadgetID)
      
      If *StepWizardA <> #Null
        *StepWizardA\UserData = P_UserData
      EndIf
      
    EndIf
    
  EndProcedure
  
  Procedure.i GetUserData(GadgetID.i)
    
    If IsGadget(GadgetID)
      
      *StepWizardA.StepWizard = GetGadgetData(GadgetID)
      
      If *StepWizardA <> #Null
        P_UserData.i = *StepWizardA\UserData
      EndIf
      
    EndIf
    
    ProcedureReturn P_UserData
  EndProcedure
  
  Procedure Free(GadgetID.i)
    
    If IsGadget(GadgetID)
      
      *StepWizardA.StepWizard = GetGadgetData(GadgetID)
      
      If *StepWizardA <> #Null
        
        UnbindGadgetEvent(GadgetID, @Private_LeftClickHandler(), #PB_EventType_LeftClick)
        FreeStructure(*StepWizardA)
        FreeGadget(GadgetID)
        
      EndIf
      
    EndIf
    
  EndProcedure
  
EndModule

CompilerIf #PB_Compiler_IsMainFile
  
  If OpenWindow(0, 0, 0, 800, 250, "Step Wizard", #PB_Window_SizeGadget)
    
    StepWizard::Gadget(0, 2, 2, 800-4, 50, "1st Step|2nd Step|3rd Step|4th Step|5th Step|Finish")
    StepWizard::Gadget(1, 2, 55, 800-4, 50, "1ère Étape|2e Étape|3e Étape|4e Étape|5e Étape|Terminé")
    StepWizard::Gadget(2, 2, 110, 800-4, 50, "Étape 1|Étape 2|Étape 3|Étape 4|Étape 5|Terminé")
    
    StepWizard::SetSelectedColor(1, RGB(255, 127, 000), RGB(255, 255, 255))
    StepWizard::SetSelectedColor(2, RGB(000, 127, 255), RGB(255, 255, 255))

    ButtonGadget(3, WindowWidth(0)-110, 165,100,34,"Next")
    ButtonGadget(4, GadgetX(3)-110,165,105,34,"Prev")
    
    
    Repeat
      
      Select WaitWindowEvent()
          
        Case #PB_Event_Menu
          
          Select EventMenu()
              
          EndSelect
          
        Case #PB_Event_Gadget
          
          Select EventGadget()
              
            Case 0
              If EventType() = #PB_EventType_LeftClick
                Debug "#PB_EventType_LeftClick StepWizard 0 -> " + Str(StepWizard::GetStepID(0))
              EndIf
              
            Case 1
              If EventType() = #PB_EventType_LeftClick
                Debug "#PB_EventType_LeftClick StepWizard 1 -> " + Str(StepWizard::GetStepID(1))
              EndIf
              
            Case 2
              If EventType() = #PB_EventType_LeftClick
                Debug "#PB_EventType_LeftClick StepWizard 2 -> " + Str(StepWizard::GetStepID(2))
              EndIf
              
            Case 3
              StepWizard::NextStep(0)
              StepWizard::NextStep(1)
              StepWizard::NextStep(2)
              
            Case 4
              StepWizard::PreviousStep(0)
              StepWizard::PreviousStep(1)
              StepWizard::PreviousStep(2)
              
          EndSelect
          
        Case #PB_Event_SizeWindow
          StepWizard::Resize(0, #PB_Ignore, #PB_Ignore, WindowWidth(0)-4, #PB_Ignore)
          StepWizard::Resize(1, #PB_Ignore, #PB_Ignore, WindowWidth(0)-4, #PB_Ignore)
          StepWizard::Resize(2, #PB_Ignore, #PB_Ignore, WindowWidth(0)-4, #PB_Ignore)
          ResizeGadget(3, WindowWidth(0)-110, #PB_Ignore, #PB_Ignore, #PB_Ignore)
          ResizeGadget(4, GadgetX(3)-110, #PB_Ignore, #PB_Ignore, #PB_Ignore)
          
        Case #PB_Event_CloseWindow
          
          Select EventWindow()
              
            Case 0
              Break
              
          EndSelect
          
      EndSelect
      
    ForEver

  EndIf
  
CompilerEndIf

; <<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< FIN DU FICHIER <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<
Last edited by StarBootics on Thu Oct 07, 2021 11:21 pm, edited 1 time in total.
The Stone Age did not end due to a shortage of stones !
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8422
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Step Wizard

Post by netmaestro »

@Oliver13: Very nice concept & implementation! Thanks for sharing.

ps what are you going to do when you turn 14?
BERESHEIT
User avatar
mk-soft
Always Here
Always Here
Posts: 5313
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Step Wizard

Post by mk-soft »

Its very nice :wink:

For set alpha value 255 needs only ...

Code: Select all

...
            
            If *StepWizardA\StepID = Index + 1
              Color = *StepWizardA\SelectedColor | $FF000000
            Else
              Color = *StepWizardA\NonSelectedColor | $FF000000
            EndIf
          
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
StarBootics
Addict
Addict
Posts: 984
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: Step Wizard

Post by StarBootics »

mk-soft wrote: Thu Oct 07, 2021 4:45 pm Its very nice :wink:

For set alpha value 255 needs only ...

Code: Select all

...
            
            If *StepWizardA\StepID = Index + 1
              Color = *StepWizardA\SelectedColor | $FF000000
            Else
              Color = *StepWizardA\NonSelectedColor | $FF000000
            EndIf
          
I have updated my code, thanks for the tricks.

Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
Post Reply