Пример #1
0
func CreateWindow(left, top, right, bottom int, isVisible bool, drawCallback DrawWindow, keyCallback HandleKey, mouseClickCallback HandleMouseClick, ref interface{}) WindowID {
	regInfo := &CreateWindowData{}
	regInfo.Left = left
	regInfo.Top = top
	regInfo.Right = right
	regInfo.Bottom = bottom
	regInfo.Visible = isVisible
	regInfo.DrawWindowFunc = drawCallback
	regInfo.HandleKeyFunc = keyCallback
	regInfo.HandleMouseClickFunc = mouseClickCallback
	regInfo.Ref = ref

	id := C.CString(goplane.IdGenerator())
	windows[id] = regInfo

	return WindowID(C.XPLMCreateWindow(
		C.int(left),
		C.int(top),
		C.int(right),
		C.int(bottom),
		C.int(goplane.FromBoolToInt(isVisible)),
		C.XPLMDrawWindow_f(unsafe.Pointer(C.drawWindowCallback)),
		C.XPLMHandleKey_f(unsafe.Pointer(C.windowHandleKey)),
		C.XPLMHandleMouseClick_f(unsafe.Pointer(C.windowHandleMouseClick)),
		unsafe.Pointer(id)))
}
Пример #2
0
func LoadObjectAsync(path string, callback ObjectLoaded, ref interface{}) {
	cPath := C.CString(path)
	defer C.free(unsafe.Pointer(cPath))
	id := C.CString(goplane.IdGenerator())
	regInfo := &objectLoadedReg{callback, ref}
	objLoadedCallbacks[id] = regInfo
	C.XPLMLoadObjectAsync(cPath, C.XPLMObjectLoaded_f(unsafe.Pointer(C.objectLoadedCallback)), unsafe.Pointer(id))
}
Пример #3
0
func RegisterHotKey(key xplm.VirtualKeyCode, flags xplm.KeyFlags, description string, callback HotKeyCallback, ref interface{}) HotKeyID {
	cDescription := C.CString(description)
	defer C.free(unsafe.Pointer(cDescription))
	cId := C.CString(goplane.IdGenerator())
	regData := &hotKeyRegData{nil, callback, ref}
	hotkeys[cId] = regData
	hotkeyId := HotKeyID(C.XPLMRegisterHotKey(C.char(key), C.XPLMKeyFlags(flags), cDescription, C.XPLMHotKey_f(unsafe.Pointer(C.handleHotKey)), unsafe.Pointer(cId)))
	regData.id = hotkeyId
	return hotkeyId
}
Пример #4
0
func CreateFlightLoop(data *CreateFlightLoopData) FlightLoopId {
	id := C.CString(goplane.IdGenerator())
	cRegData := C.XPLMCreateFlightLoop_t{}
	cRegData.structSize = C.int(unsafe.Sizeof(cRegData))
	cRegData.phase = C.XPLMFlightLoopPhaseType(data.Phase)
	cRegData.callbackFunc = C.XPLMFlightLoop_f(unsafe.Pointer(C.flightLoop))
	cRegData.refcon = unsafe.Pointer(id)
	callbacks[id] = regData{fmt.Sprint(data.Callback), data}
	flightLoopId := FlightLoopId(C.XPLMCreateFlightLoop(&cRegData))
	return flightLoopId
}
Пример #5
0
func CreateMenu(name string, parentMenu MenuID, parentItem int, handler MenuHandler, menuRef interface{}) MenuID {
	cName := C.CString(name)
	defer C.free(unsafe.Pointer(cName))

	var cHandler C.XPLMMenuHandler_f
	var internalMenuRef *C.char
	if handler != nil {
		internalMenuRef = C.CString(goplane.IdGenerator())
		cHandler = C.XPLMMenuHandler_f(unsafe.Pointer(C.menuHandler))
	}
	id := MenuID(C.XPLMCreateMenu(cName, C.XPLMMenuID(parentMenu), C.int(parentItem), cHandler, unsafe.Pointer(internalMenuRef)))
	if handler != nil {
		handlers[internalMenuRef] = &regInfo{handler, id, menuRef, make(map[*C.char]interface{})}
	}
	return id
}
Пример #6
0
func CreateWindowEx(params *CreateWindowData) WindowID {
	id := C.CString(goplane.IdGenerator())
	windows[id] = params
	cCreateWindowData := C.XPLMCreateWindow_t{}
	cCreateWindowData.structSize = C.int(unsafe.Sizeof(cCreateWindowData))
	cCreateWindowData.left = C.int(params.Left)
	cCreateWindowData.top = C.int(params.Top)
	cCreateWindowData.right = C.int(params.Right)
	cCreateWindowData.bottom = C.int(params.Bottom)
	cCreateWindowData.visible = C.int(goplane.FromBoolToInt(params.Visible))
	cCreateWindowData.drawWindowFunc = C.XPLMDrawWindow_f(unsafe.Pointer(C.drawWindowCallback))
	cCreateWindowData.handleMouseClickFunc = C.XPLMHandleMouseClick_f(unsafe.Pointer(C.windowHandleMouseClick))
	cCreateWindowData.handleKeyFunc = C.XPLMHandleKey_f(unsafe.Pointer(C.windowHandleKey))
	cCreateWindowData.handleCursorFunc = C.XPLMHandleCursor_f(unsafe.Pointer(C.windowHandleCursorStatus))
	cCreateWindowData.handleMouseWheelFunc = C.XPLMHandleMouseWheel_f(unsafe.Pointer(C.windowHandleMouseWheel))
	cCreateWindowData.refcon = unsafe.Pointer(id)
	return WindowID(C.XPLMCreateWindowEx((*C.XPLMCreateWindow_t)(unsafe.Pointer(&cCreateWindowData))))
}
Пример #7
0
func RegisterFlightLoopCallback(flightLoop FlightLoopFunc, interval float32, ref interface{}) {
	data := regData{fmt.Sprint(flightLoop), &CreateFlightLoopData{FlightLoop_Phase_BeforeFlightModel, flightLoop, ref}}
	id := C.CString(goplane.IdGenerator())
	callbacks[id] = data
	C.XPLMRegisterFlightLoopCallback(C.XPLMFlightLoop_f(unsafe.Pointer(C.flightLoop)), C.float(interval), unsafe.Pointer(id))
}
Пример #8
0
func RegisterCommandHandler(command CommandRef, callback CommandCallback, before bool, ref interface{}) {
	cId := C.CString(goplane.IdGenerator())
	callbacks[cId] = &regInfo{fmt.Sprint(callback), command, callback, ref}
	C.XPLMRegisterCommandHandler(C.XPLMCommandRef(command), C.XPLMCommandCallback_f(unsafe.Pointer(C.commandCallback)), C.int(goplane.FromBoolToInt(before)), unsafe.Pointer(cId))
}
Пример #9
0
func RegisterDrawCallback(callback DrawCallback, phase DrawingPhase, wantsBefore bool, ref interface{}) bool {
	id := C.CString(goplane.IdGenerator())
	callbacks[id] = regData{fmt.Sprint(callback), callback, ref}
	return C.XPLMRegisterDrawCallback(C.XPLMDrawCallback_f(unsafe.Pointer(C.drawCallback)), C.XPLMDrawingPhase(phase), C.int(goplane.FromBoolToInt(wantsBefore)), unsafe.Pointer(id)) == 1
}
Пример #10
0
func RegisterKeySniffer(callback KeySnifferCallback, beforeWindows bool, ref interface{}) bool {
	id := C.CString(goplane.IdGenerator())
	keySnifferCallbacks[id] = regSnifferData{fmt.Sprint(callback), callback, ref}
	return C.XPLMRegisterKeySniffer(C.XPLMKeySniffer_f(unsafe.Pointer(C.keySnifferCallback)), C.int(goplane.FromBoolToInt(beforeWindows)), unsafe.Pointer(id)) == 1
}