gocui/eventMouse.go

130 lines
3.2 KiB
Go
Raw Normal View History

// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
package main
import (
2025-02-08 08:07:03 -06:00
"time"
"github.com/awesome-gocui/gocui"
"go.wit.com/log"
2025-02-01 18:27:42 -06:00
"go.wit.com/widget"
)
func mouseUp(g *gocui.Gui, v *gocui.View) error {
2025-01-31 12:36:46 -06:00
// useful to debug everything that is being clicked on
/*
for _, tk := range findByXY(w, h) {
2025-02-01 13:58:53 -06:00
tk.dumpWidget("mouseUp()")
}
*/
2025-02-08 08:07:03 -06:00
me.mouse.mouseUp = true
2025-02-08 08:47:55 -06:00
// me.mouse.globalMouseDown = false
2025-02-08 08:36:08 -06:00
me.mouse.currentDrag = nil
if me.mouse.double && (time.Since(me.mouse.down) < me.mouse.doubletime) {
me.mouse.double = false
doMouseDoubleClick(me.mouse.downW, me.mouse.downH)
return nil
}
me.mouse.double = false
2025-02-08 08:36:08 -06:00
if time.Since(me.mouse.down) < me.mouse.clicktime {
doMouseClick(me.mouse.downW, me.mouse.downH)
}
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 {
2025-02-08 08:07:03 -06:00
if me.mouse.mouseUp {
2025-02-08 08:36:08 -06:00
if time.Since(me.mouse.down) < me.mouse.doubletime {
me.mouse.double = true
2025-02-08 08:36:08 -06:00
}
2025-02-08 08:47:55 -06:00
// me.mouse.globalMouseDown = true
2025-02-08 08:07:03 -06:00
me.mouse.mouseUp = false
me.mouse.down = time.Now()
w, h := g.MousePosition()
me.mouse.downW = w
me.mouse.downH = h
return nil
}
if time.Since(me.mouse.down) < me.mouse.clicktime {
log.Info("not yet")
return nil
}
w, h := g.MousePosition()
// if the dropdown is active, never do anything else
2025-02-06 05:41:51 -06:00
if me.dropdown.active {
log.Info("mouseDown() stopping here. dropdwon menu is in effect")
for _, tk := range findByXY(w, h) {
2025-02-06 05:52:00 -06:00
if (tk.node.WidgetType == widget.Flag) && (tk == me.dropdown.tk) {
// log.Info("SENDING CLICK TO Flag (dropdown)")
2025-02-06 05:41:51 -06:00
tk.doWidgetClick(w, h)
2025-02-06 05:52:00 -06:00
me.dropdown.active = false
2025-02-06 05:41:51 -06:00
return nil
}
}
2025-02-06 05:52:00 -06:00
log.Info("never found dropdown at", w, h)
2025-02-07 00:35:08 -06:00
return nil
}
// if the textbox is active, never do anything else
if me.textbox.active {
log.Info("mouseDown() stopping here. textbox widget is open")
for _, tk := range findByXY(w, h) {
if (tk.node.WidgetType == widget.Flag) && (tk == me.textbox.tk) {
me.textbox.active = false
tk.textboxClosed()
return nil
}
}
log.Info("never found textbox at", w, h)
2025-02-06 05:41:51 -06:00
return nil
}
// figre out what window this is
tk := findWindowUnderMouse()
if tk == nil {
log.Info("mouseDown() nothing to click on at", w, h)
return nil
}
2025-02-06 13:47:19 -06:00
tk.makeWindowActive()
2025-02-06 14:13:31 -06:00
// log.Info("SENDING mouseDown() to findWindowUnderMouse()")
if tk.node.WidgetType == widget.Window {
// check to see if this is a direct click on a widget
for _, tk := range tk.findByXYreal(w, h) {
2025-02-06 14:13:31 -06:00
// tk.dumpWidget("mouseDown()")
if tk.node.WidgetType == widget.Button {
// log.Info("SENDING CLICK TO Button")
tk.doWidgetClick(w, h)
return nil
2025-02-06 04:15:36 -06:00
}
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)
2025-02-01 18:37:04 -06:00
return nil
}
}
}
2025-02-08 08:36:08 -06:00
me.mouse.currentDrag = tk
2025-02-01 19:42:04 -06:00
return nil
}