🎨 supporting global background color via style definition

This commit is contained in:
Michael Straßburger 2016-09-28 19:39:00 +02:00
parent 334032da59
commit a7c8a4206b
5 changed files with 13 additions and 14 deletions

View File

@ -22,6 +22,8 @@ module.exports = class BrailleBuffer
foregroundBuffer: null
backgroundBuffer: null
globalBackground: null
termReset: "\x1B[39;49m"
constructor: (@width, @height) ->
@ -34,6 +36,8 @@ module.exports = class BrailleBuffer
@foregroundBuffer = []
@backgroundBuffer = []
setGlobalBackground: (@globalBackground) ->
setBackground: (x, y, color) ->
return unless 0 <= x < @width and 0 <= y < @height
idx = @_project x, y
@ -58,6 +62,7 @@ module.exports = class BrailleBuffer
cb idx, mask
_termColor: (foreground, background) ->
background = background or @globalBackground
if foreground and background
"\x1B[38;5;#{foreground};48;5;#{background}m"
else if foreground

View File

@ -50,6 +50,9 @@ module.exports = class Canvas
bresenham projected[i-1]..., projected[i]...,
(x, y) => @buffer.setPixel x, y, color
setBackground: (color) ->
@buffer.setGlobalBackground color
background: (x, y, color) ->
point = @_project x, y
@buffer.setBackground point[0], point[1], color
@ -62,7 +65,7 @@ module.exports = class Canvas
point = @_project point[0], point[1]
point[0] = utils.clamp point[0], 0, @width
point[1] = utils.clamp point[1], 0, @height
if point[0] isnt lastPoint[0] or point[1] isnt lastPoint[1]
vertices = vertices.concat point[0], point[1]
lastPoint = point

View File

@ -85,10 +85,9 @@ module.exports = class Renderer
@labelBuffer.clear()
# TODO: better way for background color instead of setting filling FG?
# if color = @styler.styleById['background']?.paint['background-color']
# @canvas.strokeStyle = x256 utils.hex2rgb(color)...
# @canvas.fillRect 0, 0, @width, @height
# else
if color = @styler.styleById['background']?.paint['background-color']
@canvas.setBackground x256 utils.hex2rgb color
@canvas.clear()
@canvas.reset()

View File

@ -15,7 +15,7 @@ utils = require './utils'
module.exports = class Termap
config:
styleFile: __dirname+"/../styles/bright.json"
styleFile: __dirname+"/../styles/basic.json"
zoomStep: 0.4
width: null

View File

@ -1158,14 +1158,6 @@
},
"source-layer": "housenum_label"
},
{
"type": "symbol",
"id": "water_label",
"paint": {
"text-color": "#333"
},
"source-layer": "housenum_label"
},
{
"type": "symbol",
"id": "place_label_other",