1 (edited by ker2x 2019-09-15 10:54:52)

Topic: usage of getfillsettings SF2.41

Friendly greetings !

i have a code that need to get the current fill setting and color , do stuff, restore how it was before.

But i'm stuck, there is no setfillsettings ...

        pb%oldcolor = getcolor()
        call getfillsettings(pb%oldfill)

        call setcolor(BLACK)
        ! do some drawing

        call setfillstyle(SOLID_FILL, LIGHTGREEN)
        ! do some drawing

        ! restore previous values
        call setcolor(pb%oldcolor)
        call ??? ! there is no setfillsettings

i tried just in case it was just missing documentation but :
undefined reference to `setfillsettings_'
collect2.exe: error: ld returned 1 exit status

thank you.

2 (edited by ker2x 2019-09-15 11:51:51)

Re: usage of getfillsettings SF2.41

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

Re: usage of getfillsettings SF2.41

Not a bad idea.  I'll look into adding it.

Jeff Armstrong
Approximatrix, LLC