gocui/eventMouseMove.go

129 lines
3.2 KiB
Go
Raw Normal View History

2025-02-01 16:44:43 -06:00
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
// 2025 note by jcarr:
// this is one of the coolest things ever worked with.
// Personally, I've been working on making a gocui GO plugin
// so I can use it as a generalized console GUI toolkit.
//
// Well done everyone that has contributed to this gocui project !!!
// I am in your debt. Happy hacking & peace.
package main
import (
"fmt"
"github.com/awesome-gocui/gocui"
log "go.wit.com/log"
2025-02-01 17:03:14 -06:00
"go.wit.com/widget"
2025-02-01 16:44:43 -06:00
)
2025-02-02 23:36:33 -06:00
var currentDrag *guiWidget
2025-02-01 16:44:43 -06:00
// this function uses the mouse position to highlight & unhighlight things
// this is run every time the user moves the mouse over the terminal window
func mouseMove(g *gocui.Gui) {
2025-02-03 01:11:01 -06:00
w, h := g.MousePosition()
2025-02-01 16:44:43 -06:00
if me.supermouse {
for _, tk := range findByXY(w, h) {
2025-02-03 01:11:01 -06:00
s := fmt.Sprintf("SM (%3d,%3d)", w, h)
tk.dumpWidget(s)
2025-02-01 16:44:43 -06:00
}
}
2025-02-01 17:17:32 -06:00
if me.globalMouseDown {
// log.Info("msgMouseDown == true")
2025-02-01 17:17:32 -06:00
// plugin will segfault if you don't keep this inside a check for msgMouseDown
// don't move this code out of here
var found bool = false
2025-02-02 23:36:33 -06:00
if currentDrag != nil {
2025-02-04 11:12:13 -06:00
currentDrag.moveNew()
2025-02-02 23:36:33 -06:00
return
}
2025-02-03 10:21:43 -06:00
for _, tk := range findByXY(w, h) {
if tk.node.WidgetType == widget.Window {
currentDrag = tk
return
}
}
2025-02-02 23:36:33 -06:00
for _, tk := range findByXY(w, h) {
if tk.node.WidgetType == widget.Flag {
currentDrag = tk
2025-02-04 11:12:13 -06:00
// tk.moveNew()
2025-02-02 23:36:33 -06:00
return
}
}
2025-02-01 17:03:14 -06:00
for _, tk := range findByXY(w, h) {
2025-02-01 17:17:32 -06:00
if tk.node.WidgetType == widget.Stdout {
2025-02-03 00:07:48 -06:00
currentDrag = tk
2025-02-04 11:12:13 -06:00
// tk.moveNew()
2025-02-01 17:17:32 -06:00
return
2025-02-01 17:03:14 -06:00
}
2025-02-01 18:27:42 -06:00
if tk.node.WidgetType == widget.Label {
2025-02-02 23:36:33 -06:00
currentDrag = tk
2025-02-04 11:12:13 -06:00
// tk.moveNew()
2025-02-01 18:27:42 -06:00
return
}
found = true
}
if !found {
log.Info(fmt.Sprintf("findByXY() empty. nothing to move at (%d,%d)", w, h))
2025-02-01 17:03:14 -06:00
}
}
2025-02-01 16:44:43 -06:00
2025-02-01 19:42:04 -06:00
if widgetView, _ := g.View("msg"); widgetView == nil {
if createStdout(g) {
return
}
2025-02-01 16:44:43 -06:00
return
}
for _, view := range g.Views() {
view.Highlight = false
}
2025-02-03 01:11:01 -06:00
if v, err := g.ViewByPosition(w, h); err == nil {
2025-02-01 16:44:43 -06:00
v.Highlight = true
}
}
2025-02-01 17:17:32 -06:00
// this is how the window gets dragged around
2025-02-04 11:12:13 -06:00
func (tk *guiWidget) moveNew() {
w, h := me.baseGui.MousePosition()
2025-02-03 10:21:43 -06:00
if tk.node.WidgetType == widget.Window {
2025-02-04 12:45:52 -06:00
tk.DrawAt(w, h)
2025-02-04 10:04:45 -06:00
tk.redrawWindow(w, h)
s := fmt.Sprintf("move(%dx%d) %s WIN", w, h, tk.cuiName)
2025-02-03 10:21:43 -06:00
tk.dumpWidget(s)
return
}
2025-02-02 23:36:33 -06:00
if tk.node.WidgetType == widget.Flag {
2025-02-04 11:12:13 -06:00
me.baseGui.SetView(tk.cuiName, w-3, h-3, w+20, h+20, 0)
2025-02-03 00:07:48 -06:00
tk.verifyRect()
s := fmt.Sprintf("move(%dx%d) %s ###", w, h, tk.cuiName)
tk.dumpWidget(s)
return
2025-02-02 23:36:33 -06:00
} else {
2025-02-04 11:12:13 -06:00
// log.Info("NOT MOVE FLAG. PASSING MOVE TO MSG", tk.node.WidgetType)
2025-02-04 12:45:52 -06:00
// tk.dumpWidget("moveNew() MSG" + tk.cuiName)
outputW := 180
outputH := 40
me.baseGui.SetView("msg", w-xOffset, h-yOffset, w-xOffset+outputW, h-yOffset+outputH+me.FramePadH, 0)
me.startOutputW = w - xOffset
me.startOutputH = h - yOffset
me.baseGui.SetViewOnBottom("msg")
}
2025-02-01 16:44:43 -06:00
}
2025-02-01 17:03:14 -06:00
func createStdout(g *gocui.Gui) bool {
2025-02-01 19:42:04 -06:00
makeOutputWidget(g, "this is a create before a mouse click")
if me.logStdout != nil {
msg := fmt.Sprintf("test out gocuiEvent() %d\n", me.ecount)
// me.logStdout.v.Write([]byte(msg))
me.logStdout.Write([]byte(msg))
log.Log(NOW, "logStdout test out")
2025-02-01 16:44:43 -06:00
}
2025-02-01 19:42:04 -06:00
return true
2025-02-01 16:44:43 -06:00
}