Commit 161f33d0 authored by Tobias Hunger's avatar Tobias Hunger Committed by Tobias Hunger

JsonWizard: Replace GLSL wizards with JsonWizard

Change-Id: Ieeeec4d1a023b7cca19e3bd23ba1aa6dd1d76e72
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
parent bb7a6f92
uniform sampler2D qt_Texture0;
varying vec4 qt_TexCoord0;
void main(void)
{
gl_FragColor = texture2D(qt_Texture0, qt_TexCoord0.st);
}
{
"version": 1,
"kind": "file",
"id": "J.GLSL",
"category": "U.GLSL",
"trDescription": "Creates a fragment shader in the Desktop OpenGL Shading Language (GLSL). Fragment shaders generate the final pixel colors for triangles, points and lines rendered with OpenGL.",
"trDisplayName": "Fragment Shader (Desktop OpenGL)",
"trDisplayCategory": "GLSL",
"icon": "../../../../global/genericfilewizard.png",
"platformIndependent": true,
"featuresRequired": [ "Plugin.GLSLEditor" ],
"pages" :
[
{
"trDisplayName": "Location",
"trShortTitle": "Location",
"typeId": "File"
},
{
"trDisplayName": "Project Management",
"trShortTitle": "Summary",
"typeId": "Summary"
}
],
"generators" :
[
{
"typeId": "File",
"data":
{
"source": "file.frag",
"target": "%{JS: Cpp.fileName('%{TargetPath}', '%{JS: Util.preferredSuffix('text/x-glsl-frag')}')}",
"openInEditor": true
}
}
]
}
attribute vec4 qt_Vertex;
attribute vec4 qt_MultiTexCoord0;
uniform mat4 qt_ModelViewProjectionMatrix;
varying vec4 qt_TexCoord0;
void main(void)
{
gl_Position = qt_ModelViewProjectionMatrix * qt_Vertex;
qt_TexCoord0 = qt_MultiTexCoord0;
}
{
"version": 1,
"kind": "file",
"id": "K.GLSL",
"category": "U.GLSL",
"trDescription": "Creates a vertex shader in the Desktop OpenGL Shading Language (GLSL). Vertex shaders transform the positions, normals and texture co-ordinates of triangles, points and lines rendered with OpenGL.",
"trDisplayName": "Vertex Shader (Desktop OpenGL)",
"trDisplayCategory": "GLSL",
"icon": "../../../../global/genericfilewizard.png",
"platformIndependent": true,
"featuresRequired": [ "Plugin.GLSLEditor" ],
"pages" :
[
{
"trDisplayName": "Location",
"trShortTitle": "Location",
"typeId": "File"
},
{
"trDisplayName": "Project Management",
"trShortTitle": "Summary",
"typeId": "Summary"
}
],
"generators" :
[
{
"typeId": "File",
"data":
{
"source": "file.vert",
"target": "%{JS: Cpp.fileName('%{TargetPath}', '%{JS: Util.preferredSuffix('text/x-glsl-vert')}')}",
"openInEditor": true
}
}
]
}
uniform sampler2D qt_Texture0;
varying highp vec4 qt_TexCoord0;
void main(void)
{
gl_FragColor = texture2D(qt_Texture0, qt_TexCoord0.st);
}
{
"version": 1,
"kind": "file",
"id": "F.GLSL",
"category": "U.GLSL",
"trDescription": "Creates a fragment shader in the OpenGL/ES 2.0 Shading Language (GLSL/ES). Fragment shaders generate the final pixel colors for triangles, points and lines rendered with OpenGL.",
"trDisplayName": "Fragment Shader (OpenGL/ES 2.0)",
"trDisplayCategory": "GLSL",
"icon": "../../../../global/genericfilewizard.png",
"platformIndependent": true,
"featuresRequired": [ "Plugin.GLSLEditor" ],
"pages" :
[
{
"trDisplayName": "Location",
"trShortTitle": "Location",
"typeId": "File"
},
{
"trDisplayName": "Project Management",
"trShortTitle": "Summary",
"typeId": "Summary"
}
],
"generators" :
[
{
"typeId": "File",
"data":
{
"source": "file.fsh",
"target": "%{JS: Cpp.fileName('%{TargetPath}', '%{JS: Util.preferredSuffix('text/x-glsl-es-frag')}')}",
"openInEditor": true
}
}
]
}
attribute highp vec4 qt_Vertex;
attribute highp vec4 qt_MultiTexCoord0;
uniform highp mat4 qt_ModelViewProjectionMatrix;
varying highp vec4 qt_TexCoord0;
void main(void)
{
gl_Position = qt_ModelViewProjectionMatrix * qt_Vertex;
qt_TexCoord0 = qt_MultiTexCoord0;
}
{
"version": 1,
"kind": "file",
"id": "G.GLSL",
"category": "U.GLSL",
"trDescription": "Creates a vertex shader in the OpenGL/ES 2.0 Shading Language (GLSL/ES). Vertex shaders transform the positions, normals and texture co-ordinates of triangles, points and lines rendered with OpenGL.",
"trDisplayName": "Vertex Shader (OpenGL/ES 2.0)",
"trDisplayCategory": "GLSL",
"icon": "../../../../global/genericfilewizard.png",
"platformIndependent": true,
"featuresRequired": [ "Plugin.GLSLEditor" ],
"pages" :
[
{
"trDisplayName": "Location",
"trShortTitle": "Location",
"typeId": "File"
},
{
"trDisplayName": "Project Management",
"trShortTitle": "Summary",
"typeId": "Summary"
}
],
"generators" :
[
{
"typeId": "File",
"data":
{
"source": "file.vsh",
"target": "%{JS: Cpp.fileName('%{TargetPath}', '%{JS: Util.preferredSuffix('text/x-glsl-es-vert')}')}",
"openInEditor": true
}
}
]
}
......@@ -7,7 +7,6 @@ HEADERS += \
glsleditor.h \
glsleditorconstants.h \
glsleditorplugin.h \
glslfilewizard.h \
glslhighlighter.h \
glslautocompleter.h \
glslindenter.h \
......@@ -17,7 +16,6 @@ glslcompletionassist.h
SOURCES += \
glsleditor.cpp \
glsleditorplugin.cpp \
glslfilewizard.cpp \
glslhighlighter.cpp \
glslautocompleter.cpp \
glslindenter.cpp \
......
......@@ -26,8 +26,6 @@ QtcPlugin {
"glsleditorconstants.h",
"glsleditorplugin.cpp",
"glsleditorplugin.h",
"glslfilewizard.cpp",
"glslfilewizard.h",
"glslhighlighter.cpp",
"glslhighlighter.h",
"glslhoverhandler.cpp",
......
......@@ -31,7 +31,6 @@
#include "glslcompletionassist.h"
#include "glsleditor.h"
#include "glsleditorconstants.h"
#include "glslfilewizard.h"
#include "glslhighlighter.h"
#include <glsl/glslengine.h>
......@@ -157,58 +156,6 @@ bool GlslEditorPlugin::initialize(const QStringList & /*arguments*/, QString *er
FileIconProvider::registerIconOverlayForMimeType(":/glsleditor/images/glslfile.png", Constants::GLSL_MIMETYPE_VERT_ES);
FileIconProvider::registerIconOverlayForMimeType(":/glsleditor/images/glslfile.png", Constants::GLSL_MIMETYPE_FRAG_ES);
IWizardFactory *wizard = new GlslFileWizard(GlslFileWizard::FragmentShaderES);
wizard->setWizardKind(IWizardFactory::FileWizard);
wizard->setCategory(QLatin1String(Constants::WIZARD_CATEGORY_GLSL));
wizard->setDisplayCategory(QCoreApplication::translate("GLSLEditor", Constants::WIZARD_TR_CATEGORY_GLSL));
wizard->setDescription
(tr("Creates a fragment shader in the OpenGL/ES 2.0 Shading "
"Language (GLSL/ES). Fragment shaders generate the final "
"pixel colors for triangles, points and lines rendered "
"with OpenGL."));
wizard->setDisplayName(tr("Fragment Shader (OpenGL/ES 2.0)"));
wizard->setId(QLatin1String("F.GLSL"));
addAutoReleasedObject(wizard);
wizard = new GlslFileWizard(GlslFileWizard::VertexShaderES);
wizard->setWizardKind(IWizardFactory::FileWizard);
wizard->setCategory(QLatin1String(Constants::WIZARD_CATEGORY_GLSL));
wizard->setDisplayCategory(QCoreApplication::translate("GLSLEditor", Constants::WIZARD_TR_CATEGORY_GLSL));
wizard->setDescription
(tr("Creates a vertex shader in the OpenGL/ES 2.0 Shading "
"Language (GLSL/ES). Vertex shaders transform the "
"positions, normals and texture co-ordinates of "
"triangles, points and lines rendered with OpenGL."));
wizard->setDisplayName(tr("Vertex Shader (OpenGL/ES 2.0)"));
wizard->setId(QLatin1String("G.GLSL"));
addAutoReleasedObject(wizard);
wizard = new GlslFileWizard(GlslFileWizard::FragmentShaderDesktop);
wizard->setWizardKind(IWizardFactory::FileWizard);
wizard->setCategory(QLatin1String(Constants::WIZARD_CATEGORY_GLSL));
wizard->setDisplayCategory(QCoreApplication::translate("GLSLEditor", Constants::WIZARD_TR_CATEGORY_GLSL));
wizard->setDescription
(tr("Creates a fragment shader in the Desktop OpenGL Shading "
"Language (GLSL). Fragment shaders generate the final "
"pixel colors for triangles, points and lines rendered "
"with OpenGL."));
wizard->setDisplayName(tr("Fragment Shader (Desktop OpenGL)"));
wizard->setId(QLatin1String("J.GLSL"));
addAutoReleasedObject(wizard);
wizard = new GlslFileWizard(GlslFileWizard::VertexShaderDesktop);
wizard->setWizardKind(IWizardFactory::FileWizard);
wizard->setCategory(QLatin1String(Constants::WIZARD_CATEGORY_GLSL));
wizard->setDisplayCategory(QCoreApplication::translate("GLSLEditor", Constants::WIZARD_TR_CATEGORY_GLSL));
wizard->setDescription
(tr("Creates a vertex shader in the Desktop OpenGL Shading "
"Language (GLSL). Vertex shaders transform the "
"positions, normals and texture co-ordinates of "
"triangles, points and lines rendered with OpenGL."));
wizard->setDisplayName(tr("Vertex Shader (Desktop OpenGL)"));
wizard->setId(QLatin1String("K.GLSL"));
addAutoReleasedObject(wizard);
auto hf = new HighlighterFactory;
hf->setProductType<GlslHighlighter>();
hf->setId(Constants::C_GLSLEDITOR_ID);
......
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "glslfilewizard.h"
#include "glsleditorconstants.h"
#include <coreplugin/basefilewizard.h>
#include <utils/filewizardpage.h>
#include <utils/qtcassert.h>
#include <QFileInfo>
#include <QTextStream>
#include <QWizard>
#include <QPushButton>
using namespace Core;
using namespace Utils;
namespace GlslEditor {
GlslFileWizard::GlslFileWizard(ShaderType shaderType)
: m_shaderType(shaderType)
{
setFlags(IWizardFactory::PlatformIndependent);
}
GeneratedFiles GlslFileWizard::generateFiles(const QWizard *w, QString * /*errorMessage*/) const
{
const BaseFileWizard *wizard = qobject_cast<const BaseFileWizard *>(w);
const FileWizardPage *page = wizard->find<FileWizardPage>();
QTC_ASSERT(page, return GeneratedFiles());
const QString path = page->path();
const QString name = page->fileName();
const QString fileName = BaseFileWizardFactory::buildFileName(path, name, preferredSuffix(m_shaderType));
GeneratedFile file(fileName);
file.setContents(fileContents(fileName, m_shaderType));
file.setAttributes(GeneratedFile::OpenEditorAttribute);
return GeneratedFiles() << file;
}
QString GlslFileWizard::fileContents(const QString &, ShaderType shaderType) const
{
QString contents;
QTextStream str(&contents);
switch (shaderType) {
case GlslFileWizard::VertexShaderES:
str << QLatin1String("attribute highp vec4 qt_Vertex;\n")
<< QLatin1String("attribute highp vec4 qt_MultiTexCoord0;\n")
<< QLatin1String("uniform highp mat4 qt_ModelViewProjectionMatrix;\n")
<< QLatin1String("varying highp vec4 qt_TexCoord0;\n")
<< QLatin1String("\n")
<< QLatin1String("void main(void)\n")
<< QLatin1String("{\n")
<< QLatin1String(" gl_Position = qt_ModelViewProjectionMatrix * qt_Vertex;\n")
<< QLatin1String(" qt_TexCoord0 = qt_MultiTexCoord0;\n")
<< QLatin1String("}\n");
break;
case GlslFileWizard::FragmentShaderES:
str << QLatin1String("uniform sampler2D qt_Texture0;\n")
<< QLatin1String("varying highp vec4 qt_TexCoord0;\n")
<< QLatin1String("\n")
<< QLatin1String("void main(void)\n")
<< QLatin1String("{\n")
<< QLatin1String(" gl_FragColor = texture2D(qt_Texture0, qt_TexCoord0.st);\n")
<< QLatin1String("}\n");
break;
case GlslFileWizard::VertexShaderDesktop:
str << QLatin1String("attribute vec4 qt_Vertex;\n")
<< QLatin1String("attribute vec4 qt_MultiTexCoord0;\n")
<< QLatin1String("uniform mat4 qt_ModelViewProjectionMatrix;\n")
<< QLatin1String("varying vec4 qt_TexCoord0;\n")
<< QLatin1String("\n")
<< QLatin1String("void main(void)\n")
<< QLatin1String("{\n")
<< QLatin1String(" gl_Position = qt_ModelViewProjectionMatrix * qt_Vertex;\n")
<< QLatin1String(" qt_TexCoord0 = qt_MultiTexCoord0;\n")
<< QLatin1String("}\n");
break;
case GlslFileWizard::FragmentShaderDesktop:
str << QLatin1String("uniform sampler2D qt_Texture0;\n")
<< QLatin1String("varying vec4 qt_TexCoord0;\n")
<< QLatin1String("\n")
<< QLatin1String("void main(void)\n")
<< QLatin1String("{\n")
<< QLatin1String(" gl_FragColor = texture2D(qt_Texture0, qt_TexCoord0.st);\n")
<< QLatin1String("}\n");
break;
default: break;
}
return contents;
}
BaseFileWizard *GlslFileWizard::create(QWidget *parent, const WizardDialogParameters &parameters) const
{
BaseFileWizard *wizard = new BaseFileWizard(parent);
wizard->setWindowTitle(tr("New %1").arg(displayName()));
FileWizardPage *page = new FileWizardPage;
page->setPath(parameters.defaultPath());
wizard->addPage(page);
foreach (QWizardPage *p, parameters.extensionPages())
wizard->addPage(p);
return wizard;
}
QString GlslFileWizard::preferredSuffix(ShaderType shaderType) const
{
switch (shaderType) {
case GlslFileWizard::VertexShaderES:
return QLatin1String("vsh");
case GlslFileWizard::FragmentShaderES:
return QLatin1String("fsh");
case GlslFileWizard::VertexShaderDesktop:
return QLatin1String("vert");
case GlslFileWizard::FragmentShaderDesktop:
return QLatin1String("frag");
default:
return QLatin1String("glsl");
}
}
} // namespace GlslEditor
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef GLSLFILEWIZARD_H
#define GLSLFILEWIZARD_H
#include <coreplugin/basefilewizardfactory.h>
namespace GlslEditor {
class GlslFileWizard: public Core::BaseFileWizardFactory
{
Q_OBJECT
public:
enum ShaderType
{
VertexShaderES,
FragmentShaderES,
VertexShaderDesktop,
FragmentShaderDesktop
};
explicit GlslFileWizard(ShaderType shaderType);
private:
QString fileContents(const QString &baseName, ShaderType shaderType) const;
Core::BaseFileWizard *create(QWidget *parent, const Core::WizardDialogParameters &parameters) const;
Core::GeneratedFiles generateFiles(const QWizard *w,
QString *errorMessage) const;
QString preferredSuffix(ShaderType shaderType) const;
private:
ShaderType m_shaderType;
};
} // namespace GlslEditor
#endif // GLSLFILEWIZARD_H
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