diff --git a/code/Render/Editor/Texture/TextureAssetEditorPage.cpp b/code/Render/Editor/Texture/TextureAssetEditorPage.cpp index fa82cf6b2..82b0cd480 100644 --- a/code/Render/Editor/Texture/TextureAssetEditorPage.cpp +++ b/code/Render/Editor/Texture/TextureAssetEditorPage.cpp @@ -32,6 +32,7 @@ #include "Ui/StatusBar/StatusBar.h" #include "Ui/ToolBar/ToolBar.h" #include "Ui/ToolBar/ToolBarButton.h" +#include "Ui/ToolBar/ToolBarButtonClickEvent.h" namespace traktor::render { @@ -60,10 +61,15 @@ bool TextureAssetEditorPage::create(ui::Container* parent) toolBar->addImage(new ui::StyleBitmap(L"Texture.RGBA", 1)); toolBar->addImage(new ui::StyleBitmap(L"Texture.RGBA", 2)); toolBar->addImage(new ui::StyleBitmap(L"Texture.RGBA", 3)); - toolBar->addItem(new ui::ToolBarButton(L"R", 0, ui::Command(L"Render.Texture.Editor.ToggleR"), ui::ToolBarButton::BsDefaultToggled)); - toolBar->addItem(new ui::ToolBarButton(L"G", 1, ui::Command(L"Render.Texture.Editor.ToggleG"), ui::ToolBarButton::BsDefaultToggled)); - toolBar->addItem(new ui::ToolBarButton(L"B", 2, ui::Command(L"Render.Texture.Editor.ToggleB"), ui::ToolBarButton::BsDefaultToggled)); - toolBar->addItem(new ui::ToolBarButton(L"A", 3, ui::Command(L"Render.Texture.Editor.ToggleA"), ui::ToolBarButton::BsDefaultToggled)); + m_toolToggleR = new ui::ToolBarButton(L"R", 0, ui::Command(L"Render.Texture.Editor.ToggleR"), ui::ToolBarButton::BsDefaultToggled); + m_toolToggleG = new ui::ToolBarButton(L"G", 1, ui::Command(L"Render.Texture.Editor.ToggleG"), ui::ToolBarButton::BsDefaultToggled); + m_toolToggleB = new ui::ToolBarButton(L"B", 2, ui::Command(L"Render.Texture.Editor.ToggleB"), ui::ToolBarButton::BsDefaultToggled); + m_toolToggleA = new ui::ToolBarButton(L"A", 3, ui::Command(L"Render.Texture.Editor.ToggleA"), ui::ToolBarButton::BsDefaultToggled); + toolBar->addItem(m_toolToggleR); + toolBar->addItem(m_toolToggleG); + toolBar->addItem(m_toolToggleB); + toolBar->addItem(m_toolToggleA); + toolBar->addEventHandler< ui::ToolBarButtonClickEvent >([=, this](ui::ToolBarButtonClickEvent* event) { updatePreview(); }); Ref< ui::Container > imageContainer = new ui::Container(); imageContainer->create(container, ui::WsNone, new ui::TableLayout(L"100%", L"100%,*", 0_ut, 0_ut)); @@ -127,7 +133,13 @@ void TextureAssetEditorPage::updatePreview() Ref< drawing::Image > image = drawing::Image::load(fileName); if (image) { - m_textureControl->setImage(image, m_asset->m_output); + const uint32_t channels = + (m_toolToggleR->isToggled() ? 1 : 0) | + (m_toolToggleG->isToggled() ? 2 : 0) | + (m_toolToggleB->isToggled() ? 4 : 0) | + (m_toolToggleA->isToggled() ? 8 : 0); + + m_textureControl->setImage(image, m_asset->m_output, channels); StringOutputStream ss; ss << image->getWidth() << L" * " << image->getHeight(); @@ -148,7 +160,7 @@ void TextureAssetEditorPage::updatePreview() } else { - m_textureControl->setImage(nullptr, m_asset->m_output); + m_textureControl->setImage(nullptr, m_asset->m_output, ~0U); m_statusBar->setText(0, L""); } } diff --git a/code/Render/Editor/Texture/TextureAssetEditorPage.h b/code/Render/Editor/Texture/TextureAssetEditorPage.h index 748144a2f..a28b142f8 100644 --- a/code/Render/Editor/Texture/TextureAssetEditorPage.h +++ b/code/Render/Editor/Texture/TextureAssetEditorPage.h @@ -33,6 +33,7 @@ namespace traktor::ui class ContentChangeEvent; class MouseMoveEvent; +class ToolBarButton; class StatusBar; } @@ -65,6 +66,10 @@ class TextureAssetEditorPage : public editor::IEditorPage editor::IEditorPageSite* m_site; editor::IDocument* m_document; Ref< TextureAsset > m_asset; + Ref< ui::ToolBarButton > m_toolToggleR; + Ref< ui::ToolBarButton > m_toolToggleG; + Ref< ui::ToolBarButton > m_toolToggleB; + Ref< ui::ToolBarButton > m_toolToggleA; Ref< TextureControl > m_textureControl; Ref< ui::StatusBar > m_statusBar; Ref< editor::PropertiesView > m_propertiesView; diff --git a/code/Render/Editor/Texture/TextureControl.cpp b/code/Render/Editor/Texture/TextureControl.cpp index f2e602ac4..6cedcd051 100644 --- a/code/Render/Editor/Texture/TextureControl.cpp +++ b/code/Render/Editor/Texture/TextureControl.cpp @@ -65,7 +65,7 @@ ui::Size TextureControl::getPreferredSize(const ui::Size& hint) const return m_bitmapSource ? m_bitmapSource->getSize(this) : ui::Size(0, 0); } -bool TextureControl::setImage(drawing::Image* image, const TextureOutput& output) +bool TextureControl::setImage(drawing::Image* image, const TextureOutput& output, uint32_t channels) { m_imageSource = nullptr; m_imageOutput = nullptr; @@ -86,6 +86,8 @@ bool TextureControl::setImage(drawing::Image* image, const TextureOutput& output // Create source image. m_imageSource = image->clone(); + + // Adjust gamma. if (!sRGB) { // Ensure image is in sRGB since that's what UI expects. @@ -191,6 +193,28 @@ bool TextureControl::setImage(drawing::Image* image, const TextureOutput& output m_imageOutput->apply(&normalizeFilter); } + // Filter channels. + if ((channels & (1 | 2 | 4 | 8)) != (1 | 2 | 4 | 8)) + { + std::wstring swizzle = L"0001"; + + if (channels & 1) + swizzle[0] = L'R'; + if (channels & 2) + swizzle[1] = L'G'; + if (channels & 4) + swizzle[2] = L'B'; + if (channels & 8) + swizzle[3] = L'A'; + + // Special case if only alpha is visible. + if (channels == 8) + swizzle = L"AAA1"; + + const drawing::SwizzleFilter swizzleFilter(swizzle); + m_imageOutput->apply(&swizzleFilter); + } + // Convert to sRGB last since that's what UI expect. { const drawing::GammaFilter gammaFilter(1.0f, 2.2f); diff --git a/code/Render/Editor/Texture/TextureControl.h b/code/Render/Editor/Texture/TextureControl.h index 448de2866..0c628a59c 100644 --- a/code/Render/Editor/Texture/TextureControl.h +++ b/code/Render/Editor/Texture/TextureControl.h @@ -45,7 +45,7 @@ class T_DLLCLASS TextureControl : public ui::Widget virtual ui::Size getPreferredSize(const ui::Size& hint) const override; - bool setImage(drawing::Image* image, const TextureOutput& output); + bool setImage(drawing::Image* image, const TextureOutput& output, uint32_t channels); bool getPixel(const ui::Point& position, Color4f& outColor) const;