示例#1
0
void GetVertices()      //initially take input in form of vertex
{
	char name_v='A';
	vcount=0;

	setcolor(WHITE);
	outtextxy(50,250,"MINIMUM COST SPANNING TREE...(PRESS ENTER TO CONTINUE)") ;
       getch();

       cleardevice;
	setcolor(BLACK);
		outtextxy(50,250,"MINIMUM COST SPANNING TREE...(PRESS ENTER TO CONTINUE)") ;
	setcolor(LIGHTGREEN);
	outtextxy(4,1,"Click with mouse and press enter to add vertex");
       outtextxy(4,10,"Press 1 if creation of vertices are done");
	 InitMouse();
	ShowMouse();

	do
      //	      while(!kbhit())
	{
	   if(IsClick())
		{
			sprintf(vert[vcount].name,"%c",name_v++);
			vert[vcount].x=o.x.cx;
			vert[vcount].y=o.x.dx;
			vert[vcount].i=vcount;
			vert[vcount].number=vcount+1;
			vertex_fill(&vert[vcount],YELLOW);
			vcount++;
		   //	getch();

	    //   if(kbhit())
	      //	     break;
		       if(getch()=='1')
			break;
			}
	}while(vcount<MAX_VERT); //TOTAL VERTEX

	HideMouse();
}
示例#2
0
void GetEdges()   //take weight from user
{        getch();
    //  cleardevice;
	setcolor(BROWN);
	outtextxy(4,1,"Point with mouse and press enter to add vertex");
       outtextxy(4,10,"Press 1 if creation of vertices are done");
	int i,j,p,q,p1,q1;
	int first_v,second_v,flag1,flag2;
  int count1=0,temp1=0;
  // flag1=flag2=0;
	for(i=0;i<vcount;i++)
		for(j=0;j<vcount;j++)
		{
			adj[i][j]=MAX_NUM;
			extra[i][j]=0;
		}
     InitMouse();
	ShowMouse();
		setcolor(LIGHTGREEN);

	outtextxy(10,20,"Create edges");
	outtextxy(4,30,"Presss right mouse click to select first vertex");
       outtextxy(4,40,"Press left mouse click to select other vertex.");
       outtextxy(4,50,"Press any keyboard key when done ");

 while(!kbhit())
{   flag1=flag2=0;
   if(IsClick())
      {if(count1==0&&o.x.bx==2&&temp1==0) //right button is clicked
	{
	    p=o.x.cx;
	    q=o.x.dx;
	    count1=1;
	    o.x.bx=0;
	    temp1=1;
		for(int i=0;i<vcount;i++)
	     {
	       if((dist(vert[i].x,vert[i].y,p,q))<=20&& flag1==0)
	       {    first_v=i;
			 vertex_fill(&vert[first_v],WHITE);
		  //break;
		  flag1=1;
		}
	     }
	  }
	    }
	  //  getch();

	  if(IsClick())
     { if(o.x.bx==1&&count1==1&&temp1==1)
      {
       count1=0;
       p1=o.x.cx;
       q1=o.x.dx;
       temp1=0;


		 for(int j=0;j<vcount;j++)
		 {
		    if(dist(vert[j].x,vert[j].y,p1,q1)<=20&& flag2==0 && j!=first_v)
		    {       second_v=j;
				 vertex_fill(&vert[second_v],WHITE);
				 flag2=1;

		     Edge_fill(&vert[first_v],&vert[second_v],RED,FALSE);
		     adj[first_v][second_v]=adj[second_v][first_v]=-1;
		      //	break;
		    }
		 }
      }
     }


	   }


 }
示例#3
0
/*****************************************************************************
 *
 * Builtin which determines if the button press was a click or double click...
 *
 ****************************************************************************/
void ComplexFunction(XEvent * eventp, Window w, FvwmWindow * tmp_win,
                     unsigned long context, char *action, int *Module)
{
    char type = MOTION;
    char c;
    MenuItem *mi;
    Bool Persist = False;
    Bool HaveDoubleClick = False;
    Bool NeedsTarget = False;
    char *arguments[10], *junk, *taction;
    int x, y, i;
    XEvent d, *ev;
    MenuRoot *mr;
    extern Bool desperate;

    mr = FindPopup(action);
    if (mr == NULL) {
        if (!desperate)
            fvwm_msg(ERR, "ComplexFunction", "No such function %s", action);
        return;
    }
    desperate = 0;
    /* Get the argument list */
    /* First entry in action is the function-name, ignore it */
    action = GetNextToken(action, &junk);
    if (junk != NULL)
        free(junk);
    for (i = 0; i < 10; i++)
        action = GetNextToken(action, &arguments[i]);
    /* These built-ins require a selected window
     * The function code is >= 100 and < 1000
     * F_RESIZE
     * F_MOVE
     * F_ICONIFY
     * F_RAISE
     * F_LOWER
     * F_DESTROY
     * F_DELETE
     * F_STICK
     * F_RAISELOWER
     * F_MAXIMIZE
     * F_FOCUS
     *
     * These do not:
     * The function code is < 100
     * F_NOP
     * F_TITLE
     * F_BEEP
     * F_SCROLL
     * F_MOVECURSOR
     * F_RESTART
     * F_EXEC
     * F_REFRESH
     * F_GOTO_PAGE
     * F_TOGGLE_PAGE
     * F_CIRCULATE_UP
     * F_CIRCULATE_DOWN
     * F_WARP
     * F_DESK
     * F_MODULE
     * F_POPUP
     * F_QUIT
     * F_WINDOWLIST
     * F_FUNCTION
     * F_SEND_WINDOW_LIST
     */
    ev = eventp;
    /* In case we want to perform an action on a button press, we
     * need to fool other routines */
    if (eventp->type == ButtonPress)
        eventp->type = ButtonRelease;
    mi = mr->first;
    while (mi != NULL) {
        /* make lower case */
        c = *(mi->item);
        if ((mi->func_type >= 100) && (mi->func_type < 1000))
            NeedsTarget = True;
        if (isupper(c))
            c = tolower(c);
        if (c == DOUBLE_CLICK) {
            HaveDoubleClick = True;
            Persist = True;
        } else if (c == IMMEDIATE) {
            if (tmp_win)
                w = tmp_win->frame;
            else
                w = None;
            taction = expand(mi->action, arguments, tmp_win);
            ExecuteFunction(taction, tmp_win, eventp, context, -2);
            free(taction);
        } else
            Persist = True;
        mi = mi->next;
    }

    if (!Persist) {
        for (i = 0; i < 10; i++)
            if (arguments[i] != NULL)
                free(arguments[i]);
        return;
    }

    /* Only defer execution if there is a possibility of needing
     * a window to operate on */
    if (NeedsTarget) {
        if (DeferExecution
                (eventp, &w, &tmp_win, &context, SELECT, ButtonPress)) {
            WaitForButtonsUp();
            for (i = 0; i < 10; i++)
                if (arguments[i] != NULL)
                    free(arguments[i]);
            return;
        }
    }

    if (!GrabEm(SELECT)) {
        XBell(dpy, Scr.screen);
        for (i = 0; i < 10; i++)
            if (arguments[i] != NULL)
                free(arguments[i]);
        return;
    }
    XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild,
                  &x, &y, &JunkX, &JunkY, &JunkMask);


    /* Wait and see if we have a click, or a move */
    /* wait 100 msec, see if the user releases the button */
    if (IsClick(x, y, ButtonReleaseMask, &d)) {
        ev = &d;
        type = CLICK;
    }

    /* If it was a click, wait to see if its a double click */
    if ((HaveDoubleClick) && (type == CLICK) &&
            (IsClick(x, y, ButtonPressMask, &d))) {
        type = ONE_AND_A_HALF_CLICKS;
        ev = &d;
    }
    if ((HaveDoubleClick) && (type == ONE_AND_A_HALF_CLICKS) &&
            (IsClick(x, y, ButtonReleaseMask, &d))) {
        type = DOUBLE_CLICK;
        ev = &d;
    }
    /* some functions operate on button release instead of
     * presses. These gets really weird for complex functions ... */
    if (ev->type == ButtonPress)
        ev->type = ButtonRelease;

    mi = mr->first;
    while (mi != NULL) {
        /* make lower case */
        c = *(mi->item);
        if (isupper(c))
            c = tolower(c);
        if (c == type) {
            if (tmp_win)
                w = tmp_win->frame;
            else
                w = None;
            taction = expand(mi->action, arguments, tmp_win);
            ExecuteFunction(taction, tmp_win, ev, context, -2);
            free(taction);
        }
        mi = mi->next;
    }
    WaitForButtonsUp();
    UngrabEm();
    for (i = 0; i < 10; i++)
        if (arguments[i] != NULL)
            free(arguments[i]);
}