示例#1
0
func (q *QmlDebugDrawer) StartUp(config types.JGameObject) {
	defer debug.Trace().UnTrace()

	qml.RegisterTypes("SqclDebugDrawExtensions", 1, 0, []qml.TypeSpec{{
		Init: func(r *GoBox, obj qml.Object) {
			r.Object = obj
		},
	}})

	cfg := config.Comp("graphics.Config").(*Config)
	file := `
import QtQuick 2.0
import SqclDebugDrawExtensions 1.0

Item {
    property var box : Component {
        Rectangle {
            opacity: 0.5;
            width: 100; height: 100;
            border.width:5;
            border.color:"blue";
        }
    }
}
    `
	component, err := cfg.Engine.LoadString("file.qml", strings.TrimSpace(file))
	if err != nil {
		panic(err)
	}
	q.Comp = component.Create(nil)
	q.engine = cfg.Engine
	q.window = cfg.Window
}
示例#2
0
func (q *QmlDebugDrawer) AddLine(goc types.JGameObject, x1, y1, x2, y2 int) {
	defer debug.Trace().UnTrace()

	if q.Object == nil {
		q.Object = &GoBox{x1: x1, y1: y1, x2: x2, y2: y2}
		q.Object.Init()
		q.goc = goc

		input := core.Core.Manager("QmlInputMngr").(types.JManager)
		// TODO: how to unregister specific message?
		// tracker := goc.Register("collision", input, func(e event.Data) {
		goc.Register("collision", input, func(e event.Data) {
			border := q.Object.Property("border").(qml.Object)
			red := color.RGBA{255, 0, 0, 255}
			if border.Color("color") == red {
				border.Set("color", "blue")
			} else {
				border.Set("color", "red")
			}
		})
		// goc.Unregister(tracker)
		// tracker.Unlink()
	} else {
		q.Object.Deinit()
		q.Object = nil
	}
}
示例#3
0
func (q *QmlGrfxMngr) StartUp(config types.JGameObject) {
	defer debug.Trace().UnTrace()

	types := []qml.TypeSpec{
		{
			Init: func(r *GoQmlRect, obj qml.Object) {
				defer debug.Trace().UnTrace()
				r.Object = obj
			},
		},
	}
	qml.RegisterTypes("GoExtensions", 1, 0, types)

	cfg := config.Comp("graphics.Config").(*Config)
	q.engine = cfg.Engine
	q.window = cfg.Window
	q.window.Set("width", cfg.W)
	q.window.Set("height", cfg.H)
}