Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#5342: Refactor the ShaderDefinitionView to make it more generic. Add…
… MaterialDefinitionView specialised for viewing materials.
- Loading branch information
1 parent
2285f2c
commit 3bc0db0
Showing
10 changed files
with
245 additions
and
155 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#include "DefinitionView.h" | ||
|
||
#include "i18n.h" | ||
#include "ishaders.h" | ||
#include "imainframe.h" | ||
|
||
#include "wxutil/SourceView.h" | ||
|
||
#include <wx/sizer.h> | ||
#include <wx/stattext.h> | ||
|
||
namespace ui | ||
{ | ||
|
||
DefinitionView::DefinitionView(const std::string& title) : | ||
wxutil::DialogBase(title), | ||
_view(nullptr) | ||
{ | ||
SetSizer(new wxBoxSizer(wxVERTICAL)); | ||
|
||
_panel = new wxPanel(this, wxID_ANY); | ||
_panel->SetSizer(new wxBoxSizer(wxVERTICAL)); | ||
|
||
auto* table = new wxFlexGridSizer(2, 2, 6, 6); | ||
|
||
auto* nameLabel = new wxStaticText(_panel, wxID_ANY, _("Name:")); | ||
auto* materialFileLabel = new wxStaticText(_panel, wxID_ANY, _("Defined in:")); | ||
|
||
_declName = new wxStaticText(_panel, wxID_ANY, ""); | ||
_declName->SetFont(_declName->GetFont().Bold()); | ||
|
||
_filename = new wxStaticText(_panel, wxID_ANY, ""); | ||
_filename->SetFont(_filename->GetFont().Bold()); | ||
|
||
nameLabel->SetMinSize(wxSize(90, -1)); | ||
materialFileLabel->SetMinSize(wxSize(90, -1)); | ||
|
||
table->Add(nameLabel, 0, wxALIGN_CENTER_VERTICAL); | ||
table->Add(_declName, 0, wxALIGN_CENTER_VERTICAL); | ||
|
||
table->Add(materialFileLabel, 0, wxALIGN_CENTER_VERTICAL); | ||
table->Add(_filename, 0, wxALIGN_CENTER_VERTICAL); | ||
|
||
auto* defLabel = new wxStaticText(_panel, wxID_ANY, _("Definition:")); | ||
|
||
_panel->GetSizer()->Add(table, 0); | ||
_panel->GetSizer()->Add(defLabel, 0, wxTOP, 6); | ||
|
||
GetSizer()->Add(_panel, 1, wxEXPAND | wxALL, 12); | ||
GetSizer()->Add(CreateStdDialogButtonSizer(wxOK), 0, wxALIGN_RIGHT | wxBOTTOM | wxRIGHT, 12); | ||
} | ||
|
||
void DefinitionView::addSourceView(wxutil::SourceViewCtrl* view) | ||
{ | ||
_view = view; | ||
_panel->GetSizer()->Add(_view, 1, wxEXPAND | wxTOP, 6); | ||
} | ||
|
||
int DefinitionView::ShowModal() | ||
{ | ||
// Let subclasses load the values into the controls | ||
update(); | ||
|
||
FitToScreen(0.6f, 0.66f); | ||
|
||
return DialogBase::ShowModal(); | ||
} | ||
|
||
void DefinitionView::update() | ||
{ | ||
if (isEmpty()) | ||
{ | ||
// Null-ify the contents | ||
_declName->SetLabelMarkup(""); | ||
_filename->SetLabelMarkup(""); | ||
|
||
_view->Enable(false); | ||
return; | ||
} | ||
|
||
// Add the shader and file name | ||
auto declName = getDeclName(); | ||
|
||
_declName->SetLabel(declName); | ||
_filename->SetLabel(getDeclFileName()); | ||
|
||
_view->Enable(true); | ||
|
||
// Surround the definition with curly braces, these are not included | ||
std::string definition = declName + "\n{\n\r"; | ||
definition += getDefinition(); | ||
definition += "\n\r}"; | ||
|
||
// Value Updates are only possible when read-only is false | ||
_view->SetReadOnly(false); | ||
_view->SetValue(definition); | ||
_view->SetReadOnly(true); | ||
} | ||
|
||
wxWindow* DefinitionView::getMainPanel() | ||
{ | ||
return _panel; | ||
} | ||
|
||
} // namespace ui |
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,49 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <wx/panel.h> | ||
#include "wxutil/dialog/DialogBase.h" | ||
|
||
namespace wxutil { class SourceViewCtrl; } | ||
class wxStaticText; | ||
|
||
namespace ui | ||
{ | ||
|
||
class DefinitionView : | ||
public wxutil::DialogBase | ||
{ | ||
private: | ||
wxStaticText* _declName; | ||
wxStaticText* _filename; | ||
|
||
wxPanel* _panel; | ||
|
||
// Will be created by subclasses | ||
wxutil::SourceViewCtrl* _view; | ||
|
||
public: | ||
DefinitionView(const std::string& title); | ||
|
||
int ShowModal() override; | ||
|
||
protected: | ||
void update(); | ||
|
||
// Whether there is anything to show. If false, the view will be disabled. | ||
virtual bool isEmpty() const = 0; | ||
|
||
// Get the name of the declaration | ||
virtual std::string getDeclName() = 0; | ||
|
||
// Get the file name the declaration is defined in | ||
virtual std::string getDeclFileName() = 0; | ||
|
||
// Provide the definition without the name and the outermost curly braces | ||
virtual std::string getDefinition() = 0; | ||
|
||
wxWindow* getMainPanel(); | ||
void addSourceView(wxutil::SourceViewCtrl* view); | ||
}; | ||
|
||
} // namespace ui |
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,41 @@ | ||
#include "MaterialDefinitionView.h" | ||
|
||
#include "wxutil/SourceView.h" | ||
|
||
namespace ui | ||
{ | ||
|
||
MaterialDefinitionView::MaterialDefinitionView(const std::string& shaderName) : | ||
DefinitionView(_("View Shader Definition")) | ||
{ | ||
addSourceView(new wxutil::D3MaterialSourceViewCtrl(getMainPanel())); | ||
_material = GlobalMaterialManager().getMaterialForName(shaderName); | ||
} | ||
|
||
void MaterialDefinitionView::setShader(const std::string& shader) | ||
{ | ||
_material = GlobalMaterialManager().getMaterialForName(shader); | ||
update(); | ||
} | ||
|
||
bool MaterialDefinitionView::isEmpty() const | ||
{ | ||
return !_material; | ||
} | ||
|
||
std::string MaterialDefinitionView::getDeclName() | ||
{ | ||
return _material ? _material->getName() : std::string(); | ||
} | ||
|
||
std::string MaterialDefinitionView::getDeclFileName() | ||
{ | ||
return _material ? _material->getShaderFileName() : std::string(); | ||
} | ||
|
||
std::string MaterialDefinitionView::getDefinition() | ||
{ | ||
return _material ? _material->getDefinition() : std::string(); | ||
} | ||
|
||
} |
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 "ishaders.h" | ||
#include "DefinitionView.h" | ||
|
||
namespace ui | ||
{ | ||
|
||
class MaterialDefinitionView: | ||
public DefinitionView | ||
{ | ||
private: | ||
// The material which should be previewed | ||
MaterialPtr _material; | ||
|
||
public: | ||
MaterialDefinitionView(const std::string& shaderName); | ||
|
||
void setShader(const std::string& shader); | ||
|
||
protected: | ||
bool isEmpty() const override; | ||
std::string getDeclName() override; | ||
std::string getDeclFileName() override; | ||
std::string getDefinition() override; | ||
}; | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.