diff options
author | Yotam Barnoy | 2010-10-14 13:19:32 +0000 |
---|---|---|
committer | Yotam Barnoy | 2010-10-14 13:19:32 +0000 |
commit | 7c2254589937d9f35d4779c270c9ef6f426e4b73 (patch) | |
tree | 5dfeebbdce92997b7d9dddd036e378ed476ae59b /backends/platform | |
parent | 90e12a43fd8e0f6e94f59a52b6794e01200adcc7 (diff) | |
download | scummvm-rg350-7c2254589937d9f35d4779c270c9ef6f426e4b73.tar.gz scummvm-rg350-7c2254589937d9f35d4779c270c9ef6f426e4b73.tar.bz2 scummvm-rg350-7c2254589937d9f35d4779c270c9ef6f426e4b73.zip |
PSP: added image viewer for viewing images during games
svn-id: r53455
Diffstat (limited to 'backends/platform')
-rw-r--r-- | backends/platform/psp/Makefile | 1 | ||||
-rw-r--r-- | backends/platform/psp/README.PSP | 35 | ||||
-rw-r--r-- | backends/platform/psp/display_manager.cpp | 26 | ||||
-rw-r--r-- | backends/platform/psp/display_manager.h | 9 | ||||
-rw-r--r-- | backends/platform/psp/image_viewer.cpp | 280 | ||||
-rw-r--r-- | backends/platform/psp/image_viewer.h | 92 | ||||
-rw-r--r-- | backends/platform/psp/input.cpp | 66 | ||||
-rw-r--r-- | backends/platform/psp/input.h | 49 | ||||
-rw-r--r-- | backends/platform/psp/module.mk | 1 | ||||
-rw-r--r-- | backends/platform/psp/osys_psp.cpp | 5 | ||||
-rw-r--r-- | backends/platform/psp/osys_psp.h | 3 |
11 files changed, 537 insertions, 30 deletions
diff --git a/backends/platform/psp/Makefile b/backends/platform/psp/Makefile index 7f9ae153eb..8ddf58ad88 100644 --- a/backends/platform/psp/Makefile +++ b/backends/platform/psp/Makefile @@ -149,6 +149,7 @@ OBJS := powerman.o \ rtc.o \ mp3.o \ png_loader.o \ + image_viewer.o \ tests.o BACKEND := psp diff --git a/backends/platform/psp/README.PSP b/backends/platform/psp/README.PSP index 0849d68c78..b83f1cab6d 100644 --- a/backends/platform/psp/README.PSP +++ b/backends/platform/psp/README.PSP @@ -6,6 +6,7 @@ Installation - Copy the relevant game datafiles to your memory stick (location doesn't matter). - Install ScummVM like any other homebrew. - Run ScummVM and use the launcher to add games and run them. + - Press Start to return to the launcher and play another game. Controls ======== @@ -20,9 +21,10 @@ Cross - Left Mouse Button (usually the main button) Circle - Right Mouse Button (secondary button in some games) Square - '.' (skip dialogue in some games e.g. Scumm) Right trigger + Square - Spacebar (useful in Gobli*ns and SCI games) -Start - Global Menu. Allows you to 'Return To Launcher' to play another game Right trigger + Start - F5 (Main Menu in some games) Select - Show/Hide Virtual Keyboard. Hold down to move keyboard onscreen (with D-Pad). +Right trigger + Select - Show Image Viewer (see below) +Start - Global Menu. Allows you to 'Return To Launcher' to play another game Virtual Keyboard Mode ===================== @@ -37,6 +39,34 @@ Buttons/Triggers - Choose a specific character in the square. The four center c Analog - Moves in a direction (left/right/up/down) (Useful to keep moving while typing in AGI games among other things) + +Image Viewer +============ +For your convenience, I've included a simple image viewer in the PSP port. +You can view anything you want while playing a game. +There are a few simple rules to follow: + +- Images must be of PNG format. If you have images in another format, many + graphics utilities will convert them for you. +- Images must be named psp_image1.png, psp_image2.png etc. This is to make + sure there's no possible conflict between image files and game files. +- Images must be placed in the game directories. When using the image viewer, + only the images of the particular game being played will be available for viewing. +- Don't place any images in the ScummVM directory, or you won't be able to see + the images in the game directories. +- There's no guarantee that you'll be able to view your image. This is because + big images take a lot of memory (more than the size of the image on disk). If there + isn't enough memory left to show the image, ScummVM will tell you so. Try to make the + image smaller by either shrinking it or reducing the colors to 256 color palette mode. + +Image Viewer Controls: +===================== +Left/Right - previous/next image (e.g. go from psp_image1.png to psp_image2.png) +Up/down - zoom in/out +Analog - move around the image +Triggers, Start: - exit image viewer + + 1st Person Game Mode (Can be ignored by most users) ==================== This is a special mode built for 1st person games like Lands of Lore. If you don't have these games you can @@ -49,9 +79,12 @@ Square - Is the modifier key instead of Right Trigger. Left/Right Trigger - Strafe left/right D-Pad Left/Right - Turn left/right Square + D-Pad - F1/F2/F3/F4 +Square + Select - Image Viewer Square + Start - Esc (shows game menu) + + Notes ===== - Notice that you can switch between games! This is much faster than quitting diff --git a/backends/platform/psp/display_manager.cpp b/backends/platform/psp/display_manager.cpp index 5d75ac531e..2c94882a63 100644 --- a/backends/platform/psp/display_manager.cpp +++ b/backends/platform/psp/display_manager.cpp @@ -34,6 +34,7 @@ #include "backends/platform/psp/default_display_client.h" #include "backends/platform/psp/cursor.h" #include "backends/platform/psp/pspkeyboard.h" +#include "backends/platform/psp/image_viewer.h" #define USE_DISPLAY_CALLBACK // to use callback for finishing the render #include "backends/platform/psp/display_manager.h" @@ -385,10 +386,12 @@ bool DisplayManager::renderAll() { #endif /* USE_DISPLAY_CALLBACK */ // This is cheaper than checking time, so we do it first + // Any one of these being dirty causes everything to draw if (!_screen->isDirty() && - (!_overlay->isDirty()) && - (!_cursor->isDirty()) && - (!_keyboard->isDirty())) { + !_overlay->isDirty() && + !_cursor->isDirty() && + !_keyboard->isDirty() && + !_imageViewer->isDirty()) { PSP_DEBUG_PRINT("Nothing dirty\n"); return true; // nothing to render } @@ -396,34 +399,35 @@ bool DisplayManager::renderAll() { if (!isTimeToUpdate()) return false; // didn't render - PSP_DEBUG_PRINT("screen[%s], overlay[%s], cursor[%s], keyboard[%s]\n", + PSP_DEBUG_PRINT("dirty: screen[%s], overlay[%s], cursor[%s], keyboard[%s], imageViewer[%s]\n", _screen->isDirty() ? "true" : "false", _overlay->isDirty() ? "true" : "false", _cursor->isDirty() ? "true" : "false", - _keyboard->isDirty() ? "true" : "false" + _keyboard->isDirty() ? "true" : "false", + _imageViewer->isDirty() ? "true" : "false", ); _masterGuRenderer.guPreRender(); // Set up rendering _screen->render(); - _screen->setClean(); // clean out dirty bit + + if (_imageViewer->isVisible()) + _imageViewer->render(); + _imageViewer->setClean(); if (_overlay->isVisible()) - _overlay->render(); - + _overlay->render(); _overlay->setClean(); if (_cursor->isVisible()) _cursor->render(); - _cursor->setClean(); if (_keyboard->isVisible()) _keyboard->render(); - _keyboard->setClean(); - + _masterGuRenderer.guPostRender(); return true; // rendered successfully diff --git a/backends/platform/psp/display_manager.h b/backends/platform/psp/display_manager.h index 00d3851243..4537af0096 100644 --- a/backends/platform/psp/display_manager.h +++ b/backends/platform/psp/display_manager.h @@ -96,6 +96,7 @@ class Screen; class Overlay; class Cursor; class PSPKeyboard; +class ImageViewer; /** * Class that manages all display clients @@ -107,7 +108,8 @@ public: KEEP_ASPECT_RATIO, STRETCHED_FULL_SCREEN }; - DisplayManager() : _screen(0), _cursor(0), _overlay(0), _keyboard(0), _lastUpdateTime(0), _graphicsMode(0) {} + DisplayManager() : _screen(0), _cursor(0), _overlay(0), _keyboard(0), + _imageViewer(0), _lastUpdateTime(0), _graphicsMode(0) {} ~DisplayManager(); void init(); @@ -118,11 +120,13 @@ public: uint32 getDefaultGraphicsMode() const { return STRETCHED_FULL_SCREEN; } const OSystem::GraphicsMode* getSupportedGraphicsModes() const { return _supportedModes; } - // Setters + // Setters for pointers void setScreen(Screen *screen) { _screen = screen; } void setCursor(Cursor *cursor) { _cursor = cursor; } void setOverlay(Overlay *overlay) { _overlay = overlay; } void setKeyboard(PSPKeyboard *keyboard) { _keyboard = keyboard; } + void setImageViewer(ImageViewer *imageViewer) { _imageViewer = imageViewer; } + void setSizeAndPixelFormat(uint width, uint height, const Graphics::PixelFormat *format); // Getters @@ -148,6 +152,7 @@ private: Cursor *_cursor; Overlay *_overlay; PSPKeyboard *_keyboard; + ImageViewer *_imageViewer; MasterGuRenderer _masterGuRenderer; uint32 _lastUpdateTime; // For limiting FPS diff --git a/backends/platform/psp/image_viewer.cpp b/backends/platform/psp/image_viewer.cpp new file mode 100644 index 0000000000..66a5412034 --- /dev/null +++ b/backends/platform/psp/image_viewer.cpp @@ -0,0 +1,280 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/backends/platform/psp/osys_psp.cpp $ + * $Id: osys_psp.cpp 46126 2009-11-24 14:18:46Z fingolfin $ + * + */ + +#include "common/scummsys.h" +#include "common/str.h" +#include "common/stream.h" +#include "common/archive.h" +#include "common/ptr.h" +#include "gui/message.h" +#include "engines/engine.h" +#include "backends/platform/psp/input.h" +#include "backends/platform/psp/display_client.h" +#include "backends/platform/psp/image_viewer.h" +#include "backends/platform/psp/png_loader.h" + +static const char *imageName = "psp_image"; +#define PSP_SCREEN_HEIGHT 272 +#define PSP_SCREEN_WIDTH 480 + +bool ImageViewer::load(int imageNum) { + if (_init) + unload(); + + // build string + char number[8]; + sprintf(number, "%d", imageNum); + Common::String imageNameStr(imageName); + Common::String specificImageName = imageNameStr + Common::String(number) + Common::String(".png"); + + // search for image file + if (!SearchMan.hasFile(specificImageName)) { + PSP_ERROR("file %s not found\n", specificImageName.c_str()); + return false; + } + + Common::ScopedPtr<Common::SeekableReadStream> file(SearchMan.createReadStreamForMember(specificImageName)); + + _buffer = new Buffer(); + _palette = new Palette(); + _renderer = new GuRenderer(); + + assert(_buffer); + assert(_palette); + assert(_renderer); + + // Load a PNG into our buffer and palette. Size it by the actual size of the image + PngLoader image(file, *_buffer, *_palette, Buffer::kSizeBySourceSize); + + PngLoader::Status status = image.allocate(); // allocate the buffers for the file + + char error[100]; + if (status == PngLoader::BAD_FILE) { + sprintf(error, "Cannot display %s. Not a proper PNG file", specificImageName.c_str()); + GUI::TimedMessageDialog dialog(error, 4000); + dialog.runModal(); + } else if (status == PngLoader::OUT_OF_MEMORY) { + sprintf(error, "Out of memory loading %s. Try making the image smaller", specificImageName.c_str()); + GUI::TimedMessageDialog dialog(error, 4000); + dialog.runModal(); + } + // try to load the image file + if (!image.load()) { + sprintf(error, "Cannot display %s. Not a proper PNG file", specificImageName.c_str()); + GUI::TimedMessageDialog dialog(error, 4000); + dialog.runModal(); + } + + setConstantRendererOptions(); + setFullScreenImageParams(); // prepare renderer for full screen view + + _imageNum = imageNum; // now we can say we displayed this image + _init = true; + + return true; +} + +void ImageViewer::setConstantRendererOptions() { + _renderer->setBuffer(_buffer); + _renderer->setPalette(_palette); + + _renderer->setAlphaBlending(false); + _renderer->setColorTest(false); + _renderer->setUseGlobalScaler(false); + _renderer->setStretch(true); + _renderer->setOffsetInBuffer(0, 0); + _renderer->setDrawWholeBuffer(); +} + +void ImageViewer::unload() { + delete _buffer; + delete _palette; + delete _renderer; + _buffer = 0; + _palette = 0; + _renderer = 0; + _init = false; +} + +void ImageViewer::setVisible(bool visible) { + DEBUG_ENTER_FUNC(); + if (_visible == visible) + return; + + if (!g_engine) // we can only run the image viewer when there's an engine + return; // otherwise we won't know where to open the image + + // from here on, we're making the loader visible + if (visible && load(_imageNum ? _imageNum : 1)) { // load the 1st image or the current + g_engine->pauseEngine(true); + _visible = true; + setDirty(); + setViewerButtons(true); + + GUI::TimedMessageDialog dialog("Image Viewer", 1000); + dialog.runModal(); + } else { // all other cases + _visible = false; + setDirty(); + unload(); + setViewerButtons(false); + + if (g_engine->isPaused()) + g_engine->pauseEngine(false); + } +} + +void ImageViewer::setViewerButtons(bool active) { + _inputHandler->setImageViewerMode(active); +} + +void ImageViewer::loadNextImage() { + if (!load(_imageNum+1)) { // try to load the next image + if (!load(_imageNum)) // we failed, so reload the current image + setVisible(false); // just hide + } +} + +void ImageViewer::loadLastImage() { + if (_imageNum - 1 > 0) { + if (!load(_imageNum-1)) + if (!load(_imageNum)) + setVisible(false); // we can't even show the old image so hide + } +} + +void ImageViewer::setFullScreenImageParams() { + // we try to fit the image fullscreen at least in one dimension + uint32 width = _buffer->getSourceWidth(); + uint32 height = _buffer->getSourceHeight(); + + _centerX = PSP_SCREEN_WIDTH / 2.0f; + _centerY = PSP_SCREEN_HEIGHT / 2.0f; + + // see if we fit width wise + if (PSP_SCREEN_HEIGHT >= (int)((height * PSP_SCREEN_WIDTH) / (float)width)) { + setZoom(PSP_SCREEN_WIDTH / (float)width); + } else { + setZoom(PSP_SCREEN_HEIGHT / (float)height); + } +} + +void ImageViewer::render() { + assert(_buffer); + assert(_renderer); + + _renderer->render(); +} + +void ImageViewer::modifyZoom(bool up) { + float factor = _zoomFactor; + if (up) + factor += 0.1f; + else // down + factor -= 0.1f; + + setZoom(factor); +} + +void ImageViewer::setZoom(float value) { + if (value <= 0.0f) // don't want 0 or negative zoom + return; + + _zoomFactor = value; + _renderer->setStretchXY(value, value); + setOffsetParams(); +} + +void ImageViewer::moveImageX(int val) { + float newVal = _centerX + val; + + if (newVal < 0 || newVal > PSP_SCREEN_WIDTH) + return; + _centerX = newVal; + setOffsetParams(); +} + +void ImageViewer::moveImageY(int val) { + float newVal = _centerY + val; + + if (newVal < 0 || newVal > PSP_SCREEN_HEIGHT) + return; + _centerY = newVal; + setOffsetParams(); +} + +// Set the renderer with the proper offset on the screen +// +void ImageViewer::setOffsetParams() { + _visibleWidth = _zoomFactor * _buffer->getSourceWidth(); + _visibleHeight = _zoomFactor * _buffer->getSourceHeight(); + + int offsetX = _centerX - (int)(_visibleWidth * 0.5f); + int offsetY = _centerY - (int)(_visibleHeight * 0.5f); + + _renderer->setOffsetOnScreen(offsetX, offsetY); +} + +// Handler events coming in from the inputHandler +// +void ImageViewer::handleEvent(uint32 event) { + DEBUG_ENTER_FUNC(); + + switch (event) { + case EVENT_HIDE: + setVisible(false); + break; + case EVENT_SHOW: + setVisible(true); + break; + case EVENT_ZOOM_IN: + modifyZoom(true); + break; + case EVENT_ZOOM_OUT: + modifyZoom(false); + break; + case EVENT_MOVE_LEFT: + moveImageX(-5); + break; + case EVENT_MOVE_UP: + moveImageY(-5); + break; + case EVENT_MOVE_RIGHT: + moveImageX(5); + break; + case EVENT_MOVE_DOWN: + moveImageY(5); + break; + case EVENT_NEXT_IMAGE: + loadNextImage(); + break; + case EVENT_LAST_IMAGE: + loadLastImage(); + break; + default: + PSP_ERROR("Unknown event %d\n", event); + break; + } +}
\ No newline at end of file diff --git a/backends/platform/psp/image_viewer.h b/backends/platform/psp/image_viewer.h new file mode 100644 index 0000000000..3e2630a97e --- /dev/null +++ b/backends/platform/psp/image_viewer.h @@ -0,0 +1,92 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/backends/platform/psp/osys_psp.cpp $ + * $Id: osys_psp.cpp 46126 2009-11-24 14:18:46Z fingolfin $ + * + */ + +#ifndef PSP_IMAGE_VIEWER_H +#define PSP_IMAGE_VIEWER_H + +class InputHandler; + +class ImageViewer : public DisplayClient { +private: + Buffer *_buffer; + Palette *_palette; + GuRenderer *_renderer; + bool _visible; + bool _dirty; + bool _init; + uint32 _imageNum; // current image number + float _zoomFactor; // how much we're zooming in/out on the image + float _visibleHeight, _visibleWidth; + float _centerX, _centerY; + + InputHandler *_inputHandler; + + void setFullScreenImageParams(); + void loadNextImage(); + void loadLastImage(); + void setViewerButtons(bool active); + void setConstantRendererOptions(); + void moveImageX(int val); + void moveImageY(int val); + bool load(int imageNum); + void unload(); + + void setZoom(float value); + void setOffsetParams(); + void modifyZoom(bool up); // up or down + void setVisible(bool visible); + +public: + enum Events { + EVENT_HIDE = 0, + EVENT_SHOW = 1, + EVENT_ZOOM_IN, + EVENT_ZOOM_OUT, + EVENT_MOVE_LEFT, + EVENT_MOVE_UP, + EVENT_MOVE_RIGHT, + EVENT_MOVE_DOWN, + EVENT_NEXT_IMAGE, + EVENT_LAST_IMAGE, + }; + + ImageViewer() : _buffer(0), _palette(0), _visible(false), _dirty(false), _init(false), _imageNum(0), + _zoomFactor(0.0f), _visibleHeight(0.0f), _visibleWidth(0.0f), + _centerX(0.0f), _centerY(0.0f) {} + ~ImageViewer() { unload(); } // deallocate images + bool load(); + void render(); + bool isVisible() { return _visible; } + bool isDirty() { return _dirty; } + void setDirty() { _dirty = true; } + void setClean() { _dirty = false; } + + void handleEvent(uint32 event); + + // pointer setters + void setInputHandler(InputHandler *inputHandler) { _inputHandler = inputHandler; } +}; + +#endif /* PSP_IMAGE_VIEWER_H */
\ No newline at end of file diff --git a/backends/platform/psp/input.cpp b/backends/platform/psp/input.cpp index ed868ef375..ba599cdac2 100644 --- a/backends/platform/psp/input.cpp +++ b/backends/platform/psp/input.cpp @@ -95,7 +95,7 @@ const uint32 ButtonPad::_buttonMap[] = { }; ButtonPad::ButtonPad() : _prevButtonState(0), _shifted(UNSHIFTED), _padMode(PAD_MODE_NORMAL), - _comboMode(false) { + _comboMode(false), _combosEnabled(true) { for (int i = UNSHIFTED; i < SHIFTED_MODE_LAST; i++) _buttonsChanged[i] = 0; clearButtons(); @@ -154,6 +154,7 @@ void ButtonPad::initButtonsNormalMode() { _button[BTN_START][SHIFTED].setKey(Common::KEYCODE_F5, Common::ASCII_F5); _button[BTN_START][UNSHIFTED].setKey(Common::KEYCODE_F5, Common::ASCII_F5, Common::KBD_CTRL); _button[BTN_SELECT][UNSHIFTED].setPspEvent(PSP_EVENT_SHOW_VIRTUAL_KB, true, PSP_EVENT_NONE, 0); + _button[BTN_SELECT][SHIFTED].setPspEvent(PSP_EVENT_IMAGE_VIEWER, true, PSP_EVENT_NONE, 0); } void ButtonPad::initButtonsLolMode() { @@ -199,7 +200,8 @@ bool ButtonPad::getEvent(Common::Event &event, PspEvent &pspEvent, SceCtrlData & uint32 curButtonState = PSP_ALL_BUTTONS & pad.Buttons; // we only care about these - modifyButtonsForCombos(pad); // change buttons for combos + if (_combosEnabled) + modifyButtonsForCombos(pad); // change buttons for combos return getEventFromButtonState(event, pspEvent, curButtonState); } @@ -369,6 +371,7 @@ void InputHandler::init() { sceCtrlSetSamplingMode(1); // analog _buttonPad.initButtons(); + _nub.init(); } bool InputHandler::getAllInputs(Common::Event &event) { @@ -460,6 +463,12 @@ bool InputHandler::handlePspEvent(Common::Event &event, PspEvent &pspEvent) { /*case PSP_EVENT_CHANGE_SPEED: handleSpeedChange(pspEvent.data); break;*/ + case PSP_EVENT_IMAGE_VIEWER: + _imageViewer->handleEvent(pspEvent.data); + break; + case PSP_EVENT_IMAGE_VIEWER_SET_BUTTONS: + setImageViewerMode(pspEvent.data); + break; default: PSP_ERROR("Unhandled PSP Event[%d]\n", pspEvent.type); break; @@ -509,3 +518,56 @@ void InputHandler::handleSpeedChange(bool up) { GUI::TimedMessageDialog dialog(_padModeText[_padMode], 1500); dialog.runModal(); }*/ + +void InputHandler::setImageViewerMode(bool active) { + if (_buttonPad.isButtonDown() || _nub.isButtonDown()) { // can't switch yet + PSP_DEBUG_PRINT("postponing image viewer on event\n"); + _pendingPspEvent.type = PSP_EVENT_IMAGE_VIEWER_SET_BUTTONS; // queue it to be done later + _pendingPspEvent.data = active; + } else if (active) { + _nub.setDpadMode(true); + _buttonPad.enableCombos(false); // disable combos + setButtonsForImageViewer(); + } else { // deactivate + _nub.setDpadMode(false); + _nub.init(); + _buttonPad.enableCombos(true); // re-enable combos + _buttonPad.initButtons(); + } +} + +void InputHandler::setButtonsForImageViewer() { + DEBUG_ENTER_FUNC(); + + // Dpad + _buttonPad.clearButtons(); + _buttonPad.getButton(ButtonPad::BTN_UP, UNSHIFTED).setPspEvent(PSP_EVENT_IMAGE_VIEWER, ImageViewer::EVENT_ZOOM_IN, + PSP_EVENT_NONE, false); + _buttonPad.getButton(ButtonPad::BTN_DOWN, UNSHIFTED).setPspEvent(PSP_EVENT_IMAGE_VIEWER, ImageViewer::EVENT_ZOOM_OUT, + PSP_EVENT_NONE, false); + _buttonPad.getButton(ButtonPad::BTN_LEFT, UNSHIFTED).setPspEvent(PSP_EVENT_IMAGE_VIEWER, ImageViewer::EVENT_LAST_IMAGE, + PSP_EVENT_NONE, false); + _buttonPad.getButton(ButtonPad::BTN_RIGHT, UNSHIFTED).setPspEvent(PSP_EVENT_IMAGE_VIEWER, ImageViewer::EVENT_NEXT_IMAGE, + PSP_EVENT_NONE, false); + _buttonPad.getButton(ButtonPad::BTN_LTRIGGER, UNSHIFTED).setPspEvent(PSP_EVENT_IMAGE_VIEWER, ImageViewer::EVENT_HIDE, + PSP_EVENT_NONE, false); + _buttonPad.getButton(ButtonPad::BTN_RTRIGGER, UNSHIFTED).setPspEvent(PSP_EVENT_IMAGE_VIEWER, ImageViewer::EVENT_HIDE, + PSP_EVENT_NONE, false); + _buttonPad.getButton(ButtonPad::BTN_START, UNSHIFTED).setPspEvent(PSP_EVENT_IMAGE_VIEWER, ImageViewer::EVENT_HIDE, + PSP_EVENT_NONE, false); + _buttonPad.getButton(ButtonPad::BTN_SELECT, UNSHIFTED).setPspEvent(PSP_EVENT_IMAGE_VIEWER, ImageViewer::EVENT_HIDE, + PSP_EVENT_NONE, false); + + //Nub + _nub.getPad().clearButtons(); + _nub.getPad().getButton(ButtonPad::BTN_UP, UNSHIFTED).setPspEvent(PSP_EVENT_IMAGE_VIEWER, ImageViewer::EVENT_MOVE_UP, + PSP_EVENT_NONE, false); + _nub.getPad().getButton(ButtonPad::BTN_DOWN, UNSHIFTED).setPspEvent(PSP_EVENT_IMAGE_VIEWER, ImageViewer::EVENT_MOVE_DOWN, + PSP_EVENT_NONE, false); + _nub.getPad().getButton(ButtonPad::BTN_LEFT, UNSHIFTED).setPspEvent(PSP_EVENT_IMAGE_VIEWER, ImageViewer::EVENT_MOVE_LEFT, + PSP_EVENT_NONE, false); + _nub.getPad().getButton(ButtonPad::BTN_RIGHT, UNSHIFTED).setPspEvent(PSP_EVENT_IMAGE_VIEWER, ImageViewer::EVENT_MOVE_RIGHT, + PSP_EVENT_NONE, false); +} + + diff --git a/backends/platform/psp/input.h b/backends/platform/psp/input.h index acca04f376..9a1ab6faab 100644 --- a/backends/platform/psp/input.h +++ b/backends/platform/psp/input.h @@ -30,6 +30,7 @@ #include "common/events.h" #include "backends/platform/psp/pspkeyboard.h" #include "backends/platform/psp/cursor.h" +#include "backends/platform/psp/image_viewer.h" #include <pspctrl.h> enum PspEventType { @@ -40,10 +41,11 @@ enum PspEventType { PSP_EVENT_RBUTTON, PSP_EVENT_MODE_SWITCH, PSP_EVENT_CHANGE_SPEED, + PSP_EVENT_IMAGE_VIEWER, + PSP_EVENT_IMAGE_VIEWER_SET_BUTTONS, PSP_EVENT_LAST }; - struct PspEvent { PspEventType type; uint32 data; @@ -112,59 +114,77 @@ private: ShiftMode _shifted; PspPadMode _padMode; bool _comboMode; // are we in the middle of combos - static const uint32 _buttonMap[]; // maps the buttons to their values + bool _combosEnabled; // can we do combos + static const uint32 _buttonMap[]; // maps the buttons to their values void initButtonsNormalMode(); void initButtonsLolMode(); void modifyButtonsForCombos(SceCtrlData &pad); - void clearButtons(); public: ButtonPad(); + void initButtons(); // set the buttons to the mode that's selected + void clearButtons(); // empty the buttons of all events + bool getEvent(Common::Event &event, PspEvent &pspEvent, SceCtrlData &pad); bool getEventFromButtonState(Common::Event &event, PspEvent &pspEvent, uint32 buttonState); + void setShifted(ShiftMode shifted) { _shifted = shifted; } void setPadMode(PspPadMode mode) { _padMode = mode; } bool isButtonDown() { return _prevButtonState; } - void initButtons(); + + void enableCombos(bool value) { _combosEnabled = value; } + Button &getButton(ButtonType type, ShiftMode mode) { return _button[type][mode]; } }; class Nub { private: Cursor *_cursor; // to enable changing/getting cursor position - ButtonPad _buttonPad; // private buttonpad for dpad mode ShiftMode _shifted; bool _dpadMode; - + + ButtonPad _buttonPad; // private buttonpad for dpad mode + + int32 modifyNubAxisMotion(int32 input); + void translateToDpadState(int dpadX, int dpadY, uint32 &buttonState); // convert nub data to dpad data public: - Nub() : _shifted(UNSHIFTED), _dpadMode(false) { _buttonPad.initButtons(); } + Nub() : _shifted(UNSHIFTED), _dpadMode(false) { } + void init() { _buttonPad.initButtons(); } void setCursor(Cursor *cursor) { _cursor = cursor; } + + // setters void setDpadMode(bool active) { _dpadMode = active; } void setShifted(ShiftMode shifted) { _shifted = shifted; } - bool isButtonDown(); + // getters + bool isButtonDown(); bool getEvent(Common::Event &event, PspEvent &pspEvent, SceCtrlData &pad); - int32 modifyNubAxisMotion(int32 input); - void translateToDpadState(int dpadX, int dpadY, uint32 &buttonState); // convert nub data to dpad data + ButtonPad &getPad() { return _buttonPad; } }; class InputHandler { public: - InputHandler() : _keyboard(0), _cursor(0), _padMode(PAD_MODE_NORMAL), _lastPadCheckTime(0) {} + InputHandler() : _keyboard(0), _cursor(0), _imageViewer(0), _padMode(PAD_MODE_NORMAL), + _lastPadCheckTime(0) {} + // pointer setters void setKeyboard(PSPKeyboard *keyboard) { _keyboard = keyboard; } void setCursor(Cursor *cursor) { _cursor = cursor; _nub.setCursor(cursor); } + void setImageViewer(ImageViewer *imageViewer) { _imageViewer = imageViewer; } void init(); bool getAllInputs(Common::Event &event); + void setImageViewerMode(bool active); private: + Nub _nub; + ButtonPad _buttonPad; + + // Pointers to relevant other classes PSPKeyboard *_keyboard; Cursor *_cursor; - - Nub _nub; - ButtonPad _buttonPad; + ImageViewer *_imageViewer; PspPadMode _padMode; // whice mode we're in PspEvent _pendingPspEvent; // an event that can't be handled yet @@ -176,6 +196,7 @@ private: void handleMouseEvent(Common::Event &event, Common::EventType type, const char *string); void handleShiftEvent(ShiftMode shifted); void handleModeSwitchEvent(); + void setButtonsForImageViewer(); }; #endif /* PSP_INPUT_H */ diff --git a/backends/platform/psp/module.mk b/backends/platform/psp/module.mk index f96c4ef583..26887761c8 100644 --- a/backends/platform/psp/module.mk +++ b/backends/platform/psp/module.mk @@ -18,6 +18,7 @@ MODULE_OBJS := powerman.o \ rtc.o \ mp3.o \ png_loader.o \ + image_viewer.o \ tests.o # We don't use rules.mk but rather manually update OBJS and MODULE_DIRS. diff --git a/backends/platform/psp/osys_psp.cpp b/backends/platform/psp/osys_psp.cpp index 047ec1957f..4b6983785c 100644 --- a/backends/platform/psp/osys_psp.cpp +++ b/backends/platform/psp/osys_psp.cpp @@ -76,12 +76,17 @@ void OSystem_PSP::initBackend() { _displayManager.setScreen(&_screen); _displayManager.setOverlay(&_overlay); _displayManager.setKeyboard(&_keyboard); + _displayManager.setImageViewer(&_imageViewer); _displayManager.init(); // Set pointers for input handler _inputHandler.setCursor(&_cursor); _inputHandler.setKeyboard(&_keyboard); + _inputHandler.setImageViewer(&_imageViewer); _inputHandler.init(); + + // Set pointers for image viewer + _imageViewer.setInputHandler(&_inputHandler); _savefile = new PSPSaveFileManager; diff --git a/backends/platform/psp/osys_psp.h b/backends/platform/psp/osys_psp.h index 5721296c94..d59951c94c 100644 --- a/backends/platform/psp/osys_psp.h +++ b/backends/platform/psp/osys_psp.h @@ -32,10 +32,12 @@ #include "sound/mixer_intern.h" #include "backends/base-backend.h" #include "backends/fs/psp/psp-fs-factory.h" + #include "backends/platform/psp/display_client.h" #include "backends/platform/psp/default_display_client.h" #include "backends/platform/psp/cursor.h" #include "backends/platform/psp/pspkeyboard.h" +#include "backends/platform/psp/image_viewer.h" #include "backends/platform/psp/display_manager.h" #include "backends/platform/psp/input.h" #include "backends/platform/psp/audio.h" @@ -60,6 +62,7 @@ private: InputHandler _inputHandler; PspAudio _audio; PspTimer _pspTimer; + ImageViewer _imageViewer; public: OSystem_PSP() : _savefile(0), _mixer(0), _timer(0), _pendingUpdate(false), _pendingUpdateCounter(0) {} |