Skip to content

Commit

Permalink
Engine/Python: add missing func Double2DParam::setUsePointInteract()
Browse files Browse the repository at this point in the history
  • Loading branch information
devernay committed Apr 23, 2018
1 parent d410667 commit d4be1e4
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Engine/EngineFwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ class PlanarTrackLayer;
class Plugin;
class PluginGroupNode;
class PluginMemory;
class PointOverlayInteract;
class PrecompNode;
class ProcessHandler;
class ProcessInputChannel;
Expand Down Expand Up @@ -455,6 +456,7 @@ typedef boost::shared_ptr<PlanarTrackLayer> PlanarTrackLayerPtr;
typedef boost::shared_ptr<Plugin> PluginPtr;
typedef boost::shared_ptr<PluginGroupNode> PluginGroupNodePtr;
typedef boost::shared_ptr<PluginMemory> PluginMemoryPtr;
typedef boost::shared_ptr<PointOverlayInteract> PointOverlayInteractPtr;
typedef boost::shared_ptr<PrecompNode> PrecompNodePtr;
typedef boost::shared_ptr<ProcessHandler> ProcessHandlerPtr;
typedef boost::shared_ptr<Project> ProjectPtr;
Expand Down
10 changes: 10 additions & 0 deletions Engine/PointOverlayInteract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,16 @@ PointOverlayInteract::fetchKnobs(const std::map<std::string, std::string>& knobs
_imp->interactive = getEffectKnobByRole<KnobBool>(knobs, "interactive", 1, true);
}

std::string
PointOverlayInteract::getName()
{
KnobDoublePtr knob = _imp->param.lock();

if (knob) {
return knob->getName();
}
return "";
}

void
PointOverlayInteract::drawOverlay(TimeValue time,
Expand Down
2 changes: 2 additions & 0 deletions Engine/PointOverlayInteract.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class PointOverlayInteract : public OverlayInteractBase
PointOverlayInteract();

virtual ~PointOverlayInteract();

std::string getName();

private:

Expand Down
56 changes: 55 additions & 1 deletion Engine/PyParameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ GCC_DIAG_ON(unused-parameter)
#include "Engine/Project.h"
#include "Engine/ViewIdx.h"
#include "Engine/LoadKnobsCompat.h"

#include "Engine/PointOverlayInteract.h"
#include "Engine/PyAppInstance.h"
#include "Engine/PyNode.h"
#include "Engine/PyItemsTable.h"
Expand Down Expand Up @@ -2218,6 +2218,60 @@ Double2DParam::set(double x,
}


void
Double2DParam::setUsePointInteract(bool use)
{
KnobDoublePtr knob = _doubleKnob.lock();
if (!knob) {
return;
}
// Natron 2 version:
//return knob->setHasHostOverlayHandle(use);

// Natron 3 version:
KnobHolderPtr holder = knob->getHolder();
if (!holder) {
return;
}
NodePtr node;
EffectInstancePtr isEffect = toEffectInstance(holder);

if (!isEffect) {
return;
}
std::list<OverlayInteractBasePtr> overlays;
isEffect->getOverlays(eOverlayViewportTypeViewer, &overlays);
std::string name = knob->getName();
// check if PointOverlayInteract already exists for this knob
std::list<OverlayInteractBasePtr>::iterator it;
PointOverlayInteractPtr found;
for(it = overlays.begin(); it != overlays.end(); ++it) {
PointOverlayInteractPtr found = boost::dynamic_pointer_cast<PointOverlayInteract>(*it);
if (found && found->getName() == name) {
// we found a PointOverlayInteract associated to this param name
break;
}
}
if (use) {
// create it if it doesn't exist, else do nothing
if ( it == overlays.end() ) {
assert(!found);
// same code as in OfxDouble2DInstance::OfxDouble2DInstance()
boost::shared_ptr<PointOverlayInteract> interact(new PointOverlayInteract());
std::map<std::string,std::string> knobs;
knobs["position"] = name;
isEffect->registerOverlay(eOverlayViewportTypeViewer, interact, knobs);
}
} else {
// remove it if it exists, else do nothing
if ( it != overlays.end() ) {
assert(found);
isEffect->removeOverlay(eOverlayViewportTypeViewer, found);
}
}
}


void
Double2DParam::setCanAutoFoldDimensions(bool can)
{
Expand Down

0 comments on commit d4be1e4

Please sign in to comment.