Esempio n. 1
0
// function reacting to pen motion
static OfxStatus
interactPenMotion(OfxImageEffectHandle  pluginInstance,
		  OfxInteractHandle interactInstance,	
		  OfxPropertySetHandle inArgs)
{
  // get my data handle
  MyInteractData *data = getInteractData(interactInstance);

  // Have we grabbed on a pen down already?
  if(data->selected) {
    // get the project size as we are normalising to this
    OfxPointD projSize, projOffset;
    ofxuGetProjectSetup(pluginInstance, projSize, projOffset);

    // get the pen position and normalise that
    OfxPointD penPos;
    gPropHost->propGetDoubleN(inArgs, kOfxInteractPropPenPosition, 2, &penPos.x);
    penPos.x = (penPos.x - projOffset.x)/projSize.x;
    penPos.y = (penPos.y - projOffset.y)/projSize.y;

    // set the value of the 'point' param
    gParamHost->paramSetValue(data->pointParam, penPos.x, penPos.y);
    return kOfxStatOK;
  }
  return kOfxStatReplyDefault;
}
Esempio n. 2
0
static OfxStatus
interactPenDown(OfxImageEffectHandle  pluginInstance, 
		OfxInteractHandle interactInstance,	
		OfxPropertySetHandle inArgs)
{
  // get my data handle
  MyInteractData *data = getInteractData(interactInstance);

  // get the point param's value
  double x, y;
  gParamHost->paramGetValue(data->pointParam, &x, &y);

  // get the size of a pixel on screen
  double pixelScale[2];
  ofxuGetInteractPixelScale(inArgs, pixelScale);

  // see if the pen is within 5 screen pixels of the point, in which case, select it
  double penPos[2];
  gPropHost->propGetDoubleN(inArgs, kOfxInteractPropPenPosition, 2, penPos);
  if(fabs(x - penPos[0]) < 5 * pixelScale[0] && fabs(y - penPos[1]) < 5 * pixelScale[1]) {
    data->selected = true;   
    return kOfxStatOK;
  }
  return kOfxStatReplyDefault;
}
Esempio n. 3
0
static OfxStatus
interactPenDown(OfxImageEffectHandle  pluginInstance, 
		OfxInteractHandle interactInstance,	
		OfxPropertySetHandle inArgs)
{
  // get my data handle
  MyInteractData *data = getInteractData(interactInstance);

  // get the project size as we are normalising to this
  OfxPointD projSize, projOffset;
  ofxuGetProjectSetup(pluginInstance, projSize, projOffset);

  // get the point param's value
  double x, y;
  gParamHost->paramGetValue(data->pointParam, &x, &y);

  // scale it up to the project size as it is a normalised spatial parameter
  x = projOffset.x + x * projSize.x;
  y = projOffset.y + y * projSize.y;

  // get the size of a pixel on screen
  double pixelScale[2];
  ofxuGetInteractPixelScale(inArgs, pixelScale);

  // see if the pen is within 5 screen pixels of the point, in which case, select it
  double penPos[2];
  gPropHost->propGetDoubleN(inArgs, kOfxInteractPropPenPosition, 2, penPos);
  if(fabs(x - penPos[0]) < 5 * pixelScale[0] && fabs(y - penPos[1]) < 5 * pixelScale[1]) {
    data->selected = true;   
    return kOfxStatOK;
  }
  return kOfxStatReplyDefault;
}
Esempio n. 4
0
// destruction of an interact instance
static OfxStatus 
interactDestroyInstance(OfxImageEffectHandle  /*pluginInstance*/,
			OfxInteractHandle interactInstance)
{
  MyInteractData *data = getInteractData(interactInstance);
  delete data;
  return kOfxStatOK;
}
Esempio n. 5
0
// draw an interact instance
static OfxStatus 
interactDraw(OfxImageEffectHandle pluginInstance, 
	     OfxInteractHandle interactInstance,
	     OfxPropertySetHandle drawArgs)
{
  OfxStatus err;
  // get my private interact data
  MyInteractData *data = getInteractData(interactInstance);

  // get the project size
  OfxPointD projSize, projOffset;
  ofxuGetProjectSetup(pluginInstance, projSize, projOffset);

  // get the size of a pixel in the current projection
  double pixelScale[2];
  ofxuGetInteractPixelScale(drawArgs, pixelScale);

  // get my param's value
  double x, y;
  if((err = getCustomParam(pluginInstance, x, y)) != kOfxStatOK)
    return err;

  // scale it up to the project size as it is normalised
  x = projOffset.x + x * projSize.x;
  y = projOffset.y + y * projSize.y;

  // make the xhair a constant size on screen by scaling by the pixel scale
  float dx = kXHairSize * pixelScale[0];
  float dy = kXHairSize * pixelScale[1];

  // if the we have selected the Xhair, draw it highlit
  if(data->selected)
    glColor3f(1, 1, 1);
  else
    glColor3f(1, 0, 0);

  // Draw a cross hair, the current coordinate system aligns with the image plane.
  glPushMatrix();
  
  glTranslated(x, y, 0);

  glBegin(GL_LINES);

  glVertex2f(-dx, 0);
  glVertex2f(dx, 0);

  glVertex2f(0, -dy);
  glVertex2f(0, dy);

  glEnd();
  

  glPopMatrix();

  return kOfxStatOK;
}
Esempio n. 6
0
static OfxStatus interactKeyUp (OfxImageEffectHandle  effect, OfxInteractHandle interactInstance, OfxPropertySetHandle inArgs)
{
	MyInteractData *data = getInteractData(interactInstance);

	int key;
	gPropHost->propGetInt (inArgs, kOfxPropKeySym, 0, &key);
	if (key == kOfxKey_Shift_L || key == kOfxKey_Shift_R)
		data->Shift = false;
	
	return kOfxStatOK;
}
Esempio n. 7
0
static OfxStatus
interactPenUp(OfxImageEffectHandle  /*pluginInstance*/,
		OfxInteractHandle interactInstance,
		OfxPropertySetHandle /*inArgs*/)
{
  // get my data handle
  MyInteractData *data = getInteractData(interactInstance);
  
  if(data->selected) {
    // pen's gone up, deselect
    data->selected = false;
    return kOfxStatOK;
  }
  return kOfxStatReplyDefault;
}
Esempio n. 8
0
// draw an interact instance
static OfxStatus 
interactDraw(OfxImageEffectHandle  pluginInstance,
	     OfxInteractHandle interactInstance,
	     OfxPropertySetHandle drawArgs)
{
  // get my private interact data
  MyInteractData *data = getInteractData(interactInstance);

  // get the size of a pixel in the current projection
  double pixelScale[2];
  ofxuGetInteractPixelScale(drawArgs, pixelScale);

  // get my param's value
  double x, y;
  gParamHost->paramGetValue(data->pointParam, &x, &y);

  // make the xhair a constant size on screen by scaling by the pixel scale
  float dx = kXHairSize * pixelScale[0];
  float dy = kXHairSize * pixelScale[1];

  // if the we have selected the Xhair, draw it highlit
  if(data->selected)
    glColor3f(1, 1, 1);
  else
    glColor3f(1, 0, 0);

  // Draw a cross hair, the current coordinate system aligns with the image plane.
  glPushMatrix();
  
  glTranslated(x, y, 0);

  glBegin(GL_LINES);

  glVertex2f(-dx, 0);
  glVertex2f(dx, 0);

  glVertex2f(0, -dy);
  glVertex2f(0, dy);

  glEnd();
  

  glPopMatrix();

  return kOfxStatOK;
}
Esempio n. 9
0
static OfxStatus interactPenDown(OfxImageEffectHandle  effect, OfxInteractHandle interactInstance, OfxPropertySetHandle inArgs)
{
	// get my data handle
	MyInteractData *data = getInteractData(interactInstance);

	double penPos[2];
	gPropHost->propGetDoubleN(inArgs, kOfxInteractPropPenPosition, 2, penPos);

	Instance *instance = (Instance*)ofxuGetEffectInstanceData(effect);

	// Get the image size
	const std::pair<int, int> &size = instance->Mask.getSize ();
	data->DownX = (int)penPos[0];
	data->DownY = size.second-(int)penPos[1]-1;
	data->Down = true;

	return kOfxStatOK;
}
Esempio n. 10
0
// function reacting to pen motion
static OfxStatus
interactPenMotion(OfxImageEffectHandle  pluginInstance,
		  OfxInteractHandle interactInstance,	
		  OfxPropertySetHandle inArgs)
{
  // get my data handle
  MyInteractData *data = getInteractData(interactInstance);

  // Have we grabbed on a pen down already?
  if(data->selected) {
    // get the pen position
    OfxPointD penPos;
    gPropHost->propGetDoubleN(inArgs, kOfxInteractPropPenPosition, 2, &penPos.x);

    // set the value of the 'point' param
    gParamHost->paramSetValue(data->pointParam, penPos.x, penPos.y);
    return kOfxStatOK;
  }
  return kOfxStatReplyDefault;
}
Esempio n. 11
0
// draw an interact instance
static OfxStatus interactDraw(OfxImageEffectHandle  effect, OfxInteractHandle interactInstance, OfxPropertySetHandle drawArgs)
{
	// get my private interact data
	MyInteractData *data = getInteractData(interactInstance);
	Instance *instance = (Instance*)ofxuGetEffectInstanceData(effect);

	if (data->Down)
	{
		double penPos[2];
		gPropHost->propGetDoubleN(drawArgs, kOfxInteractPropPenPosition, 2, penPos);

		// Get the image size
		const std::pair<int, int> &size = instance->Mask.getSize ();
		const float x0 = (float)data->DownX;
		const float y0 = size.second-(float)data->DownY-1;
		const float x1 = (float)penPos[0];
		const float y1 = (float)penPos[1];

		glPushAttrib (GL_ENABLE_BIT|GL_CURRENT_BIT);
			// if the we have selected the Xhair, draw it highlit
			glColor3f(1, 1, 1);
		
			glEnable(GL_COLOR_LOGIC_OP);
			glLogicOp(GL_XOR);
			glLineStipple(1, 0xF0F0);
			glEnable(GL_LINE_STIPPLE);

			glBegin(GL_LINE_STRIP);

				glVertex2f(x0, y0);
				glVertex2f(x1, y0);
				glVertex2f(x1, y1);
				glVertex2f(x0, y1);
				glVertex2f(x0, y0);

			glEnd();
		glPopAttrib ();
	}

	return kOfxStatOK;
}
Esempio n. 12
0
static OfxStatus interactPenUp(OfxImageEffectHandle  effect, OfxInteractHandle interactInstance, OfxPropertySetHandle inArgs)
{
	// get my data handle
	MyInteractData *data = getInteractData(interactInstance);
	Instance *instance = (Instance*)ofxuGetEffectInstanceData(effect);

	double penPos[2];
	gPropHost->propGetDoubleN(inArgs, kOfxInteractPropPenPosition, 2, penPos);

	if (data->Down)
	{
		// Get the image size
		const std::pair<int, int> &size = instance->Mask.getSize ();
		const int upX = (int)penPos[0];
		const int upY = size.second-(int)penPos[1]-1;

		std::set<std::string> names;
		openexrid::Sample sample;

		const int alpha = instance->Mask.findSlice ("A");

		const int maxX = std::min (std::max (upX, data->DownX)+1, size.first);
		const int maxY = std::min (std::max (upY, data->DownY)+1, size.second);
		for (int y = std::max (std::min (upY, data->DownY), 0); y < maxY; ++y)
		for (int x = std::max (std::min (upX, data->DownX), 0); x < maxX; ++x)
 		{
 			// Get the max coverage sample in the pixel
			float maxCoverage = 0;
			uint32_t maxId = ~0U;
			const int sampleN = instance->Mask.getSampleN (x, y);
			for (int s = 0; s < sampleN; ++s)
			{
				openexrid::Sample sample;
				instance->Mask.getSample (x, y, s, sample);
				if (alpha == -1 || sample.Values[alpha] > maxCoverage)
				{
					maxId = sample.Id;
					if (alpha != -1)
						maxCoverage = sample.Values[alpha];
				}
			}

			// Found something ?
			if (maxId != ~0U)
			{
				const char *name = instance->Mask.getName (maxId);
				names.insert (escapeRegExp (name));
			}
		}
 
		// Get the old pattern
		const char *_oldPattern;
		gParamHost->paramGetValue (data->patternParam, &_oldPattern);
		std::string oldPattern = _oldPattern;
		
		/* Nuke escapes the \ of the text parameter */
		std::set<std::string> oldNames (split (oldPattern.c_str (), "\n\r"));

		// Shift ?
		if (data->Shift)
		{
			// Reverse the selection for the previously selected names
			for (const auto &name : oldNames)
			{
				// Try insert
				auto r = names.insert (name);

				// Already there, remove it
				if (!r.second)
					names.erase (r.first);
			}
		}

		// get the point param's value
		std::string pattern = join (names, "\n");
		gParamHost->paramSetValue(data->patternParam, pattern.c_str ());
		data->Down = false;
	}
	return kOfxStatOK;
}