Atlas - SDL_render_ngage.cpp

Home / ext / SDL / src / render / ngage Lines: 1 | Size: 22080 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2026 Sam Lantinga <[email protected]> 4 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any damages 7 arising from the use of this software. 8 9 Permission is granted to anyone to use this software for any purpose, 10 including commercial applications, and to alter it and redistribute it 11 freely, subject to the following restrictions: 12 13 1. The origin of this software must not be misrepresented; you must not 14 claim that you wrote the original software. If you use this software 15 in a product, an acknowledgment in the product documentation would be 16 appreciated but is not required. 17 2. Altered source versions must be plainly marked as such, and must not be 18 misrepresented as being the original software. 19 3. This notice may not be removed or altered from any source distribution. 20*/ 21#ifdef __cplusplus 22extern "C" { 23#endif 24 25#include "../../events/SDL_keyboard_c.h" 26#include "../SDL_sysrender.h" 27#include "SDL_internal.h" 28#include "SDL_render_ngage_c.h" 29 30#ifdef __cplusplus 31} 32#endif 33 34#ifdef SDL_VIDEO_RENDER_NGAGE 35 36#include "SDL_render_ngage_c.hpp" 37#include "SDL_render_ops.hpp" 38 39const TUint32 WindowClientHandle = 0x571D0A; 40 41extern CRenderer *gRenderer; 42 43#ifdef __cplusplus 44extern "C" { 45#endif 46 47void NGAGE_Clear(const Uint32 color) 48{ 49 gRenderer->Clear(color); 50} 51 52bool NGAGE_Copy(SDL_Renderer *renderer, SDL_Texture *texture, SDL_Rect *srcrect, SDL_Rect *dstrect) 53{ 54 return gRenderer->Copy(renderer, texture, srcrect, dstrect); 55} 56 57bool NGAGE_CopyEx(SDL_Renderer *renderer, SDL_Texture *texture, NGAGE_CopyExData *copydata) 58{ 59 return gRenderer->CopyEx(renderer, texture, copydata); 60} 61 62bool NGAGE_CreateTextureData(NGAGE_TextureData *data, const int width, const int height, const int access) 63{ 64 return gRenderer->CreateTextureData(data, width, height, access); 65} 66 67void NGAGE_DestroyTextureData(NGAGE_TextureData *data) 68{ 69 if (data) { 70 if (data->gc) { 71 delete data->gc; 72 data->gc = NULL; 73 } 74 if (data->device) { 75 delete data->device; 76 data->device = NULL; 77 } 78 delete data->bitmap; 79 data->bitmap = NULL; 80 } 81} 82 83void *NGAGE_GetBitmapDataAddress(NGAGE_TextureData *data) 84{ 85 if (!data || !data->bitmap) { 86 return NULL; 87 } 88 return data->bitmap->DataAddress(); 89} 90 91void NGAGE_DrawLines(NGAGE_Vertex *verts, const int count) 92{ 93 gRenderer->DrawLines(verts, count); 94} 95 96void NGAGE_DrawPoints(NGAGE_Vertex *verts, const int count) 97{ 98 gRenderer->DrawPoints(verts, count); 99} 100 101void NGAGE_FillRects(NGAGE_Vertex *verts, const int count) 102{ 103 gRenderer->FillRects(verts, count); 104} 105 106void NGAGE_Flip() 107{ 108 gRenderer->Flip(); 109} 110 111void NGAGE_SetClipRect(const SDL_Rect *rect) 112{ 113 gRenderer->SetClipRect(rect->x, rect->y, rect->w, rect->h); 114} 115 116void NGAGE_SetDrawColor(const Uint32 color) 117{ 118 if (gRenderer) { 119 gRenderer->SetDrawColor(color); 120 } 121} 122 123void NGAGE_PumpEventsInternal() 124{ 125 gRenderer->PumpEvents(); 126} 127 128void NGAGE_SuspendScreenSaverInternal(bool suspend) 129{ 130 gRenderer->SuspendScreenSaver(suspend); 131} 132 133void NGAGE_SetRenderTargetInternal(NGAGE_TextureData *target) 134{ 135 if (gRenderer) { 136 gRenderer->SetRenderTarget(target); 137 } 138} 139 140#ifdef __cplusplus 141} 142#endif 143 144CRenderer *CRenderer::NewL() 145{ 146 CRenderer *self = new (ELeave) CRenderer(); 147 CleanupStack::PushL(self); 148 self->ConstructL(); 149 CleanupStack::Pop(self); 150 return self; 151} 152 153CRenderer::CRenderer() : iRenderer(0), iDirectScreen(0), iScreenGc(0), iWsSession(), iWsWindowGroup(), iWsWindowGroupID(0), iWsWindow(), iWsScreen(0), iWsEventStatus(), iWsEvent(), iShowFPS(EFalse), iFPS(0), iFont(0), iCurrentRenderTarget(0), iPixelBufferA(0), iPixelBufferB(0), iPixelBufferSize(0), iPointsBuffer(0), iPointsBufferSize(0) {} 154 155CRenderer::~CRenderer() 156{ 157 delete iRenderer; 158 iRenderer = 0; 159 160 SDL_free(iPixelBufferA); 161 SDL_free(iPixelBufferB); 162 delete[] iPointsBuffer; 163} 164 165void CRenderer::ConstructL() 166{ 167 TInt error = KErrNone; 168 169 error = iWsSession.Connect(); 170 if (error != KErrNone) { 171 SDL_Log("Failed to connect to window server: %d", error); 172 User::Leave(error); 173 } 174 175 iWsScreen = new (ELeave) CWsScreenDevice(iWsSession); 176 error = iWsScreen->Construct(); 177 if (error != KErrNone) { 178 SDL_Log("Failed to construct screen device: %d", error); 179 User::Leave(error); 180 } 181 182 iWsWindowGroup = RWindowGroup(iWsSession); 183 error = iWsWindowGroup.Construct(WindowClientHandle); 184 if (error != KErrNone) { 185 SDL_Log("Failed to construct window group: %d", error); 186 User::Leave(error); 187 } 188 iWsWindowGroup.SetOrdinalPosition(0); 189 190 RProcess thisProcess; 191 TParse exeName; 192 exeName.Set(thisProcess.FileName(), NULL, NULL); 193 TBuf<32> winGroupName; 194 winGroupName.Append(0); 195 winGroupName.Append(0); 196 winGroupName.Append(0); // UID 197 winGroupName.Append(0); 198 winGroupName.Append(exeName.Name()); // Caption 199 winGroupName.Append(0); 200 winGroupName.Append(0); // DOC name 201 iWsWindowGroup.SetName(winGroupName); 202 203 iWsWindow = RWindow(iWsSession); 204 error = iWsWindow.Construct(iWsWindowGroup, WindowClientHandle - 1); 205 if (error != KErrNone) { 206 SDL_Log("Failed to construct window: %d", error); 207 User::Leave(error); 208 } 209 iWsWindow.SetBackgroundColor(KRgbWhite); 210 iWsWindow.SetRequiredDisplayMode(EColor4K); 211 iWsWindow.Activate(); 212 iWsWindow.SetSize(iWsScreen->SizeInPixels()); 213 iWsWindow.SetVisible(ETrue); 214 215 iWsWindowGroupID = iWsWindowGroup.Identifier(); 216 217 TRAPD(errc, iRenderer = iRenderer->NewL()); 218 if (errc != KErrNone) { 219 SDL_Log("Failed to create renderer: %d", errc); 220 return; 221 } 222 223 iDirectScreen = CDirectScreenAccess::NewL( 224 iWsSession, 225 *(iWsScreen), 226 iWsWindow, *this); 227 228 // Select font. 229 TFontSpec fontSpec(_L("LatinBold12"), 12); 230 TInt errd = iWsScreen->GetNearestFontInTwips((CFont *&)iFont, fontSpec); 231 if (errd != KErrNone) { 232 SDL_Log("Failed to get font: %d", errd); 233 return; 234 } 235 236 // Activate events. 237 iWsEventStatus = KRequestPending; 238 iWsSession.EventReady(&iWsEventStatus); 239 240 DisableKeyBlocking(); 241 242 iIsFocused = ETrue; 243 iShowFPS = EFalse; 244 iSuspendScreenSaver = EFalse; 245 246 if (!iDirectScreen->IsActive()) { 247 TRAPD(err, iDirectScreen->StartL()); 248 if (KErrNone != err) { 249 return; 250 } 251 iDirectScreen->ScreenDevice()->SetAutoUpdate(ETrue); 252 } 253} 254 255void CRenderer::Restart(RDirectScreenAccess::TTerminationReasons aReason) 256{ 257 if (!iDirectScreen->IsActive()) { 258 TRAPD(err, iDirectScreen->StartL()); 259 if (KErrNone != err) { 260 return; 261 } 262 iDirectScreen->ScreenDevice()->SetAutoUpdate(ETrue); 263 } 264} 265 266void CRenderer::AbortNow(RDirectScreenAccess::TTerminationReasons aReason) 267{ 268 if (iDirectScreen->IsActive()) { 269 iDirectScreen->Cancel(); 270 } 271} 272 273void CRenderer::Clear(TUint32 iColor) 274{ 275 CFbsBitGc *gc = GetCurrentGc(); 276 if (gc) { 277 gc->SetBrushColor(iColor); 278 gc->Clear(); 279 } 280} 281 282#ifdef __cplusplus 283extern "C" { 284#endif 285 286Uint32 NGAGE_ConvertColor(float r, float g, float b, float a, float color_scale) 287{ 288 TFixed ff = 255 << 16; // 255.f 289 290 TFixed scalef = Real2Fix(color_scale); 291 TFixed rf = Real2Fix(r); 292 TFixed gf = Real2Fix(g); 293 TFixed bf = Real2Fix(b); 294 TFixed af = Real2Fix(a); 295 296 rf = FixMul(rf, scalef); 297 gf = FixMul(gf, scalef); 298 bf = FixMul(bf, scalef); 299 300 rf = SDL_clamp(rf, 0, ff); 301 gf = SDL_clamp(gf, 0, ff); 302 bf = SDL_clamp(bf, 0, ff); 303 af = SDL_clamp(af, 0, ff); 304 305 rf = FixMul(rf, ff) >> 16; 306 gf = FixMul(gf, ff) >> 16; 307 bf = FixMul(bf, ff) >> 16; 308 af = FixMul(af, ff) >> 16; 309 310 return (af << 24) | (bf << 16) | (gf << 8) | rf; 311} 312 313#ifdef __cplusplus 314} 315#endif 316 317bool CRenderer::Copy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, const SDL_Rect *dstrect) 318{ 319 if (!texture) { 320 return false; 321 } 322 323 NGAGE_TextureData *phdata = (NGAGE_TextureData *)texture->internal; 324 if (!phdata || !phdata->bitmap) { 325 return false; 326 } 327 328 SDL_FColor *c = &texture->color; 329 int w = texture->w; 330 int h = texture->h; 331 const int bytes_per_pixel = 2; 332 int pitch = w * bytes_per_pixel; 333 void *source = phdata->bitmap->DataAddress(); 334 void *dest; 335 336 if (!source) { 337 return false; 338 } 339 340 TInt required_size = pitch * h; 341 if (required_size > iPixelBufferSize) { 342 void *new_buffer_a = SDL_realloc(iPixelBufferA, required_size); 343 if (!new_buffer_a) { 344 return false; 345 } 346 iPixelBufferA = new_buffer_a; 347 348 void *new_buffer_b = SDL_realloc(iPixelBufferB, required_size); 349 if (!new_buffer_b) { 350 return false; 351 } 352 iPixelBufferB = new_buffer_b; 353 354 iPixelBufferSize = required_size; 355 } 356 357 dest = iPixelBufferA; 358 359 if (c->a != 1.f || c->r != 1.f || c->g != 1.f || c->b != 1.f) { 360 ApplyColorMod(dest, source, pitch, w, h, texture->color); 361 362 source = dest; 363 } 364 365 float sx; 366 float sy; 367 SDL_GetRenderScale(renderer, &sx, &sy); 368 369 if (sx != 1.f || sy != 1.f) { 370 TFixed scale_x = Real2Fix(sx); 371 TFixed scale_y = Real2Fix(sy); 372 TFixed center_x = Int2Fix(w / 2); 373 TFixed center_y = Int2Fix(h / 2); 374 375 dest == iPixelBufferA ? dest = iPixelBufferB : dest = iPixelBufferA; 376 377 ApplyScale(dest, source, pitch, w, h, center_x, center_y, scale_x, scale_y); 378 379 source = dest; 380 } 381 382 Mem::Copy(phdata->bitmap->DataAddress(), source, pitch * h); 383 384 if (phdata->bitmap) { 385 CFbsBitGc *gc = GetCurrentGc(); 386 if (gc) { 387 TRect aSource(TPoint(srcrect->x, srcrect->y), TSize(srcrect->w, srcrect->h)); 388 TPoint aDest(dstrect->x, dstrect->y); 389 gc->BitBlt(aDest, phdata->bitmap, aSource); 390 } 391 } 392 393 return true; 394} 395 396bool CRenderer::CopyEx(SDL_Renderer *renderer, SDL_Texture *texture, const NGAGE_CopyExData *copydata) 397{ 398 NGAGE_TextureData *phdata = (NGAGE_TextureData *)texture->internal; 399 if (!phdata || !phdata->bitmap) { 400 return false; 401 } 402 403 SDL_FColor *c = &texture->color; 404 int w = texture->w; 405 int h = texture->h; 406 const int bytes_per_pixel = 2; 407 int pitch = w * bytes_per_pixel; 408 void *source = phdata->bitmap->DataAddress(); 409 void *dest; 410 411 if (!source) { 412 return false; 413 } 414 415 TInt required_size = pitch * h; 416 if (required_size > iPixelBufferSize) { 417 void *new_buffer_a = SDL_realloc(iPixelBufferA, required_size); 418 if (!new_buffer_a) { 419 return false; 420 } 421 iPixelBufferA = new_buffer_a; 422 423 void *new_buffer_b = SDL_realloc(iPixelBufferB, required_size); 424 if (!new_buffer_b) { 425 return false; 426 } 427 iPixelBufferB = new_buffer_b; 428 429 iPixelBufferSize = required_size; 430 } 431 432 dest = iPixelBufferA; 433 434 if (copydata->flip) { 435 ApplyFlip(dest, source, pitch, w, h, copydata->flip); 436 source = dest; 437 } 438 439 if (copydata->scale_x != 1.f || copydata->scale_y != 1.f) { 440 dest == iPixelBufferA ? dest = iPixelBufferB : dest = iPixelBufferA; 441 ApplyScale(dest, source, pitch, w, h, copydata->center.x, copydata->center.y, copydata->scale_x, copydata->scale_y); 442 source = dest; 443 } 444 445 if (copydata->angle) { 446 dest == iPixelBufferA ? dest = iPixelBufferB : dest = iPixelBufferA; 447 ApplyRotation(dest, source, pitch, w, h, copydata->center.x, copydata->center.y, copydata->angle); 448 source = dest; 449 } 450 451 if (c->a != 1.f || c->r != 1.f || c->g != 1.f || c->b != 1.f) { 452 dest == iPixelBufferA ? dest = iPixelBufferB : dest = iPixelBufferA; 453 ApplyColorMod(dest, source, pitch, w, h, texture->color); 454 source = dest; 455 } 456 457 Mem::Copy(phdata->bitmap->DataAddress(), source, pitch * h); 458 459 if (phdata->bitmap) { 460 CFbsBitGc *gc = GetCurrentGc(); 461 if (gc) { 462 TRect aSource(TPoint(copydata->srcrect.x, copydata->srcrect.y), TSize(copydata->srcrect.w, copydata->srcrect.h)); 463 TPoint aDest(copydata->dstrect.x, copydata->dstrect.y); 464 gc->BitBlt(aDest, phdata->bitmap, aSource); 465 } 466 } 467 468 return true; 469} 470 471bool CRenderer::CreateTextureData(NGAGE_TextureData *aTextureData, const TInt aWidth, const TInt aHeight, const TInt aAccess) 472{ 473 if (!aTextureData) { 474 return false; 475 } 476 477 aTextureData->bitmap = new CFbsBitmap(); 478 if (!aTextureData->bitmap) { 479 return false; 480 } 481 482 TInt error = aTextureData->bitmap->Create(TSize(aWidth, aHeight), EColor4K); 483 if (error != KErrNone) { 484 delete aTextureData->bitmap; 485 aTextureData->bitmap = NULL; 486 return false; 487 } 488 489 if (aAccess == SDL_TEXTUREACCESS_TARGET) { 490 TRAPD(err1, aTextureData->device = CFbsBitmapDevice::NewL(aTextureData->bitmap)); 491 if (err1 != KErrNone || !aTextureData->device) { 492 delete aTextureData->bitmap; 493 aTextureData->bitmap = NULL; 494 return false; 495 } 496 497 TRAPD(err2, aTextureData->gc = CFbsBitGc::NewL()); 498 if (err2 != KErrNone || !aTextureData->gc) { 499 delete aTextureData->device; 500 aTextureData->device = NULL; 501 delete aTextureData->bitmap; 502 aTextureData->bitmap = NULL; 503 return false; 504 } 505 506 aTextureData->gc->Activate(aTextureData->device); 507 } else { 508 aTextureData->gc = NULL; 509 aTextureData->device = NULL; 510 } 511 512 return true; 513} 514 515void CRenderer::DrawLines(NGAGE_Vertex *aVerts, const TInt aCount) 516{ 517 CFbsBitGc *gc = GetCurrentGc(); 518 if (gc) { 519 gc->SetPenStyle(CGraphicsContext::ESolidPen); 520 521 // Draw lines as pairs of points (start, end) 522 for (TInt i = 0; i < aCount - 1; i += 2) { 523 TPoint start(aVerts[i].x, aVerts[i].y); 524 TPoint end(aVerts[i + 1].x, aVerts[i + 1].y); 525 526 TRgb color = TRgb(aVerts[i].color.r, aVerts[i].color.g, aVerts[i].color.b); 527 528 gc->SetPenColor(color); 529 gc->DrawLine(start, end); 530 } 531 } 532} 533 534void CRenderer::DrawPoints(NGAGE_Vertex *aVerts, const TInt aCount) 535{ 536 CFbsBitGc *gc = GetCurrentGc(); 537 if (gc) { 538 for (TInt i = 0; i < aCount; i++, aVerts++) { 539 TUint32 aColor = (((TUint8)aVerts->color.a << 24) | 540 ((TUint8)aVerts->color.b << 16) | 541 ((TUint8)aVerts->color.g << 8) | 542 (TUint8)aVerts->color.r); 543 544 gc->SetPenColor(aColor); 545 gc->Plot(TPoint(aVerts->x, aVerts->y)); 546 } 547 } 548} 549 550void CRenderer::FillRects(NGAGE_Vertex *aVerts, const TInt aCount) 551{ 552 CFbsBitGc *gc = GetCurrentGc(); 553 if (gc) { 554 for (TInt i = 0; i < aCount; i++, aVerts++) { 555 TPoint pos(aVerts[i].x, aVerts[i].y); 556 TSize size( 557 aVerts[i + 1].x, 558 aVerts[i + 1].y); 559 TRect rect(pos, size); 560 561 TUint32 aColor = (((TUint8)aVerts->color.a << 24) | 562 ((TUint8)aVerts->color.b << 16) | 563 ((TUint8)aVerts->color.g << 8) | 564 (TUint8)aVerts->color.r); 565 566 gc->SetPenColor(aColor); 567 gc->SetBrushColor(aColor); 568 gc->SetBrushStyle(CGraphicsContext::ESolidBrush); 569 gc->SetPenStyle(CGraphicsContext::ENullPen); 570 gc->DrawRect(rect); 571 } 572 } 573} 574 575void CRenderer::Flip() 576{ 577 if (!iRenderer) { 578 SDL_Log("iRenderer is NULL."); 579 return; 580 } 581 582 if (!iIsFocused) { 583 return; 584 } 585 586 iRenderer->Gc()->UseFont(iFont); 587 588 if (iShowFPS && iRenderer->Gc()) { 589 UpdateFPS(); 590 591 TBuf<64> info; 592 593 iRenderer->Gc()->SetPenStyle(CGraphicsContext::ESolidPen); 594 iRenderer->Gc()->SetBrushStyle(CGraphicsContext::ENullBrush); 595 iRenderer->Gc()->SetPenColor(KRgbCyan); 596 597 TRect aTextRect(TPoint(3, 203 - iFont->HeightInPixels()), TSize(45, iFont->HeightInPixels() + 2)); 598 iRenderer->Gc()->SetBrushStyle(CGraphicsContext::ESolidBrush); 599 iRenderer->Gc()->SetBrushColor(KRgbBlack); 600 iRenderer->Gc()->DrawRect(aTextRect); 601 602 // Draw messages. 603 info.Format(_L("FPS: %d"), iFPS); 604 iRenderer->Gc()->DrawText(info, TPoint(5, 203)); 605 } else { 606 // This is a workaround that helps regulating the FPS. 607 iRenderer->Gc()->DrawText(_L(""), TPoint(0, 0)); 608 } 609 iRenderer->Gc()->DiscardFont(); 610 iRenderer->Flip(iDirectScreen); 611 612 // Keep the backlight on. 613 if (iSuspendScreenSaver) { 614 User::ResetInactivityTime(); 615 } 616 // Suspend the current thread for a short while. 617 // Give some time to other threads and active objects. 618 User::After(0); 619} 620 621void CRenderer::SetDrawColor(TUint32 iColor) 622{ 623 CFbsBitGc *gc = GetCurrentGc(); 624 if (gc) { 625 gc->SetPenColor(iColor); 626 gc->SetBrushColor(iColor); 627 gc->SetBrushStyle(CGraphicsContext::ESolidBrush); 628 } 629 630 if (iRenderer) { 631 TRAPD(err, iRenderer->SetCurrentColor(iColor)); 632 if (err != KErrNone) { 633 return; 634 } 635 } 636} 637 638void CRenderer::SetClipRect(TInt aX, TInt aY, TInt aWidth, TInt aHeight) 639{ 640 CFbsBitGc *gc = GetCurrentGc(); 641 if (gc) { 642 TRect viewportRect(aX, aY, aX + aWidth, aY + aHeight); 643 gc->SetClippingRect(viewportRect); 644 } 645} 646 647void CRenderer::UpdateFPS() 648{ 649 static TTime lastTime; 650 static TInt frameCount = 0; 651 TTime currentTime; 652 const TUint KOneSecond = 1000000; // 1s in ms. 653 654 currentTime.HomeTime(); 655 ++frameCount; 656 657 TTimeIntervalMicroSeconds timeDiff = currentTime.MicroSecondsFrom(lastTime); 658 659 if (timeDiff.Int64() >= KOneSecond) { 660 // Calculate FPS. 661 iFPS = frameCount; 662 663 // Reset frame count and last time. 664 frameCount = 0; 665 lastTime = currentTime; 666 } 667} 668 669void CRenderer::SuspendScreenSaver(TBool aSuspend) 670{ 671 iSuspendScreenSaver = aSuspend; 672} 673 674void CRenderer::SetRenderTarget(NGAGE_TextureData *aTarget) 675{ 676 iCurrentRenderTarget = aTarget; 677} 678 679CFbsBitGc *CRenderer::GetCurrentGc() 680{ 681 if (iCurrentRenderTarget && iCurrentRenderTarget->gc) { 682 return iCurrentRenderTarget->gc; 683 } 684 return iRenderer ? iRenderer->Gc() : NULL; 685} 686 687static SDL_Scancode ConvertScancode(int key) 688{ 689 SDL_Keycode keycode; 690 691 switch (key) { 692 case EStdKeyBackspace: // Clear key 693 keycode = SDLK_BACKSPACE; 694 break; 695 case 0x31: // 1 696 keycode = SDLK_1; 697 break; 698 case 0x32: // 2 699 keycode = SDLK_2; 700 break; 701 case 0x33: // 3 702 keycode = SDLK_3; 703 break; 704 case 0x34: // 4 705 keycode = SDLK_4; 706 break; 707 case 0x35: // 5 708 keycode = SDLK_5; 709 break; 710 case 0x36: // 6 711 keycode = SDLK_6; 712 break; 713 case 0x37: // 7 714 keycode = SDLK_7; 715 break; 716 case 0x38: // 8 717 keycode = SDLK_8; 718 break; 719 case 0x39: // 9 720 keycode = SDLK_9; 721 break; 722 case 0x30: // 0 723 keycode = SDLK_0; 724 break; 725 case 0x2a: // Asterisk 726 keycode = SDLK_ASTERISK; 727 break; 728 case EStdKeyHash: // Hash 729 keycode = SDLK_HASH; 730 break; 731 case EStdKeyDevice0: // Left softkey 732 keycode = SDLK_SOFTLEFT; 733 break; 734 case EStdKeyDevice1: // Right softkey 735 keycode = SDLK_SOFTRIGHT; 736 break; 737 case EStdKeyApplication0: // Call softkey 738 keycode = SDLK_CALL; 739 break; 740 case EStdKeyApplication1: // End call softkey 741 keycode = SDLK_ENDCALL; 742 break; 743 case EStdKeyDevice3: // Middle softkey 744 keycode = SDLK_SELECT; 745 break; 746 case EStdKeyUpArrow: // Up arrow 747 keycode = SDLK_UP; 748 break; 749 case EStdKeyDownArrow: // Down arrow 750 keycode = SDLK_DOWN; 751 break; 752 case EStdKeyLeftArrow: // Left arrow 753 keycode = SDLK_LEFT; 754 break; 755 case EStdKeyRightArrow: // Right arrow 756 keycode = SDLK_RIGHT; 757 break; 758 default: 759 keycode = SDLK_UNKNOWN; 760 break; 761 } 762 763 return SDL_GetScancodeFromKey(keycode, NULL); 764} 765 766void CRenderer::HandleEvent(const TWsEvent &aWsEvent) 767{ 768 Uint64 timestamp; 769 770 switch (aWsEvent.Type()) { 771 case EEventKeyDown: /* Key events */ 772 timestamp = SDL_GetPerformanceCounter(); 773 SDL_SendKeyboardKey(timestamp, 1, aWsEvent.Key()->iCode, ConvertScancode(aWsEvent.Key()->iScanCode), true); 774 775 if (aWsEvent.Key()->iScanCode == EStdKeyHash) { 776 if (iShowFPS) { 777 iShowFPS = EFalse; 778 } else { 779 iShowFPS = ETrue; 780 } 781 } 782 783 break; 784 case EEventKeyUp: /* Key events */ 785 timestamp = SDL_GetPerformanceCounter(); 786 SDL_SendKeyboardKey(timestamp, 1, aWsEvent.Key()->iCode, ConvertScancode(aWsEvent.Key()->iScanCode), false); 787 788 break; 789 case EEventFocusGained: 790 DisableKeyBlocking(); 791 if (!iDirectScreen->IsActive()) { 792 TRAPD(err, iDirectScreen->StartL()); 793 if (KErrNone != err) { 794 return; 795 } 796 iDirectScreen->ScreenDevice()->SetAutoUpdate(ETrue); 797 iIsFocused = ETrue; 798 } 799 Flip(); 800 break; 801 case EEventFocusLost: 802 { 803 if (iDirectScreen->IsActive()) { 804 iDirectScreen->Cancel(); 805 } 806 807 iIsFocused = EFalse; 808 break; 809 } 810 default: 811 break; 812 } 813} 814 815void CRenderer::DisableKeyBlocking() 816{ 817 TRawEvent aEvent; 818 819 aEvent.Set((TRawEvent::TType) /*EDisableKeyBlock*/ 51); 820 iWsSession.SimulateRawEvent(aEvent); 821} 822 823void CRenderer::PumpEvents() 824{ 825 while (iWsEventStatus != KRequestPending) { 826 iWsSession.GetEvent(iWsEvent); 827 HandleEvent(iWsEvent); 828 iWsEventStatus = KRequestPending; 829 iWsSession.EventReady(&iWsEventStatus); 830 } 831} 832 833#endif // SDL_VIDEO_RENDER_NGAGE 834
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.