diff --git a/rtdata/languages/default b/rtdata/languages/default index c25bf79ff..e9386e350 100644 --- a/rtdata/languages/default +++ b/rtdata/languages/default @@ -725,11 +725,11 @@ HISTORY_MSG_490;HDR TM - Amount HISTORY_MSG_491;White Balance HISTORY_MSG_492;RGB Curves HISTORY_MSG_493;L*a*b* Adjustments -HISTORY_MSG_494;Local Contrast -HISTORY_MSG_495;Local Contrast - Radius -HISTORY_MSG_496;Local Contrast - Amount -HISTORY_MSG_497;Local Contrast - Darkness -HISTORY_MSG_498;Local Contrast - Lightness +HISTORY_MSG_LOCALCONTRAST_ENABLED;Local Contrast +HISTORY_MSG_LOCALCONTRAST_RADIUS;Local Contrast - Radius +HISTORY_MSG_LOCALCONTRAST_AMOUNT;Local Contrast - Amount +HISTORY_MSG_LOCALCONTRAST_DARKNESS;Local Contrast - Darkness +HISTORY_MSG_LOCALCONTRAST_LIGHTNESS;Local Contrast - Lightness HISTORY_NEWSNAPSHOT;Add HISTORY_NEWSNAPSHOT_TOOLTIP;Shortcut: Alt-s HISTORY_SNAPSHOT;Snapshot diff --git a/rtengine/improccoordinator.cc b/rtengine/improccoordinator.cc index 9c80eed9e..6403612d6 100644 --- a/rtengine/improccoordinator.cc +++ b/rtengine/improccoordinator.cc @@ -1378,7 +1378,8 @@ ProcParams* ImProcCoordinator::beginUpdateParams () void ImProcCoordinator::endUpdateParams (ProcEvent change) { - endUpdateParams ( refreshmap[ (int)change] ); + int action = RefreshMapper::getInstance()->getAction(change); + endUpdateParams(action); } void ImProcCoordinator::endUpdateParams (int changeFlags) diff --git a/rtengine/procevents.h b/rtengine/procevents.h index faffbe780..5658a346b 100644 --- a/rtengine/procevents.h +++ b/rtengine/procevents.h @@ -26,7 +26,7 @@ namespace rtengine // Aligned so the first entry starts on line 30 -enum ProcEvent { +enum ProcEventCode { EvPhotoLoaded = 0, EvProfileLoaded = 1, EvProfileChanged = 2, @@ -520,15 +520,31 @@ enum ProcEvent { EvWBEnabled = 490, EvRGBEnabled = 491, EvLEnabled = 492, - EvLocalContrastEnabled = 493, - EvLocalContrastRadius = 494, - EvLocalContrastAmount = 495, - EvLocalContrastDarkness = 496, - EvLocalContrastLightness = 497, NUMOFEVENTS }; + + +class ProcEvent { +public: + ProcEvent(): code_(0) {} + ProcEvent(ProcEventCode code): code_(code) {} + explicit ProcEvent(int code): code_(code) {} + operator int() { return code_; } + +private: + int code_; +}; + + +inline bool operator==(ProcEvent a, ProcEvent b) { return int(a) == int(b); } +inline bool operator==(ProcEvent a, ProcEventCode b) { return int(a) == int(b); } +inline bool operator==(ProcEventCode a, ProcEvent b) { return int(a) == int(b); } +inline bool operator!=(ProcEvent a, ProcEvent b) { return int(a) != int(b); } +inline bool operator!=(ProcEvent a, ProcEventCode b) { return int(a) != int(b); } +inline bool operator!=(ProcEventCode a, ProcEvent b) { return int(a) != int(b); } + } #endif diff --git a/rtengine/refreshmap.cc b/rtengine/refreshmap.cc index 96575b464..93fe01f0b 100644 --- a/rtengine/refreshmap.cc +++ b/rtengine/refreshmap.cc @@ -519,11 +519,48 @@ int refreshmap[rtengine::NUMOFEVENTS] = { HDR, // EvTMFattalAmount ALLNORAW, // EvWBEnabled RGBCURVE, // EvRGBEnabled - LUMINANCECURVE, // EvLEnabled - RGBCURVE, // EvLocalContastEnabled - RGBCURVE, // EvLocalContrastRadius - RGBCURVE, // EvLocalContrastAmount - RGBCURVE, // EvLocalContrastDarkness - RGBCURVE // EvLocalContrastLightness + LUMINANCECURVE // EvLEnabled }; + +namespace rtengine { + +RefreshMapper::RefreshMapper(): + next_event_(rtengine::NUMOFEVENTS) +{ + for (int event = 0; event < rtengine::NUMOFEVENTS; ++event) { + actions_[event] = refreshmap[event]; + } +} + + +ProcEvent RefreshMapper::newEvent() +{ + return ProcEvent(++next_event_); +} + + +void RefreshMapper::mapEvent(ProcEvent event, int action) +{ + actions_[event] = action; +} + + +int RefreshMapper::getAction(ProcEvent event) const +{ + auto it = actions_.find(event); + if (it == actions_.end()) { + return 0; + } else { + return it->second; + } +} + + +RefreshMapper *RefreshMapper::getInstance() +{ + static RefreshMapper instance; + return &instance; +} + +} // namespace rtengine diff --git a/rtengine/refreshmap.h b/rtengine/refreshmap.h index cea6b3c8e..09059470b 100644 --- a/rtengine/refreshmap.h +++ b/rtengine/refreshmap.h @@ -19,6 +19,9 @@ #ifndef __REFRESHMAP__ #define __REFRESHMAP__ +#include +#include "procevents.h" + // Use M_VOID if you wish to update the proc params without updating the preview at all ! #define M_VOID (1<<17) // Use M_MINUPDATE if you wish to update the preview without modifying the image (think about it like a "refreshPreview") @@ -74,4 +77,23 @@ #define OUTPUTPROFILE M_MONITOR extern int refreshmap[]; + +namespace rtengine { + +class RefreshMapper { +public: + static RefreshMapper *getInstance(); + ProcEvent newEvent(); + void mapEvent(ProcEvent event, int action); + int getAction(ProcEvent event) const; + +private: + RefreshMapper(); + + int next_event_; + std::unordered_map actions_; +}; + +} // namespace rtengine + #endif diff --git a/rtgui/CMakeLists.txt b/rtgui/CMakeLists.txt index e42666625..222ee2550 100644 --- a/rtgui/CMakeLists.txt +++ b/rtgui/CMakeLists.txt @@ -149,6 +149,7 @@ set(NONCLISOURCEFILES zoompanel.cc fattaltonemap.cc localcontrast.cc + eventmapper.cc ) include_directories(BEFORE "${CMAKE_CURRENT_BINARY_DIR}") diff --git a/rtgui/eventmapper.cc b/rtgui/eventmapper.cc new file mode 100644 index 000000000..de5258413 --- /dev/null +++ b/rtgui/eventmapper.cc @@ -0,0 +1,63 @@ +/* -*- C++ -*- + * + * This file is part of RawTherapee. + * + * Copyright (c) 2017 Alberto Griggio + * + * RawTherapee is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * RawTherapee is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with RawTherapee. If not, see . + */ + +#include "eventmapper.h" + + +ProcEventMapper::ProcEventMapper() +{ + for (int event = 0; event < rtengine::NUMOFEVENTS; ++event) { + history_msgs_[event] = "HISTORY_MSG_" + std::to_string(event + 1); + } +} + + +ProcEventMapper *ProcEventMapper::getInstance() +{ + static ProcEventMapper instance; + return &instance; +} + + +rtengine::ProcEvent ProcEventMapper::newEvent(int action, const std::string &history_msg) +{ + rtengine::ProcEvent event = rtengine::RefreshMapper::getInstance()->newEvent(); + rtengine::RefreshMapper::getInstance()->mapEvent(event, action); + + if (history_msg.empty()) { + history_msgs_[event] = "HISTORY_MSG_" + std::to_string(event + 1); + } else { + history_msgs_[event] = history_msg; + } + + return event; +} + + +const std::string &ProcEventMapper::getHistoryMsg(rtengine::ProcEvent event) const +{ + static std::string empty; + auto it = history_msgs_.find(event); + if (it == history_msgs_.end()) { + return empty; + } else { + return it->second; + } +} diff --git a/rtgui/eventmapper.h b/rtgui/eventmapper.h new file mode 100644 index 000000000..87ccc1d9b --- /dev/null +++ b/rtgui/eventmapper.h @@ -0,0 +1,37 @@ +/* -*- C++ -*- + * + * This file is part of RawTherapee. + * + * Copyright (c) 2017 Alberto Griggio + * + * RawTherapee is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * RawTherapee is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with RawTherapee. If not, see . + */ +#pragma once + +#include +#include +#include "../rtengine/refreshmap.h" + + +class ProcEventMapper { +public: + static ProcEventMapper *getInstance(); + rtengine::ProcEvent newEvent(int action, const std::string &history_msg=""); + const std::string &getHistoryMsg(rtengine::ProcEvent event) const; + +private: + ProcEventMapper(); + + std::unordered_map history_msgs_; +}; diff --git a/rtgui/history.cc b/rtgui/history.cc index d62fcdb30..6b07ee7b2 100644 --- a/rtgui/history.cc +++ b/rtgui/history.cc @@ -20,6 +20,7 @@ #include "multilangmgr.h" #include "rtimage.h" #include "guiutils.h" +#include "eventmapper.h" using namespace rtengine; using namespace rtengine::procparams; @@ -231,7 +232,7 @@ void History::procParamsChanged (ProcParams* params, ProcEvent ev, Glib::ustring } // construct formatted list content - Glib::ustring text = M("HISTORY_MSG_" + std::to_string(ev + 1)); + Glib::ustring text = M(ProcEventMapper::getInstance()->getHistoryMsg(ev)); Glib::RefPtr selection = hTreeView->get_selection(); Gtk::TreeModel::iterator iter = selection->get_selected(); diff --git a/rtgui/localcontrast.cc b/rtgui/localcontrast.cc index 3c2d47786..8e1b5660e 100644 --- a/rtgui/localcontrast.cc +++ b/rtgui/localcontrast.cc @@ -18,6 +18,7 @@ * along with RawTherapee. If not, see . */ #include "localcontrast.h" +#include "eventmapper.h" #include #include @@ -26,6 +27,13 @@ using namespace rtengine::procparams; LocalContrast::LocalContrast(): FoldableToolPanel(this, "localcontrast", M("TP_LOCALCONTRAST_LABEL"), false, true) { + auto m = ProcEventMapper::getInstance(); + EvLocalContrastEnabled = m->newEvent(RGBCURVE, "HISTORY_MSG_LOCALCONTRAST_ENABLED"); + EvLocalContrastRadius = m->newEvent(RGBCURVE, "HISTORY_MSG_LOCALCONTRAST_RADIUS"); + EvLocalContrastAmount = m->newEvent(RGBCURVE, "HISTORY_MSG_LOCALCONTRAST_AMOUNT"); + EvLocalContrastDarkness = m->newEvent(RGBCURVE, "HISTORY_MSG_LOCALCONTRAST_DARKNESS"); + EvLocalContrastLightness = m->newEvent(RGBCURVE, "HISTORY_MSG_LOCALCONTRAST_LIGHTNESS"); + radius = Gtk::manage(new Adjuster(M("TP_LOCALCONTRAST_RADIUS"), 3., 200., 1., 8.)); amount = Gtk::manage(new Adjuster(M("TP_LOCALCONTRAST_AMOUNT"), 0., 1., 0.01, 0.2)); darkness = Gtk::manage(new Adjuster(M("TP_LOCALCONTRAST_DARKNESS"), 0., 4., 0.1, 1.)); diff --git a/rtgui/localcontrast.h b/rtgui/localcontrast.h index 858d860a3..d3a4e54d5 100644 --- a/rtgui/localcontrast.h +++ b/rtgui/localcontrast.h @@ -25,12 +25,18 @@ class LocalContrast: public ToolParamBlock, public AdjusterListener, public FoldableToolPanel { -protected: +private: Adjuster *radius; Adjuster *amount; Adjuster *darkness; Adjuster *lightness; + rtengine::ProcEvent EvLocalContrastEnabled; + rtengine::ProcEvent EvLocalContrastRadius; + rtengine::ProcEvent EvLocalContrastAmount; + rtengine::ProcEvent EvLocalContrastDarkness; + rtengine::ProcEvent EvLocalContrastLightness; + public: LocalContrast(); diff --git a/rtgui/toolpanelcoord.cc b/rtgui/toolpanelcoord.cc index 1b77379bb..318ebf55b 100644 --- a/rtgui/toolpanelcoord.cc +++ b/rtgui/toolpanelcoord.cc @@ -315,7 +315,7 @@ void ToolPanelCoordinator::panelChanged (rtengine::ProcEvent event, const Glib:: return; } - int changeFlags = refreshmap[ (int)event]; + int changeFlags = rtengine::RefreshMapper::getInstance()->getAction(event); ProcParams* params = ipc->beginUpdateParams (); @@ -327,7 +327,7 @@ void ToolPanelCoordinator::panelChanged (rtengine::ProcEvent event, const Glib:: if (event == rtengine::EvCTHFlip || event == rtengine::EvCTVFlip) { if (fabs (params->rotate.degree) > 0.001) { params->rotate.degree *= -1; - changeFlags |= refreshmap[ (int)rtengine::EvROTDegree]; + changeFlags |= rtengine::RefreshMapper::getInstance()->getAction(rtengine::EvROTDegree); rotate->read (params); } } @@ -446,7 +446,7 @@ void ToolPanelCoordinator::profileChange (const PartialProfile *nparams, rtengi // start the IPC processing if (filterRawRefresh) { - ipc->endUpdateParams ( refreshmap[ (int)event] & ALLNORAW ); + ipc->endUpdateParams ( rtengine::RefreshMapper::getInstance()->getAction(event) & ALLNORAW ); } else { ipc->endUpdateParams (event); }