Added basic cursor drawing.
svn-id: r50954
This commit is contained in:
parent
3995b2d8f7
commit
0e748c5a97
5 changed files with 130 additions and 10 deletions
|
@ -47,10 +47,23 @@ OpenGLGraphicsManager::OpenGLGraphicsManager()
|
||||||
_videoMode.mode = OpenGL::GFX_NORMAL;
|
_videoMode.mode = OpenGL::GFX_NORMAL;
|
||||||
_videoMode.scaleFactor = 1;
|
_videoMode.scaleFactor = 1;
|
||||||
_videoMode.fullscreen = false;
|
_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() {
|
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) {
|
bool OpenGLGraphicsManager::hasFeature(OSystem::Feature f) {
|
||||||
return false;
|
return (f == OSystem::kFeatureCursorHasPalette);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGLGraphicsManager::setFeatureState(OSystem::Feature f, bool enable) {
|
void OpenGLGraphicsManager::setFeatureState(OSystem::Feature f, bool enable) {
|
||||||
|
@ -74,7 +87,7 @@ bool OpenGLGraphicsManager::getFeatureState(OSystem::Feature f) {
|
||||||
//
|
//
|
||||||
|
|
||||||
static const OSystem::GraphicsMode s_supportedGraphicsModes[] = {
|
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
|
#ifdef USE_SCALERS
|
||||||
{"gl2x", "OpenGL 2x", OpenGL::GFX_DOUBLESIZE},
|
{"gl2x", "OpenGL 2x", OpenGL::GFX_DOUBLESIZE},
|
||||||
{"gl3x", "OpenGL 3x", OpenGL::GFX_TRIPLESIZE},
|
{"gl3x", "OpenGL 3x", OpenGL::GFX_TRIPLESIZE},
|
||||||
|
@ -113,7 +126,7 @@ void OpenGLGraphicsManager::initSize(uint width, uint height, const Graphics::Pi
|
||||||
//avoid redundant format changes
|
//avoid redundant format changes
|
||||||
Graphics::PixelFormat newFormat;
|
Graphics::PixelFormat newFormat;
|
||||||
if (!format)
|
if (!format)
|
||||||
newFormat = Graphics::PixelFormat::createFormatCLUT8();
|
newFormat = Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0);//Graphics::PixelFormat::createFormatCLUT8();
|
||||||
else
|
else
|
||||||
newFormat = *format;
|
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) {
|
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) {
|
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) {
|
void OpenGLGraphicsManager::disableCursorPalette(bool disable) {
|
||||||
|
_cursorPaletteDisabled = disable;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -439,10 +503,18 @@ void OpenGLGraphicsManager::getGLPixelFormat(Graphics::PixelFormat pixelFormat,
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGLGraphicsManager::internUpdateScreen() {
|
void OpenGLGraphicsManager::internUpdateScreen() {
|
||||||
|
// Clear the screen
|
||||||
glClear( GL_COLOR_BUFFER_BIT );
|
glClear( GL_COLOR_BUFFER_BIT );
|
||||||
|
|
||||||
|
// Draw the game texture
|
||||||
_gameTexture->drawTexture(0, 0, _videoMode.hardwareWidth, _videoMode.hardwareHeight);
|
_gameTexture->drawTexture(0, 0, _videoMode.hardwareWidth, _videoMode.hardwareHeight);
|
||||||
|
|
||||||
|
// Draw the overlay texture
|
||||||
_overlayTexture->drawTexture(0, 0, _videoMode.hardwareWidth, _videoMode.hardwareHeight);
|
_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() {
|
bool OpenGLGraphicsManager::loadGFXMode() {
|
||||||
|
@ -512,4 +584,40 @@ bool OpenGLGraphicsManager::hotswapGFXMode() {
|
||||||
return false;
|
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
|
#endif
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
|
|
||||||
#include "backends/graphics/opengl/gltexture.h"
|
#include "backends/graphics/opengl/gltexture.h"
|
||||||
#include "backends/graphics/graphics.h"
|
#include "backends/graphics/graphics.h"
|
||||||
|
#include "common/events.h"
|
||||||
|
|
||||||
namespace OpenGL {
|
namespace OpenGL {
|
||||||
|
|
||||||
|
@ -42,7 +43,7 @@ enum {
|
||||||
/**
|
/**
|
||||||
* Open GL graphics manager
|
* Open GL graphics manager
|
||||||
*/
|
*/
|
||||||
class OpenGLGraphicsManager : public GraphicsManager {
|
class OpenGLGraphicsManager : public GraphicsManager, public Common::EventObserver {
|
||||||
public:
|
public:
|
||||||
OpenGLGraphicsManager();
|
OpenGLGraphicsManager();
|
||||||
virtual ~OpenGLGraphicsManager();
|
virtual ~OpenGLGraphicsManager();
|
||||||
|
@ -95,7 +96,8 @@ public:
|
||||||
|
|
||||||
virtual void displayMessageOnOSD(const char *msg);
|
virtual void displayMessageOnOSD(const char *msg);
|
||||||
|
|
||||||
virtual void setMousePos(int x, int y);
|
// Override from Common::EventObserver
|
||||||
|
bool notifyEvent(const Common::Event &event);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
GLTexture* _gameTexture;
|
GLTexture* _gameTexture;
|
||||||
|
@ -186,6 +188,12 @@ protected:
|
||||||
bool _mouseVisible;
|
bool _mouseVisible;
|
||||||
bool _mouseNeedsRedraw;
|
bool _mouseNeedsRedraw;
|
||||||
|
|
||||||
|
uint8 *_cursorPalette;
|
||||||
|
bool _cursorPaletteDisabled;
|
||||||
|
|
||||||
|
virtual void adjustMouseEvent(const Common::Event &event);
|
||||||
|
virtual void setMousePos(int x, int y);
|
||||||
|
|
||||||
// Shake mode
|
// Shake mode
|
||||||
int _currentShakePos;
|
int _currentShakePos;
|
||||||
int _newShakePos;
|
int _newShakePos;
|
||||||
|
|
|
@ -190,6 +190,10 @@ SdlGraphicsManager::SdlGraphicsManager()
|
||||||
}
|
}
|
||||||
|
|
||||||
SdlGraphicsManager::~SdlGraphicsManager() {
|
SdlGraphicsManager::~SdlGraphicsManager() {
|
||||||
|
// Unregister the event observer
|
||||||
|
if (g_system->getEventManager()->getEventDispatcher() != NULL)
|
||||||
|
g_system->getEventManager()->getEventDispatcher()->unregisterObserver(this);
|
||||||
|
|
||||||
unloadGFXMode();
|
unloadGFXMode();
|
||||||
g_system->deleteMutex(_graphicsMutex);
|
g_system->deleteMutex(_graphicsMutex);
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* SDL graphics manager
|
* SDL graphics manager
|
||||||
*/
|
*/
|
||||||
class SdlGraphicsManager : public GraphicsManager, public Common::EventObserver {
|
class SdlGraphicsManager : public GraphicsManager, public Common::EventObserver {
|
||||||
public:
|
public:
|
||||||
SdlGraphicsManager();
|
SdlGraphicsManager();
|
||||||
virtual ~SdlGraphicsManager();
|
virtual ~SdlGraphicsManager();
|
||||||
|
|
|
@ -187,12 +187,12 @@ void OSystem_SDL::setWindowCaption(const char *caption) {
|
||||||
void OSystem_SDL::deinit() {
|
void OSystem_SDL::deinit() {
|
||||||
SDL_ShowCursor(SDL_ENABLE);
|
SDL_ShowCursor(SDL_ENABLE);
|
||||||
|
|
||||||
delete _eventManager;
|
|
||||||
_eventManager = 0;
|
|
||||||
delete _savefileManager;
|
delete _savefileManager;
|
||||||
_savefileManager = 0;
|
_savefileManager = 0;
|
||||||
delete _graphicsManager;
|
delete _graphicsManager;
|
||||||
_graphicsManager = 0;
|
_graphicsManager = 0;
|
||||||
|
delete _eventManager;
|
||||||
|
_eventManager = 0;
|
||||||
delete _audiocdManager;
|
delete _audiocdManager;
|
||||||
_audiocdManager = 0;
|
_audiocdManager = 0;
|
||||||
delete _mixerManager;
|
delete _mixerManager;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue