2019-05-22 20:35:00 -05:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import "log"
|
2019-05-29 11:54:46 -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 {
|
|
|
|
log.Println("defaultButtonClick() Data.AllButtons =", key, foo)
|
|
|
|
// if Data.AllButtons[key] == *button {
|
|
|
|
if &foo == button {
|
|
|
|
a = &foo
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return a
|
|
|
|
}
|
|
|
|
|
2019-05-29 09:24:40 -05:00
|
|
|
func makeSplashArea() *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-29 11:54:46 -05:00
|
|
|
newB := CreateFontButton("AREA")
|
2019-05-22 20:35:00 -05:00
|
|
|
|
2019-05-29 11:54:46 -05:00
|
|
|
time.Sleep(200 * time.Millisecond)
|
|
|
|
tmp := findFB(newB)
|
|
|
|
log.Println("makeSplashArea() newB =", newB)
|
|
|
|
log.Println("makeSplashArea() newB.AH =", newB.AH)
|
|
|
|
log.Println("makeSplashArea() newB =", newB)
|
|
|
|
newB.AH = &myAH
|
|
|
|
// log.Println("makeSplashArea() newB.AH =", newB.AH)
|
|
|
|
log.Println("makeSplashArea() newB =", newB)
|
|
|
|
|
|
|
|
time.Sleep(200 * time.Millisecond)
|
|
|
|
tmp = findFB(newB)
|
|
|
|
log.Println("makeSplashArea() tmp =", tmp, "newB", newB)
|
2019-05-26 00:07:37 -05:00
|
|
|
|
2019-05-29 11:54:46 -05:00
|
|
|
myAH.Attrstr = makeAttributedString()
|
|
|
|
myAH.Area = ui.NewArea(myAH)
|
|
|
|
newB.A = myAH.Area
|
|
|
|
myAH.FontButton = newB.FB
|
|
|
|
myAH.Button = newB
|
2019-05-22 20:35:00 -05:00
|
|
|
|
2019-05-23 15:13:42 -05:00
|
|
|
if (Data.Debug) {
|
2019-05-29 11:54:46 -05:00
|
|
|
spew.Dump(myAH.Area)
|
2019-05-23 15:13:42 -05:00
|
|
|
log.Println("DEBUGGING", Data.Debug)
|
|
|
|
} else {
|
2019-05-29 09:24:40 -05:00
|
|
|
log.Println("NOT DEBUGGING AREA mhAH.Button =", myAH.Button)
|
2019-05-23 15:13:42 -05:00
|
|
|
}
|
2019-05-29 09:24:40 -05:00
|
|
|
return &myAH
|
2019-05-22 20:35:00 -05:00
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
DefaultFont: ah.FontButton.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-24 03:51:37 -05:00
|
|
|
log.Println("GOT MouseEvent()")
|
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")
|
|
|
|
}
|
|
|
|
if (me.Up == 1) {
|
|
|
|
log.Println("GOT MOUSE UP")
|
|
|
|
log.Println("GOT MOUSE UP")
|
|
|
|
log.Println("GOT MOUSE UP")
|
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
|
|
|
|
}
|