Commit 6d082bc0 authored by Jan Möbius's avatar Jan Möbius

Box to show and hide shaders in render object widgets

More highlighting of code

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@16269 383ad7c9-94d9-4d36-a494-682f7c89f535
parent baa95efb
......@@ -58,96 +58,136 @@ RenderObjectHighlighter::RenderObjectHighlighter(QTextEdit *parent)
void RenderObjectHighlighter::init() {
// Set the basic format styles
VertexShaderFormat_.setForeground(Qt::darkGreen);
VertexShaderFormat_.setFontWeight(QFont::Bold);
FragmentShaderFormat_.setForeground(Qt::darkRed);
FragmentShaderFormat_.setFontWeight(QFont::Bold);
vertexShaderFormat_.setBackground(Qt::green);
vertexShaderFormat_.setFontWeight(QFont::Bold);
vertexShaderStartExpression_ = QRegExp("---------------------vertex-shader--------------------");
vertexShaderEndExpression_ = QRegExp("---------------------end-vertex-shader--------------------");
geometryShaderFormat_.setBackground(Qt::blue);
geometryShaderFormat_.setFontWeight(QFont::Bold);
geometryShaderStartExpression_ = QRegExp("---------------------geometry-shader--------------------");;
geometryShaderEndExpression_ = QRegExp("---------------------end-geometry-shader--------------------");;
fragmentShaderFormat_.setBackground(Qt::red);
fragmentShaderFormat_.setFontWeight(QFont::Bold);
fragmentShaderStartExpression_ = QRegExp("---------------------fragment-shader--------------------");
fragmentShaderEndExpression_ = QRegExp("---------------------end-fragment-shader--------------------");
update();
// match whole line containing the define
defineFormat_.setForeground(Qt::green);
defineFormat_.setFontWeight(QFont::Bold);
// Single line comments
singleLineCommentFormat_.setForeground(Qt::red);
// Set the basic format styles
keywordFormat_.setForeground(Qt::darkGreen);
keywordFormat_.setFontWeight(QFont::Bold);
// Define basic keywords
keywordPatterns_ << "main" << "while" << "for" << "if" << "dot" << "sqrt" << "max" << "pow" << "return" << "normalize";
keywordPatterns_ << "min" << "clamp" << "step";
typeFormat_.setForeground(Qt::darkMagenta);
typeFormat_.setFontWeight(QFont::Bold);
// classFormat.setFontWeight(QFont::Bold);
// classFormat.setForeground(Qt::darkMagenta);
// rule.pattern = QRegExp("\\bQ[A-Za-z]+\\b");
// rule.format = classFormat;
// highlightingRules.append(rule);
//
// Types
typePatterns_ << "in" << "out" << "mat3" << "mat4" << "vec2" << "vec3" << "vec4" << "float" << "double" <<"uniform" ;
update();
}
void RenderObjectHighlighter::update() {
highlightingRules_.clear();
// HighlightingRule rule;
//
// // Create Rules for keywords
// foreach (QString pattern, keywordPatterns_) {
// rule.pattern = QRegExp("\\b" + pattern + "\\b" );
// rule.format = keywordFormat_;
// highlightingRules_.append(rule);
// }
HighlightingRule rule;
// Define rule
rule.pattern = QRegExp("#define.*");
rule.format = defineFormat_;
highlightingRules_.append(rule);
// Rule for single line comments
rule.pattern = QRegExp("//[^\n]*");
rule.format = singleLineCommentFormat_;
highlightingRules_.append(rule);
// Create Rules for keywords
foreach (QString pattern, keywordPatterns_) {
rule.pattern = QRegExp("\\b" + pattern + "\\b" );
rule.format = keywordFormat_;
highlightingRules_.append(rule);
}
// Create Rules for types
foreach (QString pattern, typePatterns_ ) {
rule.pattern = QRegExp("\\b" + pattern + "\\b" );
rule.format = typeFormat_;
highlightingRules_.append(rule);
}
}
void RenderObjectHighlighter::highlightBlock(const QString &text)
{
// foreach (HighlightingRule rule, highlightingRules_) {
// QRegExp expression(rule.pattern);
// int index = text.indexOf(expression);
// while (index >= 0) {
// int length = expression.matchedLength();
// setFormat(index, length, rule.format);
// index = text.indexOf(expression, index + length);
// }
// }
// Single word highlighting
foreach (HighlightingRule rule, highlightingRules_) {
QRegExp expression(rule.pattern);
int index = text.indexOf(expression);
while (index >= 0) {
int length = expression.matchedLength();
setFormat(index, length, rule.format);
index = text.indexOf(expression, index + length);
}
}
// Blockstate -1,0 : nothing
// Blockstate 1 : vertexShader Code
// Blockstate 2 : geometryShader Code
// Blockstate 3 : fragment Shader Code
setCurrentBlockState(0);
// Vertex shader block
int startIndex = 0;
if (previousBlockState() != 1)
startIndex = text.indexOf(vertexShaderStartExpression_);
while (startIndex >= 0) {
int endIndex = text.indexOf(vertexShaderEndExpression_, startIndex);
int commentLength;
if (endIndex == -1) {
setCurrentBlockState(1);
commentLength = text.length() - startIndex;
} else {
commentLength = endIndex - startIndex + vertexShaderEndExpression_.matchedLength();
}
setFormat(startIndex, commentLength, VertexShaderFormat_);
startIndex = text.indexOf(vertexShaderStartExpression_, startIndex + commentLength);
}
// Fragment shader block
startIndex = 0;
if (previousBlockState() != 3)
startIndex = text.indexOf(fragmentShaderStartExpression_);
while (startIndex >= 0) {
int endIndex = text.indexOf(fragmentShaderEndExpression_, startIndex);
int commentLength;
if (endIndex == -1) {
setCurrentBlockState(3);
commentLength = text.length() - startIndex;
} else {
commentLength = endIndex - startIndex + fragmentShaderEndExpression_.matchedLength();
}
setFormat(startIndex, commentLength, FragmentShaderFormat_);
startIndex = text.indexOf(fragmentShaderStartExpression_, startIndex + commentLength);
}
// setCurrentBlockState(0);
//
// // Vertex shader block
// int startIndex = 0;
// if (previousBlockState() != 1)
// startIndex = text.indexOf(vertexShaderStartExpression_);
//
// while (startIndex >= 0) {
// int endIndex = text.indexOf(vertexShaderEndExpression_, startIndex);
// int commentLength;
// if (endIndex == -1) {
// setCurrentBlockState(1);
// commentLength = text.length() - startIndex;
// } else {
// commentLength = endIndex - startIndex + vertexShaderEndExpression_.matchedLength();
// }
// setFormat(startIndex, commentLength, vertexShaderFormat_);
// startIndex = text.indexOf(vertexShaderStartExpression_, startIndex + commentLength);
// }
//
// // Fragment shader block
// startIndex = 0;
// if (previousBlockState() != 3)
// startIndex = text.indexOf(fragmentShaderStartExpression_);
//
// while (startIndex >= 0) {
// int endIndex = text.indexOf(fragmentShaderEndExpression_, startIndex);
// int commentLength;
// if (endIndex == -1) {
// setCurrentBlockState(3);
// commentLength = text.length() - startIndex;
// } else {
// commentLength = endIndex - startIndex + fragmentShaderEndExpression_.matchedLength();
// }
// setFormat(startIndex, commentLength, fragmentShaderFormat_);
// startIndex = text.indexOf(fragmentShaderStartExpression_, startIndex + commentLength);
// }
}
......@@ -74,16 +74,36 @@ class RenderObjectHighlighter : public QSyntaxHighlighter
QTextCharFormat format;
};
// Single line rules
QStringList keywordPatterns_;
QStringList typePatterns_;
// All single line rules combined with their format
QVector<HighlightingRule> highlightingRules_;
// Multi line rules
QRegExp vertexShaderStartExpression_;
QRegExp vertexShaderEndExpression_;
QRegExp geometryShaderStartExpression_;
QRegExp geometryShaderEndExpression_;
QRegExp fragmentShaderStartExpression_;
QRegExp fragmentShaderEndExpression_;
QTextCharFormat VertexShaderFormat_;
QTextCharFormat FragmentShaderFormat_;
// Single formats
QTextCharFormat keywordFormat_;
QTextCharFormat defineFormat_;
QTextCharFormat typeFormat_;
QTextCharFormat singleLineCommentFormat_;
// Multi Line formats
QTextCharFormat vertexShaderFormat_;
QTextCharFormat geometryShaderFormat_;
QTextCharFormat fragmentShaderFormat_;
};
......@@ -63,6 +63,8 @@ RendererObjectWidget::RendererObjectWidget(QWidget *parent)
closeButton->setIcon( QIcon(iconPath + "window-close.png"));
highlighter_ = new RenderObjectHighlighter( textBrowser->document() );
connect(showShadersBox,SIGNAL(clicked()),this,SLOT(update()));
}
void RendererObjectWidget::closeEvent(QCloseEvent *event)
......@@ -90,7 +92,7 @@ void RendererObjectWidget::update()
//TODO: Flag for shader output activate/deactivate
if ( renderManager().activeId(PluginFunctions::activeExaminer()) != 0 )
textBrowser->insertPlainText(renderer->plugin->renderObjectsInfo(true));
textBrowser->insertPlainText(renderer->plugin->renderObjectsInfo(showShadersBox->isChecked()));
} else {
textBrowser->setText("Unable to get renderer!");
......
......@@ -59,10 +59,10 @@ class RendererObjectWidget : public QDialog, public Ui::RendererObjectWidget
void showEvent ( QShowEvent * );
private:
private slots:
void update();
private:
RenderObjectHighlighter* highlighter_;
};
......
......@@ -64,6 +64,16 @@
<item>
<widget class="QTextBrowser" name="textBrowser"/>
</item>
<item>
<widget class="QCheckBox" name="showShadersBox">
<property name="text">
<string>Show Shaders</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment