當前位置: 首頁>>代碼示例>>Golang>>正文


Golang C.SDL_WaitEvent函數代碼示例

本文整理匯總了Golang中C.SDL_WaitEvent函數的典型用法代碼示例。如果您正苦於以下問題:Golang SDL_WaitEvent函數的具體用法?Golang SDL_WaitEvent怎麽用?Golang SDL_WaitEvent使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了SDL_WaitEvent函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: WaitEvent

// Waits indefinitely for the next available event
func WaitEvent() Event {
	var cev C.SDL_Event
	ret := C.SDL_WaitEvent(&cev)
	if ret == 0 {
		return nil
	}

	return goEvent((*cevent)(cast(&cev)))
}
開發者ID:gnanderson,項目名稱:Go-SDL,代碼行數:10,代碼來源:sdl.go

示例2: WaitEvent

// WaitEvent (https://wiki.libsdl.org/SDL_WaitEvent)
func WaitEvent() Event {
	var cevent CEvent
	_event := (*C.SDL_Event)(unsafe.Pointer(&cevent))
	ok := int(C.SDL_WaitEvent(_event))
	if ok == 0 {
		return nil
	}
	return goEvent(&cevent)
}
開發者ID:flazz,項目名稱:go-sdl2,代碼行數:10,代碼來源:events.go

示例3: WaitEvent

func WaitEvent(ev *Event) error {
	evLock.Lock()
	defer evLock.Unlock()

	if C.SDL_WaitEvent(evCache.c()) == 0 {
		return getError()
	}

	*ev = evCache.toGo()

	return nil
}
開發者ID:willemvds,項目名稱:sdl,代碼行數:12,代碼來源:events.go

示例4: HandleEvents

func HandleEvents() {
	for running := true; running; {
		var e C.SDL_Event
		C.SDL_WaitEvent(&e)
		switch C.eventType(&e) {
		case C.SDL_QUIT:
			inputChan <- e
			running = false
		case C.SDL_KEYDOWN, C.SDL_KEYUP, C.SDL_MOUSEBUTTONDOWN, C.SDL_MOUSEBUTTONUP, C.SDL_MOUSEWHEEL:
			inputChan <- e
		case Event_MainOpEvent:
			(<-mainOpChan)()
		case Event_DrawEvent:
			drawFunc()
			C.SDL_RenderPresent(renderer)
			drawComplete <- nil
		}
	}
}
開發者ID:gtalent,項目名稱:starfish,代碼行數:19,代碼來源:sdl.go

示例5: Wait

// Waits indefinitely for the next available event
func (event *Event) Wait() bool {
	var ret = C.SDL_WaitEvent((*C.SDL_Event)(cast(event)))
	return ret != 0
}
開發者ID:cjyar,項目名稱:Go-SDL,代碼行數:5,代碼來源:sdl.go

示例6: main


//.........這裏部分代碼省略.........
	defer decoder.Close()

	// audio
	aCodecCtx := decoder.AudioStreams[0].codec
	audioStream := setupAudioOutput(int(aCodecCtx.sample_rate), int(aCodecCtx.channels), decoder)

	// call closure in sdl thread
	callEventCode := C.SDL_RegisterEvents(1)
	callbacks := make(chan func(Env), 1024)
	call := func(f func(env Env)) {
		var event C.SDL_Event
		var userevent C.SDL_UserEvent
		userevent._type = C.SDL_USEREVENT
		userevent.code = C.Sint32(callEventCode)
		C.set_userevent(&event, userevent)
		callbacks <- f
		C.SDL_PushEvent(&event)
	}

	// show fps
	nFrames := 0
	var fpsTexture *C.SDL_Texture
	var fpsColor C.SDL_Color
	var fpsSrc, fpsDst C.SDL_Rect
	fpsColor.r = 255
	fpsColor.g = 255
	fpsColor.b = 255
	fpsColor.a = 0
	go func() {
		for _ = range time.NewTicker(time.Second * 1).C {
			call(func(env Env) {
				cText := C.CString(fmt.Sprintf("%d", nFrames))
				sur := C.TTF_RenderUTF8_Blended(font, cText, fpsColor)
				fpsSrc.w = sur.w
				fpsSrc.h = sur.h
				fpsDst.w = sur.w
				fpsDst.h = sur.h
				C.SDL_DestroyTexture(fpsTexture)
				fpsTexture = C.SDL_CreateTextureFromSurface(env.renderer, sur)
				C.SDL_FreeSurface(sur)
				C.free(unsafe.Pointer(cText))
				nFrames = 0
			})
		}
	}()

	// render
	go func() {
		for {
			frame := <-decoder.timedFrames
			nFrames++
			call(func(env Env) {
				C.SDL_UpdateYUVTexture(env.texture, nil,
					(*C.Uint8)(unsafe.Pointer(frame.data[0])), frame.linesize[0],
					(*C.Uint8)(unsafe.Pointer(frame.data[1])), frame.linesize[1],
					(*C.Uint8)(unsafe.Pointer(frame.data[2])), frame.linesize[2])
				C.SDL_RenderCopy(env.renderer, env.texture, nil, nil)
				C.SDL_RenderCopy(env.renderer, fpsTexture, &fpsSrc, &fpsDst)
				C.SDL_RenderPresent(env.renderer)
				decoder.RecycleFrame(frame)
			})
		}
	}()

	// start decode
	decoder.Start(decoder.VideoStreams[0], decoder.AudioStreams[0], width, height)
	ret := C.Pa_StartStream(audioStream)
	if ret != C.paNoError {
		fatalPAError(ret)
	}

	// main loop
	var ev C.SDL_Event
	env := Env{
		window:   window,
		renderer: renderer,
		texture:  texture,
	}
	for {
		if C.SDL_WaitEvent(&ev) == C.int(0) {
			fatalSDLError()
		}
		switch C.get_event_type(&ev) {
		case C.SDL_QUIT:
			os.Exit(0)
		case C.SDL_KEYDOWN:
			key := C.get_event_key(&ev)
			switch key.keysym.sym {
			case C.SDLK_q: // quit
				os.Exit(0)
			case C.SDLK_f: // forward
				decoder.Seek(time.Second * 60)
			}
		case C.SDL_USEREVENT:
			if C.get_userevent_code(&ev) == callEventCode {
				(<-callbacks)(env)
			}
		}
	}
}
開發者ID:reusee,項目名稱:player,代碼行數:101,代碼來源:player.go

示例7: run

func run() {
	scrollFunc := func(b bool, x, y int) {
		var e MouseWheelEvent
		e.Up = b
		e.X = x
		e.Y = y
		mouseWheelListenersLock.Lock()
		for _, v := range mouseWheelListeners {
			go v.MouseWheelScroll(e)
		}
		mouseWheelListenersLock.Unlock()
	}
	for running {
		var e C.SDL_Event
		C.SDL_WaitEvent(&e)
		switch C.eventType(&e) {
		case C.SDL_QUIT:
			go func() {
				quitListenersLock.Lock()
				for _, v := range quitListeners {
					go v.Quit()
				}
				quitListenersLock.Unlock()
			}()
			running = false
		case C.SDL_KEYDOWN:
			go func() {
				var ke KeyEvent
				ke.Key = int(C.eventKey(&e))
				keyPressListenersLock.Lock()
				for _, v := range keyPressListeners {
					go v.KeyPress(ke)
				}
				keyPressListenersLock.Unlock()
			}()
		case C.SDL_KEYUP:
			go func() {
				var ke KeyEvent
				ke.Key = int(C.eventKey(&e))
				keyReleaseListenersLock.Lock()
				for _, v := range keyReleaseListeners {
					go v.KeyRelease(ke)
				}
				keyReleaseListenersLock.Unlock()
			}()
		case C.SDL_MOUSEBUTTONDOWN:
			x := int(C.eventMouseX(&e))
			y := int(C.eventMouseY(&e))
			switch C.eventMouseButton(&e) {
			case C.SDL_BUTTON_WHEELUP:
				go scrollFunc(true, x, y)
			case C.SDL_BUTTON_WHEELDOWN:
				go scrollFunc(false, x, y)
			default:
				go func() {
					var me MouseEvent
					me.X = x
					me.Y = y
					me.Button = int(C.eventMouseButton(&e))
					mousePressListenersLock.Lock()
					for _, v := range mousePressListeners {
						go v.MouseButtonPress(me)
					}
					mousePressListenersLock.Unlock()
				}()
			}
		case C.SDL_MOUSEBUTTONUP:
			x := int(C.eventMouseX(&e))
			y := int(C.eventMouseY(&e))
			switch C.eventMouseButton(&e) {
			case C.SDL_BUTTON_WHEELUP:
				go scrollFunc(true, x, y)
			case C.SDL_BUTTON_WHEELDOWN:
				go scrollFunc(false, x, y)
			default:
				go func() {
					var me MouseEvent
					me.Button = int(C.eventMouseButton(&e))
					me.X = int(C.eventMouseX(&e))
					me.Y = int(C.eventMouseY(&e))
					mouseReleaseListenersLock.Lock()
					for _, v := range mouseReleaseListeners {
						go v.MouseButtonRelease(me)
					}
					mouseReleaseListenersLock.Unlock()
				}()
			}
		}
	}
}
開發者ID:griffy,項目名稱:starfish,代碼行數:90,代碼來源:input.go


注:本文中的C.SDL_WaitEvent函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。