mirror of
https://github.com/rastapasta/mapscii.git
synced 2025-06-19 17:27:41 +02:00
🎨 support label characters with width>1
This commit is contained in:
parent
0bdb01f706
commit
0e5ce02e79
@ -13,6 +13,8 @@
|
|||||||
|
|
||||||
Will either be merged into node-drawille or become an own module at some point
|
Will either be merged into node-drawille or become an own module at some point
|
||||||
###
|
###
|
||||||
|
stringWidth = require 'string-width'
|
||||||
|
config = require './config'
|
||||||
|
|
||||||
module.exports = class BrailleBuffer
|
module.exports = class BrailleBuffer
|
||||||
characterMap: [[0x1, 0x8],[0x2, 0x10],[0x4, 0x20],[0x40, 0x80]]
|
characterMap: [[0x1, 0x8],[0x2, 0x10],[0x4, 0x20],[0x40, 0x80]]
|
||||||
@ -78,20 +80,34 @@ module.exports = class BrailleBuffer
|
|||||||
frame: ->
|
frame: ->
|
||||||
output = []
|
output = []
|
||||||
currentColor = null
|
currentColor = null
|
||||||
delimeter = "\n"
|
skip = 0
|
||||||
|
|
||||||
for idx in [0...@pixelBuffer.length]
|
for y in [0...@height/4]
|
||||||
output.push delimeter if idx and (idx % (@width/2)) is 0
|
skip = 0
|
||||||
|
|
||||||
|
for x in [0...@width/2]
|
||||||
|
idx = y*@width/2 + x
|
||||||
|
|
||||||
|
if idx and not x
|
||||||
|
output.push config.delimeter
|
||||||
|
|
||||||
if currentColor isnt colorCode = @_termColor @foregroundBuffer[idx], @backgroundBuffer[idx]
|
if currentColor isnt colorCode = @_termColor @foregroundBuffer[idx], @backgroundBuffer[idx]
|
||||||
output.push currentColor = colorCode
|
output.push currentColor = colorCode
|
||||||
|
|
||||||
output.push if @charBuffer[idx]
|
output.push if char = @charBuffer[idx]
|
||||||
@charBuffer[idx]
|
skip += stringWidth(char)-1
|
||||||
|
if skip+x >= @width/2
|
||||||
|
''
|
||||||
else
|
else
|
||||||
|
char
|
||||||
|
else
|
||||||
|
if not skip
|
||||||
String.fromCharCode 0x2800+@pixelBuffer[idx]
|
String.fromCharCode 0x2800+@pixelBuffer[idx]
|
||||||
|
else
|
||||||
|
skip--
|
||||||
|
''
|
||||||
|
|
||||||
output.push @termReset+delimeter
|
output.push @termReset+config.delimeter
|
||||||
output.join ''
|
output.join ''
|
||||||
|
|
||||||
setChar: (char, x, y, color) ->
|
setChar: (char, x, y, color) ->
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
Using 2D spatial indexing to avoid overlapping labels and markers
|
Using 2D spatial indexing to avoid overlapping labels and markers
|
||||||
and to find labels underneath a mouse cursor's position
|
and to find labels underneath a mouse cursor's position
|
||||||
###
|
###
|
||||||
|
|
||||||
rbush = require 'rbush'
|
rbush = require 'rbush'
|
||||||
|
stringWidth = require 'string-width'
|
||||||
|
|
||||||
module.exports = class LabelBuffer
|
module.exports = class LabelBuffer
|
||||||
tree: null
|
tree: null
|
||||||
@ -41,5 +41,5 @@ module.exports = class LabelBuffer
|
|||||||
_calculateArea: (text, x, y, margin = 0) ->
|
_calculateArea: (text, x, y, margin = 0) ->
|
||||||
minX: x-margin
|
minX: x-margin
|
||||||
minY: y-margin/2
|
minY: y-margin/2
|
||||||
maxX: x+margin+text.length
|
maxX: x+margin+stringWidth(text)
|
||||||
maxY: y+margin/2
|
maxY: y+margin/2
|
||||||
|
@ -33,3 +33,5 @@ module.exports =
|
|||||||
output: process.stdout
|
output: process.stdout
|
||||||
|
|
||||||
headless: false
|
headless: false
|
||||||
|
|
||||||
|
delimeter: "\n\r"
|
Loading…
x
Reference in New Issue
Block a user