Skip to content

Commit

Permalink
#5532: Start working on control population
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Feb 19, 2021
1 parent 4d59979 commit 1c0f9a7
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 7 deletions.
4 changes: 2 additions & 2 deletions install/ui/materialeditor.fbp
Expand Up @@ -17977,15 +17977,15 @@
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="subclass"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style">wxTAB_TRAVERSAL</property>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">bSizer137</property>
<property name="name">bSizer77</property>
<property name="orient">wxVERTICAL</property>
<property name="permission">none</property>
</object>
Expand Down
57 changes: 52 additions & 5 deletions radiant/ui/materials/MaterialEditor.cpp
Expand Up @@ -4,6 +4,10 @@

#include <wx/panel.h>
#include <wx/splitter.h>
#include <wx/textctrl.h>
#include <wx/collpane.h>
#include "wxutil/SourceView.h"
#include "fmt/format.h"

namespace ui
{
Expand Down Expand Up @@ -51,23 +55,27 @@ MaterialEditor::MaterialEditor() :
makeLabelBold(this, "MaterialEditorStageSettingsLabel");

// Wire up the close button
findNamedObject<wxButton>(this, "MaterialEditorCloseButton")->Bind(wxEVT_BUTTON, &MaterialEditor::_onClose, this);
getControl<wxButton>("MaterialEditorCloseButton")->Bind(wxEVT_BUTTON, &MaterialEditor::_onClose, this);

// Add the treeview
auto* panel = findNamedObject<wxPanel>(this, "MaterialEditorTreeView");
auto* panel = getControl<wxPanel>("MaterialEditorTreeView");
_treeView = new MaterialTreeView(panel);
_treeView->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, &MaterialEditor::_onTreeViewSelectionChanged, this);
panel->GetSizer()->Add(_treeView, 1, wxEXPAND);

// Setup the splitter and preview
auto* splitter = findNamedObject<wxSplitterWindow>(this, "MaterialEditorSplitter");
auto* splitter = getControl<wxSplitterWindow>("MaterialEditorSplitter");
splitter->SetSashPosition(GetSize().GetWidth() * 0.6f);
splitter->SetMinimumPaneSize(10); // disallow unsplitting

// Set up the preview
auto* previewPanel = findNamedObject<wxPanel>(this, "MaterialEditorPreviewPanel");
auto* previewPanel = getControl<wxPanel>("MaterialEditorPreviewPanel");
_preview.reset(new wxutil::ModelPreview(previewPanel));

_sourceView = new wxutil::D3MaterialSourceViewCtrl(previewPanel);

previewPanel->GetSizer()->Add(_preview->getWidget(), 1, wxEXPAND);
previewPanel->GetSizer()->Add(_sourceView, 1, wxEXPAND);

setupMaterialStageView();

Expand Down Expand Up @@ -119,7 +127,7 @@ void MaterialEditor::ShowDialog(const cmd::ArgumentList& args)
void MaterialEditor::setupMaterialStageView()
{
// Stage view
auto* panel = findNamedObject<wxPanel>(this, "MaterialEditorStageView");
auto* panel = getControl<wxPanel>("MaterialEditorStageView");

_stageView = wxutil::TreeView::CreateWithModel(panel, _stageList.get(), wxDV_NO_HEADER);
panel->GetSizer()->Add(_stageView, 1, wxEXPAND);
Expand All @@ -129,4 +137,43 @@ void MaterialEditor::setupMaterialStageView()
wxDATAVIEW_CELL_INERT, wxCOL_WIDTH_AUTOSIZE, wxALIGN_NOT, wxDATAVIEW_COL_SORTABLE);
}

void MaterialEditor::_onTreeViewSelectionChanged(wxDataViewEvent& ev)
{
// Update the preview if a texture is selected
if (!_treeView->IsDirectorySelected())
{
_material = GlobalMaterialManager().getMaterialForName(_treeView->GetSelectedFullname());
}
else
{
_material.reset();
}

updateControlsFromMaterial();
}

void MaterialEditor::updateControlsFromMaterial()
{
updateMaterialPropertiesFromMaterial();
}

void MaterialEditor::updateMaterialPropertiesFromMaterial()
{
getControl<wxPanel>("MaterialEditorMaterialPropertiesPanel")->Enable(_material != nullptr);

if (_material)
{
getControl<wxTextCtrl>("MaterialDescription")->SetValue(_material->getDescription());

// Surround the definition with curly braces, these are not included
auto definition = fmt::format("{0}\n{{{1}}}", _material->getName(), _material->getDefinition());
_sourceView->SetValue(definition);
}
else
{
getControl<wxTextCtrl>("MaterialDescription")->SetValue("");
_sourceView->SetValue("");
}
}

}
16 changes: 16 additions & 0 deletions radiant/ui/materials/MaterialEditor.h
@@ -1,12 +1,14 @@
#pragma once

#include "icommandsystem.h"
#include "ishaders.h"

#include "wxutil/dialog/DialogBase.h"
#include "wxutil/WindowPosition.h"
#include "wxutil/PanedPosition.h"
#include "wxutil/XmlResourceBasedWidget.h"
#include "wxutil/preview/ModelPreview.h"
#include "wxutil/SourceView.h"

#include "ui/common/MaterialTreeView.h"

Expand All @@ -27,6 +29,9 @@ class MaterialEditor :
wxutil::PanedPosition _panedPosition;

std::shared_ptr<wxutil::ModelPreview> _preview;
wxutil::D3MaterialSourceViewCtrl* _sourceView;

MaterialPtr _material;

private:
MaterialEditor();
Expand All @@ -40,6 +45,17 @@ class MaterialEditor :

private:
void setupMaterialStageView();
void updateControlsFromMaterial();
void updateMaterialPropertiesFromMaterial();

void _onTreeViewSelectionChanged(wxDataViewEvent& ev);

// Shortcut
template<typename ObjectClass>
ObjectClass* getControl(const std::string& name)
{
return findNamedObject<ObjectClass>(this, name);
}
};

}

0 comments on commit 1c0f9a7

Please sign in to comment.