From de3e4b528b8dab023f260269513e3d8ce66dea3e Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Tue, 15 Nov 2022 11:16:29 -0500 Subject: [PATCH] Redid color system --- application.go | 22 +++++++++++++++++----- backends/x/draw.go | 8 ++++---- backends/x/x.go | 4 ++-- buffer.go | 15 +++++++++++---- config.go | 2 +- 5 files changed, 35 insertions(+), 16 deletions(-) diff --git a/application.go b/application.go index 0c7c405..9a41891 100644 --- a/application.go +++ b/application.go @@ -26,11 +26,23 @@ func (application *Application) Run () ( application.DamageBuffer.SetSize(width, height) // TODO: load these from a file - application.config.colors = [4]color.Color { - color.RGBA { R: 0x2B, G: 0x30, B: 0x3C, A: 0xFF }, - color.RGBA { R: 0x4C, G: 0x56, B: 0x6A, A: 0xFF }, - color.RGBA { R: 0x2E, G: 0x34, B: 0x40, A: 0xFF }, - color.RGBA { R: 0xA8, G: 0x55, B: 0x5D, A: 0xFF }, + application.config.colors = [8]color.Color { + // background + color.RGBA { R: 0, G: 0, B: 0, A: 0 }, + // foreground + 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.fontSize = 11 diff --git a/backends/x/draw.go b/backends/x/draw.go index 0a94d08..4eb42a5 100644 --- a/backends/x/draw.go +++ b/backends/x/draw.go @@ -30,14 +30,14 @@ func (backend *Backend) updateWindowAreas (areas ...image.Rectangle) { 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 // application background color as the background. that way, we won't // need to redraw the characters *or* composite them. fillRectangle ( &image.Uniform { - C: backend.config.Color(stone.ColorApplication), + C: backend.config.Color(stone.ColorBackground), }, backend.canvas, backend.boundsOfCell(x, y)) @@ -65,7 +65,7 @@ func (backend *Backend) drawRune (x, y int, character rune) { backend.canvas, destinationRectangle, &image.Uniform { - C: backend.config.Color(stone.ColorForeground), + C: backend.config.Color(runeColor), }, image.Point { }, mask, @@ -86,7 +86,7 @@ func (backend *Backend) drawCells (forceRedraw bool) (areas []image.Rectangle) { if forceRedraw && content < 32 { continue } areas = append(areas, backend.boundsOfCell(x, y)) - backend.drawRune(x, y, content) + backend.drawRune(x, y, content, cell.Color()) }} if backend.drawBufferBounds && forceRedraw { diff --git a/backends/x/x.go b/backends/x/x.go index c930c84..00d4e6f 100644 --- a/backends/x/x.go +++ b/backends/x/x.go @@ -30,7 +30,7 @@ type Backend struct { face font.Face } - colors [4]xgraphics.BGRA + colors [8]xgraphics.BGRA metrics struct { windowWidth int @@ -125,7 +125,7 @@ func (backend *Backend) reallocateCanvas () { backend.metrics.windowWidth, backend.metrics.windowHeight)) 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) diff --git a/buffer.go b/buffer.go index 29f15b5..35b13c1 100644 --- a/buffer.go +++ b/buffer.go @@ -5,9 +5,13 @@ type Color uint8 const ( ColorBackground Color = 0x0 - ColorSelection Color = 0x1 - ColorForeground Color = 0x2 - ColorApplication Color = 0x3 + ColorForeground Color = 0x1 + ColorRed Color = 0x2 + 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 @@ -30,7 +34,7 @@ type Cell struct { } // Color returns the cell's color. -func (cell Cell) Color (color Color) { +func (cell Cell) Color () (color Color) { color = cell.color return } @@ -81,6 +85,9 @@ func (buffer *Buffer) SetSize (width, height int) { buffer.width = width buffer.height = 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 diff --git a/config.go b/config.go index cf190b9..c731075 100644 --- a/config.go +++ b/config.go @@ -5,7 +5,7 @@ import "image/color" // Config stores configuration parameters. Backends only should honor parameters // that they can support. type Config struct { - colors [4]color.Color + colors [8]color.Color padding int fontSize int fontName string