Skip to content

Commit

Permalink
Add NodeViewerContext generic interface that allows to have any param…
Browse files Browse the repository at this point in the history
…eter defined into the viewer UI. It is also possible to control the toolbar from any plug-in. Also update ofxNatron.h spec to control this from OpenFX. Implementation to be finished
  • Loading branch information
MrKepzie committed May 11, 2016
1 parent dd81fc8 commit bbcfb38
Show file tree
Hide file tree
Showing 52 changed files with 2,079 additions and 161 deletions.
137 changes: 108 additions & 29 deletions Engine/Knob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,17 +237,26 @@ struct KnobHelperPrivate
KnobHolder* holder;
mutable QMutex labelMutex;
std::string label; //< the text label that will be displayed on the GUI
bool labelVisible;
std::string iconFilePath; //< an icon to replace the label
std::string iconFilePath[2]; //< an icon to replace the label (one when checked, one when unchecked, for toggable buttons)
std::string name; //< the knob can have a name different than the label displayed on GUI.
//By default this is the same as label but can be set by calling setName().

std::string originalName; //< the original name passed to setName() by the user
//By default this is the same as _description but can be set by calling setName().

// Gui related stuff
bool newLine;
bool addSeparator;
int itemSpacing;

// If this knob is supposed to be visible in the Viewer UI, this is the index at which it should be positioned
int inViewerContextIndex;
int inViewerContextAddSeparator;
int inViewerContextItemSpacing;
int inViewerContextAddNewLine;

boost::weak_ptr<KnobI> parentKnob;
mutable QMutex stateMutex; // protects IsSecret defaultIsSecret enabled
bool IsSecret, defaultIsSecret;
bool IsSecret, defaultIsSecret, inViewerContextSecret;
std::vector<bool> enabled, defaultEnabled;
bool CanUndo;
QMutex evaluateOnChangeMutex;
Expand Down Expand Up @@ -320,17 +329,21 @@ struct KnobHelperPrivate
, holder(holder_)
, labelMutex()
, label(label_)
, labelVisible(true)
, iconFilePath()
, name( label_.c_str() )
, originalName( label_.c_str() )
, newLine(true)
, addSeparator(false)
, itemSpacing(0)
, inViewerContextIndex(-1)
, inViewerContextAddSeparator(false)
, inViewerContextItemSpacing(1)
, inViewerContextAddNewLine(false)
, parentKnob()
, stateMutex()
, IsSecret(false)
, defaultIsSecret(false)
, inViewerContextSecret(false)
, enabled(dimension_)
, defaultEnabled(dimension_)
, CanUndo(true)
Expand Down Expand Up @@ -1711,6 +1724,71 @@ KnobHelper::setSpacingBetweenItems(int spacing)
_imp->itemSpacing = spacing;
}

void
KnobHelper::setInViewerContextIndex(int index)
{
_imp->inViewerContextIndex = index;
}

int
KnobHelper::getInViewerContextIndex() const
{
return _imp->inViewerContextIndex;
}

void
KnobHelper::setInViewerContextItemSpacing(int spacing)
{
_imp->inViewerContextItemSpacing = spacing;
}

int
KnobHelper::getInViewerContextItemSpacing() const
{
return _imp->inViewerContextItemSpacing;
}

void
KnobHelper::setInViewerContextAddSeparator(bool addSeparator)
{
_imp->inViewerContextAddSeparator = addSeparator;
}

bool
KnobHelper::getInViewerContextAddSeparator() const
{
return _imp->inViewerContextAddSeparator;
}

void
KnobHelper::setInViewerContextNewLineActivated(bool activated)
{
_imp->inViewerContextAddNewLine = activated;
}

bool
KnobHelper::getInViewerContextNewLineActivated() const
{
return _imp->inViewerContextAddNewLine;
}

void
KnobHelper::setInViewerContextSecret(bool secret)
{
{
QMutexLocker k(&_imp->stateMutex);
_imp->inViewerContextSecret = secret;
}
_signalSlotHandler->s_viewerContextSecretChanged();
}

bool
KnobHelper::getInViewerContextSecret() const
{
QMutexLocker k(&_imp->stateMutex);
return _imp->inViewerContextSecret;
}

void
KnobHelper::setEnabled(int dimension,
bool b)
Expand All @@ -1719,9 +1797,8 @@ KnobHelper::setEnabled(int dimension,
QMutexLocker k(&_imp->stateMutex);
_imp->enabled[dimension] = b;
}
if (_signalSlotHandler) {
_signalSlotHandler->s_enabledChanged();
}
_signalSlotHandler->s_enabledChanged();

}

void
Expand Down Expand Up @@ -1831,36 +1908,25 @@ KnobHelper::setLabel(const std::string& label)
}

void
KnobHelper::setIconLabel(const std::string& iconFilePath)
KnobHelper::setIconLabel(const std::string& iconFilePath,bool checked)
{
QMutexLocker k(&_imp->labelMutex);

_imp->iconFilePath = iconFilePath;
int idx = !checked ? 0 : 1;
_imp->iconFilePath[idx] = iconFilePath;
}

const std::string&
KnobHelper::getIconLabel() const
{
QMutexLocker k(&_imp->labelMutex);

return _imp->iconFilePath;
}

void
KnobHelper::hideLabel()
KnobHelper::getIconLabel(bool checked) const
{
QMutexLocker k(&_imp->labelMutex);

_imp->labelVisible = false;
int idx = !checked ? 0 : 1;
if (!_imp->iconFilePath[idx].empty()) {
return _imp->iconFilePath[idx];
}
int otherIdx = !checked ? 1 : 0;
return _imp->iconFilePath[otherIdx];
}

bool
KnobHelper::isLabelVisible() const
{
QMutexLocker k(&_imp->labelMutex);

return _imp->labelVisible;
}

bool
KnobHelper::hasAnimation() const
Expand Down Expand Up @@ -4393,6 +4459,19 @@ KnobHolder::~KnobHolder()
}
}

bool
KnobHolder::hasKnobWithViewerInContextUI() const
{
QMutexLocker k(&_imp->knobsMutex);
for (KnobsVec::const_iterator it = _imp->knobs.begin(); it != _imp->knobs.end(); ++it) {
int index = (*it)->getInViewerContextIndex();
if (index != -1) {
return true;
}
}
return false;
}

void
KnobHolder::setIsInitializingKnobs(bool b)
{
Expand Down
77 changes: 64 additions & 13 deletions Engine/Knob.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ class KnobSignalSlotHandler
Q_EMIT secretChanged();
}

void s_viewerContextSecretChanged()
{
Q_EMIT viewerContextSecretChanged();
}

void s_enabledChanged()
{
Q_EMIT enabledChanged();
Expand Down Expand Up @@ -273,6 +278,9 @@ public Q_SLOTS:
///Emitted when the secret state of the knob changed
void secretChanged();

///Emitted when the secret state of the knob changed in the viewer context
void viewerContextSecretChanged();

///Emitted when a dimension enabled state changed
void enabledChanged();

Expand Down Expand Up @@ -785,16 +793,11 @@ class KnobI

/**
* @brief Set an icon instead of the text label for this knob
* @param modeOff If true, this icon will be used when the parameter is an unchecked state (only relevant for
* buttons/booleans parameters), otherwise the icon will be used when the parameter is in a checked state
**/
virtual void setIconLabel(const std::string& iconFilePath) = 0;
virtual const std::string& getIconLabel() const = 0;

/**
* @brief Hide the label label on the GUI on the left of the knob. This is not dynamic
* and must be called upon the knob creation.
**/
virtual void hideLabel() = 0;
virtual bool isLabelVisible() const = 0;
virtual void setIconLabel(const std::string& iconFilePath, bool checked = false) = 0;
virtual const std::string& getIconLabel(bool checked = false) const = 0;

/**
* @brief Returns a pointer to the holder owning the knob.
Expand Down Expand Up @@ -824,6 +827,44 @@ class KnobI
**/
virtual void setSpacingBetweenItems(int spacing) = 0;

/**
* @brief Set whether the knob should have a GUI on the viewer, if so set at which index
**/
virtual void setInViewerContextIndex(int index) = 0;
virtual int getInViewerContextIndex() const = 0;

/**
* @brief Returns whether this type of knob can be instantiated in the viewer UI
**/
virtual bool supportsInViewerContext() const
{
return false;
}

/**
* @brief Set how much space (in pixels) to leave between the current parameter and the next parameter in horizontal layouts.
**/
virtual void setInViewerContextItemSpacing(int spacing) = 0;
virtual int getInViewerContextItemSpacing() const = 0;

/**
* @brief Set whether the knob should have a vertical separator after or not in the viewer
**/
virtual void setInViewerContextAddSeparator(bool addSeparator) = 0;
virtual bool getInViewerContextAddSeparator() const = 0;

/**
* @brief Set whether the viewer UI should create a new line after this parameter or not
**/
virtual void setInViewerContextNewLineActivated(bool activated) = 0;
virtual bool getInViewerContextNewLineActivated() const = 0;

/**
* @brief Set whether the knob should have its viewer GUI secret or not
**/
virtual void setInViewerContextSecret(bool secret) = 0;
virtual bool getInViewerContextSecret() const = 0;

/**
* @brief Enables/disables user interaction with the given dimension.
**/
Expand Down Expand Up @@ -1346,10 +1387,8 @@ class KnobHelper
virtual bool isAnimationEnabled() const OVERRIDE FINAL WARN_UNUSED_RETURN;
virtual std::string getLabel() const OVERRIDE FINAL WARN_UNUSED_RETURN;
void setLabel(const std::string& label) OVERRIDE FINAL;
virtual void setIconLabel(const std::string& iconFilePath) OVERRIDE FINAL;
virtual const std::string& getIconLabel() const OVERRIDE FINAL WARN_UNUSED_RETURN;
virtual void hideLabel() OVERRIDE FINAL;
virtual bool isLabelVisible() const OVERRIDE FINAL WARN_UNUSED_RETURN;
virtual void setIconLabel(const std::string& iconFilePath,bool checked = false) OVERRIDE FINAL;
virtual const std::string& getIconLabel(bool checked = false) const OVERRIDE FINAL WARN_UNUSED_RETURN;
virtual KnobHolder* getHolder() const OVERRIDE FINAL WARN_UNUSED_RETURN;
virtual void setHolder(KnobHolder* holder) OVERRIDE FINAL;
virtual int getDimension() const OVERRIDE FINAL WARN_UNUSED_RETURN;
Expand All @@ -1358,6 +1397,16 @@ class KnobHelper
virtual bool isNewLineActivated() const OVERRIDE FINAL WARN_UNUSED_RETURN;
virtual bool isSeparatorActivated() const OVERRIDE FINAL WARN_UNUSED_RETURN;
virtual void setSpacingBetweenItems(int spacing) OVERRIDE FINAL;
virtual void setInViewerContextIndex(int index) OVERRIDE FINAL;
virtual int getInViewerContextIndex() const OVERRIDE FINAL WARN_UNUSED_RETURN;
virtual void setInViewerContextItemSpacing(int spacing) OVERRIDE FINAL;
virtual int getInViewerContextItemSpacing() const OVERRIDE FINAL WARN_UNUSED_RETURN;
virtual void setInViewerContextAddSeparator(bool addSeparator) OVERRIDE FINAL;
virtual bool getInViewerContextAddSeparator() const OVERRIDE FINAL WARN_UNUSED_RETURN;
virtual void setInViewerContextNewLineActivated(bool activated) OVERRIDE FINAL;
virtual bool getInViewerContextNewLineActivated() const OVERRIDE FINAL WARN_UNUSED_RETURN;
virtual void setInViewerContextSecret(bool secret) OVERRIDE FINAL;
virtual bool getInViewerContextSecret() const OVERRIDE FINAL WARN_UNUSED_RETURN;
virtual void setEnabled(int dimension, bool b) OVERRIDE FINAL;
virtual void setDefaultEnabled(int dimension, bool b) OVERRIDE FINAL;
virtual bool isEnabled(int dimension) const OVERRIDE FINAL;
Expand Down Expand Up @@ -2195,6 +2244,8 @@ class KnobHolder
void setIsInitializingKnobs(bool b);
bool isInitializingKnobs() const;

bool hasKnobWithViewerInContextUI() const;

protected:

virtual void refreshExtraStateAfterTimeChanged(double /*time*/) {}
Expand Down
2 changes: 1 addition & 1 deletion Engine/KnobTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ KnobButton::KnobButton(KnobHolder* holder,
bool declaredByPlugin)
: Knob<bool>(holder, label, dimension, declaredByPlugin)
, _renderButton(false)
, _checkable(false)
{
//setIsPersistant(false);
}
Expand Down Expand Up @@ -1369,7 +1370,6 @@ void
KnobString::setAsLabel()
{
setAnimationEnabled(false); //< labels cannot animate
// hideLabel(); // labels do not have a label
_isLabel = true;
}

Expand Down
Loading

0 comments on commit bbcfb38

Please sign in to comment.