Exemple #1
0
/***********************************************************************

  DrawLinks() - this function draws the current link hierarchy as stated 
		in the data structure 'data'.

***********************************************************************/
int 
DrawLinks(MyProgram *data)
{
   int i;

   if (data->redraw == TRUE)
      SetDrawMode(SANE_XOR);

   /*  draw each link 
    */
   for (i = 0; i < data->num_links; i++)
      DrawLine(data->links[i].start.x, InvertY(data->links[i].start.y), 
		data->links[i].visend.x, InvertY(data->links[i].visend.y));

   /*  draw end effector
    */
   switch(data->end_effect.type) {
      case ENDEFF_SQUARE:
         DrawFilledBox(data->end_effect.center.x, 
			InvertY(data->end_effect.center.y),
			ENDEFF_SIZE, ENDEFF_SIZE);
         break;
      case ENDEFF_CIRCLE:
         DrawFilledArc(data->end_effect.center.x, 
			InvertY(data->end_effect.center.y),
			ENDEFF_SIZE, ENDEFF_SIZE, 0, 360);
         break;
      case ENDEFF_TRIANGLE:
         break;
      default:
         break;
   }

   SetDrawMode(GXcopy);

   return(0);
} /* end of DrawLinks() */
Exemple #2
0
void draw_object(Canvas *canvas, Quark *q)
{
    VPoint anchor;
    DObject *o = object_get_data(q);

    if (o == NULL) {
        return;
    }

    if (Apoint2Vpoint(q, &o->ap, &anchor) != RETURN_SUCCESS) {
        return;
    }
    anchor.x += o->offset.x;
    anchor.y += o->offset.y;

    setclipping(canvas, FALSE);

    activate_bbox(canvas, BBOX_TYPE_TEMP, TRUE);
    reset_bbox(canvas, BBOX_TYPE_TEMP);

    switch (o->type) {
    case DO_LINE:
    {
        DOLineData *l = (DOLineData *) o->odata;

        VPoint vp1;
        double x, y, co, si;

        x = l->vector.x;
        y = l->vector.y;

        co = cos(M_PI/180.0*o->angle);
        si = sin(M_PI/180.0*o->angle);

        vp1.x = anchor.x + x*co - y*si;
        vp1.y = anchor.y + x*si + y*co;

        setline(canvas, &o->line);
        DrawLine(canvas, &anchor, &vp1);

        switch (l->arrow_end) {
        case ARROW_AT_NONE:
            break;
        case ARROW_AT_BEGINNING:
            draw_arrowhead(canvas, &vp1, &anchor, &l->arrow,
                           &o->line.pen, &o->fillpen);
            break;
        case ARROW_AT_END:
            draw_arrowhead(canvas, &anchor, &vp1, &l->arrow,
                           &o->line.pen, &o->fillpen);
            break;
        case ARROW_AT_BOTH:
            draw_arrowhead(canvas, &vp1, &anchor, &l->arrow,
                           &o->line.pen, &o->fillpen);
            draw_arrowhead(canvas, &anchor, &vp1, &l->arrow,
                           &o->line.pen, &o->fillpen);
            break;
        }
    }
    break;
    case DO_BOX:
    {
        DOBoxData *b = (DOBoxData *) o->odata;
        if (o->angle == 0.0) {
            VPoint vp1, vp2;

            vp1.x = anchor.x - b->width/2;
            vp2.x = anchor.x + b->width/2;
            vp1.y = anchor.y - b->height/2;
            vp2.y = anchor.y + b->height/2;

            setpen(canvas, &o->fillpen);
            DrawFilledRect(canvas, &vp1, &vp2);

            setline(canvas, &o->line);
            DrawRect(canvas, &vp1, &vp2);
        } else {
            VPoint vps[4];
            double x, y, co, si;

            x = b->width/2;
            y = b->height/2;

            co = cos(M_PI/180.0*o->angle);
            si = sin(M_PI/180.0*o->angle);

            vps[0].x = anchor.x + x*co - y*si;
            vps[0].y = anchor.y + x*si + y*co;
            vps[1].x = anchor.x - x*co - y*si;
            vps[1].y = anchor.y - x*si + y*co;
            vps[2].x = anchor.x - x*co + y*si;
            vps[2].y = anchor.y - x*si - y*co;
            vps[3].x = anchor.x + x*co + y*si;
            vps[3].y = anchor.y + x*si - y*co;

            setpen(canvas, &o->fillpen);
            DrawPolygon(canvas, vps, 4);

            setline(canvas, &o->line);
            DrawPolyline(canvas, vps, 4, POLYLINE_CLOSED);
        }
    }
    break;
    case DO_ARC:
    {
        VPoint vp1, vp2;
        DOArcData *e = (DOArcData *) o->odata;

        vp1.x = anchor.x - e->width/2;
        vp2.x = anchor.x + e->width/2;
        vp1.y = anchor.y - e->height/2;
        vp2.y = anchor.y + e->height/2;

        setpen(canvas, &o->fillpen);
        /* FIXME: implement true ellipse rotation! */
        DrawFilledArc(canvas, &vp1, &vp2, e->angle1 + o->angle, e->angle2,
                      e->closure_type);

        setline(canvas, &o->line);
        DrawArc(canvas, &vp1, &vp2, e->angle1 + o->angle, e->angle2,
                e->closure_type, e->draw_closure);
    }
    break;
    case DO_NONE:
        break;
    }

    get_bbox(canvas, BBOX_TYPE_TEMP, &o->bb);
}