2019-05-22 20:35:00 -05:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import "log"
|
2019-05-29 13:48:32 -05:00
|
|
|
// import "time"
|
2019-05-22 20:35:00 -05:00
|
|
|
|
|
|
|
import "github.com/andlabs/ui"
|
|
|
|
import _ "github.com/andlabs/ui/winmanifest"
|
|
|
|
|
|
|
|
import "github.com/davecgh/go-spew/spew"
|
|
|
|
|
2019-05-29 11:54:46 -05:00
|
|
|
func findFB(button *ButtonMap) *ButtonMap {
|
|
|
|
var a *ButtonMap
|
|
|
|
for key, foo := range Data.AllButtons {
|
2019-05-29 13:48:32 -05:00
|
|
|
log.Println("findFB() Data.AllButtons key, foo=", key, foo)
|
2019-05-29 11:54:46 -05:00
|
|
|
if &foo == button {
|
2019-05-29 13:48:32 -05:00
|
|
|
log.Println("findFB() FOUND BUTTON key, foo=", key, foo)
|
2019-05-29 11:54:46 -05:00
|
|
|
a = &foo
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return a
|
|
|
|
}
|
|
|
|
|
2019-05-30 02:51:59 -05:00
|
|
|
func makeSplashArea(wm *WindowMap, ah *AreaHandler) {
|
2019-05-22 20:35:00 -05:00
|
|
|
// make this button just to get the default font (but don't display the button)
|
|
|
|
// There should be another way to do this (?)
|
2019-05-30 02:51:59 -05:00
|
|
|
newB := CreateFontButton(wm, "AREA")
|
2019-05-29 12:49:29 -05:00
|
|
|
|
2019-05-29 17:46:21 -05:00
|
|
|
// ah.Attrstr = makeAttributedString()
|
2019-05-29 13:10:12 -05:00
|
|
|
ah.Area = ui.NewArea(ah)
|
|
|
|
newB.A = ah.Area
|
2019-05-30 02:51:59 -05:00
|
|
|
// Data.AllButtons[1].A = ah.Area
|
|
|
|
// ah.Button = &Data.AllButtons[1]
|
|
|
|
ah.Button = newB
|
2019-05-22 20:35:00 -05:00
|
|
|
|
2019-05-23 15:13:42 -05:00
|
|
|
if (Data.Debug) {
|
2019-05-29 13:10:12 -05:00
|
|
|
spew.Dump(ah.Area)
|
2019-05-23 15:13:42 -05:00
|
|
|
log.Println("DEBUGGING", Data.Debug)
|
|
|
|
} else {
|
2019-05-29 13:10:12 -05:00
|
|
|
log.Println("NOT DEBUGGING AREA mhAH.Button =", ah.Button)
|
2019-05-23 15:13:42 -05:00
|
|
|
}
|
2019-05-22 20:35:00 -05:00
|
|
|
}
|
|
|
|
|
2019-05-29 13:25:25 -05:00
|
|
|
func AreaAppendText(newText *ui.AttributedString, what string, attrs ...ui.Attribute) {
|
|
|
|
start := len(newText.String())
|
|
|
|
end := start + len(what)
|
|
|
|
newText.AppendUnattributed(what)
|
|
|
|
for _, a := range attrs {
|
|
|
|
newText.SetAttribute(a, start, end)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-29 09:24:40 -05:00
|
|
|
func appendWithAttributes(newText *ui.AttributedString, what string, attrs ...ui.Attribute) {
|
|
|
|
start := len(newText.String())
|
2019-05-22 20:35:00 -05:00
|
|
|
end := start + len(what)
|
2019-05-29 09:24:40 -05:00
|
|
|
newText.AppendUnattributed(what)
|
2019-05-22 20:35:00 -05:00
|
|
|
for _, a := range attrs {
|
2019-05-29 09:24:40 -05:00
|
|
|
newText.SetAttribute(a, start, end)
|
2019-05-22 20:35:00 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-29 09:24:40 -05:00
|
|
|
func (ah AreaHandler) Draw(a *ui.Area, p *ui.AreaDrawParams) {
|
2019-05-22 20:35:00 -05:00
|
|
|
tl := ui.DrawNewTextLayout(&ui.DrawTextLayoutParams{
|
2019-05-29 11:54:46 -05:00
|
|
|
String: ah.Attrstr,
|
2019-05-29 13:32:07 -05:00
|
|
|
DefaultFont: ah.Button.FB.Font(),
|
2019-05-22 20:35:00 -05:00
|
|
|
Width: p.AreaWidth,
|
|
|
|
Align: ui.DrawTextAlign(1),
|
|
|
|
})
|
|
|
|
p.Context.Text(tl, 0, 0)
|
|
|
|
defer tl.Free()
|
|
|
|
}
|
|
|
|
|
2019-05-29 09:24:40 -05:00
|
|
|
func (ah AreaHandler) MouseEvent(a *ui.Area, me *ui.AreaMouseEvent) {
|
2019-05-23 15:44:53 -05:00
|
|
|
if (Data.Debug) {
|
2019-05-29 13:32:07 -05:00
|
|
|
log.Println("GOT MouseEvent() ah.Button =", ah.Button)
|
2019-05-23 15:44:53 -05:00
|
|
|
spew.Dump(me)
|
|
|
|
}
|
2019-05-22 20:35:00 -05:00
|
|
|
if (me.Down == 1) {
|
|
|
|
log.Println("GOT MOUSE DOWN")
|
2019-05-29 13:32:07 -05:00
|
|
|
log.Println("GOT MOUSE DOWN ah.Button =", ah.Button)
|
|
|
|
log.Println("GOT MOUSE UP ah.Button.FB =", ah.Button.FB)
|
2019-05-22 20:35:00 -05:00
|
|
|
}
|
|
|
|
if (me.Up == 1) {
|
|
|
|
log.Println("GOT MOUSE UP")
|
2019-05-29 13:07:14 -05:00
|
|
|
log.Println("GOT MOUSE UP ah.Button =", ah.Button)
|
2019-05-29 13:32:07 -05:00
|
|
|
log.Println("GOT MOUSE UP ah.Button.FB =", ah.Button.FB)
|
2019-05-29 11:54:46 -05:00
|
|
|
mouseClick(ah.Button)
|
2019-05-22 20:35:00 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-29 09:24:40 -05:00
|
|
|
func (ah AreaHandler) MouseCrossed(a *ui.Area, left bool) {
|
2019-05-22 20:35:00 -05:00
|
|
|
log.Println("GOT MouseCrossed()")
|
|
|
|
}
|
|
|
|
|
2019-05-29 09:24:40 -05:00
|
|
|
func (ah AreaHandler) DragBroken(a *ui.Area) {
|
2019-05-22 20:35:00 -05:00
|
|
|
log.Println("GOT DragBroken()")
|
|
|
|
}
|
|
|
|
|
2019-05-29 09:24:40 -05:00
|
|
|
func (ah AreaHandler) KeyEvent(a *ui.Area, ke *ui.AreaKeyEvent) (handled bool) {
|
2019-05-22 20:35:00 -05:00
|
|
|
log.Println("GOT KeyEvent()")
|
|
|
|
if (ke.Key == 10) {
|
|
|
|
log.Println("GOT ENTER")
|
|
|
|
log.Println("GOT ENTER")
|
|
|
|
log.Println("GOT ENTER")
|
|
|
|
}
|
|
|
|
if (ke.Key == 32) {
|
|
|
|
log.Println("GOT ENTER")
|
|
|
|
log.Println("GOT ENTER")
|
|
|
|
log.Println("GOT ENTER")
|
|
|
|
}
|
|
|
|
spew.Dump(ke)
|
|
|
|
// splashWin.Destroy()
|
|
|
|
// ui.Quit()
|
|
|
|
return false
|
|
|
|
}
|