Redid color system

This commit is contained in:
Sasha Koshka 2022-11-15 11:16:29 -05:00
parent 100e72fada
commit de3e4b528b
5 changed files with 35 additions and 16 deletions

View File

@ -26,11 +26,23 @@ func (application *Application) Run () (
application.DamageBuffer.SetSize(width, height) application.DamageBuffer.SetSize(width, height)
// TODO: load these from a file // TODO: load these from a file
application.config.colors = [4]color.Color { application.config.colors = [8]color.Color {
color.RGBA { R: 0x2B, G: 0x30, B: 0x3C, A: 0xFF }, // background
color.RGBA { R: 0x4C, G: 0x56, B: 0x6A, A: 0xFF }, color.RGBA { R: 0, G: 0, B: 0, A: 0 },
color.RGBA { R: 0x2E, G: 0x34, B: 0x40, A: 0xFF }, // foreground
color.RGBA { R: 0xA8, G: 0x55, B: 0x5D, A: 0xFF }, color.RGBA { R: 0xFF, G: 0xFF, B: 0xFF, A: 0xFF },
// red
color.RGBA { R: 0xFF, G: 0xFF, B: 0xFF, A: 0xFF },
// orange
color.RGBA { R: 0xFF, G: 0x80, B: 0x00, A: 0xFF },
// yellow
color.RGBA { R: 0xFF, G: 0xFF, B: 0x00, A: 0xFF },
// green
color.RGBA { R: 0x00, G: 0xFF, B: 0x00, A: 0xFF },
// blue
color.RGBA { R: 0x00, G: 0x00, B: 0xFF, A: 0xFF },
// purple
color.RGBA { R: 0x80, G: 0x00, B: 0xFF, A: 0xFF },
} }
application.config.fontName = "" application.config.fontName = ""
application.config.fontSize = 11 application.config.fontSize = 11

View File

@ -30,14 +30,14 @@ func (backend *Backend) updateWindowAreas (areas ...image.Rectangle) {
backend.canvas.XPaintRects(backend.window.Id, areas...) backend.canvas.XPaintRects(backend.window.Id, areas...)
} }
func (backend *Backend) drawRune (x, y int, character rune) { func (backend *Backend) drawRune (x, y int, character rune, runeColor stone.Color) {
// TODO: cache these draws as non-transparent buffers with the // TODO: cache these draws as non-transparent buffers with the
// application background color as the background. that way, we won't // application background color as the background. that way, we won't
// need to redraw the characters *or* composite them. // need to redraw the characters *or* composite them.
fillRectangle ( fillRectangle (
&image.Uniform { &image.Uniform {
C: backend.config.Color(stone.ColorApplication), C: backend.config.Color(stone.ColorBackground),
}, },
backend.canvas, backend.canvas,
backend.boundsOfCell(x, y)) backend.boundsOfCell(x, y))
@ -65,7 +65,7 @@ func (backend *Backend) drawRune (x, y int, character rune) {
backend.canvas, backend.canvas,
destinationRectangle, destinationRectangle,
&image.Uniform { &image.Uniform {
C: backend.config.Color(stone.ColorForeground), C: backend.config.Color(runeColor),
}, },
image.Point { }, image.Point { },
mask, mask,
@ -86,7 +86,7 @@ func (backend *Backend) drawCells (forceRedraw bool) (areas []image.Rectangle) {
if forceRedraw && content < 32 { continue } if forceRedraw && content < 32 { continue }
areas = append(areas, backend.boundsOfCell(x, y)) areas = append(areas, backend.boundsOfCell(x, y))
backend.drawRune(x, y, content) backend.drawRune(x, y, content, cell.Color())
}} }}
if backend.drawBufferBounds && forceRedraw { if backend.drawBufferBounds && forceRedraw {

View File

@ -30,7 +30,7 @@ type Backend struct {
face font.Face face font.Face
} }
colors [4]xgraphics.BGRA colors [8]xgraphics.BGRA
metrics struct { metrics struct {
windowWidth int windowWidth int
@ -125,7 +125,7 @@ func (backend *Backend) reallocateCanvas () {
backend.metrics.windowWidth, backend.metrics.windowWidth,
backend.metrics.windowHeight)) backend.metrics.windowHeight))
backend.canvas.For (func (x, y int) xgraphics.BGRA { backend.canvas.For (func (x, y int) xgraphics.BGRA {
return backend.colors[stone.ColorApplication] return backend.colors[stone.ColorBackground]
}) })
backend.canvas.XSurfaceSet(backend.window.Id) backend.canvas.XSurfaceSet(backend.window.Id)

View File

@ -5,9 +5,13 @@ type Color uint8
const ( const (
ColorBackground Color = 0x0 ColorBackground Color = 0x0
ColorSelection Color = 0x1 ColorForeground Color = 0x1
ColorForeground Color = 0x2 ColorRed Color = 0x2
ColorApplication Color = 0x3 ColorOrange Color = 0x3
ColorYellow Color = 0x4
ColorGreen Color = 0x5
ColorBlue Color = 0x6
ColorPurple Color = 0x7
) )
// Style contains styling information about cells. These properties can be or'd // Style contains styling information about cells. These properties can be or'd
@ -30,7 +34,7 @@ type Cell struct {
} }
// Color returns the cell's color. // Color returns the cell's color.
func (cell Cell) Color (color Color) { func (cell Cell) Color () (color Color) {
color = cell.color color = cell.color
return return
} }
@ -81,6 +85,9 @@ func (buffer *Buffer) SetSize (width, height int) {
buffer.width = width buffer.width = width
buffer.height = height buffer.height = height
buffer.content = make([]Cell, width * height) buffer.content = make([]Cell, width * height)
for index := 0; index < len(buffer.content); index ++ {
buffer.content[index].color = ColorForeground
}
} }
// Cell returns the cell at the specified x and y coordinates. If the // Cell returns the cell at the specified x and y coordinates. If the

View File

@ -5,7 +5,7 @@ import "image/color"
// Config stores configuration parameters. Backends only should honor parameters // Config stores configuration parameters. Backends only should honor parameters
// that they can support. // that they can support.
type Config struct { type Config struct {
colors [4]color.Color colors [8]color.Color
padding int padding int
fontSize int fontSize int
fontName string fontName string