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
Hide 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 (
var
(
N
int
display
draw
.
Context
display
draw
.
Window
screen
draw
.
Image
screenr
image
.
Rectangle
board
[
NY
][
NX
]
byte
...
...
@@ -69,12 +69,12 @@ var (
DY
int
DMOUSE
int
lastmx
int
mouse
draw
.
Mouse
mouse
draw
.
Mouse
Event
newscreen
bool
timerc
<-
chan
int64
suspc
chan
bool
mousec
chan
draw
.
Mouse
resizec
<-
chan
bool
mousec
chan
draw
.
Mouse
Event
resizec
chan
bool
kbdc
chan
int
suspended
bool
tsleep
int
...
...
@@ -160,7 +160,7 @@ var txpix = [NCOL]image.ColorImage{
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
.
X
return
mouse
.
Loc
.
X
}
func
warp
(
p
image
.
Point
,
x
int
)
int
{
...
...
@@ -408,7 +408,7 @@ func pause(t int) {
suspend
(
true
)
}
else
if
suspended
&&
!
s
{
suspend
(
false
)
lastmx
=
warp
(
mouse
.
Point
,
lastmx
)
lastmx
=
warp
(
mouse
.
Loc
,
lastmx
)
}
case
<-
timerc
:
if
suspended
{
...
...
@@ -534,17 +534,17 @@ func drop(f bool) bool {
setpiece
(
nil
)
pause
(
1500
)
choosepiece
()
lastmx
=
warp
(
mouse
.
Point
,
lastmx
)
lastmx
=
warp
(
mouse
.
Loc
,
lastmx
)
return
false
}
func
play
()
{
var
om
draw
.
Mouse
var
om
draw
.
Mouse
Event
dt
=
64
lastmx
=
-
1
lastmx
=
movemouse
()
choosepiece
()
lastmx
=
warp
(
mouse
.
Point
,
lastmx
)
lastmx
=
warp
(
mouse
.
Loc
,
lastmx
)
for
{
select
{
case
mouse
=
<-
mousec
:
...
...
@@ -553,15 +553,15 @@ func play() {
break
}
if
lastmx
<
0
{
lastmx
=
mouse
.
X
lastmx
=
mouse
.
Loc
.
X
}
if
mouse
.
X
>
lastmx
+
DMOUSE
{
if
mouse
.
Loc
.
X
>
lastmx
+
DMOUSE
{
mright
()
lastmx
=
mouse
.
X
lastmx
=
mouse
.
Loc
.
X
}
if
mouse
.
X
<
lastmx
-
DMOUSE
{
if
mouse
.
Loc
.
X
<
lastmx
-
DMOUSE
{
mleft
()
lastmx
=
mouse
.
X
lastmx
=
mouse
.
Loc
.
X
}
if
mouse
.
Buttons
&^
om
.
Buttons
&
1
==
1
{
rleft
()
...
...
@@ -581,7 +581,7 @@ func play() {
suspend
(
true
)
}
else
if
suspended
&&
!
s
{
suspend
(
false
)
lastmx
=
warp
(
mouse
.
Point
,
lastmx
)
lastmx
=
warp
(
mouse
.
Loc
,
lastmx
)
}
case
<-
resizec
:
...
...
@@ -637,15 +637,12 @@ func play() {
}
func
suspproc
()
{
mc
:=
display
.
MouseChan
()
kc
:=
display
.
KeyboardChan
()
s
:=
false
for
{
select
{
case
mouse
=
<-
mc
:
case
mouse
=
<-
m
ouse
c
:
mousec
<-
mouse
case
r
:=
<-
kc
:
case
r
:=
<-
k
bd
c
:
switch
r
{
case
'q'
,
'Q'
,
0x04
,
0x7F
:
os
.
Exit
(
0
)
...
...
@@ -716,12 +713,21 @@ func redraw(new bool) {
display
.
FlushImage
()
}
func
quitter
(
c
<-
chan
bool
)
{
<-
c
func
demuxEvents
(
w
draw
.
Window
)
{
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
)
}
func
Play
(
pp
[]
Piece
,
ctxt
draw
.
Context
)
{
func
Play
(
pp
[]
Piece
,
ctxt
draw
.
Window
)
{
display
=
ctxt
screen
=
ctxt
.
Screen
()
screenr
=
screen
.
Bounds
()
...
...
@@ -733,10 +739,10 @@ func Play(pp []Piece, ctxt draw.Context) {
tsleep
=
50
timerc
=
time
.
Tick
(
int64
(
tsleep
/
2
)
*
1e6
)
suspc
=
make
(
chan
bool
)
mousec
=
make
(
chan
draw
.
Mouse
)
resizec
=
ctxt
.
ResizeChan
(
)
mousec
=
make
(
chan
draw
.
Mouse
Event
)
resizec
=
make
(
chan
bool
)
kbdc
=
make
(
chan
int
)
go
quitter
(
ctxt
.
QuitChan
()
)
go
demuxEvents
(
ctxt
)
go
suspproc
()
points
=
0
redraw
(
false
)
...
...
src/pkg/exp/nacl/av/av.go
View file @
58795ea3
...
...
@@ -43,26 +43,19 @@ const (
type
Window
struct
{
Embedded
bool
// running as part of a web page?
*
Image
// screen image
mousec
chan
draw
.
Mouse
kbdc
chan
int
quitc
chan
bool
resizec
chan
bool
eventc
chan
interface
{}
}
// *Window implements draw.
Context
var
_
draw
.
Context
=
(
*
Window
)(
nil
)
// *Window implements draw.
Window.
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
{
return
w
.
mousec
func
(
w
*
Window
)
Close
()
os
.
Error
{
// 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
}
// 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
}
w
.
Image
=
newImage
(
dx
,
dy
,
bridge
.
pixel
)
w
.
resizec
=
make
(
chan
bool
,
64
)
w
.
kbdc
=
make
(
chan
int
,
64
)
w
.
mousec
=
make
(
chan
draw
.
Mouse
,
64
)
w
.
quitc
=
make
(
chan
bool
)
w
.
eventc
=
make
(
chan
interface
{},
64
)
}
if
subsys
&
SubsystemAudio
!=
0
{
...
...
src/pkg/exp/nacl/av/event.go
View file @
58795ea3
...
...
@@ -12,6 +12,7 @@ package av
import
(
"encoding/binary"
"exp/draw"
"image"
"log"
"os"
"time"
...
...
@@ -398,11 +399,11 @@ func (w *Window) readEvents() {
mbe
*
mouseButtonEvent
qe
*
quitEvent
)
var
m
draw
.
Mouse
var
m
draw
.
Mouse
Event
for
{
if
err
:=
videoPollEvent
(
buf
);
err
!=
nil
{
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
continue
...
...
@@ -440,33 +441,33 @@ func (w *Window) readEvents() {
// log.Stdoutf("%#v\n", e);
switch
buf
[
0
]
{
case
eventExpose
:
w
.
resizec
<-
true
w
.
eventc
<-
draw
.
ConfigEvent
{
image
.
Config
{
ColorModel
,
w
.
Image
.
Bounds
()
.
Dx
(),
w
.
Image
.
Bounds
()
.
Dy
()}}
case
eventKeyDown
:
w
.
kbdc
<-
int
(
ke
.
Key
)
w
.
eventc
<-
draw
.
KeyEvent
{
int
(
ke
.
Key
)}
case
eventKeyUp
:
w
.
kbdc
<-
-
int
(
ke
.
Key
)
w
.
eventc
<-
draw
.
KeyEvent
{
-
int
(
ke
.
Key
)}
case
eventMouseMotion
:
m
.
X
=
int
(
mme
.
X
)
m
.
Y
=
int
(
mme
.
Y
)
m
.
Loc
.
X
=
int
(
mme
.
X
)
m
.
Loc
.
Y
=
int
(
mme
.
Y
)
m
.
Buttons
=
int
(
mme
.
Buttons
)
m
.
Nsec
=
time
.
Nanoseconds
()
_
=
w
.
mouse
c
<-
m
_
=
w
.
event
c
<-
m
case
eventMouseButtonDown
:
m
.
X
=
int
(
mbe
.
X
)
m
.
Y
=
int
(
mbe
.
Y
)
m
.
Loc
.
X
=
int
(
mbe
.
X
)
m
.
Loc
.
Y
=
int
(
mbe
.
Y
)
// TODO(rsc): Remove uint cast once 8g bug is fixed.
m
.
Buttons
|=
1
<<
uint
(
mbe
.
Button
-
1
)
m
.
Nsec
=
time
.
Nanoseconds
()
_
=
w
.
mouse
c
<-
m
_
=
w
.
event
c
<-
m
case
eventMouseButtonUp
:
m
.
X
=
int
(
mbe
.
X
)
m
.
Y
=
int
(
mbe
.
Y
)
m
.
Loc
.
X
=
int
(
mbe
.
X
)
m
.
Loc
.
Y
=
int
(
mbe
.
Y
)
// TODO(rsc): Remove uint cast once 8g bug is fixed.
m
.
Buttons
&^=
1
<<
uint
(
mbe
.
Button
-
1
)
m
.
Nsec
=
time
.
Nanoseconds
()
_
=
w
.
mouse
c
<-
m
_
=
w
.
event
c
<-
m
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