155 lines
3.7 KiB
Go
155 lines
3.7 KiB
Go
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
|
|
// Use of this source code is governed by the GPL 3.0
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/awesome-gocui/gocui"
|
|
|
|
"go.wit.com/log"
|
|
"go.wit.com/widget"
|
|
)
|
|
|
|
func mouseUp(g *gocui.Gui, v *gocui.View) error {
|
|
w, h := g.MousePosition()
|
|
|
|
// useful to debug everything that is being clicked on
|
|
/*
|
|
for _, tk := range findByXY(w, h) {
|
|
tk.dumpWidget("mouseUp()")
|
|
}
|
|
*/
|
|
|
|
log.Info("mouseUp() setting me.globalMouseDown = false")
|
|
me.globalMouseDown = false
|
|
currentDrag = nil
|
|
|
|
dropdownUnclicked(w, h)
|
|
|
|
return nil
|
|
}
|
|
|
|
// this is where you have to figure out what
|
|
// widget was underneath so you can active
|
|
// the right response for the toolkit user's app
|
|
func mouseDown(g *gocui.Gui, v *gocui.View) error {
|
|
log.Info("mouseDown() setting globalMouseDown = true")
|
|
me.globalMouseDown = true
|
|
|
|
if me.dropdown.active {
|
|
w, h := g.MousePosition()
|
|
log.Info("mouseDown() stopping here. dropdwon menu is in effect")
|
|
for _, tk := range findByXY(w, h) {
|
|
if (tk.node.WidgetType == widget.Flag) && (tk == me.dropdown.tk) {
|
|
log.Info("SENDING CLICK TO Flag (dropdown)")
|
|
tk.doWidgetClick(w, h)
|
|
me.dropdown.active = false
|
|
return nil
|
|
}
|
|
}
|
|
log.Info("never found dropdown at", w, h)
|
|
// me.dropdown.active = false
|
|
return nil
|
|
}
|
|
|
|
var found bool = false
|
|
w, h := g.MousePosition()
|
|
for _, tk := range findByXY(w, h) {
|
|
tk.dumpWidget("mouseDown()")
|
|
if tk.node.WidgetType == widget.Button {
|
|
log.Info("SENDING CLICK TO Button")
|
|
tk.doWidgetClick(w, h)
|
|
return nil
|
|
}
|
|
if tk.node.WidgetType == widget.Checkbox {
|
|
log.Info("SENDING CLICK TO Checkbox")
|
|
tk.doWidgetClick(w, h)
|
|
return nil
|
|
}
|
|
if tk.node.WidgetType == widget.Dropdown {
|
|
log.Info("SENDING CLICK TO Dropdown")
|
|
tk.doWidgetClick(w, h)
|
|
return nil
|
|
}
|
|
if tk.node.WidgetType == widget.Textbox {
|
|
log.Info("SENDING CLICK TO Textbox")
|
|
tk.doWidgetClick(w, h)
|
|
return nil
|
|
}
|
|
found = true
|
|
}
|
|
|
|
mx, my := g.MousePosition()
|
|
for _, tk := range findByXY(mx, my) {
|
|
if tk.node.WidgetType == widget.Window {
|
|
tk.dragW = mx - tk.gocuiSize.w0
|
|
tk.dragH = my - tk.gocuiSize.h0
|
|
if (mx-tk.gocuiSize.w0 < 3) && (my-tk.gocuiSize.h0 < 3) {
|
|
log.Info("RESIZE WINDOW", tk.dragW, tk.dragH)
|
|
}
|
|
log.Info("SENDING CLICK TO WINDOW", tk.dragW, tk.dragH)
|
|
tk.doWidgetClick(mx-tk.dragW, my-tk.dragH)
|
|
return nil
|
|
}
|
|
if tk.node.WidgetType == widget.Label {
|
|
log.Info("IGNORE LABLE")
|
|
found = false
|
|
log.Info("setting mousedown to true for label")
|
|
// msgMouseDown = true
|
|
return nil
|
|
}
|
|
/*
|
|
if tk.node.WidgetType == widget.Label {
|
|
log.Info("SENDING CLICK TO Label")
|
|
tk.doWidgetClick(mx, my)
|
|
return nil
|
|
}
|
|
*/
|
|
found = true
|
|
}
|
|
if !found {
|
|
log.Log(GOCUI, fmt.Sprintf("mouseDown() found nothing at (%d,%d)", mx, my))
|
|
}
|
|
|
|
// sort this junk out
|
|
vx0, vy0, vx1, vy1, err := g.ViewPosition("msg")
|
|
if err == nil {
|
|
if mx >= vx0 && mx <= vx1 && my >= vy0 && my <= vy1 {
|
|
return msgDown(g, v)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// this needs to go
|
|
// event triggers when you push down on a mouse button
|
|
func msgDown(g *gocui.Gui, v *gocui.View) error {
|
|
w, h := g.MousePosition()
|
|
|
|
for _, tk := range findByXY(w, h) {
|
|
tk.dumpWidget("msgDown()")
|
|
}
|
|
|
|
vx, vy, _, _, err := g.ViewPosition("msg")
|
|
if err == nil {
|
|
me.stdout.mouseOffsetW = w - vx
|
|
me.stdout.mouseOffsetH = h - vy
|
|
}
|
|
|
|
// did the user click in the corner of the stdout window? If so, resize the window.
|
|
cornerW := w - vx
|
|
cornerH := h - vy
|
|
if (me.stdout.w-cornerW < 4) && (me.stdout.h-cornerH < 4) {
|
|
log.Info("Resize msg", cornerW, cornerH)
|
|
me.stdout.resize = true
|
|
} else {
|
|
log.Info("not Resize msg", cornerW, cornerH)
|
|
me.stdout.resize = false
|
|
}
|
|
log.Info("setting mousedown to true for msg")
|
|
// msgMouseDown = true
|
|
return nil
|
|
}
|