Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
58795ea3
Commit
58795ea3
authored
Sep 22, 2010
by
Nigel Tao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
exp/4s, exp/nacl/av: sync to recent exp/draw changes.
R=rsc CC=golang-dev
https://golang.org/cl/2257042
parent
0e73fffe
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
59 deletions
+56
-59
src/pkg/exp/4s/xs.go
src/pkg/exp/4s/xs.go
+32
-26
src/pkg/exp/nacl/av/av.go
src/pkg/exp/nacl/av/av.go
+8
-18
src/pkg/exp/nacl/av/event.go
src/pkg/exp/nacl/av/event.go
+16
-15
No files found.
src/pkg/exp/4s/xs.go
View file @
58795ea3
...
@@ -51,7 +51,7 @@ const (
...
@@ -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 (
...
@@ -69,12 +69,12 @@ var (
DY
int
DY
int
DMOUSE
int
DMOUSE
int
lastmx
int
lastmx
int
mouse
draw
.
Mouse
mouse
draw
.
Mouse
Event
newscreen
bool
newscreen
bool
timerc
<-
chan
int64
timerc
<-
chan
int64
suspc
chan
bool
suspc
chan
bool
mousec
chan
draw
.
Mouse
mousec
chan
draw
.
Mouse
Event
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{
...
@@ -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) {
...
@@ -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 {
...
@@ -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
.
Mouse
Event
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() {
...
@@ -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() {
...
@@ -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() {
...
@@ -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
=
<-
m
ouse
c
:
mousec
<-
mouse
mousec
<-
mouse
case
r
:=
<-
kc
:
case
r
:=
<-
k
bd
c
:
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) {
...
@@ -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) {
...
@@ -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
.
Mouse
Event
)
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
)
...
...
src/pkg/exp/nacl/av/av.go
View file @
58795ea3
...
@@ -43,26 +43,19 @@ const (
...
@@ -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
.
kbd
c
}
func
(
w
*
Window
)
EventChan
()
<-
chan
interface
{}
{
return
w
.
event
c
}
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) {
...
@@ -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
{
...
...
src/pkg/exp/nacl/av/event.go
View file @
58795ea3
...
@@ -12,6 +12,7 @@ package av
...
@@ -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() {
...
@@ -398,11 +399,11 @@ func (w *Window) readEvents() {
mbe
*
mouseButtonEvent
mbe
*
mouseButtonEvent
qe
*
quitEvent
qe
*
quitEvent
)
)
var
m
draw
.
Mouse
var
m
draw
.
Mouse
Event
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() {
...
@@ -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
.
mouse
c
<-
m
_
=
w
.
event
c
<-
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
.
mouse
c
<-
m
_
=
w
.
event
c
<-
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
.
mouse
c
<-
m
_
=
w
.
event
c
<-
m
case
eventQuit
:
case
eventQuit
:
w
.
quitc
<-
true
close
(
w
.
eventc
)
}
}
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment