//-1 if completely out
int s[4];
- s[0]=( ((x >=view.Selection.X)&& (x <= (view.Selection.X + view.Selection.W) ))) ? 1:0;
- s[1]=( (((x+W) >=view.Selection.X)&& ((x+W) <= (view.Selection.X + view.Selection.W) ))) ? 1:0;
+ s[0]=( ((x >=view->Selection.X)&& (x <= (view->Selection.X + view->Selection.W) ))) ? 1:0;
+ s[1]=( (((x+W) >=view->Selection.X)&& ((x+W) <= (view->Selection.X + view->Selection.W) ))) ? 1:0;
- s[2]=( ((y >=view.Selection.Y)&& (y <= (view.Selection.Y + view.Selection.H) ))) ? 1:0;
- s[3]=( (((y+H) >=view.Selection.Y)&& ((y+H) <= (view.Selection.Y + view.Selection.H) ))) ? 1:0;
+ s[2]=( ((y >=view->Selection.Y)&& (y <= (view->Selection.Y + view->Selection.H) ))) ? 1:0;
+ s[3]=( (((y+H) >=view->Selection.Y)&& ((y+H) <= (view->Selection.Y + view->Selection.H) ))) ? 1:0;
if (s[0] && s[1] && s[2] && s[3])
float x,y,m,iter;
float RX,RY,RW,RH;
int intersects,in;
- RX=view.Selection.X;
- RY=view.Selection.Y;
- RW=view.Selection.W;
- RH=view.Selection.H;
+ RX=view->Selection.X;
+ RY=view->Selection.Y;
+ RW=view->Selection.W;
+ RH=view->Selection.H;
if((is_point_in_rectangle(X1,Y1,RX,RY,RW,RH)) && (is_point_in_rectangle(X2,Y2,RX,RY,RW,RH)))
return 1;
if((is_point_in_rectangle(X1,Y1,RX,RY,RW,RH)) || (is_point_in_rectangle(X2,Y2,RX,RY,RW,RH)))
int SelectBeziers(xdot_op* op)
{
- if(!view.Selection.Active)
+ if(!view->Selection.Active)
return 0;
- switch (view.Selection.Type)
+ switch (view->Selection.Type)
{
case 0:
- if (view.Selection.AlreadySelected)
+ if (view->Selection.AlreadySelected)
return 0;
if( spline_x_rect(op))
{
if ( ((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected==0)
{
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected=1;
- select_object (view.g[view.activeGraph],((xdot*)(op->parentxdot))->obj);
- view.Selection.AlreadySelected=1;
+ select_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
+ view->Selection.AlreadySelected=1;
}
else
{
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected=0;
- deselect_object (view.g[view.activeGraph],((xdot*)(op->parentxdot))->obj);
- view.Selection.AlreadySelected=1;
+ deselect_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
+ view->Selection.AlreadySelected=1;
}
}
break;
if( ( ((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->selectionflag != -1 ) && (spline_in_rect(op)) )
{
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Preselected=1;
-// select_object (view.g[view.activeGraph],((xdot*)(op->parentxdot))->obj);
- view.Selection.AlreadySelected=1;
+// select_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
+ view->Selection.AlreadySelected=1;
}
else
{
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Preselected=0;
-// deselect_object (view.g[view.activeGraph],((xdot*)(op->parentxdot))->obj);
- view.Selection.AlreadySelected=1;
+// deselect_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
+ view->Selection.AlreadySelected=1;
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->selectionflag = -1;
}
break;
if(spline_x_rect(op))
{
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected=1;
- select_object (view.g[view.activeGraph],((xdot*)(op->parentxdot))->obj);
- view.Selection.AlreadySelected=1;
+ select_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
+ view->Selection.AlreadySelected=1;
}
break;
default:
int SelectPolygon(xdot_op* op)
{
- if(!view.Selection.Active)
+ if(!view->Selection.Active)
return 0;
- switch (view.Selection.Type)
+ switch (view->Selection.Type)
{
case 0:
- if (view.Selection.AlreadySelected)
+ if (view->Selection.AlreadySelected)
return 0;
if ( ((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected==0)
{
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected=1;
- select_object (view.g[view.activeGraph],((xdot*)(op->parentxdot))->obj);
- view.Selection.AlreadySelected=1;
+ select_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
+ view->Selection.AlreadySelected=1;
}
else
{
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected=0;
- deselect_object (view.g[view.activeGraph],((xdot*)(op->parentxdot))->obj);
- view.Selection.AlreadySelected=1;
+ deselect_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
+ view->Selection.AlreadySelected=1;
}
}
if( ( ((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->selectionflag != -1 ) && (polygon_in_rect(op)) )
{
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Preselected=1;
-// select_object (view.g[view.activeGraph],((xdot*)(op->parentxdot))->obj);
-// view.Selection.AlreadySelected=1;
+// select_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
+// view->Selection.AlreadySelected=1;
}
else
{
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Preselected=0;
-// deselect_object (view.g[view.activeGraph],((xdot*)(op->parentxdot))->obj);
- view.Selection.AlreadySelected=1;
+// deselect_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
+ view->Selection.AlreadySelected=1;
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->selectionflag = -1;
}
if(polygon_x_rect(op))
{
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected=1;
- select_object (view.g[view.activeGraph],((xdot*)(op->parentxdot))->obj);
- view.Selection.AlreadySelected=1;
+ select_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
+ view->Selection.AlreadySelected=1;
}
break;
int SelectPolyline(xdot_op* op)
{
- if(!view.Selection.Active)
+ if(!view->Selection.Active)
return 0;
- switch (view.Selection.Type)
+ switch (view->Selection.Type)
{
case 0:
- if (view.Selection.AlreadySelected)
+ if (view->Selection.AlreadySelected)
return 0;
if ( ((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected==0)
{
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected=1;
- select_object (view.g[view.activeGraph],((xdot*)(op->parentxdot))->obj);
- view.Selection.AlreadySelected=1;
+ select_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
+ view->Selection.AlreadySelected=1;
}
else
{
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected=0;
- deselect_object (view.g[view.activeGraph],((xdot*)(op->parentxdot))->obj);
- view.Selection.AlreadySelected=1;
+ deselect_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
+ view->Selection.AlreadySelected=1;
}
}
else
{
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Preselected=0;
- view.Selection.AlreadySelected=1;
+ view->Selection.AlreadySelected=1;
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->selectionflag = -1;
}
if(polyline_x_rect(op))
{
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected=1;
- select_object (view.g[view.activeGraph],((xdot*)(op->parentxdot))->obj);
- view.Selection.AlreadySelected=1;
+ select_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
+ view->Selection.AlreadySelected=1;
}
break;
}
int SelectEllipse(xdot_op* op)
{
- if(!view.Selection.Active)
+ if(!view->Selection.Active)
return 0;
- switch (view.Selection.Type)
+ switch (view->Selection.Type)
{
case 0:
- if (view.Selection.AlreadySelected)
+ if (view->Selection.AlreadySelected)
return 0;
if( point_within_ellipse(op))
if ( ((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected==0)
{
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected=1;
- select_object (view.g[view.activeGraph],((xdot*)(op->parentxdot))->obj);
- view.Selection.AlreadySelected=1;
+ select_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
+ view->Selection.AlreadySelected=1;
}
else
{
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected=0;
- deselect_object (view.g[view.activeGraph],((xdot*)(op->parentxdot))->obj);
- view.Selection.AlreadySelected=1;
+ deselect_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
+ view->Selection.AlreadySelected=1;
}
}
if ( ((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected==0)
{
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected=1;
- select_object (view.g[view.activeGraph],((xdot*)(op->parentxdot))->obj);
- view.Selection.AlreadySelected=1;
+ select_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
+ view->Selection.AlreadySelected=1;
}
else
{
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected=0;
- deselect_object (view.g[view.activeGraph],((xdot*)(op->parentxdot))->obj);
- view.Selection.AlreadySelected=1;
+ deselect_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
+ view->Selection.AlreadySelected=1;
}
}
if( ( ((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->selectionflag != -1 ) && (ellipse_in_rect(op)) )
{
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Preselected=1;
- view.Selection.AlreadySelected=1;
+ view->Selection.AlreadySelected=1;
}
else
{
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Preselected=0;
- view.Selection.AlreadySelected=1;
+ view->Selection.AlreadySelected=1;
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->selectionflag = -1;
}
if(ellipse_x_rect(op))
{
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected=1;
- select_object (view.g[view.activeGraph],((xdot*)(op->parentxdot))->obj);
- view.Selection.AlreadySelected=1;
+ select_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
+ view->Selection.AlreadySelected=1;
}
break;
int SelectText(xdot_op* op)
{
- if(!view.Selection.Active)
+ if(!view->Selection.Active)
return 0;
- switch (view.Selection.Type)
+ switch (view->Selection.Type)
{
case 0:
- if (view.Selection.AlreadySelected)
+ if (view->Selection.AlreadySelected)
return 0;
if( text_x_rect(op))
{
if(text_in_rect(op))
{
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected=1;
- select_object (view.g[view.activeGraph],((xdot*)(op->parentxdot))->obj);
- view.Selection.AlreadySelected=1;
+ select_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
+ view->Selection.AlreadySelected=1;
}
break;
if(text_x_rect(op))
{
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected=1;
- select_object (view.g[view.activeGraph],((xdot*)(op->parentxdot))->obj);
- view.Selection.AlreadySelected=1;
+ select_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
+ view->Selection.AlreadySelected=1;
}
break;
default:
int SelectImage(xdot_op* op)
{
- if(!view.Selection.Active)
+ if(!view->Selection.Active)
return 0;
- switch (view.Selection.Type)
+ switch (view->Selection.Type)
{
case 0:
- if (view.Selection.AlreadySelected)
+ if (view->Selection.AlreadySelected)
return 0;
if( image_x_rect(op))
{
if ( ((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected==0)
{
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected=1;
- select_object (view.g[view.activeGraph],((xdot*)(op->parentxdot))->obj);
- view.Selection.AlreadySelected=1;
+ select_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj);
+ view->Selection.AlreadySelected=1;
}
else
((custom_object_data*)AGDATA(((xdot*)(op->parentxdot))->obj))->Selected=0;
ey=op->u.ellipse.y;
ea=op->u.ellipse.w;
eb=op->u.ellipse.h;
- px=view.Selection.X+SINGLE_SELECTION_WIDTH/2;
- py=view.Selection.Y+SINGLE_SELECTION_WIDTH/2;
+ px=view->Selection.X+SINGLE_SELECTION_WIDTH/2;
+ py=view->Selection.Y+SINGLE_SELECTION_WIDTH/2;
dx = px - ex;
dy = py - ey;
a=(dx*dx)/(ea*ea) + (dy*dy)/(eb*eb);
float x,y;
op->u.polygon.pts[i].y;
op->u.polygon.pts[i].x;
- x=view.Selection.X+SINGLE_SELECTION_WIDTH/2;
- y=view.Selection.Y+SINGLE_SELECTION_WIDTH/2;
+ x=view->Selection.X+SINGLE_SELECTION_WIDTH/2;
+ y=view->Selection.Y+SINGLE_SELECTION_WIDTH/2;
for (i = 0, j = npol-1; i < npol; j = i++) {
deselect_all_graphs(g);
return 1;
}
+int line_intersects (float* x,float* y,float* X,float* Y)
+{
+ //x,y are arrayf of float for two lines parameters theyt hold 4 points with x and y
+ //limitx and limity are float arrays with two points, thse points are the end points of the second line
+ //X,Y are the variables to put intersection point coordinates in
+ pointf pA,pB,pC,pD,pX;
+ pA.x=x[0];pA.y=y[0];
+ pB.x=x[1];pB.y=y[1];
+ pC.x=x[2];pC.y=y[2];
+ pD.x=x[3];pD.y=y[3];
+
+ if(intersect (pA, pB, pC, pD, &pX))
+ {
+ *X=pX.x;
+ *Y=pX.y;
+ if ( (pX.x >=x[2]-0.01) && (pX.x <x[3]+0.01) &&
+ (pX.y >=y[2]-0.01) && (pX.x <y[3]+0.01))
+ {
+ return 1;
+
+ }
+ return 0;
+
+ }
+ else
+ return 0;
+}
+int point_within_ellips_with_coords(float ex,float ey,float ea,float eb,float px,float py)
+{
+
+ float dx,dy;
+ float a;
+ dx = px - ex;
+ dy = py - ey;
+ a=(dx*dx)/(ea*ea) + (dy*dy)/(eb*eb);
+ return (a <= 1);
+}
#include <assert.h>
#include <sys/types.h>
#include <time.h>
+#include "draw.h"
+
#define NEW(t) (t*)malloc(sizeof(t))
s = parseAlign (s, &op->u.text.align);
s = parseInt (s, &op->u.text.width);
s = parseString (s, &op->u.text.text);
- op->u.text.texture=NULL;
op->drawfunc=EmbedText;
break;
int j=0;
int a=0;
char* pch;
- int pos[100]; //maximum pos count hopefully does not exceed 100
+ int pos[MAXIMUM_POS_COUNT]; //maximum pos count hopefully does not exceed 100
if (!x)
return "\0";
break;
}
}
- view.GLx=view.GLx2;
- view.GLy=view.GLy2;
+ view->GLx=view->GLx2;
+ view->GLy=view->GLy2;
return sprintXDot (x);
-//OpenGL extension
void drawXdot (xdot* xDot,int param)
{
int id=0;
}
if ( ((custom_object_data*)AGDATA(xDot->obj))->Preselected == 1)
- select_object (view.g[view.activeGraph],xDot->obj);
+ select_object (view->g[view->activeGraph],xDot->obj);
((custom_object_data*)AGDATA(xDot->obj))->Preselected =0;
}
void execOp (xdot_op* op,int param)
}
void drawXdotwithattrs(void* e,int param)
{
-
-
drawXdotwithattr(e,"_draw_",param);
drawXdotwithattr(e,"_ldraw_",param);
drawXdotwithattr(e,"_hdraw_",param);
drawXdotwithattr(e,"_tdraw_",param);
drawXdotwithattr(e,"_hldraw_",param);
drawXdotwithattr(e,"_tldraw_",param);
-
-}
-void drawGraph(Agraph_t *g)
-{
- Agnode_t *v;
- Agedge_t *e;
- Agraph_t *s;
- int param=0;
-
- for (s = agfstsubg(g); s; s = agnxtsubg(s))
- {
-
- ((custom_object_data*)AGDATA(s))->selectionflag=0;
- if( ((custom_object_data*)AGDATA(s))->Selected==1)
- param=1;
- else
- param=0;
- drawXdotwithattrs(s,param);
- }
-
- for (v = agfstnode(g); v; v = agnxtnode(g, v))
- {
- if( ((custom_object_data*)AGDATA(v))->Selected==1)
- param=1;
- else
- param=0;
- ((custom_object_data*)AGDATA(v))->selectionflag=0;
- drawXdotwithattr(v,"_draw_",param);
- drawXdotwithattr(v,"_ldraw_",param);
- for (e = agfstout(g,v) ; e ; e = agnxtout (g,e))
- {
- ((custom_object_data*)AGDATA(e))->selectionflag=0;
- if( ((custom_object_data*)AGDATA(e))->Selected==1)
- param=1;
- else
- param=0;
-
- drawXdotwithattrs(e,param);
-
- }
- }
- if((view.Selection.Active>0) && (!SignalBlock))
- {
- view.Selection.Active=0;
- drawGraph(g);
- SignalBlock=1;
- expose_event (drawing_area,NULL,NULL);
- SignalBlock=0;
- }
-
-}
-void drawTopViewGraph3(Agraph_t *g)
-{
-// DWORD t1,t2;
- char* pch;
- Agnode_t *v;
- Agedge_t *e;
- Agraph_t *s;
- char buf [100];
- GLfloat a,b;
- glPointSize(2);
-// t1=GetTickCount();
-// glBegin(GL_POINTS);
- for (v = agfstnode(g); v; v = agnxtnode(g, v))
- {
- //use pos to put dots
-/* if( ((custom_object_data*)AGDATA(v))->Selected==1)
- glColor4f(view.selectColor.R,view.selectColor.G,view.selectColor.B,view.selectColor.A);
- else
- glColor4f(view.penColor.R,view.penColor.G,view.penColor.B,view.penColor.A);
- strcpy(buf,agget(v, "pos"));
- a=atof(strtok (buf,"," ));
- b=atof(strtok (NULL,"," ));
- glVertex3f(a ,b,0.0); */
-
- }
-// glEnd();
-// t2=GetTickCount();
-// printf("recorded tickcounts %d-%d \n", t1,t2);
-// printf("iterating time (NODES):%d \n", t2-t1);
-
-
- //draw edges
-/* glBegin(GL_LINES);
- for (v = agfstnode(g); v; v = agnxtnode(g, v))
- {
- for (e = agfstout(g,v) ; e ; e = agnxtout (g,e))
- {
- if( ((custom_object_data*)AGDATA(e))->Selected==1)
- glColor4f(view.selectColor.R,view.selectColor.G,view.selectColor.B,view.selectColor.A);
- else
- glColor4f(view.penColor.R,view.penColor.G,view.penColor.B,view.penColor.A);
- strcpy(buf,agget(aghead(e), "pos"));
- a=atof(strtok (buf,"," ));
- b=atof(strtok (NULL,"," ));
- glVertex3f(a ,b,0.0);
- strcpy(buf,agget(agtail(e), "pos"));
- a=atof(strtok (buf,"," ));
- b=atof(strtok (NULL,"," ));
- glVertex3f(a ,b,0.0);
- }
- }
- glEnd(); */
-}
-void PrepareTopview2(Agraph_t *g)
-{
- float a,b;
- char* pch;
- Agnode_t *v;
- Agedge_t *e;
- int ind,ind2;
- char buf[100];
- ind=0;ind2=0;
- for (v = agfstnode(g); v; v = agnxtnode(g, v))
- {
-
- strcpy(buf,agget(v, "pos"));
- a=atof(strtok (buf,"," ));
- b=atof(strtok (NULL,"," ));
-
- TopViewPointsX[ind]=a;
- TopViewPointsY[ind]=b;
-
-
- for (e = agfstout(g,v) ; e ; e = agnxtout (g,e))
- {
- strcpy(buf,agget(aghead(e), "pos"));
- a=atof(strtok (buf,"," ));
- b=atof(strtok (NULL,"," ));
- TopViewEdgesHeadX[ind2]=a;
- TopViewEdgesHeadY[ind2]=b;
- strcpy(buf,agget(agtail(e), "pos"));
- a=atof(strtok (buf,"," ));
- b=atof(strtok (NULL,"," ));
- TopViewEdgesTailX[ind2]=a;
- TopViewEdgesTailY[ind2]=b;
- ind2++;
- }
- ind++;
- }
- TopViewNodeCount=ind;
- TopViewEdgeCount=ind2;
-}
-void drawTopViewGraph2(Agraph_t *g)
-{
-// DWORD t1,t2;
- int ind=0;
- glPointSize(3);
- glBegin(GL_POINTS);
- for (ind=0;ind < TopViewNodeCount;ind ++)
- {
- glVertex3f(TopViewPointsX[ind] ,TopViewPointsY[ind],0.0);
- }
- glEnd();
- glBegin(GL_LINES);
- for (ind=0;ind < TopViewEdgeCount;ind ++)
- {
-// glColor4f(view.selectColor.R,view.selectColor.G,view.selectColor.B,view.selectColor.A);
- glVertex3f(TopViewEdgesHeadX[ind],TopViewEdgesHeadY[ind],0.0);
- glVertex3f(TopViewEdgesTailX[ind],TopViewEdgesTailY[ind],0.0);
-
- }
- glEnd();
}