From 6a5998c68421923512a3d43cb9a073c89ec7a9c6 Mon Sep 17 00:00:00 2001 From: stephena Date: Wed, 11 Aug 2010 21:53:19 +0000 Subject: [PATCH] Multiple events can now be assigned to combo events from the UI. Still TODO is update the documentation for this. Fixed bug reported by Buzbard from AtariAge concerning very large images in the RomInfoWidget being clipped too small. Reworked 'center window' functionality. Using the SDL_VIDEO_CENTERED environment variable was always a hack, and a bug was introduced in X11 OpenGL mode in version 1.2.14. However, since SDL is now in maintenance mode and won't be receiving any further updates, we have to bypass it entirely. Added infrastructure for OSystem to center the application window. For now, only Linux X11 mode is supported. Still TODO is add support for Windows. OSX was never supported anyway. This also means that the center window variable no longer requires the application to be restarted. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@2091 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- Changes.txt | 5 +++-- configure | 14 ++++++++++++++ src/common/PNGLibrary.cxx | 8 ++++---- src/common/mainSDL.cxx | 4 ---- src/emucore/EventHandler.cxx | 20 +++++++++++++++++--- src/emucore/FrameBuffer.cxx | 21 +++++++++++++++------ src/emucore/OSystem.hxx | 6 ++++++ src/gui/ComboDialog.cxx | 10 +++++++--- src/gui/VideoDialog.cxx | 2 +- src/unix/OSystemUNIX.cxx | 34 ++++++++++++++++++++++++++++++++++ src/unix/OSystemUNIX.hxx | 3 +++ 11 files changed, 104 insertions(+), 23 deletions(-) diff --git a/Changes.txt b/Changes.txt index 1e9b5ea00..38ff9b5f1 100644 --- a/Changes.txt +++ b/Changes.txt @@ -39,8 +39,9 @@ FIXME (previously, the app had to be restarted), and a vertical line separates the disassembly from the raw bytes. - * Fixed behaviour of SWCHB and SWBCNT; the three unused bits can now be - configured as input or output. Some ROMs use this for extra storage. + * Fixed behaviour of SWCHB and SWBCNT; pins set to output now remember + the values previously written. Some ROMs use this functionality for + extra storage. * Added 'finishing touches' to some of the UI descriptions, giving a better explanation of the functions. Related to this, certain diff --git a/configure b/configure index 512bbd7cc..59f0ec953 100755 --- a/configure +++ b/configure @@ -686,6 +686,20 @@ case $_host_os in DEFINES="$DEFINES -DBSPF_UNIX -DHAVE_GETTIMEOFDAY -DHAVE_INTTYPES" MODULES="$MODULES $SRC/unix" INCLUDES="$INCLUDES -I$SRC/unix" + + # + # Check for X11 + # + _x11=no + cat > $TMPC << EOF + #include + int main(void) { return 0; } +EOF + cc_check $LDFLAGS $CXXFLAGS -lX11 && _x11=yes + if test "$_x11" = yes ; then + DEFINES="$DEFINES -DHAVE_X11" + LIBS="$LIBS -lX11" + fi ;; win32) DEFINES="$DEFINES -DBSPF_WIN32 -DHAVE_GETTIMEOFDAY -DHAVE_INTTYPES" diff --git a/src/common/PNGLibrary.cxx b/src/common/PNGLibrary.cxx index e2ad8b6ef..6015e89a0 100644 --- a/src/common/PNGLibrary.cxx +++ b/src/common/PNGLibrary.cxx @@ -145,7 +145,6 @@ void PNGLibrary::scaleImagetoSurface(uInt32 iwidth, uInt32 iheight, uInt8* buffe uInt32 izoom = uInt32(ceil(iwidth/320.0)), szoom = surface.getWidth()/320; - // Set the surface size uInt32 sw = iwidth / izoom * szoom, sh = iheight / izoom * szoom; sw = BSPF_min(sw, surface.getWidth()); @@ -159,9 +158,10 @@ void PNGLibrary::scaleImagetoSurface(uInt32 iwidth, uInt32 iheight, uInt8* buffe uInt32 buf_offset = ipitch * izoom; uInt32 i_offset = 3 * izoom; - - // We can only scan at most the height of the surface - iheight = BSPF_min(iheight, surface.getHeight()); + + // We can only scan at most the height of the image to the constraints of + // the surface height (some multiple of 256) + iheight = BSPF_min(iheight, izoom * 256); // Grab each non-duplicate row of data from the image for(uInt32 irow = 0, srow = 0; irow < iheight; irow += izoom, buffer += buf_offset) diff --git a/src/common/mainSDL.cxx b/src/common/mainSDL.cxx index d69ff1cd6..d9b30fe50 100644 --- a/src/common/mainSDL.cxx +++ b/src/common/mainSDL.cxx @@ -149,10 +149,6 @@ int main(int argc, char* argv[]) return Cleanup(); } - // Request that the SDL window be centered, if possible - if(theOSystem->settings().getBool("center")) - putenv((char*)"SDL_VIDEO_CENTERED=1"); - #ifdef BSPF_UNIX // Nvidia cards under UNIX don't currently support SDL_GL_SWAP_CONTROL // So we need to do it with an Nvidia-specific environment variable diff --git a/src/emucore/EventHandler.cxx b/src/emucore/EventHandler.cxx index 14a84f719..3be2e3dcd 100644 --- a/src/emucore/EventHandler.cxx +++ b/src/emucore/EventHandler.cxx @@ -1867,7 +1867,7 @@ StringMap EventHandler::getComboList(EventMode) const StringMap l; ostringstream buf; - l.push_back("None", "0"); + l.push_back("None", "-1"); for(uInt32 i = 0; i < kEmulActionListSize; ++i) if(EventHandler::ourEmulActionList[i].allow_combo) { @@ -1900,9 +1900,9 @@ StringList EventHandler::getComboListForEvent(Event::Type event) const buf.str(""); } } - // Make sure entries are 1-to-1, using Event::NoType when necessary + // Make sure entries are 1-to-1, using '-1' to indicate Event::NoType if(i == l.size()) - l.push_back("0"); + l.push_back("-1"); } } return l; @@ -1911,6 +1911,20 @@ StringList EventHandler::getComboListForEvent(Event::Type event) const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void EventHandler::setComboListForEvent(Event::Type event, const StringList& events) { + if(event >= Event::Combo1 && event <= Event::Combo16) + { + assert(events.size() == 8); + int combo = event - Event::Combo1; + for(int i = 0; i < 8; ++i) + { + int idx = atoi(events[i].c_str()); + if(idx >=0 && idx < kEmulActionListSize) + myComboTable[combo][i] = EventHandler::ourEmulActionList[idx].event; + else + myComboTable[combo][i] = Event::NoType; + } + saveComboMapping(); + } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/FrameBuffer.cxx b/src/emucore/FrameBuffer.cxx index 2b7a86459..df71426dc 100644 --- a/src/emucore/FrameBuffer.cxx +++ b/src/emucore/FrameBuffer.cxx @@ -127,13 +127,17 @@ FBInitStatus FrameBuffer::initialize(const string& title, uInt32 width, uInt32 h setWindowTitle(title); if(myInitializedCount == 1) setWindowIcon(); - if(!initSubsystem(mode)) - { - myOSystem->logMessage("ERROR: Couldn't initialize video subsystem\n", 0); - return kFailNotSupported; - } - else + if(initSubsystem(mode)) { + // Attempt to center the application window in non-fullscreen mode + if(!fullScreen() && myOSystem->settings().getBool("center")) + { + myOSystem->setAppWindowPos( + (myOSystem->desktopWidth() - mode.screen_w) / 2, + (myOSystem->desktopHeight() - mode.screen_h) / 2, + mode.screen_w, mode.screen_h); + } + myImageRect.setWidth(mode.image_w); myImageRect.setHeight(mode.image_h); myImageRect.moveTo(mode.image_x, mode.image_y); @@ -147,6 +151,11 @@ FBInitStatus FrameBuffer::initialize(const string& title, uInt32 width, uInt32 h myOSystem->settings().setString("fullscreen", fullScreen() ? "1" : "0"); setCursorState(); } + else + { + myOSystem->logMessage("ERROR: Couldn't initialize video subsystem\n", 0); + return kFailNotSupported; + } } else return kFailTooLarge; diff --git a/src/emucore/OSystem.hxx b/src/emucore/OSystem.hxx index 40ca3bb45..bb6bece4d 100644 --- a/src/emucore/OSystem.hxx +++ b/src/emucore/OSystem.hxx @@ -444,6 +444,12 @@ class OSystem */ virtual void stateChanged(EventHandler::State state); + /** + Set the position of the application window, generally using + platform-specific code. + */ + virtual void setAppWindowPos(int x, int y, int w, int h) { }; + protected: /** Query the OSystem video hardware for resolution information. diff --git a/src/gui/ComboDialog.cxx b/src/gui/ComboDialog.cxx index eb7ad065b..00eab71dd 100644 --- a/src/gui/ComboDialog.cxx +++ b/src/gui/ComboDialog.cxx @@ -120,20 +120,24 @@ void ComboDialog::loadConfig() // Fill any remaining items to 'None' if(size < 8) for(int i = size; i < 8; ++i) - myEvents[i]->setSelected("None", "0"); + myEvents[i]->setSelected("None", "-1"); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void ComboDialog::saveConfig() { - Settings& settings = instance().settings(); + StringList events; + for(int i = 0; i < 8; ++i) + events.push_back(myEvents[i]->getSelectedTag()); + + instance().eventHandler().setComboListForEvent(myComboEvent, events); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void ComboDialog::setDefaults() { for(int i = 0; i < 8; ++i) - myEvents[i]->setSelected("None", "0"); + myEvents[i]->setSelected("None", "-1"); _dirty = true; } diff --git a/src/gui/VideoDialog.cxx b/src/gui/VideoDialog.cxx index 9deb69119..d96af9886 100644 --- a/src/gui/VideoDialog.cxx +++ b/src/gui/VideoDialog.cxx @@ -225,7 +225,7 @@ VideoDialog::VideoDialog(OSystem* osystem, DialogContainer* parent, // Center window (in windowed mode) myCenterCheckbox = new CheckboxWidget(myTab, font, xpos, ypos, - "Center window (*)"); + "Center window"); wid.push_back(myCenterCheckbox); ypos += lineHeight + 4; diff --git a/src/unix/OSystemUNIX.cxx b/src/unix/OSystemUNIX.cxx index 3e49b0c61..f35237fff 100644 --- a/src/unix/OSystemUNIX.cxx +++ b/src/unix/OSystemUNIX.cxx @@ -17,6 +17,11 @@ // $Id$ //============================================================================ +#if defined(HAVE_X11) + #include + #include +#endif + #include "bspf.hxx" #include "OSystem.hxx" #include "OSystemUNIX.hxx" @@ -43,3 +48,32 @@ OSystemUNIX::OSystemUNIX() OSystemUNIX::~OSystemUNIX() { } + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void OSystemUNIX::setAppWindowPos(int x, int y, int, int) +{ +#if defined(HAVE_X11) + SDL_SysWMinfo sdl_info; + memset(&sdl_info, 0, sizeof(sdl_info)); + + SDL_VERSION (&sdl_info.version); + if(SDL_GetWMInfo(&sdl_info) > 0 && sdl_info.subsystem == SDL_SYSWM_X11) + { + XSizeHints* hints = XAllocSizeHints(); + if(hints) + { + Display* display = sdl_info.info.x11.display; + Window window = sdl_info.info.x11.wmwindow; + hints->flags |= USPosition; + hints->x = x; + hints->y = y; + XMoveWindow(display, window, hints->x, hints->y); + + /* Flush the resize event so we don't catch it later */ + XSync(display, True); + XSetWMNormalHints(display, window, hints); + XFree(hints); + } + } +#endif +} diff --git a/src/unix/OSystemUNIX.hxx b/src/unix/OSystemUNIX.hxx index dd70bc5c4..4d1178839 100644 --- a/src/unix/OSystemUNIX.hxx +++ b/src/unix/OSystemUNIX.hxx @@ -40,6 +40,9 @@ class OSystemUNIX : public OSystem Destructor */ virtual ~OSystemUNIX(); + + /** Move X11 window to given position. */ + void setAppWindowPos(int x, int y, /* not used*/ int, int); }; #endif