Skip to content

Commit

Permalink
Merge pull request #45 from sbroadfoot90/master
Browse files Browse the repository at this point in the history
Ran gofix to update to latest Go API
  • Loading branch information
banthar committed Nov 4, 2011
2 parents 94e50af + cc10a46 commit 8309d2a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 35 deletions.
12 changes: 6 additions & 6 deletions gui/gui.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package sdlgui

import (
"os"
"errors"
"sdl"
"time"
"image"
Expand Down Expand Up @@ -72,7 +72,7 @@ func (win *window) EventChan() <-chan interface{} {
return win.ec
}

func (win *window) Close() os.Error {
func (win *window) Close() error {
win.events = false

win.screen.Free()
Expand All @@ -84,11 +84,11 @@ func (win *window) Close() os.Error {

var initnum uint

func initinc() os.Error {
func initinc() error {
if initnum == 0 {
errn := sdl.Init(sdl.INIT_VIDEO)
if errn < 0 {
return os.NewError(sdl.GetError())
return errors.New(sdl.GetError())
}
}

Expand All @@ -105,7 +105,7 @@ func initdec() {
}
}

func NewWindow(w, h, bpp int, flags uint32) (gui.Window, os.Error) {
func NewWindow(w, h, bpp int, flags uint32) (gui.Window, error) {
win := new(window)

err := initinc()
Expand All @@ -115,7 +115,7 @@ func NewWindow(w, h, bpp int, flags uint32) (gui.Window, os.Error) {

win.screen = sdl.SetVideoMode(w, h, bpp, flags)
if win.screen == nil {
return nil, os.NewError(sdl.GetError())
return nil, errors.New(sdl.GetError())
}

win.ec = make(chan interface{})
Expand Down
3 changes: 2 additions & 1 deletion gui/test/test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"image/color"
"os"
"fmt"
"sdl"
Expand All @@ -19,7 +20,7 @@ func main() {

screen := win.Screen()

cimg := image.NewColorImage(image.RGBAColor{255, 0, 255, 255})
cimg := image.NewUniform(color.RGBA{255, 0, 255, 255})
draw.Draw(screen,
image.Rect(10, 10, 200, 200),
cimg,
Expand Down
60 changes: 32 additions & 28 deletions sdl/sdl.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ package sdl
// static int RWclose(SDL_RWops *rw){return SDL_RWclose(rw);}
// static int __SDL_SaveBMP(SDL_Surface *surface, const char *file) { return SDL_SaveBMP(surface, file); }
import "C"
import "unsafe"
import (
"errors"
"image/color"
"unsafe"
)
import "image"
import "image/draw"
import "io"
Expand Down Expand Up @@ -287,23 +291,23 @@ func (img *Surface) pixPtr(x, y int) reflect.Value {
panic(fmt.Errorf("Image has unexpected BPP: %v", img.Format.BitsPerPixel))
}

func (img *Surface) ColorModel() image.ColorModel {
func (img *Surface) ColorModel() color.Model {
// TODO: Properly handle various colormodels.
return image.RGBAColorModel
return color.RGBAModel
}

func (img *Surface) Bounds() image.Rectangle {
return image.Rect(0, 0, int(img.W), int(img.H))
}

func (img *Surface) At(x, y int) image.Color {
func (img *Surface) At(x, y int) color.Color {
var r, g, b, a uint8
GetRGBA(uint32(img.pixPtr(x, y).Uint()), img.Format, &r, &g, &b, &a)

return img.ColorModel().Convert(image.RGBAColor{r, g, b, a})
return img.ColorModel().Convert(color.RGBA{r, g, b, a})
}

func (img *Surface) Set(x, y int, c image.Color) {
func (img *Surface) Set(x, y int, c color.Color) {
img.Lock()
defer img.Unlock()

Expand Down Expand Up @@ -510,43 +514,43 @@ func JoystickOpened(n int) bool {
return C.SDL_JoystickOpened(C.int(n)) != 0
}

func (j *Joystick)Index() int {
func (j *Joystick) Index() int {
return int(C.SDL_JoystickIndex((*C.SDL_Joystick)(unsafe.Pointer(j))))
}

func (j *Joystick)NumAxes() int {
func (j *Joystick) NumAxes() int {
return int(C.SDL_JoystickNumAxes((*C.SDL_Joystick)(unsafe.Pointer(j))))
}

func (j *Joystick)NumBalls() int {
func (j *Joystick) NumBalls() int {
return int(C.SDL_JoystickNumBalls((*C.SDL_Joystick)(unsafe.Pointer(j))))
}

func (j *Joystick)NumHats() int {
func (j *Joystick) NumHats() int {
return int(C.SDL_JoystickNumHats((*C.SDL_Joystick)(unsafe.Pointer(j))))
}

func (j *Joystick)NumButtons() int {
func (j *Joystick) NumButtons() int {
return int(C.SDL_JoystickNumButtons((*C.SDL_Joystick)(unsafe.Pointer(j))))
}

func JoystickUpdate() {
C.SDL_JoystickUpdate()
}

func (j *Joystick)GetAxis(n int) int16 {
func (j *Joystick) GetAxis(n int) int16 {
return int16(C.SDL_JoystickGetAxis((*C.SDL_Joystick)(unsafe.Pointer(j)), C.int(n)))
}

func (j *Joystick)GetHat(n int) int8 {
func (j *Joystick) GetHat(n int) int8 {
return int8(C.SDL_JoystickGetHat((*C.SDL_Joystick)(unsafe.Pointer(j)), C.int(n)))
}

func (j *Joystick)GetButton(n int) bool {
func (j *Joystick) GetButton(n int) bool {
return C.SDL_JoystickGetButton((*C.SDL_Joystick)(unsafe.Pointer(j)), C.int(n)) != 0
}

func (j *Joystick)GetBall(n int) (dx, dy int) {
func (j *Joystick) GetBall(n int) (dx, dy int) {
ret := C.SDL_JoystickGetBall((*C.SDL_Joystick)(unsafe.Pointer(j)),
C.int(n),
(*C.int)(unsafe.Pointer(&dx)),
Expand All @@ -560,7 +564,7 @@ func (j *Joystick)GetBall(n int) (dx, dy int) {
return
}

func (j *Joystick)Close() os.Error {
func (j *Joystick) Close() error {
C.SDL_JoystickClose((*C.SDL_Joystick)(unsafe.Pointer(j)))

return nil
Expand Down Expand Up @@ -668,7 +672,7 @@ func RWFromConstMem(m []byte) *RWops {
func RWFromReader(r io.Reader) *RWops {
data, err := ioutil.ReadAll(r)
if err != nil {
SetError(err.String())
SetError(err.Error())
return nil
}

Expand Down Expand Up @@ -728,7 +732,7 @@ func RWFromFP(fp *os.File, ac bool) *RWops {
func (rw *RWops) Tell() int64 {
cur, err := rw.Seek(0, 1)
if err != nil {
SetError(err.String())
SetError(err.Error())
return -1
}

Expand All @@ -743,7 +747,7 @@ func (rw *RWops) Length() int64 {

eof, err := rw.Seek(0, 2)
if err != nil {
SetError(err.String())
SetError(err.Error())
return -1
}

Expand All @@ -766,7 +770,7 @@ func (rw *RWops) EOF() bool {
return false
}

func (rw *RWops) Seek(offset int64, whence int) (int64, os.Error) {
func (rw *RWops) Seek(offset int64, whence int) (int64, error) {
var w C.int
switch whence {
case 0:
Expand All @@ -776,39 +780,39 @@ func (rw *RWops) Seek(offset int64, whence int) (int64, os.Error) {
case 2:
w = C.SEEK_END
default:
return offset, os.NewError("Bad whence.")
return offset, errors.New("Bad whence.")
}

return int64(C.RWseek((*C.SDL_RWops)(rw), C.int(offset), w)), nil
}

func (rw *RWops) Read(buf []byte) (n int, err os.Error) {
func (rw *RWops) Read(buf []byte) (n int, err error) {
n = int(C.RWread((*C.SDL_RWops)(rw), unsafe.Pointer(&buf[0]), 1, C.int(len(buf))))

if rw.EOF() {
err = os.EOF
err = io.EOF
}

if n < 0 {
err = os.NewError(GetError())
err = errors.New(GetError())
}

return n, nil
}

func (rw *RWops) Write(buf []byte) (n int, err os.Error) {
func (rw *RWops) Write(buf []byte) (n int, err error) {
n = int(C.RWwrite((*C.SDL_RWops)(rw), unsafe.Pointer(&buf[0]), 1, C.int(len(buf))))

if n < 0 {
err = os.NewError(GetError())
err = errors.New(GetError())
}

return n, err
}

func (rw *RWops) Close() os.Error {
func (rw *RWops) Close() error {
if int(C.RWclose((*C.SDL_RWops)(rw))) != 0 {
return os.NewError(GetError())
return errors.New(GetError())
}

return nil
Expand Down

0 comments on commit 8309d2a

Please sign in to comment.