Added a context menu to the Qt nametable viewer.

This commit is contained in:
mjbudd77 2021-01-31 13:50:39 -05:00
parent 27e94f0fad
commit 1958daf6cb
4 changed files with 126 additions and 14 deletions

View File

@ -38,12 +38,15 @@
#include "../../debug.h"
#include "../../palette.h"
#include "Qt/ConsoleWindow.h"
#include "Qt/ConsoleUtilities.h"
#include "Qt/NameTableViewer.h"
#include "Qt/HexEditor.h"
#include "Qt/main.h"
#include "Qt/dface.h"
#include "Qt/input.h"
#include "Qt/config.h"
#include "Qt/ppuViewer.h"
#include "Qt/fceuWrapper.h"
static ppuNameTableViewerDialog_t *nameTableViewWindow = NULL;
@ -856,6 +859,10 @@ ppuNameTableView_t::ppuNameTableView_t(QWidget *parent)
selTable = 0;
scrollArea = NULL;
hover2Focus = false;
ppuAddr = 0x2000;
palAddr = 0x3F00;
atrbAddr = 0x3F00;
tileAddr = 0x0000;
tileSelColor.setRgb(255,255,255);
tileGridColor.setRgb(255, 0, 0);
@ -1009,19 +1016,23 @@ int ppuNameTableView_t::calcTableTileAddr( int NameTable, int TileX, int TileY
//----------------------------------------------------
void ppuNameTableView_t::computeNameTableProperties( int NameTable, int TileX, int TileY )
{
int TileID, PPUAddress, AttAddress, Attrib, palAddr;
int TileID, PPUAddress, AttAddress, Attrib;
if ( vnapage[0] == NULL )
{
return;
}
PPUAddress = 0x2000+(NameTable*0x400)+((TileY%30)*32)+(TileX%32);
ppuAddr = PPUAddress = 0x2000+(NameTable*0x400)+((TileY%30)*32)+(TileX%32);
TileID = vnapage[(PPUAddress>>10)&0x3][PPUAddress&0x3FF];
AttAddress = 0x23C0 | (PPUAddress & 0x0C00) | ((PPUAddress >> 4) & 0x38) | ((PPUAddress >> 2) & 0x07);
tileAddr = TileID << 4;
atrbAddr = AttAddress = 0x23C0 | (PPUAddress & 0x0C00) | ((PPUAddress >> 4) & 0x38) | ((PPUAddress >> 2) & 0x07);
Attrib = vnapage[(AttAddress>>10)&0x3][AttAddress&0x3FF];
//Attrib = (Attrib >> ((PPUAddress&2) | ((PPUAddress&64)>>4))) & 0x3;
//palAddr = 0x3F00 + ( FCEUPPU_GetAttr( NameTable, TileX, TileY ) * 4 );
@ -1203,6 +1214,71 @@ void ppuNameTableView_t::mousePressEvent(QMouseEvent * event)
redrawtables = true;
}
//----------------------------------------------------
void ppuNameTableView_t::contextMenuEvent(QContextMenuEvent *event)
{
QAction *act;
QMenu menu(this);
QMenu *subMenu;
//QActionGroup *group;
char stmp[64];
int tIdx, tx, ty;
convertXY2TableTile( event->pos().x(), event->pos().y(), &tIdx, &tx, &ty );
selTable = tIdx;
selTile.setX( tx );
selTile.setY( ty );
redrawtables = true;
sprintf( stmp, "Open Tile %X%X in PPU Viewer", selTile.x(), selTile.y() );
act = new QAction(tr(stmp), &menu);
act->setShortcut( QKeySequence(tr("V")));
connect( act, SIGNAL(triggered(void)), this, SLOT(openTilePpuViewer(void)) );
menu.addAction( act );
sprintf( stmp, "Open Tile Addr $%04X in Hex Editor", tileAddr );
act = new QAction(tr(stmp), &menu);
//act->setShortcut( QKeySequence(tr("H")));
connect( act, SIGNAL(triggered(void)), this, SLOT(openTileAddrHexEdit(void)) );
menu.addAction( act );
sprintf( stmp, "Open Attr Addr $%04X in Hex Editor", atrbAddr );
act = new QAction(tr(stmp), &menu);
//act->setShortcut( QKeySequence(tr("H")));
connect( act, SIGNAL(triggered(void)), this, SLOT(openAtrbAddrHexEdit(void)) );
menu.addAction( act );
sprintf( stmp, "Open PPU Addr $%04X in Hex Editor", ppuAddr );
act = new QAction(tr(stmp), &menu);
//act->setShortcut( QKeySequence(tr("H")));
connect( act, SIGNAL(triggered(void)), this, SLOT(openPpuAddrHexEdit(void)) );
menu.addAction( act );
menu.exec(event->globalPos());
}
//----------------------------------------------------
void ppuNameTableView_t::openTilePpuViewer(void)
{
openPPUViewWindow( consoleWindow );
}
//----------------------------------------------------
void ppuNameTableView_t::openTileAddrHexEdit(void)
{
hexEditorOpenFromDebugger( QHexEdit::MODE_NES_PPU, tileAddr );
}
//----------------------------------------------------
void ppuNameTableView_t::openAtrbAddrHexEdit(void)
{
hexEditorOpenFromDebugger( QHexEdit::MODE_NES_PPU, atrbAddr );
}
//----------------------------------------------------
void ppuNameTableView_t::openPpuAddrHexEdit(void)
{
hexEditorOpenFromDebugger( QHexEdit::MODE_NES_PPU, ppuAddr );
}
//----------------------------------------------------
void ppuNameTableView_t::paintEvent(QPaintEvent *event)
{
ppuNameTable_t *nt;
@ -1383,6 +1459,8 @@ inline void DrawChr( ppuNameTableTile_t *tile, const uint8_t *chr, int pal)
uint8 chr0, chr1;
//uint8 *table = &VPage[0][0]; //use the background table
//pbitmap += 3*
//
tile->pal = pal;
for (y = 0; y < 8; y++) { //todo: use index for y?
chr0 = chr[index];
@ -1471,6 +1549,8 @@ static void DrawNameTable(int scanline, int ntnum, bool invalidateCache)
const uint8* chrp = FCEUPPU_GetCHR(ptable+chr,refreshaddr);
if (attview) chrp = ATTRIBUTE_VIEW_TILE;
nameTable[ntnum].tile[y][x].pTbl = ptable;
//a good way to do it:
DrawChr( &nameTable[ntnum].tile[y][x], chrp, a);

View File

@ -30,6 +30,15 @@ struct ppuNameTableTile_t
int x;
int y;
int pTbl;
int pal;
ppuNameTableTile_t(void)
{
x = y = 0;
pTbl = 0;
pal = 0;
}
};
struct ppuNameTable_t
@ -40,6 +49,12 @@ struct ppuNameTable_t
int y;
int w;
int h;
ppuNameTable_t(void)
{
x = y = 0;
w = h = 8;
}
};
class ppuNameTableViewerDialog_t;
@ -71,6 +86,7 @@ class ppuNameTableView_t : public QWidget
void keyPressEvent(QKeyEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent * event);
void contextMenuEvent(QContextMenuEvent *event);
void computeNameTableProperties( int NameTable, int TileX, int TileY );
int convertXY2TableTile( int x, int y, int *tableIdxOut, int *tileXout, int *tileYout );
int calcTableTileAddr( int table, int tileX, int tileY );
@ -79,6 +95,10 @@ class ppuNameTableView_t : public QWidget
int viewWidth;
int viewHeight;
int viewScale;
int ppuAddr;
int atrbAddr;
int tileAddr;
int palAddr;
int selTable;
QPoint selTile;
QPoint selTileLoc;
@ -87,6 +107,11 @@ class ppuNameTableView_t : public QWidget
bool ensureVis;
bool hover2Focus;
private slots:
void openTilePpuViewer(void);
void openPpuAddrHexEdit(void);
void openTileAddrHexEdit(void);
void openAtrbAddrHexEdit(void);
};
class ppuNameTableTileView_t : public QWidget

View File

@ -99,7 +99,7 @@ ppuViewerDialog_t::ppuViewerDialog_t(QWidget *parent)
ppuViewWindow = this;
setWindowTitle( tr("PPU Viewer") );
setWindowTitle( tr("PPU Viewer") );
mainLayout = new QVBoxLayout();
@ -191,11 +191,14 @@ ppuViewerDialog_t::ppuViewerDialog_t(QWidget *parent)
connect( refreshSlider, SIGNAL(valueChanged(int)), this, SLOT(refreshSliderChanged(int)));
cycleCount = 0;
PPUViewSkip = 100;
FCEUD_UpdatePPUView( -1, 1 );
updateTimer = new QTimer( this );
connect( updateTimer, &QTimer::timeout, this, &ppuViewerDialog_t::periodicUpdate );
connect( updateTimer, &QTimer::timeout, this, &ppuViewerDialog_t::periodicUpdate );
updateTimer->start( 33 ); // 30hz
}
@ -226,7 +229,9 @@ void ppuViewerDialog_t::closeWindow(void)
//----------------------------------------------------
void ppuViewerDialog_t::periodicUpdate(void)
{
if ( redrawWindow )
cycleCount = (cycleCount + 1) % 30;
if ( redrawWindow || (cycleCount == 0) )
{
this->update();
redrawWindow = false;
@ -382,7 +387,7 @@ void ppuPatternView_t::mouseMoveEvent(QMouseEvent *event)
sprintf( stmp, "Tile: $%X%X", tile.y(), tile.x() );
tileLabel->setText( tr(stmp) );
selTile = tile;
selTile = tile;
}
}
}
@ -495,7 +500,7 @@ void ppuPatternView_t::exitTileMode(void)
//----------------------------------------------------
void ppuPatternView_t::openTileEditor(void)
{
ppuTileEditor_t *tileEditor;
ppuTileEditor_t *tileEditor;
tileEditor = new ppuTileEditor_t( patternIndex, this );
@ -506,7 +511,7 @@ void ppuPatternView_t::openTileEditor(void)
//----------------------------------------------------
void ppuPatternView_t::cycleNextPalette(void)
{
pindex[ patternIndex ] = (pindex[ patternIndex ] + 1) % 9;
pindex[ patternIndex ] = (pindex[ patternIndex ] + 1) % 9;
PPUViewSkip = 100;

View File

@ -218,8 +218,8 @@ class ppuTileEditor_t : public QDialog
int palIdx;
int tileAddr;
public slots:
void closeWindow(void);
public slots:
void closeWindow(void);
private slots:
void periodicUpdate(void);
void paletteChanged(int index);
@ -239,7 +239,7 @@ class ppuViewerDialog_t : public QDialog
ppuPatternView_t *patternView[2];
ppuPalatteView_t *paletteView;
void closeEvent(QCloseEvent *bar);
void closeEvent(QCloseEvent *bar);
private:
QGroupBox *patternFrame[2];
@ -252,8 +252,10 @@ class ppuViewerDialog_t : public QDialog
QLineEdit *scanLineEdit;
QTimer *updateTimer;
public slots:
void closeWindow(void);
int cycleCount;
public slots:
void closeWindow(void);
private slots:
void periodicUpdate(void);
void sprite8x16Changed0(int state);