func main() { win, err := sdlgui.NewWindow(320, 240, 32, sdl.DOUBLEBUF|sdl.RESIZABLE) if err != nil { fmt.Println(err) os.Exit(1) } screen := win.Screen() cimg := image.NewColorImage(image.RGBAColor{255, 0, 255, 255}) draw.Draw(screen, image.Rect(10, 10, 200, 200), cimg, image.ZP, draw.Over, ) timg := sdl.Load("test.png") draw.Draw(screen, image.Rect(50, 50, 100, 100), timg, image.ZP, draw.Over, ) win.FlushImage() for ev := range win.EventChan() { switch e := ev.(type) { case gui.ConfigEvent: fmt.Printf("Window size: (%v, %v)\n", e.Config.Width, e.Config.Height) case gui.KeyEvent: fmt.Printf("Key pressed: %v\n", e.Key) if e.Key == sdl.K_ESCAPE { win.Close() } case gui.MouseEvent: if e.Buttons&(1<<0) > 0 { fmt.Println("The left mouse button has been pressed.") } if e.Buttons&(1<<1) > 0 { fmt.Println("The middle mouse button has been pressed.") } if e.Buttons&(1<<2) > 0 { fmt.Println("The right mouse button has been pressed.") } } } }
func Play(pp []Piece, ctxt draw.Window) { display = ctxt screen = ctxt.Screen() screenr = screen.Bounds() pieces = pp N = len(pieces[0].d) initPieces() rand.Seed(int64(time.Nanoseconds() % (1e9 - 1))) whitemask = image.NewColorImage(image.AlphaColor{0x7F}) tsleep = 50 timerc = time.Tick(int64(tsleep/2) * 1e6) suspc = make(chan bool) mousec = make(chan draw.MouseEvent) resizec = make(chan bool) kbdc = make(chan int) go demuxEvents(ctxt) go suspproc() points = 0 redraw(false) play() }
func fillAlpha(alpha int) image.Image { return image.NewColorImage(image.AlphaColor{uint8(alpha)}) }
func fillBlue(alpha int) image.Image { return image.NewColorImage(image.RGBAColor{0, 0, uint8(alpha), uint8(alpha)}) }
0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, }, {0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, }, {0xCC, 0xCC, 0xCC, 0xCC, 0x33, 0x33, 0x33, 0x33, 0xCC, 0xCC, 0xCC, 0xCC, 0x33, 0x33, 0x33, 0x33, 0xCC, 0xCC, 0xCC, 0xCC, 0x33, 0x33, 0x33, 0x33, 0xCC, 0xCC, 0xCC, 0xCC, 0x33, 0x33, 0x33, 0x33, }, } var txpix = [NCOL]image.Image{ image.NewColorImage(image.RGBAColor{0xFF, 0xFF, 0x00, 0xFF}), /* yellow */ image.NewColorImage(image.RGBAColor{0x00, 0xFF, 0xFF, 0xFF}), /* cyan */ image.NewColorImage(image.RGBAColor{0x00, 0xFF, 0x00, 0xFF}), /* lime green */ image.NewColorImage(image.RGBAColor{0x00, 0x5D, 0xBB, 0xFF}), /* slate */ image.NewColorImage(image.RGBAColor{0xFF, 0x00, 0x00, 0xFF}), /* red */ image.NewColorImage(image.RGBAColor{0x55, 0xAA, 0xAA, 0xFF}), /* olive green */ image.NewColorImage(image.RGBAColor{0x00, 0x00, 0xFF, 0xFF}), /* blue */ image.NewColorImage(image.RGBAColor{0xFF, 0x55, 0xAA, 0xFF}), /* pink */ image.NewColorImage(image.RGBAColor{0xFF, 0xAA, 0xFF, 0xFF}), /* lavender */ image.NewColorImage(image.RGBAColor{0xBB, 0x00, 0x5D, 0xFF}), /* maroon */ } func movemouse() int { //mouse.image.Point = image.Pt(rboard.Min.X + rboard.Dx()/2, rboard.Min.Y + rboard.Dy()/2); //moveto(mousectl, mouse.Xy); return mouse.Loc.X