Skip to content

Commit

Permalink
Added a way to commit all effects everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
ypujante committed Aug 23, 2023
1 parent d518bd9 commit 29d3da4
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 36 deletions.
26 changes: 23 additions & 3 deletions src/cpp/re/edit/AppContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,10 @@ void AppContext::renderMainMenu()
{
handleUnusedTextures();
}
if(ImGui::MenuItem(ReGui_Prefix(ICON_FAC_SparklesCircleCheck, "Commit All Effects")))
{
commitTextureEffects();
}
ImGui::EndMenu();
}

Expand Down Expand Up @@ -1030,7 +1034,7 @@ void AppContext::save()
UserError errors{};
auto GUI2D = fRoot / "GUI2D";
importBuiltIns(&errors); // convert built ins into actual images first (so that cmake() can see them)
applyEffects(&errors);
applyTextureEffects(&errors);
Application::saveFile(GUI2D / "device_2D.lua", device2D(), &errors);
Application::saveFile(GUI2D / "hdgui_2D.lua", hdgui2D(), &errors);
if(fs::exists(fRoot / "CMakeLists.txt"))
Expand Down Expand Up @@ -1297,9 +1301,9 @@ void AppContext::importBuiltIns(UserError *oErrors)
}

//------------------------------------------------------------------------
// AppContext::applyEffects
// AppContext::applyTextureEffects
//------------------------------------------------------------------------
void AppContext::applyEffects(UserError *oErrors)
void AppContext::applyTextureEffects(UserError *oErrors)
{
std::vector<FilmStripFX> effects{};
fFrontPanel->fPanel.collectFilmStripEffects(effects);
Expand All @@ -1314,6 +1318,22 @@ void AppContext::applyEffects(UserError *oErrors)
fTextureManager->applyEffects(effects, oErrors);
}

//------------------------------------------------------------------------
// AppContext::commitTextureEffects
//------------------------------------------------------------------------
void AppContext::commitTextureEffects()
{
beginUndoTx("Commit image effects");
fFrontPanel->fPanel.commitTextureEffects(*this);
fBackPanel->fPanel.commitTextureEffects(*this);
if(fHasFoldedPanels)
{
fFoldedFrontPanel->fPanel.commitTextureEffects(*this);
fFoldedBackPanel->fPanel.commitTextureEffects(*this);
}
commitUndoTx();
}

//------------------------------------------------------------------------
// AppContext::renderZoomSelection
//------------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion src/cpp/re/edit/AppContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ class AppContext
void reloadDevice();
void save();
void importBuiltIns(UserError *oErrors = nullptr);
void applyEffects(UserError *oErrors = nullptr);
void applyTextureEffects(UserError *oErrors = nullptr);
void commitTextureEffects();
std::string hdgui2D() const;
std::string device2D() const;
std::string cmake() const;
Expand Down
20 changes: 10 additions & 10 deletions src/cpp/re/edit/FilmStrip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,31 +640,31 @@ std::set<FilmStrip::key_t> FilmStripMgr::importBuiltIns(std::set<FilmStrip::key_
//------------------------------------------------------------------------
// FilmStripMgr::applyEffects
//------------------------------------------------------------------------
std::optional<FilmStrip::key_t> FilmStripMgr::applyEffects(FilmStrip::key_t const &iKey,
texture::FX const &iEffects,
UserError *oErrors)
std::pair<FilmStrip::key_t, bool> FilmStripMgr::applyEffects(FilmStrip::key_t const &iKey,
texture::FX const &iEffects,
UserError *oErrors)
{
auto filmStrip = findFilmStrip(iKey);
if(filmStrip && filmStrip->isValid())
{
// no effects => return
if(!iEffects.hasAny())
return std::nullopt;
return {iKey, false};

auto keyFX = FilmStrip::computeKey(iKey, filmStrip->numFrames(), iEffects);

// do we already know about this?
auto filmStripFX = findFilmStrip(keyFX);
if(filmStripFX && filmStripFX->isValid())
return std::nullopt;
return {keyFX, false};
else
{
// no we don't so save and add to map
filmStripFX = save(keyFX, filmStrip->applyEffects(iEffects));
if(filmStripFX)
{
fFilmStrips[keyFX] = filmStripFX;
return keyFX;
return {keyFX, true};
}
else
{
Expand All @@ -674,7 +674,7 @@ std::optional<FilmStrip::key_t> FilmStripMgr::applyEffects(FilmStrip::key_t cons
}
}

return std::nullopt;
return {iKey, false};
}

//------------------------------------------------------------------------
Expand All @@ -686,9 +686,9 @@ std::set<FilmStrip::key_t> FilmStripMgr::applyEffects(std::vector<FilmStripFX> c

for(auto const &e: iEffects)
{
auto keyFX = applyEffects(e.fKey, e.fEffects, oErrors);
if(keyFX)
modifiedKeys.emplace(*keyFX);
auto [keyFX, modified] = applyEffects(e.fKey, e.fEffects, oErrors);
if(modified)
modifiedKeys.emplace(keyFX);
}

return modifiedKeys;
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/re/edit/FilmStrip.h
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ class FilmStripMgr
std::set<FilmStrip::key_t> importBuiltIns(std::set<FilmStrip::key_t> const &iKeys, UserError *oErrors = nullptr);
bool remove(FilmStrip::key_t const &iKey);

std::optional<FilmStrip::key_t> applyEffects(FilmStrip::key_t const &iKey, texture::FX const &iEffects, UserError *oErrors = nullptr);
std::pair<FilmStrip::key_t, bool> applyEffects(FilmStrip::key_t const &iKey, texture::FX const &iEffects, UserError *oErrors = nullptr);
std::set<FilmStrip::key_t> applyEffects(std::vector<FilmStripFX> const &iEffects, UserError *oErrors = nullptr);

static std::vector<FilmStrip::Source> scanDirectory(fs::path const &iDirectory);
Expand Down
29 changes: 14 additions & 15 deletions src/cpp/re/edit/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,7 @@ void Graphics::editView(AppContext &iCtx)
if(ImGui::MenuItem(ReGui_Prefix(ReGui_Icon_ResetAllEffects, "Reset All Effects")))
fParent->setBackgroundEffect("all effects (reset)", texture::kDefaultFX, MergeKey::from(&fEffects));
if(ImGui::MenuItem(ReGui_Prefix(ICON_FAC_SparklesCircleCheck, "Commit All Effects")))
{
if(hasTexture())
{
auto newKey = iCtx.applyTextureEffects(getTextureKey(), fEffects);
if(newKey)
fParent->setBackgroundKey(*newKey);
}
}
fParent->commitBackgroundEffects(iCtx);
ImGui::EndDisabled();

ImGui::EndPopup();
Expand Down Expand Up @@ -788,13 +781,7 @@ void Graphics::editView(AppContext &iCtx)
{
editView(iCtx,
fFilter,
[this](auto &k) {
update([this, &k] {
setTextureKey(k);
fFrameNumber = 0;
},
fmt::printf("Change %s graphics", getParent()->getName()));
},
[this](auto &k) { updateTextureKey(k); },
[this](auto &s) {
update([this, &s] {
if(hasTexture())
Expand Down Expand Up @@ -1055,11 +1042,23 @@ bool Graphics::copyFromAction(Attribute const *iFromAttribute)
void Graphics::setTextureKey(Texture::key_t const &iTextureKey)
{
fTexture = iTextureKey;
fFrameNumber = 0;
fDNZTexture = AppContext::GetCurrent().getTexture(iTextureKey);
fEffects = texture::kDefaultFX;
fEdited = true;
}

//------------------------------------------------------------------------
// Graphics::updateTextureKey
//------------------------------------------------------------------------
void Graphics::updateTextureKey(Texture::key_t const &iTextureKey)
{
update([this, &iTextureKey] {
setTextureKey(iTextureKey);
},
fmt::printf("Change %s graphics", getParent()->getName()));
}

//------------------------------------------------------------------------
// Graphics::initTextureKey
//------------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion src/cpp/re/edit/Graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ class Graphics : public Attribute

inline Texture const *getTexture() const { RE_EDIT_INTERNAL_ASSERT(fDNZTexture != nullptr); return fDNZTexture.get(); }
inline Texture::key_t getTextureKey() const { return std::get<Texture::key_t>(fTexture); }
void setTextureKey(Texture::key_t const &iTextureKey);
void setTextureKey(Texture::key_t const &iTextureKey); // action only
void updateTextureKey(Texture::key_t const &iTextureKey); // action with undo
void initTextureKey(Texture::key_t const &iTextureKey,
std::optional<Texture::key_t> const &iOriginalTextureKey,
texture::FX const &iEffects);
Expand Down
2 changes: 2 additions & 0 deletions src/cpp/re/edit/Panel.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ class Panel : public Editable
bool checkForErrors(AppContext &iCtx) override;

void setBackgroundKey(Texture::key_t const &iTextureKey);
void commitBackgroundEffects(AppContext &iCtx);
void commitTextureEffects(AppContext &iCtx);
void setBackgroundEffect(char const *iName, texture::FX const &fx, MergeKey const &iMergeKey);
void setOptions(std::vector<std::string> const &iOptions);
int addWidget(AppContext &iCtx, std::unique_ptr<Widget> iWidget, bool iMakeSingleSelected, char const *iUndoActionName = "Add");
Expand Down
25 changes: 25 additions & 0 deletions src/cpp/re/edit/PanelActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,31 @@ void Panel::setBackgroundKey(Texture::key_t const &iTextureKey)
MergeKey::from(&fGraphics.fTextureKey));
}

//------------------------------------------------------------------------
// Panel::commitBackgroundEffects
//------------------------------------------------------------------------
void Panel::commitBackgroundEffects(AppContext &iCtx)
{
if(fGraphics.hasTexture() && fGraphics.fEffects.hasAny())
{
auto newKey = iCtx.applyTextureEffects(fGraphics.getTextureKey(), fGraphics.fEffects);
if(newKey)
setBackgroundKey(*newKey);
}
}

//------------------------------------------------------------------------
// Panel::commitTextureEffects
//------------------------------------------------------------------------
void Panel::commitTextureEffects(AppContext &iCtx)
{
iCtx.beginUndoTx(fmt::printf("Commit image effects (%s)", getName()));
commitBackgroundEffects(iCtx);
for(auto &[id, w]: fWidgets)
w->commitTextureEffects(iCtx);
iCtx.commitUndoTx();
}

//------------------------------------------------------------------------
// Panel::setBackgroundEffect
//------------------------------------------------------------------------
Expand Down
10 changes: 6 additions & 4 deletions src/cpp/re/edit/TextureManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,12 @@ std::optional<FilmStrip::key_t> TextureManager::applyEffects(FilmStrip::key_t co
texture::FX const &iEffects,
UserError *oErrors)
{
auto key = fFilmStripMgr->applyEffects(iKey, iEffects, oErrors);
if(key)
updateTexture(*key);
return key;
auto [keyFX, needsUpdate] = fFilmStripMgr->applyEffects(iKey, iEffects, oErrors);
if(needsUpdate)
{
updateTexture(keyFX);
}
return keyFX != iKey ? std::optional<FilmStrip::key_t>{keyFX} : std::nullopt;
}

//------------------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions src/cpp/re/edit/TextureManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ class TextureManager
std::optional<FilmStrip::key_t> importTexture(fs::path const &iTexturePath);
void importBuiltIns(std::set<FilmStrip::key_t> const &iKeys, UserError *oErrors = nullptr);
void applyEffects(std::vector<FilmStripFX> const &iEffects, UserError *oErrors = nullptr);

/**
* If no effects or no filmstrip found for `iKey` returns `std::nullopt` otherwise returns the key of the new texture */
std::optional<FilmStrip::key_t> applyEffects(FilmStrip::key_t const &iKey, texture::FX const &iEffects, UserError *oErrors = nullptr);

bool remove(FilmStrip::key_t const &iKey);

protected:
Expand Down
1 change: 1 addition & 0 deletions src/cpp/re/edit/Widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class Widget : public Editable
void init(AppContext &iCtx);
void draw(AppContext &iCtx, ReGui::Canvas &iCanvas);
void editView(AppContext &iCtx);
void commitTextureEffects(AppContext &iCtx);
bool checkForErrors(AppContext &iCtx) override;
void markEdited() override;

Expand Down
16 changes: 15 additions & 1 deletion src/cpp/re/edit/WidgetActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ void Widget::setVisibility(widget::Visibility iVisibility)
MergeKey::from(&fName));
}


//------------------------------------------------------------------------
// Widget::toggleVisibility
//------------------------------------------------------------------------
Expand All @@ -151,5 +150,20 @@ void Widget::toggleVisibility()
setVisibility(isHidden() ? widget::Visibility::kManualVisible : widget::Visibility::kManualHidden);
}

//------------------------------------------------------------------------
// Widget::commitTextureEffects
//------------------------------------------------------------------------
void Widget::commitTextureEffects(AppContext &iCtx)
{
if(fGraphics->hasTexture() && fGraphics->fEffects.hasAny())
{
auto newKey = iCtx.applyTextureEffects(fGraphics->getTextureKey(), fGraphics->fEffects);
if(newKey)
{
fGraphics->updateTextureKey(*newKey);
fEdited = fGraphics->isEdited();
}
}
}

}

0 comments on commit 29d3da4

Please sign in to comment.