github.com/jmigpin/editor@v1.6.0/util/drawutil/drawer4/bgfill.go (about)

     1  package drawer4
     2  
     3  import (
     4  	"github.com/jmigpin/editor/util/imageutil"
     5  )
     6  
     7  type BgFill struct {
     8  	d *Drawer
     9  }
    10  
    11  func (bgf *BgFill) Init() {}
    12  
    13  func (bgf *BgFill) Iter() {
    14  	bgf.iter2()
    15  	if !bgf.d.iterNext() {
    16  		return
    17  	}
    18  }
    19  func (bgf *BgFill) iter2() {
    20  	// skip draw
    21  	if bgf.d.st.runeR.ru < 0 {
    22  		if bgf.d.st.runeR.ru == eofRune {
    23  			// allow painting line at eof position
    24  		} else {
    25  			return
    26  		}
    27  	}
    28  
    29  	st := &bgf.d.st.curColors
    30  	if st.lineBg != nil {
    31  		r := bgf.d.iters.runeR.penBoundsRect()
    32  		b := bgf.d.bounds
    33  		r.Min.X = b.Min.X
    34  		r.Max.X = b.Max.X
    35  		r = r.Intersect(b)
    36  		imageutil.FillRectangle(bgf.d.st.drawR.img, r, st.lineBg)
    37  	}
    38  	if st.bg != nil {
    39  		r := bgf.d.iters.runeR.penBoundsRect()
    40  		r = r.Intersect(bgf.d.bounds)
    41  		imageutil.FillRectangle(bgf.d.st.drawR.img, r, st.bg)
    42  	}
    43  }
    44  
    45  func (bgf *BgFill) End() {}