hedgewars/SDLh.pas
changeset 2428 6800f8aa0184
parent 2390 57fb33ab04a4
child 2477 d1ab2e2549d0
equal deleted inserted replaced
2427:241e3bb6a146 2428:6800f8aa0184
    61 	SDL_SWSURFACE   = $00000000;
    61 	SDL_SWSURFACE   = $00000000;
    62 	SDL_HWSURFACE   = $00000001;
    62 	SDL_HWSURFACE   = $00000001;
    63 	SDL_SRCALPHA    = $00010000;
    63 	SDL_SRCALPHA    = $00010000;
    64 	SDL_INIT_VIDEO  = $00000020;
    64 	SDL_INIT_VIDEO  = $00000020;
    65 	SDL_INIT_AUDIO  = $00000010;
    65 	SDL_INIT_AUDIO  = $00000010;
       
    66 	SDL_INIT_JOYSTICK = $00000200;
    66 
    67 
    67 	SDL_APPINPUTFOCUS=$00000010;
    68 	SDL_APPINPUTFOCUS=$00000010;
    68 
    69 
    69 {$IFDEF SDL13}
    70 {$IFDEF SDL13}
    70 	SDL_ASYNCBLIT   = $08000000;
    71 	SDL_ASYNCBLIT   = $08000000;
    94 
    95 
    95 {*begin sdl_event binding*}
    96 {*begin sdl_event binding*}
    96 	SDL_NOEVENT     = 0;
    97 	SDL_NOEVENT     = 0;
    97 	SDL_KEYDOWN     = 2;
    98 	SDL_KEYDOWN     = 2;
    98 	SDL_KEYUP       = 3;
    99 	SDL_KEYUP       = 3;
    99 	SDL_QUITEV      = 12;
   100 	//SDL_QUITEV      = 12;
   100 	SDL_VIDEORESIZE = 16;
   101 	SDL_VIDEORESIZE = 16; // TODO: outdated? no longer in SDL 1.3?
   101 
   102 
   102 {$IFDEF SDL13}
   103 {$IFDEF SDL13}
   103         SDL_WINDOWEVENT = 1;
   104         SDL_WINDOWEVENT = 1;
   104         SDL_TEXTINPUT = 4;
   105         SDL_TEXTINPUT = 4;
   105 	SDL_MOUSEMOTION  = 5;
   106 	SDL_MOUSEMOTION  = 5;
   106         SDL_MOUSEBUTTONDOWN = 6;
   107         SDL_MOUSEBUTTONDOWN = 6;
   107 	SDL_MOUSEBUTTONUP   = 7;
   108 	SDL_MOUSEBUTTONUP   = 7;
   108         SDL_MOUSEWHEEL = 8;  //different handling, should create SDL_MouseWheelEvent type
   109         SDL_MOUSEWHEEL = 8;  //different handling, should create SDL_MouseWheelEvent type
       
   110 	SDL_JOYAXIS = 10;
       
   111 	SDL_JOYHAT = 12;
       
   112 	SDL_JOYBUTTONDOWN = 13;
       
   113 	SDL_JOYBUTTONUP = 14;
       
   114 	SDL_QUITEV      = 15;
   109 {$ELSE}
   115 {$ELSE}
   110         SDL_ACTIVEEVENT = 1;
   116         SDL_ACTIVEEVENT = 1;
   111        	SDL_MOUSEBUTTONDOWN = 5;
   117        	SDL_MOUSEBUTTONDOWN = 5;
   112 	SDL_MOUSEBUTTONUP   = 6;
   118 	SDL_MOUSEBUTTONUP   = 6;
   113         SDL_BUTTON_WHEELDUP = 4;
   119         SDL_BUTTON_WHEELDUP = 4;
   114 	SDL_BUTTON_WHEELDOWN = 5;
   120 	SDL_BUTTON_WHEELDOWN = 5;
       
   121 	SDL_JOYAXIS = 7;
       
   122 	SDL_JOYHAT = 9;
       
   123 	SDL_JOYBUTTONDOWN = 10;
       
   124 	SDL_JOYBUTTONUP = 11;
       
   125 	SDL_QUITEV      = 12;
   115 {$ENDIF}
   126 {$ENDIF}
   116 {*end sdl_event binding*}
   127 {*end sdl_event binding*}
   117 
   128 
   118 	RMask = $000000FF;
   129 	RMask = $000000FF;
   119 	GMask = $0000FF00;
   130 	GMask = $0000FF00;
   281      TSDL_ResizeEvent = record
   292      TSDL_ResizeEvent = record
   282 			type_: Byte;
   293 			type_: Byte;
   283 			w, h: LongInt;
   294 			w, h: LongInt;
   284 			end;
   295 			end;
   285 
   296 
   286      PSDL_Event = ^TSDL_Event;
   297      TSDL_JoyAxisEvent = record
       
   298 			type_: Byte;
       
   299 			which: Byte;
       
   300 			axis: Byte;
       
   301 			value: LongInt;
       
   302 			end;
       
   303 			
       
   304      TSDL_JoyHatEvent = record
       
   305 			type_: Byte;
       
   306 			which: Byte;
       
   307 			hat: Byte;
       
   308 			value: Byte;
       
   309 			end;
       
   310 	
       
   311      TSDL_JoyButtonEvent = record
       
   312 			type_: Byte;
       
   313 			which: Byte;
       
   314 			button: Byte;
       
   315 			state: Byte;
       
   316 			end;
       
   317 	 
       
   318 	 PSDL_Event = ^TSDL_Event;
   287      TSDL_Event = record
   319      TSDL_Event = record
   288                   case Byte of
   320                   case Byte of
   289 {$IFDEF SDL13}
   321 {$IFDEF SDL13}
   290                         //doublecheck the type of WINDOWEVENT TEXTINPUT
   322                         //doublecheck the type of WINDOWEVENT TEXTINPUT
   291                         SDL_NOEVENT: (type_: byte);
   323                         SDL_NOEVENT: (type_: byte);
   304                        SDL_QUITEV: (quit: TSDL_QuitEvent);
   336                        SDL_QUITEV: (quit: TSDL_QuitEvent);
   305                        SDL_VIDEORESIZE: (resize: TSDL_ResizeEvent);
   337                        SDL_VIDEORESIZE: (resize: TSDL_ResizeEvent);
   306                        SDL_MOUSEBUTTONDOWN,
   338                        SDL_MOUSEBUTTONDOWN,
   307                        SDL_MOUSEBUTTONUP: (button: TSDL_MouseButtonEvent);
   339                        SDL_MOUSEBUTTONUP: (button: TSDL_MouseButtonEvent);
   308 {$ENDIF}
   340 {$ENDIF}
       
   341 						SDL_JOYAXIS: (jaxis: TSDL_JoyAxisEvent);
       
   342 						SDL_JOYHAT: (jhat: TSDL_JoyHatEvent);
       
   343 						SDL_JOYBUTTONDOWN,
       
   344 						SDL_JOYBUTTONUP: (jbutton: TSDL_JoyButtonEvent);
   309      end;
   345      end;
   310 
   346 
   311      PByteArray = ^TByteArray;
   347      PByteArray = ^TByteArray;
   312      TByteArray = array[0..65535] of Byte;
   348      TByteArray = array[0..65535] of Byte;
   313      PLongWordArray = ^TLongWordArray;
   349      PLongWordArray = ^TLongWordArray;
   363 function  SDL_GetMouseState(x, y: PLongInt): Byte; cdecl; external SDLLibName;
   399 function  SDL_GetMouseState(x, y: PLongInt): Byte; cdecl; external SDLLibName;
   364 {$ENDIF}
   400 {$ENDIF}
   365 function  SDL_GetKeyName(key: Longword): PChar; cdecl; external SDLLibName;
   401 function  SDL_GetKeyName(key: Longword): PChar; cdecl; external SDLLibName;
   366 procedure SDL_WarpMouse(x, y: Word); cdecl; external SDLLibName;
   402 procedure SDL_WarpMouse(x, y: Word); cdecl; external SDLLibName;
   367 
   403 
       
   404 procedure SDL_PumpEvents; cdecl; external SDLLibName;
   368 function  SDL_PollEvent(event: PSDL_Event): LongInt; cdecl; external SDLLibName;
   405 function  SDL_PollEvent(event: PSDL_Event): LongInt; cdecl; external SDLLibName;
   369 
   406 
   370 function  SDL_ShowCursor(toggle: LongInt): LongInt; cdecl; external SDLLibName;
   407 function  SDL_ShowCursor(toggle: LongInt): LongInt; cdecl; external SDLLibName;
   371 
   408 
   372 procedure SDL_WM_SetCaption(title: PChar; icon: PChar); cdecl; external SDLLibName;
   409 procedure SDL_WM_SetCaption(title: PChar; icon: PChar); cdecl; external SDLLibName;
   488 procedure SDLNet_Write16(value: Word; buf: pointer);
   525 procedure SDLNet_Write16(value: Word; buf: pointer);
   489 procedure SDLNet_Write32(value: LongWord; buf: pointer);
   526 procedure SDLNet_Write32(value: LongWord; buf: pointer);
   490 function  SDLNet_Read16(buf: pointer): Word;
   527 function  SDLNet_Read16(buf: pointer): Word;
   491 function  SDLNet_Read32(buf: pointer): LongWord;
   528 function  SDLNet_Read32(buf: pointer): LongWord;
   492 
   529 
       
   530 // Joystick/Controller support
       
   531 type PSDLJoystick = ^TSDLJoystick;
       
   532      TSDLJoystick = record
       
   533 	                end;
       
   534 
       
   535 function SDL_NumJoysticks: LongInt; cdecl; external SDLLibName;
       
   536 function SDL_JoystickName(idx: LongInt): PChar; cdecl; external SDLLibName;
       
   537 function SDL_JoystickOpen(idx: LongInt): PSDLJoystick; cdecl; external SDLLibName;
       
   538 function SDL_JoystickOpened(idx: LongInt): LongInt; cdecl; external SDLLibName;
       
   539 function SDL_JoystickIndex(joy: PSDLJoystick): LongInt; cdecl; external SDLLibName;
       
   540 function SDL_JoystickNumAxes(joy: PSDLJoystick): LongInt; cdecl; external SDLLibName;
       
   541 function SDL_JoystickNumBalls(joy: PSDLJoystick): LongInt; cdecl; external SDLLibName;
       
   542 function SDL_JoystickNumHats(joy: PSDLJoystick): LongInt; cdecl; external SDLLibName;
       
   543 function SDL_JoystickNumButtons(joy: PSDLJoystick): LongInt; cdecl; external SDLLibName;
       
   544 procedure SDL_JoystickUpdate; cdecl; external SDLLibName;
       
   545 function SDL_JoystickEventState(state: LongInt): LongInt; cdecl; external SDLLibName;
       
   546 function SDL_JoystickGetAxis(joy: PSDLJoystick; axis: LongInt): Word; cdecl; external SDLLibName;
       
   547 const SDL_HAT_CENTERED  = $00;
       
   548       SDL_HAT_UP        = $01;
       
   549 	  SDL_HAT_RIGHT     = $02;
       
   550 	  SDL_HAT_DOWN      = $04;
       
   551 	  SDL_HAT_LEFT      = $08;
       
   552 	  SDL_HAT_RIGHTUP   = SDL_HAT_RIGHT or SDL_HAT_UP;
       
   553 	  SDL_HAT_RIGHTDOWN = SDL_HAT_RIGHT or SDL_HAT_DOWN;
       
   554 	  SDL_HAT_LEFTUP    = SDL_HAT_LEFT or SDL_HAT_UP;
       
   555 	  SDL_HAT_LEFTDOWN  = SDL_HAT_LEFT or SDL_HAT_DOWN;
       
   556 function SDL_JoystickGetBall(joy: PSDLJoystick; ball: LongInt; dx: PInteger; dy: PInteger): Word; cdecl; external SDLLibName;
       
   557 function SDL_JoystickGetHat(joy: PSDLJoystick; hat: LongInt): Byte; cdecl; external SDLLibName;
       
   558 function SDL_JoystickGetButton(joy: PSDLJoystick; button: LongInt): Byte; cdecl; external SDLLibName;
       
   559 procedure SDL_JoystickClose(joy: PSDLJoystick); cdecl; external SDLLibName;
       
   560 
   493 implementation
   561 implementation
   494 
   562 
   495 function SDL_MustLock(Surface: PSDL_Surface): Boolean;
   563 function SDL_MustLock(Surface: PSDL_Surface): Boolean;
   496 begin
   564 begin
   497 SDL_MustLock:= ( surface^.offset <> 0 )
   565 SDL_MustLock:= ( surface^.offset <> 0 )