Merge pull request #244 from mjbudd77/master
Corrections for zapper emulation via mouse using Qt GUI.
This commit is contained in:
commit
e21ab72f7d
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
|
#include <QMouseEvent>
|
||||||
|
|
||||||
#include "Qt/nes_shm.h"
|
#include "Qt/nes_shm.h"
|
||||||
#include "Qt/fceuWrapper.h"
|
#include "Qt/fceuWrapper.h"
|
||||||
|
@ -27,6 +28,10 @@ ConsoleViewGL_t::ConsoleViewGL_t(QWidget *parent)
|
||||||
autoScaleEna = true;
|
autoScaleEna = true;
|
||||||
xscale = 2.0;
|
xscale = 2.0;
|
||||||
yscale = 2.0;
|
yscale = 2.0;
|
||||||
|
sx = 0; sy = 0;
|
||||||
|
rw = 256;
|
||||||
|
rh = 240;
|
||||||
|
mouseButtonMask = 0;
|
||||||
|
|
||||||
setMinimumWidth( GL_NES_WIDTH );
|
setMinimumWidth( GL_NES_WIDTH );
|
||||||
setMinimumHeight( GL_NES_HEIGHT );
|
setMinimumHeight( GL_NES_HEIGHT );
|
||||||
|
@ -208,6 +213,61 @@ void ConsoleViewGL_t::transfer2LocalBuffer(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConsoleViewGL_t::mousePressEvent(QMouseEvent * event)
|
||||||
|
{
|
||||||
|
//printf("Mouse Button Press: (%i,%i) %x %x\n",
|
||||||
|
// event->pos().x(), event->pos().y(), event->button(), event->buttons() );
|
||||||
|
|
||||||
|
mouseButtonMask = event->buttons();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConsoleViewGL_t::mouseReleaseEvent(QMouseEvent * event)
|
||||||
|
{
|
||||||
|
//printf("Mouse Button Release: (%i,%i) %x %x\n",
|
||||||
|
// event->pos().x(), event->pos().y(), event->button(), event->buttons() );
|
||||||
|
|
||||||
|
mouseButtonMask = event->buttons();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ConsoleViewGL_t::getMouseButtonState( unsigned int btn )
|
||||||
|
{
|
||||||
|
return (mouseButtonMask & btn) ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConsoleViewGL_t::getNormalizedCursorPos( double &x, double &y )
|
||||||
|
{
|
||||||
|
QPoint cursor;
|
||||||
|
|
||||||
|
cursor = QCursor::pos();
|
||||||
|
|
||||||
|
//printf("Global Cursor (%i,%i) \n", cursor.x(), cursor.y() );
|
||||||
|
|
||||||
|
cursor = mapFromGlobal( cursor );
|
||||||
|
|
||||||
|
//printf("Window Cursor (%i,%i) \n", cursor.x(), cursor.y() );
|
||||||
|
|
||||||
|
x = (double)(cursor.x() - sx) / (double)rw;
|
||||||
|
y = (double)(cursor.y() - sy) / (double)rh;
|
||||||
|
|
||||||
|
if ( x < 0.0 )
|
||||||
|
{
|
||||||
|
x = 0.0;
|
||||||
|
}
|
||||||
|
else if ( x > 1.0 )
|
||||||
|
{
|
||||||
|
x = 1.0;
|
||||||
|
}
|
||||||
|
if ( y < 0.0 )
|
||||||
|
{
|
||||||
|
y = 0.0;
|
||||||
|
}
|
||||||
|
else if ( y > 1.0 )
|
||||||
|
{
|
||||||
|
y = 1.0;
|
||||||
|
}
|
||||||
|
//printf("Normalized Cursor (%f,%f) \n", x, y );
|
||||||
|
}
|
||||||
|
|
||||||
void ConsoleViewGL_t::paintGL(void)
|
void ConsoleViewGL_t::paintGL(void)
|
||||||
{
|
{
|
||||||
int texture_width = nes_shm->video.ncol;
|
int texture_width = nes_shm->video.ncol;
|
||||||
|
@ -247,10 +307,10 @@ void ConsoleViewGL_t::paintGL(void)
|
||||||
yscaleTmp = yscale;
|
yscaleTmp = yscale;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int rw=(int)((r-l)*xscaleTmp);
|
rw=(int)((r-l)*xscaleTmp);
|
||||||
int rh=(int)((b-t)*yscaleTmp);
|
rh=(int)((b-t)*yscaleTmp);
|
||||||
int sx=(view_width-rw)/2;
|
sx=(view_width-rw)/2;
|
||||||
int sy=(view_height-rh)/2;
|
sy=(view_height-rh)/2;
|
||||||
|
|
||||||
glViewport(sx, sy, rw, rh);
|
glViewport(sx, sy, rw, rh);
|
||||||
|
|
||||||
|
|
|
@ -29,11 +29,15 @@ class ConsoleViewGL_t : public QOpenGLWidget, protected QOpenGLFunctions
|
||||||
double getScaleX(void){ return xscale; };
|
double getScaleX(void){ return xscale; };
|
||||||
double getScaleY(void){ return yscale; };
|
double getScaleY(void){ return yscale; };
|
||||||
void setScaleXY( double xs, double ys );
|
void setScaleXY( double xs, double ys );
|
||||||
|
void getNormalizedCursorPos( double &x, double &y );
|
||||||
|
bool getMouseButtonState( unsigned int btn );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void initializeGL(void);
|
void initializeGL(void);
|
||||||
void resizeGL(int w, int h);
|
void resizeGL(int w, int h);
|
||||||
void paintGL(void);
|
void paintGL(void);
|
||||||
|
void mousePressEvent(QMouseEvent * event);
|
||||||
|
void mouseReleaseEvent(QMouseEvent * event);
|
||||||
|
|
||||||
void buildTextures(void);
|
void buildTextures(void);
|
||||||
void calcPixRemap(void);
|
void calcPixRemap(void);
|
||||||
|
@ -44,11 +48,17 @@ class ConsoleViewGL_t : public QOpenGLWidget, protected QOpenGLFunctions
|
||||||
double yscale;
|
double yscale;
|
||||||
int view_width;
|
int view_width;
|
||||||
int view_height;
|
int view_height;
|
||||||
|
int sx;
|
||||||
|
int sy;
|
||||||
|
int rw;
|
||||||
|
int rh;
|
||||||
GLuint gltexture;
|
GLuint gltexture;
|
||||||
bool linearFilter;
|
bool linearFilter;
|
||||||
bool sqrPixels;
|
bool sqrPixels;
|
||||||
bool autoScaleEna;
|
bool autoScaleEna;
|
||||||
|
|
||||||
|
unsigned int mouseButtonMask;
|
||||||
|
|
||||||
uint32_t *localBuf;
|
uint32_t *localBuf;
|
||||||
uint32_t localBufSize;
|
uint32_t localBufSize;
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@ ConsoleViewSDL_t::ConsoleViewSDL_t(QWidget *parent)
|
||||||
sdlTexture = NULL;
|
sdlTexture = NULL;
|
||||||
|
|
||||||
vsyncEnabled = false;
|
vsyncEnabled = false;
|
||||||
|
mouseButtonMask = 0;
|
||||||
|
|
||||||
localBufSize = (4 * GL_NES_WIDTH) * (4 * GL_NES_HEIGHT) * sizeof(uint32_t);
|
localBufSize = (4 * GL_NES_WIDTH) * (4 * GL_NES_HEIGHT) * sizeof(uint32_t);
|
||||||
|
|
||||||
|
@ -252,6 +253,61 @@ void ConsoleViewSDL_t::resizeEvent(QResizeEvent *event)
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConsoleViewSDL_t::mousePressEvent(QMouseEvent * event)
|
||||||
|
{
|
||||||
|
//printf("Mouse Button Press: (%i,%i) %x %x\n",
|
||||||
|
// event->pos().x(), event->pos().y(), event->button(), event->buttons() );
|
||||||
|
|
||||||
|
mouseButtonMask = event->buttons();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConsoleViewSDL_t::mouseReleaseEvent(QMouseEvent * event)
|
||||||
|
{
|
||||||
|
//printf("Mouse Button Release: (%i,%i) %x %x\n",
|
||||||
|
// event->pos().x(), event->pos().y(), event->button(), event->buttons() );
|
||||||
|
|
||||||
|
mouseButtonMask = event->buttons();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ConsoleViewSDL_t::getMouseButtonState( unsigned int btn )
|
||||||
|
{
|
||||||
|
return (mouseButtonMask & btn) ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConsoleViewSDL_t::getNormalizedCursorPos( double &x, double &y )
|
||||||
|
{
|
||||||
|
QPoint cursor;
|
||||||
|
|
||||||
|
cursor = QCursor::pos();
|
||||||
|
|
||||||
|
//printf("Global Cursor (%i,%i) \n", cursor.x(), cursor.y() );
|
||||||
|
|
||||||
|
cursor = mapFromGlobal( cursor );
|
||||||
|
|
||||||
|
//printf("Window Cursor (%i,%i) \n", cursor.x(), cursor.y() );
|
||||||
|
|
||||||
|
x = (double)(cursor.x() - sx) / (double)rw;
|
||||||
|
y = (double)(cursor.y() - sy) / (double)rh;
|
||||||
|
|
||||||
|
if ( x < 0.0 )
|
||||||
|
{
|
||||||
|
x = 0.0;
|
||||||
|
}
|
||||||
|
else if ( x > 1.0 )
|
||||||
|
{
|
||||||
|
x = 1.0;
|
||||||
|
}
|
||||||
|
if ( y < 0.0 )
|
||||||
|
{
|
||||||
|
y = 0.0;
|
||||||
|
}
|
||||||
|
else if ( y > 1.0 )
|
||||||
|
{
|
||||||
|
y = 1.0;
|
||||||
|
}
|
||||||
|
//printf("Normalized Cursor (%f,%f) \n", x, y );
|
||||||
|
}
|
||||||
|
|
||||||
void ConsoleViewSDL_t::render(void)
|
void ConsoleViewSDL_t::render(void)
|
||||||
{
|
{
|
||||||
int nesWidth = GL_NES_WIDTH;
|
int nesWidth = GL_NES_WIDTH;
|
||||||
|
|
|
@ -32,11 +32,16 @@ class ConsoleViewSDL_t : public QWidget
|
||||||
double getScaleX(void){ return xscale; };
|
double getScaleX(void){ return xscale; };
|
||||||
double getScaleY(void){ return yscale; };
|
double getScaleY(void){ return yscale; };
|
||||||
void setScaleXY( double xs, double ys );
|
void setScaleXY( double xs, double ys );
|
||||||
|
void getNormalizedCursorPos( double &x, double &y );
|
||||||
|
bool getMouseButtonState( unsigned int btn );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
//void paintEvent(QPaintEvent *event);
|
//void paintEvent(QPaintEvent *event);
|
||||||
void resizeEvent(QResizeEvent *event);
|
void resizeEvent(QResizeEvent *event);
|
||||||
|
void mousePressEvent(QMouseEvent * event);
|
||||||
|
void mouseReleaseEvent(QMouseEvent * event);
|
||||||
|
|
||||||
int view_width;
|
int view_width;
|
||||||
int view_height;
|
int view_height;
|
||||||
|
|
||||||
|
@ -57,6 +62,7 @@ class ConsoleViewSDL_t : public QWidget
|
||||||
|
|
||||||
uint32_t *localBuf;
|
uint32_t *localBuf;
|
||||||
uint32_t localBufSize;
|
uint32_t localBufSize;
|
||||||
|
unsigned int mouseButtonMask;
|
||||||
|
|
||||||
SDL_Window *sdlWindow;
|
SDL_Window *sdlWindow;
|
||||||
SDL_Renderer *sdlRenderer;
|
SDL_Renderer *sdlRenderer;
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "Qt/dface.h"
|
#include "Qt/dface.h"
|
||||||
#include "Qt/input.h"
|
#include "Qt/input.h"
|
||||||
#include "Qt/config.h"
|
#include "Qt/config.h"
|
||||||
|
#include "Qt/ConsoleWindow.h"
|
||||||
|
|
||||||
|
|
||||||
#include "Qt/sdl.h"
|
#include "Qt/sdl.h"
|
||||||
|
@ -1068,31 +1069,46 @@ do { \
|
||||||
* Return the state of the mouse buttons. Input 'd' is an array of 3
|
* Return the state of the mouse buttons. Input 'd' is an array of 3
|
||||||
* integers that store <x, y, button state>.
|
* integers that store <x, y, button state>.
|
||||||
*/
|
*/
|
||||||
void // removed static for a call in lua-engine.cpp
|
void GetMouseData (uint32 (&d)[3])
|
||||||
GetMouseData (uint32 (&d)[3])
|
|
||||||
{
|
{
|
||||||
int x, y;
|
uint32 t, b;
|
||||||
uint32 t;
|
double nx = 0.0, ny = 0.0;
|
||||||
|
|
||||||
// retrieve the state of the mouse from SDL
|
b = 0; // map mouse buttons
|
||||||
t = SDL_GetMouseState (&x, &y);
|
|
||||||
|
|
||||||
d[2] = 0;
|
if ( consoleWindow->viewport_SDL )
|
||||||
if (t & SDL_BUTTON (1))
|
|
||||||
{
|
{
|
||||||
d[2] |= 0x1;
|
consoleWindow->viewport_SDL->getNormalizedCursorPos(nx,ny);
|
||||||
|
|
||||||
|
if ( consoleWindow->viewport_SDL->getMouseButtonState( Qt::LeftButton ) )
|
||||||
|
{
|
||||||
|
b |= 0x01;
|
||||||
}
|
}
|
||||||
if (t & SDL_BUTTON (3))
|
if ( consoleWindow->viewport_SDL->getMouseButtonState( Qt::RightButton ) )
|
||||||
{
|
{
|
||||||
d[2] |= 0x2;
|
b |= 0x02;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
consoleWindow->viewport_GL->getNormalizedCursorPos(nx,ny);
|
||||||
|
|
||||||
|
if ( consoleWindow->viewport_GL->getMouseButtonState( Qt::LeftButton ) )
|
||||||
|
{
|
||||||
|
b |= 0x01;
|
||||||
|
}
|
||||||
|
if ( consoleWindow->viewport_GL->getMouseButtonState( Qt::RightButton ) )
|
||||||
|
{
|
||||||
|
b |= 0x02;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the mouse position from the SDL video driver
|
t = PtoV (nx, ny);
|
||||||
t = PtoV (x, y);
|
d[2] = b;
|
||||||
d[0] = t & 0xFFFF;
|
d[0] = t & 0xFFFF;
|
||||||
d[1] = (t >> 16) & 0xFFFF;
|
d[1] = (t >> 16) & 0xFFFF;
|
||||||
// debug print
|
|
||||||
// printf("mouse %d %d %d\n", d[0], d[1], d[2]);
|
//printf("mouse %d %d %d\n", d[0], d[1], d[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetMouseRelative (int32 (&d)[3])
|
void GetMouseRelative (int32 (&d)[3])
|
||||||
|
|
|
@ -492,16 +492,28 @@ BlitScreen(uint8 *XBuf)
|
||||||
* Converts an x-y coordinate in the window manager into an x-y
|
* Converts an x-y coordinate in the window manager into an x-y
|
||||||
* coordinate on FCEU's screen.
|
* coordinate on FCEU's screen.
|
||||||
*/
|
*/
|
||||||
uint32
|
uint32 PtoV(double nx, double ny)
|
||||||
PtoV(uint16 x,
|
|
||||||
uint16 y)
|
|
||||||
{
|
{
|
||||||
y = (uint16)((double)y / s_eys);
|
int x, y;
|
||||||
x = (uint16)((double)x / s_exs);
|
y = (int)( ny * (double)nes_shm->video.nrow );
|
||||||
if(s_clipSides) {
|
x = (int)( nx * (double)nes_shm->video.ncol );
|
||||||
|
|
||||||
|
//printf("Scaled (%i,%i) \n", x, y);
|
||||||
|
|
||||||
|
x = x / nes_shm->video.scale;
|
||||||
|
|
||||||
|
if ( nes_shm->video.xyRatio == 1 )
|
||||||
|
{
|
||||||
|
y = y / nes_shm->video.scale;
|
||||||
|
}
|
||||||
|
//printf("UnScaled (%i,%i) \n", x, y);
|
||||||
|
|
||||||
|
if (s_clipSides)
|
||||||
|
{
|
||||||
x += 8;
|
x += 8;
|
||||||
}
|
}
|
||||||
y += s_srendline;
|
y += s_srendline;
|
||||||
|
|
||||||
return (x | (y << 16));
|
return (x | (y << 16));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint32 PtoV(uint16 x, uint16 y);
|
uint32 PtoV(double x, double y);
|
||||||
bool FCEUD_ShouldDrawInputAids();
|
bool FCEUD_ShouldDrawInputAids();
|
||||||
bool FCEUI_AviDisableMovieMessages();
|
bool FCEUI_AviDisableMovieMessages();
|
||||||
bool FCEUI_AviEnableHUDrecording();
|
bool FCEUI_AviEnableHUDrecording();
|
||||||
|
|
Loading…
Reference in New Issue