From d2193d3e8388cd66a5debf7f6df003c7ee45af5a Mon Sep 17 00:00:00 2001 From: mjbudd77 Date: Wed, 10 Nov 2021 21:07:18 -0500 Subject: [PATCH] Qt TAS editor key logic in work. --- src/drivers/Qt/TasEditor/TasEditorWindow.cpp | 78 ++++++++++++++++++-- src/drivers/Qt/TasEditor/TasEditorWindow.h | 6 ++ src/drivers/Qt/fceuWrapper.h | 15 ++++ 3 files changed, 91 insertions(+), 8 deletions(-) diff --git a/src/drivers/Qt/TasEditor/TasEditorWindow.cpp b/src/drivers/Qt/TasEditor/TasEditorWindow.cpp index a3573d13..027f11c1 100644 --- a/src/drivers/Qt/TasEditor/TasEditorWindow.cpp +++ b/src/drivers/Qt/TasEditor/TasEditorWindow.cpp @@ -41,6 +41,7 @@ #include "driver.h" #include "Qt/config.h" +#include "Qt/keyscan.h" #include "Qt/throttle.h" #include "Qt/fceuWrapper.h" #include "Qt/ConsoleUtilities.h" @@ -951,15 +952,22 @@ void TasEditorWindow::buildPianoRollDisplay(void) QHBoxLayout *hbox; QGridLayout *grid; + pianoRollFrame = new QFrame(); grid = new QGridLayout(); pianoRoll = new QPianoRoll(this); pianoRollVBar = new QScrollBar( Qt::Vertical, this ); pianoRollHBar = new QScrollBar( Qt::Horizontal, this ); upperMarkerLabel = new QLabel( tr("Marker 0") ); - lowerMarkerLabel = new QLabel( tr("Marker 1") ); + lowerMarkerLabel = new QLabel( tr("Marker 0") ); upperMarkerNote = new QLineEdit(); lowerMarkerNote = new QLineEdit(); + pianoRollFrame->setLineWidth(2); + pianoRollFrame->setMidLineWidth(1); + //pianoRollFrame->setFrameShape( QFrame::StyledPanel ); + pianoRollFrame->setFrameShape( QFrame::Box ); + + pianoRollVBar->setInvertedAppearance(true); pianoRoll->setScrollBars( pianoRollHBar, pianoRollVBar ); connect( pianoRollHBar, SIGNAL(valueChanged(int)), pianoRoll, SLOT(hbarChanged(int)) ); connect( pianoRollVBar, SIGNAL(valueChanged(int)), pianoRoll, SLOT(vbarChanged(int)) ); @@ -980,7 +988,9 @@ void TasEditorWindow::buildPianoRollDisplay(void) hbox->addWidget( upperMarkerNote, 10 ); vbox->addLayout( hbox, 1 ); - vbox->addLayout( grid, 100 ); + vbox->addWidget( pianoRollFrame, 100 ); + //vbox->addLayout( grid, 100 ); + pianoRollFrame->setLayout( grid ); hbox = new QHBoxLayout(); hbox->addWidget( lowerMarkerLabel, 1 ); @@ -2159,7 +2169,7 @@ void QPianoRoll::hbarChanged(int val) //---------------------------------------------------------------------------- void QPianoRoll::vbarChanged(int val) { - lineOffset = val; + lineOffset = maxLineOffset - val; if ( lineOffset < 0 ) { @@ -2311,6 +2321,8 @@ void QPianoRoll::ensureTheLineIsVisible( int lineNum ) { lineOffset = 0; } + vbar->setValue( lineOffset ); + update(); } } @@ -2324,14 +2336,20 @@ void QPianoRoll::resizeEvent(QResizeEvent *event) viewLines = (viewHeight / pxLineSpacing) + 1; - maxLineOffset = currMovieData.records.size() - viewLines + 1; + maxLineOffset = currMovieData.records.size() - viewLines + 5; if ( maxLineOffset < 0 ) { + vbar->hide(); maxLineOffset = 0; } + else + { + vbar->show(); + } vbar->setMinimum(0); vbar->setMaximum(maxLineOffset); + vbar->setPageStep( (3*viewLines)/4 ); if ( viewWidth >= pxLineWidth ) { @@ -2345,11 +2363,12 @@ void QPianoRoll::resizeEvent(QResizeEvent *event) hbar->show(); pxLineXScroll = hbar->value(); } - vbar->setPageStep( (3*viewLines)/4 ); + } //---------------------------------------------------------------------------- void QPianoRoll::mousePressEvent(QMouseEvent * event) { + fceuCriticalSection emuLock; int col, line, row_index, column_index, kbModifiers, alt_pressed; QPoint c = convPixToCursor( event->pos() ); @@ -2506,6 +2525,7 @@ void QPianoRoll::mousePressEvent(QMouseEvent * event) //---------------------------------------------------------------------------- void QPianoRoll::mouseReleaseEvent(QMouseEvent * event) { + fceuCriticalSection emuLock; int col, line; QPoint c = convPixToCursor( event->pos() ); @@ -2532,6 +2552,7 @@ void QPianoRoll::mouseReleaseEvent(QMouseEvent * event) //---------------------------------------------------------------------------- void QPianoRoll::mouseMoveEvent(QMouseEvent * event) { + fceuCriticalSection emuLock; int col, line; QPoint c = convPixToCursor( event->pos() ); @@ -2544,7 +2565,7 @@ void QPianoRoll::mouseMoveEvent(QMouseEvent * event) rowUnderMouse = realRowUnderMouse = line; columnUnderMouse = col; - printf("Mouse Move Event: 0x%x (%i,%i) Col:%i\n", event->button(), c.x(), c.y(), col ); + //printf("Mouse Move Event: 0x%x (%i,%i) Col:%i\n", event->button(), c.x(), c.y(), col ); if ( event->button() == Qt::LeftButton ) { @@ -2553,6 +2574,40 @@ void QPianoRoll::mouseMoveEvent(QMouseEvent * event) updateDrag(); } //---------------------------------------------------------------------------- +void QPianoRoll::keyPressEvent(QKeyEvent *event) +{ + //printf("Key Press: 0x%x \n", event->key() ); + pushKeyEvent( event, 1 ); + + event->accept(); +} + +void QPianoRoll::keyReleaseEvent(QKeyEvent *event) +{ + //printf("Key Release: 0x%x \n", event->key() ); + pushKeyEvent( event, 0 ); + + event->accept(); +} +//---------------------------------------------------------------------------- +void QPianoRoll::focusInEvent(QFocusEvent *event) +{ + QWidget::focusInEvent(event); + + printf("PianoRoll Focus In\n"); + + parent->pianoRollFrame->setStyleSheet("QFrame { border: 2px solid rgb(48,140,198); }"); +} +//---------------------------------------------------------------------------- +void QPianoRoll::focusOutEvent(QFocusEvent *event) +{ + QWidget::focusOutEvent(event); + + printf("PianoRoll Focus Out\n"); + + parent->pianoRollFrame->setStyleSheet(NULL); +} +//---------------------------------------------------------------------------- void QPianoRoll::updateDrag(void) { int kbModifiers, altHeld; @@ -3033,7 +3088,7 @@ void QPianoRoll::paintEvent(QPaintEvent *event) { int x, y, row, nrow, lineNum; QPainter painter(this); - QColor white("white"), black("black"), blkColor; + QColor white(255,255,255), black(0,0,0), blkColor; static const char *buttonNames[] = { "A", "B", "S", "T", "U", "D", "L", "R", NULL }; char stmp[32]; char rowIsSel=0; @@ -3048,12 +3103,19 @@ void QPianoRoll::paintEvent(QPaintEvent *event) viewLines = nrow; - maxLineOffset = currMovieData.records.size() - nrow + 1; + maxLineOffset = currMovieData.records.size() - nrow + 5; if ( maxLineOffset < 0 ) { + vbar->hide(); maxLineOffset = 0; } + else + { + vbar->show(); + } + + lineOffset = maxLineOffset - vbar->value(); if ( lineOffset < 0 ) { diff --git a/src/drivers/Qt/TasEditor/TasEditorWindow.h b/src/drivers/Qt/TasEditor/TasEditorWindow.h index d5e93b73..cb50bf53 100644 --- a/src/drivers/Qt/TasEditor/TasEditorWindow.h +++ b/src/drivers/Qt/TasEditor/TasEditorWindow.h @@ -88,6 +88,10 @@ class QPianoRoll : public QWidget void mousePressEvent(QMouseEvent * event); void mouseReleaseEvent(QMouseEvent * event); void mouseMoveEvent(QMouseEvent * event); + void keyPressEvent(QKeyEvent *event); + void keyReleaseEvent(QKeyEvent *event); + void focusInEvent(QFocusEvent *event); + void focusOutEvent(QFocusEvent *event); void startDraggingPlaybackCursor(void); void startDraggingMarker(int mouseX, int mouseY, int rowIndex, int columnIndex); @@ -208,6 +212,7 @@ class TasEditorWindow : public QDialog QAction *showToolTipsAct; QSplitter *mainHBox; + QFrame *pianoRollFrame; QWidget *pianoRollContainerWidget; QWidget *controlPanelContainerWidget; QScrollBar *pianoRollHBar; @@ -316,6 +321,7 @@ class TasEditorWindow : public QDialog friend class SELECTION; friend class PLAYBACK; friend class HISTORY; + friend class QPianoRoll; }; extern TASEDITOR_PROJECT *project; diff --git a/src/drivers/Qt/fceuWrapper.h b/src/drivers/Qt/fceuWrapper.h index 48e35ddd..198d6563 100644 --- a/src/drivers/Qt/fceuWrapper.h +++ b/src/drivers/Qt/fceuWrapper.h @@ -43,3 +43,18 @@ int fceuWrapperTogglePause(void); bool fceuWrapperGameLoaded(void); void fceuWrapperRequestAppExit(void); +class fceuCriticalSection +{ + public: + fceuCriticalSection(void) + { + //printf("Wrapper Lock\n"); + fceuWrapperLock(); + } + + ~fceuCriticalSection(void) + { + //printf("Wrapper UnLock\n"); + fceuWrapperUnLock(); + } +};