Skip to content

Commit

Permalink
sdl: Replace ints with booleans (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
malashin committed Mar 30, 2018
1 parent b77db23 commit 8e7373e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 41 deletions.
17 changes: 11 additions & 6 deletions BREAKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,13 @@
+ Renamed `Texture.GL_UnbindTexture()` to `Texture.GLUnbind()`
+ Renamed `TouchId` to `TouchID` in `MultiGestureEvent` struct
+ Renamed `Unicode` to `unused` in `Keysym` struct (must have been a typo)
+ `GetCurrentDisplayMode` returns (DisplayMode, error) instead of error
+ `GetCurrentVideoDriver()` returns (string, error) instead of string
+ `GetDesktopDisplayMode` returns (DisplayMode, error) instead of error
+ `GetDisplayBounds` returns (Rect, error) instead of error
+ `GetDisplayMode` returns (DisplayMode, error) instead of error
+ `GetDisplayName()` returns (string, error) instead of string
+ `GetDisplayUsableBounds` returns (Rect, error) instead of error
+ `GetNumRenderDrivers()` returns (int, error) instead of int
+ `GetRenderDriverInfo()` returns (int, error) instead of int
+ `Haptic.GetEffectStatus()` returns (int, error) instead of int
Expand All @@ -77,20 +82,20 @@
+ `HapticIndex()` returns (int, error) instead of int
+ `HapticName()` returns (string, error) instead of string
+ `HapticOpenFromJoystick()` returns (\*Haptic, error) instead of \*Haptic
+ `LoadBMPRW()` requires (\*RWops, bool) instead of (\*RWops, int)
+ `LoadWAV()` requires string instead of (string ,\*AudioSpec)
+ `LoadWAVRW()` requires (\*RWops, bool) instead of (\*RWops, bool ,\*AudioSpec)
+ `NumHaptics()` returns (int, error) instead of int
+ `Renderer.Destroy()` returns error
+ `Renderer.GetViewport()` and `Renderer.GetClipRect()` now returns Rect instead of being passed a \*Rect
+ `ShowCursor` returns (int, error) instead of int
+ `Surface.SaveBMPRW()` requires (\*RWops, bool) instead of (\*RWops, int)
+ `Surface.SetColorKey()` requires (bool, uint32) instead of (int, uint32)
+ `Surface.SetRLE()` requires bool instead of int
+ `Texture.Destroy()` returns error
+ `Window.Destroy()` returns error
+ `Window.GetID()` returns (uint32, error) instead of uint32
+ `GetDisplayBounds` returns (Rect, error) instead of error
+ `GetDisplayUsableBounds` returns (Rect, error) instead of error
+ `GetDisplayMode` returns (DisplayMode, error) instead of error
+ `GetDesktopDisplayMode` returns (DisplayMode, error) instead of error
+ `GetCurrentDisplayMode` returns (DisplayMode, error) instead of error
+ `Window.GetDisplayMode` returns (DisplayMode, error) instead of error
+ `Window.GetID()` returns (uint32, error) instead of uint32
+ Changed Mutex, Sem, Cond to have methods instead of functions
+ Changed `GameControllerMapping()` into `GameController.Mapping()`
+ Haptic functions now return bool and/or error instead of int
Expand Down
34 changes: 17 additions & 17 deletions sdl/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,83 +130,83 @@ func Log(str string, args ...interface{}) {

// LogVerbose logs a message with LOG_PRIORITY_VERBOSE.
// (https://wiki.libsdl.org/SDL_LogVerbose)
func LogVerbose(cat int, str string, args ...interface{}) {
func LogVerbose(category int, str string, args ...interface{}) {
str = fmt.Sprintf(str, args...)

cstr := C.CString(str)
defer C.free(unsafe.Pointer(cstr))

C._SDL_LogVerbose(C.int(cat), cstr)
C._SDL_LogVerbose(C.int(category), cstr)
}

// LogDebug logs a message with LOG_PRIORITY_DEBUG.
// (https://wiki.libsdl.org/SDL_LogDebug)
func LogDebug(cat int, str string, args ...interface{}) {
func LogDebug(category int, str string, args ...interface{}) {
str = fmt.Sprintf(str, args...)

cstr := C.CString(str)
defer C.free(unsafe.Pointer(cstr))

C._SDL_LogDebug(C.int(cat), cstr)
C._SDL_LogDebug(C.int(category), cstr)
}

// LogInfo logs a message with LOG_PRIORITY_INFO.
// (https://wiki.libsdl.org/SDL_LogInfo)
func LogInfo(cat int, str string, args ...interface{}) {
func LogInfo(category int, str string, args ...interface{}) {
str = fmt.Sprintf(str, args...)

cstr := C.CString(str)
defer C.free(unsafe.Pointer(cstr))

C._SDL_LogInfo(C.int(cat), cstr)
C._SDL_LogInfo(C.int(category), cstr)
}

// LogWarn logs a message with LOG_PRIORITY_WARN.
// (https://wiki.libsdl.org/SDL_LogWarn)
func LogWarn(cat int, str string, args ...interface{}) {
func LogWarn(category int, str string, args ...interface{}) {
str = fmt.Sprintf(str, args...)

cstr := C.CString(str)
defer C.free(unsafe.Pointer(cstr))

C._SDL_LogWarn(C.int(cat), cstr)
C._SDL_LogWarn(C.int(category), cstr)
}

// LogError logs a message with LOG_PRIORITY_ERROR.
// (https://wiki.libsdl.org/SDL_LogError)
func LogError(cat int, str string, args ...interface{}) {
func LogError(category int, str string, args ...interface{}) {
str = fmt.Sprintf(str, args...)

cstr := C.CString(str)
defer C.free(unsafe.Pointer(cstr))

C._SDL_LogError(C.int(cat), cstr)
C._SDL_LogError(C.int(category), cstr)
}

// LogCritical logs a message with LOG_PRIORITY_CRITICAL.
// (https://wiki.libsdl.org/SDL_LogCritical)
func LogCritical(cat int, str string, args ...interface{}) {
func LogCritical(category int, str string, args ...interface{}) {
str = fmt.Sprintf(str, args...)

cstr := C.CString(str)
defer C.free(unsafe.Pointer(cstr))

C._SDL_LogCritical(C.int(cat), cstr)
C._SDL_LogCritical(C.int(category), cstr)
}

// LogMessage logs a message with the specified category and priority.
// (https://wiki.libsdl.org/SDL_LogMessage)
func LogMessage(cat int, pri LogPriority, str string, args ...interface{}) {
func LogMessage(category int, pri LogPriority, str string, args ...interface{}) {
str = fmt.Sprintf(str, args...)

cstr := C.CString(str)
defer C.free(unsafe.Pointer(cstr))

C._SDL_LogMessage(C.int(cat), C.SDL_LogPriority(pri), cstr)
C._SDL_LogMessage(C.int(category), C.SDL_LogPriority(pri), cstr)
}

// LogOutputFunction is the function to call instead of the default
type LogOutputFunction func(data interface{}, cat int, pri LogPriority, message string)
type LogOutputFunction func(data interface{}, category int, pri LogPriority, message string)

type logOutputFunctionCtx struct {
f LogOutputFunction
Expand All @@ -216,10 +216,10 @@ type logOutputFunctionCtx struct {
// Yissakhar Z. Beck (DeedleFake)'s implementation
//
//export logOutputFunction
func logOutputFunction(data unsafe.Pointer, cat C.int, pri C.SDL_LogPriority, message *C.char) {
func logOutputFunction(data unsafe.Pointer, category C.int, pri C.SDL_LogPriority, message *C.char) {
ctx := (*logOutputFunctionCtx)(data)

ctx.f(ctx.d, int(cat), LogPriority(pri), C.GoString(message))
ctx.f(ctx.d, int(category), LogPriority(pri), C.GoString(message))
}

var (
Expand Down
5 changes: 3 additions & 2 deletions sdl/mouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,9 @@ func FreeCursor(cursor *Cursor) {

// ShowCursor toggles whether or not the cursor is shown.
// (https://wiki.libsdl.org/SDL_ShowCursor)
func ShowCursor(toggle int) int {
return int(C.SDL_ShowCursor(C.int(toggle)))
func ShowCursor(toggle int) (int, error) {
i := int(C.SDL_ShowCursor(C.int(toggle)))
return i, errorFromInt(i)
}

// CaptureMouse captures the mouse and tracks input outside an SDL window.
Expand Down
20 changes: 10 additions & 10 deletions sdl/surface.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ func (surface *Surface) Unlock() {

// LoadBMPRW loads a BMP image from a seekable SDL data stream (memory or file).
// (https://wiki.libsdl.org/SDL_LoadBMP_RW)
func LoadBMPRW(src *RWops, freeSrc int) (*Surface, error) {
surface := (*Surface)(unsafe.Pointer(C.SDL_LoadBMP_RW(src.cptr(), C.int(freeSrc))))
func LoadBMPRW(src *RWops, freeSrc bool) (*Surface, error) {
surface := (*Surface)(unsafe.Pointer(C.SDL_LoadBMP_RW(src.cptr(), C.int(Btoi(freeSrc)))))
if surface == nil {
return nil, GetError()
}
Expand All @@ -168,13 +168,13 @@ func LoadBMPRW(src *RWops, freeSrc int) (*Surface, error) {
// LoadBMP loads a surface from a BMP file.
// (https://wiki.libsdl.org/SDL_LoadBMP)
func LoadBMP(file string) (*Surface, error) {
return LoadBMPRW(RWFromFile(file, "rb"), 1)
return LoadBMPRW(RWFromFile(file, "rb"), true)
}

// SaveBMPRW save the surface to a seekable SDL data stream (memory or file) in BMP format.
// (https://wiki.libsdl.org/SDL_SaveBMP_RW)
func (surface *Surface) SaveBMPRW(dst *RWops, freeDst int) error {
if C.SDL_SaveBMP_RW(surface.cptr(), dst.cptr(), C.int(freeDst)) != 0 {
func (surface *Surface) SaveBMPRW(dst *RWops, freeDst bool) error {
if C.SDL_SaveBMP_RW(surface.cptr(), dst.cptr(), C.int(Btoi(freeDst))) != 0 {
return GetError()
}
return nil
Expand All @@ -183,22 +183,22 @@ func (surface *Surface) SaveBMPRW(dst *RWops, freeDst int) error {
// SaveBMP saves the surface to a BMP file.
// (https://wiki.libsdl.org/SDL_SaveBMP)
func (surface *Surface) SaveBMP(file string) error {
return surface.SaveBMPRW(RWFromFile(file, "wb"), 1)
return surface.SaveBMPRW(RWFromFile(file, "wb"), true)
}

// SetRLE sets the RLE acceleration hint for the surface.
// (https://wiki.libsdl.org/SDL_SetSurfaceRLE)
func (surface *Surface) SetRLE(flag int) error {
if C.SDL_SetSurfaceRLE(surface.cptr(), C.int(flag)) != 0 {
func (surface *Surface) SetRLE(flag bool) error {
if C.SDL_SetSurfaceRLE(surface.cptr(), C.int(Btoi(flag))) != 0 {
return GetError()
}
return nil
}

// SetColorKey sets the color key (transparent pixel) in the surface.
// (https://wiki.libsdl.org/SDL_SetColorKey)
func (surface *Surface) SetColorKey(flag int, key uint32) error {
if C.SDL_SetColorKey(surface.cptr(), C.int(flag), C.Uint32(key)) != 0 {
func (surface *Surface) SetColorKey(flag bool, key uint32) error {
if C.SDL_SetColorKey(surface.cptr(), C.int(Btoi(flag)), C.Uint32(key)) != 0 {
return GetError()
}
return nil
Expand Down
8 changes: 2 additions & 6 deletions sdl/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,11 +560,7 @@ func (window *Window) GetPosition() (x, y int32) {
// SetResizable sets the user-resizable state of the window.
// (https://wiki.libsdl.org/SDL_SetWindowResizable)
func (window *Window) SetResizable(resizable bool) {
var _resizable C.SDL_bool = C.SDL_FALSE
if resizable {
_resizable = C.SDL_TRUE
}
C.SDL_SetWindowResizable(window.cptr(), _resizable)
C.SDL_SetWindowResizable(window.cptr(), C.SDL_bool(Btoi(resizable)))
}

// SetSize sets the size of the window's client area.
Expand Down Expand Up @@ -612,7 +608,7 @@ func (window *Window) GetMaximumSize() (w, h int32) {
// SetBordered sets the border state of the window.
// (https://wiki.libsdl.org/SDL_SetWindowBordered)
func (window *Window) SetBordered(bordered bool) {
C.SDL_SetWindowBordered(window.cptr(), (C.SDL_bool)(Btoi(bordered)))
C.SDL_SetWindowBordered(window.cptr(), C.SDL_bool(Btoi(bordered)))
}

// Show shows the window.
Expand Down

0 comments on commit 8e7373e

Please sign in to comment.