1 /*
2 SDL - Simple DirectMedia Layer
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
18
19 */
20
21 /*
22
23 S60 application framework integration utilities.
24
25 Markus Mertama
26
27 When porting SDL to S60, CSDL should make it
28 very easy.- see c2doomexe sources for example.
29
30 */
31
32 #ifndef EPOC_SDL_H
33 #define EPOC_SDL_H
34
35 #include<e32base.h>
36
37
38 class CDesC8Array;
39 class TWsEvent;
40 class RWindow;
41 class CAknAppUi;
42 class RWsSession;
43 class CWsScreenDevice;
44 class CBitmapContext;
45 class CFbsBitmap;
46 class TRgb;
47
48
49
50
51 //internal stuff
52 //extern "C"
53 // {
54 typedef int (*mainfunc1) ();
55 typedef int (*mainfunc2) (int argc, char* argv[]);
56 typedef int (*mainfunc3) (int argc, char* argv[], char* env[]);
57 typedef void (*mainfunc4) ();
58 typedef void (*mainfunc5) (int argc, char* argv[]);
59 typedef void (*mainfunc6) (int argc, char* argv[], char* env[]);
60 // }
61
62 //internal stuff
63 extern "C"
64 {
65 int SDL_main (int argc, char* argv[]);
66 }
67
68 //internal stuff
NONSHARABLE_CLASS(TMainFunc)69 NONSHARABLE_CLASS(TMainFunc)
70 {
71 public:
72 IMPORT_C TMainFunc();
73 IMPORT_C TMainFunc(mainfunc1);
74 IMPORT_C TMainFunc(mainfunc2);
75 IMPORT_C TMainFunc(mainfunc3);
76 IMPORT_C TMainFunc(mainfunc4);
77 IMPORT_C TMainFunc(mainfunc5);
78 IMPORT_C TMainFunc(mainfunc6);
79 const void* operator[](TInt aIndex) const;
80 private:
81 void* iMainFunc[6];
82 };
83
84 /*Overlays add something be drawn on SDL screen Surface e.g. mouse cursor or virtual keyboard*/
NONSHARABLE_CLASS(MOverlay)85 NONSHARABLE_CLASS(MOverlay)
86 {
87 public:
88 virtual void Draw(CBitmapContext& aGc, const TRect& aTargetRect, const TSize& aSize) = 0;
89 };
90
91 /*If SDL screen Surface does not fit screen its scaled - MBlitter let user use more effient alogortihms*/
NONSHARABLE_CLASS(MBlitter)92 NONSHARABLE_CLASS(MBlitter)
93 {
94 public:
95 virtual TBool BitBlt(CBitmapContext& aGc, CFbsBitmap& aBmp, const TRect& aTargetRect, const TSize& aSize) = 0;
96 };
97
NONSHARABLE_CLASS(MSDLObserver)98 NONSHARABLE_CLASS(MSDLObserver)
99 {
100 public:
101 enum //these events indicates the state changes in SDL
102 {
103 EEventWindowReserved, //window is created, nothing else should use the window
104 EEventWindowNotAvailable, //window not available, can be ignored
105 EEventScreenSizeChanged, //screen size is changed
106 EEventSuspend, //SDL thread will be stopped next
107 EEventResume, //SDL thread resumed
108 EEventKeyMapInit, //Keymap is inited and can now be rewritten
109 EEventMainExit, //Main thread is about to exit
110 EEventVolumeChange, //New audio volume level. Maximum is 256
111 EEventScreenSurfaceCreated //SDL screen surface is created
112 };
113
114 virtual TInt SdlEvent(TInt aEvent, TInt aParam) = 0; //event is called in application thread
115 virtual TInt SdlThreadEvent(TInt aEvent, TInt aParam) = 0; //event is called in SDL thread
116 };
117
118
119 class CSDL : public CBase
120 {
121 public:
122 enum TFlags //these flags set SDL modes
123 {
124 ENoFlags = 0x0,
125 EEnableFocusStop = 0x1, //let SDL thread to be stopped if not on top
126 EDrawModeDSB = 0x2, //Depricated, Default drawmode is DSA, but if you request a antitearing this flag may help
127 EAllowImageResize = 0x4, //image is resized if requested image does not fit to screen
128 EDrawModeDSBDoubleBuffer = 0xA, //Depricated
129 EDrawModeDSBIncrementalUpdate = 0x12, //Depricated
130 EAllowImageResizeKeepRatio = 0x24,
131 EDrawModeGdi = 0x40, //Depricated, use BITGDI surface instead of Direct Screen Access
132 EDrawModeDSBAsync = 0x82, //Depricated, set DSB to drawn asynchrounsuly, all frames may not be viewed
133 EOwnThread = 0x1000, //always put SDL running its own thread. Has issues, plz avoid if possible :-)
134 EMainThread = 0x2000, //always put SDL in application thread. Default
135 EImageResizeZoomOut = 0x4000, //Zooms automatically if screen surface is smaller that given window.
136 EAutoOrientation = 0x8000, //set orientation automatically if either of dimension requests to window size, affects only if TAppOrientation is EDefault
137 EDisableVolumeKeys =0x10000, //Volumekeys does not affect to audio
138 };
139
140 enum TOrientationMode
141 {
142 EOrientation0,
143 EOrientation90,
144 EOrientation180,
145 EOrientation270
146 };
147 enum TParamFlags
148 {
149 ENoParamFlags = 0x0,
150 ERequestResume = 0x1, //The SDL thread is not running until a RThread::Resume is explicitly called for it
151 //also if SDL running in same thread
152 //then ERequestResume has no effect
153 };
154
155 enum TAppOrientation
156 {
157 EDefaultAppOrientation = 0, //system default - SDL default
158 ELandscapeAppOrientation, // set system landcape, overrides EAutoOrientation
159 EPortraitAppOrientation // set system portrait, overrides EAutoOrientation
160 };
161
162 IMPORT_C static CSDL* NewL(TInt aFlags = CSDL::ENoFlags);
163 IMPORT_C MSDLObserver* Observer(); //get current observer
164 IMPORT_C void SetObserver(MSDLObserver* aObserver); //set observer to receive events, if NULL then observer is removed
165 IMPORT_C void SetContainerWindowL(RWindow& aWindow, RWsSession& aSession, CWsScreenDevice& aDevice); //the window where drawn happens, should be recalled (propably in application HandleResourceChange) if screen device changes
166 IMPORT_C void DisableKeyBlocking(CAknAppUi& aAppUi) const;
167 IMPORT_C void SetAppOrientation(CAknAppUi& aAppUi, TAppOrientation aAppOrientation); //Set application orientation
168 IMPORT_C ~CSDL();
169 IMPORT_C TInt AppendWsEvent(const TWsEvent& aEvent); //give event to SDL, return error code if event buffer is full (insert in application HandleWsEvent)
170 IMPORT_C TInt GetSDLCode(TInt aScanCode); //get SDL internal key code bind to given scancode, return -1 if scancode is not found, aScancode must be postive number
171 IMPORT_C TInt SetSDLCode(TInt aScanCode, TInt aSDLCode); //set internal SDL code with given key code, return replaced code
172 IMPORT_C TInt SDLCodesCount() const; //return count of scancodes
173 IMPORT_C void ResetSDLCodes(); //rest all code replacement to their initial values
174 IMPORT_C void SetOrientation(TOrientationMode aMode); //rotate screen and arrow keys - does not affect to screen dimensions.
175 IMPORT_C void Resume(); //Resumes SDL
176 IMPORT_C void Suspend(); //Stops SDL
177 IMPORT_C TInt SetBlitter(MBlitter* aBlitter); //set an alternative blitting function, useful e.g. when scaling is needed (EAllowImageResize used) and default implementation is too slow. Without scaling default is fast.
178 IMPORT_C TInt AppendOverlay(MOverlay& aOverlay, TInt aPriority);
179 IMPORT_C TInt RemoveOverlay(MOverlay& aOverlay);
180 IMPORT_C TInt RedrawRequest(); //Asks surface blit refresh
181
182 IMPORT_C void ChangeBgColor(TRgb& aColor); //in new color - out old color. The color that is used for Wipe and background if SDL screen surface does not fill whole screen
183 IMPORT_C void SuspendRequestsLC(TInt aRunFirst = CActive::EPriorityIdle); //Prevents SDL stray signals, for mixing SDL and Symbian AOs.
184
185 inline TThreadId CallMainL(TRequestStatus& aStatus, TInt aFlags = CSDL::ENoParamFlags, TInt aStackSize = KDefaultStackSize); //call SDL main() function
186 inline TThreadId CallMainL(TRequestStatus& aStatus, const CDesC8Array& iArg, TInt aFlags = CSDL::ENoParamFlags, TInt aStackSize = KDefaultStackSize); //call SDL main(int argc, char* argv[]) function with given parameters
187 inline TThreadId CallMainL(TInt aFlags = CSDL::ENoParamFlags, TInt aStackSize = KDefaultStackSize); //call SDL main() function
188 inline TThreadId CallMainL(const CDesC8Array& iArg, TInt aFlags = CSDL::ENoParamFlags, TInt aStackSize = KDefaultStackSize); //call SDL main(int argc, char* argv[]) function with given parameters
189 IMPORT_C void SDLPanic(const TDesC& aInfo, TInt aErr); //Panic from SDL thread (see SDLThreadEvent)
190 public:
191 IMPORT_C TThreadId CallMainL(const TMainFunc& aFunc, TRequestStatus* const aStatus, const CDesC8Array* const iArg, TInt aFlags, TInt aStackSize); //internal
192 IMPORT_C TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1);
193 //this is a pretty useless function, just example of using Extension_
194 inline TInt BuildDate(TDes& aDes) const;
195 // inline TInt BitGdiCanvas() const;
196
197 protected:
198 IMPORT_C CSDL();
199 };
200
201
CallMainL(TRequestStatus & aStatus,TInt aFlags,TInt aStackSize)202 inline TThreadId CSDL::CallMainL(TRequestStatus& aStatus, TInt aFlags, TInt aStackSize)
203 {
204 return CallMainL(TMainFunc(SDL_main), &aStatus, NULL, aFlags, aStackSize);
205 }
206
CallMainL(TRequestStatus & aStatus,const CDesC8Array & iArg,TInt aFlags,TInt aStackSize)207 inline TThreadId CSDL::CallMainL(TRequestStatus& aStatus, const CDesC8Array& iArg, TInt aFlags, TInt aStackSize)
208 {
209 return CallMainL(TMainFunc(SDL_main), &aStatus, &iArg, aFlags, aStackSize);
210 }
211
212
CallMainL(TInt aFlags,TInt aStackSize)213 inline TThreadId CSDL::CallMainL(TInt aFlags, TInt aStackSize)
214 {
215 return CallMainL(TMainFunc(SDL_main), NULL, NULL, aFlags, aStackSize);
216 }
217
CallMainL(const CDesC8Array & iArg,TInt aFlags,TInt aStackSize)218 inline TThreadId CSDL::CallMainL(const CDesC8Array& iArg, TInt aFlags, TInt aStackSize)
219 {
220 return CallMainL(TMainFunc(SDL_main), NULL, &iArg, aFlags, aStackSize);
221 }
222
223 const TInt KSDLExtensionBuildDate = 0x5544;
224 //const TInt KSDLExtensionBitGdiCanvas = 0x5545;
225
BuildDate(TDes & aDes)226 inline TInt CSDL::BuildDate(TDes& aDes) const
227 {
228 TAny* null = NULL;
229 return const_cast<CSDL*>(this)->Extension_(KSDLExtensionBuildDate, null, static_cast<TAny*>(&aDes));
230 }
231
232
233
234
235 #endif
236
237
238