mirror of https://github.com/liamg/aminal.git
cursor basics
This commit is contained in:
parent
8f1efd822e
commit
2ea6f067c5
|
@ -188,24 +188,12 @@ func (buffer *Buffer) Backspace() {
|
||||||
line := buffer.getCurrentLine()
|
line := buffer.getCurrentLine()
|
||||||
if line.wrapped {
|
if line.wrapped {
|
||||||
buffer.MovePosition(int16(buffer.Width()-1), -1)
|
buffer.MovePosition(int16(buffer.Width()-1), -1)
|
||||||
line := buffer.getCurrentLine()
|
|
||||||
if int(buffer.cursorX) < len(line.cells) {
|
|
||||||
fmt.Printf("Deleting (end) %s\n", string(line.cells[buffer.cursorX].Rune()))
|
|
||||||
line.cells[buffer.cursorX].erase()
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
//@todo ring bell or whatever
|
//@todo ring bell or whatever
|
||||||
fmt.Println("BELL?")
|
fmt.Println("BELL?")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
buffer.MovePosition(-1, 0)
|
buffer.MovePosition(-1, 0)
|
||||||
line := buffer.getCurrentLine()
|
|
||||||
if int(buffer.cursorX) < len(line.cells) {
|
|
||||||
fmt.Printf("Deleting %s\n", string(line.cells[buffer.cursorX].Rune()))
|
|
||||||
line.cells[buffer.cursorX].erase()
|
|
||||||
} else {
|
|
||||||
fmt.Println("Wat?")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -410,7 +410,7 @@ func TestBackspace(t *testing.T) {
|
||||||
b.Backspace()
|
b.Backspace()
|
||||||
b.Write([]rune("l")...)
|
b.Write([]rune("l")...)
|
||||||
lines := b.GetVisibleLines()
|
lines := b.GetVisibleLines()
|
||||||
assert.Equal(t, "hell", lines[0].String())
|
assert.Equal(t, "hell\x00", lines[0].String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBackspaceWithWrap(t *testing.T) {
|
func TestBackspaceWithWrap(t *testing.T) {
|
||||||
|
|
|
@ -10,11 +10,11 @@ var DefaultConfig = Config{
|
||||||
Red: strToColourNoErr("#c2454e"),
|
Red: strToColourNoErr("#c2454e"),
|
||||||
Green: strToColourNoErr("#7cbf9e"),
|
Green: strToColourNoErr("#7cbf9e"),
|
||||||
Yellow: strToColourNoErr("#8a7a63"),
|
Yellow: strToColourNoErr("#8a7a63"),
|
||||||
Blue: strToColourNoErr("#2e3340"),
|
Blue: strToColourNoErr("#065f73"),
|
||||||
Magenta: strToColourNoErr("#ff5879"),
|
Magenta: strToColourNoErr("#ff5879"),
|
||||||
Cyan: strToColourNoErr("#44b5b1"),
|
Cyan: strToColourNoErr("#44b5b1"),
|
||||||
LightGrey: strToColourNoErr("#f2f1b9"),
|
LightGrey: strToColourNoErr("#f2f1b9"),
|
||||||
DarkGrey: strToColourNoErr("#065f73"),
|
DarkGrey: strToColourNoErr("#3e4360"),
|
||||||
LightRed: strToColourNoErr("#ef5847"),
|
LightRed: strToColourNoErr("#ef5847"),
|
||||||
LightGreen: strToColourNoErr("#a2db91"),
|
LightGreen: strToColourNoErr("#a2db91"),
|
||||||
LightYellow: strToColourNoErr("#beb090"),
|
LightYellow: strToColourNoErr("#beb090"),
|
||||||
|
|
27
gui/gui.go
27
gui/gui.go
|
@ -113,6 +113,12 @@ func (gui *GUI) Render() error {
|
||||||
gui.window.SetFramebufferSizeCallback(gui.resize)
|
gui.window.SetFramebufferSizeCallback(gui.resize)
|
||||||
gui.window.SetKeyCallback(gui.key)
|
gui.window.SetKeyCallback(gui.key)
|
||||||
gui.window.SetCharCallback(gui.char)
|
gui.window.SetCharCallback(gui.char)
|
||||||
|
gui.window.SetRefreshCallback(func(w *glfw.Window) {
|
||||||
|
select {
|
||||||
|
case changeChan <- true:
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
})
|
||||||
gui.window.SetFocusCallback(func(w *glfw.Window, focused bool) {
|
gui.window.SetFocusCallback(func(w *glfw.Window, focused bool) {
|
||||||
if focused {
|
if focused {
|
||||||
select {
|
select {
|
||||||
|
@ -190,12 +196,19 @@ func (gui *GUI) Render() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gui.font.SetColor(1, 0.5, 0.5, 0.5)
|
cx := int(gui.terminal.GetLogicalCursorX())
|
||||||
fpsData := ""
|
cy := int(gui.terminal.GetLogicalCursorY())
|
||||||
if gui.config.Rendering.AlwaysRepaint {
|
gui.renderer.DrawCursor(cx, cy, gui.config.ColourScheme.Cursor)
|
||||||
fpsData = fmt.Sprintf("%d FPS | %d,%d", fps, gui.terminal.GetLogicalCursorX(), gui.terminal.GetLogicalCursorY())
|
|
||||||
}
|
_ = fps
|
||||||
gui.font.Print(10, float32(gui.height-20), 1.5, fmt.Sprintf("%s", fpsData))
|
/*
|
||||||
|
gui.font.SetColor(1, 0.5, 0.5, 0.5)
|
||||||
|
fpsData := ""
|
||||||
|
if gui.config.Rendering.AlwaysRepaint {
|
||||||
|
fpsData = fmt.Sprintf("%d FPS | %d,%d", fps, gui.terminal.GetLogicalCursorX(), gui.terminal.GetLogicalCursorY())
|
||||||
|
}
|
||||||
|
gui.font.Print(10, float32(gui.height-20), 1.5, fmt.Sprintf("%s", fpsData))
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
if gui.config.Rendering.AlwaysRepaint || frames > 0 {
|
if gui.config.Rendering.AlwaysRepaint || frames > 0 {
|
||||||
|
@ -204,7 +217,7 @@ func (gui *GUI) Render() error {
|
||||||
frames--
|
frames--
|
||||||
}
|
}
|
||||||
|
|
||||||
glfw.WaitEventsTimeout(0.02) // every 20ms = 50fps on nothing changing
|
glfw.WaitEventsTimeout(0.02) // up to 50fps on no input, otherwise higher
|
||||||
}
|
}
|
||||||
|
|
||||||
gui.logger.Debugf("Stopping render...")
|
gui.logger.Debugf("Stopping render...")
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
type Renderer interface {
|
type Renderer interface {
|
||||||
SetArea(areaX int, areaY int, areaWidth int, areaHeight int)
|
SetArea(areaX int, areaY int, areaWidth int, areaHeight int)
|
||||||
DrawCell(cell *buffer.Cell, col int, row int)
|
DrawCell(cell *buffer.Cell, col int, row int)
|
||||||
|
DrawCursor(col int, row int, colour config.Colour)
|
||||||
GetTermSize() (int, int)
|
GetTermSize() (int, int)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,12 +55,13 @@ func (r *OpenGLRenderer) newRectangle(x float32, y float32, colourAttr uint32) *
|
||||||
rect := &rectangle{
|
rect := &rectangle{
|
||||||
colour: [3]float32{0, 0, 1},
|
colour: [3]float32{0, 0, 1},
|
||||||
points: []float32{
|
points: []float32{
|
||||||
x, y + h, 0,
|
|
||||||
x, y, 0,
|
x, y, 0,
|
||||||
x + w, y, 0,
|
|
||||||
x, y + h, 0,
|
x, y + h, 0,
|
||||||
x + w, y + h, 0,
|
x + w, y + h, 0,
|
||||||
|
|
||||||
x + w, y, 0,
|
x + w, y, 0,
|
||||||
|
x, y, 0,
|
||||||
|
x + w, y + h, 0,
|
||||||
},
|
},
|
||||||
colourAttr: colourAttr,
|
colourAttr: colourAttr,
|
||||||
}
|
}
|
||||||
|
@ -151,7 +153,7 @@ func (r *OpenGLRenderer) SetFontScale(fontScale int32) {
|
||||||
|
|
||||||
func (r *OpenGLRenderer) SetFont(font *glfont.Font) { // @todo check for monospace and return error if not?
|
func (r *OpenGLRenderer) SetFont(font *glfont.Font) { // @todo check for monospace and return error if not?
|
||||||
r.font = font
|
r.font = font
|
||||||
r.verticalCellPadding = (0.3 * float32(r.fontScale))
|
r.verticalCellPadding = (0.25 * float32(r.fontScale))
|
||||||
r.cellWidth = font.Width(1, "X")
|
r.cellWidth = font.Width(1, "X")
|
||||||
r.cellHeight = font.Height(1, "X") + (r.verticalCellPadding * 2) // vertical padding
|
r.cellHeight = font.Height(1, "X") + (r.verticalCellPadding * 2) // vertical padding
|
||||||
r.termCols = int(math.Floor(float64(float32(r.areaWidth) / r.cellWidth)))
|
r.termCols = int(math.Floor(float64(float32(r.areaWidth) / r.cellWidth)))
|
||||||
|
@ -191,9 +193,34 @@ func (r *OpenGLRenderer) generateRectangles() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *OpenGLRenderer) DrawCursor(col int, row int, colour config.Colour) {
|
||||||
|
|
||||||
|
rect, ok := r.rectangles[[2]int{col, row}]
|
||||||
|
if !ok { // probably trying to draw during resize - perhaps add a mutex?
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
solid := true
|
||||||
|
|
||||||
|
mode := uint32(gl.LINE_LOOP) // gl.TRIANGES for solid cursor
|
||||||
|
points := int32(4)
|
||||||
|
|
||||||
|
if solid {
|
||||||
|
mode = gl.TRIANGLES
|
||||||
|
points = 6
|
||||||
|
}
|
||||||
|
|
||||||
|
gl.UseProgram(r.program)
|
||||||
|
rect.setColour(colour)
|
||||||
|
gl.BindVertexArray(rect.vao)
|
||||||
|
//gl.PolygonMode(gl.FRONT_AND_BACK, gl.FILL)
|
||||||
|
gl.DrawArrays(mode, 0, points)
|
||||||
|
//gl.PolygonMode(gl.FRONT_AND_BACK, gl.FILL)
|
||||||
|
}
|
||||||
|
|
||||||
func (r *OpenGLRenderer) DrawCell(cell *buffer.Cell, col int, row int) {
|
func (r *OpenGLRenderer) DrawCell(cell *buffer.Cell, col int, row int) {
|
||||||
|
|
||||||
if cell == nil || cell.Attr().Hidden || cell.Rune() == 0x00 {
|
if cell == nil || cell.Attr().Hidden || (cell.Rune() == 0x00) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,61 +235,34 @@ func (r *OpenGLRenderer) DrawCell(cell *buffer.Cell, col int, row int) {
|
||||||
bg = cell.Bg()
|
bg = cell.Bg()
|
||||||
}
|
}
|
||||||
|
|
||||||
var alpha float32 = 1
|
|
||||||
if cell.Attr().Dim {
|
|
||||||
alpha = 0.5
|
|
||||||
}
|
|
||||||
r.font.SetColor(fg[0], fg[1], fg[2], alpha)
|
|
||||||
|
|
||||||
pos, ok := r.cellPositions[[2]int{col, row}]
|
pos, ok := r.cellPositions[[2]int{col, row}]
|
||||||
if !ok {
|
if !ok {
|
||||||
panic(fmt.Sprintf("Missing position data for cell at %d,%d", col, row))
|
panic(fmt.Sprintf("Missing position data for cell at %d,%d", col, row))
|
||||||
}
|
}
|
||||||
|
|
||||||
rect, ok := r.rectangles[[2]int{col, row}]
|
|
||||||
if !ok {
|
|
||||||
panic(fmt.Sprintf("Missing rectangle data for cell at %d,%d", col, row))
|
|
||||||
}
|
|
||||||
|
|
||||||
gl.UseProgram(r.program)
|
gl.UseProgram(r.program)
|
||||||
|
|
||||||
// don't bother rendering rectangles that are the same colour as the background
|
// don't bother rendering rectangles that are the same colour as the background
|
||||||
if bg != r.config.ColourScheme.Background {
|
if bg != r.config.ColourScheme.Background {
|
||||||
|
|
||||||
|
rect, ok := r.rectangles[[2]int{col, row}]
|
||||||
|
if !ok {
|
||||||
|
panic(fmt.Sprintf("Missing rectangle data for cell at %d,%d", col, row))
|
||||||
|
}
|
||||||
rect.setColour(bg)
|
rect.setColour(bg)
|
||||||
gl.BindVertexArray(rect.vao)
|
gl.BindVertexArray(rect.vao)
|
||||||
gl.DrawArrays(gl.TRIANGLES, 0, 6)
|
gl.DrawArrays(gl.TRIANGLES, 0, 6)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var alpha float32 = 1
|
||||||
|
if cell.Attr().Dim {
|
||||||
|
alpha = 0.5
|
||||||
|
}
|
||||||
|
r.font.SetColor(fg[0], fg[1], fg[2], alpha)
|
||||||
|
|
||||||
if cell.Attr().Bold { // bold means draw text again one pixel to right, so it's fatter
|
if cell.Attr().Bold { // bold means draw text again one pixel to right, so it's fatter
|
||||||
r.font.Print(pos[0]+1, pos[1], 1, string(cell.Rune()))
|
r.font.Print(pos[0]+1, pos[1], 1, string(cell.Rune()))
|
||||||
}
|
}
|
||||||
r.font.Print(pos[0], pos[1], 1, string(cell.Rune()))
|
r.font.Print(pos[0], pos[1], 1, string(cell.Rune()))
|
||||||
|
|
||||||
/*
|
|
||||||
this was passed into cell
|
|
||||||
x := ((float32(col) * gui.charWidth) - (float32(gui.width) / 2)) + (gui.charWidth / 2)
|
|
||||||
y := -(((float32(row) * gui.charHeight) - (float32(gui.height) / 2)) + (gui.charHeight / 2))
|
|
||||||
|
|
||||||
this was in cell:
|
|
||||||
x: x + (float32(gui.width) / 2) - float32(gui.charWidth/2),
|
|
||||||
y: float32(gui.height) - (y + (float32(gui.height) / 2)) + (gui.charHeight / 2) - (gui.verticalPadding / 2),
|
|
||||||
|
|
||||||
|
|
||||||
and then points:
|
|
||||||
|
|
||||||
x = (x - (w / 2)) / (float32(gui.width) / 2)
|
|
||||||
y = (y - (h / 2)) / (float32(gui.height) / 2)
|
|
||||||
w = (w / float32(gui.width/2))
|
|
||||||
h = (h / float32(gui.height/2))
|
|
||||||
cell.points = []float32{
|
|
||||||
x, y + h, 0,
|
|
||||||
x, y, 0,
|
|
||||||
x + w, y, 0,
|
|
||||||
x, y + h, 0,
|
|
||||||
x + w, y + h, 0,
|
|
||||||
x + w, y, 0,
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue