sdlgameinterface.pas 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. unit sdlgameinterface;
  2. {
  3. $Id: sdlgameinterface.pas,v 1.3 2004/10/17 18:41:49 savage Exp $
  4. }
  5. {******************************************************************************}
  6. { }
  7. { JEDI-SDL : Pascal units for SDL - Simple DirectMedia Layer }
  8. { Game Interface Base class }
  9. { }
  10. { The initial developer of this Pascal code was : }
  11. { Dominqiue Louis <[email protected]> }
  12. { }
  13. { Portions created by Dominqiue Louis are }
  14. { Copyright (C) 2000 - 2001 Dominqiue Louis. }
  15. { }
  16. { }
  17. { Contributor(s) }
  18. { -------------- }
  19. { }
  20. { }
  21. { Obtained through: }
  22. { Joint Endeavour of Delphi Innovators ( Project JEDI ) }
  23. { }
  24. { You may retrieve the latest version of this file at the Project }
  25. { JEDI home page, located at http://delphi-jedi.org }
  26. { }
  27. { The contents of this file are used with permission, subject to }
  28. { the Mozilla Public License Version 1.1 (the "License"); you may }
  29. { not use this file except in compliance with the License. You may }
  30. { obtain a copy of the License at }
  31. { http://www.mozilla.org/MPL/MPL-1.1.html }
  32. { }
  33. { Software distributed under the License is distributed on an }
  34. { "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or }
  35. { implied. See the License for the specific language governing }
  36. { rights and limitations under the License. }
  37. { }
  38. { Description }
  39. { ----------- }
  40. { }
  41. { }
  42. { }
  43. { }
  44. { }
  45. { }
  46. { }
  47. { Requires }
  48. { -------- }
  49. { The SDL Runtime libraris on Win32 : SDL.dll on Linux : libSDL.so }
  50. { They are available from... }
  51. { http://www.libsdl.org . }
  52. { }
  53. { Programming Notes }
  54. { ----------------- }
  55. { }
  56. { }
  57. { }
  58. { }
  59. { Revision History }
  60. { ---------------- }
  61. { September 23 2004 - DL : Initial Creation }
  62. {
  63. $Log: sdlgameinterface.pas,v $
  64. Revision 1.3 2004/10/17 18:41:49 savage
  65. Slight Change to allow Reseting of Input Event handlers
  66. Revision 1.2 2004/09/30 22:35:47 savage
  67. Changes, enhancements and additions as required to get SoAoS working.
  68. }
  69. {******************************************************************************}
  70. interface
  71. uses
  72. sdl,
  73. sdlwindow;
  74. type
  75. TGameInterfaceClass = class of TGameInterface;
  76. TGameInterface = class( TObject )
  77. private
  78. FNextGameInterface : TGameInterfaceClass;
  79. protected
  80. Dragging : Boolean;
  81. Loaded : Boolean;
  82. procedure FreeSurfaces; virtual;
  83. procedure Render; virtual; abstract;
  84. procedure Close; virtual;
  85. procedure Update( aElapsedTime : single ); virtual;
  86. procedure MouseDown( Button : Integer; Shift: TSDLMod; MousePos : TPoint ); virtual;
  87. procedure MouseMove( Shift: TSDLMod; CurrentPos : TPoint; RelativePos : TPoint ); virtual;
  88. procedure MouseUp( Button : Integer; Shift: TSDLMod; MousePos : TPoint ); virtual;
  89. procedure MouseWheelScroll( WheelDelta : Integer; Shift: TSDLMod; MousePos : TPoint ); virtual;
  90. procedure KeyDown( var Key: TSDLKey; Shift: TSDLMod; unicode : UInt16 ); virtual;
  91. public
  92. MainWindow : TSDL2DWindow;
  93. procedure ResetInputManager;
  94. procedure LoadSurfaces; virtual;
  95. function PointIsInRect( Point : TPoint; x, y, x1, y1 : integer ) : Boolean;
  96. constructor Create( const aMainWindow : TSDL2DWindow );
  97. destructor Destroy; override;
  98. property NextGameInterface : TGameInterfaceClass read FNextGameInterface write FNextGameInterface;
  99. end;
  100. implementation
  101. { TGameInterface }
  102. procedure TGameInterface.Close;
  103. begin
  104. FNextGameInterface := nil;
  105. end;
  106. constructor TGameInterface.Create( const aMainWindow : TSDL2DWindow );
  107. begin
  108. inherited Create;
  109. MainWindow := aMainWindow;
  110. FNextGameInterface := TGameInterface;
  111. ResetInputManager;
  112. end;
  113. destructor TGameInterface.Destroy;
  114. begin
  115. if Loaded then
  116. FreeSurfaces;
  117. inherited;
  118. end;
  119. procedure TGameInterface.FreeSurfaces;
  120. begin
  121. Loaded := False;
  122. end;
  123. procedure TGameInterface.KeyDown(var Key: TSDLKey; Shift: TSDLMod; unicode: UInt16);
  124. begin
  125. end;
  126. procedure TGameInterface.LoadSurfaces;
  127. begin
  128. Loaded := True;
  129. end;
  130. procedure TGameInterface.MouseDown(Button: Integer; Shift: TSDLMod; MousePos: TPoint);
  131. begin
  132. Dragging := True;
  133. end;
  134. procedure TGameInterface.MouseMove(Shift: TSDLMod; CurrentPos, RelativePos: TPoint);
  135. begin
  136. end;
  137. procedure TGameInterface.MouseUp(Button: Integer; Shift: TSDLMod; MousePos: TPoint);
  138. begin
  139. Dragging := True;
  140. end;
  141. procedure TGameInterface.MouseWheelScroll(WheelDelta: Integer; Shift: TSDLMod; MousePos: TPoint);
  142. begin
  143. end;
  144. function TGameInterface.PointIsInRect( Point : TPoint; x, y, x1, y1: integer ): Boolean;
  145. begin
  146. if ( Point.x >= x )
  147. and ( Point.y >= y )
  148. and ( Point.x <= x1 )
  149. and ( Point.y <= y1 ) then
  150. result := true
  151. else
  152. result := false;
  153. end;
  154. procedure TGameInterface.ResetInputManager;
  155. begin
  156. MainWindow.InputManager.Mouse.OnMouseDown := MouseDown;
  157. MainWindow.InputManager.Mouse.OnMouseMove := MouseMove;
  158. MainWindow.InputManager.Mouse.OnMouseUp := MouseUp;
  159. MainWindow.InputManager.Mouse.OnMouseWheel := MouseWheelScroll;
  160. MainWindow.InputManager.KeyBoard.OnKeyDown := KeyDown;
  161. MainWindow.OnRender := Render;
  162. MainWindow.OnClose := Close;
  163. MainWindow.OnUpdate := Update;
  164. end;
  165. procedure TGameInterface.Update(aElapsedTime: single);
  166. begin
  167. end;
  168. end.