A barberpole spinner
#1
There are times when a process will take a liong time, but a status bar is not usable for feedback as there is no feedback from the process. A barberpole slinner will give the user some idea that the process is still running.
The following is a library and example program


example program

Code:
#!yab


import spinner
// set DEBUG = 1 to print out all messages on the console
DEBUG = 0

OpenWindow()


// Main Message Loop
dim msg$(1)
while(not leavingLoop)
    nCommands = token(message$, msg$(), "|")

    for everyCommand = 1 to nCommands
        if(DEBUG and msg$(everyCommand)<>"") print msg$(everyCommand)

        switch(msg$(everyCommand))
            case "_QuitRequested"
            case "MainWindow:_QuitRequested"
                leavingLoop = true
                break
            case "start"
                display_spinner("horizontal")
                display_spinner("virtictal")
                
                countdown=1
                break
            case "stop"
                hide_spinner("horizontal")
                hide_spinner("virtictal")
                countdown = 0
                
                break
            default
            
                
        end switch
            

    next everyCommand
    if countdown >0 then
        countdown=countdown+1
        if countdown=400 countdown=0
    endif    
    if countdown then
        spin("horizontal")
        spin("virtictal")
    endif

wend


CloseWindow()

end
sub OpenWindow()
    window open 100,100 to 600,500, "MainWindow", "Main Window"
    button 80,30 to 150,60, "start", "start", "MainWindow"
    button 180,30 to 250,60, "stop", "stop", "MainWindow"
    new_spinner(100,100,100,0,"horizontal", "MainWindow")
    new_spinner(10,10,50,1,"virtictal", "MainWindow")
    return
end sub


// Close down the main window
sub CloseWindow()
    window close "MainWindow"
    return
end sub

new_spinner( x,y,length,virtical,name$)

x and y are the top left co-ordinates of the spinner.

length is the number of pixels right or down from the x,y origin

if virtical is true, the spinner is virtical otherwise it is horizontal

name$ is the name of the new slinner.

display_spinner(name$) and hide_spinner(name$) show/hide the spinner.

spin(name$) rotates the barber poel one step. This should be in your main program loop. one cannot spin a hidden spinner ( the view for the spinner is removed on hide, and added on show)


the library ( save as spinner.yab and place in the library search path)

Code:
export sub new_spinner(hz,vt,htln,orentationn, name$, view$)
static mumber
number = number+1
dim spinner(number,4)
dim spinnername$(number,2)

spinner(number,1)=hz
spinner(number,2)=vt
spinner(number,3)=htln
if spinner(number,3)=0 spinner(number,3)=1
spinner(number,4)=orentationn
spinnername$(number,1)=name$
spinnername$(number,2)=view$
end sub



export sub display_spinner(name$)

local x,i.number,view$, length
x=arraysize(spinnername$(),1)
for i=1 to x
if (spinnername$(i,1)=name$) number = i
next

view$=spinnername$(number,2)
length=spinner(number,3)

if spinner(number,4) = 0 then
    view spinner(number,1),spinner(number,2) to spinner(number,2)+length,spinner(number,1)+15, name$+"_view", view$
    draw set 0,"HighSolidFill"
    draw set "highcolor",180,180,180, name$+"_view"
    draw rect 0,0 to length,15, name$+"_view"
    draw set "highcolor",225,225,235, name$+"_view"
    draw line 0,15 to length,15, name$+"_view"
    draw line length,0 to length,15 , name$+"_view"
    draw set "highcolor",150,150,150, name$+"_view"    
    draw line 0,0 to 0,15 , name$+"_view"
    draw line 1,0 to length-1,0 , name$+"_view"
    CANVAS 2,2 to length-2,13,  name$, name$+"_view"
    draw set "highcolor", 0,80,225, name$
    draw set "lowcolor", 245,245,245, name$
    
    
else

    view spinner(number,1),spinner(number,2) to spinner(number,2)+15,spinner(number,1)+length, name$+"_view", view$
    draw set 0,"HighSolidFill"
    draw set "highcolor",180,180,180, name$+"_view"
    draw rect 0,0 to 15,length, name$+"_view"    
    draw set "highcolor",225,225,235, name$+"_view"
    draw line 0,length to 15,length, name$+"_view"
    draw line 15,0 to 15,length, name$+"_view"
    draw set "highcolor",150,150,150, name$+"_view"
    draw line 0,0 to 14,0 , name$+"_view"
    draw line 0,0 to 0,length , name$+"_view"
    CANVAS 2,2 to 13, length-2, name$, name$+"_view"
    draw set "highcolor", 0,80,225, name$
    draw set "lowcolor", 245,245,245, name$
    
    
    
    
endif




end sub

export sub hide_spinner(name$)
view remove name$+"_view"
end sub



export sub spin(name$)
local i,length,x
x=arraysize(spinnername$(),1)
for i=1 to x
if (spinnername$(i,1)=name$) number = i
next
length=spinner(number,3)


p = spinner(number,0)
switch p
    case 0    
        pattern$= "030060120240225195135015"
    break
    case 1
        pattern$ = "060120240225195135015030"
    break
    case 2
        pattern$ = "120240225195135015030060"
    break
    case 3
        pattern$ = "240225195135015030060120"
    break
    case 4
        pattern$ = "225195135015030060120240"
    break
    case 5
        pattern$ = "195135015030060120240225"
    break
    case 6
        pattern$ = "135015030060120240225195"
    break
    case 7
        pattern$ = "015030060120240225195135"
    break
end switch
        
draw set 0, pattern$        
if spinner(number,4) = 0 then // spin to the right or up
    draw rect 0,0 to length-4, 13, name$
    p=p-1
    if p<0 p=7
    spinner(number,0)=p    
else
    draw rect 0,0 to 13 ,length, name$
    p=p+1
    if p=8 p=0
    spinner(number,0)=p    
endif    


end sub
Reply


Messages In This Thread
A barberpole spinner - by bbjimmy - 05-05-2016, 10:58 AM
RE: A barberpole spinner - by clasqm - 05-07-2016, 02:57 PM
RE: A barberpole spinner - by bbjimmy - 05-07-2016, 07:21 PM
RE: A barberpole spinner - by clasqm - 05-08-2016, 08:02 AM
RE: A barberpole spinner - by clasqm - 05-08-2016, 09:40 AM
RE: A barberpole spinner - by bbjimmy - 05-08-2016, 12:43 PM
RE: A barberpole spinner - by clasqm - 05-09-2016, 04:40 PM
RE: A barberpole spinner - by bbjimmy - 05-09-2016, 09:46 PM
RE: A barberpole spinner - by clasqm - 05-10-2016, 11:12 AM
RE: A barberpole spinner - by bbjimmy - 05-10-2016, 02:02 PM
RE: A barberpole spinner - by clasqm - 05-10-2016, 03:23 PM
RE: A barberpole spinner - by bbjimmy - 05-11-2016, 09:21 AM
RE: A barberpole spinner - by clasqm - 05-13-2016, 02:08 PM
RE: A barberpole spinner - by clasqm - 05-17-2016, 11:11 AM

Forum Jump:


Users browsing this thread: 5 Guest(s)
Free Web Hosting