Example #1
0
File: event.c Project: jollywho/nav
void event_cycle_once()
{
  bool pstate = mainloop()->running;
  mainloop()->running = false;
  queue_process_events(eventq(), TIMEOUT);
  queue_process_events(drawq(),  TIMEOUT);
  uv_run(eventloop(), UV_RUN_NOWAIT);
  uv_run(eventloop(), UV_RUN_ONCE);
  mainloop()->running = pstate;
}
Example #2
0
File: event.c Project: jollywho/nav
void event_init(void)
{
  log_msg("INIT", "event");
  uv_loop_init(eventloop());
  uv_prepare_init(eventloop(), &mainloop()->event_prepare);
  uv_timer_init(eventloop(), &mainloop()->children_kill_timer);
  uv_signal_init(eventloop(), &mainloop()->children_watcher);
  SLIST_INIT(&mainloop()->children);
  eventloop()->data = eventloop();
  QUEUE_INIT(&eventq()->headtail);
  QUEUE_INIT(&drawq()->headtail);
  mainloop()->running = false;
}
Example #3
0
File: event.c Project: jollywho/nav
static void prepare_events(uv_prepare_t *handle)
{
  log_msg("", "--event--");
  if (mainloop()->running)
    return;

  mainloop()->running = true;
  while (1) {
    queue_process_events(eventq(), TIMEOUT);
    queue_process_events(drawq(),  TIMEOUT);

    if (!mainloop_busy()) {
      uv_prepare_stop(handle);
      break;
    }
    else {
      uv_run(eventloop(), UV_RUN_NOWAIT);
    }
  }
  mainloop()->running = false;
}
Example #4
0
void main()
{

// VARIABLE DECLARATIONS

int i=0,j=0,a,front=-1,rear=-1;
char ch,ch1;
int item;

// FUNCTION PROTOTYPE DECLARATIONS

void show();
void slidebar(int *rear,int *front);
void showqueuesize();
void slidebar();
void cpoiters();
void drawq();
void moveptrs(int *rear,int *front);
void insertq(int *rear,char c);
void deleteq(int *front);
void qdelete(int q[],int rear,int front);
void hidequeueinfo();
void shownumbers(int x1,int y1,int x2,int y2);
int initmouse();
void getmousepos(int *button,int *x,int *y);
void showmouseptr();
void restrictmouseptr(int a,int b,int c,int d);
void exitbutton(int x1,int y1,int x2,int y2,int e_x,int e_y,int xit_x,int xit_y);
void zoomin();

// CHECKING THE GRAPHICS DRIVER

int gd=DETECT,gm,maxx,maxy,x,y,button;
initgraph(&gd,&gm,"c:\\TC");

// GET THE MAXIMUM X AND Y CO ORDINATES

	maxx=getmaxx();
	maxy=getmaxy();

// DRAW THE BORDER FOR THE WINDOW

	rectangle(0,0,maxx,maxy);

// SET THE AREA WITHIN THE SCREEN WHERE GRAPHICAL O/P DISPLAYED

	setviewport(1,1,maxx-1,maxy-1,1);

// WRITE THE HEADDING

	gotoxy(150,1);
	settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
	setcolor(WHITE);
	setbkcolor(216);
	settextjustify(0,2);
	outtextxy(220,2," LINEAR QUEUE ");
	setcolor(RED);
	settextstyle(8,HORIZ_DIR,3);
	outtextxy(40,35,"DEVELOPED IN 'C'  : IT'S A KVSM PRODUCT");
	settextstyle(0,HORIZ_DIR,0);

// INITIALIZE MOUSE,IF IT DOESN'T GET INITIALIZED CLOSE GRAPHICS MODE

	if (initmouse()==0)
	{
		closegraph();
		restorecrtmode();
		printf("\nMouse Driver not installed");
		exit(1);
	}

// IF MOUSE DRIVER INITIALISED THEN
// RESTRICT THE MOUSE POINTER WITHIN THE COORDINATES GIVEN GIVEN BELOW

	restrictmouseptr(1,57,maxx-1,maxy-1);

// SHOW THE MOUSE POINTER

	showmouseptr();

// SET THE TEXT COLOR TO WHITE

	setcolor(WHITE);
	line(0,70,getmaxx(),70);
	line(0,400,getmaxx(),400);

	setcolor(14);
	outtextxy(65,115,"QUEUE OPERATIONS                      QUEUE STATUS");
	outtextxy(140,440,"Press the Key that is Highlighted or use Mouse.");
	setcolor(CYAN);
	line(65,125,190,125);
	line(368,125,464,125);

// CALL THE SHOW FUNCTION TO DRAW THE VARIOUS BUTTONS

	show();

// DRAW THE QUEUE

	drawq();

// DRAW THE POINTERS THAT IS FRONT AND REAR

	moveptrs(&rear,&front);

// SET THE LABEL M THAT WILL BE USED LATER FOR UNCONDITIONAL JUMP

	m:

// GO ON CHECKING WHETHER A KEY IS PRESSED OR NOT

	while (i==0)
	       {
	       if (kbhit())
	       {
	       ch=getche();

	       // CHECK IF THE KEY PRESSED IS E OR e
	       switch(ch)
	       {
	       case 'e':
	       case 'E':

	       {
	       // CALL THE FUNCTION THAT WILL BE FOR EXIT
	       zoomin();
	       }
	       reset:
	       case 'R':
	       case 'r':
	       {
	       // CALL THE RESET QUEUE FUNCTION
	       hidequeueinfo();
	       // CALL THE PROGRESSBAR
	       slidebar(&rear,&front);
	       // AGAIN DRAW THE QUEUE
	       drawq();
	       restrictmouseptr(1,57,maxx-1,maxy-1);
	       goto m;
	       }
	       queueinfo:
	       case 'A' :
	       case 'a':
	       {
	       // CALL THE FUNCTION TO GIVE INFORMATION ABOUT QUEUE
	       hidequeueinfo();
	       showqueuesize();
	       goto m;
	       }
	       delet:
	       case 'D':
	       case 'd':
	       {
	       //  CALL THE DELETE QUEUE OPERATIONS
	       hidequeueinfo();
	       deleteq(&front);
	       // CHECK IF QUEUE IS EMPTY, IF SO PRINT THE MESSAGE
		       if(rear==-1 || front==5 ||rear<front)
			{
			// CLEAR THE INFO, THERE IN INFORMATION PART
			hidequeueinfo();
			// DISPLAY THE TEXT IN THE INFORMATION PART
			outtextxy(200,430,"Queue is empty, you can't delete");
			}
			else
			{
			front=front+1;
			moveptrs(&rear,&front);
			}
		goto m;
	       }
	       ins:
	       case 'I':
	       case 'i':
	       {
	       // HERE IS THE OPERATIONS FOR INSERTING AN ELEMENT
	       hidequeueinfo();
	       if(rear==4)
			{
			hidequeueinfo();
			outtextxy(200,430,"Queue is full, you can't insert");
			goto m;
			}

	       // SHOWS THE NUMBERS AND CANCEL BUTTON
	       shownumbers(20,430,60,470);
	       // CHECK FOR WHAT KEY PRESSED

	       n:

	       while(j==0)
	       {
		 if (kbhit())
		  {
		   ch1=getche();

			       if(front==-1)
			       {
			       front=front+1;
			       }
		   switch(ch1)
		   {
		   cancel:
		   case 'C':
		   case 'c':
		       {
		       hidequeueinfo();
		       restrictmouseptr(1,57,maxx-1,maxy-1);
		       goto m;
		       }
		   zero:
		   case '0':
		       {
			       insertq(&rear,'0');
			       rear=rear+1;
			       moveptrs(&rear,&front);
			       hidequeueinfo();
			       restrictmouseptr(1,57,maxx-1,maxy-1);
			       goto m;
		       }
		   one:
		   case '1':
		       {
			       insertq(&rear,'1');
			       rear=rear+1;
			       moveptrs(&rear,&front);
			       hidequeueinfo();
			       restrictmouseptr(1,57,maxx-1,maxy-1);
			       goto m;
		       }
		   two:
		   case '2':
		       {
			       insertq(&rear,'2');
			       rear=rear+1;
			       moveptrs(&rear,&front);
			       hidequeueinfo();
			       restrictmouseptr(1,57,maxx-1,maxy-1);
			       goto m;
		       }
		   three:
		  case '3':
		       {
			       insertq(&rear,'3');
			       rear=rear+1;
			       moveptrs(&rear,&front);
			       hidequeueinfo();
			       restrictmouseptr(1,57,maxx-1,maxy-1);
			       goto m;
		       }
		  four:
		   case '4':
		       {
			       insertq(&rear,'4');
			       rear=rear+1;
			       moveptrs(&rear,&front);
			       hidequeueinfo();
			       restrictmouseptr(1,57,maxx-1,maxy-1);
			       goto m;
		       }
		   five:
		   case '5':
		       {
			       insertq(&rear,'5');
			       rear=rear+1;
			       moveptrs(&rear,&front);
			       hidequeueinfo();
			       restrictmouseptr(1,57,maxx-1,maxy-1);
			       goto m;
		       }
		   six:
		   case '6':
		       {
			       insertq(&rear,'6');
			       rear=rear+1;
			       moveptrs(&rear,&front);
			       hidequeueinfo();
			       restrictmouseptr(1,57,maxx-1,maxy-1);
			       goto m;
		       }
		   seven:
		   case '7':
		       {
			       insertq(&rear,'7');
			       rear=rear+1;
			       moveptrs(&rear,&front);
			       hidequeueinfo();
			       restrictmouseptr(1,57,maxx-1,maxy-1);
			       goto m;
		       }
		  eight:
		   case '8':
		       {
			       insertq(&rear,'8');
			       rear=rear+1;
			       moveptrs(&rear,&front);
			       hidequeueinfo();
			       restrictmouseptr(1,57,maxx-1,maxy-1);
			       goto m;
		       }
		   nine:
		   case '9':
		       {
			       insertq(&rear,'9');
			       rear=rear+1;
			       moveptrs(&rear,&front);
			       hidequeueinfo();
			       restrictmouseptr(1,57,maxx-1,maxy-1);
			       goto m;
		       }
		   default :
				hidequeueinfo();
				outtextxy(200,430,"Invalid Key Pressed ! Press a valid key");
				delay(550);
				hidequeueinfo();
				shownumbers(20,430,60,470);
				goto n;
		   }
		}
		else
		{
		//write code here to press the 0-----9 and cancel
		       getmousepos(&button,&x,&y);
		       if((button & 1)==1)
		       {
			       if(front==-1)
			       {
			       front=front+1;
			       }
		       }
		       if( (x>500 && x<getmaxx()-10 && y>445 && y<470) && (button & 1)==1)
			{
			goto cancel;
			}
		       if( (x>20 && x<60 && y>430 && y<470) && (button & 1)==1)
			{
			goto zero;
			}
		       if( (x>60 && x<100 && y>430 && y<470) && (button & 1)==1)
			{
			goto one;
			}
		       if( (x>100 && x<140 && y>430 && y<470) && (button & 1)==1)
			{
			goto two;
			}
		       if( (x>140 && x<180 && y>430 && y<470) && (button & 1)==1)
			{
			goto three;
			}
		       if( (x>180 && x<220 && y>430 && y<470) && (button & 1)==1)
			{
			goto four;
			}
		       if( (x>220 && x<260 && y>430 && y<470) && (button & 1)==1)
			{
			goto five;
			}
		       if( (x>260 && x<300 && y>430 && y<470) && (button & 1)==1)
			{
			goto six;
			}
		       if( (x>300 && x<340 && y>430 && y<470) && (button & 1)==1)
			{
			goto seven;
			}
		       if( (x>340 && x<380 && y>430 && y<470) && (button & 1)==1)
			{
			goto eight;
			}
		       if( (x>380 && x<420 && y>430 && y<470) && (button & 1)==1)
			{
			goto nine;
			}
		}
	}
	}
	 default :
			hidequeueinfo();
			outtextxy(220,420,"Please Press a Valid Key");
			goto m;
	 }
	 }
	 // ELSE CONDITION FOR THE IF AFTER THE FIRST WHILE
	 else
	       {

		  getmousepos(&button,&x,&y);
		  if( (x>50 && x<200 && y<370 && y>350) && (button & 1)==1)
			{
			//exit button click
			zoomin();
			}
		  if( (x>50 && x<200 && y>150 && y<170) && (button & 1)==1)
			{
			//clicked the queueinfo button
			goto queueinfo;
			}
		  if( (x>50 && x<200 && y>200 && y<220) && (button & 1)==1)
			{
			//clicked the insert button
			goto ins;
			}

		  if( (x>50 && x<200 && y>250 && y<270) && (button & 1)==1)
			{
			//clicked the delete button
			delay(500);
			goto delet;
			}
		  if( (x>50 && x<200 && y>300 && y<320) && (button & 1)==1)
			{
			//clicked the reset button
			goto reset;
			}

		}


	}

getche();
}
Example #5
0
File: event.c Project: jollywho/nav
bool mainloop_busy()
{
  return !(queue_empty(eventq()) && queue_empty(drawq()));
}