mirror of
https://github.com/golang/go
synced 2024-11-21 22:14:41 -07:00
exp/4s, exp/nacl/av: sync to recent exp/draw changes.
R=rsc CC=golang-dev https://golang.org/cl/2257042
This commit is contained in:
parent
0e73fffe36
commit
58795ea31a
@ -51,7 +51,7 @@ const (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
N int
|
N int
|
||||||
display draw.Context
|
display draw.Window
|
||||||
screen draw.Image
|
screen draw.Image
|
||||||
screenr image.Rectangle
|
screenr image.Rectangle
|
||||||
board [NY][NX]byte
|
board [NY][NX]byte
|
||||||
@ -69,12 +69,12 @@ var (
|
|||||||
DY int
|
DY int
|
||||||
DMOUSE int
|
DMOUSE int
|
||||||
lastmx int
|
lastmx int
|
||||||
mouse draw.Mouse
|
mouse draw.MouseEvent
|
||||||
newscreen bool
|
newscreen bool
|
||||||
timerc <-chan int64
|
timerc <-chan int64
|
||||||
suspc chan bool
|
suspc chan bool
|
||||||
mousec chan draw.Mouse
|
mousec chan draw.MouseEvent
|
||||||
resizec <-chan bool
|
resizec chan bool
|
||||||
kbdc chan int
|
kbdc chan int
|
||||||
suspended bool
|
suspended bool
|
||||||
tsleep int
|
tsleep int
|
||||||
@ -160,7 +160,7 @@ var txpix = [NCOL]image.ColorImage{
|
|||||||
func movemouse() int {
|
func movemouse() int {
|
||||||
//mouse.image.Point = image.Pt(rboard.Min.X + rboard.Dx()/2, rboard.Min.Y + rboard.Dy()/2);
|
//mouse.image.Point = image.Pt(rboard.Min.X + rboard.Dx()/2, rboard.Min.Y + rboard.Dy()/2);
|
||||||
//moveto(mousectl, mouse.Xy);
|
//moveto(mousectl, mouse.Xy);
|
||||||
return mouse.X
|
return mouse.Loc.X
|
||||||
}
|
}
|
||||||
|
|
||||||
func warp(p image.Point, x int) int {
|
func warp(p image.Point, x int) int {
|
||||||
@ -408,7 +408,7 @@ func pause(t int) {
|
|||||||
suspend(true)
|
suspend(true)
|
||||||
} else if suspended && !s {
|
} else if suspended && !s {
|
||||||
suspend(false)
|
suspend(false)
|
||||||
lastmx = warp(mouse.Point, lastmx)
|
lastmx = warp(mouse.Loc, lastmx)
|
||||||
}
|
}
|
||||||
case <-timerc:
|
case <-timerc:
|
||||||
if suspended {
|
if suspended {
|
||||||
@ -534,17 +534,17 @@ func drop(f bool) bool {
|
|||||||
setpiece(nil)
|
setpiece(nil)
|
||||||
pause(1500)
|
pause(1500)
|
||||||
choosepiece()
|
choosepiece()
|
||||||
lastmx = warp(mouse.Point, lastmx)
|
lastmx = warp(mouse.Loc, lastmx)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func play() {
|
func play() {
|
||||||
var om draw.Mouse
|
var om draw.MouseEvent
|
||||||
dt = 64
|
dt = 64
|
||||||
lastmx = -1
|
lastmx = -1
|
||||||
lastmx = movemouse()
|
lastmx = movemouse()
|
||||||
choosepiece()
|
choosepiece()
|
||||||
lastmx = warp(mouse.Point, lastmx)
|
lastmx = warp(mouse.Loc, lastmx)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case mouse = <-mousec:
|
case mouse = <-mousec:
|
||||||
@ -553,15 +553,15 @@ func play() {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
if lastmx < 0 {
|
if lastmx < 0 {
|
||||||
lastmx = mouse.X
|
lastmx = mouse.Loc.X
|
||||||
}
|
}
|
||||||
if mouse.X > lastmx+DMOUSE {
|
if mouse.Loc.X > lastmx+DMOUSE {
|
||||||
mright()
|
mright()
|
||||||
lastmx = mouse.X
|
lastmx = mouse.Loc.X
|
||||||
}
|
}
|
||||||
if mouse.X < lastmx-DMOUSE {
|
if mouse.Loc.X < lastmx-DMOUSE {
|
||||||
mleft()
|
mleft()
|
||||||
lastmx = mouse.X
|
lastmx = mouse.Loc.X
|
||||||
}
|
}
|
||||||
if mouse.Buttons&^om.Buttons&1 == 1 {
|
if mouse.Buttons&^om.Buttons&1 == 1 {
|
||||||
rleft()
|
rleft()
|
||||||
@ -581,7 +581,7 @@ func play() {
|
|||||||
suspend(true)
|
suspend(true)
|
||||||
} else if suspended && !s {
|
} else if suspended && !s {
|
||||||
suspend(false)
|
suspend(false)
|
||||||
lastmx = warp(mouse.Point, lastmx)
|
lastmx = warp(mouse.Loc, lastmx)
|
||||||
}
|
}
|
||||||
|
|
||||||
case <-resizec:
|
case <-resizec:
|
||||||
@ -637,15 +637,12 @@ func play() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func suspproc() {
|
func suspproc() {
|
||||||
mc := display.MouseChan()
|
|
||||||
kc := display.KeyboardChan()
|
|
||||||
|
|
||||||
s := false
|
s := false
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case mouse = <-mc:
|
case mouse = <-mousec:
|
||||||
mousec <- mouse
|
mousec <- mouse
|
||||||
case r := <-kc:
|
case r := <-kbdc:
|
||||||
switch r {
|
switch r {
|
||||||
case 'q', 'Q', 0x04, 0x7F:
|
case 'q', 'Q', 0x04, 0x7F:
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
@ -716,12 +713,21 @@ func redraw(new bool) {
|
|||||||
display.FlushImage()
|
display.FlushImage()
|
||||||
}
|
}
|
||||||
|
|
||||||
func quitter(c <-chan bool) {
|
func demuxEvents(w draw.Window) {
|
||||||
<-c
|
for event := range w.EventChan() {
|
||||||
|
switch e := event.(type) {
|
||||||
|
case draw.MouseEvent:
|
||||||
|
mousec <- e
|
||||||
|
case draw.ConfigEvent:
|
||||||
|
resizec <- true
|
||||||
|
case draw.KeyEvent:
|
||||||
|
kbdc <- e.Key
|
||||||
|
}
|
||||||
|
}
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Play(pp []Piece, ctxt draw.Context) {
|
func Play(pp []Piece, ctxt draw.Window) {
|
||||||
display = ctxt
|
display = ctxt
|
||||||
screen = ctxt.Screen()
|
screen = ctxt.Screen()
|
||||||
screenr = screen.Bounds()
|
screenr = screen.Bounds()
|
||||||
@ -733,10 +739,10 @@ func Play(pp []Piece, ctxt draw.Context) {
|
|||||||
tsleep = 50
|
tsleep = 50
|
||||||
timerc = time.Tick(int64(tsleep/2) * 1e6)
|
timerc = time.Tick(int64(tsleep/2) * 1e6)
|
||||||
suspc = make(chan bool)
|
suspc = make(chan bool)
|
||||||
mousec = make(chan draw.Mouse)
|
mousec = make(chan draw.MouseEvent)
|
||||||
resizec = ctxt.ResizeChan()
|
resizec = make(chan bool)
|
||||||
kbdc = make(chan int)
|
kbdc = make(chan int)
|
||||||
go quitter(ctxt.QuitChan())
|
go demuxEvents(ctxt)
|
||||||
go suspproc()
|
go suspproc()
|
||||||
points = 0
|
points = 0
|
||||||
redraw(false)
|
redraw(false)
|
||||||
|
@ -43,26 +43,19 @@ const (
|
|||||||
type Window struct {
|
type Window struct {
|
||||||
Embedded bool // running as part of a web page?
|
Embedded bool // running as part of a web page?
|
||||||
*Image // screen image
|
*Image // screen image
|
||||||
|
eventc chan interface{}
|
||||||
mousec chan draw.Mouse
|
|
||||||
kbdc chan int
|
|
||||||
quitc chan bool
|
|
||||||
resizec chan bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// *Window implements draw.Context
|
// *Window implements draw.Window.
|
||||||
var _ draw.Context = (*Window)(nil)
|
var _ draw.Window = (*Window)(nil)
|
||||||
|
|
||||||
func (w *Window) KeyboardChan() <-chan int { return w.kbdc }
|
func (w *Window) EventChan() <-chan interface{} { return w.eventc }
|
||||||
|
|
||||||
func (w *Window) MouseChan() <-chan draw.Mouse {
|
func (w *Window) Close() os.Error {
|
||||||
return w.mousec
|
// TODO(nigeltao): implement.
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Window) QuitChan() <-chan bool { return w.quitc }
|
|
||||||
|
|
||||||
func (w *Window) ResizeChan() <-chan bool { return w.resizec }
|
|
||||||
|
|
||||||
func (w *Window) Screen() draw.Image { return w.Image }
|
func (w *Window) Screen() draw.Image { return w.Image }
|
||||||
|
|
||||||
// Init initializes the Native Client subsystems specified by subsys.
|
// Init initializes the Native Client subsystems specified by subsys.
|
||||||
@ -98,10 +91,7 @@ func Init(subsys int, dx, dy int) (*Window, os.Error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
w.Image = newImage(dx, dy, bridge.pixel)
|
w.Image = newImage(dx, dy, bridge.pixel)
|
||||||
w.resizec = make(chan bool, 64)
|
w.eventc = make(chan interface{}, 64)
|
||||||
w.kbdc = make(chan int, 64)
|
|
||||||
w.mousec = make(chan draw.Mouse, 64)
|
|
||||||
w.quitc = make(chan bool)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if subsys&SubsystemAudio != 0 {
|
if subsys&SubsystemAudio != 0 {
|
||||||
|
@ -12,6 +12,7 @@ package av
|
|||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"exp/draw"
|
"exp/draw"
|
||||||
|
"image"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
@ -398,11 +399,11 @@ func (w *Window) readEvents() {
|
|||||||
mbe *mouseButtonEvent
|
mbe *mouseButtonEvent
|
||||||
qe *quitEvent
|
qe *quitEvent
|
||||||
)
|
)
|
||||||
var m draw.Mouse
|
var m draw.MouseEvent
|
||||||
for {
|
for {
|
||||||
if err := videoPollEvent(buf); err != nil {
|
if err := videoPollEvent(buf); err != nil {
|
||||||
if !clean {
|
if !clean {
|
||||||
clean = w.resizec <- false
|
clean = w.eventc <- draw.ConfigEvent{image.Config{ColorModel, w.Image.Bounds().Dx(), w.Image.Bounds().Dy()}}
|
||||||
}
|
}
|
||||||
time.Sleep(10e6) // 10ms
|
time.Sleep(10e6) // 10ms
|
||||||
continue
|
continue
|
||||||
@ -440,33 +441,33 @@ func (w *Window) readEvents() {
|
|||||||
// log.Stdoutf("%#v\n", e);
|
// log.Stdoutf("%#v\n", e);
|
||||||
switch buf[0] {
|
switch buf[0] {
|
||||||
case eventExpose:
|
case eventExpose:
|
||||||
w.resizec <- true
|
w.eventc <- draw.ConfigEvent{image.Config{ColorModel, w.Image.Bounds().Dx(), w.Image.Bounds().Dy()}}
|
||||||
case eventKeyDown:
|
case eventKeyDown:
|
||||||
w.kbdc <- int(ke.Key)
|
w.eventc <- draw.KeyEvent{int(ke.Key)}
|
||||||
case eventKeyUp:
|
case eventKeyUp:
|
||||||
w.kbdc <- -int(ke.Key)
|
w.eventc <- draw.KeyEvent{-int(ke.Key)}
|
||||||
case eventMouseMotion:
|
case eventMouseMotion:
|
||||||
m.X = int(mme.X)
|
m.Loc.X = int(mme.X)
|
||||||
m.Y = int(mme.Y)
|
m.Loc.Y = int(mme.Y)
|
||||||
m.Buttons = int(mme.Buttons)
|
m.Buttons = int(mme.Buttons)
|
||||||
m.Nsec = time.Nanoseconds()
|
m.Nsec = time.Nanoseconds()
|
||||||
_ = w.mousec <- m
|
_ = w.eventc <- m
|
||||||
case eventMouseButtonDown:
|
case eventMouseButtonDown:
|
||||||
m.X = int(mbe.X)
|
m.Loc.X = int(mbe.X)
|
||||||
m.Y = int(mbe.Y)
|
m.Loc.Y = int(mbe.Y)
|
||||||
// TODO(rsc): Remove uint cast once 8g bug is fixed.
|
// TODO(rsc): Remove uint cast once 8g bug is fixed.
|
||||||
m.Buttons |= 1 << uint(mbe.Button-1)
|
m.Buttons |= 1 << uint(mbe.Button-1)
|
||||||
m.Nsec = time.Nanoseconds()
|
m.Nsec = time.Nanoseconds()
|
||||||
_ = w.mousec <- m
|
_ = w.eventc <- m
|
||||||
case eventMouseButtonUp:
|
case eventMouseButtonUp:
|
||||||
m.X = int(mbe.X)
|
m.Loc.X = int(mbe.X)
|
||||||
m.Y = int(mbe.Y)
|
m.Loc.Y = int(mbe.Y)
|
||||||
// TODO(rsc): Remove uint cast once 8g bug is fixed.
|
// TODO(rsc): Remove uint cast once 8g bug is fixed.
|
||||||
m.Buttons &^= 1 << uint(mbe.Button-1)
|
m.Buttons &^= 1 << uint(mbe.Button-1)
|
||||||
m.Nsec = time.Nanoseconds()
|
m.Nsec = time.Nanoseconds()
|
||||||
_ = w.mousec <- m
|
_ = w.eventc <- m
|
||||||
case eventQuit:
|
case eventQuit:
|
||||||
w.quitc <- true
|
close(w.eventc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user