From 8447a3650e7de2fc780c1c354f70bf0d119622b3 Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Wed, 3 Jun 2009 23:36:23 +0000 Subject: Applying the temporary 16-bit SDL hack. svn-id: r41152 --- backends/platform/sdl/graphics.cpp | 96 +++++++++++++++++++++++++++++++++++++- backends/platform/sdl/sdl.cpp | 3 ++ backends/platform/sdl/sdl.h | 3 ++ 3 files changed, 100 insertions(+), 2 deletions(-) (limited to 'backends') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index 78b8bd8c63..389a7a0735 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -407,6 +407,20 @@ bool OSystem_SDL::loadGFXMode() { } } +#ifdef ENABLE_16BIT + // + // Create the surface that contains the 16 bit game data + // + _screen16 = SDL_CreateRGBSurface(SDL_SWSURFACE, _videoMode.screenWidth, _videoMode.screenHeight, + 16, + 0x7C00, + 0x3E0, + 0x1F, + 0); //555, not 565 + if (_screen16 == NULL) + error("allocating _screen16 failed"); +#endif + // // Create the surface used for the graphics in 16 bit before scaling, and also the overlay // @@ -484,10 +498,17 @@ bool OSystem_SDL::loadGFXMode() { } void OSystem_SDL::unloadGFXMode() { +#ifdef ENABLE_16BIT + if (_screen16) { + SDL_FreeSurface(_screen16); + _screen16 = NULL; + } +#else if (_screen) { SDL_FreeSurface(_screen); _screen = NULL; } +#endif if (_hwscreen) { SDL_FreeSurface(_hwscreen); @@ -519,14 +540,23 @@ void OSystem_SDL::unloadGFXMode() { } bool OSystem_SDL::hotswapGFXMode() { +#ifdef ENABLE_16BIT + if (!_screen16) +#else if (!_screen) +#endif return false; // Keep around the old _screen & _overlayscreen so we can restore the screen data // after the mode switch. +#ifdef ENABLE_16BIT + SDL_Surface *old_screen = _screen16; + _screen16 = NULL; +#else SDL_Surface *old_screen = _screen; - SDL_Surface *old_overlayscreen = _overlayscreen; _screen = NULL; +#endif + SDL_Surface *old_overlayscreen = _overlayscreen; _overlayscreen = NULL; // Release the HW screen surface @@ -544,7 +574,11 @@ bool OSystem_SDL::hotswapGFXMode() { if (!loadGFXMode()) { unloadGFXMode(); +#ifdef ENABLE_16BIT + _screen16 = old_screen; +#else _screen = old_screen; +#endif _overlayscreen = old_overlayscreen; return false; @@ -554,7 +588,11 @@ bool OSystem_SDL::hotswapGFXMode() { SDL_SetColors(_screen, _currentPalette, 0, 256); // Restore old screen content +#ifdef ENABLE_16BIT + SDL_BlitSurface(old_screen, NULL, _screen16, NULL); +#else SDL_BlitSurface(old_screen, NULL, _screen, NULL); +#endif SDL_BlitSurface(old_overlayscreen, NULL, _overlayscreen, NULL); // Free the old surfaces @@ -636,7 +674,11 @@ void OSystem_SDL::internUpdateScreen() { #endif if (!_overlayVisible) { +#ifdef ENABLE_16BIT + origSurf = _screen16; +#else origSurf = _screen; +#endif srcSurf = _tmpscreen; width = _videoMode.screenWidth; height = _videoMode.screenHeight; @@ -781,6 +823,12 @@ void OSystem_SDL::copyRectToScreen(const byte *src, int pitch, int x, int y, int assert (_transactionMode == kTransactionNone); assert(src); +#ifdef ENABLE_16BIT + if (_screen16 == NULL) { + warning("OSystem_SDL::copyRectToScreen: _screen16 == NULL"); + return; + } +#endif if (_screen == NULL) { warning("OSystem_SDL::copyRectToScreen: _screen == NULL"); return; @@ -829,11 +877,29 @@ void OSystem_SDL::copyRectToScreen(const byte *src, int pitch, int x, int y, int } // Try to lock the screen surface +#ifdef ENABLE_16BIT + if (SDL_LockSurface(_screen16) == -1) +#else if (SDL_LockSurface(_screen) == -1) +#endif error("SDL_LockSurface failed: %s", SDL_GetError()); - byte *dst = (byte *)_screen->pixels + y * _videoMode.screenWidth + x; +#ifdef ENABLE_16BIT + byte *dst = (byte *)_screen16->pixels + y * _videoMode.screenWidth * 2 + x * 2; + if (_videoMode.screenWidth == w && pitch == w * 2) { + memcpy(dst, src, h*w*2); + } else { + do { + memcpy(dst, src, w * 2); + src += pitch; + dst += _videoMode.screenWidth * 2; + } while (--h); + } + // Unlock the screen surface + SDL_UnlockSurface(_screen16); +#else + byte *dst = (byte *)_screen->pixels + y * _videoMode.screenWidth + x; if (_videoMode.screenWidth == pitch && pitch == w) { memcpy(dst, src, h*w); } else { @@ -846,6 +912,7 @@ void OSystem_SDL::copyRectToScreen(const byte *src, int pitch, int x, int y, int // Unlock the screen surface SDL_UnlockSurface(_screen); +#endif } Graphics::Surface *OSystem_SDL::lockScreen() { @@ -859,14 +926,26 @@ Graphics::Surface *OSystem_SDL::lockScreen() { _screenIsLocked = true; // Try to lock the screen surface +#ifdef ENABLE_16BIT + if (SDL_LockSurface(_screen16) == -1) +#else if (SDL_LockSurface(_screen) == -1) +#endif error("SDL_LockSurface failed: %s", SDL_GetError()); +#ifdef ENABLE_16BIT + _framebuffer.pixels = _screen16->pixels; + _framebuffer.w = _screen16->w; + _framebuffer.h = _screen16->h; + _framebuffer.pitch = _screen16->pitch; + _framebuffer.bytesPerPixel = 2; +#else _framebuffer.pixels = _screen->pixels; _framebuffer.w = _screen->w; _framebuffer.h = _screen->h; _framebuffer.pitch = _screen->pitch; _framebuffer.bytesPerPixel = 1; +#endif return &_framebuffer; } @@ -879,7 +958,11 @@ void OSystem_SDL::unlockScreen() { _screenIsLocked = false; // Unlock the screen surface +#ifdef ENABLE_16BIT + SDL_UnlockSurface(_screen16); +#else SDL_UnlockSurface(_screen); +#endif // Trigger a full screen update _forceFull = true; @@ -1054,8 +1137,13 @@ void OSystem_SDL::setPalette(const byte *colors, uint start, uint num) { // since we don't actually set the palette until the screen is updated. // But it could indicate a programming error, so let's warn about it. +#ifdef ENABLE_16BIT + if (!_screen16) + warning("OSystem_SDL::setPalette: _screen16 == NULL"); +#else if (!_screen) warning("OSystem_SDL::setPalette: _screen == NULL"); +#endif const byte *b = colors; uint i; @@ -1179,7 +1267,11 @@ void OSystem_SDL::clearOverlay() { dst.x = dst.y = 1; src.w = dst.w = _videoMode.screenWidth; src.h = dst.h = _videoMode.screenHeight; +#ifdef ENABLE_16BIT + if (SDL_BlitSurface(_screen16, &src, _tmpscreen, &dst) != 0) +#else if (SDL_BlitSurface(_screen, &src, _tmpscreen, &dst) != 0) +#endif error("SDL_BlitSurface failed: %s", SDL_GetError()); SDL_LockSurface(_tmpscreen); diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index c11c97c041..b91d6938a2 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -196,6 +196,9 @@ OSystem_SDL::OSystem_SDL() _osdSurface(0), _osdAlpha(SDL_ALPHA_TRANSPARENT), _osdFadeStartTime(0), #endif _hwscreen(0), _screen(0), _tmpscreen(0), +#ifdef ENABLE_16BIT + _screen16(0), +#endif _overlayVisible(false), _overlayscreen(0), _tmpscreen2(0), _samplesPerSec(0), diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index 7498f48b08..f843066749 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -227,6 +227,9 @@ protected: // unseen game screen SDL_Surface *_screen; +#ifdef ENABLE_16BIT + SDL_Surface *_screen16; +#endif // temporary screen (for scalers) SDL_Surface *_tmpscreen; -- cgit v1.2.3 From f8361b5c53b96faddb56024bb932ce46b7005dbf Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Fri, 5 Jun 2009 06:41:04 +0000 Subject: Converted cursor code to use 16-bit. svn-id: r41191 --- backends/platform/sdl/graphics.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'backends') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index 389a7a0735..1a80b9be19 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -1438,8 +1438,13 @@ void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, free(_mouseData); +#ifdef ENABLE_16BIT + _mouseData = (byte *)malloc(w * h * 2); + memcpy(_mouseData, buf, w * h * 2); +#else _mouseData = (byte *)malloc(w * h); memcpy(_mouseData, buf, w * h); +#endif blitCursor(); } @@ -1481,12 +1486,24 @@ void OSystem_SDL::blitCursor() { for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { color = *srcPtr; +#ifdef ENABLE_16BIT + if (color != _mouseKeyColor) { // transparent, don't draw + int8 r = ((*(uint16 *)srcPtr >> 10) & 0x1F) << 3; + int8 g = ((*(uint16 *)srcPtr >> 5) & 0x1F) << 3; + int8 b = (*(uint16 *)srcPtr & 0x1F) << 3; + *(uint16 *)dstPtr = SDL_MapRGB(_mouseOrigSurface->format, + r, g, b); + } + dstPtr += 2; + srcPtr += 2; +#else if (color != _mouseKeyColor) { // transparent, don't draw *(uint16 *)dstPtr = SDL_MapRGB(_mouseOrigSurface->format, palette[color].r, palette[color].g, palette[color].b); } dstPtr += 2; srcPtr++; +#endif } dstPtr += _mouseOrigSurface->pitch - w * 2; } -- cgit v1.2.3 From 9789ba7f28d2c0a093adda01435306f28e91fede Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Fri, 5 Jun 2009 08:09:37 +0000 Subject: Corrected backend to be able to accept a 16-bit mouseKeyColor without overflow svn-id: r41194 --- backends/platform/sdl/graphics.cpp | 47 ++++++++++++++++++++++++++++++++++---- backends/platform/sdl/sdl.h | 4 ++++ 2 files changed, 47 insertions(+), 4 deletions(-) (limited to 'backends') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index 1a80b9be19..fadd7a376c 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -1403,7 +1403,8 @@ void OSystem_SDL::warpMouse(int x, int y) { } } -void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor, int cursorTargetScale) { +#ifdef ENABLE_16BIT +void OSystem_SDL::setMouseCursor16(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint16 keycolor, int cursorTargetScale) { if (w == 0 || h == 0) return; @@ -1438,13 +1439,51 @@ void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, free(_mouseData); -#ifdef ENABLE_16BIT _mouseData = (byte *)malloc(w * h * 2); memcpy(_mouseData, buf, w * h * 2); -#else + + blitCursor(); +} +#endif + +void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor, int cursorTargetScale) { + if (w == 0 || h == 0) + return; + + _mouseCurState.hotX = hotspot_x; + _mouseCurState.hotY = hotspot_y; + + _mouseKeyColor = keycolor; + + _cursorTargetScale = cursorTargetScale; + + if (_mouseCurState.w != (int)w || _mouseCurState.h != (int)h) { + _mouseCurState.w = w; + _mouseCurState.h = h; + + if (_mouseOrigSurface) + SDL_FreeSurface(_mouseOrigSurface); + + // Allocate bigger surface because AdvMame2x adds black pixel at [0,0] + _mouseOrigSurface = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA, + _mouseCurState.w + 2, + _mouseCurState.h + 2, + 16, + _hwscreen->format->Rmask, + _hwscreen->format->Gmask, + _hwscreen->format->Bmask, + _hwscreen->format->Amask); + + if (_mouseOrigSurface == NULL) + error("allocating _mouseOrigSurface failed"); + SDL_SetColorKey(_mouseOrigSurface, SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA, kMouseColorKey); + } + + free(_mouseData); + _mouseData = (byte *)malloc(w * h); memcpy(_mouseData, buf, w * h); -#endif + blitCursor(); } diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index f843066749..3e0bf19f8f 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -112,6 +112,10 @@ public: virtual void warpMouse(int x, int y); // overloaded by CE backend (FIXME) // Set the bitmap that's used when drawing the cursor. +#ifdef ENABLE_16BIT + //HACK Made a second method as a quick and dirty workaround to avoid linker errors with engine libs + virtual void setMouseCursor16(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint16 keycolor, int cursorTargetScale); // overloaded by CE backend (FIXME) +#endif virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor, int cursorTargetScale); // overloaded by CE backend (FIXME) // Set colors of cursor palette -- cgit v1.2.3 From 56e5920bba753820c457c078237a8c06241302ed Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Sat, 6 Jun 2009 01:16:04 +0000 Subject: Corrected cursor display errors introduced by revision 41204, reimplemented 16-bit cursor support in a less hacky, but still temporary way. svn-id: r41209 --- backends/platform/sdl/graphics.cpp | 92 ++++++++++++++++---------------------- backends/platform/sdl/sdl.h | 10 +++-- 2 files changed, 45 insertions(+), 57 deletions(-) (limited to 'backends') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index fadd7a376c..8ecf4ecda1 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -1404,49 +1404,19 @@ void OSystem_SDL::warpMouse(int x, int y) { } #ifdef ENABLE_16BIT -void OSystem_SDL::setMouseCursor16(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint16 keycolor, int cursorTargetScale) { - if (w == 0 || h == 0) - return; - - _mouseCurState.hotX = hotspot_x; - _mouseCurState.hotY = hotspot_y; - - _mouseKeyColor = keycolor; - - _cursorTargetScale = cursorTargetScale; - - if (_mouseCurState.w != (int)w || _mouseCurState.h != (int)h) { - _mouseCurState.w = w; - _mouseCurState.h = h; - - if (_mouseOrigSurface) - SDL_FreeSurface(_mouseOrigSurface); - - // Allocate bigger surface because AdvMame2x adds black pixel at [0,0] - _mouseOrigSurface = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA, - _mouseCurState.w + 2, - _mouseCurState.h + 2, - 16, - _hwscreen->format->Rmask, - _hwscreen->format->Gmask, - _hwscreen->format->Bmask, - _hwscreen->format->Amask); - - if (_mouseOrigSurface == NULL) - error("allocating _mouseOrigSurface failed"); - SDL_SetColorKey(_mouseOrigSurface, SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA, kMouseColorKey); +void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale, uint8 bitDepth) { + uint32 colmask = 0xFF; + uint8 byteDepth = bitDepth >> 3; + for (int i = byteDepth; i > 1; i--) { + colmask <<= 8; + colmask |= 0xFF; } + keycolor &= colmask; - free(_mouseData); - - _mouseData = (byte *)malloc(w * h * 2); - memcpy(_mouseData, buf, w * h * 2); - - blitCursor(); -} +#else +void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor, int cursorTargetScale) { #endif -void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor, int cursorTargetScale) { if (w == 0 || h == 0) return; @@ -1480,14 +1450,24 @@ void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, } free(_mouseData); +#ifdef ENABLE_16BIT + _mouseData = (byte *)malloc(w * h * byteDepth); + memcpy(_mouseData, buf, w * h * byteDepth); + blitCursor(bitDepth); +#else _mouseData = (byte *)malloc(w * h); memcpy(_mouseData, buf, w * h); blitCursor(); +#endif } +#ifdef ENABLE_16BIT +void OSystem_SDL::blitCursor(uint8 bitDepth) { +#else void OSystem_SDL::blitCursor() { +#endif byte *dstPtr; const byte *srcPtr = _mouseData; byte color; @@ -1526,22 +1506,26 @@ void OSystem_SDL::blitCursor() { for (j = 0; j < w; j++) { color = *srcPtr; #ifdef ENABLE_16BIT - if (color != _mouseKeyColor) { // transparent, don't draw - int8 r = ((*(uint16 *)srcPtr >> 10) & 0x1F) << 3; - int8 g = ((*(uint16 *)srcPtr >> 5) & 0x1F) << 3; - int8 b = (*(uint16 *)srcPtr & 0x1F) << 3; - *(uint16 *)dstPtr = SDL_MapRGB(_mouseOrigSurface->format, - r, g, b); - } - dstPtr += 2; - srcPtr += 2; -#else - if (color != _mouseKeyColor) { // transparent, don't draw - *(uint16 *)dstPtr = SDL_MapRGB(_mouseOrigSurface->format, - palette[color].r, palette[color].g, palette[color].b); + if (bitDepth == 16) { + if (color != _mouseKeyColor) { // transparent, don't draw + int8 r = ((*(uint16 *)srcPtr >> 10) & 0x1F) << 3; + int8 g = ((*(uint16 *)srcPtr >> 5) & 0x1F) << 3; + int8 b = (*(uint16 *)srcPtr & 0x1F) << 3; + *(uint16 *)dstPtr = SDL_MapRGB(_mouseOrigSurface->format, + r, g, b); + } + dstPtr += 2; + srcPtr += 2; + } else { +#endif + if (color != _mouseKeyColor) { // transparent, don't draw + *(uint16 *)dstPtr = SDL_MapRGB(_mouseOrigSurface->format, + palette[color].r, palette[color].g, palette[color].b); + } + dstPtr += 2; + srcPtr++; +#ifdef ENABLE_16BIT } - dstPtr += 2; - srcPtr++; #endif } dstPtr += _mouseOrigSurface->pitch - w * 2; diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index 3e0bf19f8f..7d71ecb6ab 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -113,10 +113,10 @@ public: // Set the bitmap that's used when drawing the cursor. #ifdef ENABLE_16BIT - //HACK Made a second method as a quick and dirty workaround to avoid linker errors with engine libs - virtual void setMouseCursor16(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint16 keycolor, int cursorTargetScale); // overloaded by CE backend (FIXME) -#endif + virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale, uint8 bitDepth = 8); // overloaded by CE backend (FIXME) +#else virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor, int cursorTargetScale); // overloaded by CE backend (FIXME) +#endif // Set colors of cursor palette void setCursorPalette(const byte *colors, uint start, uint num); @@ -413,7 +413,11 @@ protected: virtual void drawMouse(); // overloaded by CE backend virtual void undrawMouse(); // overloaded by CE backend (FIXME) +#ifdef ENABLE_16BIT + virtual void blitCursor(uint8 bitDepth = 8); // overloaded by CE backend (FIXME) +#else virtual void blitCursor(); // overloaded by CE backend (FIXME) +#endif /** Set the position of the virtual mouse cursor. */ void setMousePos(int x, int y); -- cgit v1.2.3 From 4087a3e6e8ebc0b519fc4c178a29696bd64fdd6f Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Sat, 6 Jun 2009 08:02:45 +0000 Subject: Corrected 16-bit cursor blit errors on GFX mode change. svn-id: r41212 --- backends/platform/sdl/graphics.cpp | 18 +++++++++++++++++- backends/platform/sdl/sdl.cpp | 2 +- backends/platform/sdl/sdl.h | 7 +++++++ 3 files changed, 25 insertions(+), 2 deletions(-) (limited to 'backends') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index 8ecf4ecda1..81e137e19c 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -332,7 +332,11 @@ void OSystem_SDL::setGraphicsModeIntern() { // Even if the old and new scale factors are the same, we may have a // different scaler for the cursor now. +#ifdef ENABLE_16BIT + blitCursor(_cursorBitDepth); +#else blitCursor(); +#endif } int OSystem_SDL::getGraphicsMode() const { @@ -600,7 +604,11 @@ bool OSystem_SDL::hotswapGFXMode() { SDL_FreeSurface(old_overlayscreen); // Update cursor to new scale +#ifdef ENABLE_16BIT + blitCursor(_cursorBitDepth); +#else blitCursor(); +#endif // Blit everything to the screen internUpdateScreen(); @@ -1163,7 +1171,11 @@ void OSystem_SDL::setPalette(const byte *colors, uint start, uint num) { // Some games blink cursors with palette if (_cursorPaletteDisabled) +#ifdef ENABLE_16BIT + blitCursor(_cursorBitDepth); +#else blitCursor(); +#endif } void OSystem_SDL::grabPalette(byte *colors, uint start, uint num) { @@ -1192,7 +1204,11 @@ void OSystem_SDL::setCursorPalette(const byte *colors, uint start, uint num) { _cursorPaletteDisabled = false; +#ifdef ENABLE_16BIT + blitCursor(_cursorBitDepth); +#else blitCursor(); +#endif } void OSystem_SDL::setShakePos(int shake_pos) { @@ -1412,7 +1428,7 @@ void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, colmask |= 0xFF; } keycolor &= colmask; - + _cursorBitDepth = bitDepth; #else void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor, int cursorTargetScale) { #endif diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index b91d6938a2..3e8cefc86a 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -197,7 +197,7 @@ OSystem_SDL::OSystem_SDL() #endif _hwscreen(0), _screen(0), _tmpscreen(0), #ifdef ENABLE_16BIT - _screen16(0), + _screen16(0), _cursorBitDepth(8), #endif _overlayVisible(false), _overlayscreen(0), _tmpscreen2(0), diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index 7d71ecb6ab..b6b7a8b284 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -124,7 +124,11 @@ public: // Disables or enables cursor palette void disableCursorPalette(bool disable) { _cursorPaletteDisabled = disable; +#ifdef ENABLE_16BIT + blitCursor(_cursorBitDepth); +#else blitCursor(); +#endif } // Shaking is used in SCUMM. Set current shake position. @@ -354,6 +358,9 @@ protected: MousePos _mouseCurState; byte _mouseKeyColor; int _cursorTargetScale; +#ifdef ENABLE_16BIT + uint8 _cursorBitDepth; +#endif bool _cursorPaletteDisabled; SDL_Surface *_mouseOrigSurface; SDL_Surface *_mouseSurface; -- cgit v1.2.3 From 0323638ce933e1dea7dd81b35a6646a9773a01ea Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Sat, 6 Jun 2009 08:41:03 +0000 Subject: Streamlined the cursor blitting changes introduced in revision 41412 svn-id: r41213 --- backends/platform/sdl/graphics.cpp | 26 ++------------------------ backends/platform/sdl/sdl.h | 8 -------- 2 files changed, 2 insertions(+), 32 deletions(-) (limited to 'backends') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index 81e137e19c..2872c71f44 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -332,11 +332,7 @@ void OSystem_SDL::setGraphicsModeIntern() { // Even if the old and new scale factors are the same, we may have a // different scaler for the cursor now. -#ifdef ENABLE_16BIT - blitCursor(_cursorBitDepth); -#else blitCursor(); -#endif } int OSystem_SDL::getGraphicsMode() const { @@ -604,11 +600,7 @@ bool OSystem_SDL::hotswapGFXMode() { SDL_FreeSurface(old_overlayscreen); // Update cursor to new scale -#ifdef ENABLE_16BIT - blitCursor(_cursorBitDepth); -#else blitCursor(); -#endif // Blit everything to the screen internUpdateScreen(); @@ -1171,11 +1163,7 @@ void OSystem_SDL::setPalette(const byte *colors, uint start, uint num) { // Some games blink cursors with palette if (_cursorPaletteDisabled) -#ifdef ENABLE_16BIT - blitCursor(_cursorBitDepth); -#else blitCursor(); -#endif } void OSystem_SDL::grabPalette(byte *colors, uint start, uint num) { @@ -1204,11 +1192,7 @@ void OSystem_SDL::setCursorPalette(const byte *colors, uint start, uint num) { _cursorPaletteDisabled = false; -#ifdef ENABLE_16BIT - blitCursor(_cursorBitDepth); -#else blitCursor(); -#endif } void OSystem_SDL::setShakePos(int shake_pos) { @@ -1469,21 +1453,15 @@ void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, #ifdef ENABLE_16BIT _mouseData = (byte *)malloc(w * h * byteDepth); memcpy(_mouseData, buf, w * h * byteDepth); - - blitCursor(bitDepth); #else _mouseData = (byte *)malloc(w * h); memcpy(_mouseData, buf, w * h); +#endif blitCursor(); -#endif } -#ifdef ENABLE_16BIT -void OSystem_SDL::blitCursor(uint8 bitDepth) { -#else void OSystem_SDL::blitCursor() { -#endif byte *dstPtr; const byte *srcPtr = _mouseData; byte color; @@ -1522,7 +1500,7 @@ void OSystem_SDL::blitCursor() { for (j = 0; j < w; j++) { color = *srcPtr; #ifdef ENABLE_16BIT - if (bitDepth == 16) { + if (_cursorBitDepth == 16) { if (color != _mouseKeyColor) { // transparent, don't draw int8 r = ((*(uint16 *)srcPtr >> 10) & 0x1F) << 3; int8 g = ((*(uint16 *)srcPtr >> 5) & 0x1F) << 3; diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index b6b7a8b284..6fe871fa83 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -124,11 +124,7 @@ public: // Disables or enables cursor palette void disableCursorPalette(bool disable) { _cursorPaletteDisabled = disable; -#ifdef ENABLE_16BIT - blitCursor(_cursorBitDepth); -#else blitCursor(); -#endif } // Shaking is used in SCUMM. Set current shake position. @@ -420,11 +416,7 @@ protected: virtual void drawMouse(); // overloaded by CE backend virtual void undrawMouse(); // overloaded by CE backend (FIXME) -#ifdef ENABLE_16BIT - virtual void blitCursor(uint8 bitDepth = 8); // overloaded by CE backend (FIXME) -#else virtual void blitCursor(); // overloaded by CE backend (FIXME) -#endif /** Set the position of the virtual mouse cursor. */ void setMousePos(int x, int y); -- cgit v1.2.3 From c426dd99a4c4149418fa16996e38f0995ddcaea5 Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Tue, 9 Jun 2009 07:55:43 +0000 Subject: Laying the foundation for preliminary bitdepth negotiation. (No functionality changes yet) svn-id: r41396 --- backends/platform/sdl/sdl.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'backends') diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index 6fe871fa83..22d3d41b00 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -178,6 +178,12 @@ public: // Overlay virtual Graphics::PixelFormat getOverlayFormat() const { return _overlayFormat; } + +#ifdef ENABLE_16BIT + // Game screen + virtual Graphics::PixelFormat getScreenFormat() const { return _screenFormat; } +#endif + virtual void showOverlay(); virtual void hideOverlay(); virtual void clearOverlay(); @@ -232,7 +238,12 @@ protected: // unseen game screen SDL_Surface *_screen; #ifdef ENABLE_16BIT - SDL_Surface *_screen16; + Graphics::PixelFormat _screenFormat; + + //HACK This is a temporary hack to get 16-bit graphics + //displaying quickly, which will be removed in favor of + //configuring the format of _screen on a per-game basis + SDL_Surface *_screen16; #endif // temporary screen (for scalers) -- cgit v1.2.3 From 0a793f08a4d198f3f766214ed4ce85ac51ccea5e Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Wed, 10 Jun 2009 05:35:18 +0000 Subject: SDL backend now dynamically generates 8 or 16-bit color surface depending on engine request (using ad-hoc format). svn-id: r41416 --- backends/platform/sdl/graphics.cpp | 244 ++++++++++++++++++++++++------------- backends/platform/sdl/sdl.cpp | 3 +- backends/platform/sdl/sdl.h | 32 +++-- 3 files changed, 182 insertions(+), 97 deletions(-) (limited to 'backends') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index 2872c71f44..142fa94dba 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -97,6 +97,9 @@ void OSystem_SDL::beginGFXTransaction(void) { _transactionDetails.needUpdatescreen = false; _transactionDetails.normal1xScaler = false; +#ifdef ENABLE_16BIT + _transactionDetails.formatChanged = false; +#endif _oldVideoMode = _videoMode; } @@ -127,6 +130,12 @@ OSystem::TransactionError OSystem_SDL::endGFXTransaction(void) { _videoMode.screenHeight = _oldVideoMode.screenHeight; _videoMode.overlayWidth = _oldVideoMode.overlayWidth; _videoMode.overlayHeight = _oldVideoMode.overlayHeight; +#ifdef ENABLE_16BIT + } else if (_videoMode.format != _oldVideoMode.format) { + errors |= kTransactionPixelFormatNotSupported; + + _videoMode.format = _oldVideoMode.format; +#endif } if (_videoMode.fullscreen == _oldVideoMode.fullscreen && @@ -143,6 +152,32 @@ OSystem::TransactionError OSystem_SDL::endGFXTransaction(void) { } } +#ifdef ENABLE_16BIT + if (_transactionDetails.formatChanged) { + _screenFormat = getPixelFormat(_videoMode.format); + if (!_transactionDetails.sizeChanged) { + unloadGFXMode(); + if (!loadGFXMode()) { + if (_oldVideoMode.setup) { + _transactionMode = kTransactionRollback; + errors |= endGFXTransaction(); + } + } else { + setGraphicsModeIntern(); + clearOverlay(); + + _videoMode.setup = true; + _modeChanged = true; + // OSystem_SDL::pollEvent used to update the screen change count, + // but actually it gives problems when a video mode was changed + // but OSystem_SDL::pollEvent was not called. This for example + // caused a crash under certain circumstances when doing an RTL. + // To fix this issue we update the screen change count right here. + _screenChangeCount++; + } + } + } +#endif if (_transactionDetails.sizeChanged) { unloadGFXMode(); if (!loadGFXMode()) { @@ -186,7 +221,7 @@ OSystem::TransactionError OSystem_SDL::endGFXTransaction(void) { } else if (_transactionDetails.needUpdatescreen) { setGraphicsModeIntern(); internUpdateScreen(); - } + } _transactionMode = kTransactionNone; return (TransactionError)errors; @@ -339,6 +374,102 @@ int OSystem_SDL::getGraphicsMode() const { assert (_transactionMode == kTransactionNone); return _videoMode.mode; } +#ifdef ENABLE_16BIT +Graphics::ColorFormat OSystem_SDL::findCompatibleFormat(Common::List formatList) +{ + bool typeAccepted = false; + Graphics::ColorFormat format; + + while (!formatList.empty() && !typeAccepted) + { + typeAccepted = false; + format = formatList.front(); + + //no need to keep searching if the screen + //is already in one of the desired formats + if (format == _videoMode.format) + return format; + + formatList.pop_front(); + switch (format & Graphics::kFormatTypeMask) + { + case Graphics::kFormat8Bit: + if (format == Graphics::kFormat8Bit) + return format; + break; + case Graphics::kFormatRGB555: + case Graphics::kFormatARGB1555: + case Graphics::kFormatRGB565: + typeAccepted = true; + break; + } + + if (!typeAccepted) + continue; + + switch (format & Graphics::kFormatOrderMask) { + case Graphics::kFormatRGB: + case Graphics::kFormatRGBA: + return format; + default: + break; + } + } + return Graphics::kFormat8Bit; +} + +void OSystem_SDL::initFormat(Graphics::ColorFormat format) { + assert(_transactionMode == kTransactionActive); + + //avoid redundant format changes + if (format == _videoMode.format) + return; + + _videoMode.format = format; + _transactionDetails.formatChanged = true; + +} + +//This should only ever be called with a format that is known supported. +Graphics::PixelFormat OSystem_SDL::getPixelFormat(Graphics::ColorFormat format) { + Graphics::PixelFormat result; + switch (format & Graphics::kFormatTypeMask) { + case Graphics::kFormatARGB1555: + result.aLoss = 7; + result.bytesPerPixel = 2; + result.rLoss = result.gLoss = result.bLoss = 3; + case Graphics::kFormatRGB555: + result.aLoss = 8; + result.bytesPerPixel = 2; + result.rLoss = result.gLoss = result.bLoss = 3; + break; + case Graphics::kFormatRGB565: + result.bytesPerPixel = 2; + result.aLoss = 8; + result.gLoss = 2; + result.rLoss = result.bLoss = 3; + break; + case Graphics::kFormat8Bit: + default: + result.bytesPerPixel = 1; + result.rShift = result.gShift = result.bShift = result.aShift = 0; + result.rLoss = result.gLoss = result.bLoss = result.aLoss = 8; + return result; + } + switch (format & Graphics::kFormatOrderMask) + { + default: + case Graphics::kFormatRGBA: + result.aShift = 0; + case Graphics::kFormatRGB: + result.bShift = result.aBits(); + result.gShift = result.bShift + result.bBits(); + result.rShift = result.gShift + result.gBits(); + break; + } + return result; +} +#endif void OSystem_SDL::initSize(uint w, uint h) { assert(_transactionMode == kTransactionActive); @@ -384,9 +515,21 @@ bool OSystem_SDL::loadGFXMode() { // // Create the surface that contains the 8 bit game data // +#ifdef ENABLE_16BIT + _screen = SDL_CreateRGBSurface(SDL_SWSURFACE, _videoMode.screenWidth, _videoMode.screenHeight, + _screenFormat.bytesPerPixel << 3, + ((1 << _screenFormat.rBits()) - 1) << _screenFormat.rShift , + ((1 << _screenFormat.gBits()) - 1) << _screenFormat.gShift , + ((1 << _screenFormat.bBits()) - 1) << _screenFormat.bShift , + ((1 << _screenFormat.aBits()) - 1) << _screenFormat.aShift ); + if (_screen == NULL) + error("allocating _screen failed"); + +#else _screen = SDL_CreateRGBSurface(SDL_SWSURFACE, _videoMode.screenWidth, _videoMode.screenHeight, 8, 0, 0, 0, 0); if (_screen == NULL) error("allocating _screen failed"); +#endif // // Create the surface that contains the scaled graphics in 16 bit mode @@ -407,20 +550,6 @@ bool OSystem_SDL::loadGFXMode() { } } -#ifdef ENABLE_16BIT - // - // Create the surface that contains the 16 bit game data - // - _screen16 = SDL_CreateRGBSurface(SDL_SWSURFACE, _videoMode.screenWidth, _videoMode.screenHeight, - 16, - 0x7C00, - 0x3E0, - 0x1F, - 0); //555, not 565 - if (_screen16 == NULL) - error("allocating _screen16 failed"); -#endif - // // Create the surface used for the graphics in 16 bit before scaling, and also the overlay // @@ -498,17 +627,10 @@ bool OSystem_SDL::loadGFXMode() { } void OSystem_SDL::unloadGFXMode() { -#ifdef ENABLE_16BIT - if (_screen16) { - SDL_FreeSurface(_screen16); - _screen16 = NULL; - } -#else if (_screen) { SDL_FreeSurface(_screen); _screen = NULL; } -#endif if (_hwscreen) { SDL_FreeSurface(_hwscreen); @@ -540,22 +662,13 @@ void OSystem_SDL::unloadGFXMode() { } bool OSystem_SDL::hotswapGFXMode() { -#ifdef ENABLE_16BIT - if (!_screen16) -#else if (!_screen) -#endif return false; // Keep around the old _screen & _overlayscreen so we can restore the screen data // after the mode switch. -#ifdef ENABLE_16BIT - SDL_Surface *old_screen = _screen16; - _screen16 = NULL; -#else SDL_Surface *old_screen = _screen; _screen = NULL; -#endif SDL_Surface *old_overlayscreen = _overlayscreen; _overlayscreen = NULL; @@ -574,11 +687,7 @@ bool OSystem_SDL::hotswapGFXMode() { if (!loadGFXMode()) { unloadGFXMode(); -#ifdef ENABLE_16BIT - _screen16 = old_screen; -#else _screen = old_screen; -#endif _overlayscreen = old_overlayscreen; return false; @@ -588,11 +697,7 @@ bool OSystem_SDL::hotswapGFXMode() { SDL_SetColors(_screen, _currentPalette, 0, 256); // Restore old screen content -#ifdef ENABLE_16BIT - SDL_BlitSurface(old_screen, NULL, _screen16, NULL); -#else SDL_BlitSurface(old_screen, NULL, _screen, NULL); -#endif SDL_BlitSurface(old_overlayscreen, NULL, _overlayscreen, NULL); // Free the old surfaces @@ -674,11 +779,7 @@ void OSystem_SDL::internUpdateScreen() { #endif if (!_overlayVisible) { -#ifdef ENABLE_16BIT - origSurf = _screen16; -#else origSurf = _screen; -#endif srcSurf = _tmpscreen; width = _videoMode.screenWidth; height = _videoMode.screenHeight; @@ -823,12 +924,6 @@ void OSystem_SDL::copyRectToScreen(const byte *src, int pitch, int x, int y, int assert (_transactionMode == kTransactionNone); assert(src); -#ifdef ENABLE_16BIT - if (_screen16 == NULL) { - warning("OSystem_SDL::copyRectToScreen: _screen16 == NULL"); - return; - } -#endif if (_screen == NULL) { warning("OSystem_SDL::copyRectToScreen: _screen == NULL"); return; @@ -877,27 +972,20 @@ void OSystem_SDL::copyRectToScreen(const byte *src, int pitch, int x, int y, int } // Try to lock the screen surface -#ifdef ENABLE_16BIT - if (SDL_LockSurface(_screen16) == -1) -#else if (SDL_LockSurface(_screen) == -1) -#endif error("SDL_LockSurface failed: %s", SDL_GetError()); #ifdef ENABLE_16BIT - byte *dst = (byte *)_screen16->pixels + y * _videoMode.screenWidth * 2 + x * 2; - if (_videoMode.screenWidth == w && pitch == w * 2) { - memcpy(dst, src, h*w*2); + byte *dst = (byte *)_screen->pixels + y * _videoMode.screenWidth * _screenFormat.bytesPerPixel + x * _screenFormat.bytesPerPixel; + if (_videoMode.screenWidth == w && pitch == w * _screenFormat.bytesPerPixel) { + memcpy(dst, src, h*w*_screenFormat.bytesPerPixel); } else { do { - memcpy(dst, src, w * 2); + memcpy(dst, src, w * _screenFormat.bytesPerPixel); src += pitch; - dst += _videoMode.screenWidth * 2; + dst += _videoMode.screenWidth * _screenFormat.bytesPerPixel; } while (--h); } - - // Unlock the screen surface - SDL_UnlockSurface(_screen16); #else byte *dst = (byte *)_screen->pixels + y * _videoMode.screenWidth + x; if (_videoMode.screenWidth == pitch && pitch == w) { @@ -909,10 +997,10 @@ void OSystem_SDL::copyRectToScreen(const byte *src, int pitch, int x, int y, int dst += _videoMode.screenWidth; } while (--h); } +#endif // Unlock the screen surface SDL_UnlockSurface(_screen); -#endif } Graphics::Surface *OSystem_SDL::lockScreen() { @@ -926,24 +1014,16 @@ Graphics::Surface *OSystem_SDL::lockScreen() { _screenIsLocked = true; // Try to lock the screen surface -#ifdef ENABLE_16BIT - if (SDL_LockSurface(_screen16) == -1) -#else if (SDL_LockSurface(_screen) == -1) -#endif error("SDL_LockSurface failed: %s", SDL_GetError()); -#ifdef ENABLE_16BIT - _framebuffer.pixels = _screen16->pixels; - _framebuffer.w = _screen16->w; - _framebuffer.h = _screen16->h; - _framebuffer.pitch = _screen16->pitch; - _framebuffer.bytesPerPixel = 2; -#else _framebuffer.pixels = _screen->pixels; _framebuffer.w = _screen->w; _framebuffer.h = _screen->h; _framebuffer.pitch = _screen->pitch; +#ifdef ENABLE_16BIT + _framebuffer.bytesPerPixel = _screenFormat.bytesPerPixel; +#else _framebuffer.bytesPerPixel = 1; #endif @@ -958,11 +1038,7 @@ void OSystem_SDL::unlockScreen() { _screenIsLocked = false; // Unlock the screen surface -#ifdef ENABLE_16BIT - SDL_UnlockSurface(_screen16); -#else SDL_UnlockSurface(_screen); -#endif // Trigger a full screen update _forceFull = true; @@ -1133,17 +1209,17 @@ int16 OSystem_SDL::getWidth() { void OSystem_SDL::setPalette(const byte *colors, uint start, uint num) { assert(colors); +#ifdef ENABLE_16BIT + if (_screenFormat.bytesPerPixel > 1) + return; //not using a paletted pixel format +#endif + // Setting the palette before _screen is created is allowed - for now - // since we don't actually set the palette until the screen is updated. // But it could indicate a programming error, so let's warn about it. -#ifdef ENABLE_16BIT - if (!_screen16) - warning("OSystem_SDL::setPalette: _screen16 == NULL"); -#else if (!_screen) warning("OSystem_SDL::setPalette: _screen == NULL"); -#endif const byte *b = colors; uint i; @@ -1267,11 +1343,7 @@ void OSystem_SDL::clearOverlay() { dst.x = dst.y = 1; src.w = dst.w = _videoMode.screenWidth; src.h = dst.h = _videoMode.screenHeight; -#ifdef ENABLE_16BIT - if (SDL_BlitSurface(_screen16, &src, _tmpscreen, &dst) != 0) -#else if (SDL_BlitSurface(_screen, &src, _tmpscreen, &dst) != 0) -#endif error("SDL_BlitSurface failed: %s", SDL_GetError()); SDL_LockSurface(_tmpscreen); diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index 3e8cefc86a..3ec4da1196 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -197,7 +197,8 @@ OSystem_SDL::OSystem_SDL() #endif _hwscreen(0), _screen(0), _tmpscreen(0), #ifdef ENABLE_16BIT - _screen16(0), _cursorBitDepth(8), + _screenFormat(getPixelFormat(Graphics::kFormat8Bit)), + _cursorBitDepth(8), #endif _overlayVisible(false), _overlayscreen(0), _tmpscreen2(0), diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index 22d3d41b00..513ad73934 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -81,6 +81,22 @@ public: void beginGFXTransaction(void); TransactionError endGFXTransaction(void); +#ifdef ENABLE_16BIT + // Find a compatible format from the list of formats supported by the engine + // Fallback to CLUT8 if none found + virtual Graphics::ColorFormat findCompatibleFormat(Common::List formatList); + + // Set the depth and format of the video bitmap + // Typically, CLUT8 + virtual void initFormat(Graphics::ColorFormat format); + + // Game screen + virtual Graphics::PixelFormat getScreenFormat() const { return _screenFormat; } + + //Create a Graphics::PixelFormat to describe the requested color mode + virtual Graphics::PixelFormat getPixelFormat(Graphics::ColorFormat format); +#endif + // Set the size of the video bitmap. // Typically, 320x200 virtual void initSize(uint w, uint h); // overloaded by CE backend @@ -179,11 +195,6 @@ public: // Overlay virtual Graphics::PixelFormat getOverlayFormat() const { return _overlayFormat; } -#ifdef ENABLE_16BIT - // Game screen - virtual Graphics::PixelFormat getScreenFormat() const { return _screenFormat; } -#endif - virtual void showOverlay(); virtual void hideOverlay(); virtual void clearOverlay(); @@ -239,11 +250,6 @@ protected: SDL_Surface *_screen; #ifdef ENABLE_16BIT Graphics::PixelFormat _screenFormat; - - //HACK This is a temporary hack to get 16-bit graphics - //displaying quickly, which will be removed in favor of - //configuring the format of _screen on a per-game basis - SDL_Surface *_screen16; #endif // temporary screen (for scalers) @@ -278,6 +284,9 @@ protected: bool needHotswap; bool needUpdatescreen; bool normal1xScaler; +#ifdef ENABLE_16BIT + bool formatChanged; +#endif }; TransactionDetails _transactionDetails; @@ -292,6 +301,9 @@ protected: int screenWidth, screenHeight; int overlayWidth, overlayHeight; +#ifdef ENABLE_16BIT + Graphics::ColorFormat format; +#endif }; VideoState _videoMode, _oldVideoMode; -- cgit v1.2.3 From b4c44a018b636a9805c725f9a286e58be554afc2 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Wed, 10 Jun 2009 08:41:33 +0000 Subject: Code formatting svn-id: r41420 --- backends/platform/sdl/graphics.cpp | 99 ++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 51 deletions(-) (limited to 'backends') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index 142fa94dba..4035bdb661 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -375,13 +375,11 @@ int OSystem_SDL::getGraphicsMode() const { return _videoMode.mode; } #ifdef ENABLE_16BIT -Graphics::ColorFormat OSystem_SDL::findCompatibleFormat(Common::List formatList) -{ +Graphics::ColorFormat OSystem_SDL::findCompatibleFormat(Common::List formatList) { bool typeAccepted = false; Graphics::ColorFormat format; - while (!formatList.empty() && !typeAccepted) - { + while (!formatList.empty() && !typeAccepted) { typeAccepted = false; format = formatList.front(); @@ -391,28 +389,27 @@ Graphics::ColorFormat OSystem_SDL::findCompatibleFormat(Common::List formatList) { +Graphics::ColorMode OSystem_SDL::findCompatibleFormat(Common::List formatList) { bool typeAccepted = false; - Graphics::ColorFormat format; + Graphics::ColorMode format; - while (!formatList.empty() && !typeAccepted) { + while (!formatList.empty()) { typeAccepted = false; format = formatList.front(); @@ -389,33 +366,21 @@ Graphics::ColorFormat OSystem_SDL::findCompatibleFormat(Common::List> 3; - for (int i = byteDepth; i > 1; i--) { - colmask <<= 8; - colmask |= 0xFF; - } - keycolor &= colmask; - _cursorBitDepth = bitDepth; +void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale) { + keycolor &= (1 << (_screenFormat.bytesPerPixel << 3)) - 1; #else void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor, int cursorTargetScale) { #endif @@ -1520,8 +1467,8 @@ void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, free(_mouseData); #ifdef ENABLE_16BIT - _mouseData = (byte *)malloc(w * h * byteDepth); - memcpy(_mouseData, buf, w * h * byteDepth); + _mouseData = (byte *)malloc(w * h * _screenFormat.bytesPerPixel); + memcpy(_mouseData, buf, w * h * _screenFormat.bytesPerPixel); #else _mouseData = (byte *)malloc(w * h); memcpy(_mouseData, buf, w * h); @@ -1533,7 +1480,12 @@ void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, void OSystem_SDL::blitCursor() { byte *dstPtr; const byte *srcPtr = _mouseData; +#ifdef ENABLE_16BIT + uint32 color; + uint32 colormask = (1 << (_screenFormat.bytesPerPixel << 3)) - 1; +#else byte color; +#endif int w, h, i, j; if (!_mouseOrigSurface || !_mouseData) @@ -1567,20 +1519,20 @@ void OSystem_SDL::blitCursor() { for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { - color = *srcPtr; #ifdef ENABLE_16BIT - if (_cursorBitDepth == 16) { + if (_screenFormat.bytesPerPixel > 1) { + color = (*(uint32 *) srcPtr) & colormask; if (color != _mouseKeyColor) { // transparent, don't draw - int8 r = ((*(uint16 *)srcPtr >> 10) & 0x1F) << 3; - int8 g = ((*(uint16 *)srcPtr >> 5) & 0x1F) << 3; - int8 b = (*(uint16 *)srcPtr & 0x1F) << 3; + uint8 r,g,b; + _screenFormat.colorToRGB(color,r,g,b); *(uint16 *)dstPtr = SDL_MapRGB(_mouseOrigSurface->format, r, g, b); } dstPtr += 2; - srcPtr += 2; + srcPtr += _screenFormat.bytesPerPixel; } else { #endif + color = *srcPtr; if (color != _mouseKeyColor) { // transparent, don't draw *(uint16 *)dstPtr = SDL_MapRGB(_mouseOrigSurface->format, palette[color].r, palette[color].g, palette[color].b); diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index 3ec4da1196..5bcd91d566 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -197,7 +197,7 @@ OSystem_SDL::OSystem_SDL() #endif _hwscreen(0), _screen(0), _tmpscreen(0), #ifdef ENABLE_16BIT - _screenFormat(getPixelFormat(Graphics::kFormat8Bit)), + _screenFormat(getPixelFormat(Graphics::kFormatCLUT8)), _cursorBitDepth(8), #endif _overlayVisible(false), diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index 513ad73934..4d5ea3f548 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -84,17 +84,17 @@ public: #ifdef ENABLE_16BIT // Find a compatible format from the list of formats supported by the engine // Fallback to CLUT8 if none found - virtual Graphics::ColorFormat findCompatibleFormat(Common::List formatList); + virtual Graphics::ColorMode findCompatibleFormat(Common::List formatList); // Set the depth and format of the video bitmap // Typically, CLUT8 - virtual void initFormat(Graphics::ColorFormat format); + virtual void initFormat(Graphics::ColorMode format); // Game screen virtual Graphics::PixelFormat getScreenFormat() const { return _screenFormat; } //Create a Graphics::PixelFormat to describe the requested color mode - virtual Graphics::PixelFormat getPixelFormat(Graphics::ColorFormat format); + virtual Graphics::PixelFormat getPixelFormat(Graphics::ColorMode format); #endif // Set the size of the video bitmap. @@ -129,7 +129,7 @@ public: // Set the bitmap that's used when drawing the cursor. #ifdef ENABLE_16BIT - virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale, uint8 bitDepth = 8); // overloaded by CE backend (FIXME) + virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale); // overloaded by CE backend (FIXME) #else virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor, int cursorTargetScale); // overloaded by CE backend (FIXME) #endif @@ -302,7 +302,7 @@ protected: int screenWidth, screenHeight; int overlayWidth, overlayHeight; #ifdef ENABLE_16BIT - Graphics::ColorFormat format; + Graphics::ColorMode format; #endif }; VideoState _videoMode, _oldVideoMode; -- cgit v1.2.3 From 2ee51a8fa189fc7817fd6d78533664ec870fca48 Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Fri, 12 Jun 2009 08:49:45 +0000 Subject: Unfinished proof of concept regarding my compromise with LordHoto in IRC. svn-id: r41464 --- backends/platform/sdl/graphics.cpp | 41 +++++++++++++++++++++++++++++++++----- backends/platform/sdl/sdl.h | 4 ++-- 2 files changed, 38 insertions(+), 7 deletions(-) (limited to 'backends') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index 51f63a364a..e5d8ba4fbc 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -128,7 +128,7 @@ OSystem::TransactionError OSystem_SDL::endGFXTransaction(void) { errors |= kTransactionPixelFormatNotSupported; _videoMode.format = _oldVideoMode.format; - _screenFormat = getPixelFormat(_videoMode.format); + _screenFormat = _videoMode.format; #endif } else if (_videoMode.screenWidth != _oldVideoMode.screenWidth || _videoMode.screenHeight != _oldVideoMode.screenHeight) { errors |= kTransactionSizeChangeFailed; @@ -362,7 +362,7 @@ Graphics::ColorMode OSystem_SDL::findCompatibleFormat(Common::List 1) { + if (_cursorFormat.bytesPerPixel > 1) { color = (*(uint32 *) srcPtr) & colormask; if (color != _mouseKeyColor) { // transparent, don't draw uint8 r,g,b; - _screenFormat.colorToRGB(color,r,g,b); + _cursorFormat.colorToRGB(color,r,g,b); *(uint16 *)dstPtr = SDL_MapRGB(_mouseOrigSurface->format, r, g, b); } dstPtr += 2; - srcPtr += _screenFormat.bytesPerPixel; + srcPtr += _cursorFormat.bytesPerPixel; } else { #endif color = *srcPtr; diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index 69b85c7959..a25f697c80 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -130,6 +130,7 @@ public: // Set the bitmap that's used when drawing the cursor. #ifdef ENABLE_16BIT virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale); // overloaded by CE backend (FIXME) + virtual void setCursorFormat(Graphics::PixelFormat format); #else virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor, int cursorTargetScale); // overloaded by CE backend (FIXME) #endif @@ -250,6 +251,7 @@ protected: SDL_Surface *_screen; #ifdef ENABLE_16BIT Graphics::PixelFormat _screenFormat; + Graphics::PixelFormat _cursorFormat; #endif // temporary screen (for scalers) -- cgit v1.2.3 From 8d306ebccfa7e88b2e4f4635bff3987e550f98d3 Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Mon, 15 Jun 2009 09:45:19 +0000 Subject: Added kUnsupportedColorMode error code brought Scumm engine and SDL backend into compliance with API outlined in http://scummvmupthorn09.wordpress.com/2009/06/14/how-this-is-going-to-work/ Provided convenient Graphics::PixelFormat constructors for ColorMode enums, and bitformat integers. Removed last vestiges (I think) of initial cursor hack. svn-id: r41539 --- backends/platform/sdl/graphics.cpp | 88 -------------------------------------- backends/platform/sdl/sdl.cpp | 4 +- backends/platform/sdl/sdl.h | 10 ----- 3 files changed, 2 insertions(+), 100 deletions(-) (limited to 'backends') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index 0d1b3fb8aa..f550621a28 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -352,34 +352,6 @@ int OSystem_SDL::getGraphicsMode() const { return _videoMode.mode; } #ifdef ENABLE_16BIT -Graphics::ColorMode OSystem_SDL::findCompatibleFormat(Common::List formatList) { - bool typeAccepted = false; - Graphics::ColorMode format; - - while (!formatList.empty()) { - typeAccepted = false; - format = formatList.front(); - - //no need to keep searching if the screen - //is already in one of the desired formats - if (getPixelFormat(format) == _videoMode.format) - return format; - - formatList.pop_front(); - switch (format) { - case Graphics::kFormatCLUT8: - if (format == Graphics::kFormatCLUT8) - return format; - break; - case Graphics::kFormatRGB555: - case Graphics::kFormatRGB565: - return format; - break; - } - } - return Graphics::kFormatCLUT8; -} - void OSystem_SDL::initFormat(Graphics::PixelFormat format) { assert(_transactionMode == kTransactionActive); @@ -391,66 +363,6 @@ void OSystem_SDL::initFormat(Graphics::PixelFormat format) { _transactionDetails.formatChanged = true; _screenFormat = format; } - -//TODO: Move this out of OSystem and into Graphics, where engine can access it. -//TODO: ABGR support -Graphics::PixelFormat OSystem_SDL::getPixelFormat(Graphics::ColorMode format) { - Graphics::PixelFormat result; - switch (format) { - case Graphics::kFormatRGB555: - result.aLoss = 8; - result.bytesPerPixel = 2; - result.rLoss = result.gLoss = result.bLoss = 3; - break; - case Graphics::kFormatRGB565: - result.bytesPerPixel = 2; - result.aLoss = 8; - result.gLoss = 2; - result.rLoss = result.bLoss = 3; - break; - case Graphics::kFormatXRGB1555: - //Special case, alpha bit is always high in this mode. - result.aLoss = 7; - result.bytesPerPixel = 2; - result.rLoss = result.gLoss = result.bLoss = 3; - result.bShift = 0; - result.gShift = result.bShift + result.bBits(); - result.rShift = result.gShift + result.gBits(); - result.aShift = result.rShift + result.rBits(); - //HACK: there should be a clean way to handle setting - //up the color order without prematurely returning - return result; - case Graphics::kFormatRGBA4444: - result.bytesPerPixel = 2; - result.aLoss = result.gLoss = result.rLoss = result.bLoss = 4; - break; - case Graphics::kFormatRGB888: - result.bytesPerPixel = 3; - result.aLoss = 8; - result.gLoss = result.rLoss = result.bLoss = 0; - break; - case Graphics::kFormatRGBA6666: - result.bytesPerPixel = 3; - result.aLoss = result.gLoss = result.rLoss = result.bLoss = 2; - break; - case Graphics::kFormatRGBA8888: - result.bytesPerPixel = 4; - result.aLoss = result.gLoss = result.rLoss = result.bLoss = 0; - break; - case Graphics::kFormatCLUT8: - default: - result.bytesPerPixel = 1; - result.rShift = result.gShift = result.bShift = result.aShift = 0; - result.rLoss = result.gLoss = result.bLoss = result.aLoss = 8; - return result; - } - - result.aShift = 0; - result.bShift = result.aBits(); - result.gShift = result.bShift + result.bBits(); - result.rShift = result.gShift + result.gBits(); - return result; -} #endif void OSystem_SDL::initSize(uint w, uint h) { diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index 5bcd91d566..81b5fcc3eb 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -197,8 +197,8 @@ OSystem_SDL::OSystem_SDL() #endif _hwscreen(0), _screen(0), _tmpscreen(0), #ifdef ENABLE_16BIT - _screenFormat(getPixelFormat(Graphics::kFormatCLUT8)), - _cursorBitDepth(8), + _screenFormat(Graphics::kFormatCLUT8), + _cursorFormat(Graphics::kFormatCLUT8), #endif _overlayVisible(false), _overlayscreen(0), _tmpscreen2(0), diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index a25f697c80..b36139f24b 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -82,19 +82,12 @@ public: TransactionError endGFXTransaction(void); #ifdef ENABLE_16BIT - // Find a compatible format from the list of formats supported by the engine - // Fallback to CLUT8 if none found - virtual Graphics::ColorMode findCompatibleFormat(Common::List formatList); - // Set the depth and format of the video bitmap // Typically, CLUT8 virtual void initFormat(Graphics::PixelFormat format); // Game screen virtual Graphics::PixelFormat getScreenFormat() const { return _screenFormat; } - - //Create a Graphics::PixelFormat to describe the requested color mode - virtual Graphics::PixelFormat getPixelFormat(Graphics::ColorMode format); #endif // Set the size of the video bitmap. @@ -379,9 +372,6 @@ protected: MousePos _mouseCurState; byte _mouseKeyColor; int _cursorTargetScale; -#ifdef ENABLE_16BIT - uint8 _cursorBitDepth; -#endif bool _cursorPaletteDisabled; SDL_Surface *_mouseOrigSurface; SDL_Surface *_mouseSurface; -- cgit v1.2.3 From 0ca17a7f8c79940873a4dc82537310584f03e439 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Mon, 15 Jun 2009 11:46:28 +0000 Subject: Fix compilation when 16BIT code is disabled. svn-id: r41543 --- backends/platform/sdl/graphics.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'backends') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index f550621a28..2cee0ea83d 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -155,6 +155,8 @@ OSystem::TransactionError OSystem_SDL::endGFXTransaction(void) { #ifdef ENABLE_16BIT if (_transactionDetails.sizeChanged || _transactionDetails.formatChanged) { +#else + if (_transactionDetails.sizeChanged) { #endif unloadGFXMode(); if (!loadGFXMode()) { -- cgit v1.2.3 From fb96e826f27b071d6696731f43cb5fa0d8760205 Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Tue, 16 Jun 2009 05:33:11 +0000 Subject: Simplified cursor related 16-bit code. svn-id: r41577 --- backends/platform/sdl/graphics.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'backends') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index 2cee0ea83d..f4269b55b2 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -1379,11 +1379,11 @@ void OSystem_SDL::warpMouse(int x, int y) { } } -#ifdef ENABLE_16BIT void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale) { +#ifdef ENABLE_16BIT keycolor &= (1 << (_cursorFormat.bytesPerPixel << 3)) - 1; #else -void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor, int cursorTargetScale) { + keycolor &= 0xFF; #endif if (w == 0 || h == 0) -- cgit v1.2.3 From cb56169a2770c25ce27256db339353011158998f Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Tue, 16 Jun 2009 09:04:37 +0000 Subject: Declared getBestFormat in OSystem base class, and implemented in SDL backend. svn-id: r41580 --- backends/platform/sdl/sdl.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'backends') diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index b36139f24b..b788022d57 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -88,6 +88,18 @@ public: // Game screen virtual Graphics::PixelFormat getScreenFormat() const { return _screenFormat; } + + // Highest supported + virtual Graphics::PixelFormat getBestFormat() const { + //TODO scale down 16/32 bit based on hardware support +#ifdef ENABLE_32BIT + return Graphics::PixelFormat(Graphics::kFormatRGBA8888); +#elif defined ENABLE_16BIT + return Graphics::PixelFormat(Graphics::kFormatRGB565); +#else + return Graphics::PixelFormat(Graphics::kFormatCLUT8); +#endif + } #endif // Set the size of the video bitmap. -- cgit v1.2.3 From db9cfc6f962790a270b357c3d47a5dc0e15a37b0 Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Tue, 16 Jun 2009 09:15:06 +0000 Subject: Corrected oversight in earlier ifdef simplification which leads to compilation failure if ENABLE_16BIT is not defined. svn-id: r41581 --- backends/platform/sdl/sdl.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'backends') diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index b788022d57..074a55069d 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -133,11 +133,9 @@ public: virtual void warpMouse(int x, int y); // overloaded by CE backend (FIXME) // Set the bitmap that's used when drawing the cursor. -#ifdef ENABLE_16BIT virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale); // overloaded by CE backend (FIXME) +#ifdef ENABLE_16BIT virtual void setCursorFormat(Graphics::PixelFormat format); -#else - virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor, int cursorTargetScale); // overloaded by CE backend (FIXME) #endif // Set colors of cursor palette -- cgit v1.2.3 From f55419ee451070dbe07014bc7d747507e431edf6 Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Wed, 17 Jun 2009 10:03:59 +0000 Subject: OSystem_SDL::GetBestFormat will no longer return modes greater than that which hardware supports. svn-id: r41606 --- backends/platform/sdl/sdl.h | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'backends') diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index 074a55069d..598b943e4b 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -92,13 +92,26 @@ public: // Highest supported virtual Graphics::PixelFormat getBestFormat() const { //TODO scale down 16/32 bit based on hardware support -#ifdef ENABLE_32BIT - return Graphics::PixelFormat(Graphics::kFormatRGBA8888); -#elif defined ENABLE_16BIT - return Graphics::PixelFormat(Graphics::kFormatRGB565); -#else +#if (defined ENABLE_32BIT) || (defined ENABLE_16BIT) + { + SDL_PixelFormat *HWFormat = SDL_GetVideoInfo()->vfmt; +#ifdef ENABLE_32BIT + if (HWFormat->BitsPerPixel > 32) + return Graphics::PixelFormat(Graphics::kFormatRGBA8888); + return Graphics::PixelFormat(HWFormat->BytesPerPixel, + HWFormat->Rloss, HWFormat->Gloss, HWFormat->Bloss, HWFormat->Aloss, + HWFormat->Rshift, HWFormat->Gshift, HWFormat->Bshift, HWFormat->Ashift); +#else //16 + if (HWFormat->BitsPerPixel > 16) + return Graphics::PixelFormat(Graphics::kFormatRGB565); + return Graphics::PixelFormat(HWFormat->BytesPerPixel, + HWFormat->Rloss, HWFormat->Gloss, HWFormat->Bloss, HWFormat->Aloss, + HWFormat->Rshift, HWFormat->Gshift, HWFormat->Bshift, HWFormat->Ashift); + } +#endif //ENABLE_32BIT +#else //8BIT only return Graphics::PixelFormat(Graphics::kFormatCLUT8); -#endif +#endif //ENABLE_32BIT or ENABLE_16BIT } #endif -- cgit v1.2.3 From 704386d3b09b68f96b6d4160a1a261e3e754f461 Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Fri, 19 Jun 2009 09:28:55 +0000 Subject: Removed replaced Graphics::ColorMode enum type with factory methods for Graphics::PixelFormat. svn-id: r41662 --- backends/platform/sdl/sdl.cpp | 4 ++-- backends/platform/sdl/sdl.h | 23 +++++++++-------------- 2 files changed, 11 insertions(+), 16 deletions(-) (limited to 'backends') diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index 81b5fcc3eb..17ee5941a4 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -197,8 +197,8 @@ OSystem_SDL::OSystem_SDL() #endif _hwscreen(0), _screen(0), _tmpscreen(0), #ifdef ENABLE_16BIT - _screenFormat(Graphics::kFormatCLUT8), - _cursorFormat(Graphics::kFormatCLUT8), + _screenFormat(Graphics::PixelFormat::createFormatCLUT8()), + _cursorFormat(Graphics::PixelFormat::createFormatCLUT8()), #endif _overlayVisible(false), _overlayscreen(0), _tmpscreen2(0), diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index 598b943e4b..2cb9451a0d 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -96,22 +96,17 @@ public: { SDL_PixelFormat *HWFormat = SDL_GetVideoInfo()->vfmt; #ifdef ENABLE_32BIT - if (HWFormat->BitsPerPixel > 32) - return Graphics::PixelFormat(Graphics::kFormatRGBA8888); - return Graphics::PixelFormat(HWFormat->BytesPerPixel, - HWFormat->Rloss, HWFormat->Gloss, HWFormat->Bloss, HWFormat->Aloss, - HWFormat->Rshift, HWFormat->Gshift, HWFormat->Bshift, HWFormat->Ashift); -#else //16 - if (HWFormat->BitsPerPixel > 16) - return Graphics::PixelFormat(Graphics::kFormatRGB565); - return Graphics::PixelFormat(HWFormat->BytesPerPixel, - HWFormat->Rloss, HWFormat->Gloss, HWFormat->Bloss, HWFormat->Aloss, - HWFormat->Rshift, HWFormat->Gshift, HWFormat->Bshift, HWFormat->Ashift); + if (HWFormat->BitsPerPixel >= 32) + return Graphics::PixelFormat::createFormatRGBA8888(); + if (HWFormat->BitsPerPixel >= 24) + return Graphics:: + FormatRGB888(); +#endif //ENABLE_32BIT + if (HWFormat->BitsPerPixel >= 16) + return Graphics::PixelFormat::createFormatRGB565(); } -#endif //ENABLE_32BIT -#else //8BIT only - return Graphics::PixelFormat(Graphics::kFormatCLUT8); #endif //ENABLE_32BIT or ENABLE_16BIT + return Graphics::PixelFormat::createFormatCLUT8(); } #endif -- cgit v1.2.3 From f7dd1c15ed38418a0371032966144eb6c2e004cb Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Sat, 20 Jun 2009 05:23:09 +0000 Subject: renamed ENABLE_16BIT define to more accurate ENABLE_RGB_COLOR svn-id: r41696 --- backends/platform/sdl/graphics.cpp | 28 ++++++++++++++-------------- backends/platform/sdl/sdl.cpp | 2 +- backends/platform/sdl/sdl.h | 12 +++++------- 3 files changed, 20 insertions(+), 22 deletions(-) (limited to 'backends') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index f4269b55b2..a08239d472 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -97,7 +97,7 @@ void OSystem_SDL::beginGFXTransaction(void) { _transactionDetails.needUpdatescreen = false; _transactionDetails.normal1xScaler = false; -#ifdef ENABLE_16BIT +#ifdef ENABLE_RGB_COLOR _transactionDetails.formatChanged = false; #endif @@ -123,7 +123,7 @@ OSystem::TransactionError OSystem_SDL::endGFXTransaction(void) { _videoMode.mode = _oldVideoMode.mode; _videoMode.scaleFactor = _oldVideoMode.scaleFactor; -#ifdef ENABLE_16BIT +#ifdef ENABLE_RGB_COLOR } else if (_videoMode.format != _oldVideoMode.format) { errors |= kTransactionPixelFormatNotSupported; @@ -153,7 +153,7 @@ OSystem::TransactionError OSystem_SDL::endGFXTransaction(void) { } } -#ifdef ENABLE_16BIT +#ifdef ENABLE_RGB_COLOR if (_transactionDetails.sizeChanged || _transactionDetails.formatChanged) { #else if (_transactionDetails.sizeChanged) { @@ -353,7 +353,7 @@ int OSystem_SDL::getGraphicsMode() const { assert (_transactionMode == kTransactionNone); return _videoMode.mode; } -#ifdef ENABLE_16BIT +#ifdef ENABLE_RGB_COLOR void OSystem_SDL::initFormat(Graphics::PixelFormat format) { assert(_transactionMode == kTransactionActive); @@ -411,7 +411,7 @@ bool OSystem_SDL::loadGFXMode() { // // Create the surface that contains the 8 bit game data // -#ifdef ENABLE_16BIT +#ifdef ENABLE_RGB_COLOR _screen = SDL_CreateRGBSurface(SDL_SWSURFACE, _videoMode.screenWidth, _videoMode.screenHeight, _screenFormat.bytesPerPixel << 3, ((1 << _screenFormat.rBits()) - 1) << _screenFormat.rShift , @@ -871,7 +871,7 @@ void OSystem_SDL::copyRectToScreen(const byte *src, int pitch, int x, int y, int if (SDL_LockSurface(_screen) == -1) error("SDL_LockSurface failed: %s", SDL_GetError()); -#ifdef ENABLE_16BIT +#ifdef ENABLE_RGB_COLOR byte *dst = (byte *)_screen->pixels + y * _videoMode.screenWidth * _screenFormat.bytesPerPixel + x * _screenFormat.bytesPerPixel; if (_videoMode.screenWidth == w && pitch == w * _screenFormat.bytesPerPixel) { memcpy(dst, src, h*w*_screenFormat.bytesPerPixel); @@ -917,7 +917,7 @@ Graphics::Surface *OSystem_SDL::lockScreen() { _framebuffer.w = _screen->w; _framebuffer.h = _screen->h; _framebuffer.pitch = _screen->pitch; -#ifdef ENABLE_16BIT +#ifdef ENABLE_RGB_COLOR _framebuffer.bytesPerPixel = _screenFormat.bytesPerPixel; #else _framebuffer.bytesPerPixel = 1; @@ -1105,7 +1105,7 @@ int16 OSystem_SDL::getWidth() { void OSystem_SDL::setPalette(const byte *colors, uint start, uint num) { assert(colors); -#ifdef ENABLE_16BIT +#ifdef ENABLE_RGB_COLOR if (_screenFormat.bytesPerPixel > 1) return; //not using a paletted pixel format #endif @@ -1163,7 +1163,7 @@ void OSystem_SDL::setCursorPalette(const byte *colors, uint start, uint num) { } _cursorPaletteDisabled = false; -#ifdef ENABLE_16BIT +#ifdef ENABLE_RGB_COLOR } void OSystem_SDL::setCursorFormat(Graphics::PixelFormat format) { @@ -1380,7 +1380,7 @@ void OSystem_SDL::warpMouse(int x, int y) { } void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale) { -#ifdef ENABLE_16BIT +#ifdef ENABLE_RGB_COLOR keycolor &= (1 << (_cursorFormat.bytesPerPixel << 3)) - 1; #else keycolor &= 0xFF; @@ -1419,7 +1419,7 @@ void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, } free(_mouseData); -#ifdef ENABLE_16BIT +#ifdef ENABLE_RGB_COLOR _mouseData = (byte *)malloc(w * h * _cursorFormat.bytesPerPixel); memcpy(_mouseData, buf, w * h * _cursorFormat.bytesPerPixel); #else @@ -1433,7 +1433,7 @@ void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, void OSystem_SDL::blitCursor() { byte *dstPtr; const byte *srcPtr = _mouseData; -#ifdef ENABLE_16BIT +#ifdef ENABLE_RGB_COLOR uint32 color; uint32 colormask = (1 << (_cursorFormat.bytesPerPixel << 3)) - 1; #else @@ -1472,7 +1472,7 @@ void OSystem_SDL::blitCursor() { for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { -#ifdef ENABLE_16BIT +#ifdef ENABLE_RGB_COLOR if (_cursorFormat.bytesPerPixel > 1) { color = (*(uint32 *) srcPtr) & colormask; if (color != _mouseKeyColor) { // transparent, don't draw @@ -1492,7 +1492,7 @@ void OSystem_SDL::blitCursor() { } dstPtr += 2; srcPtr++; -#ifdef ENABLE_16BIT +#ifdef ENABLE_RGB_COLOR } #endif } diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index 17ee5941a4..3f9b81a912 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -196,7 +196,7 @@ OSystem_SDL::OSystem_SDL() _osdSurface(0), _osdAlpha(SDL_ALPHA_TRANSPARENT), _osdFadeStartTime(0), #endif _hwscreen(0), _screen(0), _tmpscreen(0), -#ifdef ENABLE_16BIT +#ifdef ENABLE_RGB_COLOR _screenFormat(Graphics::PixelFormat::createFormatCLUT8()), _cursorFormat(Graphics::PixelFormat::createFormatCLUT8()), #endif diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index 2cb9451a0d..aee15fcbd0 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -81,7 +81,7 @@ public: void beginGFXTransaction(void); TransactionError endGFXTransaction(void); -#ifdef ENABLE_16BIT +#ifdef ENABLE_RGB_COLOR // Set the depth and format of the video bitmap // Typically, CLUT8 virtual void initFormat(Graphics::PixelFormat format); @@ -92,7 +92,6 @@ public: // Highest supported virtual Graphics::PixelFormat getBestFormat() const { //TODO scale down 16/32 bit based on hardware support -#if (defined ENABLE_32BIT) || (defined ENABLE_16BIT) { SDL_PixelFormat *HWFormat = SDL_GetVideoInfo()->vfmt; #ifdef ENABLE_32BIT @@ -105,7 +104,6 @@ public: if (HWFormat->BitsPerPixel >= 16) return Graphics::PixelFormat::createFormatRGB565(); } -#endif //ENABLE_32BIT or ENABLE_16BIT return Graphics::PixelFormat::createFormatCLUT8(); } #endif @@ -142,7 +140,7 @@ public: // Set the bitmap that's used when drawing the cursor. virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale); // overloaded by CE backend (FIXME) -#ifdef ENABLE_16BIT +#ifdef ENABLE_RGB_COLOR virtual void setCursorFormat(Graphics::PixelFormat format); #endif @@ -260,7 +258,7 @@ protected: // unseen game screen SDL_Surface *_screen; -#ifdef ENABLE_16BIT +#ifdef ENABLE_RGB_COLOR Graphics::PixelFormat _screenFormat; Graphics::PixelFormat _cursorFormat; #endif @@ -297,7 +295,7 @@ protected: bool needHotswap; bool needUpdatescreen; bool normal1xScaler; -#ifdef ENABLE_16BIT +#ifdef ENABLE_RGB_COLOR bool formatChanged; #endif }; @@ -314,7 +312,7 @@ protected: int screenWidth, screenHeight; int overlayWidth, overlayHeight; -#ifdef ENABLE_16BIT +#ifdef ENABLE_RGB_COLOR Graphics::PixelFormat format; #endif }; -- cgit v1.2.3 From 7c622423157e29b7206ba0c39a7756443ed1e70d Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Tue, 23 Jun 2009 02:02:51 +0000 Subject: Merged format initialization into InitSize to allow for backends not supporting gfx transactions. svn-id: r41801 --- backends/platform/sdl/graphics.cpp | 21 ++++++++++----------- backends/platform/sdl/sdl.h | 10 +++------- 2 files changed, 13 insertions(+), 18 deletions(-) (limited to 'backends') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index a08239d472..b5ec9b9db8 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -353,23 +353,22 @@ int OSystem_SDL::getGraphicsMode() const { assert (_transactionMode == kTransactionNone); return _videoMode.mode; } -#ifdef ENABLE_RGB_COLOR -void OSystem_SDL::initFormat(Graphics::PixelFormat format) { + +void OSystem_SDL::initSize(uint w, uint h, Graphics::PixelFormat format) { assert(_transactionMode == kTransactionActive); +#ifdef ENABLE_RGB_COLOR //avoid redundant format changes - if (format == _videoMode.format) - return; + assert(format.bytesPerPixel > 0); - _videoMode.format = format; - _transactionDetails.formatChanged = true; - _screenFormat = format; -} + if (format != _videoMode.format) + { + _videoMode.format = format; + _transactionDetails.formatChanged = true; + _screenFormat = format; + } #endif -void OSystem_SDL::initSize(uint w, uint h) { - assert(_transactionMode == kTransactionActive); - // Avoid redundant res changes if ((int)w == _videoMode.screenWidth && (int)h == _videoMode.screenHeight) return; diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index aee15fcbd0..db855094cb 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -82,10 +82,6 @@ public: TransactionError endGFXTransaction(void); #ifdef ENABLE_RGB_COLOR - // Set the depth and format of the video bitmap - // Typically, CLUT8 - virtual void initFormat(Graphics::PixelFormat format); - // Game screen virtual Graphics::PixelFormat getScreenFormat() const { return _screenFormat; } @@ -108,9 +104,9 @@ public: } #endif - // Set the size of the video bitmap. - // Typically, 320x200 - virtual void initSize(uint w, uint h); // overloaded by CE backend + // Set the size and format of the video bitmap. + // Typically, 320x200 CLUT8 + virtual void initSize(uint w, uint h, Graphics::PixelFormat format); // overloaded by CE backend virtual int getScreenChangeID() const { return _screenChangeCount; } -- cgit v1.2.3 From 865129a5630017f05d08e778ba1ef430c23cd55a Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Wed, 24 Jun 2009 06:44:30 +0000 Subject: made the cursor's pixel format a member of the cursor object, merged ____CursorFormat functions into equivalent ____Cursor functions. svn-id: r41825 --- backends/platform/sdl/graphics.cpp | 4 +++- backends/platform/sdl/sdl.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'backends') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index b5ec9b9db8..d7cabd00cc 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -1378,8 +1378,10 @@ void OSystem_SDL::warpMouse(int x, int y) { } } -void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale) { +void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale, Graphics::PixelFormat format) { #ifdef ENABLE_RGB_COLOR + if (format.bytesPerPixel <= _screenFormat.bytesPerPixel) + _cursorFormat = format; keycolor &= (1 << (_cursorFormat.bytesPerPixel << 3)) - 1; #else keycolor &= 0xFF; diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index db855094cb..7aeebf9264 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -135,7 +135,7 @@ public: virtual void warpMouse(int x, int y); // overloaded by CE backend (FIXME) // Set the bitmap that's used when drawing the cursor. - virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale); // overloaded by CE backend (FIXME) + virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale, Graphics::PixelFormat format); // overloaded by CE backend (FIXME) #ifdef ENABLE_RGB_COLOR virtual void setCursorFormat(Graphics::PixelFormat format); #endif -- cgit v1.2.3 From 53eb83dc95b825b2bf4f5f3943e8f10d9add3aa6 Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Thu, 25 Jun 2009 08:55:16 +0000 Subject: API modification -- replaced "Graphics::PixelFormat getBestFormat()" with "Common::List getSupportedFormats()" svn-id: r41854 --- backends/platform/sdl/sdl.h | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) (limited to 'backends') diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index 7aeebf9264..efe1984446 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -86,21 +86,38 @@ public: virtual Graphics::PixelFormat getScreenFormat() const { return _screenFormat; } // Highest supported - virtual Graphics::PixelFormat getBestFormat() const { - //TODO scale down 16/32 bit based on hardware support - { - SDL_PixelFormat *HWFormat = SDL_GetVideoInfo()->vfmt; + virtual Common::List getSupportedFormats() const { + //TODO determine hardware color component order + Common::List list; + SDL_PixelFormat *HWFormat = SDL_GetVideoInfo()->vfmt; #ifdef ENABLE_32BIT - if (HWFormat->BitsPerPixel >= 32) - return Graphics::PixelFormat::createFormatRGBA8888(); - if (HWFormat->BitsPerPixel >= 24) - return Graphics:: - FormatRGB888(); + if (HWFormat->BitsPerPixel >= 32) + { + list.push_back(Graphics::PixelFormat::createFormatRGBA8888()); + list.push_back(Graphics::PixelFormat::createFormatARGB8888()); + list.push_back(Graphics::PixelFormat::createFormatABGR8888()); + list.push_back(Graphics::PixelFormat::createFormatBGRA8888()); } + if (HWFormat->BitsPerPixel >= 24) + { + list.push_back(Graphics::PixelFormat::createFormatRGB888()); + list.push_back(Graphics::PixelFormat::createFormatBGR888()); + } #endif //ENABLE_32BIT - if (HWFormat->BitsPerPixel >= 16) - return Graphics::PixelFormat::createFormatRGB565(); + if (HWFormat->BitsPerPixel >= 16) + { + list.push_back(Graphics::PixelFormat::createFormatRGB565()); + list.push_back(Graphics::PixelFormat::createFormatXRGB1555()); + list.push_back(Graphics::PixelFormat::createFormatRGB555()); + list.push_back(Graphics::PixelFormat::createFormatRGBA4444()); + list.push_back(Graphics::PixelFormat::createFormatARGB4444()); + list.push_back(Graphics::PixelFormat::createFormatBGR565()); + list.push_back(Graphics::PixelFormat::createFormatXBGR1555()); + list.push_back(Graphics::PixelFormat::createFormatBGR555()); + list.push_back(Graphics::PixelFormat::createFormatABGR4444()); + list.push_back(Graphics::PixelFormat::createFormatBGRA4444()); } - return Graphics::PixelFormat::createFormatCLUT8(); + list.push_back(Graphics::PixelFormat::createFormatCLUT8()); + return list; } #endif -- cgit v1.2.3 From 27e50db5d7cdbed498d6a61b1ee1ad5405ce33a2 Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Fri, 26 Jun 2009 10:37:00 +0000 Subject: Converted OSystem::SetMouseCursor to take pointer to PixelFormat, instead of full PixelFormat. Removed OSystem::setCursorFormat (since I forgot to do so several commits ago) svn-id: r41901 --- backends/platform/sdl/graphics.cpp | 18 ++++++------------ backends/platform/sdl/sdl.h | 5 +---- 2 files changed, 7 insertions(+), 16 deletions(-) (limited to 'backends') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index d7cabd00cc..f6b4d76418 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -1162,15 +1162,7 @@ void OSystem_SDL::setCursorPalette(const byte *colors, uint start, uint num) { } _cursorPaletteDisabled = false; -#ifdef ENABLE_RGB_COLOR -} - -void OSystem_SDL::setCursorFormat(Graphics::PixelFormat format) { - assert(format.bytesPerPixel); - _cursorFormat = format; - -#endif -// blitCursor(); + blitCursor(); } @@ -1378,10 +1370,12 @@ void OSystem_SDL::warpMouse(int x, int y) { } } -void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale, Graphics::PixelFormat format) { +void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale, Graphics::PixelFormat *format) { #ifdef ENABLE_RGB_COLOR - if (format.bytesPerPixel <= _screenFormat.bytesPerPixel) - _cursorFormat = format; + if (!format) + format = new Graphics::PixelFormat(1,8,8,8,8,0,0,0,0); + if (format->bytesPerPixel <= _screenFormat.bytesPerPixel) + _cursorFormat = *format; keycolor &= (1 << (_cursorFormat.bytesPerPixel << 3)) - 1; #else keycolor &= 0xFF; diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index efe1984446..2048b7f536 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -152,10 +152,7 @@ public: virtual void warpMouse(int x, int y); // overloaded by CE backend (FIXME) // Set the bitmap that's used when drawing the cursor. - virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale, Graphics::PixelFormat format); // overloaded by CE backend (FIXME) -#ifdef ENABLE_RGB_COLOR - virtual void setCursorFormat(Graphics::PixelFormat format); -#endif + virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale, Graphics::PixelFormat *format); // overloaded by CE backend (FIXME) // Set colors of cursor palette void setCursorPalette(const byte *colors, uint start, uint num); -- cgit v1.2.3 From 853aec05ba4485f0bfc90e7515322dfd56a8d4af Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Sat, 27 Jun 2009 05:58:44 +0000 Subject: changed initGraphics, and OSystem::initSize to take Graphics::PixelFormat * parameters instead of Graphics::PixelFormat parameters, to save unnecessary pixelformat initialization if ENABLE_RGB_COLOR is not set. svn-id: r41909 --- backends/platform/sdl/graphics.cpp | 13 ++++++++----- backends/platform/sdl/sdl.h | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'backends') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index f6b4d76418..a45f31108b 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -354,18 +354,21 @@ int OSystem_SDL::getGraphicsMode() const { return _videoMode.mode; } -void OSystem_SDL::initSize(uint w, uint h, Graphics::PixelFormat format) { +void OSystem_SDL::initSize(uint w, uint h, Graphics::PixelFormat *format) { assert(_transactionMode == kTransactionActive); #ifdef ENABLE_RGB_COLOR //avoid redundant format changes - assert(format.bytesPerPixel > 0); + if (!format) + format = new Graphics::PixelFormat(1,8,8,8,8,0,0,0,0); + + assert(format->bytesPerPixel > 0); - if (format != _videoMode.format) + if (*format != _videoMode.format) { - _videoMode.format = format; + _videoMode.format = *format; _transactionDetails.formatChanged = true; - _screenFormat = format; + _screenFormat = *format; } #endif diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index 2048b7f536..befb82cc89 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -123,7 +123,7 @@ public: // Set the size and format of the video bitmap. // Typically, 320x200 CLUT8 - virtual void initSize(uint w, uint h, Graphics::PixelFormat format); // overloaded by CE backend + virtual void initSize(uint w, uint h, Graphics::PixelFormat *format); // overloaded by CE backend virtual int getScreenChangeID() const { return _screenChangeCount; } -- cgit v1.2.3 From 9e1916bcad3cc33a870bdbff5bd01b39e523492d Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Tue, 30 Jun 2009 07:30:57 +0000 Subject: renamed kTransactionPixelFormatNotSupported to kTransactionFormatNotSupported, retyped all Graphics::PixelFormat * parameters to const Graphics::PixelFormat *, (hopefully) repaired all memory leaks on screen and cursor format changes, provided OSystem::getScreenFormat and OSystem::getSupportedFormats methods for when ENABLE_RGB_COLOR is not set, completely forgot the "commit early, commit often" mantra. svn-id: r41972 --- backends/platform/sdl/graphics.cpp | 23 +++++++++++++---------- backends/platform/sdl/sdl.h | 4 ++-- 2 files changed, 15 insertions(+), 12 deletions(-) (limited to 'backends') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index a45f31108b..27f32ee8d2 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -125,7 +125,7 @@ OSystem::TransactionError OSystem_SDL::endGFXTransaction(void) { _videoMode.scaleFactor = _oldVideoMode.scaleFactor; #ifdef ENABLE_RGB_COLOR } else if (_videoMode.format != _oldVideoMode.format) { - errors |= kTransactionPixelFormatNotSupported; + errors |= kTransactionFormatNotSupported; _videoMode.format = _oldVideoMode.format; _screenFormat = _videoMode.format; @@ -354,21 +354,24 @@ int OSystem_SDL::getGraphicsMode() const { return _videoMode.mode; } -void OSystem_SDL::initSize(uint w, uint h, Graphics::PixelFormat *format) { +void OSystem_SDL::initSize(uint w, uint h, const Graphics::PixelFormat *format) { assert(_transactionMode == kTransactionActive); #ifdef ENABLE_RGB_COLOR //avoid redundant format changes + Graphics::PixelFormat newFormat; if (!format) - format = new Graphics::PixelFormat(1,8,8,8,8,0,0,0,0); + newFormat = Graphics::PixelFormat::createFormatCLUT8(); + else + newFormat = *format; - assert(format->bytesPerPixel > 0); + assert(newFormat.bytesPerPixel > 0); - if (*format != _videoMode.format) + if (newFormat != _videoMode.format) { - _videoMode.format = *format; + _videoMode.format = newFormat; _transactionDetails.formatChanged = true; - _screenFormat = *format; + _screenFormat = newFormat; } #endif @@ -1373,11 +1376,11 @@ void OSystem_SDL::warpMouse(int x, int y) { } } -void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale, Graphics::PixelFormat *format) { +void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale, const Graphics::PixelFormat *format) { #ifdef ENABLE_RGB_COLOR if (!format) - format = new Graphics::PixelFormat(1,8,8,8,8,0,0,0,0); - if (format->bytesPerPixel <= _screenFormat.bytesPerPixel) + _cursorFormat = Graphics::PixelFormat(1,8,8,8,8,0,0,0,0); + else if (format->bytesPerPixel <= _screenFormat.bytesPerPixel) _cursorFormat = *format; keycolor &= (1 << (_cursorFormat.bytesPerPixel << 3)) - 1; #else diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index befb82cc89..68dfe64d53 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -123,7 +123,7 @@ public: // Set the size and format of the video bitmap. // Typically, 320x200 CLUT8 - virtual void initSize(uint w, uint h, Graphics::PixelFormat *format); // overloaded by CE backend + virtual void initSize(uint w, uint h, const Graphics::PixelFormat *format); // overloaded by CE backend virtual int getScreenChangeID() const { return _screenChangeCount; } @@ -152,7 +152,7 @@ public: virtual void warpMouse(int x, int y); // overloaded by CE backend (FIXME) // Set the bitmap that's used when drawing the cursor. - virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale, Graphics::PixelFormat *format); // overloaded by CE backend (FIXME) + virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale, const Graphics::PixelFormat *format); // overloaded by CE backend (FIXME) // Set colors of cursor palette void setCursorPalette(const byte *colors, uint start, uint num); -- cgit v1.2.3 From 2c5d11b67b35f93b2292c1ca56d0c9fc89608921 Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Tue, 7 Jul 2009 07:50:40 +0000 Subject: Removed PixelFormat convenience constructors at behest of Max and Eugene. svn-id: r42207 --- backends/platform/sdl/graphics.cpp | 2 +- backends/platform/sdl/sdl.cpp | 4 ++-- backends/platform/sdl/sdl.h | 47 +++++++++++++++++++++++++------------- 3 files changed, 34 insertions(+), 19 deletions(-) (limited to 'backends') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index 27f32ee8d2..95a3276fa5 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -361,7 +361,7 @@ void OSystem_SDL::initSize(uint w, uint h, const Graphics::PixelFormat *format) //avoid redundant format changes Graphics::PixelFormat newFormat; if (!format) - newFormat = Graphics::PixelFormat::createFormatCLUT8(); + newFormat = Graphics::PixelFormat(1, 8, 8, 8, 8, 0, 0, 0, 0); else newFormat = *format; diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index 105206ec07..f7bd71361f 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -197,8 +197,8 @@ OSystem_SDL::OSystem_SDL() #endif _hwscreen(0), _screen(0), _tmpscreen(0), #ifdef ENABLE_RGB_COLOR - _screenFormat(Graphics::PixelFormat::createFormatCLUT8()), - _cursorFormat(Graphics::PixelFormat::createFormatCLUT8()), + _screenFormat(Graphics::PixelFormat(1, 8, 8, 8, 8, 0, 0, 0, 0)), + _cursorFormat(Graphics::PixelFormat(1, 8, 8, 8, 8, 0, 0, 0, 0)), #endif _overlayVisible(false), _overlayscreen(0), _tmpscreen2(0), diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index 68dfe64d53..b8ab2f6d97 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -94,29 +94,44 @@ public: if (HWFormat->BitsPerPixel >= 32) { list.push_back(Graphics::PixelFormat::createFormatRGBA8888()); - list.push_back(Graphics::PixelFormat::createFormatARGB8888()); - list.push_back(Graphics::PixelFormat::createFormatABGR8888()); - list.push_back(Graphics::PixelFormat::createFormatBGRA8888()); } + list.push_back(Graphics::PixelFormat(4, 0, 0, 0, 0, 16, 8, 0, 24) +); + list.push_back(Graphics::PixelFormat(4, 0, 0, 0, 0, 0, 8, 16, 24) +); + list.push_back(Graphics::PixelFormat(4, 0, 0, 0, 0, 8, 16, 24, 0) +); } if (HWFormat->BitsPerPixel >= 24) { - list.push_back(Graphics::PixelFormat::createFormatRGB888()); - list.push_back(Graphics::PixelFormat::createFormatBGR888()); + list.push_back(Graphics::PixelFormat(3, 0, 0, 0, 8, 16, 8, 0, 0) +); + list.push_back(Graphics::PixelFormat(3, 0, 0, 0, 8, 0, 8, 16, 0) +); } #endif //ENABLE_32BIT if (HWFormat->BitsPerPixel >= 16) { - list.push_back(Graphics::PixelFormat::createFormatRGB565()); - list.push_back(Graphics::PixelFormat::createFormatXRGB1555()); - list.push_back(Graphics::PixelFormat::createFormatRGB555()); - list.push_back(Graphics::PixelFormat::createFormatRGBA4444()); - list.push_back(Graphics::PixelFormat::createFormatARGB4444()); - list.push_back(Graphics::PixelFormat::createFormatBGR565()); - list.push_back(Graphics::PixelFormat::createFormatXBGR1555()); - list.push_back(Graphics::PixelFormat::createFormatBGR555()); - list.push_back(Graphics::PixelFormat::createFormatABGR4444()); - list.push_back(Graphics::PixelFormat::createFormatBGRA4444()); + list.push_back(Graphics::PixelFormat(2, 3, 2, 3, 8, 11, 5, 0, 0) +); + list.push_back(Graphics::PixelFormat(2, 3, 3, 3, 7, 10, 5, 0, 15) +); + list.push_back(Graphics::PixelFormat(2, 3, 3, 3, 8, 10, 5, 0, 0) +); + list.push_back(Graphics::PixelFormat(2, 4, 4, 4, 4, 12, 8, 4, 0) +); + list.push_back(Graphics::PixelFormat(2, 4, 4, 4, 4, 8, 4, 0, 12) +); + list.push_back(Graphics::PixelFormat(2, 3, 2, 3, 8, 0, 5, 11, 0) +); + list.push_back(Graphics::PixelFormat(2, 3, 3, 3, 7, 0, 5, 10, 15) +); + list.push_back(Graphics::PixelFormat(2, 3, 3, 3, 8, 0, 5, 10, 0) +); + list.push_back(Graphics::PixelFormat(2, 4, 4, 4, 4, 0, 4, 8, 12) +); + list.push_back(Graphics::PixelFormat(2, 4, 4, 4, 4, 4, 8, 12, 0) +); } - list.push_back(Graphics::PixelFormat::createFormatCLUT8()); + list.push_back(Graphics::PixelFormat(1, 8, 8, 8, 8, 0, 0, 0, 0)); return list; } #endif -- cgit v1.2.3 From 828ed66555b99363fed62b4cbb83c36de68c3024 Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Wed, 8 Jul 2009 16:07:58 +0000 Subject: Reinstated static inline Graphics::PixelFormat::createFormatCLUT8(), which I am told was not supposed to be removed with the others. svn-id: r42268 --- backends/platform/sdl/graphics.cpp | 2 +- backends/platform/sdl/sdl.cpp | 4 +-- backends/platform/sdl/sdl.h | 51 ++++++++++++++------------------------ 3 files changed, 21 insertions(+), 36 deletions(-) (limited to 'backends') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index 95a3276fa5..27f32ee8d2 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -361,7 +361,7 @@ void OSystem_SDL::initSize(uint w, uint h, const Graphics::PixelFormat *format) //avoid redundant format changes Graphics::PixelFormat newFormat; if (!format) - newFormat = Graphics::PixelFormat(1, 8, 8, 8, 8, 0, 0, 0, 0); + newFormat = Graphics::PixelFormat::createFormatCLUT8(); else newFormat = *format; diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index f7bd71361f..105206ec07 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -197,8 +197,8 @@ OSystem_SDL::OSystem_SDL() #endif _hwscreen(0), _screen(0), _tmpscreen(0), #ifdef ENABLE_RGB_COLOR - _screenFormat(Graphics::PixelFormat(1, 8, 8, 8, 8, 0, 0, 0, 0)), - _cursorFormat(Graphics::PixelFormat(1, 8, 8, 8, 8, 0, 0, 0, 0)), + _screenFormat(Graphics::PixelFormat::createFormatCLUT8()), + _cursorFormat(Graphics::PixelFormat::createFormatCLUT8()), #endif _overlayVisible(false), _overlayscreen(0), _tmpscreen2(0), diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index b8ab2f6d97..c2648e8ed7 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -94,44 +94,29 @@ public: if (HWFormat->BitsPerPixel >= 32) { list.push_back(Graphics::PixelFormat::createFormatRGBA8888()); - list.push_back(Graphics::PixelFormat(4, 0, 0, 0, 0, 16, 8, 0, 24) -); - list.push_back(Graphics::PixelFormat(4, 0, 0, 0, 0, 0, 8, 16, 24) -); - list.push_back(Graphics::PixelFormat(4, 0, 0, 0, 0, 8, 16, 24, 0) -); } + list.push_back(Graphics::PixelFormat(4, 0, 0, 0, 0, 16, 8, 0, 24)); + list.push_back(Graphics::PixelFormat(4, 0, 0, 0, 0, 0, 8, 16, 24)); + list.push_back(Graphics::PixelFormat(4, 0, 0, 0, 0, 8, 16, 24, 0)); + } if (HWFormat->BitsPerPixel >= 24) { - list.push_back(Graphics::PixelFormat(3, 0, 0, 0, 8, 16, 8, 0, 0) -); - list.push_back(Graphics::PixelFormat(3, 0, 0, 0, 8, 0, 8, 16, 0) -); + list.push_back(Graphics::PixelFormat(3, 0, 0, 0, 8, 16, 8, 0, 0)); + list.push_back(Graphics::PixelFormat(3, 0, 0, 0, 8, 0, 8, 16, 0)); } #endif //ENABLE_32BIT - if (HWFormat->BitsPerPixel >= 16) - { - list.push_back(Graphics::PixelFormat(2, 3, 2, 3, 8, 11, 5, 0, 0) -); - list.push_back(Graphics::PixelFormat(2, 3, 3, 3, 7, 10, 5, 0, 15) -); - list.push_back(Graphics::PixelFormat(2, 3, 3, 3, 8, 10, 5, 0, 0) -); - list.push_back(Graphics::PixelFormat(2, 4, 4, 4, 4, 12, 8, 4, 0) -); - list.push_back(Graphics::PixelFormat(2, 4, 4, 4, 4, 8, 4, 0, 12) -); - list.push_back(Graphics::PixelFormat(2, 3, 2, 3, 8, 0, 5, 11, 0) -); - list.push_back(Graphics::PixelFormat(2, 3, 3, 3, 7, 0, 5, 10, 15) -); - list.push_back(Graphics::PixelFormat(2, 3, 3, 3, 8, 0, 5, 10, 0) -); - list.push_back(Graphics::PixelFormat(2, 4, 4, 4, 4, 0, 4, 8, 12) -); - list.push_back(Graphics::PixelFormat(2, 4, 4, 4, 4, 4, 8, 12, 0) -); + if (HWFormat->BitsPerPixel >= 16) { + list.push_back(Graphics::PixelFormat(2, 3, 2, 3, 8, 11, 5, 0, 0)); + list.push_back(Graphics::PixelFormat(2, 3, 3, 3, 7, 10, 5, 0, 15)); + list.push_back(Graphics::PixelFormat(2, 3, 3, 3, 8, 10, 5, 0, 0)); + list.push_back(Graphics::PixelFormat(2, 4, 4, 4, 4, 12, 8, 4, 0)); + list.push_back(Graphics::PixelFormat(2, 4, 4, 4, 4, 8, 4, 0, 12)); + list.push_back(Graphics::PixelFormat(2, 3, 2, 3, 8, 0, 5, 11, 0)); + list.push_back(Graphics::PixelFormat(2, 3, 3, 3, 7, 0, 5, 10, 15)); + list.push_back(Graphics::PixelFormat(2, 3, 3, 3, 8, 0, 5, 10, 0)); + list.push_back(Graphics::PixelFormat(2, 4, 4, 4, 4, 0, 4, 8, 12)); + list.push_back(Graphics::PixelFormat(2, 4, 4, 4, 4, 4, 8, 12, 0)); } - list.push_back(Graphics::PixelFormat(1, 8, 8, 8, 8, 0, 0, 0, 0)); + list.push_back(Graphics::PixelFormat::createFormatCLUT8()); return list; } #endif -- cgit v1.2.3 From a4f3a8390068fc372a96d4473b91eb09158353ef Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Thu, 9 Jul 2009 09:10:05 +0000 Subject: corrected creation of one Graphics::PixelFormat to reflect the resurrection of Graphics::PixelFormat::createFormatCLUT8 svn-id: r42282 --- backends/platform/sdl/graphics.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'backends') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index 27f32ee8d2..3029f43d87 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -1379,7 +1379,7 @@ void OSystem_SDL::warpMouse(int x, int y) { void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale, const Graphics::PixelFormat *format) { #ifdef ENABLE_RGB_COLOR if (!format) - _cursorFormat = Graphics::PixelFormat(1,8,8,8,8,0,0,0,0); + _cursorFormat = Graphics::PixelFormat::createFormatCLUT8; else if (format->bytesPerPixel <= _screenFormat.bytesPerPixel) _cursorFormat = *format; keycolor &= (1 << (_cursorFormat.bytesPerPixel << 3)) - 1; -- cgit v1.2.3 From ff208c5387a8566546a384afa9ab48c0a1f356a0 Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Thu, 9 Jul 2009 17:25:06 +0000 Subject: fix compile svn-id: r42308 --- backends/platform/sdl/graphics.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'backends') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index 3029f43d87..fa162a6348 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -1379,7 +1379,7 @@ void OSystem_SDL::warpMouse(int x, int y) { void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale, const Graphics::PixelFormat *format) { #ifdef ENABLE_RGB_COLOR if (!format) - _cursorFormat = Graphics::PixelFormat::createFormatCLUT8; + _cursorFormat = Graphics::PixelFormat::createFormatCLUT8(); else if (format->bytesPerPixel <= _screenFormat.bytesPerPixel) _cursorFormat = *format; keycolor &= (1 << (_cursorFormat.bytesPerPixel << 3)) - 1; -- cgit v1.2.3 From a5d374bded6204c9250155d572d23b0caef636a5 Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Fri, 10 Jul 2009 06:46:50 +0000 Subject: Moved OSystem_SDL::getSupportedFormats function body from platforms/sdl/sdl.h to platforms/sdl/graphics.cpp, Improved and simplified list-generation method for OSystem_SDL::getSupportedFormats. svn-id: r42325 --- backends/platform/sdl/graphics.cpp | 70 ++++++++++++++++++++++++++++++++++++++ backends/platform/sdl/sdl.h | 34 +----------------- 2 files changed, 71 insertions(+), 33 deletions(-) (limited to 'backends') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index fa162a6348..61f33569af 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -26,6 +26,9 @@ #include "backends/platform/sdl/sdl.h" #include "common/mutex.h" #include "common/util.h" +#ifdef ENABLE_RGB_COLOR +#include "common/list.h" +#endif #include "graphics/font.h" #include "graphics/fontman.h" #include "graphics/scaler.h" @@ -206,6 +209,73 @@ OSystem::TransactionError OSystem_SDL::endGFXTransaction(void) { return (TransactionError)errors; } +#ifdef ENABLE_RGB_COLOR +const Graphics::PixelFormat RGBList[] = { +#ifdef ENABLE_32BIT + // RGBA8888, ARGB8888, RGB888 + Graphics::PixelFormat(4, 0, 0, 0, 0, 24, 16, 8, 0), + Graphics::PixelFormat(4, 0, 0, 0, 0, 16, 8, 0, 24), + Graphics::PixelFormat(3, 0, 0, 0, 8, 16, 8, 0, 0), +#endif + // RGB565, XRGB1555, RGB555, RGBA4444, ARGB4444 + Graphics::PixelFormat(2, 3, 2, 3, 8, 11, 5, 0, 0), + Graphics::PixelFormat(2, 3, 3, 3, 7, 10, 5, 0, 15), + Graphics::PixelFormat(2, 3, 3, 3, 8, 10, 5, 0, 0), + Graphics::PixelFormat(2, 4, 4, 4, 4, 12, 8, 4, 0), + Graphics::PixelFormat(2, 4, 4, 4, 4, 8, 4, 0, 12) +}; +const Graphics::PixelFormat BGRList[] = { +#ifdef ENABLE_32BIT + // ABGR8888, BGRA8888, BGR888 + Graphics::PixelFormat(4, 0, 0, 0, 0, 0, 8, 16, 24), + Graphics::PixelFormat(4, 0, 0, 0, 0, 8, 16, 24, 0), + Graphics::PixelFormat(3, 0, 0, 0, 8, 0, 8, 16, 0), +#endif + // BGR565, XBGR1555, BGR555, ABGR4444, BGRA4444 + Graphics::PixelFormat(2, 3, 2, 3, 8, 0, 5, 11, 0), + Graphics::PixelFormat(2, 3, 3, 3, 7, 0, 5, 10, 15), + Graphics::PixelFormat(2, 3, 3, 3, 8, 0, 5, 10, 0), + Graphics::PixelFormat(2, 4, 4, 4, 4, 0, 4, 8, 12), + Graphics::PixelFormat(2, 3, 3, 3, 8, 4, 8, 12, 0) +}; + +// TODO: prioritize matching alpha masks +Common::List OSystem_SDL::getSupportedFormats() { + static Common::List list; + if (!list.empty()) + return list; + bool BGR = false; + int listLength = ARRAYSIZE(RGBList); + + // Get our currently set format + Graphics::PixelFormat format(_hwscreen->format->BytesPerPixel, + _hwscreen->format->Rloss, _hwscreen->format->Gloss, + _hwscreen->format->Bloss, _hwscreen->format->Aloss, + _hwscreen->format->Rshift, _hwscreen->format->Gshift, + _hwscreen->format->Bshift, _hwscreen->format->Ashift); + + // Push it first, as the prefered format. + list.push_back(format); + if (format.bShift > format.rShift) + BGR = true; + for (int i = 0; i < listLength; i++) { + if (RGBList[i].bytesPerPixel > format.bytesPerPixel) + continue; + if (BGR) { + if (BGRList[i] != format) + list.push_back(BGRList[i]); + list.push_back(RGBList[i]); + } else { + if (RGBList[i] != format) + list.push_back(RGBList[i]); + list.push_back(BGRList[i]); + } + } + list.push_back(Graphics::PixelFormat::createFormatCLUT8()); + return list; +} +#endif + bool OSystem_SDL::setGraphicsMode(int mode) { Common::StackLock lock(_graphicsMutex); diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index c2648e8ed7..3e074a884a 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -86,39 +86,7 @@ public: virtual Graphics::PixelFormat getScreenFormat() const { return _screenFormat; } // Highest supported - virtual Common::List getSupportedFormats() const { - //TODO determine hardware color component order - Common::List list; - SDL_PixelFormat *HWFormat = SDL_GetVideoInfo()->vfmt; -#ifdef ENABLE_32BIT - if (HWFormat->BitsPerPixel >= 32) - { - list.push_back(Graphics::PixelFormat::createFormatRGBA8888()); - list.push_back(Graphics::PixelFormat(4, 0, 0, 0, 0, 16, 8, 0, 24)); - list.push_back(Graphics::PixelFormat(4, 0, 0, 0, 0, 0, 8, 16, 24)); - list.push_back(Graphics::PixelFormat(4, 0, 0, 0, 0, 8, 16, 24, 0)); - } - if (HWFormat->BitsPerPixel >= 24) - { - list.push_back(Graphics::PixelFormat(3, 0, 0, 0, 8, 16, 8, 0, 0)); - list.push_back(Graphics::PixelFormat(3, 0, 0, 0, 8, 0, 8, 16, 0)); - } -#endif //ENABLE_32BIT - if (HWFormat->BitsPerPixel >= 16) { - list.push_back(Graphics::PixelFormat(2, 3, 2, 3, 8, 11, 5, 0, 0)); - list.push_back(Graphics::PixelFormat(2, 3, 3, 3, 7, 10, 5, 0, 15)); - list.push_back(Graphics::PixelFormat(2, 3, 3, 3, 8, 10, 5, 0, 0)); - list.push_back(Graphics::PixelFormat(2, 4, 4, 4, 4, 12, 8, 4, 0)); - list.push_back(Graphics::PixelFormat(2, 4, 4, 4, 4, 8, 4, 0, 12)); - list.push_back(Graphics::PixelFormat(2, 3, 2, 3, 8, 0, 5, 11, 0)); - list.push_back(Graphics::PixelFormat(2, 3, 3, 3, 7, 0, 5, 10, 15)); - list.push_back(Graphics::PixelFormat(2, 3, 3, 3, 8, 0, 5, 10, 0)); - list.push_back(Graphics::PixelFormat(2, 4, 4, 4, 4, 0, 4, 8, 12)); - list.push_back(Graphics::PixelFormat(2, 4, 4, 4, 4, 4, 8, 12, 0)); - } - list.push_back(Graphics::PixelFormat::createFormatCLUT8()); - return list; - } + virtual Common::List getSupportedFormats(); #endif // Set the size and format of the video bitmap. -- cgit v1.2.3 From 02e639ea0ceaa4b6a530847dbb043a5c2352e4a2 Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Fri, 10 Jul 2009 19:55:06 +0000 Subject: Fixed a couple of errors in the new getSupportedFormats implementation. svn-id: r42350 --- backends/platform/sdl/graphics.cpp | 39 ++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) (limited to 'backends') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index 61f33569af..ea9c285a44 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -242,22 +242,37 @@ const Graphics::PixelFormat BGRList[] = { // TODO: prioritize matching alpha masks Common::List OSystem_SDL::getSupportedFormats() { static Common::List list; - if (!list.empty()) + static bool inited = false; + + if (inited) return list; + bool BGR = false; int listLength = ARRAYSIZE(RGBList); - // Get our currently set format - Graphics::PixelFormat format(_hwscreen->format->BytesPerPixel, - _hwscreen->format->Rloss, _hwscreen->format->Gloss, - _hwscreen->format->Bloss, _hwscreen->format->Aloss, - _hwscreen->format->Rshift, _hwscreen->format->Gshift, - _hwscreen->format->Bshift, _hwscreen->format->Ashift); - - // Push it first, as the prefered format. - list.push_back(format); - if (format.bShift > format.rShift) - BGR = true; + Graphics::PixelFormat format = Graphics::PixelFormat::createFormatCLUT8(); + if (_hwscreen) { + // Get our currently set hardware format + format = Graphics::PixelFormat(_hwscreen->format->BytesPerPixel, + _hwscreen->format->Rloss, _hwscreen->format->Gloss, + _hwscreen->format->Bloss, _hwscreen->format->Aloss, + _hwscreen->format->Rshift, _hwscreen->format->Gshift, + _hwscreen->format->Bshift, _hwscreen->format->Ashift); + + // Workaround to MacOSX SDL not providing an accurate Aloss value. + if (_hwscreen->format->Amask == 0) + format.aLoss = 8; + + // Push it first, as the prefered format. + list.push_back(format); + + if (format.bShift > format.rShift) + BGR = true; + + // Mark that we don't need to do this any more. + inited = true; + } + for (int i = 0; i < listLength; i++) { if (RGBList[i].bytesPerPixel > format.bytesPerPixel) continue; -- cgit v1.2.3 From 70c138651dc71f886a4314943c4e9a753dc44607 Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Fri, 10 Jul 2009 19:56:40 +0000 Subject: Whoops, and one more. svn-id: r42351 --- backends/platform/sdl/graphics.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'backends') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index ea9c285a44..a090db01b6 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -274,7 +274,7 @@ Common::List OSystem_SDL::getSupportedFormats() { } for (int i = 0; i < listLength; i++) { - if (RGBList[i].bytesPerPixel > format.bytesPerPixel) + if (inited && (RGBList[i].bytesPerPixel > format.bytesPerPixel)) continue; if (BGR) { if (BGRList[i] != format) -- cgit v1.2.3 From cdf751accda346f5d96e3fdfa2fd4a1b92ed4d19 Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Tue, 14 Jul 2009 08:27:36 +0000 Subject: changed generic Graphics::PixelFormat constructor to take xBits instead of xLoss. Modified OSystem_SDL::getSupportedFormats and ScummEngine::init to account for this change. svn-id: r42467 --- backends/platform/sdl/graphics.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'backends') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index a090db01b6..4e47db0827 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -213,30 +213,30 @@ OSystem::TransactionError OSystem_SDL::endGFXTransaction(void) { const Graphics::PixelFormat RGBList[] = { #ifdef ENABLE_32BIT // RGBA8888, ARGB8888, RGB888 - Graphics::PixelFormat(4, 0, 0, 0, 0, 24, 16, 8, 0), - Graphics::PixelFormat(4, 0, 0, 0, 0, 16, 8, 0, 24), - Graphics::PixelFormat(3, 0, 0, 0, 8, 16, 8, 0, 0), + Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0), + Graphics::PixelFormat(4, 8, 8, 8, 8, 16, 8, 0, 24), + Graphics::PixelFormat(3, 8, 8, 8, 0, 16, 8, 0, 0), #endif // RGB565, XRGB1555, RGB555, RGBA4444, ARGB4444 - Graphics::PixelFormat(2, 3, 2, 3, 8, 11, 5, 0, 0), - Graphics::PixelFormat(2, 3, 3, 3, 7, 10, 5, 0, 15), - Graphics::PixelFormat(2, 3, 3, 3, 8, 10, 5, 0, 0), + Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0), + Graphics::PixelFormat(2, 5, 5, 5, 1, 10, 5, 0, 15), + Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0), Graphics::PixelFormat(2, 4, 4, 4, 4, 12, 8, 4, 0), Graphics::PixelFormat(2, 4, 4, 4, 4, 8, 4, 0, 12) }; const Graphics::PixelFormat BGRList[] = { #ifdef ENABLE_32BIT // ABGR8888, BGRA8888, BGR888 - Graphics::PixelFormat(4, 0, 0, 0, 0, 0, 8, 16, 24), - Graphics::PixelFormat(4, 0, 0, 0, 0, 8, 16, 24, 0), - Graphics::PixelFormat(3, 0, 0, 0, 8, 0, 8, 16, 0), + Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24), + Graphics::PixelFormat(4, 8, 8, 8, 8, 8, 16, 24, 0), + Graphics::PixelFormat(3, 8, 8, 8, 0, 0, 8, 16, 0), #endif // BGR565, XBGR1555, BGR555, ABGR4444, BGRA4444 - Graphics::PixelFormat(2, 3, 2, 3, 8, 0, 5, 11, 0), - Graphics::PixelFormat(2, 3, 3, 3, 7, 0, 5, 10, 15), - Graphics::PixelFormat(2, 3, 3, 3, 8, 0, 5, 10, 0), + Graphics::PixelFormat(2, 5, 6, 5, 0, 0, 5, 11, 0), + Graphics::PixelFormat(2, 5, 5, 5, 1, 0, 5, 10, 15), + Graphics::PixelFormat(2, 5, 5, 5, 0, 0, 5, 10, 0), Graphics::PixelFormat(2, 4, 4, 4, 4, 0, 4, 8, 12), - Graphics::PixelFormat(2, 3, 3, 3, 8, 4, 8, 12, 0) + Graphics::PixelFormat(2, 4, 4, 4, 4, 4, 8, 12, 0) }; // TODO: prioritize matching alpha masks -- cgit v1.2.3 From 52a160657f4db676e30b6d52abbf513154aad662 Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Sun, 19 Jul 2009 15:00:39 +0000 Subject: Fix 16bit color when using the hardware screen's pixel format. The call was never updated after r42467. svn-id: r42617 --- backends/platform/sdl/graphics.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'backends') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index 4e47db0827..6d9f3fc6eb 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -254,8 +254,8 @@ Common::List OSystem_SDL::getSupportedFormats() { if (_hwscreen) { // Get our currently set hardware format format = Graphics::PixelFormat(_hwscreen->format->BytesPerPixel, - _hwscreen->format->Rloss, _hwscreen->format->Gloss, - _hwscreen->format->Bloss, _hwscreen->format->Aloss, + 8 - _hwscreen->format->Rloss, 8 - _hwscreen->format->Gloss, + 8 - _hwscreen->format->Bloss, 8 - _hwscreen->format->Aloss, _hwscreen->format->Rshift, _hwscreen->format->Gshift, _hwscreen->format->Bshift, _hwscreen->format->Ashift); -- cgit v1.2.3 From 8062d37283bcf8390d8fb66cce99c2bfd65668d8 Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Wed, 5 Aug 2009 21:32:42 +0000 Subject: Some groundwork for a better implementation of modifier keys. (incomplete, and breaks previous implementation) svn-id: r43078 --- backends/keymapper/hardware-key.h | 40 +++++ backends/keymapper/types.h | 1 + backends/platform/sdl/hardwarekeys.cpp | 302 +++++++++++++++++---------------- 3 files changed, 194 insertions(+), 149 deletions(-) (limited to 'backends') diff --git a/backends/keymapper/hardware-key.h b/backends/keymapper/hardware-key.h index 8ddeada51e..c8c1d3c145 100644 --- a/backends/keymapper/hardware-key.h +++ b/backends/keymapper/hardware-key.h @@ -64,6 +64,29 @@ struct HardwareKey { } }; +/** +* Describes an available hardware modifier +*/ +struct HardwareMod { + /** unique id used for saving/loading to config */ + char hwModId[HWKEY_ID_SIZE]; + + /** Human readable description */ + String description; + + /** + * The modifier flags that are generated by the + * back-end when this modifier key is pressed. + */ + byte modFlags; + + HardwareMod(const char *i, byte mf, String desc = "") + : modFlags(mf), description(desc) { + assert(i); + strncpy(hwModId, i, HWKEY_ID_SIZE); + } +}; + /** * Simple class to encapsulate a device's set of HardwareKeys. @@ -80,6 +103,11 @@ public: delete *it; } + void addHardwareMod(HardwareMod *mod) { + checkForMod(mod); + _mods.push_back(mod); + } + void addHardwareKey(HardwareKey *key) { checkForKey(key); _keys.push_back(key); @@ -127,7 +155,19 @@ private: } } + void checkForMod(HardwareMod *mod) { + List::iterator it; + + for (it = _mods.begin(); it != _mods.end(); it++) { + if (strncmp((*it)->hwModId, mod->hwModId, HWKEY_ID_SIZE) == 0) + error("Error adding HardwareMod '%s' - id of %s already in use!", mod->description.c_str(), mod->hwModId); + else if ((*it)->modFlags == mod->modFlags) + error("Error adding HardwareMod '%s' - modFlags already in use!", mod->description.c_str()); + } + } + List _keys; + List _mods; }; diff --git a/backends/keymapper/types.h b/backends/keymapper/types.h index 7ad4c0e538..004a90bfcd 100644 --- a/backends/keymapper/types.h +++ b/backends/keymapper/types.h @@ -43,6 +43,7 @@ enum KeyType { kTriggerRightKeyType, kStartKeyType, kSelectKeyType, +// kModiferKeyType, /* ... */ kKeyTypeMax diff --git a/backends/platform/sdl/hardwarekeys.cpp b/backends/platform/sdl/hardwarekeys.cpp index 1a8124bbf3..bba48286f0 100644 --- a/backends/platform/sdl/hardwarekeys.cpp +++ b/backends/platform/sdl/hardwarekeys.cpp @@ -37,161 +37,170 @@ struct Key { uint16 ascii; const char *desc; KeyType preferredAction; - bool shiftable; + int32 modableMask; }; static const Key keys[] = { - {"BACKSPACE", KEYCODE_BACKSPACE, ASCII_BACKSPACE, "Backspace", kActionKeyType, false}, - {"TAB", KEYCODE_TAB, ASCII_TAB, "Tab", kActionKeyType, false}, - {"CLEAR", KEYCODE_CLEAR, 0, "Clear", kActionKeyType, false}, - {"RETURN", KEYCODE_RETURN, ASCII_RETURN, "Return", kActionKeyType, false}, - {"PAUSE", KEYCODE_PAUSE, 0, "Pause", kActionKeyType, false}, - {"ESCAPE", KEYCODE_ESCAPE, ASCII_ESCAPE, "Esc", kStartKeyType, false}, - {"SPACE", KEYCODE_SPACE, ASCII_SPACE, "Space", kActionKeyType, false}, - {"EXCLAIM", KEYCODE_EXCLAIM, '!', "!", kActionKeyType, false}, - {"QUOTEDBL", KEYCODE_QUOTEDBL, '"', "\"", kActionKeyType, false}, - {"HASH", KEYCODE_HASH, '#', "#", kActionKeyType, false}, - {"DOLLAR", KEYCODE_DOLLAR, '$', "$", kActionKeyType, false}, - {"AMPERSAND", KEYCODE_AMPERSAND, '&', "&", kActionKeyType, false}, - {"QUOTE", KEYCODE_QUOTE, '\'', "'", kActionKeyType, false}, - {"LEFTPAREN", KEYCODE_LEFTPAREN, '(', "(", kActionKeyType, false}, - {"RIGHTPAREN", KEYCODE_RIGHTPAREN, ')', ")", kActionKeyType, false}, - {"ASTERISK", KEYCODE_ASTERISK, '*', "*", kActionKeyType, false}, - {"PLUS", KEYCODE_PLUS, '+', "+", kActionKeyType, false}, - {"COMMA", KEYCODE_COMMA, ',', ",", kActionKeyType, false}, - {"MINUS", KEYCODE_MINUS, '-', "-", kActionKeyType, false}, - {"PERIOD", KEYCODE_PERIOD, '.', ".", kActionKeyType, false}, - {"SLASH", KEYCODE_SLASH, '/', "/", kActionKeyType, false}, - {"0", KEYCODE_0, '0', "0", kActionKeyType, false}, - {"1", KEYCODE_1, '1', "1", kActionKeyType, false}, - {"2", KEYCODE_2, '2', "2", kActionKeyType, false}, - {"3", KEYCODE_3, '3', "3", kActionKeyType, false}, - {"4", KEYCODE_4, '4', "4", kActionKeyType, false}, - {"5", KEYCODE_5, '5', "5", kActionKeyType, false}, - {"6", KEYCODE_6, '6', "6", kActionKeyType, false}, - {"7", KEYCODE_7, '7', "7", kActionKeyType, false}, - {"8", KEYCODE_8, '8', "8", kActionKeyType, false}, - {"9", KEYCODE_9, '9', "9", kActionKeyType, false}, - {"COLON", KEYCODE_COLON, ':', ":", kActionKeyType, false}, - {"SEMICOLON", KEYCODE_SEMICOLON, ';', ";", kActionKeyType, false}, - {"LESS", KEYCODE_LESS, '<', "<", kActionKeyType, false}, - {"EQUALS", KEYCODE_EQUALS, '=', "=", kActionKeyType, false}, - {"GREATER", KEYCODE_GREATER, '>', ">", kActionKeyType, false}, - {"QUESTION", KEYCODE_QUESTION, '?', "?", kActionKeyType, false}, - {"AT", KEYCODE_AT, '@', "@", kActionKeyType, false}, - - {"LEFTBRACKET", KEYCODE_LEFTBRACKET, '[', "[", kActionKeyType, false}, - {"BACKSLASH", KEYCODE_BACKSLASH, '\\', "\\", kActionKeyType, false}, - {"RIGHTBRACKET", KEYCODE_RIGHTBRACKET, ']', "]", kActionKeyType, false}, - {"CARET", KEYCODE_CARET, '^', "^", kActionKeyType, false}, - {"UNDERSCORE", KEYCODE_UNDERSCORE, '_', "_", kActionKeyType, false}, - {"BACKQUOTE", KEYCODE_BACKQUOTE, '`', "`", kActionKeyType, false}, - {"a", KEYCODE_a, 'a', "a", kActionKeyType, true}, - {"b", KEYCODE_b, 'b', "b", kActionKeyType, true}, - {"c", KEYCODE_c, 'c', "c", kActionKeyType, true}, - {"d", KEYCODE_d, 'd', "d", kActionKeyType, true}, - {"e", KEYCODE_e, 'e', "e", kActionKeyType, true}, - {"f", KEYCODE_f, 'f', "f", kActionKeyType, true}, - {"g", KEYCODE_g, 'g', "g", kActionKeyType, true}, - {"h", KEYCODE_h, 'h', "h", kActionKeyType, true}, - {"i", KEYCODE_i, 'i', "i", kActionKeyType, true}, - {"j", KEYCODE_j, 'j', "j", kActionKeyType, true}, - {"k", KEYCODE_k, 'k', "k", kActionKeyType, true}, - {"l", KEYCODE_l, 'l', "l", kActionKeyType, true}, - {"m", KEYCODE_m, 'm', "m", kActionKeyType, true}, - {"n", KEYCODE_n, 'n', "n", kActionKeyType, true}, - {"o", KEYCODE_o, 'o', "o", kActionKeyType, true}, - {"p", KEYCODE_p, 'p', "p", kActionKeyType, true}, - {"q", KEYCODE_q, 'q', "q", kActionKeyType, true}, - {"r", KEYCODE_r, 'r', "r", kActionKeyType, true}, - {"s", KEYCODE_s, 's', "s", kActionKeyType, true}, - {"t", KEYCODE_t, 't', "t", kActionKeyType, true}, - {"u", KEYCODE_u, 'u', "u", kActionKeyType, true}, - {"v", KEYCODE_v, 'v', "v", kActionKeyType, true}, - {"w", KEYCODE_w, 'w', "w", kActionKeyType, true}, - {"x", KEYCODE_x, 'x', "x", kActionKeyType, true}, - {"y", KEYCODE_y, 'y', "y", kActionKeyType, true}, - {"z", KEYCODE_z, 'z', "z", kActionKeyType, true}, - {"DELETE", KEYCODE_DELETE, 0, "Del", kActionKeyType, false}, + {"BACKSPACE", KEYCODE_BACKSPACE, ASCII_BACKSPACE, "Backspace", kActionKeyType, ~0}, + {"TAB", KEYCODE_TAB, ASCII_TAB, "Tab", kActionKeyType, ~0}, + {"CLEAR", KEYCODE_CLEAR, 0, "Clear", kActionKeyType, ~0}, + {"RETURN", KEYCODE_RETURN, ASCII_RETURN, "Return", kActionKeyType, ~0}, + {"PAUSE", KEYCODE_PAUSE, 0, "Pause", kActionKeyType, ~0}, + {"ESCAPE", KEYCODE_ESCAPE, ASCII_ESCAPE, "Esc", kStartKeyType, ~0}, + {"SPACE", KEYCODE_SPACE, ASCII_SPACE, "Space", kActionKeyType, ~0}, + {"EXCLAIM", KEYCODE_EXCLAIM, '!', "!", kActionKeyType, ~0}, + {"QUOTEDBL", KEYCODE_QUOTEDBL, '"', "\"", kActionKeyType, ~0}, + {"HASH", KEYCODE_HASH, '#', "#", kActionKeyType, ~0}, + {"DOLLAR", KEYCODE_DOLLAR, '$', "$", kActionKeyType, ~0}, + {"AMPERSAND", KEYCODE_AMPERSAND, '&', "&", kActionKeyType, ~0}, + {"QUOTE", KEYCODE_QUOTE, '\'', "'", kActionKeyType, ~0}, + {"LEFTPAREN", KEYCODE_LEFTPAREN, '(', "(", kActionKeyType, ~0}, + {"RIGHTPAREN", KEYCODE_RIGHTPAREN, ')', ")", kActionKeyType, ~0}, + {"ASTERISK", KEYCODE_ASTERISK, '*', "*", kActionKeyType, ~0}, + {"PLUS", KEYCODE_PLUS, '+', "+", kActionKeyType, ~0}, + {"COMMA", KEYCODE_COMMA, ',', ",", kActionKeyType, ~0}, + {"MINUS", KEYCODE_MINUS, '-', "-", kActionKeyType, ~0}, + {"PERIOD", KEYCODE_PERIOD, '.', ".", kActionKeyType, ~0}, + {"SLASH", KEYCODE_SLASH, '/', "/", kActionKeyType, ~0}, + {"0", KEYCODE_0, '0', "0", kActionKeyType, ~0}, + {"1", KEYCODE_1, '1', "1", kActionKeyType, ~0}, + {"2", KEYCODE_2, '2', "2", kActionKeyType, ~0}, + {"3", KEYCODE_3, '3', "3", kActionKeyType, ~0}, + {"4", KEYCODE_4, '4', "4", kActionKeyType, ~0}, + {"5", KEYCODE_5, '5', "5", kActionKeyType, ~0}, + {"6", KEYCODE_6, '6', "6", kActionKeyType, ~0}, + {"7", KEYCODE_7, '7', "7", kActionKeyType, ~0}, + {"8", KEYCODE_8, '8', "8", kActionKeyType, ~0}, + {"9", KEYCODE_9, '9', "9", kActionKeyType, ~0}, + {"COLON", KEYCODE_COLON, ':', ":", kActionKeyType, ~0}, + {"SEMICOLON", KEYCODE_SEMICOLON, ';', ";", kActionKeyType, ~0}, + {"LESS", KEYCODE_LESS, '<', "<", kActionKeyType, ~0}, + {"EQUALS", KEYCODE_EQUALS, '=', "=", kActionKeyType, ~0}, + {"GREATER", KEYCODE_GREATER, '>', ">", kActionKeyType, ~0}, + {"QUESTION", KEYCODE_QUESTION, '?', "?", kActionKeyType, ~0}, + {"AT", KEYCODE_AT, '@', "@", kActionKeyType, ~0}, + + {"LEFTBRACKET", KEYCODE_LEFTBRACKET, '[', "[", kActionKeyType, ~0}, + {"BACKSLASH", KEYCODE_BACKSLASH, '\\', "\\", kActionKeyType, ~0}, + {"RIGHTBRACKET", KEYCODE_RIGHTBRACKET, ']', "]", kActionKeyType, ~0}, + {"CARET", KEYCODE_CARET, '^', "^", kActionKeyType, ~0}, + {"UNDERSCORE", KEYCODE_UNDERSCORE, '_', "_", kActionKeyType, ~0}, + {"BACKQUOTE", KEYCODE_BACKQUOTE, '`', "`", kActionKeyType, ~0}, + {"a", KEYCODE_a, 'A', "A", kActionKeyType, ~0}, + {"b", KEYCODE_b, 'B', "B", kActionKeyType, ~0}, + {"c", KEYCODE_c, 'C', "C", kActionKeyType, ~0}, + {"d", KEYCODE_d, 'D', "D", kActionKeyType, ~0}, + {"e", KEYCODE_e, 'E', "E", kActionKeyType, ~0}, + {"f", KEYCODE_f, 'F', "F", kActionKeyType, ~0}, + {"g", KEYCODE_g, 'G', "G", kActionKeyType, ~0}, + {"h", KEYCODE_h, 'H', "H", kActionKeyType, ~0}, + {"i", KEYCODE_i, 'I', "I", kActionKeyType, ~0}, + {"j", KEYCODE_j, 'J', "J", kActionKeyType, ~0}, + {"k", KEYCODE_k, 'K', "K", kActionKeyType, ~0}, + {"l", KEYCODE_l, 'L', "L", kActionKeyType, ~0}, + {"m", KEYCODE_m, 'M', "M", kActionKeyType, ~0}, + {"n", KEYCODE_n, 'N', "N", kActionKeyType, ~0}, + {"o", KEYCODE_o, 'O', "O", kActionKeyType, ~0}, + {"p", KEYCODE_p, 'P', "P", kActionKeyType, ~0}, + {"q", KEYCODE_q, 'Q', "Q", kActionKeyType, ~0}, + {"r", KEYCODE_r, 'R', "R", kActionKeyType, ~0}, + {"s", KEYCODE_s, 'S', "S", kActionKeyType, ~0}, + {"t", KEYCODE_t, 'T', "T", kActionKeyType, ~0}, + {"u", KEYCODE_u, 'U', "U", kActionKeyType, ~0}, + {"v", KEYCODE_v, 'V', "V", kActionKeyType, ~0}, + {"w", KEYCODE_w, 'W', "W", kActionKeyType, ~0}, + {"x", KEYCODE_x, 'X', "X", kActionKeyType, ~0}, + {"y", KEYCODE_y, 'Y', "Y", kActionKeyType, ~0}, + {"z", KEYCODE_z, 'Z', "Z", kActionKeyType, ~0}, + {"DELETE", KEYCODE_DELETE, 0, "Del", kActionKeyType, ~0}, // Numeric keypad - {"KP0", KEYCODE_KP0, 0, "KP0", kActionKeyType, false}, - {"KP1", KEYCODE_KP1, 0, "KP1", kActionKeyType, false}, - {"KP2", KEYCODE_KP2, 0, "KP2", kActionKeyType, false}, - {"KP3", KEYCODE_KP3, 0, "KP3", kActionKeyType, false}, - {"KP4", KEYCODE_KP4, 0, "KP4", kActionKeyType, false}, - {"KP5", KEYCODE_KP5, 0, "KP5", kActionKeyType, false}, - {"KP6", KEYCODE_KP6, 0, "KP6", kActionKeyType, false}, - {"KP7", KEYCODE_KP7, 0, "KP7", kActionKeyType, false}, - {"KP8", KEYCODE_KP8, 0, "KP8", kActionKeyType, false}, - {"KP9", KEYCODE_KP9, 0, "KP9", kActionKeyType, false}, - {"KP_PERIOD", KEYCODE_KP_PERIOD, 0, "KP.", kActionKeyType, false}, - {"KP_DIVIDE", KEYCODE_KP_DIVIDE, 0, "KP/", kActionKeyType, false}, - {"KP_MULTIPLY", KEYCODE_KP_MULTIPLY, 0, "KP*", kActionKeyType, false}, - {"KP_MINUS", KEYCODE_KP_MINUS, 0, "KP-", kActionKeyType, false}, - {"KP_PLUS", KEYCODE_KP_PLUS, 0, "KP+", kActionKeyType, false}, - {"KP_ENTER", KEYCODE_KP_ENTER, 0, "KP Enter", kActionKeyType, false}, - {"KP_EQUALS", KEYCODE_KP_EQUALS, 0, "KP=", kActionKeyType, false}, + {"KP0", KEYCODE_KP0, 0, "KP0", kActionKeyType, ~0}, + {"KP1", KEYCODE_KP1, 0, "KP1", kActionKeyType, ~0}, + {"KP2", KEYCODE_KP2, 0, "KP2", kActionKeyType, ~0}, + {"KP3", KEYCODE_KP3, 0, "KP3", kActionKeyType, ~0}, + {"KP4", KEYCODE_KP4, 0, "KP4", kActionKeyType, ~0}, + {"KP5", KEYCODE_KP5, 0, "KP5", kActionKeyType, ~0}, + {"KP6", KEYCODE_KP6, 0, "KP6", kActionKeyType, ~0}, + {"KP7", KEYCODE_KP7, 0, "KP7", kActionKeyType, ~0}, + {"KP8", KEYCODE_KP8, 0, "KP8", kActionKeyType, ~0}, + {"KP9", KEYCODE_KP9, 0, "KP9", kActionKeyType, ~0}, + {"KP_PERIOD", KEYCODE_KP_PERIOD, 0, "KP.", kActionKeyType, ~0}, + {"KP_DIVIDE", KEYCODE_KP_DIVIDE, 0, "KP/", kActionKeyType, ~0}, + {"KP_MULTIPLY", KEYCODE_KP_MULTIPLY, 0, "KP*", kActionKeyType, ~0}, + {"KP_MINUS", KEYCODE_KP_MINUS, 0, "KP-", kActionKeyType, ~0}, + {"KP_PLUS", KEYCODE_KP_PLUS, 0, "KP+", kActionKeyType, ~0}, + {"KP_ENTER", KEYCODE_KP_ENTER, 0, "KP Enter", kActionKeyType, ~0}, + {"KP_EQUALS", KEYCODE_KP_EQUALS, 0, "KP=", kActionKeyType, ~0}, // Arrows + Home/End pad - {"UP", KEYCODE_UP, 0, "Up", kDirUpKeyType, false}, - {"DOWN", KEYCODE_DOWN, 0, "Down", kDirDownKeyType, false}, - {"RIGHT", KEYCODE_RIGHT, 0, "Right", kDirRightKeyType, false}, - {"LEFT", KEYCODE_LEFT, 0, "Left", kDirLeftKeyType, false}, - {"INSERT", KEYCODE_INSERT, 0, "Insert", kActionKeyType, false}, - {"HOME", KEYCODE_HOME, 0, "Home", kActionKeyType, false}, - {"END", KEYCODE_END, 0, "End", kActionKeyType, false}, - {"PAGEUP", KEYCODE_PAGEUP, 0, "PgUp", kActionKeyType, false}, - {"PAGEDOWN", KEYCODE_PAGEDOWN, 0, "PgDn", kActionKeyType, false}, + {"UP", KEYCODE_UP, 0, "Up", kDirUpKeyType, ~0}, + {"DOWN", KEYCODE_DOWN, 0, "Down", kDirDownKeyType, ~0}, + {"RIGHT", KEYCODE_RIGHT, 0, "Right", kDirRightKeyType, ~0}, + {"LEFT", KEYCODE_LEFT, 0, "Left", kDirLeftKeyType, ~0}, + {"INSERT", KEYCODE_INSERT, 0, "Insert", kActionKeyType, ~0}, + {"HOME", KEYCODE_HOME, 0, "Home", kActionKeyType, ~0}, + {"END", KEYCODE_END, 0, "End", kActionKeyType, ~0}, + {"PAGEUP", KEYCODE_PAGEUP, 0, "PgUp", kActionKeyType, ~0}, + {"PAGEDOWN", KEYCODE_PAGEDOWN, 0, "PgDn", kActionKeyType, ~0}, // Function keys - {"F1", KEYCODE_F1, ASCII_F1, "F1", kActionKeyType, false}, - {"F2", KEYCODE_F2, ASCII_F2, "F2", kActionKeyType, false}, - {"F3", KEYCODE_F3, ASCII_F3, "F3", kActionKeyType, false}, - {"F4", KEYCODE_F4, ASCII_F4, "F4", kActionKeyType, false}, - {"F5", KEYCODE_F5, ASCII_F5, "F5", kActionKeyType, false}, - {"F6", KEYCODE_F6, ASCII_F6, "F6", kActionKeyType, false}, - {"F7", KEYCODE_F7, ASCII_F7, "F7", kActionKeyType, false}, - {"F8", KEYCODE_F8, ASCII_F8, "F8", kActionKeyType, false}, - {"F9", KEYCODE_F9, ASCII_F9, "F9", kActionKeyType, false}, - {"F10", KEYCODE_F10, ASCII_F10, "F10", kActionKeyType, false}, - {"F11", KEYCODE_F11, ASCII_F11, "F11", kActionKeyType, false}, - {"F12", KEYCODE_F12, ASCII_F12, "F12", kActionKeyType, false}, - {"F13", KEYCODE_F13, 0, "F13", kActionKeyType, false}, - {"F14", KEYCODE_F14, 0, "F14", kActionKeyType, false}, - {"F15", KEYCODE_F15, 0, "F15", kActionKeyType, false}, + {"F1", KEYCODE_F1, ASCII_F1, "F1", kActionKeyType, ~0}, + {"F2", KEYCODE_F2, ASCII_F2, "F2", kActionKeyType, ~0}, + {"F3", KEYCODE_F3, ASCII_F3, "F3", kActionKeyType, ~0}, + {"F4", KEYCODE_F4, ASCII_F4, "F4", kActionKeyType, ~0}, + {"F5", KEYCODE_F5, ASCII_F5, "F5", kActionKeyType, ~0}, + {"F6", KEYCODE_F6, ASCII_F6, "F6", kActionKeyType, ~0}, + {"F7", KEYCODE_F7, ASCII_F7, "F7", kActionKeyType, ~0}, + {"F8", KEYCODE_F8, ASCII_F8, "F8", kActionKeyType, ~0}, + {"F9", KEYCODE_F9, ASCII_F9, "F9", kActionKeyType, ~0}, + {"F10", KEYCODE_F10, ASCII_F10, "F10", kActionKeyType, ~0}, + {"F11", KEYCODE_F11, ASCII_F11, "F11", kActionKeyType, ~0}, + {"F12", KEYCODE_F12, ASCII_F12, "F12", kActionKeyType, ~0}, + {"F13", KEYCODE_F13, 0, "F13", kActionKeyType, ~0}, + {"F14", KEYCODE_F14, 0, "F14", kActionKeyType, ~0}, + {"F15", KEYCODE_F15, 0, "F15", kActionKeyType, ~0}, + + +// // Modifier keys pressed alone +// {"RSHIFT", KEYCODE_RSHIFT, 0, "Right Shift", kModiferKeyType, ~KBD_SHIFT}, +// {"LSHIFT", KEYCODE_LSHIFT, 0, "Left Shift", kModiferKeyType, ~KBD_SHIFT}, +// {"RCTRL", KEYCODE_RCTRL, 0, "Right Ctrl", kModiferKeyType, ~KBD_CTRL}, +// {"LCTRL", KEYCODE_LCTRL, 0, "Left Ctrl", kModiferKeyType, ~KBD_CTRL}, +// {"RALT", KEYCODE_RALT, 0, "Right Alt", kModiferKeyType, ~KBD_ALT}, +// {"LALT", KEYCODE_LALT, 0, "Left Alt", kModiferKeyType, ~KBD_ALT}, + // Miscellaneous function keys - {"HELP", KEYCODE_HELP, 0, "Help", kActionKeyType, false}, - {"PRINT", KEYCODE_PRINT, 0, "Print", kActionKeyType, false}, - {"SYSREQ", KEYCODE_SYSREQ, 0, "SysRq", kActionKeyType, false}, - {"BREAK", KEYCODE_BREAK, 0, "Break", kActionKeyType, false}, - {"MENU", KEYCODE_MENU, 0, "Menu", kActionKeyType, false}, + {"HELP", KEYCODE_HELP, 0, "Help", kActionKeyType, ~0}, + {"PRINT", KEYCODE_PRINT, 0, "Print", kActionKeyType, ~0}, + {"SYSREQ", KEYCODE_SYSREQ, 0, "SysRq", kActionKeyType, ~0}, + {"BREAK", KEYCODE_BREAK, 0, "Break", kActionKeyType, ~0}, + {"MENU", KEYCODE_MENU, 0, "Menu", kActionKeyType, ~0}, // Power Macintosh power key - {"POWER", KEYCODE_POWER, 0, "Power", kActionKeyType, false}, + {"POWER", KEYCODE_POWER, 0, "Power", kActionKeyType, ~0}, // Some european keyboards - {"EURO", KEYCODE_EURO, 0, "Euro", kActionKeyType, false}, + {"EURO", KEYCODE_EURO, 0, "Euro", kActionKeyType, ~0}, // Atari keyboard has Undo - {"UNDO", KEYCODE_UNDO, 0, "Undo", kActionKeyType, false}, - {0, KEYCODE_INVALID, 0, 0, kGenericKeyType, false} + {"UNDO", KEYCODE_UNDO, 0, "Undo", kActionKeyType, ~0}, + {0, KEYCODE_INVALID, 0, 0, kGenericKeyType, ~0} }; struct Mod { byte flag; const char *id; const char *desc; - bool shiftable; }; static const Mod modifiers[] = { - { 0, "", "", false }, - { KBD_CTRL, "C+", "Ctrl+", false }, - { KBD_ALT, "A+", "Alt+", false }, - { KBD_SHIFT, "", "", true }, - { KBD_CTRL | KBD_ALT, "C+A+", "Ctrl+Alt+", false }, - { KBD_SHIFT | KBD_CTRL, "S+C+", "Shift+Ctrl+", true }, - { KBD_SHIFT | KBD_CTRL | KBD_ALT, "C+A+", "Ctrl+Alt+", true }, - { 0, 0, 0, false } + { 0, "", "" }, + { KBD_CTRL, "C+", "Ctrl+" }, + { KBD_ALT, "A+", "Alt+" }, + { KBD_SHIFT, "S+", "Shift+" }, + { KBD_CTRL | KBD_ALT, "C+A+", "Ctrl+Alt+" }, + { KBD_SHIFT | KBD_CTRL, "S+C+", "Shift+Ctrl+" }, + { KBD_SHIFT | KBD_CTRL | KBD_ALT, "S+C+A+", "Shift+Ctrl+Alt+" }, + { 0, 0, 0 } }; #endif @@ -206,23 +215,18 @@ Common::HardwareKeySet *OSystem_SDL::getHardwareKeySet() { uint16 ascii; for (mod = modifiers; mod->id; mod++) { - for (key = keys; key->hwId; key++) { - ascii = key->ascii; - - if (mod->shiftable && key->shiftable) { - snprintf(fullKeyId, 50, "%s%c", mod->id, toupper(key->hwId[0])); - snprintf(fullKeyDesc, 100, "%s%c", mod->desc, toupper(key->desc[0])); - ascii = toupper(key->ascii); - } else if (mod->shiftable) { - snprintf(fullKeyId, 50, "S+%s%s", mod->id, key->hwId); - snprintf(fullKeyDesc, 100, "Shift+%s%s", mod->desc, key->desc); - } else { - snprintf(fullKeyId, 50, "%s%s", mod->id, key->hwId); - snprintf(fullKeyDesc, 100, "%s%s", mod->desc, key->desc); - } - - keySet->addHardwareKey(new HardwareKey(fullKeyId, KeyState(key->keycode, ascii, mod->flag), fullKeyDesc, key->preferredAction )); - } + snprintf(fullKeyId, 50, "S+%s", mod->id); + snprintf(fullKeyDesc, 100, "Shift+%s", mod->desc); + + keySet->addHardwareMod(new HardwareMod(fullKeyId, mod->flag, fullKeyDesc)); + } + for (key = keys; key->hwId; key++) { + ascii = key->ascii; + + snprintf(fullKeyId, 50, "%s", key->hwId); + snprintf(fullKeyDesc, 100, "%s", key->desc); + + keySet->addHardwareKey(new HardwareKey(fullKeyId, KeyState(key->keycode, ascii, 0), fullKeyDesc, key->preferredAction)); } return keySet; -- cgit v1.2.3 From e0e09e43b84cf9637fb289bd466235116674c1f2 Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Fri, 7 Aug 2009 01:17:57 +0000 Subject: key remap dialog correctly reads keystrokes again, and can tell modified keys from unmodified keys (but does not yet print modifier prefixes, and actions mapped to modified keys still do not trigger) svn-id: r43091 --- backends/keymapper/hardware-key.h | 22 +++++++++++++- backends/keymapper/keymapper.cpp | 4 +++ backends/keymapper/keymapper.h | 5 ++++ backends/keymapper/remap-dialog.cpp | 6 +++- backends/platform/sdl/hardwarekeys.cpp | 52 +++++++++++++++++----------------- 5 files changed, 61 insertions(+), 28 deletions(-) (limited to 'backends') diff --git a/backends/keymapper/hardware-key.h b/backends/keymapper/hardware-key.h index c8c1d3c145..34631a9484 100644 --- a/backends/keymapper/hardware-key.h +++ b/backends/keymapper/hardware-key.h @@ -127,7 +127,27 @@ public: List::const_iterator it; for (it = _keys.begin(); it != _keys.end(); it++) { - if ((*it)->key == keystate) + if ((*it)->key.keycode == keystate.keycode) + return (*it); + } + return 0; + } + + const HardwareMod *findHardwareMod(const char *id) const { + List::const_iterator it; + + for (it = _mods.begin(); it != _mods.end(); it++) { + if (strncmp((*it)->hwModId, id, HWKEY_ID_SIZE) == 0) + return (*it); + } + return 0; + } + + const HardwareMod *findHardwareMod(const KeyState& keystate) const { + List::const_iterator it; + + for (it = _mods.begin(); it != _mods.end(); it++) { + if ((*it)->modFlags == keystate.flags) return (*it); } return 0; diff --git a/backends/keymapper/keymapper.cpp b/backends/keymapper/keymapper.cpp index c0c454168c..a121ebafee 100644 --- a/backends/keymapper/keymapper.cpp +++ b/backends/keymapper/keymapper.cpp @@ -272,6 +272,10 @@ const HardwareKey *Keymapper::findHardwareKey(const KeyState& key) { return (_hardwareKeys) ? _hardwareKeys->findHardwareKey(key) : 0; } +const HardwareMod *Keymapper::findHardwareMod(const KeyState& key) { + return (_hardwareKeys) ? _hardwareKeys->findHardwareMod(key) : 0; +} + } // end of namespace Common #endif // #ifdef ENABLE_KEYMAPPER diff --git a/backends/keymapper/keymapper.h b/backends/keymapper/keymapper.h index f492882ca2..af3314f8f5 100644 --- a/backends/keymapper/keymapper.h +++ b/backends/keymapper/keymapper.h @@ -170,6 +170,11 @@ public: */ const HardwareKey *findHardwareKey(const KeyState& key); + /** + * Return a HardwareMod pointer for the given key state + */ + const HardwareMod *findHardwareMod(const KeyState& key); + Domain& getGlobalDomain() { return _globalDomain; } Domain& getGameDomain() { return _gameDomain; } const Stack& getActiveStack() const { return _activeMaps; } diff --git a/backends/keymapper/remap-dialog.cpp b/backends/keymapper/remap-dialog.cpp index 0440acdd0a..9341c82747 100644 --- a/backends/keymapper/remap-dialog.cpp +++ b/backends/keymapper/remap-dialog.cpp @@ -239,11 +239,15 @@ void RemapDialog::handleKeyDown(Common::KeyState state) { void RemapDialog::handleKeyUp(Common::KeyState state) { if (_activeRemapAction) { const HardwareKey *hwkey = _keymapper->findHardwareKey(state); + const HardwareMod *hwmod = _keymapper->findHardwareMod(state); debug(0, "Key: %d, %d (%c), %x", state.keycode, state.ascii, (state.ascii ? state.ascii : ' '), state.flags); if (hwkey) { - _activeRemapAction->mapKey(hwkey); + HardwareKey *temphwkey = new HardwareKey(*hwkey); + temphwkey->description = hwkey->description; + temphwkey->key.flags = hwmod->modFlags; + _activeRemapAction->mapKey(temphwkey); _activeRemapAction->getParent()->saveMappings(); _changes = true; stopRemapping(); diff --git a/backends/platform/sdl/hardwarekeys.cpp b/backends/platform/sdl/hardwarekeys.cpp index bba48286f0..c063ea5bff 100644 --- a/backends/platform/sdl/hardwarekeys.cpp +++ b/backends/platform/sdl/hardwarekeys.cpp @@ -86,32 +86,32 @@ static const Key keys[] = { {"CARET", KEYCODE_CARET, '^', "^", kActionKeyType, ~0}, {"UNDERSCORE", KEYCODE_UNDERSCORE, '_', "_", kActionKeyType, ~0}, {"BACKQUOTE", KEYCODE_BACKQUOTE, '`', "`", kActionKeyType, ~0}, - {"a", KEYCODE_a, 'A', "A", kActionKeyType, ~0}, - {"b", KEYCODE_b, 'B', "B", kActionKeyType, ~0}, - {"c", KEYCODE_c, 'C', "C", kActionKeyType, ~0}, - {"d", KEYCODE_d, 'D', "D", kActionKeyType, ~0}, - {"e", KEYCODE_e, 'E', "E", kActionKeyType, ~0}, - {"f", KEYCODE_f, 'F', "F", kActionKeyType, ~0}, - {"g", KEYCODE_g, 'G', "G", kActionKeyType, ~0}, - {"h", KEYCODE_h, 'H', "H", kActionKeyType, ~0}, - {"i", KEYCODE_i, 'I', "I", kActionKeyType, ~0}, - {"j", KEYCODE_j, 'J', "J", kActionKeyType, ~0}, - {"k", KEYCODE_k, 'K', "K", kActionKeyType, ~0}, - {"l", KEYCODE_l, 'L', "L", kActionKeyType, ~0}, - {"m", KEYCODE_m, 'M', "M", kActionKeyType, ~0}, - {"n", KEYCODE_n, 'N', "N", kActionKeyType, ~0}, - {"o", KEYCODE_o, 'O', "O", kActionKeyType, ~0}, - {"p", KEYCODE_p, 'P', "P", kActionKeyType, ~0}, - {"q", KEYCODE_q, 'Q', "Q", kActionKeyType, ~0}, - {"r", KEYCODE_r, 'R', "R", kActionKeyType, ~0}, - {"s", KEYCODE_s, 'S', "S", kActionKeyType, ~0}, - {"t", KEYCODE_t, 'T', "T", kActionKeyType, ~0}, - {"u", KEYCODE_u, 'U', "U", kActionKeyType, ~0}, - {"v", KEYCODE_v, 'V', "V", kActionKeyType, ~0}, - {"w", KEYCODE_w, 'W', "W", kActionKeyType, ~0}, - {"x", KEYCODE_x, 'X', "X", kActionKeyType, ~0}, - {"y", KEYCODE_y, 'Y', "Y", kActionKeyType, ~0}, - {"z", KEYCODE_z, 'Z', "Z", kActionKeyType, ~0}, + {"a", KEYCODE_a, 'a', "A", kActionKeyType, ~0}, + {"b", KEYCODE_b, 'b', "B", kActionKeyType, ~0}, + {"c", KEYCODE_c, 'c', "C", kActionKeyType, ~0}, + {"d", KEYCODE_d, 'd', "D", kActionKeyType, ~0}, + {"e", KEYCODE_e, 'e', "E", kActionKeyType, ~0}, + {"f", KEYCODE_f, 'f', "F", kActionKeyType, ~0}, + {"g", KEYCODE_g, 'g', "G", kActionKeyType, ~0}, + {"h", KEYCODE_h, 'h', "H", kActionKeyType, ~0}, + {"i", KEYCODE_i, 'i', "I", kActionKeyType, ~0}, + {"j", KEYCODE_j, 'j', "J", kActionKeyType, ~0}, + {"k", KEYCODE_k, 'k', "K", kActionKeyType, ~0}, + {"l", KEYCODE_l, 'l', "L", kActionKeyType, ~0}, + {"m", KEYCODE_m, 'm', "M", kActionKeyType, ~0}, + {"n", KEYCODE_n, 'n', "N", kActionKeyType, ~0}, + {"o", KEYCODE_o, 'o', "O", kActionKeyType, ~0}, + {"p", KEYCODE_p, 'p', "P", kActionKeyType, ~0}, + {"q", KEYCODE_q, 'q', "Q", kActionKeyType, ~0}, + {"r", KEYCODE_r, 'r', "R", kActionKeyType, ~0}, + {"s", KEYCODE_s, 's', "S", kActionKeyType, ~0}, + {"t", KEYCODE_t, 't', "T", kActionKeyType, ~0}, + {"u", KEYCODE_u, 'u', "U", kActionKeyType, ~0}, + {"v", KEYCODE_v, 'v', "V", kActionKeyType, ~0}, + {"w", KEYCODE_w, 'w', "W", kActionKeyType, ~0}, + {"x", KEYCODE_x, 'x', "X", kActionKeyType, ~0}, + {"y", KEYCODE_y, 'y', "Y", kActionKeyType, ~0}, + {"z", KEYCODE_z, 'z', "Z", kActionKeyType, ~0}, {"DELETE", KEYCODE_DELETE, 0, "Del", kActionKeyType, ~0}, // Numeric keypad -- cgit v1.2.3 From 77594f46b1db7ed6bde4413f74d12a48e720cbfa Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Wed, 12 Aug 2009 09:26:00 +0000 Subject: Laying some groundwork for hopefully getting modifiers working in a less hacked-on manner svn-id: r43316 --- backends/keymapper/hardware-key.h | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'backends') diff --git a/backends/keymapper/hardware-key.h b/backends/keymapper/hardware-key.h index 34631a9484..8c286288ae 100644 --- a/backends/keymapper/hardware-key.h +++ b/backends/keymapper/hardware-key.h @@ -37,6 +37,22 @@ namespace Common { #define HWKEY_ID_SIZE (30) + +// Structure for describing specific key+modifier combos mapped to actions, +// to allow for modifiers to work properly without having to define the whole +// hardware key set an additional time for each possible modifier combination +struct ActionKey { + KeyCode keycode; + byte flags; + /** unique id used for saving/loading to config */ + char actKeyId[HWKEY_ID_SIZE]; + + /** Human readable description */ + String description; + +}; + + /** * Describes an available hardware key */ @@ -56,9 +72,12 @@ struct HardwareKey { KeyType type; ActionType preferredAction; + // Mask of modifiers that can possibly apply to this key. + uint32 modMask; + HardwareKey(const char *i, KeyState ky = KeyState(), String desc = "", - KeyType typ = kGenericKeyType, ActionType prefAct = kGenericActionType) - : key(ky), description(desc), type(typ), preferredAction(prefAct) { + KeyType typ = kGenericKeyType, ActionType prefAct = kGenericActionType, uint32 mods = ~0) + : key(ky), description(desc), type(typ), preferredAction(prefAct), modMask(mods) { assert(i); strncpy(hwKeyId, i, HWKEY_ID_SIZE); } -- cgit v1.2.3 From 44e79803648ba7704e97031752506ad42176990d Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Fri, 14 Aug 2009 08:11:18 +0000 Subject: Added proper saving/loading of mapped key modifiers. Fixed modifier recognition in a much less hackish manner, (but still using a minor hack as a stopgap until KeyState can be replaced as the primary lookup type for the keymapper). svn-id: r43363 --- backends/keymapper/keymap.cpp | 22 +++++++++++++++++----- backends/keymapper/keymapper.cpp | 14 ++++++++++++-- backends/keymapper/remap-dialog.cpp | 28 ++++++++++++++++++++-------- 3 files changed, 49 insertions(+), 15 deletions(-) (limited to 'backends') diff --git a/backends/keymapper/keymap.cpp b/backends/keymapper/keymap.cpp index 95b64f88e7..fe6f133254 100644 --- a/backends/keymapper/keymap.cpp +++ b/backends/keymapper/keymap.cpp @@ -127,6 +127,10 @@ void Keymap::loadMappings(const HardwareKeySet *hwKeys) { ConfigManager::Domain::iterator it; String prefix = KEYMAP_KEY_PREFIX + _name + "_"; + uint32 modId = 0; + char hwId[HWKEY_ID_SIZE+1]; + memset(hwId,0,HWKEY_ID_SIZE+1); + for (it = _configDomain->begin(); it != _configDomain->end(); it++) { const String& key = it->_key; @@ -145,15 +149,17 @@ void Keymap::loadMappings(const HardwareKeySet *hwKeys) { continue; } - const HardwareKey *hwKey = hwKeys->findHardwareKey(it->_value.c_str()); + sscanf(it->_value.c_str(),"%d,%s",&modId,hwId); + const HardwareKey *hwKey = hwKeys->findHardwareKey(hwId); if (!hwKey) { warning("HardwareKey with ID %s not known", it->_value.c_str()); _configDomain->erase(key); continue; } - - ua->mapKey(hwKey); + HardwareKey *mappedKey = new HardwareKey(*hwKey); + mappedKey->key.flags = modId; + ua->mapKey(mappedKey); } } @@ -171,13 +177,19 @@ void Keymap::saveMappings() { String actId((*it)->id, (*it)->id + actIdLen); char hwId[HWKEY_ID_SIZE+1]; - memset(hwId, 0, HWKEY_ID_SIZE+1); + char modId[4]; + memset(modId, 0, 4); + if ((*it)->getMappedKey()) { memcpy(hwId, (*it)->getMappedKey()->hwKeyId, HWKEY_ID_SIZE); + sprintf(modId,"%d",(*it)->getMappedKey()->key.flags); } - _configDomain->setVal(prefix + actId, hwId); + String val = modId; + val += ','; + val += hwId; + _configDomain->setVal(prefix + actId, val); } } diff --git a/backends/keymapper/keymapper.cpp b/backends/keymapper/keymapper.cpp index a121ebafee..24b4d7e5f8 100644 --- a/backends/keymapper/keymapper.cpp +++ b/backends/keymapper/keymapper.cpp @@ -192,18 +192,28 @@ bool Keymapper::mapKey(const KeyState& key, bool keyDown) { Action *action = 0; if (keyDown) { + // HACK: Temporary fix for modifier recognition, get the hwkey's keystate + // to correct for keydown and keyup generating different ascii codes in SDL + // to be solved more permanently by using a structure other than KeyState + const HardwareKey *hwkey = findHardwareKey(key); + if (!hwkey) + return false; + + KeyState k = hwkey->key; + k.flags = key.flags; + // Search for key in active keymap stack for (int i = _activeMaps.size() - 1; i >= 0; --i) { MapRecord mr = _activeMaps[i]; - action = mr.keymap->getMappedAction(key); + action = mr.keymap->getMappedAction(k); if (action || mr.inherit == false) break; } if (action) - _keysDown[key] = action; + _keysDown[k] = action; } else { HashMap::iterator it = _keysDown.find(key); diff --git a/backends/keymapper/remap-dialog.cpp b/backends/keymapper/remap-dialog.cpp index 9341c82747..aca2630d6d 100644 --- a/backends/keymapper/remap-dialog.cpp +++ b/backends/keymapper/remap-dialog.cpp @@ -239,15 +239,14 @@ void RemapDialog::handleKeyDown(Common::KeyState state) { void RemapDialog::handleKeyUp(Common::KeyState state) { if (_activeRemapAction) { const HardwareKey *hwkey = _keymapper->findHardwareKey(state); - const HardwareMod *hwmod = _keymapper->findHardwareMod(state); - debug(0, "Key: %d, %d (%c), %x", state.keycode, state.ascii, (state.ascii ? state.ascii : ' '), state.flags); + debug( "Key: %d, %d (%c), %x", state.keycode, state.ascii, (state.ascii ? state.ascii : ' '), state.flags); if (hwkey) { - HardwareKey *temphwkey = new HardwareKey(*hwkey); - temphwkey->description = hwkey->description; - temphwkey->key.flags = hwmod->modFlags; - _activeRemapAction->mapKey(temphwkey); + HardwareKey *mappedkey = new HardwareKey(*hwkey); + mappedkey->description = hwkey->description; + mappedkey->key.flags = (state.flags & hwkey->modMask); + _activeRemapAction->mapKey(mappedkey); _activeRemapAction->getParent()->saveMappings(); _changes = true; stopRemapping(); @@ -363,8 +362,21 @@ void RemapDialog::refreshKeymap() { const HardwareKey *mappedKey = info.action->getMappedKey(); if (mappedKey) - widg.keyButton->setLabel(mappedKey->description); - else + { + Common::String description = ""; + if (mappedKey->key.flags) + { + byte flags = mappedKey->key.flags; + if (flags & KBD_CTRL) + description += "Ctrl+"; + if (flags & KBD_SHIFT) + description += "Shift+"; + if (flags & KBD_ALT) + description += "Alt+"; + } + description += mappedKey->description; + widg.keyButton->setLabel(description); + } else widg.keyButton->setLabel("-"); widg.actionText->setVisible(true); -- cgit v1.2.3 From 7ea0646a49a848d2cfa1f18162dba66fc6ddef0b Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Sat, 15 Aug 2009 08:48:13 +0000 Subject: Removed excessive modifier definitions, prevented excessive memory consumption if getHardwareKeyset is called multiple times. svn-id: r43395 --- backends/platform/sdl/hardwarekeys.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'backends') diff --git a/backends/platform/sdl/hardwarekeys.cpp b/backends/platform/sdl/hardwarekeys.cpp index c063ea5bff..623e8b50cf 100644 --- a/backends/platform/sdl/hardwarekeys.cpp +++ b/backends/platform/sdl/hardwarekeys.cpp @@ -162,7 +162,7 @@ static const Key keys[] = { {"F15", KEYCODE_F15, 0, "F15", kActionKeyType, ~0}, -// // Modifier keys pressed alone + // Modifier keys pressed alone // {"RSHIFT", KEYCODE_RSHIFT, 0, "Right Shift", kModiferKeyType, ~KBD_SHIFT}, // {"LSHIFT", KEYCODE_LSHIFT, 0, "Left Shift", kModiferKeyType, ~KBD_SHIFT}, // {"RCTRL", KEYCODE_RCTRL, 0, "Right Ctrl", kModiferKeyType, ~KBD_CTRL}, @@ -197,9 +197,6 @@ static const Mod modifiers[] = { { KBD_CTRL, "C+", "Ctrl+" }, { KBD_ALT, "A+", "Alt+" }, { KBD_SHIFT, "S+", "Shift+" }, - { KBD_CTRL | KBD_ALT, "C+A+", "Ctrl+Alt+" }, - { KBD_SHIFT | KBD_CTRL, "S+C+", "Shift+Ctrl+" }, - { KBD_SHIFT | KBD_CTRL | KBD_ALT, "S+C+A+", "Shift+Ctrl+Alt+" }, { 0, 0, 0 } }; #endif @@ -207,7 +204,11 @@ static const Mod modifiers[] = { Common::HardwareKeySet *OSystem_SDL::getHardwareKeySet() { #ifdef ENABLE_KEYMAPPER - HardwareKeySet *keySet = new HardwareKeySet(); + static HardwareKeySet *keySet = new HardwareKeySet(); + static bool keySetInited = false; + if (keySet && keySetInited) + return keySet; + const Key *key; const Mod *mod; char fullKeyId[50]; @@ -226,9 +227,11 @@ Common::HardwareKeySet *OSystem_SDL::getHardwareKeySet() { snprintf(fullKeyId, 50, "%s", key->hwId); snprintf(fullKeyDesc, 100, "%s", key->desc); - keySet->addHardwareKey(new HardwareKey(fullKeyId, KeyState(key->keycode, ascii, 0), fullKeyDesc, key->preferredAction)); + keySet->addHardwareKey(new HardwareKey(fullKeyId, KeyState(key->keycode, ascii, 0), fullKeyDesc, key->modableMask, key->preferredAction)); } + keySetInited = true; + return keySet; #else -- cgit v1.2.3 From 0af775717e30af665c973283c7df69209525a69a Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Sat, 15 Aug 2009 08:52:40 +0000 Subject: Added mandatory includes into hardware-key.h (so it can be included without compile error, without having to separately include several other header files), reworked ActionKey structure, changed HardwareKey::modMask from uint32 into byte. svn-id: r43396 --- backends/keymapper/hardware-key.h | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'backends') diff --git a/backends/keymapper/hardware-key.h b/backends/keymapper/hardware-key.h index 8c286288ae..94e6589a17 100644 --- a/backends/keymapper/hardware-key.h +++ b/backends/keymapper/hardware-key.h @@ -31,6 +31,10 @@ #ifdef ENABLE_KEYMAPPER #include "backends/keymapper/types.h" +#include "common/str.h" +#include "common/keyboard.h" +#include "common/list.h" +#include "common/util.h" namespace Common { @@ -44,11 +48,15 @@ namespace Common { struct ActionKey { KeyCode keycode; byte flags; - /** unique id used for saving/loading to config */ - char actKeyId[HWKEY_ID_SIZE]; - /** Human readable description */ - String description; + ActionKey (KeyCode ky, byte f) { + keycode = ky; + flags = f; + } + + bool operator ==(const ActionKey &x) const { + return keycode == x.keycode && flags == x.flags; + } }; @@ -73,10 +81,10 @@ struct HardwareKey { ActionType preferredAction; // Mask of modifiers that can possibly apply to this key. - uint32 modMask; + byte modMask; - HardwareKey(const char *i, KeyState ky = KeyState(), String desc = "", - KeyType typ = kGenericKeyType, ActionType prefAct = kGenericActionType, uint32 mods = ~0) + HardwareKey(const char *i, KeyState ky = KeyState(), String desc = "", byte mods = ~0, + KeyType typ = kGenericKeyType, ActionType prefAct = kGenericActionType) : key(ky), description(desc), type(typ), preferredAction(prefAct), modMask(mods) { assert(i); strncpy(hwKeyId, i, HWKEY_ID_SIZE); -- cgit v1.2.3 From 6ede8310932ab8a79310ebd6b0a14eaf687c1708 Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Sat, 15 Aug 2009 08:55:22 +0000 Subject: Added hash function for ActionKey in preparation for replacing KeyStates in the main keymapper hashtable with ActionKeys, removed a duplicated comment line. svn-id: r43397 --- backends/keymapper/keymap.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'backends') diff --git a/backends/keymapper/keymap.h b/backends/keymapper/keymap.h index 615fd9097d..5bb277c924 100644 --- a/backends/keymapper/keymap.h +++ b/backends/keymapper/keymap.h @@ -36,6 +36,7 @@ #include "common/keyboard.h" #include "common/list.h" #include "backends/keymapper/action.h" +#include "backends/keymapper/hardware-key.h" namespace Common { @@ -53,6 +54,17 @@ template<> struct Hash } }; +/** + * Hash function for ActionKey + */ +template<> struct Hash + : public UnaryFunction { + + uint operator()(const ActionKey &val) const { + return (uint)val.keycode | ((uint)val.flags << 24); + } +}; + class Keymap { public: Keymap(const String& name, Keymap *parent = 0) : _name(name), _parent(parent) {} @@ -90,7 +102,6 @@ public: /** * Save this keymap's mappings to the config manager * @note Changes are *not* flushed to disk, to do so call ConfMan.flushToDisk() - * @note Changes are *not* flushed to disk, to do so call ConfMan.flushToDisk() */ void saveMappings(); -- cgit v1.2.3 From 8d051e24feeb2e7410d7676328ad66fbf04a95c8 Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Sat, 15 Aug 2009 09:12:36 +0000 Subject: Added support for mapping keys to ctrl, alt, shift, or combinations thereof (though ctrl+alt will never trigger for some reason) svn-id: r43398 --- backends/keymapper/keymapper.cpp | 3 ++- backends/keymapper/types.h | 2 +- backends/platform/sdl/hardwarekeys.cpp | 12 ++++++------ 3 files changed, 9 insertions(+), 8 deletions(-) (limited to 'backends') diff --git a/backends/keymapper/keymapper.cpp b/backends/keymapper/keymapper.cpp index 24b4d7e5f8..d101e8e0d2 100644 --- a/backends/keymapper/keymapper.cpp +++ b/backends/keymapper/keymapper.cpp @@ -195,12 +195,13 @@ bool Keymapper::mapKey(const KeyState& key, bool keyDown) { // HACK: Temporary fix for modifier recognition, get the hwkey's keystate // to correct for keydown and keyup generating different ascii codes in SDL // to be solved more permanently by using a structure other than KeyState + const HardwareKey *hwkey = findHardwareKey(key); if (!hwkey) return false; KeyState k = hwkey->key; - k.flags = key.flags; + k.flags = key.flags & hwkey->modMask; // Search for key in active keymap stack for (int i = _activeMaps.size() - 1; i >= 0; --i) { diff --git a/backends/keymapper/types.h b/backends/keymapper/types.h index 004a90bfcd..3cce79ee9a 100644 --- a/backends/keymapper/types.h +++ b/backends/keymapper/types.h @@ -43,7 +43,7 @@ enum KeyType { kTriggerRightKeyType, kStartKeyType, kSelectKeyType, -// kModiferKeyType, + kModiferKeyType, /* ... */ kKeyTypeMax diff --git a/backends/platform/sdl/hardwarekeys.cpp b/backends/platform/sdl/hardwarekeys.cpp index 623e8b50cf..506e71d092 100644 --- a/backends/platform/sdl/hardwarekeys.cpp +++ b/backends/platform/sdl/hardwarekeys.cpp @@ -163,12 +163,12 @@ static const Key keys[] = { // Modifier keys pressed alone -// {"RSHIFT", KEYCODE_RSHIFT, 0, "Right Shift", kModiferKeyType, ~KBD_SHIFT}, -// {"LSHIFT", KEYCODE_LSHIFT, 0, "Left Shift", kModiferKeyType, ~KBD_SHIFT}, -// {"RCTRL", KEYCODE_RCTRL, 0, "Right Ctrl", kModiferKeyType, ~KBD_CTRL}, -// {"LCTRL", KEYCODE_LCTRL, 0, "Left Ctrl", kModiferKeyType, ~KBD_CTRL}, -// {"RALT", KEYCODE_RALT, 0, "Right Alt", kModiferKeyType, ~KBD_ALT}, -// {"LALT", KEYCODE_LALT, 0, "Left Alt", kModiferKeyType, ~KBD_ALT}, + {"RSHIFT", KEYCODE_RSHIFT, 0, "Right Shift", kModiferKeyType, ~KBD_SHIFT}, + {"LSHIFT", KEYCODE_LSHIFT, 0, "Left Shift", kModiferKeyType, ~KBD_SHIFT}, + {"RCTRL", KEYCODE_RCTRL, 0, "Right Ctrl", kModiferKeyType, ~KBD_CTRL}, + {"LCTRL", KEYCODE_LCTRL, 0, "Left Ctrl", kModiferKeyType, ~KBD_CTRL}, + {"RALT", KEYCODE_RALT, 0, "Right Alt", kModiferKeyType, ~KBD_ALT}, + {"LALT", KEYCODE_LALT, 0, "Left Alt", kModiferKeyType, ~KBD_ALT}, // Miscellaneous function keys -- cgit v1.2.3 From 7ff9bb3a6b543777891d90a645c669b975e64445 Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Sat, 15 Aug 2009 09:15:09 +0000 Subject: Commented a memory leak whose fix requires a fundamental modification to the Action structure (replacing KeyState with ActionKey should do it) svn-id: r43399 --- backends/keymapper/remap-dialog.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'backends') diff --git a/backends/keymapper/remap-dialog.cpp b/backends/keymapper/remap-dialog.cpp index aca2630d6d..323790a700 100644 --- a/backends/keymapper/remap-dialog.cpp +++ b/backends/keymapper/remap-dialog.cpp @@ -243,9 +243,12 @@ void RemapDialog::handleKeyUp(Common::KeyState state) { debug( "Key: %d, %d (%c), %x", state.keycode, state.ascii, (state.ascii ? state.ascii : ' '), state.flags); if (hwkey) { + //FIXME: this leaks memory and there's no good way to get this pointer again as + //a non-const. this should be done differently when we switch to actionKeys. HardwareKey *mappedkey = new HardwareKey(*hwkey); mappedkey->description = hwkey->description; mappedkey->key.flags = (state.flags & hwkey->modMask); + _activeRemapAction->mapKey(mappedkey); _activeRemapAction->getParent()->saveMappings(); _changes = true; -- cgit v1.2.3 From cbffcb609f752edcc3f086521c9e0c75b5ee4cc4 Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Sun, 16 Aug 2009 07:40:13 +0000 Subject: Replaced KeyStates with ActionKeys in the keymapper, removed SDL ASCII code mismatch workaround hacks, fixed the memory leaks I had previously created. svn-id: r43430 --- backends/keymapper/action.cpp | 17 ++++++++++++----- backends/keymapper/action.h | 4 ++-- backends/keymapper/hardware-key.h | 19 +++++++++++++++---- backends/keymapper/keymap.cpp | 12 +++++------- backends/keymapper/keymap.h | 6 +++--- backends/keymapper/keymapper.cpp | 22 +++++----------------- backends/keymapper/keymapper.h | 6 +++--- backends/keymapper/remap-dialog.cpp | 9 ++------- backends/platform/sdl/hardwarekeys.cpp | 2 +- 9 files changed, 48 insertions(+), 49 deletions(-) (limited to 'backends') diff --git a/backends/keymapper/action.cpp b/backends/keymapper/action.cpp index 3feb593f19..1f4efbf457 100644 --- a/backends/keymapper/action.cpp +++ b/backends/keymapper/action.cpp @@ -43,14 +43,21 @@ Action::Action(Keymap *boss, const char *i, String des, ActionType typ, _boss->addAction(this); } -void Action::mapKey(const HardwareKey *key) { +void Action::mapKey(const HardwareKey *key, byte flags) { if (_hwKey) + { _boss->unregisterMapping(this); + delete _hwKey; + } - _hwKey = key; - - if (_hwKey) - _boss->registerMapping(this, _hwKey); + if (key) { + _hwKey = new HardwareKey(*key); + if (flags) + _hwKey->key.flags = flags & _hwKey->modMask; + if (_hwKey) + _boss->registerMapping(this, _hwKey); + } else + _hwKey = NULL; } const HardwareKey *Action::getMappedKey() const { diff --git a/backends/keymapper/action.h b/backends/keymapper/action.h index 31576e2960..c49518b605 100644 --- a/backends/keymapper/action.h +++ b/backends/keymapper/action.h @@ -59,7 +59,7 @@ struct Action { private: /** Hardware key that is mapped to this Action */ - const HardwareKey *_hwKey; + HardwareKey *_hwKey; Keymap *_boss; public: @@ -105,7 +105,7 @@ public: return _boss; } - void mapKey(const HardwareKey *key); + void mapKey(const HardwareKey *key, byte flags = 0); const HardwareKey *getMappedKey() const; }; diff --git a/backends/keymapper/hardware-key.h b/backends/keymapper/hardware-key.h index 94e6589a17..70168def2d 100644 --- a/backends/keymapper/hardware-key.h +++ b/backends/keymapper/hardware-key.h @@ -49,6 +49,17 @@ struct ActionKey { KeyCode keycode; byte flags; + ActionKey () { + keycode = KEYCODE_INVALID; + flags = 0; + } + + ActionKey (const KeyState &key) { + keycode = key.keycode; + flags = key.flags; + } + + ActionKey (KeyCode ky, byte f) { keycode = ky; flags = f; @@ -75,7 +86,7 @@ struct HardwareKey { * The KeyState that is generated by the back-end * when this hardware key is pressed. */ - KeyState key; + ActionKey key; KeyType type; ActionType preferredAction; @@ -83,7 +94,7 @@ struct HardwareKey { // Mask of modifiers that can possibly apply to this key. byte modMask; - HardwareKey(const char *i, KeyState ky = KeyState(), String desc = "", byte mods = ~0, + HardwareKey(const char *i, ActionKey ky = ActionKey(), String desc = "", byte mods = ~0, KeyType typ = kGenericKeyType, ActionType prefAct = kGenericActionType) : key(ky), description(desc), type(typ), preferredAction(prefAct), modMask(mods) { assert(i); @@ -150,7 +161,7 @@ public: return 0; } - const HardwareKey *findHardwareKey(const KeyState& keystate) const { + const HardwareKey *findHardwareKey(const ActionKey& keystate) const { List::const_iterator it; for (it = _keys.begin(); it != _keys.end(); it++) { @@ -170,7 +181,7 @@ public: return 0; } - const HardwareMod *findHardwareMod(const KeyState& keystate) const { + const HardwareMod *findHardwareMod(const ActionKey& keystate) const { List::const_iterator it; for (it = _mods.begin(); it != _mods.end(); it++) { diff --git a/backends/keymapper/keymap.cpp b/backends/keymapper/keymap.cpp index fe6f133254..9d8b6046cd 100644 --- a/backends/keymapper/keymap.cpp +++ b/backends/keymapper/keymap.cpp @@ -60,7 +60,7 @@ void Keymap::addAction(Action *action) { } void Keymap::registerMapping(Action *action, const HardwareKey *hwKey) { - HashMap::iterator it; + HashMap::iterator it; it = _keymap.find(hwKey->key); @@ -105,8 +105,8 @@ const Action *Keymap::findAction(const char *id) const { return 0; } -Action *Keymap::getMappedAction(const KeyState& ks) const { - HashMap::iterator it; +Action *Keymap::getMappedAction(const ActionKey& ks) const { + HashMap::iterator it; it = _keymap.find(ks); @@ -157,9 +157,7 @@ void Keymap::loadMappings(const HardwareKeySet *hwKeys) { _configDomain->erase(key); continue; } - HardwareKey *mappedKey = new HardwareKey(*hwKey); - mappedKey->key.flags = modId; - ua->mapKey(mappedKey); + ua->mapKey(hwKey,modId); } } @@ -335,7 +333,7 @@ void Keymap::automaticMapping(HardwareKeySet *hwKeys) { } } -Action *Keymap::getParentMappedAction(KeyState key) { +Action *Keymap::getParentMappedAction(const ActionKey &key) { if (_parent) { Action *act = _parent->getMappedAction(key); diff --git a/backends/keymapper/keymap.h b/backends/keymapper/keymap.h index 5bb277c924..f4ad8d110d 100644 --- a/backends/keymapper/keymap.h +++ b/backends/keymapper/keymap.h @@ -89,7 +89,7 @@ public: * @param key the key that is mapped to the required Action * @return a pointer to the Action or 0 if no */ - Action *getMappedAction(const KeyState& ks) const; + Action *getMappedAction(const ActionKey& ks) const; void setConfigDomain(ConfigManager::Domain *dom); @@ -147,12 +147,12 @@ private: void internalMapKey(Action *action, HardwareKey *hwKey); - Action *getParentMappedAction(KeyState key); + Action *getParentMappedAction(const ActionKey &key); String _name; Keymap *_parent; List _actions; - HashMap _keymap; + HashMap _keymap; ConfigManager::Domain *_configDomain; }; diff --git a/backends/keymapper/keymapper.cpp b/backends/keymapper/keymapper.cpp index d101e8e0d2..704affb3fe 100644 --- a/backends/keymapper/keymapper.cpp +++ b/backends/keymapper/keymapper.cpp @@ -190,33 +190,21 @@ bool Keymapper::mapKey(const KeyState& key, bool keyDown) { return false; Action *action = 0; - if (keyDown) { - // HACK: Temporary fix for modifier recognition, get the hwkey's keystate - // to correct for keydown and keyup generating different ascii codes in SDL - // to be solved more permanently by using a structure other than KeyState - - const HardwareKey *hwkey = findHardwareKey(key); - if (!hwkey) - return false; - - KeyState k = hwkey->key; - k.flags = key.flags & hwkey->modMask; - // Search for key in active keymap stack for (int i = _activeMaps.size() - 1; i >= 0; --i) { MapRecord mr = _activeMaps[i]; - action = mr.keymap->getMappedAction(k); + action = mr.keymap->getMappedAction(key); if (action || mr.inherit == false) break; } if (action) - _keysDown[k] = action; + _keysDown[key] = action; } else { - HashMap::iterator it = _keysDown.find(key); + HashMap::iterator it = _keysDown.find(key); if (it != _keysDown.end()) { action = it->_value; @@ -279,11 +267,11 @@ void Keymapper::executeAction(const Action *action, bool keyDown) { } } -const HardwareKey *Keymapper::findHardwareKey(const KeyState& key) { +const HardwareKey *Keymapper::findHardwareKey(const ActionKey& key) { return (_hardwareKeys) ? _hardwareKeys->findHardwareKey(key) : 0; } -const HardwareMod *Keymapper::findHardwareMod(const KeyState& key) { +const HardwareMod *Keymapper::findHardwareMod(const ActionKey& key) { return (_hardwareKeys) ? _hardwareKeys->findHardwareMod(key) : 0; } diff --git a/backends/keymapper/keymapper.h b/backends/keymapper/keymapper.h index af3314f8f5..24c76fb09f 100644 --- a/backends/keymapper/keymapper.h +++ b/backends/keymapper/keymapper.h @@ -168,12 +168,12 @@ public: /** * Return a HardwareKey pointer for the given key state */ - const HardwareKey *findHardwareKey(const KeyState& key); + const HardwareKey *findHardwareKey(const ActionKey& key); /** * Return a HardwareMod pointer for the given key state */ - const HardwareMod *findHardwareMod(const KeyState& key); + const HardwareMod *findHardwareMod(const ActionKey& key); Domain& getGlobalDomain() { return _globalDomain; } Domain& getGameDomain() { return _gameDomain; } @@ -198,7 +198,7 @@ private: bool _enabled; Stack _activeMaps; - HashMap _keysDown; + HashMap _keysDown; }; diff --git a/backends/keymapper/remap-dialog.cpp b/backends/keymapper/remap-dialog.cpp index 323790a700..0a93785c08 100644 --- a/backends/keymapper/remap-dialog.cpp +++ b/backends/keymapper/remap-dialog.cpp @@ -243,14 +243,9 @@ void RemapDialog::handleKeyUp(Common::KeyState state) { debug( "Key: %d, %d (%c), %x", state.keycode, state.ascii, (state.ascii ? state.ascii : ' '), state.flags); if (hwkey) { - //FIXME: this leaks memory and there's no good way to get this pointer again as - //a non-const. this should be done differently when we switch to actionKeys. - HardwareKey *mappedkey = new HardwareKey(*hwkey); - mappedkey->description = hwkey->description; - mappedkey->key.flags = (state.flags & hwkey->modMask); - - _activeRemapAction->mapKey(mappedkey); + _activeRemapAction->mapKey(hwkey,state.flags); _activeRemapAction->getParent()->saveMappings(); + _changes = true; stopRemapping(); } diff --git a/backends/platform/sdl/hardwarekeys.cpp b/backends/platform/sdl/hardwarekeys.cpp index 506e71d092..af9b0ba319 100644 --- a/backends/platform/sdl/hardwarekeys.cpp +++ b/backends/platform/sdl/hardwarekeys.cpp @@ -227,7 +227,7 @@ Common::HardwareKeySet *OSystem_SDL::getHardwareKeySet() { snprintf(fullKeyId, 50, "%s", key->hwId); snprintf(fullKeyDesc, 100, "%s", key->desc); - keySet->addHardwareKey(new HardwareKey(fullKeyId, KeyState(key->keycode, ascii, 0), fullKeyDesc, key->modableMask, key->preferredAction)); + keySet->addHardwareKey(new HardwareKey(fullKeyId, ActionKey(key->keycode, 0), fullKeyDesc, key->modableMask, key->preferredAction)); } keySetInited = true; -- cgit v1.2.3 From dfaa5acbee5766e59b35697ea1b03122aa4ea2aa Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Tue, 18 Aug 2009 08:00:24 +0000 Subject: Starting to simplify the Action structure, and rework it to facilitate making the automatic mapper smarter, at least when there is a keyboard present. Fixed a minor whitespace issue in a comment. svn-id: r43502 --- backends/keymapper/action.cpp | 4 ++-- backends/keymapper/action.h | 4 +--- backends/keymapper/keymap.cpp | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) (limited to 'backends') diff --git a/backends/keymapper/action.cpp b/backends/keymapper/action.cpp index 1f4efbf457..4633f20df3 100644 --- a/backends/keymapper/action.cpp +++ b/backends/keymapper/action.cpp @@ -32,9 +32,9 @@ namespace Common { Action::Action(Keymap *boss, const char *i, String des, ActionType typ, - KeyType prefKey, int pri, int flg) + KeyType prefKey, int pri) : _boss(boss), description(des), type(typ), preferredKey(prefKey), - priority(pri), flags(flg), _hwKey(0) { + priority(pri), _hwKey(0) { assert(i); assert(_boss); diff --git a/backends/keymapper/action.h b/backends/keymapper/action.h index c49518b605..c78a526414 100644 --- a/backends/keymapper/action.h +++ b/backends/keymapper/action.h @@ -54,8 +54,6 @@ struct Action { ActionType type; KeyType preferredKey; int priority; - int group; - int flags; private: /** Hardware key that is mapped to this Action */ @@ -66,7 +64,7 @@ public: Action(Keymap *boss, const char *id, String des = "", ActionType typ = kGenericActionType, KeyType prefKey = kGenericKeyType, - int pri = 0, int flg = 0 ); + int pri = 0); void addEvent(const Event &evt) { events.push_back(evt); diff --git a/backends/keymapper/keymap.cpp b/backends/keymapper/keymap.cpp index 9d8b6046cd..f082640f2c 100644 --- a/backends/keymapper/keymap.cpp +++ b/backends/keymapper/keymap.cpp @@ -240,7 +240,7 @@ void Keymap::automaticMapping(HardwareKeySet *hwKeys) { // First mapping pass: // - Match if a key's preferred action type is the same as the action's - // type, or vice versa. + // type, or vice versa. // - Priority is given to: // - keys that match action types over key types. // - keys that have not been used by parent maps. -- cgit v1.2.3