SDL_render_ngage.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. #include "../../events/SDL_keyboard_c.h"
  22. #include "../SDL_sysrender.h"
  23. #include "SDL_internal.h"
  24. #include "SDL_render_ngage_c.h"
  25. #ifdef __cplusplus
  26. }
  27. #endif
  28. #ifdef SDL_VIDEO_RENDER_NGAGE
  29. #include "SDL_render_ngage_c.hpp"
  30. #include "SDL_render_ops.hpp"
  31. const TUint32 WindowClientHandle = 0x571D0A;
  32. extern CRenderer *gRenderer;
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. void NGAGE_Clear(const Uint32 color)
  37. {
  38. gRenderer->Clear(color);
  39. }
  40. bool NGAGE_Copy(SDL_Renderer *renderer, SDL_Texture *texture, SDL_Rect *srcrect, SDL_Rect *dstrect)
  41. {
  42. return gRenderer->Copy(renderer, texture, srcrect, dstrect);
  43. }
  44. bool NGAGE_CopyEx(SDL_Renderer *renderer, SDL_Texture *texture, NGAGE_CopyExData *copydata)
  45. {
  46. return gRenderer->CopyEx(renderer, texture, copydata);
  47. }
  48. bool NGAGE_CreateTextureData(NGAGE_TextureData *data, const int width, const int height)
  49. {
  50. return gRenderer->CreateTextureData(data, width, height);
  51. }
  52. void NGAGE_DestroyTextureData(NGAGE_TextureData *data)
  53. {
  54. if (data) {
  55. delete data->bitmap;
  56. data->bitmap = NULL;
  57. }
  58. }
  59. void NGAGE_DrawLines(NGAGE_Vertex *verts, const int count)
  60. {
  61. gRenderer->DrawLines(verts, count);
  62. }
  63. void NGAGE_DrawPoints(NGAGE_Vertex *verts, const int count)
  64. {
  65. gRenderer->DrawPoints(verts, count);
  66. }
  67. void NGAGE_FillRects(NGAGE_Vertex *verts, const int count)
  68. {
  69. gRenderer->FillRects(verts, count);
  70. }
  71. void NGAGE_Flip()
  72. {
  73. gRenderer->Flip();
  74. }
  75. void NGAGE_SetClipRect(const SDL_Rect *rect)
  76. {
  77. gRenderer->SetClipRect(rect->x, rect->y, rect->w, rect->h);
  78. }
  79. void NGAGE_SetDrawColor(const Uint32 color)
  80. {
  81. if (gRenderer) {
  82. gRenderer->SetDrawColor(color);
  83. }
  84. }
  85. void NGAGE_PumpEventsInternal()
  86. {
  87. gRenderer->PumpEvents();
  88. }
  89. void NGAGE_SuspendScreenSaverInternal(bool suspend)
  90. {
  91. gRenderer->SuspendScreenSaver(suspend);
  92. }
  93. #ifdef __cplusplus
  94. }
  95. #endif
  96. CRenderer *CRenderer::NewL()
  97. {
  98. CRenderer *self = new (ELeave) CRenderer();
  99. CleanupStack::PushL(self);
  100. self->ConstructL();
  101. CleanupStack::Pop(self);
  102. return self;
  103. }
  104. CRenderer::CRenderer() : iRenderer(0), iDirectScreen(0), iScreenGc(0), iWsSession(), iWsWindowGroup(), iWsWindowGroupID(0), iWsWindow(), iWsScreen(0), iWsEventStatus(), iWsEvent(), iShowFPS(EFalse), iFPS(0), iFont(0) {}
  105. CRenderer::~CRenderer()
  106. {
  107. delete iRenderer;
  108. iRenderer = 0;
  109. }
  110. void CRenderer::ConstructL()
  111. {
  112. TInt error = KErrNone;
  113. error = iWsSession.Connect();
  114. if (error != KErrNone) {
  115. SDL_Log("Failed to connect to window server: %d", error);
  116. User::Leave(error);
  117. }
  118. iWsScreen = new (ELeave) CWsScreenDevice(iWsSession);
  119. error = iWsScreen->Construct();
  120. if (error != KErrNone) {
  121. SDL_Log("Failed to construct screen device: %d", error);
  122. User::Leave(error);
  123. }
  124. iWsWindowGroup = RWindowGroup(iWsSession);
  125. error = iWsWindowGroup.Construct(WindowClientHandle);
  126. if (error != KErrNone) {
  127. SDL_Log("Failed to construct window group: %d", error);
  128. User::Leave(error);
  129. }
  130. iWsWindowGroup.SetOrdinalPosition(0);
  131. RProcess thisProcess;
  132. TParse exeName;
  133. exeName.Set(thisProcess.FileName(), NULL, NULL);
  134. TBuf<32> winGroupName;
  135. winGroupName.Append(0);
  136. winGroupName.Append(0);
  137. winGroupName.Append(0); // UID
  138. winGroupName.Append(0);
  139. winGroupName.Append(exeName.Name()); // Caption
  140. winGroupName.Append(0);
  141. winGroupName.Append(0); // DOC name
  142. iWsWindowGroup.SetName(winGroupName);
  143. iWsWindow = RWindow(iWsSession);
  144. error = iWsWindow.Construct(iWsWindowGroup, WindowClientHandle - 1);
  145. if (error != KErrNone) {
  146. SDL_Log("Failed to construct window: %d", error);
  147. User::Leave(error);
  148. }
  149. iWsWindow.SetBackgroundColor(KRgbWhite);
  150. iWsWindow.SetRequiredDisplayMode(EColor4K);
  151. iWsWindow.Activate();
  152. iWsWindow.SetSize(iWsScreen->SizeInPixels());
  153. iWsWindow.SetVisible(ETrue);
  154. iWsWindowGroupID = iWsWindowGroup.Identifier();
  155. TRAPD(errc, iRenderer = iRenderer->NewL());
  156. if (errc != KErrNone) {
  157. SDL_Log("Failed to create renderer: %d", errc);
  158. return;
  159. }
  160. iDirectScreen = CDirectScreenAccess::NewL(
  161. iWsSession,
  162. *(iWsScreen),
  163. iWsWindow, *this);
  164. // Select font.
  165. TFontSpec fontSpec(_L("LatinBold12"), 12);
  166. TInt errd = iWsScreen->GetNearestFontInTwips((CFont *&)iFont, fontSpec);
  167. if (errd != KErrNone) {
  168. SDL_Log("Failed to get font: %d", errd);
  169. return;
  170. }
  171. // Activate events.
  172. iWsEventStatus = KRequestPending;
  173. iWsSession.EventReady(&iWsEventStatus);
  174. DisableKeyBlocking();
  175. iIsFocused = ETrue;
  176. iShowFPS = EFalse;
  177. iSuspendScreenSaver = EFalse;
  178. if (!iDirectScreen->IsActive()) {
  179. TRAPD(err, iDirectScreen->StartL());
  180. if (KErrNone != err) {
  181. return;
  182. }
  183. iDirectScreen->ScreenDevice()->SetAutoUpdate(ETrue);
  184. }
  185. }
  186. void CRenderer::Restart(RDirectScreenAccess::TTerminationReasons aReason)
  187. {
  188. if (!iDirectScreen->IsActive()) {
  189. TRAPD(err, iDirectScreen->StartL());
  190. if (KErrNone != err) {
  191. return;
  192. }
  193. iDirectScreen->ScreenDevice()->SetAutoUpdate(ETrue);
  194. }
  195. }
  196. void CRenderer::AbortNow(RDirectScreenAccess::TTerminationReasons aReason)
  197. {
  198. if (iDirectScreen->IsActive()) {
  199. iDirectScreen->Cancel();
  200. }
  201. }
  202. void CRenderer::Clear(TUint32 iColor)
  203. {
  204. if (iRenderer && iRenderer->Gc()) {
  205. iRenderer->Gc()->SetBrushColor(iColor);
  206. iRenderer->Gc()->Clear();
  207. }
  208. }
  209. #ifdef __cplusplus
  210. extern "C" {
  211. #endif
  212. Uint32 NGAGE_ConvertColor(float r, float g, float b, float a, float color_scale)
  213. {
  214. TFixed ff = 255 << 16; // 255.f
  215. TFixed scalef = Real2Fix(color_scale);
  216. TFixed rf = Real2Fix(r);
  217. TFixed gf = Real2Fix(g);
  218. TFixed bf = Real2Fix(b);
  219. TFixed af = Real2Fix(a);
  220. rf = FixMul(rf, scalef);
  221. gf = FixMul(gf, scalef);
  222. bf = FixMul(bf, scalef);
  223. rf = SDL_clamp(rf, 0, ff);
  224. gf = SDL_clamp(gf, 0, ff);
  225. bf = SDL_clamp(bf, 0, ff);
  226. af = SDL_clamp(af, 0, ff);
  227. rf = FixMul(rf, ff) >> 16;
  228. gf = FixMul(gf, ff) >> 16;
  229. bf = FixMul(bf, ff) >> 16;
  230. af = FixMul(af, ff) >> 16;
  231. return (af << 24) | (bf << 16) | (gf << 8) | rf;
  232. }
  233. #ifdef __cplusplus
  234. }
  235. #endif
  236. bool CRenderer::Copy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, const SDL_Rect *dstrect)
  237. {
  238. if (!texture) {
  239. return false;
  240. }
  241. NGAGE_TextureData *phdata = (NGAGE_TextureData *)texture->internal;
  242. if (!phdata) {
  243. return false;
  244. }
  245. SDL_FColor *c = &texture->color;
  246. int w = phdata->surface->w;
  247. int h = phdata->surface->h;
  248. int pitch = phdata->surface->pitch;
  249. void *source = phdata->surface->pixels;
  250. void *dest;
  251. if (!source) {
  252. return false;
  253. }
  254. void *pixel_buffer_a = SDL_calloc(1, pitch * h);
  255. if (!pixel_buffer_a) {
  256. return false;
  257. }
  258. dest = pixel_buffer_a;
  259. void *pixel_buffer_b = SDL_calloc(1, pitch * h);
  260. if (!pixel_buffer_b) {
  261. SDL_free(pixel_buffer_a);
  262. return false;
  263. }
  264. if (c->a != 1.f || c->r != 1.f || c->g != 1.f || c->b != 1.f) {
  265. ApplyColorMod(dest, source, pitch, w, h, texture->color);
  266. source = dest;
  267. }
  268. float sx;
  269. float sy;
  270. SDL_GetRenderScale(renderer, &sx, &sy);
  271. if (sx != 1.f || sy != 1.f) {
  272. TFixed scale_x = Real2Fix(sx);
  273. TFixed scale_y = Real2Fix(sy);
  274. TFixed center_x = Int2Fix(w / 2);
  275. TFixed center_y = Int2Fix(h / 2);
  276. dest == pixel_buffer_a ? dest = pixel_buffer_b : dest = pixel_buffer_a;
  277. ApplyScale(dest, source, pitch, w, h, center_x, center_y, scale_x, scale_y);
  278. source = dest;
  279. }
  280. Mem::Copy(phdata->bitmap->DataAddress(), source, pitch * h);
  281. SDL_free(pixel_buffer_a);
  282. SDL_free(pixel_buffer_b);
  283. if (phdata->bitmap) {
  284. TRect aSource(TPoint(srcrect->x, srcrect->y), TSize(srcrect->w, srcrect->h));
  285. TPoint aDest(dstrect->x, dstrect->y);
  286. iRenderer->Gc()->BitBlt(aDest, phdata->bitmap, aSource);
  287. }
  288. return true;
  289. }
  290. bool CRenderer::CopyEx(SDL_Renderer *renderer, SDL_Texture *texture, const NGAGE_CopyExData *copydata)
  291. {
  292. NGAGE_TextureData *phdata = (NGAGE_TextureData *)texture->internal;
  293. if (!phdata) {
  294. return false;
  295. }
  296. SDL_FColor *c = &texture->color;
  297. int w = phdata->surface->w;
  298. int h = phdata->surface->h;
  299. int pitch = phdata->surface->pitch;
  300. void *source = phdata->surface->pixels;
  301. void *dest;
  302. if (!source) {
  303. return false;
  304. }
  305. void *pixel_buffer_a = SDL_calloc(1, pitch * h);
  306. if (!pixel_buffer_a) {
  307. return false;
  308. }
  309. dest = pixel_buffer_a;
  310. void *pixel_buffer_b = SDL_calloc(1, pitch * h);
  311. if (!pixel_buffer_a) {
  312. SDL_free(pixel_buffer_a);
  313. return false;
  314. }
  315. if (copydata->flip) {
  316. ApplyFlip(dest, source, pitch, w, h, copydata->flip);
  317. source = dest;
  318. }
  319. if (copydata->scale_x != 1.f || copydata->scale_y != 1.f) {
  320. dest == pixel_buffer_a ? dest = pixel_buffer_b : dest = pixel_buffer_a;
  321. ApplyScale(dest, source, pitch, w, h, copydata->center.x, copydata->center.y, copydata->scale_x, copydata->scale_y);
  322. source = dest;
  323. }
  324. if (copydata->angle) {
  325. dest == pixel_buffer_a ? dest = pixel_buffer_b : dest = pixel_buffer_a;
  326. ApplyRotation(dest, source, pitch, w, h, copydata->center.x, copydata->center.y, copydata->angle);
  327. source = dest;
  328. }
  329. if (c->a != 1.f || c->r != 1.f || c->g != 1.f || c->b != 1.f) {
  330. dest == pixel_buffer_a ? dest = pixel_buffer_b : dest = pixel_buffer_a;
  331. ApplyColorMod(dest, source, pitch, w, h, texture->color);
  332. source = dest;
  333. }
  334. Mem::Copy(phdata->bitmap->DataAddress(), source, pitch * h);
  335. SDL_free(pixel_buffer_a);
  336. SDL_free(pixel_buffer_b);
  337. if (phdata->bitmap) {
  338. TRect aSource(TPoint(copydata->srcrect.x, copydata->srcrect.y), TSize(copydata->srcrect.w, copydata->srcrect.h));
  339. TPoint aDest(copydata->dstrect.x, copydata->dstrect.y);
  340. iRenderer->Gc()->BitBlt(aDest, phdata->bitmap, aSource);
  341. }
  342. return true;
  343. }
  344. bool CRenderer::CreateTextureData(NGAGE_TextureData *aTextureData, const TInt aWidth, const TInt aHeight)
  345. {
  346. if (!aTextureData) {
  347. return false;
  348. }
  349. aTextureData->bitmap = new CFbsBitmap();
  350. if (!aTextureData->bitmap) {
  351. return false;
  352. }
  353. TInt error = aTextureData->bitmap->Create(TSize(aWidth, aHeight), EColor4K);
  354. if (error != KErrNone) {
  355. delete aTextureData->bitmap;
  356. aTextureData->bitmap = NULL;
  357. return false;
  358. }
  359. return true;
  360. }
  361. void CRenderer::DrawLines(NGAGE_Vertex *aVerts, const TInt aCount)
  362. {
  363. if (iRenderer && iRenderer->Gc()) {
  364. TPoint *aPoints = new TPoint[aCount];
  365. for (TInt i = 0; i < aCount; i++) {
  366. aPoints[i] = TPoint(aVerts[i].x, aVerts[i].y);
  367. }
  368. TUint32 aColor = (((TUint8)aVerts->color.a << 24) |
  369. ((TUint8)aVerts->color.b << 16) |
  370. ((TUint8)aVerts->color.g << 8) |
  371. (TUint8)aVerts->color.r);
  372. iRenderer->Gc()->SetPenColor(aColor);
  373. iRenderer->Gc()->DrawPolyLineNoEndPoint(aPoints, aCount);
  374. delete[] aPoints;
  375. }
  376. }
  377. void CRenderer::DrawPoints(NGAGE_Vertex *aVerts, const TInt aCount)
  378. {
  379. if (iRenderer && iRenderer->Gc()) {
  380. for (TInt i = 0; i < aCount; i++, aVerts++) {
  381. TUint32 aColor = (((TUint8)aVerts->color.a << 24) |
  382. ((TUint8)aVerts->color.b << 16) |
  383. ((TUint8)aVerts->color.g << 8) |
  384. (TUint8)aVerts->color.r);
  385. iRenderer->Gc()->SetPenColor(aColor);
  386. iRenderer->Gc()->Plot(TPoint(aVerts->x, aVerts->y));
  387. }
  388. }
  389. }
  390. void CRenderer::FillRects(NGAGE_Vertex *aVerts, const TInt aCount)
  391. {
  392. if (iRenderer && iRenderer->Gc()) {
  393. for (TInt i = 0; i < aCount; i++, aVerts++) {
  394. TPoint pos(aVerts[i].x, aVerts[i].y);
  395. TSize size(
  396. aVerts[i + 1].x,
  397. aVerts[i + 1].y);
  398. TRect rect(pos, size);
  399. TUint32 aColor = (((TUint8)aVerts->color.a << 24) |
  400. ((TUint8)aVerts->color.b << 16) |
  401. ((TUint8)aVerts->color.g << 8) |
  402. (TUint8)aVerts->color.r);
  403. iRenderer->Gc()->SetPenColor(aColor);
  404. iRenderer->Gc()->SetBrushColor(aColor);
  405. iRenderer->Gc()->DrawRect(rect);
  406. }
  407. }
  408. }
  409. void CRenderer::Flip()
  410. {
  411. if (!iRenderer) {
  412. SDL_Log("iRenderer is NULL.");
  413. return;
  414. }
  415. if (!iIsFocused) {
  416. return;
  417. }
  418. iRenderer->Gc()->UseFont(iFont);
  419. if (iShowFPS && iRenderer->Gc()) {
  420. UpdateFPS();
  421. TBuf<64> info;
  422. iRenderer->Gc()->SetPenStyle(CGraphicsContext::ESolidPen);
  423. iRenderer->Gc()->SetBrushStyle(CGraphicsContext::ENullBrush);
  424. iRenderer->Gc()->SetPenColor(KRgbCyan);
  425. TRect aTextRect(TPoint(3, 203 - iFont->HeightInPixels()), TSize(45, iFont->HeightInPixels() + 2));
  426. iRenderer->Gc()->SetBrushStyle(CGraphicsContext::ESolidBrush);
  427. iRenderer->Gc()->SetBrushColor(KRgbBlack);
  428. iRenderer->Gc()->DrawRect(aTextRect);
  429. // Draw messages.
  430. info.Format(_L("FPS: %d"), iFPS);
  431. iRenderer->Gc()->DrawText(info, TPoint(5, 203));
  432. } else {
  433. // This is a workaround that helps regulating the FPS.
  434. iRenderer->Gc()->DrawText(_L(""), TPoint(0, 0));
  435. }
  436. iRenderer->Gc()->DiscardFont();
  437. iRenderer->Flip(iDirectScreen);
  438. // Keep the backlight on.
  439. if (iSuspendScreenSaver) {
  440. User::ResetInactivityTime();
  441. }
  442. // Suspend the current thread for a short while.
  443. // Give some time to other threads and active objects.
  444. User::After(0);
  445. }
  446. void CRenderer::SetDrawColor(TUint32 iColor)
  447. {
  448. if (iRenderer && iRenderer->Gc()) {
  449. iRenderer->Gc()->SetPenColor(iColor);
  450. iRenderer->Gc()->SetBrushColor(iColor);
  451. iRenderer->Gc()->SetBrushStyle(CGraphicsContext::ESolidBrush);
  452. TRAPD(err, iRenderer->SetCurrentColor(iColor));
  453. if (err != KErrNone) {
  454. return;
  455. }
  456. }
  457. }
  458. void CRenderer::SetClipRect(TInt aX, TInt aY, TInt aWidth, TInt aHeight)
  459. {
  460. if (iRenderer && iRenderer->Gc()) {
  461. TRect viewportRect(aX, aY, aX + aWidth, aY + aHeight);
  462. iRenderer->Gc()->SetClippingRect(viewportRect);
  463. }
  464. }
  465. void CRenderer::UpdateFPS()
  466. {
  467. static TTime lastTime;
  468. static TInt frameCount = 0;
  469. TTime currentTime;
  470. const TUint KOneSecond = 1000000; // 1s in ms.
  471. currentTime.HomeTime();
  472. ++frameCount;
  473. TTimeIntervalMicroSeconds timeDiff = currentTime.MicroSecondsFrom(lastTime);
  474. if (timeDiff.Int64() >= KOneSecond) {
  475. // Calculate FPS.
  476. iFPS = frameCount;
  477. // Reset frame count and last time.
  478. frameCount = 0;
  479. lastTime = currentTime;
  480. }
  481. }
  482. void CRenderer::SuspendScreenSaver(TBool aSuspend)
  483. {
  484. iSuspendScreenSaver = aSuspend;
  485. }
  486. static SDL_Scancode ConvertScancode(int key)
  487. {
  488. SDL_Keycode keycode;
  489. switch (key) {
  490. case EStdKeyBackspace: // Clear key
  491. keycode = SDLK_BACKSPACE;
  492. break;
  493. case 0x31: // 1
  494. keycode = SDLK_1;
  495. break;
  496. case 0x32: // 2
  497. keycode = SDLK_2;
  498. break;
  499. case 0x33: // 3
  500. keycode = SDLK_3;
  501. break;
  502. case 0x34: // 4
  503. keycode = SDLK_4;
  504. break;
  505. case 0x35: // 5
  506. keycode = SDLK_5;
  507. break;
  508. case 0x36: // 6
  509. keycode = SDLK_6;
  510. break;
  511. case 0x37: // 7
  512. keycode = SDLK_7;
  513. break;
  514. case 0x38: // 8
  515. keycode = SDLK_8;
  516. break;
  517. case 0x39: // 9
  518. keycode = SDLK_9;
  519. break;
  520. case 0x30: // 0
  521. keycode = SDLK_0;
  522. break;
  523. case 0x2a: // Asterisk
  524. keycode = SDLK_ASTERISK;
  525. break;
  526. case EStdKeyHash: // Hash
  527. keycode = SDLK_HASH;
  528. break;
  529. case EStdKeyDevice0: // Left softkey
  530. keycode = SDLK_SOFTLEFT;
  531. break;
  532. case EStdKeyDevice1: // Right softkey
  533. keycode = SDLK_SOFTRIGHT;
  534. break;
  535. case EStdKeyApplication0: // Call softkey
  536. keycode = SDLK_CALL;
  537. break;
  538. case EStdKeyApplication1: // End call softkey
  539. keycode = SDLK_ENDCALL;
  540. break;
  541. case EStdKeyDevice3: // Middle softkey
  542. keycode = SDLK_SELECT;
  543. break;
  544. case EStdKeyUpArrow: // Up arrow
  545. keycode = SDLK_UP;
  546. break;
  547. case EStdKeyDownArrow: // Down arrow
  548. keycode = SDLK_DOWN;
  549. break;
  550. case EStdKeyLeftArrow: // Left arrow
  551. keycode = SDLK_LEFT;
  552. break;
  553. case EStdKeyRightArrow: // Right arrow
  554. keycode = SDLK_RIGHT;
  555. break;
  556. default:
  557. keycode = SDLK_UNKNOWN;
  558. break;
  559. }
  560. return SDL_GetScancodeFromKey(keycode, NULL);
  561. }
  562. void CRenderer::HandleEvent(const TWsEvent &aWsEvent)
  563. {
  564. Uint64 timestamp;
  565. switch (aWsEvent.Type()) {
  566. case EEventKeyDown: /* Key events */
  567. timestamp = SDL_GetPerformanceCounter();
  568. SDL_SendKeyboardKey(timestamp, 1, aWsEvent.Key()->iCode, ConvertScancode(aWsEvent.Key()->iScanCode), true);
  569. if (aWsEvent.Key()->iScanCode == EStdKeyHash) {
  570. if (iShowFPS) {
  571. iShowFPS = EFalse;
  572. } else {
  573. iShowFPS = ETrue;
  574. }
  575. }
  576. break;
  577. case EEventKeyUp: /* Key events */
  578. timestamp = SDL_GetPerformanceCounter();
  579. SDL_SendKeyboardKey(timestamp, 1, aWsEvent.Key()->iCode, ConvertScancode(aWsEvent.Key()->iScanCode), false);
  580. case EEventFocusGained:
  581. DisableKeyBlocking();
  582. if (!iDirectScreen->IsActive()) {
  583. TRAPD(err, iDirectScreen->StartL());
  584. if (KErrNone != err) {
  585. return;
  586. }
  587. iDirectScreen->ScreenDevice()->SetAutoUpdate(ETrue);
  588. iIsFocused = ETrue;
  589. }
  590. Flip();
  591. break;
  592. case EEventFocusLost:
  593. {
  594. if (iDirectScreen->IsActive()) {
  595. iDirectScreen->Cancel();
  596. }
  597. iIsFocused = EFalse;
  598. break;
  599. }
  600. default:
  601. break;
  602. }
  603. }
  604. void CRenderer::DisableKeyBlocking()
  605. {
  606. TRawEvent aEvent;
  607. aEvent.Set((TRawEvent::TType) /*EDisableKeyBlock*/ 51);
  608. iWsSession.SimulateRawEvent(aEvent);
  609. }
  610. void CRenderer::PumpEvents()
  611. {
  612. while (iWsEventStatus != KRequestPending) {
  613. iWsSession.GetEvent(iWsEvent);
  614. HandleEvent(iWsEvent);
  615. iWsEventStatus = KRequestPending;
  616. iWsSession.EventReady(&iWsEventStatus);
  617. }
  618. }
  619. #endif // SDL_VIDEO_RENDER_NGAGE