mirror of https://github.com/liamg/aminal.git
colour hinting
This commit is contained in:
parent
4eb2b91d1f
commit
61edd75524
|
@ -14,7 +14,8 @@ Ensure you have your latest graphics card drivers installed before use.
|
|||
|
||||
## Contextual Hints
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
## Built-in Powerline Fonts
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
12
gui/mouse.go
12
gui/mouse.go
|
@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
|
@ -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)
|
||||
}
|
|
@ -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},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
Loading…
Reference in New Issue