[comp.windows.interviews] Arcs in Interviews

mcginnis@SHARKEY.CC.UMICH.EDU (Brian McGinnis) (05/03/91)

Hi,

Does Interviews have an easy way of drawing arcs or has anyone
implemented arcs in intervies.  I know it can probably be done
with Bsplines, but that doesn't seem like the cleanest way.  
If no one has implemented arcs, what would it take and how would
one go about implementing them. 

Thanks,

Brian McGinnis
mcginnis@applga.aa.cad.slb.com

PS:  We really like InterViews alot and have found it to be
a very usefull tool for rapid prototyping.

glenn@huxley.huxley.bitstream.com (Glenn P. Parker) (05/06/91)

In article <9105031422.AA14732@applga.aa.cad.slb.com> applga!mcginnis@SHARKEY.CC.UMICH.EDU (Brian McGinnis) writes:
> Does Interviews have an easy way of drawing arcs or has anyone
> implemented arcs in intervies.

I was able to extend the Painter class (in InterViews 2.6) to handle arcs
rather cleanly.  That is, I didn't have to modify the base Painter class at
all (thanks to the rep classes).  The whole thing is small enough that I
might as well post it.

// Begin ArcPainter.H
#include <InterViews/painter.h>

class Canvas;

class ArcPainter : public Painter
{
  public:
    ArcPainter();
    ArcPainter(Painter*);
    ~ArcPainter();

    void Arc(Canvas*, Coord cx, Coord cy, unsigned int radius,
	     int angle, int delta);
    void Arc(Canvas*, Coord left, Coord bottom, Coord right, Coord top,
	     int angle, int delta);
};
// End ArcPainter.H

// Begin ArcPainter.C
#include "ArcPainter.H"
#include <InterViews/canvas.h>
#include <InterViews/painter.h>
#include <InterViews/X11/painterrep.h>
#include <InterViews/X11/worldrep.h>
#include <InterViews/X11/Xlib.h>

extern "C"
{
    int XDrawArc(Display*, Drawable, GC,
		 int x, int y, unsigned int w, unsigned int h, int a1, int a2);
}


ArcPainter::ArcPainter() {}

ArcPainter::~ArcPainter() {}

ArcPainter::ArcPainter(Painter* p) : Painter(p) {}

void ArcPainter::Arc(Canvas* c, Coord x, Coord y,
		     unsigned int radius, int angle, int delta)
{
    const int left = x - radius;
    const int xtop = c->Height() - 1 - (y + radius);
    const unsigned int width = 2 * radius;
    const unsigned int height = width;

    XDrawArc(_world->display(), (Drawable)c->Id(), Rep()->dashgc,
	     left, xtop, width, height, angle, delta);
}

void ArcPainter::Arc(Canvas* c, Coord left, Coord bottom,
		     Coord right, Coord top, int angle, int delta)
{
    int xtop = c->Height() - 1 - top;

    XDrawArc(_world->display(), (Drawable)c->Id(), Rep()->dashgc,
	     left, xtop, right - left + 1, top - bottom + 1, angle, delta);
}
// End ArcPainter.C

--
Glenn P. Parker       glenn@bitstream.com       Bitstream, Inc.
                      uunet!huxley!glenn        215 First Street
                      BIX: parker               Cambridge, MA 02142-1270