Commit b47a38de authored by Nigel Tao's avatar Nigel Tao

image/draw: move exp/draw to image/draw and exp/gui.

R=r
CC=golang-dev
https://golang.org/cl/4515191
parent c2cea441
...@@ -77,9 +77,9 @@ DIRS=\ ...@@ -77,9 +77,9 @@ DIRS=\
encoding/pem\ encoding/pem\
exec\ exec\
exp/datafmt\ exp/datafmt\
exp/draw\
exp/draw/x11\
exp/eval\ exp/eval\
exp/gui\
exp/gui/x11\
expvar\ expvar\
flag\ flag\
fmt\ fmt\
...@@ -107,6 +107,7 @@ DIRS=\ ...@@ -107,6 +107,7 @@ DIRS=\
http/spdy\ http/spdy\
image\ image\
image/bmp\ image/bmp\
image/draw\
image/gif\ image/gif\
image/jpeg\ image/jpeg\
image/png\ image/png\
...@@ -184,7 +185,8 @@ NOTEST+=\ ...@@ -184,7 +185,8 @@ NOTEST+=\
crypto\ crypto\
crypto/openpgp/error\ crypto/openpgp/error\
debug/proc\ debug/proc\
exp/draw/x11\ exp/gui\
exp/gui/x11\
go/ast\ go/ast\
go/doc\ go/doc\
go/token\ go/token\
......
# Copyright 2009 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
include ../../../Make.inc
TARG=exp/gui
GOFILES=\
gui.go\
include ../../../Make.pkg
...@@ -2,17 +2,19 @@ ...@@ -2,17 +2,19 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package draw // Package gui defines a basic graphical user interface programming model.
package gui
import ( import (
"image" "image"
"image/draw"
"os" "os"
) )
// A Window represents a single graphics window. // A Window represents a single graphics window.
type Window interface { type Window interface {
// Screen returns an editable Image for the window. // Screen returns an editable Image for the window.
Screen() Image Screen() draw.Image
// FlushImage flushes changes made to Screen() back to screen. // FlushImage flushes changes made to Screen() back to screen.
FlushImage() FlushImage()
// EventChan returns a channel carrying UI events such as key presses, // EventChan returns a channel carrying UI events such as key presses,
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
include ../../../../Make.inc include ../../../../Make.inc
TARG=exp/draw/x11 TARG=exp/gui/x11
GOFILES=\ GOFILES=\
auth.go\ auth.go\
conn.go\ conn.go\
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// Package x11 implements an X11 backend for the exp/draw package. // Package x11 implements an X11 backend for the exp/gui package.
// //
// The X protocol specification is at ftp://ftp.x.org/pub/X11R7.0/doc/PDF/proto.pdf. // The X protocol specification is at ftp://ftp.x.org/pub/X11R7.0/doc/PDF/proto.pdf.
// A summary of the wire format can be found in XCB's xproto.xml. // A summary of the wire format can be found in XCB's xproto.xml.
...@@ -10,8 +10,9 @@ package x11 ...@@ -10,8 +10,9 @@ package x11
import ( import (
"bufio" "bufio"
"exp/draw" "exp/gui"
"image" "image"
"image/draw"
"io" "io"
"log" "log"
"net" "net"
...@@ -43,7 +44,7 @@ type conn struct { ...@@ -43,7 +44,7 @@ type conn struct {
img *image.RGBA img *image.RGBA
eventc chan interface{} eventc chan interface{}
mouseState draw.MouseEvent mouseState gui.MouseEvent
buf [256]byte // General purpose scratch buffer. buf [256]byte // General purpose scratch buffer.
...@@ -53,7 +54,7 @@ type conn struct { ...@@ -53,7 +54,7 @@ type conn struct {
} }
// writeSocket runs in its own goroutine, serving both FlushImage calls // writeSocket runs in its own goroutine, serving both FlushImage calls
// directly from the exp/draw client and indirectly from X expose events. // directly from the exp/gui client and indirectly from X expose events.
// It paints c.img to the X server via PutImage requests. // It paints c.img to the X server via PutImage requests.
func (c *conn) writeSocket() { func (c *conn) writeSocket() {
defer c.c.Close() defer c.c.Close()
...@@ -143,7 +144,7 @@ func (c *conn) Close() os.Error { ...@@ -143,7 +144,7 @@ func (c *conn) Close() os.Error {
func (c *conn) EventChan() <-chan interface{} { return c.eventc } func (c *conn) EventChan() <-chan interface{} { return c.eventc }
// readSocket runs in its own goroutine, reading X events and sending draw // readSocket runs in its own goroutine, reading X events and sending gui
// events on c's EventChan. // events on c's EventChan.
func (c *conn) readSocket() { func (c *conn) readSocket() {
var ( var (
...@@ -155,7 +156,7 @@ func (c *conn) readSocket() { ...@@ -155,7 +156,7 @@ func (c *conn) readSocket() {
// X events are always 32 bytes long. // X events are always 32 bytes long.
if _, err := io.ReadFull(c.r, c.buf[0:32]); err != nil { if _, err := io.ReadFull(c.r, c.buf[0:32]); err != nil {
if err != os.EOF { if err != os.EOF {
c.eventc <- draw.ErrEvent{err} c.eventc <- gui.ErrEvent{err}
} }
return return
} }
...@@ -165,7 +166,7 @@ func (c *conn) readSocket() { ...@@ -165,7 +166,7 @@ func (c *conn) readSocket() {
if cookie != 1 { if cookie != 1 {
// We issued only one request (GetKeyboardMapping) with a cookie of 1, // We issued only one request (GetKeyboardMapping) with a cookie of 1,
// so we shouldn't get any other reply from the X server. // so we shouldn't get any other reply from the X server.
c.eventc <- draw.ErrEvent{os.NewError("x11: unexpected cookie")} c.eventc <- gui.ErrEvent{os.NewError("x11: unexpected cookie")}
return return
} }
keysymsPerKeycode = int(c.buf[1]) keysymsPerKeycode = int(c.buf[1])
...@@ -179,7 +180,7 @@ func (c *conn) readSocket() { ...@@ -179,7 +180,7 @@ func (c *conn) readSocket() {
u, err := readU32LE(c.r, c.buf[0:4]) u, err := readU32LE(c.r, c.buf[0:4])
if err != nil { if err != nil {
if err != os.EOF { if err != os.EOF {
c.eventc <- draw.ErrEvent{err} c.eventc <- gui.ErrEvent{err}
} }
return return
} }
...@@ -204,11 +205,11 @@ func (c *conn) readSocket() { ...@@ -204,11 +205,11 @@ func (c *conn) readSocket() {
// TODO(nigeltao): Should we send KeyEvents for Shift/Ctrl/Alt? Should Shift-A send // TODO(nigeltao): Should we send KeyEvents for Shift/Ctrl/Alt? Should Shift-A send
// the same int down the channel as the sent on just the A key? // the same int down the channel as the sent on just the A key?
// TODO(nigeltao): How should IME events (e.g. key presses that should generate CJK text) work? Or // TODO(nigeltao): How should IME events (e.g. key presses that should generate CJK text) work? Or
// is that outside the scope of the draw.Window interface? // is that outside the scope of the gui.Window interface?
if c.buf[0] == 0x03 { if c.buf[0] == 0x03 {
keysym = -keysym keysym = -keysym
} }
c.eventc <- draw.KeyEvent{keysym} c.eventc <- gui.KeyEvent{keysym}
case 0x04, 0x05: // Button press, button release. case 0x04, 0x05: // Button press, button release.
mask := 1 << (c.buf[1] - 1) mask := 1 << (c.buf[1] - 1)
if c.buf[0] == 0x04 { if c.buf[0] == 0x04 {
...@@ -551,7 +552,7 @@ func (c *conn) handshake() os.Error { ...@@ -551,7 +552,7 @@ func (c *conn) handshake() os.Error {
} }
// NewWindow calls NewWindowDisplay with $DISPLAY. // NewWindow calls NewWindowDisplay with $DISPLAY.
func NewWindow() (draw.Window, os.Error) { func NewWindow() (gui.Window, os.Error) {
display := os.Getenv("DISPLAY") display := os.Getenv("DISPLAY")
if len(display) == 0 { if len(display) == 0 {
return nil, os.NewError("$DISPLAY not set") return nil, os.NewError("$DISPLAY not set")
...@@ -559,10 +560,10 @@ func NewWindow() (draw.Window, os.Error) { ...@@ -559,10 +560,10 @@ func NewWindow() (draw.Window, os.Error) {
return NewWindowDisplay(display) return NewWindowDisplay(display)
} }
// NewWindowDisplay returns a new draw.Window, backed by a newly created and // NewWindowDisplay returns a new gui.Window, backed by a newly created and
// mapped X11 window. The X server to connect to is specified by the display // mapped X11 window. The X server to connect to is specified by the display
// string, such as ":1". // string, such as ":1".
func NewWindowDisplay(display string) (draw.Window, os.Error) { func NewWindowDisplay(display string) (gui.Window, os.Error) {
socket, displayStr, err := connect(display) socket, displayStr, err := connect(display)
if err != nil { if err != nil {
return nil, err return nil, err
......
...@@ -4,9 +4,8 @@ ...@@ -4,9 +4,8 @@
include ../../../Make.inc include ../../../Make.inc
TARG=exp/draw TARG=image/draw
GOFILES=\ GOFILES=\
draw.go\ draw.go\
event.go\
include ../../../Make.pkg include ../../../Make.pkg
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// Package draw provides basic graphics and drawing primitives, // Package draw provides image composition functions
// in the style of the Plan 9 graphics library // in the style of the Plan 9 graphics library
// (see http://plan9.bell-labs.com/magic/man2html/2/draw) // (see http://plan9.bell-labs.com/magic/man2html/2/draw)
// and the X Render extension. // and the X Render extension.
...@@ -16,7 +16,7 @@ import ( ...@@ -16,7 +16,7 @@ import (
// m is the maximum color value returned by image.Color.RGBA. // m is the maximum color value returned by image.Color.RGBA.
const m = 1<<16 - 1 const m = 1<<16 - 1
// A Porter-Duff compositing operator. // Op is a Porter-Duff compositing operator.
type Op int type Op int
const ( const (
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment