-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e608436
commit d874778
Showing
9 changed files
with
130 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#pragma once | ||
|
||
#include <QApplication> | ||
#include <QDialog> | ||
#include <QWidget> | ||
#include <string> | ||
|
||
#include "zep.h" | ||
#include "zep/mode_repl.h" | ||
#include "zep/regress.h" | ||
|
||
class ShaderEditorWindow : public QDialog { | ||
Q_OBJECT | ||
|
||
private: | ||
Zep::ZepWidget_Qt zepWidget; | ||
Zep::IZepReplProvider replProvider; | ||
static constexpr float fontSize = 14.0f; | ||
|
||
// Whether this backend supports shader editor | ||
bool shaderEditorSupported = true; | ||
|
||
public: | ||
ShaderEditorWindow(QWidget* parent, const std::string& filename, const std::string& initialText); | ||
void setText(const std::string& text) { zepWidget.GetEditor().GetMRUBuffer()->SetText(text); } | ||
|
||
void setEnable(bool enable); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include <QPushButton> | ||
#include <QVBoxLayout> | ||
|
||
#include "panda_qt/main_window.hpp" | ||
#include "panda_qt/shader_editor.hpp" | ||
|
||
using namespace Zep; | ||
|
||
ShaderEditorWindow::ShaderEditorWindow(QWidget* parent, const std::string& filename, const std::string& initialText) | ||
: QDialog(parent), zepWidget(this, qApp->applicationDirPath().toStdString(), fontSize) { | ||
resize(600, 600); | ||
|
||
// Register our extensions | ||
ZepRegressExCommand::Register(zepWidget.GetEditor()); | ||
ZepReplExCommand::Register(zepWidget.GetEditor(), &replProvider); | ||
|
||
// Default to standard mode instead of vim mode, initialize text box | ||
zepWidget.GetEditor().InitWithText(filename, initialText); | ||
zepWidget.GetEditor().SetGlobalMode(Zep::ZepMode_Standard::StaticName()); | ||
|
||
// Layout for widgets | ||
QVBoxLayout* mainLayout = new QVBoxLayout(); | ||
setLayout(mainLayout); | ||
|
||
QPushButton* button = new QPushButton(tr("Reload shader"), this); | ||
button->setFixedSize(100, 20); | ||
|
||
// When the Load Script button is pressed, send the current text to the MainWindow, which will upload it to the emulator's lua object | ||
connect(button, &QPushButton::pressed, this, [this]() { | ||
if (parentWidget()) { | ||
auto buffer = zepWidget.GetEditor().GetMRUBuffer(); | ||
const std::string text = buffer->GetBufferText(buffer->Begin(), buffer->End()); | ||
|
||
static_cast<MainWindow*>(parentWidget())->reloadShader(text); | ||
} else { | ||
// This should be unreachable, only here for safety purposes | ||
printf("Text editor does not have any parent widget, click doesn't work :(\n"); | ||
} | ||
}); | ||
|
||
mainLayout->addWidget(button); | ||
mainLayout->addWidget(&zepWidget); | ||
} | ||
|
||
void ShaderEditorWindow::setEnable(bool enable) { | ||
shaderEditorSupported = enable; | ||
|
||
if (enable) { | ||
setDisabled(false); | ||
} else { | ||
setDisabled(true); | ||
setText("Shader editor window is not available for this renderer backend"); | ||
} | ||
} |