Added logic to also init SDL mouse cursor shape in addition to Qt just incase SDL is drawing mouse cursor.
This commit is contained in:
parent
b61b30e0bb
commit
842aab44aa
|
@ -65,6 +65,7 @@ ConsoleViewSDL_t::ConsoleViewSDL_t(QWidget *parent)
|
|||
sdlWindow = NULL;
|
||||
sdlRenderer = NULL;
|
||||
sdlTexture = NULL;
|
||||
sdlCursor = NULL;
|
||||
|
||||
vsyncEnabled = false;
|
||||
mouseButtonMask = 0;
|
||||
|
@ -106,6 +107,10 @@ ConsoleViewSDL_t::~ConsoleViewSDL_t(void)
|
|||
{
|
||||
free( localBuf ); localBuf = NULL;
|
||||
}
|
||||
if ( sdlCursor )
|
||||
{
|
||||
SDL_FreeCursor(sdlCursor); sdlCursor = NULL;
|
||||
}
|
||||
cleanup();
|
||||
}
|
||||
|
||||
|
@ -303,6 +308,104 @@ void ConsoleViewSDL_t::reset(void)
|
|||
}
|
||||
}
|
||||
|
||||
void ConsoleViewSDL_t::setCursor(const QCursor &c)
|
||||
{
|
||||
QImage pm;
|
||||
SDL_Surface *s;
|
||||
|
||||
pm = c.pixmap().toImage();
|
||||
|
||||
if (pm.format() != QImage::Format_ARGB32)
|
||||
{
|
||||
printf("Coverting Image to ARGB32\n");
|
||||
pm = pm.convertToFormat(QImage::Format_ARGB32);
|
||||
}
|
||||
|
||||
// QImage stores each pixel in ARGB format
|
||||
// Mask appropriately for the endianness
|
||||
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
||||
Uint32 amask = 0x000000ff;
|
||||
Uint32 rmask = 0x0000ff00;
|
||||
Uint32 gmask = 0x00ff0000;
|
||||
Uint32 bmask = 0xff000000;
|
||||
#else
|
||||
Uint32 amask = 0xff000000;
|
||||
Uint32 rmask = 0x00ff0000;
|
||||
Uint32 gmask = 0x0000ff00;
|
||||
Uint32 bmask = 0x000000ff;
|
||||
#endif
|
||||
|
||||
s = SDL_CreateRGBSurfaceFrom((void*)pm.constBits(),
|
||||
pm.width(), pm.height(), pm.depth(), pm.bytesPerLine(),
|
||||
rmask, gmask, bmask, amask);
|
||||
|
||||
if ( s == NULL )
|
||||
{
|
||||
printf("Error: Failed to create SDL Surface for Icon\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if ( sdlCursor )
|
||||
{
|
||||
SDL_FreeCursor(sdlCursor); sdlCursor = NULL;
|
||||
}
|
||||
|
||||
sdlCursor = SDL_CreateColorCursor( s, c.hotSpot().x(), c.hotSpot().y() );
|
||||
|
||||
if ( sdlCursor == NULL )
|
||||
{
|
||||
printf("SDL Cursor Failed: %s\n", SDL_GetError() );
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("SDL Cursor Initialized at (%i,%i)\n", c.hotSpot().x(), c.hotSpot().y() );
|
||||
SDL_SetCursor(sdlCursor);
|
||||
SDL_ShowCursor( SDL_ENABLE );
|
||||
}
|
||||
|
||||
QWidget::setCursor(c);
|
||||
}
|
||||
|
||||
void ConsoleViewSDL_t::setCursor( Qt::CursorShape s )
|
||||
{
|
||||
SDL_SystemCursor sdlSysCursor;
|
||||
|
||||
switch ( s )
|
||||
{
|
||||
default:
|
||||
case Qt::ArrowCursor:
|
||||
sdlSysCursor = SDL_SYSTEM_CURSOR_ARROW;
|
||||
break;
|
||||
case Qt::BlankCursor:
|
||||
sdlSysCursor = SDL_SYSTEM_CURSOR_ARROW;
|
||||
break;
|
||||
case Qt::CrossCursor:
|
||||
sdlSysCursor = SDL_SYSTEM_CURSOR_CROSSHAIR;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( sdlCursor )
|
||||
{
|
||||
SDL_FreeCursor(sdlCursor); sdlCursor = NULL;
|
||||
}
|
||||
|
||||
sdlCursor = SDL_CreateSystemCursor( sdlSysCursor );
|
||||
|
||||
if ( sdlCursor == NULL )
|
||||
{
|
||||
printf("SDL Cursor Failed: %s\n", SDL_GetError() );
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("SDL System Cursor Initialized\n");
|
||||
SDL_SetCursor(sdlCursor);
|
||||
}
|
||||
|
||||
SDL_ShowCursor( (s == Qt::BlankCursor) ? SDL_DISABLE : SDL_ENABLE );
|
||||
|
||||
QWidget::setCursor(s);
|
||||
}
|
||||
|
||||
void ConsoleViewSDL_t::showEvent(QShowEvent *event)
|
||||
{
|
||||
//printf("SDL Show: %i x %i \n", width(), height() );
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
#include <QCursor>
|
||||
#include <QPaintEvent>
|
||||
#include <QResizeEvent>
|
||||
#include <SDL.h>
|
||||
|
@ -38,6 +39,8 @@ class ConsoleViewSDL_t : public QWidget
|
|||
void getAspectXY( double &x, double &y );
|
||||
double getAspectRatio(void);
|
||||
|
||||
void setCursor(const QCursor &c);
|
||||
void setCursor( Qt::CursorShape s );
|
||||
protected:
|
||||
|
||||
//void paintEvent(QPaintEvent *event);
|
||||
|
@ -74,6 +77,7 @@ class ConsoleViewSDL_t : public QWidget
|
|||
SDL_Window *sdlWindow;
|
||||
SDL_Renderer *sdlRenderer;
|
||||
SDL_Texture *sdlTexture;
|
||||
SDL_Cursor *sdlCursor;
|
||||
//SDL_Rect sdlViewport;
|
||||
|
||||
private slots:
|
||||
|
|
Loading…
Reference in New Issue