Skip to content

Commit 1cae00e

Browse files
committed
sdl: video: Make several functions return values instead of modifying user-provided values through pointers
Signed-off-by: Lilis Iskandar <[email protected]>
1 parent e5fd0c8 commit 1cae00e

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

sdl/video.go

+23-17
Original file line numberDiff line numberDiff line change
@@ -365,37 +365,42 @@ func GetNumDisplayModes(displayIndex int) (int, error) {
365365

366366
// GetDisplayBounds returns the desktop area represented by a display, with the primary display located at 0,0.
367367
// (https://wiki.libsdl.org/SDL_GetDisplayBounds)
368-
func GetDisplayBounds(displayIndex int, rect *Rect) error {
369-
return errorFromInt(int(
370-
C.SDL_GetDisplayBounds(C.int(displayIndex), rect.cptr())))
368+
func GetDisplayBounds(displayIndex int) (rect Rect, err error) {
369+
err = errorFromInt(int(
370+
C.SDL_GetDisplayBounds(C.int(displayIndex), (&rect).cptr())))
371+
return
371372
}
372373

373374
// GetDisplayUsableBounds returns the usable desktop area represented by a display, with the primary display located at 0,0.
374375
// (https://wiki.libsdl.org/SDL_GetDisplayUsableBounds)
375-
func GetDisplayUsableBounds(displayIndex int, rect *Rect) error {
376-
return errorFromInt(int(
376+
func GetDisplayUsableBounds(displayIndex int) (rect Rect, err error) {
377+
err = errorFromInt(int(
377378
C.SDL_GetDisplayUsableBounds(C.int(displayIndex), rect.cptr())))
379+
return
378380
}
379381

380382
// GetDisplayMode retruns information about a specific display mode.
381383
// (https://wiki.libsdl.org/SDL_GetDisplayMode)
382-
func GetDisplayMode(displayIndex int, modeIndex int, mode *DisplayMode) error {
383-
return errorFromInt(int(
384-
C.SDL_GetDisplayMode(C.int(displayIndex), C.int(modeIndex), mode.cptr())))
384+
func GetDisplayMode(displayIndex int, modeIndex int) (mode DisplayMode, err error) {
385+
err = errorFromInt(int(
386+
C.SDL_GetDisplayMode(C.int(displayIndex), C.int(modeIndex), (&mode).cptr())))
387+
return
385388
}
386389

387390
// GetDesktopDisplayMode returns information about the desktop display mode.
388391
// (https://wiki.libsdl.org/SDL_GetDesktopDisplayMode)
389-
func GetDesktopDisplayMode(displayIndex int, mode *DisplayMode) error {
390-
return errorFromInt(int(
391-
C.SDL_GetDesktopDisplayMode(C.int(displayIndex), mode.cptr())))
392+
func GetDesktopDisplayMode(displayIndex int) (mode DisplayMode, err error) {
393+
err = errorFromInt(int(
394+
C.SDL_GetDesktopDisplayMode(C.int(displayIndex), (&mode).cptr())))
395+
return
392396
}
393397

394398
// GetCurrentDisplayMode returns information about the current display mode.
395399
// (https://wiki.libsdl.org/SDL_GetCurrentDisplayMode)
396-
func GetCurrentDisplayMode(displayIndex int, mode *DisplayMode) error {
397-
return errorFromInt(int(
398-
C.SDL_GetCurrentDisplayMode(C.int(displayIndex), mode.cptr())))
400+
func GetCurrentDisplayMode(displayIndex int) (mode DisplayMode, err error) {
401+
err = errorFromInt(int(
402+
C.SDL_GetCurrentDisplayMode(C.int(displayIndex), (&mode).cptr())))
403+
return
399404
}
400405

401406
// GetClosestDisplayMode returns the closest match to the requested display mode.
@@ -432,9 +437,10 @@ func (window *Window) SetDisplayMode(mode *DisplayMode) error {
432437

433438
// GetDisplayMode fills in information about the display mode to use when the window is visible at fullscreen.
434439
// (https://wiki.libsdl.org/SDL_GetWindowDisplayMode)
435-
func (window *Window) GetDisplayMode(mode *DisplayMode) error {
436-
return errorFromInt(int(
437-
C.SDL_GetWindowDisplayMode(window.cptr(), mode.cptr())))
440+
func (window *Window) GetDisplayMode() (mode DisplayMode, err error) {
441+
err = errorFromInt(int(
442+
C.SDL_GetWindowDisplayMode(window.cptr(), (&mode).cptr())))
443+
return
438444
}
439445

440446
// GetPixelFormat returns the pixel format associated with the window.

0 commit comments

Comments
 (0)