It is currently Sun Apr 05, 2020 12:25 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: Step Wizard
PostPosted: Sat Nov 02, 2019 7:52 pm 
Offline
User
User

Joined: Thu Sep 30, 2010 6:40 am
Posts: 65
Here a small code snippet to visualize progress steps

Code:
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()


Top
 Profile  
Reply with quote  
 Post subject: Re: Step Wizard
PostPosted: Sat Nov 02, 2019 8:31 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 3235
Location: Boston, MA
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Step Wizard
PostPosted: Sun Nov 03, 2019 5:21 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Jul 08, 2013 8:43 pm
Posts: 243
Really good!! thanks for share. Nice job!

_________________
If translation=Error: reply="Sorry, Im Spanish": Endif


Top
 Profile  
Reply with quote  
 Post subject: Re: Step Wizard
PostPosted: Sun Nov 03, 2019 10:02 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu Apr 18, 2019 8:17 am
Posts: 665
skywalk wrote:
drop the buttons

I disagree. The buttons are expected, so keep them. But maybe allow clicking the arrow steps as well?


Top
 Profile  
Reply with quote  
 Post subject: Re: Step Wizard
PostPosted: Sun Nov 03, 2019 11:21 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 3235
Location: Boston, MA
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Step Wizard
PostPosted: Tue Nov 05, 2019 4:01 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Aug 24, 2005 4:02 pm
Posts: 1208
Location: Germany
Nice idea.
I made a module with a gadget (GradualProgress-Module) out of it.

_________________
Sorry for my English. My language is German.
(Translated with http://www.DeepL.com/Translator)

Download of PureBasic - Modules

[Windows 10 x64] [PB V5.7x]


Top
 Profile  
Reply with quote  
 Post subject: Re: Step Wizard
PostPosted: Tue Nov 05, 2019 5:34 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4661
Location: Lyon - France
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Step Wizard
PostPosted: Fri Nov 15, 2019 4:13 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Jul 07, 2013 11:35 am
Posts: 460
Location: Canada
Hello everyone,

This is my take for a Step Wizard Gadget

Code:
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; 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 !


Top
 Profile  
Reply with quote  
 Post subject: Re: Step Wizard
PostPosted: Fri Nov 15, 2019 4:26 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 3235
Location: Boston, MA
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Step Wizard
PostPosted: Fri Nov 15, 2019 4:50 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Jul 07, 2013 11:35 am
Posts: 460
Location: Canada
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 !


Top
 Profile  
Reply with quote  
 Post subject: Re: Step Wizard
PostPosted: Fri Nov 15, 2019 4:59 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Aug 24, 2005 4:02 pm
Posts: 1208
Location: Germany
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.

https://www.purebasic.fr/english/viewtopic.php?f=27&t=73943

_________________
Sorry for my English. My language is German.
(Translated with http://www.DeepL.com/Translator)

Download of PureBasic - Modules

[Windows 10 x64] [PB V5.7x]


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye