summaryrefslogtreecommitdiff
path: root/area.go
blob: 73279aa7725b1ac950d5b8eab2424fc5fa2e9bde (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package gui

import "log"
import "time"

import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest"

import "github.com/davecgh/go-spew/spew"

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
}

func makeSplashArea(ah *AreaHandler) {
	// make this button just to get the default font (but don't display the button)
	// There should be another way to do this (?)
	newB		:= CreateFontButton("AREA")
	ah.FontButton = newB.FB

	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)
	// 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)

	Data.AllButtons[1].AH = ah

	time.Sleep(200 * time.Millisecond)
	tmp = findFB(newB)
	log.Println("makeSplashArea() tmp =", tmp, "newB", newB)

	// log.Println("makeSplashArea() ah =", ah)
	log.Println("makeSplashArea() ah.FontButton =", ah.FontButton)
	//	DefaultFont:	ah.FontButton.Font(),

	ah.Attrstr	= makeAttributedString()
	ah.Area	= ui.NewArea(ah)
	newB.A		= ah.Area
	Data.AllButtons[1].A = ah.Area
	ah.FontButton = Data.AllButtons[1].FB
	ah.Button	= &Data.AllButtons[1]

	if (Data.Debug) {
		spew.Dump(ah.Area)
		log.Println("DEBUGGING", Data.Debug)
	} else {
		log.Println("NOT DEBUGGING AREA mhAH.Button =", ah.Button)
	}
}

func appendWithAttributes(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)
	}
}

func (ah AreaHandler) Draw(a *ui.Area, p *ui.AreaDrawParams) {
	tl := ui.DrawNewTextLayout(&ui.DrawTextLayoutParams{
		String:		ah.Attrstr,
		DefaultFont:	ah.FontButton.Font(),
		Width:		p.AreaWidth,
		Align:		ui.DrawTextAlign(1),
	})
	p.Context.Text(tl, 0, 0)
	defer tl.Free()
}

func (ah AreaHandler) MouseEvent(a *ui.Area, me *ui.AreaMouseEvent) {
	if (Data.Debug) {
		log.Println("GOT MouseEvent()")
		spew.Dump(me)
	}
	if (me.Down == 1) {
		log.Println("GOT MOUSE DOWN")
	}
	if (me.Up == 1) {
		log.Println("GOT MOUSE UP")
		// log.Println("GOT MOUSE UP ah", ah)
		log.Println("GOT MOUSE UP ah.FontButton =", ah.FontButton)
		log.Println("GOT MOUSE UP ah.Button =", ah.Button)
		mouseClick(ah.Button)
	}
}

func (ah AreaHandler) MouseCrossed(a *ui.Area, left bool) {
	log.Println("GOT MouseCrossed()")
}

func (ah AreaHandler) DragBroken(a *ui.Area) {
	log.Println("GOT DragBroken()")
}

func (ah AreaHandler) KeyEvent(a *ui.Area, ke *ui.AreaKeyEvent) (handled bool) {
	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
}