From b29b07fadc61ce36b340208ae1d0dc817468ba66 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 15 Mar 2004 19:07:56 +0000 Subject: Allow multi-line OSD messages; display virtual/real screen resolutions when chaning the scaler or the aspect ratio correction svn-id: r13309 --- backends/sdl/graphics.cpp | 44 ++++++++++++++++++++++++++++++++++++++------ backends/sdl/sdl.cpp | 12 ++++++++++-- 2 files changed, 48 insertions(+), 8 deletions(-) (limited to 'backends') diff --git a/backends/sdl/graphics.cpp b/backends/sdl/graphics.cpp index 09040f5c63..8a2ff446f5 100644 --- a/backends/sdl/graphics.cpp +++ b/backends/sdl/graphics.cpp @@ -134,7 +134,11 @@ bool OSystem_SDL::setGraphicsMode(int mode) { } if (newScalerName) { char buffer[128]; - sprintf(buffer, "Active graphics filter: %s", newScalerName); + sprintf(buffer, "Active graphics filter: %s\n%d x %d -> %d x %d", + newScalerName, + _screenWidth, _screenHeight, + _hwscreen->w, _hwscreen->h + ); displayMessageOnOSD(buffer); } } @@ -1170,7 +1174,9 @@ void OSystem_SDL::undraw_mouse() { #ifdef USE_OSD void OSystem_SDL::displayMessageOnOSD(const char *msg) { -// printf("displayMessageOnOSD(%s)\n", msg); + uint i; + + // Lock the OSD surface for drawing if (SDL_LockSurface(_osdSurface)) error("displayMessageOnOSD: SDL_LockSurface failed: %s", SDL_GetError()); @@ -1181,14 +1187,36 @@ void OSystem_SDL::displayMessageOnOSD(const char *msg) { dst.pitch = _osdSurface->pitch; dst.bytesPerPixel = _osdSurface->format->BytesPerPixel; + // The font we are going to use: +// const GUI::Font *font = &GUI::g_sysfont; + const GUI::Font *font = &GUI::g_scummfont; + // Clear everything with the "transparent" color, i.e. the colorkey SDL_FillRect(_osdSurface, 0, kOSDColorKey); + + // Split the message into separate lines. + Common::StringList lines; + const char *ptr; + for (ptr = msg; *ptr; ++ptr) { + if (*ptr == '\n') { + lines.push_back(Common::String(msg, ptr - msg)); + msg = ptr + 1; + } + } + lines.push_back(Common::String(msg, ptr - msg)); // Determine a rect which would contain the message string (clipped to the // screen dimensions). - const int vOffset = 10; - int width = GUI::g_sysfont.getStringWidth(msg) + 16; - int height = GUI::g_sysfont.getFontHeight() + 2 * vOffset; + const int vOffset = 6; + const int lineSpacing = 1; + const int lineHeight = font->getFontHeight() + 2 * lineSpacing; + int width = 0; + int height = lineHeight * lines.size() + 2 * vOffset; + for (i = 0; i < lines.size(); i++) { + width = MAX(width, font->getStringWidth(lines[i]) + 14); + } + + // Clip the rect if (width > dst.w) width = dst.w; if (height > dst.h) @@ -1204,10 +1232,14 @@ void OSystem_SDL::displayMessageOnOSD(const char *msg) { SDL_FillRect(_osdSurface, &osdRect, SDL_MapRGB(_osdSurface->format, 64, 64, 64)); // Render the message, centered, and in white - GUI::g_sysfont.drawString(&dst, msg, osdRect.x, osdRect.y + vOffset, osdRect.w, + for (i = 0; i < lines.size(); i++) { + font->drawString(&dst, lines[i], + osdRect.x, osdRect.y + i * lineHeight + vOffset + lineSpacing, osdRect.w, SDL_MapRGB(_osdSurface->format, 255, 255, 255), GUI::kTextAlignCenter); + } + // Finished drawing, so unlock the OSD surface again SDL_UnlockSurface(_osdSurface); // Init the OSD display parameters, and the fade out diff --git a/backends/sdl/sdl.cpp b/backends/sdl/sdl.cpp index 783238f802..fb798caacb 100644 --- a/backends/sdl/sdl.cpp +++ b/backends/sdl/sdl.cpp @@ -151,10 +151,18 @@ void OSystem_SDL::setFeatureState(Feature f, bool enable) { hotswap_gfx_mode(); #ifdef USE_OSD + char buffer[128]; if (_adjustAspectRatio) - displayMessageOnOSD("Enabled aspect ratio correction"); + sprintf(buffer, "Enabled aspect ratio correction\n%d x %d -> %d x %d", + _screenWidth, _screenHeight, + _hwscreen->w, _hwscreen->h + ); else - displayMessageOnOSD("Disabled aspect ratio correction"); + sprintf(buffer, "Disabled aspect ratio correction\n%d x %d -> %d x %d", + _screenWidth, _screenHeight, + _hwscreen->w, _hwscreen->h + ); + displayMessageOnOSD(buffer); #endif // Blit everything to the screen -- cgit v1.2.3