forked from ethereum/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
painting.go
64 lines (52 loc) · 1.08 KB
/
painting.go
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
package main
import (
"fmt"
"os"
"gopkg.in/qml.v1"
"gopkg.in/qml.v1/gl/2.0"
)
func main() {
if err := qml.Run(run); err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
}
type GoRect struct {
qml.Object
}
func (r *GoRect) Paint(p *qml.Painter) {
gl := GL.API(p)
width := float32(r.Int("width"))
height := float32(r.Int("height"))
gl.Enable(GL.BLEND)
gl.BlendFunc(GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA)
gl.Color4f(1.0, 1.0, 1.0, 0.8)
gl.Begin(GL.QUADS)
gl.Vertex2f(0, 0)
gl.Vertex2f(width, 0)
gl.Vertex2f(width, height)
gl.Vertex2f(0, height)
gl.End()
gl.LineWidth(2.5)
gl.Color4f(0.0, 0.0, 0.0, 1.0)
gl.Begin(GL.LINES)
gl.Vertex2f(0, 0)
gl.Vertex2f(width, height)
gl.Vertex2f(width, 0)
gl.Vertex2f(0, height)
gl.End()
}
func run() error {
qml.RegisterTypes("GoExtensions", 1, 0, []qml.TypeSpec{{
Init: func(r *GoRect, obj qml.Object) { r.Object = obj },
}})
engine := qml.NewEngine()
component, err := engine.LoadFile("painting.qml")
if err != nil {
return err
}
win := component.CreateWindow(nil)
win.Show()
win.Wait()
return nil
}