package render import ( "image" "github.com/hajimehoshi/ebiten/v2" "tuxpa.in/t/erm/app/darktile/config" "tuxpa.in/t/erm/app/darktile/font" "tuxpa.in/t/erm/app/darktile/gui/popup" termutil "tuxpa.in/t/erm/app/darktile/termutil" imagefont "golang.org/x/image/font" ) type Render struct { frame *ebiten.Image screen *ebiten.Image c *config.Lark terminal *termutil.Terminal buffer *termutil.Buffer fontManager *font.Manager pixelWidth int pixelHeight int font Font popups []popup.Message enableLigatures bool cursorImage *ebiten.Image theme *termutil.Theme } type Font struct { Regular imagefont.Face Bold imagefont.Face Italic imagefont.Face BoldItalic imagefont.Face CellSize image.Point DotDepth int } func New(screen *ebiten.Image, c *config.Lark, theme *termutil.Theme, terminal *termutil.Terminal, fontManager *font.Manager, popups []popup.Message, opacity float64, enableLigatures bool, cursorImage *ebiten.Image) *Render { sz := screen.Bounds().Size() w, h := sz.X, sz.Y return &Render{ screen: screen, frame: ebiten.NewImage(w, h), terminal: terminal, buffer: terminal.GetActiveBuffer(), fontManager: fontManager, pixelWidth: w, pixelHeight: h, font: Font{ Regular: fontManager.RegularFontFace(), Bold: fontManager.BoldFontFace(), Italic: fontManager.ItalicFontFace(), BoldItalic: fontManager.BoldItalicFontFace(), CellSize: fontManager.CharSize(), DotDepth: fontManager.DotDepth(), }, popups: popups, enableLigatures: enableLigatures, cursorImage: cursorImage, theme: theme, c: c, } } func (r *Render) Draw() { r.terminal.Lock() defer r.terminal.Unlock() // 1. fill frame with default background colour r.frame.Fill(r.theme.DefaultBackground()) // 2. draw content (each row, each cell) r.drawContent() // 3. draw cursor r.drawCursor() // // 4. draw sixels r.drawSixels() // // 5. draw selection r.drawSelection() // // 6. draw highlight/annotations r.drawAnnotation() // // 7. draw popups r.drawPopups() // // 8. flush frame r.finalise() } func (r *Render) finalise() { defer r.frame.Dispose() opt := &ebiten.DrawImageOptions{} r.screen.DrawImage(r.frame, opt) }