mirror of
https://github.com/felixangell/phi.git
synced 2024-09-11 07:45:30 +03:00
move cursor render into cursor
This commit is contained in:
parent
2c0775ad55
commit
05b92f949e
@ -155,7 +155,7 @@ func NewBuffer(conf *cfg.TomlConfig, buffOpts BufferConfig, parent *View, index
|
|||||||
buff := &Buffer{
|
buff := &Buffer{
|
||||||
index: index,
|
index: index,
|
||||||
parent: parent,
|
parent: parent,
|
||||||
curs: &Cursor{},
|
curs: nil,
|
||||||
cfg: config,
|
cfg: config,
|
||||||
table: piecetable.MakePieceTable(""),
|
table: piecetable.MakePieceTable(""),
|
||||||
buffOpts: buffOpts,
|
buffOpts: buffOpts,
|
||||||
@ -163,6 +163,7 @@ func NewBuffer(conf *cfg.TomlConfig, buffOpts BufferConfig, parent *View, index
|
|||||||
cam: &camera{0, 0, 0, 0},
|
cam: &camera{0, 0, 0, 0},
|
||||||
autoComplete: newAutoCompleteBox(),
|
autoComplete: newAutoCompleteBox(),
|
||||||
}
|
}
|
||||||
|
buff.curs = newCursor(buff)
|
||||||
return buff
|
return buff
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1354,25 +1355,21 @@ func (b *Buffer) renderAt(ctx *strife.Renderer, rx int, ry int) {
|
|||||||
lastSelection.renderAt(ctx, b.x+b.ex, b.y+b.ey)
|
lastSelection.renderAt(ctx, b.x+b.ex, b.y+b.ey)
|
||||||
}
|
}
|
||||||
|
|
||||||
cursorHeight := last_h + pad
|
// calculate cursor sizes... does
|
||||||
|
// this have to be done every frame?
|
||||||
// render the ol' cursor
|
{
|
||||||
if b.HasFocus() && (renderFlashingCursor || b.curs.moving) && b.cfg.Cursor.Draw {
|
|
||||||
cursorWidth := b.cfg.Cursor.GetCaretWidth()
|
cursorWidth := b.cfg.Cursor.GetCaretWidth()
|
||||||
if cursorWidth == -1 {
|
if cursorWidth == -1 {
|
||||||
cursorWidth = last_w
|
cursorWidth = last_w
|
||||||
}
|
}
|
||||||
|
cursorHeight := last_h + pad
|
||||||
|
|
||||||
xPos := b.ex + (rx + b.curs.rx*last_w) - (b.cam.x * last_w)
|
b.curs.SetSize(cursorWidth, cursorHeight)
|
||||||
yPos := b.ey + (ry + b.curs.ry*cursorHeight) - (b.cam.y * cursorHeight)
|
}
|
||||||
|
|
||||||
ctx.SetColor(strife.HexRGB(b.buffOpts.cursor))
|
// render the ol' cursor
|
||||||
ctx.Rect(xPos, yPos, cursorWidth, cursorHeight, strife.Fill)
|
if b.HasFocus() && (renderFlashingCursor || b.curs.moving) && b.cfg.Cursor.Draw {
|
||||||
|
b.curs.Render(ctx, rx, ry)
|
||||||
if DEBUG_MODE {
|
|
||||||
ctx.SetColor(strife.HexRGB(0xff00ff))
|
|
||||||
ctx.Rect(xPos, yPos, cursorWidth, cursorHeight, strife.Line)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
numLines := len(b.table.Lines)
|
numLines := len(b.table.Lines)
|
||||||
@ -1482,9 +1479,9 @@ func (b *Buffer) renderAt(ctx *strife.Renderer, rx int, ry int) {
|
|||||||
if b.autoComplete.hasSuggestions() {
|
if b.autoComplete.hasSuggestions() {
|
||||||
|
|
||||||
xPos := b.ex + (rx + b.curs.rx*last_w) - (b.cam.x * last_w)
|
xPos := b.ex + (rx + b.curs.rx*last_w) - (b.cam.x * last_w)
|
||||||
yPos := b.ey + (ry + b.curs.ry*cursorHeight) - (b.cam.y * cursorHeight)
|
yPos := b.ey + (ry + b.curs.ry*b.curs.height) - (b.cam.y * b.curs.height)
|
||||||
|
|
||||||
autoCompleteBoxHeight := len(b.autoComplete.suggestions) * cursorHeight
|
autoCompleteBoxHeight := len(b.autoComplete.suggestions) * b.curs.height
|
||||||
yPos = yPos - autoCompleteBoxHeight
|
yPos = yPos - autoCompleteBoxHeight
|
||||||
|
|
||||||
b.autoComplete.renderAt(xPos, yPos, ctx)
|
b.autoComplete.renderAt(xPos, yPos, ctx)
|
||||||
|
@ -1,10 +1,32 @@
|
|||||||
package gui
|
package gui
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/felixangell/strife"
|
||||||
|
)
|
||||||
|
|
||||||
type Cursor struct {
|
type Cursor struct {
|
||||||
x, y int
|
parent *Buffer
|
||||||
rx, ry int
|
x, y int
|
||||||
dx, dy int
|
rx, ry int
|
||||||
moving bool
|
dx, dy int
|
||||||
|
moving bool
|
||||||
|
width, height int
|
||||||
|
}
|
||||||
|
|
||||||
|
func newCursor(parent *Buffer) *Cursor {
|
||||||
|
return &Cursor{
|
||||||
|
parent,
|
||||||
|
0, 0,
|
||||||
|
0, 0,
|
||||||
|
0, 0,
|
||||||
|
false,
|
||||||
|
0, 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Cursor) SetSize(w, h int) {
|
||||||
|
c.width = w
|
||||||
|
c.height = h
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cursor) gotoStart() {
|
func (c *Cursor) gotoStart() {
|
||||||
@ -40,3 +62,18 @@ func (c *Cursor) moveRender(x, y, rx, ry int) {
|
|||||||
c.rx += rx
|
c.rx += rx
|
||||||
c.ry += ry
|
c.ry += ry
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Cursor) Render(ctx *strife.Renderer, xOff, yOff int) {
|
||||||
|
b := c.parent
|
||||||
|
|
||||||
|
xPos := b.ex + (xOff + c.rx*last_w) - (b.cam.x * last_w)
|
||||||
|
yPos := b.ey + (yOff + c.ry*c.height) - (b.cam.y * c.height)
|
||||||
|
|
||||||
|
ctx.SetColor(strife.HexRGB(b.buffOpts.cursor))
|
||||||
|
ctx.Rect(xPos, yPos, c.width, c.height, strife.Fill)
|
||||||
|
|
||||||
|
if DEBUG_MODE {
|
||||||
|
ctx.SetColor(strife.HexRGB(0xff00ff))
|
||||||
|
ctx.Rect(xPos, yPos, c.width, c.height, strife.Line)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
39
gui/view.go
39
gui/view.go
@ -307,6 +307,29 @@ func (n *View) OnUpdate() bool {
|
|||||||
return dirty
|
return dirty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (n *View) Resize(w, h int) {
|
||||||
|
n.BaseComponent.Resize(w, h)
|
||||||
|
|
||||||
|
// dont resize any buffer panes
|
||||||
|
// because there are none.
|
||||||
|
if len(n.buffers) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// work out the size of the buffer and set it
|
||||||
|
// note that we +1 the components because
|
||||||
|
// we haven't yet added the panel
|
||||||
|
bufferWidth := n.w / len(n.buffers)
|
||||||
|
|
||||||
|
// translate all the buffers accordingly.
|
||||||
|
idx := 0
|
||||||
|
for _, buffPane := range n.buffers {
|
||||||
|
buffPane.Resize(bufferWidth, n.h)
|
||||||
|
buffPane.SetPosition(bufferWidth*idx, 0)
|
||||||
|
idx++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (n *View) OnRender(ctx *strife.Renderer) {
|
func (n *View) OnRender(ctx *strife.Renderer) {
|
||||||
for _, buffPane := range n.buffers {
|
for _, buffPane := range n.buffers {
|
||||||
buffPane.OnRender(ctx)
|
buffPane.OnRender(ctx)
|
||||||
@ -342,23 +365,9 @@ func (n *View) AddBuffer() *Buffer {
|
|||||||
|
|
||||||
c.SetFocus(true)
|
c.SetFocus(true)
|
||||||
|
|
||||||
// work out the size of the buffer and set it
|
|
||||||
// note that we +1 the components because
|
|
||||||
// we haven't yet added the panel
|
|
||||||
var bufferWidth int
|
|
||||||
bufferWidth = n.w / (c.index + 1)
|
|
||||||
|
|
||||||
n.focusedBuff = c.index
|
n.focusedBuff = c.index
|
||||||
|
|
||||||
n.buffers = append(n.buffers, NewBufferPane(c))
|
n.buffers = append(n.buffers, NewBufferPane(c))
|
||||||
|
n.Resize(n.w, n.h)
|
||||||
// translate all the buffers accordingly.
|
|
||||||
idx := 0
|
|
||||||
for _, buffPane := range n.buffers {
|
|
||||||
buffPane.Resize(bufferWidth, n.h)
|
|
||||||
buffPane.SetPosition(bufferWidth*idx, 0)
|
|
||||||
idx++
|
|
||||||
}
|
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
8
main.go
8
main.go
@ -24,6 +24,10 @@ type PhiEditor struct {
|
|||||||
mainView *gui.View
|
mainView *gui.View
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (n *PhiEditor) resize(w, h int) {
|
||||||
|
n.mainView.Resize(w, h)
|
||||||
|
}
|
||||||
|
|
||||||
func (n *PhiEditor) handleEvent(evt strife.StrifeEvent) {
|
func (n *PhiEditor) handleEvent(evt strife.StrifeEvent) {
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -84,9 +88,11 @@ func main() {
|
|||||||
|
|
||||||
editor := &PhiEditor{running: true}
|
editor := &PhiEditor{running: true}
|
||||||
window.HandleEvents(func(evt strife.StrifeEvent) {
|
window.HandleEvents(func(evt strife.StrifeEvent) {
|
||||||
switch evt.(type) {
|
switch event := evt.(type) {
|
||||||
case *strife.CloseEvent:
|
case *strife.CloseEvent:
|
||||||
window.Close()
|
window.Close()
|
||||||
|
case *strife.WindowResizeEvent:
|
||||||
|
editor.resize(event.Width, event.Height)
|
||||||
default:
|
default:
|
||||||
editor.handleEvent(evt)
|
editor.handleEvent(evt)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user