J'ai besoin d'un volontaire qui aurait idéalement 2 joysticks de branchés sur sa machine pour tester le code suivant :
Code : Tout sélectionner
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Nom du projet : Test Screen supporté par SDL
; Nom du fichier : SDL Joystick Test.pb
; Version du fichier : 1.0.0
; Programmation : OK
; Programmé par : Guimauve
; Date : 20-02-2010
; Mise à jour : 20-02-2010
; Code PureBasic : 4.41
; Plateforme : Linux
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Import "/usr/lib/libSDL.so"
; <<<<<<<<<<<<<<<<<<<
; <<<<< General <<<<<
SDL_Init(Flag.l)
SDL_InitSubSystem(Flag.l)
SDL_QuitSubSystem(Flag.l)
SDL_Quit()
SDL_WasInit(Flag.l)
SDL_VERSION(*VersionA.SDL_version); --> Useless
SDL_GetError()
SDL_ClearError()
SDL_LoadObject(SO_file.s)
SDL_Linked_Version()
; SDL_SetError (const char *fmt, ...) ; --> À VALIDER
; SDL_Error(SDL_errorcode code) ; --> À VALIDER
; SDL_LoadFunction(*handle.i, Name.s) ; --> À VALIDER
; SDL_UnloadObject(*handle.i) ; --> À VALIDER
; <<<<<<<<<<<<<<<<<
; <<<<< Video <<<<<
SDL_GetVideoSurface()
SDL_GetVideoInfo()
SDL_VideoDriverName(namebuf.s, maxlen.l)
SDL_ListModes(*Format.SDL_PixelFormat, Flags.l)
SDL_VideoModeOK(Width.l, Height.l, BitsPerPixel.l, Flags.l)
SDL_SetVideoMode(Width.l, Height.l, BitsPerPixel.l, Flags.l)
SDL_UpdateRect(*Screen.SDL_Surface, x.l, y.l, Width.l, Height.l)
SDL_UpdateRects(*Screen.SDL_Surface, NumRects.l, *Rects.SDL_Rect)
SDL_Flip(*Screen.SDL_Surface)
SDL_SetColors(*Surface.SDL_Surface, *colors.SDL_Color, firstcolor.l, ncolors.l)
SDL_SetPalette(*Surface.SDL_Surface, Flags.l, *colors.SDL_Color, firstcolor.l, ncolors.l)
SDL_SetGamma(Red_gamma.f, Green_gamma.f, Blue_gamma.f)
SDL_MapRGB(*Format.SDL_PixelFormat, Red.a, Green.a, Blue.a)
SDL_MapRGBA(*Format.SDL_PixelFormat, Red.a, Green.a, Blue.a, Alpha.a)
SDL_GetRGB(Pixel.l, *Format.SDL_PixelFormat, *Red.a, *Green.a, *Blue.a) ; --> À VALIDER
SDL_GetRGBA(Pixel.l, *Format.SDL_PixelFormat, *Red.a, *Green.a, *Blue.a, *Alpha.a) ; --> À VALIDER
SDL_CreateRGBSurface(Flags.l, Width.l, Height.l, BitsPerPixel.l, Rmask.l, Gmask.l, Bmask.l, Amask.l)
SDL_CreateRGBSurfaceFrom(*pixels.i, Width.l, Height.l, Depth.l, Pitch.l, Rmask.l, Gmask.l, Bmask.l, Amask.l) ; --> À VALIDER
SDL_FreeSurface(*Surface.SDL_Surface)
SDL_LockSurface(*Surface.SDL_Surface)
SDL_UnlockSurface(*Surface.SDL_Surface)
SDL_ConvertSurface(*Source.SDL_Surface, *fmt.SDL_PixelFormat, Flags.l)
SDL_DisplayFormat(*Surface.SDL_Surface)
SDL_DisplayFormatAlpha(*Surface.SDL_Surface)
SDL_LoadBMP(FileName.s)
SDL_SaveBMP(*Surface.SDL_Surface, FileName.s)
SDL_SetColorKey(*Surface.SDL_Surface, Flag.l, Key.l)
SDL_SetAlpha(*Surface.SDL_Surface, Flags.l, Alpha.l)
SDL_SetClipRect(*Surface.SDL_Surface, *Rect.SDL_Rect)
SDL_GetClipRect(*Surface.SDL_Surface, *Rect.SDL_Rect)
SDL_BlitSurface(*Source.SDL_Surface, *SourceRect.SDL_Rect, *Dest.SDL_Surface, *DestRect.SDL_Rect)
SDL_FillRect(*Dest.SDL_Surface, *DestRect.SDL_Rect, Color.l)
; SDL_GetGammaRamp(Uint16 *redtable, Uint16 *greentable, Uint16 *bluetable) ; --> À VALIDER
; SDL_SetGammaRamp(Uint16 *redtable, Uint16 *greentable, Uint16 *bluetable) ; --> À VALIDER
SDL_GL_LoadLibrary(Path.s)
SDL_GL_GetProcAddress(Proc.s)
SDL_GL_GetAttribute(Attribute.l, *Value.l) ; --> À VALIDER
SDL_GL_SetAttribute(Attribute.l, Value.l) ; --> À VALIDER
SDL_GL_SwapBuffers()
SDL_CreateYUVOverlay(Width.l, Height.l, Format.l, *Display.SDL_Surface)
SDL_LockYUVOverlay(*Overlay.SDL_Overlay)
SDL_UnlockYUVOverlay(*Overlay.SDL_Overlay)
SDL_DisplayYUVOverlay(*Overlay.SDL_Overlay, *DestRect.SDL_Rect)
SDL_FreeYUVOverlay(*Overlay.SDL_Overlay)
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Window management <<<<<
SDL_WM_SetCaption(Title.s, Icon.s)
SDL_WM_SetIcon(*icon.SDL_Surface, *mask.a)
SDL_WM_IconifyWindow()
SDL_WM_ToggleFullScreen(*Surface.SDL_Surface)
SDL_WM_GrabInput(Mode.b)
; SDL_GetWMInfo(*info.SDL_SysWMinfo)
; SDL_WM_GetCaption(char **title, char **icon) ; À VALIDER
; <<<<<<<<<<<<<<<<<<
; <<<<< Events <<<<<
SDL_PumpEvents()
SDL_PeepEvents(*Events.SDL_Event, numevents.l, Action.l, Mask.l)
SDL_PollEvent(*Event.SDL_Event)
SDL_WaitEvent(*Event.SDL_Event)
SDL_PushEvent(*Event.SDL_Event)
SDL_GetEventFilter()
SDL_EventState(Type.a, State.l)
SDL_GetKeyState(*numkeys.l)
SDL_GetModState()
SDL_SetModState(Modstate.l)
SDL_GetKeyName(Key.l)
SDL_EnableUNICODE(Enable.l)
SDL_EnableKeyRepeat(Delay.l, Interval.l)
SDL_GetMouseState(*x.l, *y.l)
SDL_GetRelativeMouseState(*x.l, *y.l)
SDL_GetAppState()
SDL_JoystickEventState(State.l)
SDL_StartTextInput()
SDL_StopTextInput()
SDL_SetTextInputRect(*Rect.SDL_Rect)
; SDL_SetEventFilter(SDL_EventFilter filter) ; --> À VALIDER
; <<<<<<<<<<<<<<<<<
; <<<<< Mouse <<<<<
SDL_WarpMouse(x.w, y.w)
SDL_CreateCursor(*data_.a, *mask.a, w.l, h.l, hot_x.l, hot_y.l) ; À VALIDER
SDL_FreeCursor(*Cursor.SDL_Cursor)
SDL_SetCursor(*Cursor.SDL_Cursor)
SDL_GetCursor()
SDL_ShowCursor(Toggle.l)
; <<<<<<<<<<<<<<<<<<<<
; <<<<< Joystick <<<<<
SDL_NumJoysticks()
SDL_JoystickUpdate()
SDL_JoystickName(Index.l)
SDL_JoystickOpen(Index.l)
SDL_JoystickOpened(Index.l)
SDL_JoystickIndex(*JoystickA.i)
SDL_JoystickNumAxes(*JoystickA.i)
SDL_JoystickNumBalls(*JoystickA.i)
SDL_JoystickNumHats(*JoystickA.i)
SDL_JoystickNumButtons(*JoystickA.i)
SDL_JoystickClose(*JoystickA.i)
SDL_JoystickGetAxis(*JoystickA.i, Axis.l)
SDL_JoystickGetHat(*JoystickA.i, Hat.l)
SDL_JoystickGetButton(*JoystickA.i, Button.l)
SDL_JoystickGetBall(*JoystickA.i, Ball.l, *Dx.l, *Dy.l)
EndImport
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Macro de formatage <<<<<
Macro Format_SDL_Version(SDL_VersionA)
"SDL Version : " + StrU(SDL_VersionA\major, #PB_Byte) + "." + StrU(SDL_VersionA\minor, #PB_Byte) + "." + StrU(SDL_VersionA\patch, #PB_Byte)
EndMacro
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< L'opérateur Initialize <<<<<
Procedure InitializeSDL_version(*SDL_versionA.SDL_version)
*Version.SDL_version = SDL_Linked_Version()
CopyMemory(*Version, *SDL_versionA, SizeOf(SDL_version))
EndProcedure
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Code d'essai des résolutions avec lesquelles SDL peut travailler <<<<<
SDL_Init(#SDL_INIT_EVERYTHING)
InitializeSDL_version(SDL_version.SDL_version)
Debug "; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
Debug "; " + Format_SDL_Version(SDL_Version)
Debug "; Joystick test"
Debug ""
Max = SDL_NumJoysticks()
For Index = 0 To Max -1
Debug PeekS(SDL_JoystickName(Index))
Joystick.i = SDL_JoystickOpen(Index)
JoyIndex.b = SDL_JoystickIndex(Joystick)
AxisCount.b = SDL_JoystickNumAxes(Joystick)
BallsCount.b = SDL_JoystickNumBalls(Joystick)
HatCount.b = SDL_JoystickNumHats(Joystick)
ButtonCount.b = SDL_JoystickNumButtons(Joystick)
SDL_JoystickClose(Joystick)
Debug "JoyIndex = " + Str(JoyIndex)
Debug "AxisCount = " + Str(AxisCount)
Debug "BallsCount = " + Str(BallsCount)
Debug "HatCount = " + Str(HatCount)
Debug "ButtonCount = " + Str(ButtonCount)
Next
SDL_Quit()
; <<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< FIN DU FICHIER <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<
J'en ai juste 1 de branché pour le moment.Message du débogueur a écrit :; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; SDL Version : 1.2.13
; Joystick test
Logitech Logitech Freedom 2.4
JoyIndex = 0
AxisCount = 4
BallsCount = 0
HatCount = 1
ButtonCount = 10
Merci à l'avance.
A+
Guimauve