Ejemplo n.º 1
0
//
// DrawSelf
//
// Draw the control using currently registered callbacks
//
void ICGrid::DrawSelf(PaintInfo &pi)
{
  // Draw a frame
  DrawCtrlFrame(pi);

  // Do we have a cell iteration callback
  if (cellFunc)
  {
    // Window top left pixel position
    U32 xp1 = pi.client.p0.x;
    U32 yp1 = pi.client.p0.y;

    // Initial pixel positions for each axis (changes for flipping)
    U32 xip = xFlip ? xp1 + gridSize.x * cellSize.x - cellSize.x : xp1;
    U32 yip = yFlip ? yp1 + gridSize.y * cellSize.y - cellSize.y : yp1;

    // Draw the grid
    for (U32 x = 0, px = xip; x < gridSize.x; x++, px = xFlip ? (px - cellSize.x) : (px + cellSize.x))
    {
      for (U32 y = 0, py = yip; y < gridSize.y; y++, py = yFlip ? (py - cellSize.y) : (py + cellSize.y))
      {
        // Get the color from the callback
        Color color = cellFunc(context, x, y);

        // And paint this cell
        IFace::RenderRectangle(ClipRect(px, py, px + cellSize.x, py + cellSize.y), color);
      }
    }

    // Do we have a post-iteration callback
    if (postFunc)
    {
      // Setup paint info
      postPaintInfo = &pi;

      // Trigger the callback
      postFunc(this);

      // Clear data
      postPaintInfo = NULL;
    }

    // Hackville
    if (displaySelected)
    {
      U32 x = selected.x;
      U32 y = selected.y;
      if (xFlip) { x = gridSize.x - x - 1; }
      if (yFlip) { y = gridSize.y - y - 1; }
      U32 xPos = pi.client.p0.x + (x * cellSize.x) + (cellSize.x / 4);
      U32 yPos = pi.client.p0.y + (y * cellSize.y) + (cellSize.y / 4);
      IFace::RenderRectangle(ClipRect(xPos, yPos, xPos + cellSize.x / 2, yPos + cellSize.y / 2), Color(1.0F, 1.0F, 1.0F, 0.5F));
    }
  }
}
Ejemplo n.º 2
0
MStatus Cell3D::compute(const MPlug& plug, MDataBlock& block) 
{
    if ( (plug != aOutColor) && (plug.parent() != aOutColor) &&
         (plug != aOutAlpha) &&
         (plug != aOutBorderDist) && 
         (plug != aOutF0) && (plug != aOutF1) && (plug != aOutN0)
       ) 
       return MS::kUnknownParameter;

    const float3& worldPos = block.inputValue(aPointWorld).asFloat3();
    const MFloatMatrix& m = block.inputValue(aPlaceMat).asFloatMatrix();
    const MFloatVector& cGain = block.inputValue(aColorGain).asFloatVector();
    const MFloatVector& cOff = block.inputValue(aColorOffset).asFloatVector();
    
	MFloatPoint q(worldPos[0], worldPos[1], worldPos[2]);
    q *= m;									// Convert into solid space
    
    float n0, f0, f1;
    cellFunc(R3(q.x, q.y, q.z), n0, f0, f1);

    MDataHandle outHandle = block.outputValue(aOutF0);
    outHandle.asFloat() = f0;
    outHandle.setClean();

    outHandle = block.outputValue(aOutF1);
    outHandle.asFloat() = f1;
    outHandle.setClean();

    outHandle = block.outputValue(aOutN0);
    outHandle.asFloat() = n0;
    outHandle.setClean();

    outHandle = block.outputValue(aOutBorderDist);
    outHandle.asFloat() = 0.5f*(f1 - f0);
    outHandle.setClean();

    outHandle = block.outputValue( aOutColor );
    MFloatVector & outColor = outHandle.asFloatVector();
    outColor = cGain * f0 + cOff;
    outHandle.setClean();

    outHandle = block.outputValue(aOutAlpha);
    outHandle.asFloat() = f0;
    outHandle.setClean();

    return MS::kSuccess;
}