Added a menu bar to the Qt PPU viewer. Added logic to make the grid and tile selector color selectable.
This commit is contained in:
parent
9c70a682b7
commit
e74dbeeb51
|
@ -29,6 +29,7 @@
|
||||||
#include <QMenuBar>
|
#include <QMenuBar>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
|
#include <QColorDialog>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
#include <QTreeWidget>
|
#include <QTreeWidget>
|
||||||
|
@ -92,18 +93,31 @@ int openPPUViewWindow( QWidget *parent )
|
||||||
ppuViewerDialog_t::ppuViewerDialog_t(QWidget *parent)
|
ppuViewerDialog_t::ppuViewerDialog_t(QWidget *parent)
|
||||||
: QDialog( parent, Qt::Window )
|
: QDialog( parent, Qt::Window )
|
||||||
{
|
{
|
||||||
|
QMenuBar *menuBar;
|
||||||
QVBoxLayout *mainLayout, *vbox;
|
QVBoxLayout *mainLayout, *vbox;
|
||||||
QVBoxLayout *patternVbox[2];
|
QVBoxLayout *patternVbox[2];
|
||||||
QHBoxLayout *hbox;
|
QHBoxLayout *hbox;
|
||||||
QGridLayout *grid;
|
QGridLayout *grid;
|
||||||
|
QMenu *viewMenu, *colorMenu;
|
||||||
|
QAction *act;
|
||||||
char stmp[64];
|
char stmp[64];
|
||||||
|
int useNativeMenuBar;
|
||||||
|
|
||||||
ppuViewWindow = this;
|
ppuViewWindow = this;
|
||||||
|
|
||||||
|
menuBar = new QMenuBar(this);
|
||||||
|
|
||||||
|
// This is needed for menu bar to show up on MacOS
|
||||||
|
g_config->getOption( "SDL.UseNativeMenuBar", &useNativeMenuBar );
|
||||||
|
|
||||||
|
menuBar->setNativeMenuBar( useNativeMenuBar ? true : false );
|
||||||
|
|
||||||
setWindowTitle( tr("PPU Viewer") );
|
setWindowTitle( tr("PPU Viewer") );
|
||||||
|
|
||||||
mainLayout = new QVBoxLayout();
|
mainLayout = new QVBoxLayout();
|
||||||
|
|
||||||
|
mainLayout->setMenuBar( menuBar );
|
||||||
|
|
||||||
setLayout( mainLayout );
|
setLayout( mainLayout );
|
||||||
|
|
||||||
vbox = new QVBoxLayout();
|
vbox = new QVBoxLayout();
|
||||||
|
@ -197,6 +211,77 @@ ppuViewerDialog_t::ppuViewerDialog_t(QWidget *parent)
|
||||||
|
|
||||||
FCEUD_UpdatePPUView( -1, 1 );
|
FCEUD_UpdatePPUView( -1, 1 );
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------
|
||||||
|
// Menu
|
||||||
|
//-----------------------------------------------------------------------
|
||||||
|
// View1
|
||||||
|
viewMenu = menuBar->addMenu(tr("View1"));
|
||||||
|
|
||||||
|
// View1 -> Toggle Grid
|
||||||
|
act = new QAction(tr("Toggle Grid"), this);
|
||||||
|
//act->setShortcut(QKeySequence::Open);
|
||||||
|
//act->setCheckable(true);
|
||||||
|
//act->setChecked( patternView[0]->getDrawTileGrid() );
|
||||||
|
act->setStatusTip(tr("Toggle Grid"));
|
||||||
|
connect( act, SIGNAL(triggered()), patternView[0], SLOT(toggleTileGridLines()) );
|
||||||
|
|
||||||
|
viewMenu->addAction(act);
|
||||||
|
|
||||||
|
// View1 -> Colors
|
||||||
|
colorMenu = viewMenu->addMenu(tr("Colors"));
|
||||||
|
|
||||||
|
// View1 -> Colors -> Tile Selector
|
||||||
|
act = new QAction(tr("Tile Selector"), this);
|
||||||
|
//act->setShortcut(QKeySequence::Open);
|
||||||
|
act->setStatusTip(tr("Tile Selector"));
|
||||||
|
connect(act, SIGNAL(triggered()), patternView[0], SLOT(setTileSelectorColor()) );
|
||||||
|
|
||||||
|
colorMenu->addAction(act);
|
||||||
|
|
||||||
|
// View1 -> Colors -> Tile Grid
|
||||||
|
act = new QAction(tr("Tile Grid"), this);
|
||||||
|
//act->setShortcut(QKeySequence::Open);
|
||||||
|
act->setStatusTip(tr("Tile Grid"));
|
||||||
|
connect(act, SIGNAL(triggered()), patternView[0], SLOT(setTileGridColor()) );
|
||||||
|
|
||||||
|
colorMenu->addAction(act);
|
||||||
|
|
||||||
|
// View2
|
||||||
|
viewMenu = menuBar->addMenu(tr("View2"));
|
||||||
|
|
||||||
|
// View2 -> Toggle Grid
|
||||||
|
act = new QAction(tr("Toggle Grid"), this);
|
||||||
|
//act->setShortcut(QKeySequence::Open);
|
||||||
|
//act->setCheckable(true);
|
||||||
|
//act->setChecked( patternView[1]->getDrawTileGrid() );
|
||||||
|
act->setStatusTip(tr("Toggle Grid"));
|
||||||
|
connect( act, SIGNAL(triggered()), patternView[1], SLOT(toggleTileGridLines()) );
|
||||||
|
|
||||||
|
viewMenu->addAction(act);
|
||||||
|
|
||||||
|
// View2 -> Colors
|
||||||
|
colorMenu = viewMenu->addMenu(tr("Colors"));
|
||||||
|
|
||||||
|
// View2 -> Colors -> Tile Selector
|
||||||
|
act = new QAction(tr("Tile Selector"), this);
|
||||||
|
//act->setShortcut(QKeySequence::Open);
|
||||||
|
act->setStatusTip(tr("Tile Selector"));
|
||||||
|
connect(act, SIGNAL(triggered()), patternView[1], SLOT(setTileSelectorColor()) );
|
||||||
|
|
||||||
|
colorMenu->addAction(act);
|
||||||
|
|
||||||
|
// View2 -> Colors -> Tile Grid
|
||||||
|
act = new QAction(tr("Tile Grid"), this);
|
||||||
|
//act->setShortcut(QKeySequence::Open);
|
||||||
|
act->setStatusTip(tr("Tile Grid"));
|
||||||
|
connect(act, SIGNAL(triggered()), patternView[1], SLOT(setTileGridColor()) );
|
||||||
|
|
||||||
|
colorMenu->addAction(act);
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------
|
||||||
|
// End Menu
|
||||||
|
//-----------------------------------------------------------------------
|
||||||
|
|
||||||
updateTimer = new QTimer( this );
|
updateTimer = new QTimer( this );
|
||||||
|
|
||||||
connect( updateTimer, &QTimer::timeout, this, &ppuViewerDialog_t::periodicUpdate );
|
connect( updateTimer, &QTimer::timeout, this, &ppuViewerDialog_t::periodicUpdate );
|
||||||
|
@ -280,6 +365,10 @@ ppuPatternView_t::ppuPatternView_t( int patternIndexID, QWidget *parent)
|
||||||
tileLabel = NULL;
|
tileLabel = NULL;
|
||||||
mode = 0;
|
mode = 0;
|
||||||
drawTileGrid = true;
|
drawTileGrid = true;
|
||||||
|
hover2Focus = false;
|
||||||
|
|
||||||
|
selTileColor.setRgb(255,255,255);
|
||||||
|
gridColor.setRgb(128,128,128);
|
||||||
}
|
}
|
||||||
//----------------------------------------------------
|
//----------------------------------------------------
|
||||||
void ppuPatternView_t::setPattern( ppuPatternTable_t *p )
|
void ppuPatternView_t::setPattern( ppuPatternTable_t *p )
|
||||||
|
@ -295,6 +384,36 @@ void ppuPatternView_t::setTileLabel( QLabel *l )
|
||||||
ppuPatternView_t::~ppuPatternView_t(void)
|
ppuPatternView_t::~ppuPatternView_t(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
void ppuPatternView_t::openColorPicker( QColor *c )
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
QColorDialog dialog( this );
|
||||||
|
|
||||||
|
dialog.setCurrentColor( *c );
|
||||||
|
dialog.setOption( QColorDialog::DontUseNativeDialog, true );
|
||||||
|
dialog.show();
|
||||||
|
ret = dialog.exec();
|
||||||
|
|
||||||
|
if ( ret == QDialog::Accepted )
|
||||||
|
{
|
||||||
|
//QString colorText;
|
||||||
|
//colorText = dialog.selectedColor().name();
|
||||||
|
//printf("FG Color string '%s'\n", colorText.toStdString().c_str() );
|
||||||
|
//g_config->setOption("SDL.HexEditFgColor", colorText.toStdString().c_str() );
|
||||||
|
*c = dialog.selectedColor();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
void ppuPatternView_t::setTileSelectorColor(void)
|
||||||
|
{
|
||||||
|
openColorPicker( &selTileColor );
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
void ppuPatternView_t::setTileGridColor(void)
|
||||||
|
{
|
||||||
|
openColorPicker( &gridColor );
|
||||||
}
|
}
|
||||||
//----------------------------------------------------
|
//----------------------------------------------------
|
||||||
QPoint ppuPatternView_t::convPixToTile( QPoint p )
|
QPoint ppuPatternView_t::convPixToTile( QPoint p )
|
||||||
|
@ -373,6 +492,13 @@ void ppuPatternView_t::keyPressEvent(QKeyEvent *event)
|
||||||
|
|
||||||
FCEUD_UpdatePPUView( -1, 0 );
|
FCEUD_UpdatePPUView( -1, 0 );
|
||||||
}
|
}
|
||||||
|
else if ( event->key() == Qt::Key_F5 )
|
||||||
|
{
|
||||||
|
// Load Tile Viewport
|
||||||
|
PPUViewSkip = 100;
|
||||||
|
|
||||||
|
FCEUD_UpdatePPUView( -1, 1 );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
//----------------------------------------------------
|
//----------------------------------------------------
|
||||||
|
@ -383,6 +509,8 @@ void ppuPatternView_t::mouseMoveEvent(QMouseEvent *event)
|
||||||
QPoint tile = convPixToTile( event->pos() );
|
QPoint tile = convPixToTile( event->pos() );
|
||||||
|
|
||||||
if ( (tile.x() < 16) && (tile.y() < 16) )
|
if ( (tile.x() < 16) && (tile.y() < 16) )
|
||||||
|
{
|
||||||
|
if ( hover2Focus )
|
||||||
{
|
{
|
||||||
char stmp[64];
|
char stmp[64];
|
||||||
sprintf( stmp, "Tile: $%X%X", tile.y(), tile.x() );
|
sprintf( stmp, "Tile: $%X%X", tile.y(), tile.x() );
|
||||||
|
@ -391,18 +519,23 @@ void ppuPatternView_t::mouseMoveEvent(QMouseEvent *event)
|
||||||
selTile = tile;
|
selTile = tile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
void ppuPatternView_t::mousePressEvent(QMouseEvent * event)
|
void ppuPatternView_t::mousePressEvent(QMouseEvent * event)
|
||||||
{
|
{
|
||||||
//QPoint tile = convPixToTile( event->pos() );
|
QPoint tile = convPixToTile( event->pos() );
|
||||||
|
|
||||||
if ( event->button() == Qt::LeftButton )
|
if ( event->button() == Qt::LeftButton )
|
||||||
{
|
{
|
||||||
// Load Tile Viewport
|
if ( (tile.x() < 16) && (tile.y() < 16) )
|
||||||
PPUViewSkip = 100;
|
{
|
||||||
|
char stmp[64];
|
||||||
|
sprintf( stmp, "Tile: $%X%X", tile.y(), tile.x() );
|
||||||
|
tileLabel->setText( tr(stmp) );
|
||||||
|
|
||||||
FCEUD_UpdatePPUView( -1, 0 );
|
selTile = tile;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//----------------------------------------------------
|
//----------------------------------------------------
|
||||||
|
@ -577,7 +710,7 @@ void ppuPatternView_t::paintEvent(QPaintEvent *event)
|
||||||
//printf("PPU PatternView %ix%i \n", viewWidth, viewHeight );
|
//printf("PPU PatternView %ix%i \n", viewWidth, viewHeight );
|
||||||
|
|
||||||
pen.setWidth( 1 );
|
pen.setWidth( 1 );
|
||||||
pen.setColor( QColor( 128, 128, 128) );
|
pen.setColor( gridColor );
|
||||||
painter.setPen( pen );
|
painter.setPen( pen );
|
||||||
|
|
||||||
w = viewWidth / 128;
|
w = viewWidth / 128;
|
||||||
|
@ -658,6 +791,10 @@ void ppuPatternView_t::paintEvent(QPaintEvent *event)
|
||||||
}
|
}
|
||||||
|
|
||||||
xx = (i*8)*w;
|
xx = (i*8)*w;
|
||||||
|
yy = (j*8)*h;
|
||||||
|
|
||||||
|
pattern->tile[jj][ii].x = xx;
|
||||||
|
pattern->tile[jj][ii].y = yy;
|
||||||
|
|
||||||
for (x=0; x < 8; x++)
|
for (x=0; x < 8; x++)
|
||||||
{
|
{
|
||||||
|
@ -665,8 +802,6 @@ void ppuPatternView_t::paintEvent(QPaintEvent *event)
|
||||||
|
|
||||||
for (y=0; y < 8; y++)
|
for (y=0; y < 8; y++)
|
||||||
{
|
{
|
||||||
pattern->tile[jj][ii].x = xx;
|
|
||||||
pattern->tile[jj][ii].y = yy;
|
|
||||||
painter.fillRect( xx, yy, w, h, pattern->tile[jj][ii].pixel[y][x].color );
|
painter.fillRect( xx, yy, w, h, pattern->tile[jj][ii].pixel[y][x].color );
|
||||||
yy += h;
|
yy += h;
|
||||||
}
|
}
|
||||||
|
@ -691,6 +826,21 @@ void ppuPatternView_t::paintEvent(QPaintEvent *event)
|
||||||
painter.drawLine( 0, yy , x, yy ); yy += (8*h);
|
painter.drawLine( 0, yy , x, yy ); yy += (8*h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xx = pattern->tile[ selTile.y() ][ selTile.x() ].x;
|
||||||
|
yy = pattern->tile[ selTile.y() ][ selTile.x() ].y;
|
||||||
|
|
||||||
|
pen.setWidth( 3 );
|
||||||
|
pen.setColor( QColor( 0, 0, 0) );
|
||||||
|
painter.setPen( pen );
|
||||||
|
|
||||||
|
painter.drawRect( xx, yy, w*8, h*8 );
|
||||||
|
|
||||||
|
pen.setWidth( 1 );
|
||||||
|
pen.setColor( selTileColor );
|
||||||
|
painter.setPen( pen );
|
||||||
|
|
||||||
|
painter.drawRect( xx, yy, w*8, h*8 );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -699,6 +849,10 @@ void ppuPatternView_t::paintEvent(QPaintEvent *event)
|
||||||
for (j=0; j<16; j++) //Rows
|
for (j=0; j<16; j++) //Rows
|
||||||
{
|
{
|
||||||
xx = (i*8)*w;
|
xx = (i*8)*w;
|
||||||
|
yy = (j*8)*h;
|
||||||
|
|
||||||
|
pattern->tile[j][i].x = xx;
|
||||||
|
pattern->tile[j][i].y = yy;
|
||||||
|
|
||||||
for (x=0; x < 8; x++)
|
for (x=0; x < 8; x++)
|
||||||
{
|
{
|
||||||
|
@ -706,8 +860,6 @@ void ppuPatternView_t::paintEvent(QPaintEvent *event)
|
||||||
|
|
||||||
for (y=0; y < 8; y++)
|
for (y=0; y < 8; y++)
|
||||||
{
|
{
|
||||||
pattern->tile[j][i].x = xx;
|
|
||||||
pattern->tile[j][i].y = yy;
|
|
||||||
painter.fillRect( xx, yy, w, h, pattern->tile[j][i].pixel[y][x].color );
|
painter.fillRect( xx, yy, w, h, pattern->tile[j][i].pixel[y][x].color );
|
||||||
yy += h;
|
yy += h;
|
||||||
}
|
}
|
||||||
|
@ -732,6 +884,21 @@ void ppuPatternView_t::paintEvent(QPaintEvent *event)
|
||||||
painter.drawLine( 0, yy , x, yy ); yy += (8*h);
|
painter.drawLine( 0, yy , x, yy ); yy += (8*h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xx = pattern->tile[ selTile.y() ][ selTile.x() ].x;
|
||||||
|
yy = pattern->tile[ selTile.y() ][ selTile.x() ].y;
|
||||||
|
|
||||||
|
pen.setWidth( 3 );
|
||||||
|
pen.setColor( QColor( 0, 0, 0) );
|
||||||
|
painter.setPen( pen );
|
||||||
|
|
||||||
|
painter.drawRect( xx, yy, w*8, h*8 );
|
||||||
|
|
||||||
|
pen.setWidth( 1 );
|
||||||
|
pen.setColor( selTileColor );
|
||||||
|
painter.setPen( pen );
|
||||||
|
|
||||||
|
painter.drawRect( xx, yy, w*8, h*8 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//----------------------------------------------------
|
//----------------------------------------------------
|
||||||
|
|
|
@ -50,6 +50,8 @@ class ppuPatternView_t : public QWidget
|
||||||
void setPattern( ppuPatternTable_t *p );
|
void setPattern( ppuPatternTable_t *p );
|
||||||
void setTileLabel( QLabel *l );
|
void setTileLabel( QLabel *l );
|
||||||
QPoint convPixToTile( QPoint p );
|
QPoint convPixToTile( QPoint p );
|
||||||
|
|
||||||
|
bool getDrawTileGrid(void){ return drawTileGrid; };
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *event);
|
void paintEvent(QPaintEvent *event);
|
||||||
void resizeEvent(QResizeEvent *event);
|
void resizeEvent(QResizeEvent *event);
|
||||||
|
@ -58,14 +60,23 @@ class ppuPatternView_t : public QWidget
|
||||||
void mousePressEvent(QMouseEvent * event);
|
void mousePressEvent(QMouseEvent * event);
|
||||||
void contextMenuEvent(QContextMenuEvent *event);
|
void contextMenuEvent(QContextMenuEvent *event);
|
||||||
|
|
||||||
|
void openColorPicker( QColor *c );
|
||||||
|
|
||||||
int patternIndex;
|
int patternIndex;
|
||||||
int viewWidth;
|
int viewWidth;
|
||||||
int viewHeight;
|
int viewHeight;
|
||||||
int mode;
|
int mode;
|
||||||
bool drawTileGrid;
|
bool drawTileGrid;
|
||||||
|
bool hover2Focus;
|
||||||
QLabel *tileLabel;
|
QLabel *tileLabel;
|
||||||
QPoint selTile;
|
QPoint selTile;
|
||||||
|
QColor selTileColor;
|
||||||
|
QColor gridColor;
|
||||||
ppuPatternTable_t *pattern;
|
ppuPatternTable_t *pattern;
|
||||||
|
public slots:
|
||||||
|
void toggleTileGridLines(void);
|
||||||
|
void setTileSelectorColor(void);
|
||||||
|
void setTileGridColor(void);
|
||||||
private slots:
|
private slots:
|
||||||
void showTileMode(void);
|
void showTileMode(void);
|
||||||
void exitTileMode(void);
|
void exitTileMode(void);
|
||||||
|
@ -80,7 +91,6 @@ class ppuPatternView_t : public QWidget
|
||||||
void selPalette8(void);
|
void selPalette8(void);
|
||||||
void openTileEditor(void);
|
void openTileEditor(void);
|
||||||
void cycleNextPalette(void);
|
void cycleNextPalette(void);
|
||||||
void toggleTileGridLines(void);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class ppuPalatteView_t : public QWidget
|
class ppuPalatteView_t : public QWidget
|
||||||
|
|
Loading…
Reference in New Issue