colour hinting

This commit is contained in:
Liam Galvin 2018-11-25 11:06:05 +00:00
parent 4eb2b91d1f
commit 61edd75524
10 changed files with 83 additions and 28 deletions

View File

@ -14,7 +14,8 @@ Ensure you have your latest graphics card drivers installed before use.
## Contextual Hints
![Example hint](hint.png)
![Permissions hint](hint.png)
![Colour hex hint](hint.colour.png)
## Built-in Powerline Fonts

View File

@ -41,6 +41,6 @@ func (a *annotation) render(gui *GUI) {
}
}
gui.textbox(a.hint.StartX+1, a.hint.StartY+3, a.hint.Description)
gui.textbox(a.hint.StartX+1, a.hint.StartY+3, a.hint.Description, a.hint.ForegroundColour, a.hint.BackgroundColour)
}

View File

@ -265,7 +265,10 @@ Buffer Size: %d lines
gui.terminal.ActiveBuffer().ViewWidth(),
gui.terminal.ActiveBuffer().ViewHeight(),
gui.terminal.ActiveBuffer().Height(),
))
),
[3]float32{0, 1, 0},
[3]float32{0, 0, 0},
)
}
gui.window.SwapBuffers()

View File

@ -27,13 +27,11 @@ func (gui *GUI) mouseMoveCallback(w *glfw.Window, xpos float64, ypos float64) {
gui.terminal.ActiveBuffer().EndSelection(x, y, false)
} else {
if gui.terminal.UsingMainBuffer() {
hint := gui.terminal.ActiveBuffer().GetHintAtPosition(x, y)
if hint != nil {
gui.setOverlay(newAnnotation(hint))
} else {
gui.setOverlay(nil)
}
hint := gui.terminal.ActiveBuffer().GetHintAtPosition(x, y)
if hint != nil {
gui.setOverlay(newAnnotation(hint))
} else {
gui.setOverlay(nil)
}
}

View File

@ -10,7 +10,7 @@ func (gui *GUI) setOverlay(m overlay) {
}
func (gui *GUI) renderOverlay() {
if gui.overlay == nil || !gui.terminal.UsingMainBuffer() {
if gui.overlay == nil {
return
}

View File

@ -6,7 +6,7 @@ import (
"github.com/liamg/aminal/buffer"
)
func (gui *GUI) textbox(col uint16, row uint16, text string) {
func (gui *GUI) textbox(col uint16, row uint16, text string, fg [3]float32, bg [3]float32) {
lines := []string{}
line := ""
@ -81,18 +81,16 @@ DONE:
gui.renderer.Clean()
bg := [3]float32{0, 0, 0}
for hx := col; hx < col+uint16(longestLine)+2; hx++ {
for hx := col; hx < col+uint16(longestLine)+1; hx++ {
for hy := row - 1; hy < row+uint16(len(lines))+1; hy++ {
gui.renderer.DrawCellBg(buffer.NewBackgroundCell(bg), uint(hx), uint(hy), false, nil , true)
gui.renderer.DrawCellBg(buffer.NewBackgroundCell(bg), uint(hx), uint(hy), false, nil, true)
}
}
x := float32(col) * gui.renderer.cellWidth
f := gui.fontMap.GetFont('X')
f.SetColor(0.2, 1, 0.2, 1)
f.SetColor(fg[0], fg[1], fg[2], 1)
for i, line := range lines {
y := float32(row+1+uint16(i)) * gui.renderer.cellHeight

BIN
hint.colour.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

47
hints/colours.go Normal file
View File

@ -0,0 +1,47 @@
package hints
import (
"regexp"
"strconv"
)
func init() {
hinters = append(hinters, hintColours)
}
func hintColours(word string, context string, wordX uint16, wordY uint16) *Hint {
item := NewHint(word, context, wordX, wordY)
if isColour(word) {
r, err := strconv.ParseInt(word[1:3], 16, 64)
if err != nil {
return nil
}
g, err := strconv.ParseInt(word[3:5], 16, 64)
if err != nil {
return nil
}
b, err := strconv.ParseInt(word[5:7], 16, 64)
if err != nil {
return nil
}
item.Description = word
item.BackgroundColour = [3]float32{float32(r) / 255, float32(g) / 255, float32(b) / 255}
if (r+g+b)/3 < 128 {
item.ForegroundColour = [3]float32{1, 1, 1}
} else {
item.ForegroundColour = [3]float32{0, 0, 0}
}
return item
}
return nil
}
func isColour(s string) bool {
re := regexp.MustCompile("#[0-9A-Fa-f]{6}")
return re.MatchString(s)
}

View File

@ -1,11 +1,13 @@
package hints
type Hint struct {
Word string
StartX uint16
StartY uint16
Line string
Description string
Word string
StartX uint16
StartY uint16
Line string
Description string
BackgroundColour [3]float32
ForegroundColour [3]float32
}
type hinter func(word string, context string, wordX uint16, wordY uint16) *Hint
@ -20,3 +22,14 @@ func Get(word string, context string, wordX uint16, wordY uint16) *Hint {
}
return nil
}
func NewHint(word string, context string, wordX uint16, wordY uint16) *Hint {
return &Hint{
Line: context,
Word: word,
StartX: wordX,
StartY: wordY,
BackgroundColour: [3]float32{0, 0, 0},
ForegroundColour: [3]float32{0.2, 1, 0.2},
}
}

View File

@ -112,12 +112,7 @@ func init() {
func hintPerms(word string, context string, wordX uint16, wordY uint16) *Hint {
item := &Hint{
Line: context,
Word: word,
StartX: wordX,
StartY: wordY,
}
item := NewHint(word, context, wordX, wordY)
if wordX == 0 {