static gint
timeout (C2NetworkTraffic *nt)
{
	gint current_recv, current_send, record;
	gint seconds_to_display; /* This is a dynamic value, the
							  * SECONDS_TO_DISPLAY constant
							  * is about how much we WISH to
							  * display, not how much we WILL
							  * display.
							  */
	GtkWidget *widget = GTK_WIDGET (nt);

	seconds_to_display = widget->allocation.width / PIXELS_PER_SECOND;

	current_recv = c2_net_speed_tracker_recv ();
	current_send = c2_net_speed_tracker_send ();

	if (g_slist_length (nt->recv) > seconds_to_display)
		nt->recv = g_slist_remove_link (nt->recv, g_slist_last (nt->recv));
	nt->recv = g_slist_prepend (nt->recv, (gpointer) current_recv);

	if (g_slist_length (nt->send) > seconds_to_display)
		nt->send = g_slist_remove_link (nt->send, g_slist_last (nt->send));
	nt->send = g_slist_prepend (nt->send, (gpointer) current_send);

	/* Update the maximum speed */
	record = current_send > current_recv ? current_send : current_recv;
	if (record > nt->top_speed)
		nt->top_speed = record;
	else
	{
		GSList *l;

		nt->top_speed = 1024;

		for (l = nt->send; l; l = g_slist_next (l))
			if (GPOINTER_TO_INT (l->data) > nt->top_speed)
				nt->top_speed = GPOINTER_TO_INT (l->data);
		for (l = nt->recv; l; l = g_slist_next (l))
			if (GPOINTER_TO_INT (l->data) > nt->top_speed)
				nt->top_speed = GPOINTER_TO_INT (l->data);
	}

	/* Time to draw */
	draw_background (nt);
	draw_top_speed (nt);
	draw_list (nt, nt->send);
	draw_list (nt, nt->recv);
	draw_screen (nt);
	
	return TRUE;
}
Пример #2
0
int main()
{
	int quit = 0;
	int row, col;
	WINDOW *win;

	initscr();
	start_color();
	getmaxyx(stdscr, row, col);

	init_pair(1, COLOR_RED, COLOR_BLACK);
	printw("rows: %d, cols %d", row, col);

	refresh();
	noecho();
	cbreak();

	win = newwin(row-6, col-2, 2, 1);
	box(win, 0 , 0);
	draw_list(win);
	wrefresh(win);
	keypad(win, TRUE);
	curs_set(0);

	while (!quit) {
		int ch = getch();
		mvwaddstr(win, 20, 1, "key:");
		attron(A_BOLD);
		wprintw(win, "%d %c", ch, ch);
		attroff(A_BOLD);
		switch (ch) {
			case 'q': case 'Q':
				quit = 1;
				break;
			case 'A':
				if (--sel < 0)
					sel = ncount-1;
				break;
			case 'B':
				if (++sel >= ncount)
				sel = 0;
				break;
		}
		draw_list(win);
		wrefresh(win);
	}

	endwin();
	return 0;
}
Пример #3
0
int				main(int ac, char **av)
{
	t_env	env;

	if (!(isatty(0)))
		error_quit("Invalid stdin, please run from terminal");
	g_env = &env;
	env.old_width = 0;
	env.old_height = 0;
	env.list_size = ac - 1;
	env.items = NULL;
	get_tty_fd(&env);
	build_list(&env, ac, av);
	env.curr = env.items;
	init_signals();
	tgetent(0, getenv("TERM"));
	if (!(env.caps = malloc(sizeof(*env.caps))))
		error_quit("Failed to malloc env caps");
	init_caps(env.caps);
	key_codes_init(&env);
	terminal_catch();
	env.fd = 2;
	while (1)
	{
		draw_list(&env);
		read_stdin(&env);
	}
}
Пример #4
0
int main(void)
{	
	entry* entries = main_create_entries();
	list* menu = create_list(0,24,25,entries,MAINMENU_SIZE);
	nio_scrbuf_init();
	do
	{
		int selection = update_list(menu);
		if(selection != -1)
		{
			wait_no_key_pressed();
			switch(selection)
			{
				case 0:
					display_tasks_screen();
					break;
				case 1:
					display_pools_screen();
					break;
				case 2:
					display_events_screen();
					break;
				case 3:
					display_queues_screen();
					break;
				case 4:
					display_semaphores_screen();
					break;
				case 5:
					display_mailboxes_screen();
					break;
				default:
					display_settings_screen();
					break;
			}
		}
		
		nio_scrbuf_clear();
		
		nio_grid_printf(0,0,0,0,NIO_COLOR_WHITE,NIO_COLOR_BLACK,"TI-Nspire Task Manager (built %s %s)",__DATE__,__TIME__);
		int i;
		for(i = 0; i < 53; i++)
		{
			nio_grid_putc(0,0,i,2,'-',NIO_COLOR_WHITE,NIO_COLOR_BLACK);
			nio_grid_putc(0,0,i,28,'-',NIO_COLOR_WHITE,NIO_COLOR_BLACK);
		}
		draw_list(menu);
		nio_grid_puts(0,0,0,29,"Use UP/DOWN keys to navigate, ENTER to select",NIO_COLOR_WHITE,NIO_COLOR_BLACK);
		
		nio_scrbuf_flip();
		wait_key_pressed();
	} while(!isKeyPressed(KEY_NSPIRE_ESC));
	
	nio_scrbuf_free();
	free(entries);
	free(menu);
	return 0;
}
Пример #5
0
/*
 * Callback for the horizontal slider, when it moves this function is called.
 */
static int hscroll_cb( LUI_SCROLLBAR *sb, float pos )
{
   int newleft;
   LUI_LIST *list;

   list = (LUI_LIST *) sb->userdata;

   newleft = (list->maxwidth - list->columns) * pos / 100.0;
   if (newleft != list->leftoffset) {
      list->leftoffset = newleft;
      draw_list( list );
   }
   return 1;
}
Пример #6
0
/*
 * Callback for the vertical slider, when it moves this function is called.
 */
static int vscroll_cb( LUI_SCROLLBAR *sb, float pos )
{
   int newtop;
   LUI_LIST *list;

   list = (LUI_LIST *) sb->userdata;

   newtop = (list->numstrings - list->rows) * pos / 100.0;
   if (newtop != list->topstring) {
      list->topstring = newtop;
      draw_list( list );
   }
   return 1;
}
Пример #7
0
/*
 * Deallocate the strings in a list widget.  The strings *must* have been
 * originally been allocated with malloc()!
 */
void LUI_ListUnload( LUI_LIST *list )
{
   if (list->free_flag && list->strings) {
      int i;
      for (i=0;i<list->numstrings;i++) {
         free( list->strings[i] );
      }
      free( list->strings );
      free( list->select_flags );
      list->strings = NULL;
      list->select_flags = NULL;
      list->numstrings = 0;

      draw_list( list );
      LUI_ScrollBarSet( list->vsb, 100.0, 0.0 );
   }
}
Пример #8
0
void fireworks::draw()
{
	draw_list(from_player);
	draw_list(from_enemies);
}
Пример #9
0
/*
 * Load an array of strings into the list widget.  Then, redraw the widget.
 * Input:  list - the list widget;
 *         num - number of strings
 *         strings - array of pointers to character arrays (like main's argv)
 *         free_flag - 1=free strings when finished, 0=never free strings
 */
void LUI_ListLoad( LUI_LIST *list, int num, char **strings, int free_flag )
{
   float size;
   int i;

   if (!list) {
      printf("Error in LUI_ListLoad:  NULL list argument\n");
      return;
   }

   /* deallocate old list */
   if (list->free_flag && list->strings) {
      for (i=0;i<list->numstrings;i++) {
         free( list->strings[i] );
      }
      free( list->strings );
   }
   if (list->select_flags) {
      free( list->select_flags );
      list->select_flags = NULL;
   }


   /* store new strings */
   list->free_flag = free_flag;
   list->strings = strings;
   list->numstrings = num;
   if (num>0) {
      list->select_flags = (int *) calloc( num, sizeof(int) );
   }
   list->topstring = 0;

   /* find width, in pixels, of longest line */
   list->maxwidth = 0;
   for (i=0;i<num;i++) {
      int dir, ascent, descent;
      XCharStruct overall;
      XTextExtents( LUI_Font, strings[i], strlen(strings[i]),
                    &dir, &ascent, &descent, &overall );
      if (overall.width > list->maxwidth) {
         list->maxwidth = overall.width;
      }
   }

   draw_list( list );

   /* vertical scrollbar */
   if (num==0) {
      size = 100.0;
   }
   else {
      size = 100.0 * (float) list->rows / (float) num;
      if (size>100.0) {
         size = 100.0;
      }
   }
   LUI_ScrollBarSet( list->vsb, size, 0.0 );

   /* horizontal scrollbar */
   if (list->hsb) {
      if (list->maxwidth==0) {
         size = 100.0;
      }
      else {
         size = 100.0 * (float) list->columns / (float) list->maxwidth;
         if (size>100.0) {
            size = 100.0;
         }
      }
      LUI_ScrollBarSet( list->hsb, size, 0.0 );
   }
}
Пример #10
0
/*
 * When an X event occurs in the list window, this function will be called.
 * Input:  list - which list widget
 *         event - the X event
 */
static int list_process( LUI_LIST *list, XEvent *event )
{
   static int prev_entry = -1;

   switch (event->type) {
      case Expose:
         draw_list( list );
         break;

      case ButtonPress:
         {
            /* main window */
            int row, i;
            row = (event->xbutton.y - LUI_Border) / FONT_HEIGHT;
            i = list->topstring + row;
            if (i<list->numstrings) {
               /* toggle status */
               list->select_flags[i] = !list->select_flags[i];
               prev_entry = i;
               draw_entry( list, i );
               XSync( LUI_Display, 0 );
               if (list->callback) {
                  (*list->callback)( list, i, list->select_flags[i] );
               }
            }
         }
         break;

      case MotionNotify:
         {
            /* main window */
            int row, i;
            row = (event->xmotion.y - LUI_Border) / FONT_HEIGHT;
            if (row>=0 && row<list->rows) {
               i = list->topstring + row;
#ifdef JUNK
            if (row>=list->rows && i<list->numstrings) {
               /* scroll down */
               list->topstring++;
               draw_list(list);
               LUI_ScrollBarSetPos( list->vsb,
                   100.0 * list->topstring / (list->numstrings-list->rows) );
            }
            else if (row<0 && i>0) {
               /* scroll up */
               list->topstring--;
               draw_list(list);
               LUI_ScrollBarSetPos( list->vsb,
                   100.0 * list->topstring / (list->numstrings-list->rows) );
            }
#endif
               if (i>=0 && i<list->numstrings && i!=prev_entry) {
                  int j;
                  if (i>prev_entry) {
                     for (j=prev_entry+1; j<=i; j++) {
                        /* toggle status */
                        list->select_flags[j] = !list->select_flags[j];
                        draw_entry( list, j );
                        if (list->callback) {
                           (*list->callback)( list, j, list->select_flags[j] );
                        }
                     }
                  }
                  else {
                     for (j=prev_entry-1;j>=i;j--) {
                        /* toggle status */
                        list->select_flags[j] = !list->select_flags[j];
                        draw_entry( list, j );
                        if (list->callback) {
                           (*list->callback)( list, j, list->select_flags[j] );
                        }
                     }
                  }
                  prev_entry = i;
               }
            }
         }
         break;

      case ButtonRelease:
         prev_entry = -1;
         break;

      case EnterNotify:
         break;
      case LeaveNotify:
         break;

      default:
         printf("Error in list_process:  unexpected event (%d)\n",
                (int) event->type );
   }
   return 1;
}
Пример #11
0
	void View_list::update(Core *c){
		layout();
		draw_list();
		draw_view(c);
	}
Пример #12
0
int FeOverlay::languages_dialog()
{
	std::vector<std::string> ll;
	m_feSettings.get_languages_list( ll );

	if ( ll.size() <= 1 )
	{
		// if there is nothing to select, then set what we can and get out of here
		//
		m_feSettings.set_language( ll.empty() ? "en" : ll.front() );
		return 0;
	}

	// Try and get a useful default setting based on POSIX locale value...
	//
	// TODO: figure out how to do this right on Windows...
	//
	std::string loc, test( "en" );
	try { loc = std::locale("").name(); } catch (...) {}
	if ( loc.size() > 1 )
		test = loc;

	int status( -2 ), current_i( 0 ), i( 0 );
	std::vector<std::string> pl;
	for ( std::vector<std::string>::iterator itr=ll.begin(); itr != ll.end(); ++itr )
	{
		if (( status < 0 ) && ( test.compare( 0, 5, (*itr) ) == 0 ))
		{
			current_i = i;
			status = 0;
		}
		else if (( status < -1 ) && ( test.compare( 0, 2, (*itr)) == 0 ))
		{
			current_i = i;
			status = -1;
		}

		pl.push_back( std::string() );
		m_feSettings.get_resource( (*itr), pl.back() );
		i++;
	}

	sf::Vector2i size;
	sf::Vector2f text_scale;
	int char_size;
	get_common( size, text_scale, char_size );

	FeListBox dialog(
		m_fePresent.get_font(),
		m_textColour,
		m_bgColour,
		m_selColour,
		m_selBgColour,
		char_size,
		size.y / ( char_size * 1.5 * text_scale.y ) );

	dialog.setPosition( 0, 0 );
	dialog.setSize( size.x, size.y );
	dialog.init();
	dialog.setTextScale( text_scale );

	std::vector<sf::Drawable *> draw_list( 1, &dialog );

	int sel = current_i;
	dialog.setText( sel, pl );

	FeEventLoopCtx c( draw_list, sel, current_i, pl.size() - 1 );

	while ( event_loop( c ) == false )
		dialog.setText( sel, pl );

	if ( sel >= 0 )
		m_feSettings.set_language( ll[sel] );

	return sel;
}