aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backends/graphics/opengl/opengl-graphics.cpp118
-rw-r--r--backends/graphics/opengl/opengl-graphics.h12
-rw-r--r--backends/graphics/sdl/sdl-graphics.cpp4
-rw-r--r--backends/graphics/sdl/sdl-graphics.h2
-rw-r--r--backends/platform/sdl/sdl.cpp4
5 files changed, 130 insertions, 10 deletions
diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp
index 57a558a11b..9a9e30fb69 100644
--- a/backends/graphics/opengl/opengl-graphics.cpp
+++ b/backends/graphics/opengl/opengl-graphics.cpp
@@ -47,10 +47,23 @@ OpenGLGraphicsManager::OpenGLGraphicsManager()
_videoMode.mode = OpenGL::GFX_NORMAL;
_videoMode.scaleFactor = 1;
_videoMode.fullscreen = false;
+
+ _cursorPalette = (uint8 *)calloc(sizeof(uint8), 256);
+
+ // Register the graphics manager as a event observer
+ g_system->getEventManager()->getEventDispatcher()->registerObserver(this, 2, false);
}
OpenGLGraphicsManager::~OpenGLGraphicsManager() {
+ // Unregister the event observer
+ if (g_system->getEventManager()->getEventDispatcher() != NULL)
+ g_system->getEventManager()->getEventDispatcher()->unregisterObserver(this);
+
+ free(_cursorPalette);
+ delete _gameTexture;
+ delete _overlayTexture;
+ delete _mouseTexture;
}
//
@@ -58,7 +71,7 @@ OpenGLGraphicsManager::~OpenGLGraphicsManager() {
//
bool OpenGLGraphicsManager::hasFeature(OSystem::Feature f) {
- return false;
+ return (f == OSystem::kFeatureCursorHasPalette);
}
void OpenGLGraphicsManager::setFeatureState(OSystem::Feature f, bool enable) {
@@ -74,7 +87,7 @@ bool OpenGLGraphicsManager::getFeatureState(OSystem::Feature f) {
//
static const OSystem::GraphicsMode s_supportedGraphicsModes[] = {
- {"gl1x", _s("OpenGL Normal (no scaling)"), OpenGL::GFX_NORMAL},
+ {"gl1x", _s("OpenGL Normal"), OpenGL::GFX_NORMAL},
#ifdef USE_SCALERS
{"gl2x", "OpenGL 2x", OpenGL::GFX_DOUBLESIZE},
{"gl3x", "OpenGL 3x", OpenGL::GFX_TRIPLESIZE},
@@ -113,7 +126,7 @@ void OpenGLGraphicsManager::initSize(uint width, uint height, const Graphics::Pi
//avoid redundant format changes
Graphics::PixelFormat newFormat;
if (!format)
- newFormat = Graphics::PixelFormat::createFormatCLUT8();
+ newFormat = Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0);//Graphics::PixelFormat::createFormatCLUT8();
else
newFormat = *format;
@@ -385,15 +398,66 @@ void OpenGLGraphicsManager::warpMouse(int x, int y) {
}
void OpenGLGraphicsManager::setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, int cursorTargetScale, const Graphics::PixelFormat *format) {
+ assert(keycolor < 256);
+
+ // Set cursor info
+ _mouseCurState.w = w;
+ _mouseCurState.h = h;
+ _mouseCurState.hotX = hotspotX;
+ _mouseCurState.hotY = hotspotY;
+
+ // Allocate a texture big enough for cursor
+ _mouseTexture->allocBuffer(w, h);
+
+ // Set the key color alpha to 0
+ _cursorPalette[keycolor * 4 + 3] = 0;
+
+ // Create a temporary surface
+ uint8 *surface = new uint8[w * h * 4];
+
+ // Convert the paletted cursor
+ const uint8 *src = _cursorPalette;
+ uint8 *dst = surface;
+ for (uint i = 0; i < w * h; i++) {
+ dst[0] = src[buf[i] * 4];
+ dst[1] = src[buf[i] * 4 + 1];
+ dst[2] = src[buf[i] * 4 + 2];
+ dst[3] = src[buf[i] * 4 + 3];
+ if (i == (w * 5 + 3)) {
+ printf("%d,%d,%d,%d - %d,%d,%d,%d - %d\n", dst[0],dst[1],dst[2],dst[3],src[buf[i] * 4],src[buf[i] * 4+1],src[buf[i] * 4+2],src[buf[i] * 4+3],buf[i]);
+ }
+ dst += 4;
+ }
+ // Set keycolor alpha back to normal
+ _cursorPalette[keycolor * 4] = 255;
+
+ // Update the texture with new cursor
+ _mouseTexture->updateBuffer(surface, w * 4, 0, 0, w, h);
+
+ // Free the temp surface
+ delete[] surface;
}
void OpenGLGraphicsManager::setCursorPalette(const byte *colors, uint start, uint num) {
+ assert(colors);
+
+ // Save the cursor palette
+ uint8 *dst = _cursorPalette + start * 4;
+ do {
+ dst[0] = colors[0];
+ dst[1] = colors[1];
+ dst[2] = colors[2];
+ dst[3] = 255;
+ dst += 4;
+ colors += 4;
+ } while(num--);
+ _cursorPaletteDisabled = false;
}
void OpenGLGraphicsManager::disableCursorPalette(bool disable) {
-
+ _cursorPaletteDisabled = disable;
}
//
@@ -439,10 +503,18 @@ void OpenGLGraphicsManager::getGLPixelFormat(Graphics::PixelFormat pixelFormat,
}
void OpenGLGraphicsManager::internUpdateScreen() {
+ // Clear the screen
glClear( GL_COLOR_BUFFER_BIT );
+
+ // Draw the game texture
_gameTexture->drawTexture(0, 0, _videoMode.hardwareWidth, _videoMode.hardwareHeight);
+
+ // Draw the overlay texture
_overlayTexture->drawTexture(0, 0, _videoMode.hardwareWidth, _videoMode.hardwareHeight);
- _mouseTexture->drawTexture(_mouseCurState.x, _mouseCurState.y, _mouseCurState.w, _mouseCurState.h);
+
+ // Draw the mouse texture
+ _mouseTexture->drawTexture(_mouseCurState.x - _mouseCurState.hotX,
+ _mouseCurState.y - _mouseCurState.hotY, _mouseCurState.w, _mouseCurState.h);
}
bool OpenGLGraphicsManager::loadGFXMode() {
@@ -512,4 +584,40 @@ bool OpenGLGraphicsManager::hotswapGFXMode() {
return false;
}
+void OpenGLGraphicsManager::adjustMouseEvent(const Common::Event &event) {
+ if (!event.synthetic) {
+ Common::Event newEvent(event);
+ newEvent.synthetic = true;
+ if (!_overlayVisible) {
+ newEvent.mouse.x /= _videoMode.scaleFactor;
+ newEvent.mouse.y /= _videoMode.scaleFactor;
+ //if (_videoMode.aspectRatioCorrection)
+ // newEvent.mouse.y = aspect2Real(newEvent.mouse.y);
+ }
+ g_system->getEventManager()->pushEvent(newEvent);
+ }
+}
+
+bool OpenGLGraphicsManager::notifyEvent(const Common::Event &event) {
+ switch (event.type) {
+ case Common::EVENT_MOUSEMOVE:
+ if (event.synthetic)
+ setMousePos(event.mouse.x, event.mouse.y);
+ case Common::EVENT_LBUTTONDOWN:
+ case Common::EVENT_RBUTTONDOWN:
+ case Common::EVENT_WHEELUP:
+ case Common::EVENT_WHEELDOWN:
+ case Common::EVENT_MBUTTONDOWN:
+ case Common::EVENT_LBUTTONUP:
+ case Common::EVENT_RBUTTONUP:
+ case Common::EVENT_MBUTTONUP:
+ adjustMouseEvent(event);
+ return !event.synthetic;
+ default:
+ break;
+ }
+
+ return false;
+}
+
#endif
diff --git a/backends/graphics/opengl/opengl-graphics.h b/backends/graphics/opengl/opengl-graphics.h
index 70a7bc0960..d02fcd7fe4 100644
--- a/backends/graphics/opengl/opengl-graphics.h
+++ b/backends/graphics/opengl/opengl-graphics.h
@@ -28,6 +28,7 @@
#include "backends/graphics/opengl/gltexture.h"
#include "backends/graphics/graphics.h"
+#include "common/events.h"
namespace OpenGL {
@@ -42,7 +43,7 @@ enum {
/**
* Open GL graphics manager
*/
-class OpenGLGraphicsManager : public GraphicsManager {
+class OpenGLGraphicsManager : public GraphicsManager, public Common::EventObserver {
public:
OpenGLGraphicsManager();
virtual ~OpenGLGraphicsManager();
@@ -95,7 +96,8 @@ public:
virtual void displayMessageOnOSD(const char *msg);
- virtual void setMousePos(int x, int y);
+ // Override from Common::EventObserver
+ bool notifyEvent(const Common::Event &event);
protected:
GLTexture* _gameTexture;
@@ -186,6 +188,12 @@ protected:
bool _mouseVisible;
bool _mouseNeedsRedraw;
+ uint8 *_cursorPalette;
+ bool _cursorPaletteDisabled;
+
+ virtual void adjustMouseEvent(const Common::Event &event);
+ virtual void setMousePos(int x, int y);
+
// Shake mode
int _currentShakePos;
int _newShakePos;
diff --git a/backends/graphics/sdl/sdl-graphics.cpp b/backends/graphics/sdl/sdl-graphics.cpp
index efb8e9afc8..b9318fd327 100644
--- a/backends/graphics/sdl/sdl-graphics.cpp
+++ b/backends/graphics/sdl/sdl-graphics.cpp
@@ -190,6 +190,10 @@ SdlGraphicsManager::SdlGraphicsManager()
}
SdlGraphicsManager::~SdlGraphicsManager() {
+ // Unregister the event observer
+ if (g_system->getEventManager()->getEventDispatcher() != NULL)
+ g_system->getEventManager()->getEventDispatcher()->unregisterObserver(this);
+
unloadGFXMode();
g_system->deleteMutex(_graphicsMutex);
diff --git a/backends/graphics/sdl/sdl-graphics.h b/backends/graphics/sdl/sdl-graphics.h
index 157c754a5f..a990d31a0f 100644
--- a/backends/graphics/sdl/sdl-graphics.h
+++ b/backends/graphics/sdl/sdl-graphics.h
@@ -73,7 +73,7 @@ public:
/**
* SDL graphics manager
*/
-class SdlGraphicsManager : public GraphicsManager, public Common::EventObserver {
+class SdlGraphicsManager : public GraphicsManager, public Common::EventObserver {
public:
SdlGraphicsManager();
virtual ~SdlGraphicsManager();
diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index 781cff46cb..3db6d047f8 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -187,12 +187,12 @@ void OSystem_SDL::setWindowCaption(const char *caption) {
void OSystem_SDL::deinit() {
SDL_ShowCursor(SDL_ENABLE);
- delete _eventManager;
- _eventManager = 0;
delete _savefileManager;
_savefileManager = 0;
delete _graphicsManager;
_graphicsManager = 0;
+ delete _eventManager;
+ _eventManager = 0;
delete _audiocdManager;
_audiocdManager = 0;
delete _mixerManager;