summaryrefslogtreecommitdiff
path: root/area.go
blob: 225cefbfa3e36f6189df928814619b7f26e0014f (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
package gui

import "log"

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

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

var fontButton *ui.FontButton
var attrstr *ui.AttributedString
var splashArea *ui.Area

func areaClick(a int, b string) {
	log.Println("GOT areaClick(a,b) =", a, b)
}

func makeSplashArea(custom func(int, string)) *ui.Area {
	// make this button just to get the default font (but don't display the button)
	// There should be another way to do this (?)
	fontButton = CreateFontButton("SplashFont", "CLOSE", custom)

	makeAttributedString()
	splashArea = ui.NewArea(myAH)

	spew.Dump(splashArea)
	return splashArea
}

func appendWithAttributes(what string, attrs ...ui.Attribute) {
	start := len(attrstr.String())
	end := start + len(what)
	attrstr.AppendUnattributed(what)
	for _, a := range attrs {
		attrstr.SetAttribute(a, start, end)
	}
}

func makeAttributedString() {
	attrstr = ui.NewAttributedString("")

	appendWithAttributes("Welcome to the Cloud Control Panel\n", ui.TextSize(16), ui.TextColor{0.0, 0.0, 0.8, .8}) // "RGBT"

	appendWithAttributes("(alpha)\n\n", ui.TextSize(10))

	appendWithAttributes("This control panel was designed to be an interface to your 'private' cloud. ", ui.TextWeightBold)
	appendWithAttributes("The concept of a private cloud means that you can use a providers system, or, seemlessly, use your own hardware in your own datacenter. ", ui.TextWeightBold)

	attrstr.AppendUnattributed("\n")
	attrstr.AppendUnattributed("\n")
	appendWithAttributes("This control panel requires:\n")
	attrstr.AppendUnattributed("\n")
	appendWithAttributes("IPv6\n")
	appendWithAttributes("Your hostname in DNS\n")
	attrstr.AppendUnattributed("\n\n\n\n\n")

	appendWithAttributes("<click or press any key>\n", ui.TextSize(10))
}

type areaHandler struct{
	buttonFunc func(int, int)
	closeFunc func(int)
}

var myAH areaHandler

func (ah areaHandler) Draw(a *ui.Area, p *ui.AreaDrawParams) {
	tl := ui.DrawNewTextLayout(&ui.DrawTextLayoutParams{
		String:		attrstr,
		DefaultFont:	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) {
	log.Println("GOT MouseEvent()")
	spew.Dump(me)
	if (me.Down == 1) {
		log.Println("GOT MOUSE DOWN")
		log.Println("GOT MOUSE DOWN")
		log.Println("GOT MOUSE DOWN")
	}
	if (me.Up == 1) {
		log.Println("GOT MOUSE UP")
		log.Println("GOT MOUSE UP")
		log.Println("GOT MOUSE UP")
		// splashWin.Destroy()
		// ui.Quit()
	}
	areaClick(1, "done")
}

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
}