Skip to content

Commit

Permalink
work on isf editor
Browse files Browse the repository at this point in the history
partially worked around the mac qt bug that was causing GL widgets to break event handling/pop-up buttons :: cleaned up some logs :: fixed a bug that would unload the tmp isf doc if you started saving it, but cancelled
  • Loading branch information
mrRay committed Jun 26, 2019
1 parent 0c4b14d commit 6294466
Show file tree
Hide file tree
Showing 20 changed files with 336 additions and 81 deletions.
107 changes: 58 additions & 49 deletions examples/Qt/ISFEditor/ISFEditor_app/DocWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ DocWindow::~DocWindow() {


void DocWindow::updateContentsFromISFController() {
qDebug() << __PRETTY_FUNCTION__;
//qDebug() << __PRETTY_FUNCTION__;

//ISFSceneRef scene = GetISFController()->getScene();
//ISFDocRef doc = (scene==nullptr) ? nullptr : scene->doc();
Expand Down Expand Up @@ -413,48 +413,57 @@ void DocWindow::saveOpenFile() {
lw->getBaseDirectory(),
tr("Text (*.fs)"));
}
//qDebug() << "\tdestPath is " << pathToSave;
QFileInfo saveFileInfo(pathToSave);
QString noExtPathToSave = QString("%1/%2").arg(saveFileInfo.dir().absolutePath()).arg(saveFileInfo.completeBaseName());
//qDebug() << "\tnoExtPathToSave is " << noExtPathToSave;


if (fragContentsChanged) {
QString localWritePath = QString("%1.fs").arg(noExtPathToSave);
qDebug() << "\tsaving frag to file " << localWritePath;
VVDELETE(_fragFilePath);
_fragFilePath = new QString(localWritePath);
VVDELETE(_fragFilePathContentsOnOpen)
_fragFilePathContentsOnOpen = new QString(currentFragString);
qDebug() << "\tpathToSave is " << pathToSave;
if (pathToSave.length() < 1) {
//qDebug() << "\tinvalid path, don't save!";
}
else {
QFileInfo saveFileInfo(pathToSave);
QString noExtPathToSave = QString("%1/%2").arg(saveFileInfo.dir().absolutePath()).arg(saveFileInfo.completeBaseName());
qDebug() << "\tnoExtPathToSave is " << noExtPathToSave;

QFile wFile(localWritePath);
if (wFile.open(QIODevice::WriteOnly)) {
QTextStream wStream(&wFile);
wStream << currentFragString;
wFile.close();
if (fragContentsChanged) {
QString localWritePath = QString("%1.fs").arg(noExtPathToSave);
qDebug() << "\tsaving frag to file " << localWritePath;
VVDELETE(_fragFilePath);
_fragFilePath = new QString(localWritePath);
VVDELETE(_fragFilePathContentsOnOpen)
_fragFilePathContentsOnOpen = new QString(currentFragString);

QFile wFile(localWritePath);
if (wFile.open(QIODevice::WriteOnly)) {
QTextStream wStream(&wFile);
wStream << currentFragString;
wFile.close();
_fragEditsPerformed = false;
}
}
}
if (vertContentsChanged) {
QString localWritePath = QString("%1.vs").arg(noExtPathToSave);
qDebug() << "\tsaving vert to file " << localWritePath;
VVDELETE(_vertFilePath);
_vertFilePath = new QString(localWritePath);
VVDELETE(_vertFilePathContentsOnOpen)
_vertFilePathContentsOnOpen = new QString(currentVertString);
if (vertContentsChanged) {
QString localWritePath = QString("%1.vs").arg(noExtPathToSave);
qDebug() << "\tsaving vert to file " << localWritePath;
VVDELETE(_vertFilePath);
_vertFilePath = new QString(localWritePath);
VVDELETE(_vertFilePathContentsOnOpen)
_vertFilePathContentsOnOpen = new QString(currentVertString);

QFile wFile(localWritePath);
if (wFile.open(QIODevice::WriteOnly)) {
QTextStream wStream(&wFile);
wStream << currentVertString;
wFile.close();
QFile wFile(localWritePath);
if (wFile.open(QIODevice::WriteOnly)) {
QTextStream wStream(&wFile);
wStream << currentVertString;
wFile.close();
_vertEditsPerformed = false;
}
}
}

if (fragContentsChanged || vertContentsChanged) {
if (lw != nullptr)
lw->on_loadFile(pathToSave);
if (fragContentsChanged || vertContentsChanged) {
if (lw != nullptr)
lw->on_loadFile(pathToSave);
}
}




}
// else the file path is non-nil and not in tmp, so just save it to disk
else {
Expand Down Expand Up @@ -655,7 +664,7 @@ void DocWindow::reloadColorsAndSyntaxFormats() {


void DocWindow::on_actionNew_triggered() {
qDebug() << __PRETTY_FUNCTION__;
//qDebug() << __PRETTY_FUNCTION__;
LoadingWindow *lw = GetLoadingWindow();
if (lw != nullptr)
lw->on_createNewFile();
Expand All @@ -665,11 +674,11 @@ void DocWindow::on_actionSave_triggered() {
saveOpenFile();
}
void DocWindow::on_actionImport_from_GLSLSandbox_triggered() {
qDebug() << __PRETTY_FUNCTION__;
//qDebug() << __PRETTY_FUNCTION__;

GLSLSandboxConverter *conv = new GLSLSandboxConverter(GetLoadingWindow());
int returnCode = conv->exec();
qDebug() << "returnCode is " << returnCode;
//qDebug() << "returnCode is " << returnCode;
if (!returnCode) {
LoadingWindow *lw = GetLoadingWindow();
if (lw != nullptr) {
Expand All @@ -679,11 +688,11 @@ void DocWindow::on_actionImport_from_GLSLSandbox_triggered() {
delete conv;
}
void DocWindow::on_actionImport_from_Shadertoy_triggered() {
qDebug() << __PRETTY_FUNCTION__;
//qDebug() << __PRETTY_FUNCTION__;

ShadertoyConverter *conv = new ShadertoyConverter(GetLoadingWindow());
int returnCode = conv->exec();
qDebug() << "returnCode is " << returnCode;
//qDebug() << "returnCode is " << returnCode;
if (!returnCode) {
LoadingWindow *lw = GetLoadingWindow();
if (lw != nullptr) {
Expand All @@ -693,14 +702,14 @@ void DocWindow::on_actionImport_from_Shadertoy_triggered() {
delete conv;
}
void DocWindow::on_actionPreferences_triggered() {
qDebug() << __PRETTY_FUNCTION__;
//qDebug() << __PRETTY_FUNCTION__;
Preferences *p = GetPreferences();
if (p != nullptr) {
p->show();
}
}
void DocWindow::on_actionQuit_triggered() {
qDebug() << __PRETTY_FUNCTION__;
//qDebug() << __PRETTY_FUNCTION__;
QCoreApplication::quit();
}

Expand Down Expand Up @@ -744,7 +753,7 @@ void DocWindow::on_actionUse_selection_for_next_Find_triggered() {


void DocWindow::on_actionCheck_for_Updates_triggered() {
qDebug() << __PRETTY_FUNCTION__;
//qDebug() << __PRETTY_FUNCTION__;
AutoUpdater *aa = GetGlobalAutoUpdater();
if (aa != nullptr) {
aa->checkForUpdates();
Expand All @@ -754,14 +763,14 @@ void DocWindow::on_actionCheck_for_Updates_triggered() {
}
}
void DocWindow::on_actionAbout_triggered() {
qDebug() << __PRETTY_FUNCTION__;
//qDebug() << __PRETTY_FUNCTION__;
AboutWindow *aw = GetAboutWindow();
if (aw != nullptr) {
aw->show();
}
}
void DocWindow::on_actionGet_Help_triggered() {
qDebug() << __PRETTY_FUNCTION__;
//qDebug() << __PRETTY_FUNCTION__;
ReportProblemDialog *rpd = GetReportProblemDialog();
if (rpd != nullptr) {
rpd->show();
Expand All @@ -785,7 +794,7 @@ void DocWindow::closeEvent(QCloseEvent * event) {
QCoreApplication::quit();
}
void DocWindow::showEvent(QShowEvent * event) {
qDebug() << __PRETTY_FUNCTION__;
//qDebug() << __PRETTY_FUNCTION__;

//Q_UNUSED(event);
QWidget::showEvent(event);
Expand Down Expand Up @@ -855,7 +864,7 @@ void DocWindow::showEvent(QShowEvent * event) {

}
void DocWindow::appQuitEvent() {
qDebug() << __PRETTY_FUNCTION__;
//qDebug() << __PRETTY_FUNCTION__;

QSettings settings;
settings.setValue("DocWindowGeometry", saveGeometry());
Expand Down Expand Up @@ -884,7 +893,7 @@ SimpleSourceCodeEditor * DocWindow::focusedSourceCodeEditor() {
return focusedEd;
}
void DocWindow::tmpSaveTimerSlot() {
qDebug() << __PRETTY_FUNCTION__;
//qDebug() << __PRETTY_FUNCTION__;

QString currentFragString = ui->fragShaderEditor->toPlainText();
QString currentVertString = ui->vertShaderEditor->toPlainText();
Expand Down
11 changes: 6 additions & 5 deletions examples/Qt/ISFEditor/ISFEditor_app/ISFController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void ISFController::aboutToQuit() {
std::lock_guard<std::recursive_mutex> tmpLock(sceneLock);
}
void ISFController::loadFile(const QString & inPathToLoad) {
qDebug() << __PRETTY_FUNCTION__ << "... " << inPathToLoad;
//qDebug() << __PRETTY_FUNCTION__ << "... " << inPathToLoad;

if (GetGlobalBufferPool() == nullptr) {
qDebug() << "\terr: no global buffer pool, " << __PRETTY_FUNCTION__;
Expand Down Expand Up @@ -474,23 +474,23 @@ void ISFController::threadedRenderCallback() {
sceneCtx = scene->context();

if (needToLoadFiles) {
qDebug() << "need to load, moving ctx to main thread...";
//qDebug() << "need to load, moving ctx to main thread...";
//renderThreadCtx->moveToThread(qApp->thread());
sceneCtx->moveToThread(qApp->thread());
needToLoadFiles = false;
loadingFiles = true;
return;
}
if (loadingFiles) {
qDebug() << "loading files- killing time, waiting for main thread...";
//qDebug() << "loading files- killing time, waiting for main thread...";
return;
}

// if the render thread context isn't this thread, bail immediately- we're probably loading files on the main thread
//if (renderThreadCtx==nullptr || renderThreadCtx->contextThread()!=QThread::currentThread())
if (sceneCtx==nullptr || sceneCtx->contextThread()!=QThread::currentThread())
{
cout << "no render ctx or ctx isnt attached to current thread, bailing, " << __PRETTY_FUNCTION__ << endl;
//cout << "no render ctx or ctx isnt attached to current thread, bailing, " << __PRETTY_FUNCTION__ << endl;
return;
}

Expand Down Expand Up @@ -598,7 +598,7 @@ void ISFController::threadedRenderCallback() {
}

void ISFController::populateLoadingWindowUI() {
//qDebug() << __PRETTY_FUNCTION__;
qDebug() << __PRETTY_FUNCTION__;

if (qApp->thread() != QThread::currentThread()) qDebug() << "ERR: thread is not main! " << __PRETTY_FUNCTION__;

Expand Down Expand Up @@ -645,6 +645,7 @@ void ISFController::populateLoadingWindowUI() {
return;

// run through the scene's inputs- we want to make a UI item for each...
qDebug() << "loading UI for scene at " << scene->doc()->path().c_str();
vector<ISFAttrRef> sceneInputs = scene->inputs();
for (auto it=sceneInputs.begin(); it!=sceneInputs.end(); ++it) {
ISFAttrRef attrib = *it;
Expand Down
4 changes: 3 additions & 1 deletion examples/Qt/ISFEditor/ISFEditor_app/ISFEditor_app.pro
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ SOURCES += \
../../common/GLBufferQVideoSurface.cpp \
../../common/GLBufferQWidget.cpp \
../../common/ISFGLBufferQWidget.cpp \
../../common/DisplayLinkDriver.mm \
DocWindow.cpp \
misc_classes/FileLoadEventFilter.cpp \
ISFController.cpp \
Expand Down Expand Up @@ -125,6 +126,7 @@ HEADERS += \
../../common/GLBufferQVideoSurface.h \
../../common/GLBufferQWidget.h \
../../common/ISFGLBufferQWidget.h \
../../common/DisplayLinkDriver.h \
DocWindow.h \
misc_classes/FileLoadEventFilter.h \
ISFController.h \
Expand Down Expand Up @@ -285,7 +287,7 @@ win32 {
QT += winextras
LIBS += -lAdvapi32 -lOle32 -lShell32
} else:mac {
LIBS += -framework Security
LIBS += -framework Security -framework CoreVideo
} else:unix {
LIBS += -lutil
}
Expand Down
12 changes: 6 additions & 6 deletions examples/Qt/ISFEditor/ISFEditor_app/LoadingWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ QScrollArea * LoadingWindow::getScrollArea() {
QSpinBox * LoadingWindow::getWidthSB() { return ui->renderResWidthWidget; }
QSpinBox * LoadingWindow::getHeightSB() { return ui->renderResHeightWidget; }
void LoadingWindow::on_createNewFile() {
qDebug() << __PRETTY_FUNCTION__;
//qDebug() << __PRETTY_FUNCTION__;

//QThread *mainThread = QApplication::instance()->thread();
//qDebug() << "main thread is currently " << mainThread;
Expand All @@ -95,7 +95,7 @@ void LoadingWindow::on_createNewFile() {
QFile tmpFragShaderFile( QString("%1/ISFTesterTmpFile.fs").arg(QDir::tempPath()) );
if (tmpFragShaderFile.open(QIODevice::WriteOnly)) {
tmpFilePath = tmpFragShaderFile.fileName();
qDebug() << "\ttmpFragShaderFile's path is " << tmpFilePath;
//qDebug() << "\ttmpFragShaderFile's path is " << tmpFilePath;

QFile newFileTemplate(":/resources/NewFileTemplate.txt");
if (newFileTemplate.open(QFile::ReadOnly)) {
Expand Down Expand Up @@ -161,7 +161,7 @@ void LoadingWindow::closeEvent(QCloseEvent * event) {
QWidget::closeEvent(event);
}
void LoadingWindow::showEvent(QShowEvent * event) {
qDebug() << __PRETTY_FUNCTION__;
//qDebug() << __PRETTY_FUNCTION__;

//Q_UNUSED(event);
QWidget::showEvent(event);
Expand Down Expand Up @@ -238,7 +238,7 @@ void LoadingWindow::showEvent(QShowEvent * event) {
}
}
void LoadingWindow::appQuitEvent() {
qDebug() << __PRETTY_FUNCTION__;
//qDebug() << __PRETTY_FUNCTION__;

QSettings settings;
settings.setValue("LoadingWindowGeometry", saveGeometry());
Expand Down Expand Up @@ -367,7 +367,7 @@ void LoadingWindow::newFileSelected(const QItemSelection &selected, const QItemS
}
*/
void LoadingWindow::listOfVideoSourcesUpdated(DynamicVideoSource * inSrc) {
qDebug() << __PRETTY_FUNCTION__;
//qDebug() << __PRETTY_FUNCTION__;

if (inSrc == nullptr) {
qDebug() << "ERR: bailing, inSrc null, " << __PRETTY_FUNCTION__;
Expand Down Expand Up @@ -484,7 +484,7 @@ void LoadingWindow::videoSourceChanged(int arg1) {


void LoadingWindow::setBaseDirectory(const QString & inBaseDir) {
qDebug() << __PRETTY_FUNCTION__ << ", " << inBaseDir;
//qDebug() << __PRETTY_FUNCTION__ << ", " << inBaseDir;

if (qApp->thread() != QThread::currentThread()) qDebug() << "ERR: thread is not main! " << __PRETTY_FUNCTION__;
/*
Expand Down
15 changes: 8 additions & 7 deletions examples/Qt/ISFEditor/ISFEditor_app/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ void MainWindow::widgetDrewItsFirstFrame() {

// make the global buffer pool, using a newly-created context that shares the base global context
CreateGlobalBufferPool(widgetCtx->newContextSharingMe());
cout << "global buffer pool is " << GetGlobalBufferPool() << endl;

// don't tell the widget to start rendering- doing so will cause it to start rendering at 60fps
//ui->bufferView->startRendering();
Expand Down Expand Up @@ -108,22 +107,24 @@ void FinishLaunching() {

// connect the output window's buffer view's signal to the ISFController's redraw slot
ISFGLBufferQWidget *bufferView = (ow==nullptr) ? nullptr : ow->bufferView();
if (bufferView == nullptr)
qDebug() << "ERR: bufferView nil in " << __PRETTY_FUNCTION__;
if (bufferView == nullptr) {
//qDebug() << "ERR: bufferView nil in " << __PRETTY_FUNCTION__;
}
else {
QObject::connect(bufferView, &QOpenGLWidget::frameSwapped, GetISFController(), &ISFController::widgetRedrawSlot);
}

qDebug() << "about to show the output window...";
//qDebug() << "about to show the output window...";
ow->show();
qDebug() << "finished showing the output window...";
//qDebug() << "finished showing the output window...";

// the doc window already created the auto updater- check for an update after a small delay
QTimer::singleShot(500, [&]() {
//qDebug() << "checking for update!";
AutoUpdater *aa = GetGlobalAutoUpdater();
if (aa == nullptr)
cout << "ERR: auto updater nil in main()\n";
if (aa == nullptr) {
//cout << "ERR: auto updater nil in main()\n";
}
else {
//aa->checkForUpdates();
}
Expand Down
2 changes: 1 addition & 1 deletion examples/Qt/ISFEditor/ISFEditor_app/OutputWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ void OutputWindow::widgetDrewItsFirstFrame() {
}
*/
void OutputWindow::aboutToQuit() {
qDebug() << __PRETTY_FUNCTION__;
//qDebug() << __PRETTY_FUNCTION__;

QSettings settings;
settings.setValue("OutputWindowGeometry", saveGeometry());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ MediaFile::Type DynamicVideoSource::srcType() {


void DynamicVideoSource::loadFile(const MediaFile & n) {
qDebug() << __PRETTY_FUNCTION__ << "... " << n.name();
//qDebug() << __PRETTY_FUNCTION__ << "... " << n.name();

lock_guard<recursive_mutex> tmpLock(srcLock);

Expand Down
Loading

0 comments on commit 6294466

Please sign in to comment.