2021-08-02 19:55:04 +00:00
|
|
|
package render
|
|
|
|
|
|
|
|
import (
|
|
|
|
"image"
|
2023-01-16 02:11:07 +00:00
|
|
|
"tuxpa.in/t/erm/app/darktile/font"
|
|
|
|
"tuxpa.in/t/erm/app/darktile/gui/popup"
|
|
|
|
termutil2 "tuxpa.in/t/erm/app/darktile/termutil"
|
2021-08-02 19:55:04 +00:00
|
|
|
|
|
|
|
imagefont "golang.org/x/image/font"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Render struct {
|
|
|
|
frame *ebiten.Image
|
|
|
|
screen *ebiten.Image
|
2023-01-16 02:11:07 +00:00
|
|
|
terminal *termutil2.Terminal
|
|
|
|
buffer *termutil2.Buffer
|
|
|
|
theme *termutil2.Theme
|
2021-08-02 19:55:04 +00:00
|
|
|
fontManager *font.Manager
|
|
|
|
pixelWidth int
|
|
|
|
pixelHeight int
|
|
|
|
font Font
|
|
|
|
opacity float64
|
|
|
|
popups []popup.Message
|
|
|
|
enableLigatures bool
|
|
|
|
cursorImage *ebiten.Image
|
|
|
|
}
|
|
|
|
|
|
|
|
type Font struct {
|
|
|
|
Regular imagefont.Face
|
|
|
|
Bold imagefont.Face
|
|
|
|
Italic imagefont.Face
|
|
|
|
BoldItalic imagefont.Face
|
|
|
|
CellSize image.Point
|
|
|
|
DotDepth int
|
|
|
|
}
|
|
|
|
|
2023-01-16 02:11:07 +00:00
|
|
|
func New(screen *ebiten.Image, terminal *termutil2.Terminal, fontManager *font.Manager, popups []popup.Message, opacity float64, enableLigatures bool, cursorImage *ebiten.Image) *Render {
|
2021-08-02 19:55:04 +00:00
|
|
|
w, h := screen.Size()
|
|
|
|
return &Render{
|
|
|
|
screen: screen,
|
|
|
|
frame: ebiten.NewImage(w, h),
|
|
|
|
terminal: terminal,
|
|
|
|
buffer: terminal.GetActiveBuffer(),
|
|
|
|
theme: terminal.Theme(),
|
|
|
|
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(),
|
|
|
|
},
|
|
|
|
opacity: opacity,
|
|
|
|
popups: popups,
|
|
|
|
enableLigatures: enableLigatures,
|
|
|
|
cursorImage: cursorImage,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Render) Draw() {
|
2022-05-10 08:18:01 +00:00
|
|
|
r.terminal.Lock()
|
|
|
|
defer r.terminal.Unlock()
|
2021-08-02 19:55:04 +00:00
|
|
|
|
|
|
|
// 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. apply effects (e.g. transparency)
|
|
|
|
r.finalise()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Render) finalise() {
|
|
|
|
defer r.frame.Dispose()
|
|
|
|
opt := &ebiten.DrawImageOptions{}
|
|
|
|
opt.ColorM.Scale(1, 1, 1, r.opacity)
|
|
|
|
r.screen.DrawImage(r.frame, opt)
|
|
|
|
}
|