Ejemplo n.º 1
0
Archivo: vsl.C Proyecto: sampost/ddd
// When selecting: redraw all (for statistics)
static void SelectCB(Widget w, XtPointer, XtPointer)
{
    XClearArea(XtDisplay(w), XtWindow(w), 0, 0, 0, 0, false);

    redraw(w,
           BoxRegion(BoxPoint(0,0), thebox->size()),
           BoxRegion(BoxPoint(0,0), BoxSize(1000000, 1000000)));
}
Ejemplo n.º 2
0
void GraphEdge::_print(std::ostream& os, const GraphGC &gc) const
{
    // Don't print if we're hidden
    if (hidden())
	return;
    
    // Fetch the regions
    BoxRegion start = from()->region(gc);
    BoxRegion end   = to()->region(gc);

    // Don't print edges with zero length
    if (start <= end)
	return;
    
    BoxPoint startc = start.origin() + (start.space() / BoxPoint(2));
    BoxPoint endc   = end.origin()   + (end.space()   / BoxPoint(2));

    BoxPoint startp = crosspoint (start, endc);
    BoxPoint endp   = crosspoint (end, startc);

    // This should come from gc.edgeGC
    BoxCoordinate line_width = 1;

    if (gc.printGC->isFig()) {
	if (!gc.drawArrowHeads || to()->isHint()) {
	    os << EDGEHEAD1 << line_width;
	    os << EDGEHEAD2 ;
	    os << startp[X] << " " << startp[Y] << " " ;
	    os << endp[X] << " " << endp[Y] << " " ;
	    os << "9999 9999\n" ;
	} else {
	    os << ARROWHEAD1 << line_width;
	    os << ARROWHEAD2 ;
	    os << startp[X] << " " << startp[Y] << " " ;
	    os << endp[X] << " " << endp[Y] << " " ;
	    os << "9999 9999\n" ;
	}
    } else if (gc.printGC->isPostScript()) {
	if (!gc.drawArrowHeads || to()->isHint()) {
	    os << startp[X] << " " << startp[Y] << " " ;
	    os << endp[X] << " " << endp[Y] << " " ;
	    os << line_width << " line*\n";
	} else {
	    os << gc.arrowAngle << " " << gc.arrowLength << " ";
	    os << startp[X] << " " << startp[Y] << " " ;
	    os << endp[X] << " " << endp[Y] << " " ;
	    os << line_width << " arrowline*\n";
	}
    }
}
Ejemplo n.º 3
0
cxAtlas *cxAtlas::SetCoords(const cxArray *coords,const cxFrames *frames)
{
    CX_ASSERT(!Size().IsZero(), "size not set");
    cxInt size = frames->Num();
    SetCapacity(size);
    const cxInt *map = frames->Map();
    for(cxInt i = 0;i < size;i++){
        cxInt mapIdx = map[i];
        CX_ASSERT(mapIdx < coords->Size(), "map idx error");
        //get map tex
        cxTexCoord *coord = coords->At(mapIdx)->To<cxTexCoord>();
        if(coord->IsEmpty()){
            continue;
        }
        //trimmed box
        cxBoxPoint3F bp = coord->Trimmed(BoxPoint(), Size(), FlipX(), FlipY());
        if(bp.Size().IsZero()){
            continue;
        }
        //add render
        cxBoxRender &render = renders.Inc();
        render.SetVertices(bp);
        render.SetColor(Color());
        //get coord box
        const cxBoxCoord2F &tbox = coord->BoxCoord(Pixel(), FlipX(), FlipY());
        render.SetCoords(tbox);
    }
    return this;
}
Ejemplo n.º 4
0
static BoxPoint crosspoint (BoxRegion &region, BoxPoint &p)
{
    int side = crosside (region, p);
    
    BoxDimension d1, d2;
    BoxPoint center = region.origin() + (region.space() / BoxPoint(2)) ;
    BoxPoint cross = center;
    int offset;
    
    offset = (side & (North | West)? -1 : 1) ;
    if (side & (North | South)) {
	d1 = X ; 
	d2 = Y ;
    } else {
	d1 = Y ;
	d2 = X ;
    }
    
    if (center[d1] != p[d1] && center[d2] != p[d2]) {
	cross[d1] += offset * (region.space(d2) / 2) 
	    * ( center[d1] - p[d1]) / ( center[d2] - p[d2] ) ;
    } 
    cross[d2] += offset * region.space(d2) / 2;
    
    return cross ;
}
Ejemplo n.º 5
0
static Side crosside (BoxRegion  &region, BoxPoint &p)
{
    BoxPoint center = region.origin() + (region.space() / BoxPoint(2)) ;
    BoxPoint delta = center  - p ;
	
    int side = North | South | East | West ;
    
    // exclude opposite side
    
    if (p[X] > center[X]) 
	side &= ~West ;
    else
	side &= ~East ;
    if (p[Y] > center[Y])
	side &= ~North ;
    else
	side &= ~South ;
    
    delta[X] = abs(delta[X]);
    delta[Y] = abs(delta[Y]);
    
    if (region.space(Y) * delta[X] > region.space(X) * delta[Y]) 
	side &= ~(North | South);
    else
	side &= ~(East | West);
    
    return Side(side);
}
Ejemplo n.º 6
0
// Draw arrow head at POS
void LineGraphEdge::drawArrowHead(Widget w,
				  const BoxRegion& /* exposed */,
				  const GraphGC& gc,
				  const BoxPoint& pos,
				  double alpha) const
{
    if (!gc.drawArrowHeads || to()->isHint())
	return;

    const double offset = gc.arrowAngle * PI / 180;	// Angle
    const int length    = gc.arrowLength;		// Length

    // Get coordinates
    XPoint points[3];
    points[0].x = pos[X];
    points[0].y = pos[Y];
    points[1].x = short(pos[X] + length * cos(alpha + offset / 2));
    points[1].y = short(pos[Y] + length * sin(alpha + offset / 2));
    points[2].x = short(pos[X] + length * cos(alpha - offset / 2));
    points[2].y = short(pos[Y] + length * sin(alpha - offset / 2));

#if 0
	clog << "\nangle = " << (alpha / (PI * 2.0)) * 360.0  << "\n";
	for (int i = 0; i < 3; i++)
	    clog << "points[" << i << "] = "
		 << BoxPoint(points[i].x, points[i].y) << "\n";
#endif

    XFillPolygon(XtDisplay(w), XtWindow(w), gc.edgeGC, points,
		 XtNumber(points), Convex, CoordModeOrigin);
}
Ejemplo n.º 7
0
// Expose Callback
static void ExposeCB(Widget w, XtPointer, XtPointer call_data)
{
    // Set size
    Arg arglist[10];
    int a = 0;
    XtSetArg(arglist[a], XtNwidth,  thebox->size(X)); a++;
    XtSetArg(arglist[a], XtNheight, thebox->size(Y)); a++;
    XtSetValues(w, arglist, a);

    // Get region
    XExposeEvent* event = (XExposeEvent *)call_data;
    BoxPoint expose_origin = BoxPoint(event->x, event->y);
    BoxSize  expose_space  = BoxSize(event->width, event->height);
    BoxRegion exposed(expose_origin, expose_space);

    redraw(w, BoxRegion(BoxPoint(0,0), thebox->size()), exposed);
}
Ejemplo n.º 8
0
// Find TagBox for point P
const TagBox *CompositeBox::findTag(const BoxPoint& p) const
{
    if (p != BoxPoint(-1, -1))
	for (int i = 0; i < nchildren(); i++)
	{
	    const Box *child = (*this)[i];
	    const TagBox *t = child->findTag(p);
	    if (t != 0)
		return t;   // found
	}
    return 0; // not found
}
Ejemplo n.º 9
0
cxAtlas *cxAtlas::SetCoords(const cxArray *coords)
{
    cxInt size = coords->Size();
    SetCapacity(size);
    for(cxInt i = 0;i < size;i++){
        cxBoxRender &render = renders.Inc();
        cxTexCoord *coord = coords->At(i)->To<cxTexCoord>();
        cxBoxPoint3F bp = coord->Trimmed(BoxPoint(), Size(), FlipX(), FlipY());
        const cxBoxCoord2F &tbox = coord->BoxCoord(Pixel(), FlipX(), FlipY());
        render.SetVertices(bp);
        render.SetColor(Color());
        render.SetCoords(tbox);
    }
    return this;
}
Ejemplo n.º 10
0
// Draw a BoxGraphNode
void BoxGraphNode::forceDraw(Widget w, 
			     const BoxRegion& /* exposed */,
			     const GraphGC& gc) const
{
    assert(box() != 0);
    // assert(box()->OK());

    // We do not check for exposures here --
    // boxes are usually small and partial display
    // doesn't work well with scrolling
    static BoxRegion exposed(BoxPoint(0, 0), BoxSize(INT_MAX, INT_MAX));

    if (selected() && highlight())
    {
	box()->draw(w, region(gc), exposed, gc.nodeGC, false);

	bool use_color = ColorBox::use_color;
	ColorBox::use_color = false;
	BoxRegion r = highlightRegion(gc);

	if (r <= exposed)
	{
	    XFillRectangle(XtDisplay(w), XtWindow(w), gc.clearGC,
			   r.origin(X), r.origin(Y),
			   r.space(X), r.space(Y));
	    highlight()->draw(w, r, r, gc.nodeGC, false);
	}
	ColorBox::use_color = use_color;
    }
    else if (selected())
    {
	bool use_color = ColorBox::use_color;
	ColorBox::use_color = false;
	box()->draw(w, region(gc), exposed, gc.nodeGC, false);
	ColorBox::use_color = use_color;
    }
    else
    {
	box()->draw(w, region(gc), exposed, gc.nodeGC, false);
    }
}
Ejemplo n.º 11
0
BoxPoint LineGraphEdge::annotationPosition(const GraphGC &gc) const
{
    if (from() == to())
    {
	BoxRegion region = from()->region(gc);
	if (from()->selected())
	    region.origin() += gc.offsetIfSelected;

	LineGraphEdgeSelfInfo info(region, gc);
	return info.anno_pos;
    }

    BoxPoint pos1     = from()->pos();
    BoxRegion region1 = from()->region(gc);

    BoxPoint pos2     = to()->pos();
    BoxRegion region2 = to()->region(gc);

    BoxPoint l1, l2;
    findLine(pos1, pos2, region1, region2, l1, l2, gc);

    if (from()->isHint() && to()->isHint())
    {
	// Between two hints -- don't draw anything
	return BoxPoint();
    }

    if (to()->isHint())
    {
	// Draw at hint position
	return to()->pos();
    }

    // Draw at mid-distance
    return l1 + (l2 - l1) / 2;
}
Ejemplo n.º 12
0
// Event location
BoxPoint point(XEvent *ev)
{
    if (ev == 0)
    {
	// LessTif 0.79 and Motif 1.1 sometimes pass 0 as event;
	// provide some reasonable default
	invalid_event("point");
	return BoxPoint();
    }

    switch (ev->type)
    {
	case KeyPress:
	case KeyRelease:
	    return BoxPoint(ev->xkey.x,
			    ev->xkey.y);

	case ButtonPress:
	case ButtonRelease:
	    return BoxPoint(ev->xbutton.x,
			    ev->xbutton.y);

	case MotionNotify:
	    return BoxPoint(ev->xmotion.x,
			    ev->xmotion.y);

	case EnterNotify:
	case LeaveNotify:
	    return BoxPoint(ev->xcrossing.x,
			    ev->xcrossing.y);

	case Expose:
	    return BoxPoint(ev->xexpose.x,
			    ev->xexpose.y);

	case GraphicsExpose:
	    return BoxPoint(ev->xgraphicsexpose.x,
			    ev->xgraphicsexpose.y);

	case CreateNotify:
	    return BoxPoint(ev->xcreatewindow.x,
			    ev->xcreatewindow.y);

	case ReparentNotify:
	    return BoxPoint(ev->xreparent.x,
			    ev->xreparent.y);

	case ConfigureNotify:
	    return BoxPoint(ev->xconfigure.x,
			    ev->xconfigure.y);

	case GravityNotify:
	    return BoxPoint(ev->xgravity.x,
			    ev->xgravity.y);

	case ConfigureRequest:
	    return BoxPoint(ev->xconfigurerequest.x,
			    ev->xconfigurerequest.y);

	default:
	    invalid_event("point");
	    return BoxPoint();
    }
}
Ejemplo n.º 13
0
void RuleBox::_print(std::ostream& os, 
		     const BoxRegion& region, 
		     const PrintGC& gc) const
{
    BoxSize space = region.space();
    BoxPoint origin = region.origin();
    BoxPoint width ;
    
    width = BoxPoint ( extend(X) ? space[X] : size(X) ,
		       extend(Y) ? space[Y] : size(Y) );

    if (width == BoxPoint (0,1) || width == BoxPoint (1,0)) {
	return ;
    }
    if (width[X] && width[X] < 3 && gc.isFig()) {
	// 
	// vertical Line
	//
	
	os << LINEHEAD1 ;
	os << width[X] << LINEHEAD2 ;
	os << origin[X] + width[X]/2 << " " << origin[Y] ;
	os << " " ;
	os << origin[X] + width[X]/2 << " " ;
	os << origin[Y] + width[Y] << " " ;
	os << "9999 9999\n" ;

    } else if (width[Y] && width[Y] < 3 && gc.isFig()) {
	//
	// horizontal line
	//
	
	os << LINEHEAD1 ;
	os << width[Y] << LINEHEAD2 ;
	os << origin[X] << " " << origin[Y]+width[Y]/2 ;
	os << " " ;
	os << origin[X] + width[X] << " " ;
	os << origin[Y] + width[Y]/2 << " " ;
	os << "9999 9999\n" ;
	
    } else {
	//
	// filled rectangle
	//
	if (gc.isFig()) {
	    os << RULEHEAD ;
	    os << origin[X] << " " << origin[Y] << " " ;
	    os << origin[X] + width[X] << " " << origin[Y] ;
	    os << " " ;
	    os << origin[X] + width[X] << " " ;
	    os << origin[Y] + width[Y] << " ";
	    os << origin[X] << " " << origin[Y] + width[Y] ; 
	    os << " " ;
	    os << origin[X] << " "<< origin[Y] << " 9999 9999\n" ;

	} else if (gc.isPostScript()) {

	    os << origin[X] << " " << origin[Y] << " " ;
	    os << origin[X] + width[X] << " " << origin[Y] ;
	    os << " " ;
	    os << origin[X] + width[X] << " " ;
	    os << origin[Y] + width[Y] << " ";
	    os << origin[X] << " " << origin[Y] + width[Y] ; 
	    os << " box*" << " %" <<  region << "\n"; ;
	}
    }
}
Ejemplo n.º 14
0
void Box::epsHeader (std::ostream& os, 
		     const BoxRegion& region, 
		     const PostScriptPrintGC& gc)
{
    // check size of graph

    BoxPoint space  = region.space();
    BoxPoint origin = region.origin();

    BoxPoint size;
    switch (gc.orientation)
    {
    case PostScriptPrintGC::PORTRAIT:
	size = BoxPoint(gc.hsize, gc.vsize);
	break;

    case PostScriptPrintGC::LANDSCAPE:
	size = BoxPoint(gc.vsize, gc.hsize);
	break;
    }

    double scale = 1.0;
    if (space > size)
    {
	// Scale down ...
	double hscale = double(size[X]) / region.space(X);
	double vscale = double(size[Y]) / region.space(Y);
	scale = (hscale < vscale ? hscale : vscale);
	
	space[X] = int(double(space[X]) * scale + 0.5);
	space[Y] = int(double(space[Y]) * scale + 0.5);

	origin[X] = int(double(origin[X]) * scale + 0.5);
	origin[Y] = int(double(origin[Y]) * scale + 0.5);
    }

    // Determine bounding box
    BoxPoint llcorner, urcorner;
    switch (gc.orientation)
    {
    case PostScriptPrintGC::PORTRAIT:
	llcorner = BoxPoint(gc.hoffset,
			    gc.voffset);
	urcorner = BoxPoint(gc.hoffset + space[X], 
			    gc.voffset + space[Y]);
	break;

    case PostScriptPrintGC::LANDSCAPE:
        llcorner = BoxPoint(gc.hsize - space[Y] + gc.hoffset - gc.voffset, 
			    gc.hoffset);
	urcorner = BoxPoint(gc.hsize + gc.hoffset - gc.voffset,
			    gc.hoffset + space[X]);
	break;
    }

    os << EPSHEAD
       << CREATOR
       << BOUND 
       << llcorner[X] << " " << llcorner[Y] << " "
       << urcorner[X] << " " << urcorner[Y] << "\n"
       << PAGES << ENDC
       << "\ngsave\n";

    // Write rotation
    if (gc.orientation == PostScriptPrintGC::LANDSCAPE)
	os << gc.hsize + gc.hoffset << " 0 translate 90 rotate\n";

    // Write scaling
    int hmove = gc.hoffset - origin[X];
    int vmove = gc.voffset + space[Y] + origin[Y];

    os << hmove << " " << vmove << " translate\n"
       << scale << " " << -scale << " scale\n";
}