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


Golang C.SDL_Rect類代碼示例

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


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

示例1: DrawImage

//Draws the image at the given coordinates.
func (me *Canvas) DrawImage(img *Image, x, y int) {
	C.SDL_SetAlpha(img.img, C.SDL_SRCALPHA, 255)
	var dest C.SDL_Rect
	dest.x = C.Sint16(x + me.origin.X)
	dest.y = C.Sint16(y + me.origin.Y)
	C.SDL_BlitSurface(img.img, nil, me.pane, &dest)
}
開發者ID:griffy,項目名稱:starfish,代碼行數:8,代碼來源:canvas.go

示例2: sdl_Rect

func sdl_Rect(x, y, width, height int) C.SDL_Rect {
	var r C.SDL_Rect
	r.x = C.int(x)
	r.y = C.int(y)
	r.w = C.int(width)
	r.h = C.int(height)
	return r
}
開發者ID:gtalent,項目名稱:starfish,代碼行數:8,代碼來源:sdl.go

示例3: toSDL_Rect

func toSDL_Rect(b util.Bounds) C.SDL_Rect {
	var r C.SDL_Rect
	r.x = C.Sint16(b.X)
	r.y = C.Sint16(b.Y)
	r.w = C.Uint16(b.Width)
	r.h = C.Uint16(b.Height)
	return r
}
開發者ID:griffy,項目名稱:starfish,代碼行數:8,代碼來源:misc.go

示例4: FillRect

func FillRect(x, y, w, h int, c Color) {
	var rect C.SDL_Rect
	rect.x = C.int(x)
	rect.y = C.int(y)
	rect.w = C.int(w)
	rect.h = C.int(h)
	C.SDL_SetRenderDrawColor(renderer, C.Uint8(c.Red), C.Uint8(c.Green), C.Uint8(c.Blue), C.Uint8(c.Alpha))
	C.SDL_RenderFillRect(renderer, &rect)
}
開發者ID:gtalent,項目名稱:starfish,代碼行數:9,代碼來源:sdl.go

示例5: Blit

// Blit performs a fast blit from the source surface to the destination surface.
//
// srcRect represents the rectangle to be copied or image.ZR to copy the entire
// surface.
//
// dstPoint represents the destination position.
func (src *Surface) Blit(srcRect image.Rectangle, dst *Surface, dstPoint image.Point) (err error) {
	cSrcRect := cRect(srcRect)
	cDstRect := new(C.SDL_Rect)
	cDstRect.x = C.int(dstPoint.X)
	cDstRect.y = C.int(dstPoint.Y)
	if C.SDL_BlitSurface(src.cSurface, cSrcRect, dst.cSurface, cDstRect) != 0 {
		return getError()
	}
	return nil
}
開發者ID:salihdb,項目名稱:sdl,代碼行數:16,代碼來源:surface.go

示例6: DrawImage

//Draws the image at the given coordinates.
func DrawImage(img *Image, destX, destY, srcX, srcY, srcW, srcH int) {
	var src, dest C.SDL_Rect
	dest.x = C.int(destX)
	dest.y = C.int(destY)
	dest.w = C.int(img.Width)
	dest.h = C.int(img.Height)

	src.x = C.int(srcX)
	src.y = C.int(srcY)
	src.w = C.int(srcW)
	src.h = C.int(srcH)
	C.SDL_SetTextureAlphaMod(img.surface, 255)
	C.SDL_RenderCopy(renderer, img.surface, &src, &dest)
}
開發者ID:gtalent,項目名稱:starfish,代碼行數:15,代碼來源:sdl.go

示例7: main

func main() {
	runtime.GOMAXPROCS(32)

	// sdl
	C.SDL_Init(C.SDL_INIT_AUDIO | C.SDL_INIT_VIDEO | C.SDL_INIT_TIMER)
	defer C.SDL_Quit()
	runtime.LockOSThread()
	window := C.SDL_CreateWindow(C.CString("play"), 0, 0, 1680, 1050,
		C.SDL_WINDOW_BORDERLESS|C.SDL_WINDOW_RESIZABLE|C.SDL_WINDOW_MAXIMIZED|C.SDL_WINDOW_OPENGL)
	if window == nil {
		fatalSDLError()
	}
	defer C.SDL_DestroyWindow(window)
	C.SDL_DisableScreenSaver()
	renderer := C.SDL_CreateRenderer(window, -1, C.SDL_RENDERER_ACCELERATED)
	if renderer == nil {
		fatalSDLError()
	}
	defer C.SDL_DestroyRenderer(renderer)
	var width, height C.int
	C.SDL_GetWindowSize(window, &width, &height)
	texture := C.SDL_CreateTexture(renderer,
		C.SDL_PIXELFORMAT_YV12,
		C.SDL_TEXTUREACCESS_STREAMING,
		width, height)
	if texture == nil {
		fatalSDLError()
	}
	defer C.SDL_DestroyTexture(texture)

	// sdl ttf
	if C.TTF_Init() == C.int(-1) {
		log.Fatal("sdl ttf init failed")
	}
	defer C.TTF_Quit()
	font := C.TTF_OpenFont(C.CString("/home/reus/font.ttf"), 32)
	if font == nil {
		fatalTTFError()
	}
	defer C.TTF_CloseFont(font)

	// open decoder
	decoder, err := NewDecoder(os.Args[1])
	if err != nil {
		log.Fatal(err)
	}
	if len(decoder.AudioStreams) == 0 || len(decoder.VideoStreams) == 0 {
		log.Fatal("no video or audio")
	}
	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++
//.........這裏部分代碼省略.........
開發者ID:reusee,項目名稱:player,代碼行數:101,代碼來源:player.go

示例8: DrawText

//Draws the text at the given coordinates.
func (me *Canvas) DrawText(text *Text, x, y int) {
	var dest C.SDL_Rect
	dest.x = C.Sint16(x + me.origin.X)
	dest.y = C.Sint16(y + me.origin.Y)
	C.SDL_BlitSurface(text.text, nil, me.pane, &dest)
}
開發者ID:griffy,項目名稱:starfish,代碼行數:7,代碼來源:canvas.go


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