/*------------------------------------------------------------------------------
| DrawingArea::button1DoubleClick                                              |
|                                                                              |
| Handle button 1 up double click events.  In the case of polyline and polygon |
| a double click indicates the user has finished adding data points to the     |
| object.                                                                      |
------------------------------------------------------------------------------*/
DrawingArea& DrawingArea::button1DoubleClick( const IPoint& point )
{
  if (drawState() == waitingForInput )
  {
    switch (currentObj)
    {
      case polyline:
      {
        iGraphic->drawOn( gc );
        iGraphic->setGraphicBundle( currentBundle );
        iGraphic->drawOn( gc );
        setDrawState( notDrawing );
        graphicList()->addAsLast( *iGraphic );
      }
      break;
      case polygon:
      {
        ((IGPolyline*)iGraphic)->IGPolyline::drawOn( gc );
        iGraphic->setGraphicBundle( currentBundle );
        iGraphic->drawOn( gc );
        setDrawState( notDrawing );
        graphicList()->addAsLast( *iGraphic );
      }
      break;
    }
  }
  return *this;
}
예제 #2
0
void OpenGLRenderer::draw(const glm::mat4& model, DrawBuffer* draw,
                          const Renderer::DrawParameters& p) {
    setDrawState(model, draw, p);

    glDrawElements(draw->getFaceType(), static_cast<GLsizei>(p.count),
                   GL_UNSIGNED_INT,
                   reinterpret_cast<void*>(sizeof(RenderIndex) * p.start));
}
예제 #3
0
void OpenGLRenderer::drawArrays(const glm::mat4& model, DrawBuffer* draw,
                                const Renderer::DrawParameters& p) {
    setDrawState(model, draw, p);

    glDrawArrays(draw->getFaceType(), static_cast<GLint>(p.start), static_cast<GLsizei>(p.count));
}
예제 #4
0
//-----------------------------------------------------------------------------
//       Class:  Drawable
//      Method:  draw
// Description:  Collect methods into one draw method.
//-----------------------------------------------------------------------------
    void
Drawable::draw ()
{
    setDrawState();
    DrawableObject::draw();
}		// -----  end of method Drawable::draw  -----
/*------------------------------------------------------------------------------
| DrawingArea::button1Up                                                       |
|                                                                              |
| Handle button 1 up events.  This indicates a data points final location.     |
------------------------------------------------------------------------------*/
DrawingArea& DrawingArea::button1Up( const IPoint& point )
{
  if ( drawState() == drawing )
  {
    switch (currentObj)
    {
      case move:
      break;
      case eraser:
      break;
      case stylecan:
      break;
      case line:
        ((IGLine*)iGraphic)->setEndingPoint( point );
        iGraphic->setGraphicBundle( currentBundle );
        iGraphic->drawOn( gc );
        setDrawState( notDrawing );
        graphicList()->addAsLast( *iGraphic );
      break;
      case freehand:
        ((IGPolygon*)iGraphic)->addPoint( point );
        iGraphic->setGraphicBundle( currentBundle );
        iGraphic->drawOn( gc );
        setDrawState( notDrawing );
        graphicList()->addAsLast( *iGraphic );
      break;
      case rectangle:
      {
        IRectangle rc(((IGRectangle*)iGraphic)->enclosingRect());
        rc.sizeTo( rc.size() + point - previousPt );
        ((IGRectangle*)iGraphic)->setEnclosingRect( rc );
        iGraphic->setGraphicBundle( currentBundle );
        iGraphic->drawOn( gc );
        setDrawState( notDrawing );
        graphicList()->addAsLast( *iGraphic );
      }
      break;
      case ellipse:
      {
        IRectangle rc(((IGEllipse*)iGraphic)->enclosingRect());
        rc.sizeTo( rc.size() + point - previousPt );
        ((IGEllipse*)iGraphic)->setEnclosingRect( rc );

        iGraphic->setGraphicBundle( currentBundle );
        iGraphic->drawOn( gc );
        setDrawState( notDrawing );
        graphicList()->addAsLast( *iGraphic );
      }
      break;
      case polyline:
      case polygon:
        previousPt = point;
        ((IGPolyline*)iGraphic)->setPoint(
                         ((IGPolyline*)iGraphic)->numberOfPoints()-1, point );
        setDrawState( waitingForInput );
      break;
      case arc:
      if ( pointCount == 2 )
      {
        ((IG3PointArc*)iGraphic)->setIntermediatePoint( point );
        gc.setMixMode( IGraphicBundle::xor ).setPenColor( IColor::white );
        IGLine tempLine( ((IG3PointArc*)iGraphic)->startingPoint(), previousPt );
        tempLine.drawOn( gc );
        tempLine.setEndingPoint( point );
        tempLine.drawOn( gc );
        setDrawState( waitingForInput );
      }
      else if ( pointCount == 3 )
      {
        gc.setMixMode( IGraphicBundle::xor ).setPenColor( IColor::white );
        iGraphic->drawOn( gc );
        ((IG3PointArc*)iGraphic)->setEndingPoint( point );
        iGraphic->setGraphicBundle( currentBundle );
        iGraphic->drawOn( gc );
        setDrawState( notDrawing );
        graphicList()->addAsLast( *iGraphic );
        pointCount = 0;
      }
      break;
      case pie:
      case chord:
      if ( pointCount == 2 )
      {
        gc.setMixMode( IGraphicBundle::xor ).setPenColor( IColor::white );
        setDrawState( waitingForInput );
        IPoint centerPt(((IGPie*)iGraphic)->enclosingRect().center());

        ((IGPie*)iGraphic)->setStartAngle( angleFromPoints( centerPt, point ));

        unsigned a(abs(centerPt.x()) - abs(point.x()));
        unsigned b(abs(centerPt.y()) - abs(point.y()));

        unsigned long radius((unsigned long)sqrtl(a*a + b*b));

        ((IGPie*)iGraphic)->setEnclosingRect(
           ((IGPie*)iGraphic)->enclosingRect().expandBy(radius));
      }
      else if ( pointCount == 3 )
      {
        gc.setMixMode( IGraphicBundle::xor ).setPenColor( IColor::white );
        iGraphic->drawOn( gc );

        double sweep(angleFromPoints(
                              ((IGPie*)iGraphic)->enclosingRect().center(), point ));

        if ( sweep < ((IGPie*)iGraphic)->startAngle() )
          ((IGPie*)iGraphic)->setSweepAngle( 360.0 -
                                ( ((IGPie*)iGraphic)->startAngle() - sweep ));
        else
          ((IGPie*)iGraphic)->setSweepAngle( sweep -
                                            ((IGPie*)iGraphic)->startAngle());

        iGraphic->setGraphicBundle( currentBundle );
        iGraphic->drawOn( gc );
        setDrawState( notDrawing );
        graphicList()->addAsLast( *iGraphic );
        pointCount = 0;
      }
      break;
      case text:
      {
        IString input;

        IDynamicLinkLibrary reslib("CPPWV53R");

        if (point.x() % 2)
          input = reslib.loadString( STRING_SAMPLE1 );
        else if ((point.y() % 5)==1)
          input = reslib.loadString( STRING_SAMPLE3 );
        else if ((point.y() % 5)==3)
          input = reslib.loadString( STRING_SAMPLE4 );
        else
          input = reslib.loadString( STRING_SAMPLE2 );

        IGString* text = new IGString( input.x2c(), point, currentFont());
//      IGString* text = new IGString( "Doodle", point, currentFont());
        text->rotateBy( 10.0, point );
        text->setGraphicBundle( currentBundle );
        text->drawOn( gc );
        setDrawState( notDrawing );
        graphicList()->addAsLast( *text );
      }
      break;
      case bitmap:
      {
        IGBitmap *bmp;
//      if (bitmapFileName().length() > 0)
//      {
//        bmp = new IGBitmap(bitmapFileName());
//      }

        // Select a bitmap to load
        IDynamicLinkLibrary reslib("CPPWV53R");

        if (point.x() % 2)
          bmp = new IGBitmap(reslib.loadBitmap( BITMAP_SAMPLE1 ));
        else if ((point.y() % 5)==1)
          bmp = new IGBitmap(reslib.loadBitmap( BITMAP_SAMPLE3 ));
        else if ((point.y() % 5)==3)
          bmp = new IGBitmap(reslib.loadBitmap( BITMAP_SAMPLE4 ));
        else
          bmp = new IGBitmap(reslib.loadBitmap( BITMAP_SAMPLE2 ));

        bmp->moveTo( point );
        bmp->drawOn( gc );
        setDrawState( notDrawing );
        graphicList()->addAsLast( *bmp );
      }
      break;
    } /* endswitch */
  } /* endif */
  else  // not drawing
  {
    switch (currentObj)
    {
      case move:
        if (moveGraphic && capturePointer)
        {
          moveRect.translateBy( point - previousPt );
          moveRect.drawOn( gc );
          moveRect.resetTransformMatrix();
          this->refresh( moveRect.boundingRect(gc).expandBy(2) );
          moveGraphic->translateBy( point - startingPt );
          moveGraphic->drawOn( gc );
          moveGraphic = 0;
          capturePointer(false);
        }
      break;
    }
  }
  return *this;
}
/*------------------------------------------------------------------------------
| DrawingArea::button1Down                                                     |
|                                                                              |
| Handle button 1 down messages.  This event indicates a new graphic object is |
| to be created of additional data points to add to an existing graphic object.|
------------------------------------------------------------------------------*/
DrawingArea& DrawingArea::button1Down( const IPoint& point )
{
  switch (currentObj)
  {
    case move: // Button 1 drag
      if (drawState() == notDrawing)
      {
        moveGraphic = graphicList()->topGraphicUnderPoint( point, gc );
        if ( moveGraphic )
        {
          moveRect.setEnclosingRect(moveGraphic->boundingRect( gc ));
          previousPt = point;
          startingPt = point;
          capturePointer();
        }
      }
    break;
    case eraser:
      {
        // Delete the object under the pointer
        moveGraphic = graphicList()->topGraphicUnderPoint( point, gc );
        if ( moveGraphic )
        {
          moveRect.setEnclosingRect(moveGraphic->boundingRect( gc ));
          IGList::Cursor cursor( *graphicList(), gc, point );
          for (cursor.setToFirst(); cursor.isValid(); cursor.setToNext())
          {
             IGraphic* graphic(&(graphicList()->graphicAt(cursor)));
             if (graphic == moveGraphic)
             {
               graphicList()->removeAt(cursor);
               delete graphic;
               this->refresh( moveRect.boundingRect(gc).expandBy(2) );
               moveRect.resetTransformMatrix();
               moveGraphic = 0;
               break;
             }
          }
        }
      }
    break;
    case stylecan:
    {
      // Change all objects to the current pen and fill color.
      IRectangle tempRect;
      moveGraphic = graphicList()->topGraphicUnderPoint( point, gc );
      if( moveGraphic )
      {
        tempRect = moveGraphic->boundingRect( gc );
        moveGraphic->setGraphicBundle( currentBundle );
        moveGraphic->drawOn( gc );
        tempRect |= moveGraphic->boundingRect( gc );
        this->refresh( tempRect.expandBy(2) );
        moveGraphic = 0;
      }
    }
    break;
    case line:
      startingPt = point;
      previousPt = point;
      iGraphic = new IGLine( startingPt, previousPt );
      setDrawState();
    break;
    case freehand:
      iGraphic = new IGPolygon(IPointArray());
      ((IGPolygon*)iGraphic)->addPoint( point );
      setDrawState();
    break;
    case rectangle:
      startingPt = point;
      previousPt = point;
      iGraphic = new IGRectangle(IRectangle(startingPt, previousPt));
      setDrawState();
    break;
    case ellipse:
      startingPt = point;
      previousPt = point;
      iGraphic = new IGEllipse( startingPt, 0L );
      setDrawState();
    break;
    case polyline:
    case polygon:
      if (drawState() == notDrawing)
      {
        startingPt = point;
        previousPt = point;
        if (currentObj == polyline)
          iGraphic = new IGPolyline(IPointArray());
        else
          iGraphic = new IGPolygon(IPointArray());

        ((IGPolyline*)iGraphic)->addPoint( startingPt );
        ((IGPolyline*)iGraphic)->addPoint( previousPt );
        setDrawState();
      }
      else
      {
        ((IGPolyline*)iGraphic)->IGPolyline::drawOn( gc );
        ((IGPolyline*)iGraphic)->addPoint( point );
        ((IGPolyline*)iGraphic)->IGPolyline::drawOn( gc );
      }
    break;
    case arc:
      pointCount++;
      if (drawState() == notDrawing)
      {
        iGraphic = new IG3PointArc( point, IPoint(0,0), IPoint(0,0) );
        startingPt = point;
        previousPt = point;
      }
      else if ( pointCount == 2 )
      {
        previousPt = point;
        IGLine tempLine( ((IG3PointArc*)iGraphic)->startingPoint(), point );
        tempLine.drawOn( gc );
      }
      else if ( pointCount == 3 )
      {
        IGLine tempLine( ((IG3PointArc*)iGraphic)->startingPoint(), previousPt );
        tempLine.drawOn( gc );
        previousPt = point;
        ((IG3PointArc*)iGraphic)->setEndingPoint( point );
        iGraphic->drawOn( gc );
      }
      setDrawState();
    break;
    case pie:
    case chord:
      pointCount++;
      if (drawState() == notDrawing)
      {
        if (currentObj == pie)
          iGraphic = new IGPie( IRectangle(), 0, 0);
        else
          iGraphic = new IGChord( IRectangle(), 0, 0);

        ((IGPie*)iGraphic)->setEnclosingRect(
                             ((IGPie*)iGraphic)->enclosingRect().centerAt( point ));
        startingPt = point;
        previousPt = point;
      }
      else if ( pointCount == 2 )
      {
        previousPt = point;
        IGLine tempLine( ((IGPie*)iGraphic)->enclosingRect().center(), point );
        tempLine.drawOn( gc );
      }
      else if ( pointCount == 3 )
      {
        IGLine tempLine( ((IGPie*)iGraphic)->enclosingRect().center(), previousPt );
        tempLine.drawOn( gc );
        previousPt = point;
        double sweep(angleFromPoints( ((IGPie*)iGraphic)->enclosingRect().center(), point ));
        if ( sweep < ((IGPie*)iGraphic)->startAngle() )
          ((IGPie*)iGraphic)->setSweepAngle( 360.0 -
                                ( ((IGPie*)iGraphic)->startAngle() - sweep ));
        else
          ((IGPie*)iGraphic)->setSweepAngle( sweep -
                                            ((IGPie*)iGraphic)->startAngle());
        iGraphic->drawOn( gc );
      }
      setDrawState();
    break;
    case text:
      setDrawState();
    break;
    case bitmap:
      setDrawState();
    break;
  } /* endswitch */
  return *this;
}