aboutsummaryrefslogtreecommitdiffstats
path: root/ServiceBasedPlugins/src/lib/JEDI-SDL/SDL/Pas/sdlgameinterface.pas
blob: 9a58ff40b1f6a6bf704854b99101d0dd0cb25b28 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
unit sdlgameinterface;
{
  $Id: sdlgameinterface.pas,v 1.4 2005/08/03 18:57:31 savage Exp $
  
}
{******************************************************************************}
{                                                                              }
{          JEDI-SDL : Pascal units for SDL - Simple DirectMedia Layer          }
{                    Game Interface Base class                                 }
{                                                                              }
{ The initial developer of this Pascal code was :                              }
{ Dominqiue Louis <Dominique@SavageSoftware.com.au>                            }
{                                                                              }
{ Portions created by Dominqiue Louis are                                      }
{ Copyright (C) 2000 - 2001 Dominqiue Louis.                                   }
{                                                                              }
{                                                                              }
{ Contributor(s)                                                               }
{ --------------                                                               }
{                                                                              }
{                                                                              }
{ Obtained through:                                                            }
{ Joint Endeavour of Delphi Innovators ( Project JEDI )                        }
{                                                                              }
{ You may retrieve the latest version of this file at the Project              }
{ JEDI home page, located at http://delphi-jedi.org                            }
{                                                                              }
{ The contents of this file are used with permission, subject to               }
{ the Mozilla Public License Version 1.1 (the "License"); you may              }
{ not use this file except in compliance with the License. You may             }
{ obtain a copy of the License at                                              }
{ http://www.mozilla.org/MPL/MPL-1.1.html                                      }
{                                                                              }
{ Software distributed under the License is distributed on an                  }
{ "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or               }
{ implied. See the License for the specific language governing                 }
{ rights and limitations under the License.                                    }
{                                                                              }
{ Description                                                                  }
{ -----------                                                                  }
{                                                                              }
{                                                                              }
{                                                                              }
{                                                                              }
{                                                                              }
{                                                                              }
{                                                                              }
{ Requires                                                                     }
{ --------                                                                     }
{   The SDL Runtime libraris on Win32  : SDL.dll on Linux : libSDL.so          }
{   They are available from...                                                 }
{   http://www.libsdl.org .                                                    }
{                                                                              }
{ Programming Notes                                                            }
{ -----------------                                                            }
{                                                                              }
{                                                                              }
{                                                                              }
{                                                                              }
{ Revision History                                                             }
{ ----------------                                                             }
{   September   23 2004 - DL : Initial Creation                                }
{
  $Log: sdlgameinterface.pas,v $
  Revision 1.4  2005/08/03 18:57:31  savage
  Various updates and additions. Mainly to handle OpenGL 3D Window support and better cursor support for the mouse class

  Revision 1.3  2004/10/17 18:41:49  savage
  Slight Change to allow Reseting of Input Event handlers

  Revision 1.2  2004/09/30 22:35:47  savage
  Changes, enhancements and additions as required to get SoAoS working.


}
{******************************************************************************}

interface

uses
  sdl,
  sdlwindow;

type
  TGameInterfaceClass = class of TGameInterface;

  TGameInterface = class( TObject )
  private
    FNextGameInterface : TGameInterfaceClass;
  protected
    Dragging : Boolean;
    Loaded : Boolean;
    procedure FreeSurfaces; virtual;
    procedure Render; virtual; abstract;
    procedure Close; virtual;
    procedure Update( aElapsedTime : single ); virtual; 
    procedure MouseDown( Button : Integer; Shift: TSDLMod; MousePos : TPoint ); virtual;
    procedure MouseMove( Shift: TSDLMod; CurrentPos : TPoint; RelativePos : TPoint ); virtual;
    procedure MouseUp( Button : Integer; Shift: TSDLMod; MousePos : TPoint ); virtual;
    procedure MouseWheelScroll( WheelDelta : Integer; Shift: TSDLMod; MousePos : TPoint ); virtual;
    procedure KeyDown( var Key: TSDLKey; Shift: TSDLMod; unicode : UInt16 ); virtual;
  public
    MainWindow : TSDLCustomWindow;
    procedure ResetInputManager;
    procedure LoadSurfaces; virtual;
    function PointIsInRect( Point : TPoint; x, y, x1, y1 : integer ) : Boolean;
    constructor Create( const aMainWindow : TSDLCustomWindow );
    destructor Destroy; override;
    property NextGameInterface : TGameInterfaceClass read FNextGameInterface write FNextGameInterface;
  end;

implementation

{ TGameInterface }
procedure TGameInterface.Close;
begin
  FNextGameInterface := nil;
end;

constructor TGameInterface.Create( const aMainWindow : TSDLCustomWindow );
begin
  inherited Create;
  MainWindow := aMainWindow;
  FNextGameInterface := TGameInterface;
  ResetInputManager;
end;

destructor TGameInterface.Destroy;
begin
  if Loaded then
    FreeSurfaces;
  inherited;
end;

procedure TGameInterface.FreeSurfaces;
begin
  Loaded := False;
end;

procedure TGameInterface.KeyDown(var Key: TSDLKey; Shift: TSDLMod; unicode: UInt16);
begin

end;

procedure TGameInterface.LoadSurfaces;
begin
  Loaded := True;
end;

procedure TGameInterface.MouseDown(Button: Integer; Shift: TSDLMod; MousePos: TPoint);
begin
  Dragging := True;
end;

procedure TGameInterface.MouseMove(Shift: TSDLMod; CurrentPos, RelativePos: TPoint);
begin

end;

procedure TGameInterface.MouseUp(Button: Integer; Shift: TSDLMod; MousePos: TPoint);
begin
  Dragging := True;
end;

procedure TGameInterface.MouseWheelScroll(WheelDelta: Integer; Shift: TSDLMod; MousePos: TPoint);
begin

end;

function TGameInterface.PointIsInRect( Point : TPoint; x, y, x1, y1: integer ): Boolean;
begin
  if ( Point.x >= x )
  and ( Point.y >= y )
  and ( Point.x <= x1 )
  and ( Point.y <= y1 ) then
    result := true
  else
    result := false;
end;

procedure TGameInterface.ResetInputManager;
var
  temp : TSDLNotifyEvent;
begin
  MainWindow.InputManager.Mouse.OnMouseDown := MouseDown;
  MainWindow.InputManager.Mouse.OnMouseMove := MouseMove;
  MainWindow.InputManager.Mouse.OnMouseUp := MouseUp;
  MainWindow.InputManager.Mouse.OnMouseWheel := MouseWheelScroll;
  MainWindow.InputManager.KeyBoard.OnKeyDown := KeyDown;
  temp := Render;
  MainWindow.OnRender := temp;
  temp := Close;
  MainWindow.OnClose := temp;
  MainWindow.OnUpdate := Update;
end;

procedure TGameInterface.Update(aElapsedTime: single);
begin

end;

end.