After some trials and error i managed to guess the type structure :
call setfillstyle(pb%oldfill%pattern, pb%oldfill%color )
can you please add a setfillsettings() please (in both SF2 and 3) if possible ?
the full code :
module m_progressbar
use appgraphics
implicit none
! it's just cleaner that way
type progressbar
integer :: x,y,width,height, oldcolor, progress
type(fillsettingstype) :: oldfill
end type progressbar
type(progressbar) :: pb
contains
! set some values once, so i just have to pass the progress in args later.
subroutine init_progressbar(x,y,width,height, progress)
use appgraphics, only : getcolor
implicit none
integer, intent(in) :: x,y,width,height
integer, optional :: progress
pb%x = x
pb%y = y
pb%width = width
pb%height = height
pb%oldcolor = getcolor()
pb%progress = 0 ! default value
if(present(progress)) pb%progress = progress ! overiden if specified in argument
end subroutine
! update the progress value, cap it between [1,100]
subroutine set_progressbar(progress)
implicit none
integer, intent(in) :: progress
pb%progress = progress
if(pb%progress < 1) pb%progress = 1
if(pb%progress > 100) pb%progress = 100
end subroutine
! i never used it but ... nice to have a get/set
function get_progressbar() result(progress)
implicit none
integer :: progress
progress = pb%progress
end function
! draw the progress bar, the result isn't very nice but it works.
subroutine draw_progressbar()
use appgraphics
implicit none
integer :: bar_size
bar_size = ((pb%progress / 100.0) * pb%width) + 1
pb%oldcolor = getcolor()
call getfillsettings(pb%oldfill)
call setcolor(BLACK)
call rectangle(pb%x, pb%y, pb%x + pb%width, pb%y + pb%height)
call setcolor(pb%oldcolor)
call setfillstyle(SOLID_FILL, LIGHTGREEN)
call bar(pb%x + 2, pb%y +1, (pb%x + bar_size) - 1, (pb%y + pb%height))
call setcolor(pb%oldcolor)
call setfillstyle(pb%oldfill%pattern, pb%oldfill%color )
end subroutine
end module