本文整理汇总了Golang中sdl.Event类的典型用法代码示例。如果您正苦于以下问题:Golang Event类的具体用法?Golang Event怎么用?Golang Event使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Event类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
if sdl.Init(sdl.INIT_VIDEO) != 0 {
fmt.Println(sdl.GetError())
return
}
defer sdl.Quit()
if sdl.SetVideoMode(200, 200, 32, 0) == nil {
fmt.Println(sdl.GetError())
return
}
for e := new(sdl.Event); e.Wait() && e.Type != sdl.QUIT; {
}
}
示例2: main
func main() {
flag.Parse()
var done bool
var keys []uint8
sdl.Init(sdl.INIT_VIDEO)
var screen = sdl.SetVideoMode(640, 480, 16, sdl.OPENGL|sdl.RESIZABLE)
if screen == nil {
sdl.Quit()
panic("Couldn't set 300x300 GL video mode: " + sdl.GetError() + "\n")
}
sdl.WM_SetCaption("Gears", "gears")
init_()
reshape(int(screen.W), int(screen.H))
done = false
for !done {
var event sdl.Event
idle()
for event.Poll() {
switch event.Type {
case sdl.VIDEORESIZE:
screen = sdl.SetVideoMode(int(event.Resize().W), int(event.Resize().H), 16,
sdl.OPENGL|sdl.RESIZABLE)
if screen != nil {
reshape(int(screen.W), int(screen.H))
} else {
panic("we couldn't set the new video mode??")
}
break
case sdl.QUIT:
done = true
break
}
}
keys = sdl.GetKeyState()
handleKeyPress(keys)
if keys[sdl.K_ESCAPE] != 0 {
done = true
}
draw()
}
sdl.Quit()
return
}
示例3: sdlRenderLoop
func (engine *SDLEngine) sdlRenderLoop() {
runtime.LockOSThread()
for {
var event sdl.Event
for event.Poll() {
switch event.Type {
case sdl.MOUSEMOTION:
m := event.MouseMotion()
engine.mouseEventChan <- MouseEvent{int32(m.X), int32(m.Y), int32(m.Xrel), int32(m.Yrel), int32(m.State)}
case sdl.KEYDOWN, sdl.KEYUP:
k := event.Keyboard()
engine.keyEventChan <- KeyEvent{uint32(k.Keysym.Sym), uint32(k.Type)}
case sdl.QUIT:
engine.systemEventChan <- SystemEvent{SystemQuit}
return
}
}
engine.frameEventChan <- FrameEvent{0.0}
}
runtime.UnlockOSThread()
}
示例4: main
func main() {
runtime.LockOSThread()
flag.Parse()
buildPalette()
sdl.Init(sdl.INIT_VIDEO)
defer sdl.Quit()
sdl.GL_SetAttribute(sdl.GL_SWAP_CONTROL, 1)
if sdl.SetVideoMode(512, 512, 32, sdl.OPENGL) == nil {
panic("sdl error")
}
if gl.Init() != 0 {
panic("gl error")
}
sdl.WM_SetCaption("Gomandel", "Gomandel")
gl.Enable(gl.TEXTURE_2D)
gl.Viewport(0, 0, 512, 512)
gl.MatrixMode(gl.PROJECTION)
gl.LoadIdentity()
gl.Ortho(0, 512, 512, 0, -1, 1)
gl.ClearColor(0, 0, 0, 0)
//-----------------------------------------------------------------------------
var dndDragging bool = false
var dndStart Point
var dndEnd Point
var tex gl.Texture
var tc TexCoords
var lastProgress int
initialRect := Rect{-1.5, -1.5, 3, 3}
rect := initialRect
rc := new(MandelbrotRequest)
rc.MakeRequest(512, 512, rect)
rc.WaitFor(Small, &tex, &tc)
running := true
e := new(sdl.Event)
for running {
for e.Poll() {
switch e.Type {
case sdl.QUIT:
running = false
case sdl.MOUSEBUTTONDOWN:
dndDragging = true
sdl.GetMouseState(&dndStart.X, &dndStart.Y)
dndEnd = dndStart
case sdl.MOUSEBUTTONUP:
dndDragging = false
sdl.GetMouseState(&dndEnd.X, &dndEnd.Y)
if e.MouseButton().Button == 3 {
rect = initialRect
} else {
rect = rectFromSelection(dndStart, dndEnd, 512, 512, rect)
tc = texCoordsFromSelection(dndStart, dndEnd, 512, 512, tc)
}
// make request
rc.MakeRequest(512, 512, rect)
case sdl.MOUSEMOTION:
if dndDragging {
sdl.GetMouseState(&dndEnd.X, &dndEnd.Y)
}
}
}
// if we're waiting for a result, check if it's ready
p := rc.Update(&tex, &tc)
if p != -1 {
lastProgress = p
}
gl.Clear(gl.COLOR_BUFFER_BIT)
tex.Bind(gl.TEXTURE_2D)
drawQuad(0, 0, 512, 512, tc.TX, tc.TY, tc.TX2, tc.TY2)
gl.BindTexture(gl.TEXTURE_2D, 0)
if dndDragging {
drawSelection(dndStart, dndEnd)
}
drawProgress(512, 512, lastProgress, rc.Pending)
sdl.GL_SwapBuffers()
}
}
示例5: main
func main() {
flag.Parse()
var done bool
var keys []uint8
sdl.Init(sdl.INIT_VIDEO)
var screen = sdl.SetVideoMode(300, 300, 16, sdl.OPENGL|sdl.RESIZABLE)
if screen == nil {
sdl.Quit()
panic("Couldn't set 300x300 GL video mode: " + sdl.GetError() + "\n")
}
sdl.WM_SetCaption("Gears", "gears")
init_()
reshape(int(screen.W), int(screen.H))
done = false
for !done {
var event sdl.Event
idle()
for event.Poll() {
switch event.Type {
case sdl.VIDEORESIZE:
screen = sdl.SetVideoMode(int(event.Resize().W), int(event.Resize().H), 16,
sdl.OPENGL|sdl.RESIZABLE)
if screen != nil {
reshape(int(screen.W), int(screen.H))
} else {
panic("we couldn't set the new video mode??")
}
break
case sdl.QUIT:
done = true
break
}
}
keys = sdl.GetKeyState()
if keys[sdl.K_ESCAPE] != 0 {
done = true
}
if keys[sdl.K_UP] != 0 {
view_rotx += 5.0
}
if keys[sdl.K_DOWN] != 0 {
view_rotx -= 5.0
}
if keys[sdl.K_LEFT] != 0 {
view_roty += 5.0
}
if keys[sdl.K_RIGHT] != 0 {
view_roty -= 5.0
}
if keys[sdl.K_z] != 0 {
if (sdl.GetModState() & sdl.KMOD_RSHIFT) != 0 {
view_rotz -= 5.0
} else {
view_rotz += 5.0
}
}
draw()
}
sdl.Quit()
return
}
示例6: eventLoop
func (win *window) eventLoop() {
if win.ec == nil {
win.ec = make(chan interface{})
}
eloop:
for win.events {
var ev sdl.Event
for ev.Poll() {
switch ev.Type {
case sdl.KEYUP:
key := ev.Keyboard().Keysym.Sym
win.ec <- gui.KeyEvent{int(-key)}
case sdl.KEYDOWN:
key := ev.Keyboard().Keysym.Sym
win.ec <- gui.KeyEvent{int(key)}
case sdl.MOUSEMOTION:
m := ev.MouseMotion()
win.ec <- gui.MouseEvent{
Buttons: int(m.State),
Loc: image.Pt(int(m.X), int(m.Y)),
Nsec: time.Nanoseconds(),
}
case sdl.MOUSEBUTTONUP, sdl.MOUSEBUTTONDOWN:
m := ev.MouseButton()
win.ec <- gui.MouseEvent{
Buttons: int(sdl.GetMouseState(nil, nil)),
Loc: image.Pt(int(m.X), int(m.Y)),
Nsec: time.Nanoseconds(),
}
case sdl.VIDEORESIZE:
r := ev.Resize()
win.ec <- gui.ConfigEvent{image.Config{
win.Screen().ColorModel(),
int(r.W),
int(r.H),
}}
case sdl.QUIT:
break eloop
}
}
}
close(win.ec)
}