2019-05-22 20:35:00 -05:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import "log"
|
|
|
|
|
|
|
|
import "github.com/andlabs/ui"
|
|
|
|
import _ "github.com/andlabs/ui/winmanifest"
|
|
|
|
|
|
|
|
import "github.com/davecgh/go-spew/spew"
|
|
|
|
|
2019-06-01 00:28:02 -05:00
|
|
|
// THIS IS CLEAN
|
2019-05-29 11:54:46 -05:00
|
|
|
|
2019-05-31 19:37:53 -05:00
|
|
|
func makeSplashArea(gb *GuiBox, newText *ui.AttributedString) {
|
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-31 19:37:53 -05:00
|
|
|
var newB *GuiButton
|
2019-06-01 00:28:02 -05:00
|
|
|
newB = CreateFontButton(gb, "AREA")
|
|
|
|
newB.Box = gb
|
|
|
|
newB.GW = gb.W
|
2019-05-31 19:37:53 -05:00
|
|
|
|
|
|
|
// initialize the GuiArea{}
|
2019-06-01 00:28:02 -05:00
|
|
|
gb.Area = new(GuiArea)
|
|
|
|
gb.Area.Button = newB
|
|
|
|
gb.Area.Box = gb
|
|
|
|
gb.Area.UiAttrstr = newText
|
|
|
|
gb.Area.UiArea = ui.NewArea(gb.Area)
|
2019-05-22 20:35:00 -05:00
|
|
|
|
2019-05-23 15:13:42 -05:00
|
|
|
if (Data.Debug) {
|
2019-05-31 19:37:53 -05:00
|
|
|
spew.Dump(gb.Area.UiArea)
|
2019-05-23 15:13:42 -05:00
|
|
|
log.Println("DEBUGGING", Data.Debug)
|
|
|
|
} else {
|
2019-05-31 19:37:53 -05:00
|
|
|
log.Println("NOT DEBUGGING AREA mhAH.Button =", gb.Area.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-30 11:19:49 -05:00
|
|
|
func (ah GuiArea) Draw(a *ui.Area, p *ui.AreaDrawParams) {
|
2019-05-22 20:35:00 -05:00
|
|
|
tl := ui.DrawNewTextLayout(&ui.DrawTextLayoutParams{
|
2019-05-30 11:58:05 -05:00
|
|
|
String: ah.UiAttrstr,
|
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-30 11:19:49 -05:00
|
|
|
func (ah GuiArea) 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-30 11:19:49 -05:00
|
|
|
func (ah GuiArea) MouseCrossed(a *ui.Area, left bool) {
|
2019-05-22 20:35:00 -05:00
|
|
|
log.Println("GOT MouseCrossed()")
|
|
|
|
}
|
|
|
|
|
2019-05-30 11:19:49 -05:00
|
|
|
func (ah GuiArea) DragBroken(a *ui.Area) {
|
2019-05-22 20:35:00 -05:00
|
|
|
log.Println("GOT DragBroken()")
|
|
|
|
}
|
|
|
|
|
2019-06-01 00:28:02 -05:00
|
|
|
// TODO: fix KeyEvents
|
2019-05-30 11:19:49 -05:00
|
|
|
func (ah GuiArea) 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
|
|
|
|
}
|