Ejemplo n.º 1
0
ScalePicker::ScalePicker(QwtPlot *plot)
    : QObject(plot), d_title_selected(false), d_labels_selected(false),
      d_selected_axis(NULL), d_current_axis(NULL) {
  refresh();
}
Ejemplo n.º 2
0
void print_stats(int stat_mask)
{
	char buf[16];
	boolean label;
	int row = DROWS - 1;

	label = (stat_mask & STAT_LABEL) ? 1 : 0;

	if (stat_mask & STAT_LEVEL)
	{
		if (label)
		{
			mvaddstr(row, 0, "Level: ");
		}
		/* max level taken care of in make_level() */
		sprintf(buf, "%d", cur_level);
		mvaddstr(row, 7, buf);
		pad(buf, 2);
	}
	if (stat_mask & STAT_GOLD)
	{
		if (label)
		{
			if (rogue.gold > MAX_GOLD)
			{
				rogue.gold = MAX_GOLD;
			}
			mvaddstr(row, 10, "Gold: ");
		}
		sprintf(buf, "%ld", rogue.gold);
		mvaddstr(row, 16, buf);
		pad(buf, 6);
	}
	if (stat_mask & STAT_HP)
	{
		if (label)
		{
			mvaddstr(row, 23, "Hp: ");
			if (rogue.hp_max > MAX_HP)
			{
				rogue.hp_current -= (rogue.hp_max - MAX_HP);
				rogue.hp_max = MAX_HP;
			}
		}
		sprintf(buf, "%d(%d)", rogue.hp_current, rogue.hp_max);
		mvaddstr(row, 27, buf);
		pad(buf, 8);
	}
	if (stat_mask & STAT_STRENGTH)
	{
		if (label)
		{
			mvaddstr(row, 36, "Str: ");
		}
		if (rogue.str_max > MAX_STRENGTH)
		{
			rogue.str_current -= (rogue.str_max - MAX_STRENGTH);
			rogue.str_max = MAX_STRENGTH;
		}
		sprintf(buf, "%d(%d)", (rogue.str_current + add_strength), rogue.str_max);
		mvaddstr(row, 41, buf);
		pad(buf, 6);
	}
	if (stat_mask & STAT_ARMOR)
	{
		if (label)
		{
			mvaddstr(row, 48, "Arm: ");
		}
		if (rogue.armor && (rogue.armor->d_enchant > MAX_ARMOR))
		{
			rogue.armor->d_enchant = MAX_ARMOR;
		}
		sprintf(buf, "%d", get_armor_class(rogue.armor));
		mvaddstr(row, 53, buf);
		pad(buf, 2);
	}
	if (stat_mask & STAT_EXP)
	{
		if (label)
		{
			mvaddstr(row, 56, "Exp: ");
		}
		/*  Max exp taken care of in add_exp() */
		sprintf(buf, "%d/%ld", rogue.exp, rogue.exp_points);
		mvaddstr(row, 61, buf);
		pad(buf, 11);
	}
	if (stat_mask & STAT_HUNGER)
	{
		mvaddstr(row, 73, hunger_str);
		clrtoeol();
	}
	refresh();
}
Ejemplo n.º 3
0
short get_input_line(char *prompt, char *buf, char *insert, char *if_cancelled,
                     boolean add_blank, boolean do_echo)
{
	short ch;
	short i = 0, n;

	message(prompt, 0);
	n = strlen(prompt);

	if (insert[0])
	{
		mvaddstr(0, n + 1, insert);
		(void) strcpy(buf, insert);
		i = strlen(insert);
		move(0, (n + i + 1));
		refresh();
	}

	while (((ch = rgetchar()) != '\r') && (ch != '\n') && (ch != ROGUE_KEY_CANCEL))
	{
		if ((ch >= ' ') && (ch <= '~') && (i < MAX_TITLE_LENGTH-2))
		{
			if ((ch != ' ') || (i > 0))
			{
				buf[i++] = ch;
				if (do_echo)
				{
					addch(ch);
				}
			}
		}
		//TODO:  Backspace key is not \b, need to determine correct value.
		if ((ch == '\b') && (i > 0))
		{
			if (do_echo)
			{
				mvaddch(0, i + n, ' ');
				move(MIN_ROW-1, i+n);
			}
			i--;
		}
		refresh();
	}
	check_message();
	if (add_blank)
	{
		buf[i++] = ' ';
	}
	else
	{
		while ((i > 0) && (buf[i-1] == ' '))
		{
			i--;
		}
	}

	buf[i] = 0;

	if ((ch == ROGUE_KEY_CANCEL) || (i == 0) || ((i == 1) && add_blank))
	{
		if (if_cancelled)
		{
			message(if_cancelled, 0);
		}
		return(0);
	}
	return(i);
}
Ejemplo n.º 4
0
int main(int argc, char *argv[]) {
int right[4], guess[4], backup[4];
int halfrights,rights;
int tmp,i;
int tries = 3;
int maxtries;
int place,color;
int x,y;
char charbuffer[10];
char question[2];
int pplace[4];
pplace[0] = 13;
pplace[1] = 15;
pplace[2] = 17;
pplace[3] = 19;

halfrights=rights=0;

srand(time(0));

printf("Can two places be the same color? (y/n) ");
scanf("%s",charbuffer);
strcpy(question,"n");
if (strcmp(charbuffer,question) == 0) {
	for (i=0;i<4;i++) {
		BACK:
		right[i] = (8.0*rand()/RAND_MAX+1.0);
		for (tmp=0;tmp<4;tmp++) {
			if (right[i] == right[tmp] && i != tmp) {
				goto BACK;
			}
		}
		guess[i] = 0;
	}
} else {
	for (i=0;i<4;i++) {
		right[i] = (8.0*rand()/RAND_MAX+1.0);
		guess[i] = 0;
	}
}


for (i=0;i<4;i++) {
	backup[i] = right[i];
}

printf("How many tries would you like? ");
scanf("%i",&maxtries);
printf("\n");
if (maxtries <= 0) {
printf("Ok, fine.\n");
return 1;
}

printf("\nI have come up with a color combination. Press enter to start the game.\n");

getchar();
getchar();

initscr();
start_color();

getmaxyx(stdscr,y,x);

if (y < 22) {
	endwin();
	printf("Terminal too small\n");
	return 1;
}

if (maxtries > (x/3-3)) {
endwin();
printf("You have too many tries to be on the screen.\n");
return 1;
}

/* Color definations: */
init_pair(1, COLOR_WHITE, COLOR_RED);
init_pair(2, COLOR_WHITE, COLOR_GREEN);
init_pair(3, COLOR_WHITE, COLOR_BLUE);
init_pair(4, COLOR_WHITE, COLOR_BLACK);
init_pair(5, COLOR_WHITE, COLOR_MAGENTA);
init_pair(6, COLOR_BLACK, COLOR_WHITE);
init_pair(7, COLOR_WHITE, COLOR_CYAN);
init_pair(8, COLOR_WHITE, COLOR_YELLOW);


mvprintw(5,0,"Colors: 1: Red, 2: Green, 3: Blue, 4: Black");
mvprintw(6,0,"Colors: 5: Magenta, 6: White, 7: Cyan, 8: Yellow");

mvprintw(8,0,"Right colors on right places:");
mvprintw(10,0,"Right colors on wrong places:");

mvprintw(pplace[0],0,"1:");
mvprintw(pplace[1],0,"2:");
mvprintw(pplace[2],0,"3:");
mvprintw(pplace[3],0,"4:");

mvprintw(0,x/2-10,"Tries left: %i ",maxtries);

GETPLACE:
mvprintw(0,0,"Place:");
mvprintw(1,2," ");
mvprintw(1,0,"? ");
scanw("%i",&place);
if (place < 1 || place > 4) { /* if the user types too many */
	for (i=2;i<=x;i++) {  /* cifers, we want to clean it up */
	mvprintw(1,i," ");
	}
goto GETPLACE;
}
GETCOLOR:
mvprintw(0,0,"Color:");
mvprintw(1,2," ");
move(1,2);
scanw("%i",&color);
if (color < 1 || color > 8) { /* same here */
	for (i=2;i<=x;i++) {
	mvprintw(1,i," ");
	}
goto GETCOLOR;
}

attrset(COLOR_PAIR(color));

mvprintw(pplace[place-1],tries,"%i",color);

attrset(A_NORMAL);

guess[place-1] = color;

tmp = 1;
for (i=0;i<4;i++) {
	if (guess[i] == 0) {
	tmp = 0;	
	}
}

if (tmp) { /* All fields are filled */
	mvprintw(pplace[3]+2,4,"Is that a guess? (y/n) ");
	refresh();
	scanw("%s",charbuffer);
	strcpy(question,"y");
	for (i=4;i<=x;i++) {
		mvprintw(pplace[3]+2,i," ");
	}

	if (strcmp(charbuffer,question) == 0) {
		for (i=0;i<4;i++) {
			if (right[i] == guess[i]) {  /* Finds out how many right colors on right places */
				rights++;	     /* the user has placed. */
				right[i] = guess[i] = 0; /* This line makes sure this guess is not counted again */
			}
		}
		for (i=0;i<4;i++) {
			for (tmp=0;tmp<4;tmp++) {

				if (guess[tmp] == right[i] && right[i] != 0) {
					halfrights++;
					guess[tmp] = right[i] = 0; /* This line makes sure this guess is not counted again */
				}

			}
		}

		if (rights == 4) {
			endwin();
			printf("CONGRATULATIONS!\n");
			printf("You guessed the right combination!\n");
			printf("You used %i tries\n", tries/3);

			return 0;
		}
	
		for (i=0;i<4;i++) {
			right[i] = backup[i];  /* We deleted the right[] array, we have to get it back for next check */
		}


		mvprintw(9,tries,"%i",rights);
		mvprintw(11,tries,"%i",halfrights);
		

		halfrights=rights=0;
		for (i=0;i<4;i++) {
			guess[i] = 0;
		}
		tries = tries+3;
		maxtries--;
		mvprintw(0,x/2-10,"Tries left: %i ",maxtries);
		if (maxtries == 0) {
			for (i=0;i<4;i++) {
				attrset(COLOR_PAIR(right[i]));

				mvprintw(pplace[i],0,"%i",right[i]);

				attrset(A_NORMAL);

			}
			mvprintw(y-2,0,"Wrong, and you are out of tries..\n");
			printw("Press enter to end program");
			refresh();
			getchar();
			endwin();
			return 1;
		}
	}
}


goto GETPLACE;

endwin();
return 0;
}
Ejemplo n.º 5
0
int main(void)
{
//extern variables
char *help_topic=NULL,*fname=NULL,buff[5000]={'\0'},file[50]={};
int logc,logr,ch,i,j,k,flag;
FILE *fp;

// initialise curses mode and colors
initCurses();
noecho();
cbreak();
keypad(stdscr,TRUE);
mousemask(ALL_MOUSE_EVENTS,NULL);
curs_set(0);

//displays starting blue screen
Screen();
	while(1)
	{
		int ch;
		ch=getResponse();
		switch(ch)
		{
			//file menu
			case 1:
					//pop up menu file
					(WINDOW**)draw_menu(fmenu,SIZE(fmenu),1,0);
			break;
			
			//new item
			case 2:
				refresh();
				//draws black screen
				new_file();
				noecho();
				//displays filename and line number on black screen
				New();						
			break;
			
			//Return To Shell
			case 5:
				clear();
	       		refresh();
	       		endwin();
	       		system("sh");
	       		clear();
				refresh();
				Screen();
			break;
			
			//exit menu
			case 6:
				clear();
	    		refresh();
				endwin();
				exit(EXIT_SUCCESS);
			break;
			
			/*compile menu
			case 7:
				//pop up menu compile
					(WINDOW**)draw_menu(cmenu,SIZE(cmenu),1,12);
			break;
			
			*/
			/*compile item
			case 8:
				compile();
			break;*/
			
			//help menu
			case 11:
				//pop up  help menu
 					(WINDOW**)draw_menu(hmenu,SIZE(hmenu),1,27);
			break;
			
			//help index
			case KEY_F(1):
			case 12:
				Help();
			break;
			
			//help topic
			case 13:
				help_topic=(char*)calloc(30,sizeof(char));
				help_topic=dialog("| Help |"," Find "," Cancel ");
			break;
			
			
			
			//open file
			case KEY_F(3):
			case 3:
						k=0;
					for(i=2;i<22;++i)
					{
						for(j=0;j<78;++j)
							buff[k++]=(mvinch(i,j)&A_CHARTEXT);
						buff[k++]='\n';
					}
				new_file();
					//pops up open dialogbox				
				fname=(char*)calloc(30,sizeof(char));
				fname=dialog("| Open |"," Open "," Cancel ");
				
				//if user press cancel display screen contents
				if((strlen(fname)==0))
				{
					logc=1;logr=2;
					for(k=0;buff[k]!='\0';++k)
					{
						refresh();
						if(buff[k]=='\n')
						{
					        logr+=1;
					        logc=1;
					       	move(logr+1,logc);
						}
						else
						{
							mvaddch(logr,logc,buff[k]);
							logc+=1;
						}
					}
				}
				
				//othewise open a file and display it's contents
				else
				{
					//redraws new screen
					new_file();
				
				
					if(!(fp=fopen(fname,"r")))
					{
						warning("| Warning |","	No such file ","Press a key to return !!!");
						getch();
						//new_file();
							logc=1;logr=2;
							for(k=0;buff[k]!='\0';++k)
							{
								refresh();
								if(buff[k]=='\n')
								{
					        		logr+=1;
					        		logc=1;
					       			 move(logr+1,logc);
								}
								else
								{
									mvaddch(logr,logc,buff[k]);
									logc+=1;
								}
							}	
					
					}
					//if file is exist display contents 
					else
					{	
						new_file();
						logc=1;logr=2;
						while((ch=fgetc(fp))!=EOF)
						{
							if(ch=='\n')
							{
						        logr+=1;
						        logc=1;
						        move(logr+1,logc);
							}
							else
							{
								mvaddch(logr,logc,ch);
								logc+=1;
							}
						}
						fclose(fp);
						move(2,2);
						refresh();
						
						//displays file name
							move(1,2);
						hline(ACS_HLINE,75);
						strcat(file,"| ");
						strcat(file,fname);
						strcat(file," |");
						//move(1,2);
						//hline(ACS_HLINE,60);
						writeString(stdscr,1,35,file,white_black);
					}
				}
			break;
			
			
		}
	}
}
Ejemplo n.º 6
0
void ccHistogramWindow::clear()
{
	clearInternal();
	refresh();
}
Ejemplo n.º 7
0
void pintar(struct TMovil movil){
   mvprintw(20 - movil.posicion.y, movil.posicion.x, "O");
   refresh();
}
Ejemplo n.º 8
0
void
domove(int okay)
{
	int     i;		/* index */
	int     l = 0;		/* last man */

	bestmove = -9999999.;
	if (okay) {
	    	/* see if comp should double */
		if (dflag && gvalue < 64 && dlast != cturn && dblgood()) {
			addstr(*Colorptr);
			dble();	/* double */
			/* return if declined */
			if (cturn != 1 && cturn != -1)
				return;
		}
		roll();
	}
	race = 0;
	for (i = 0; i < 26; i++) {
		if (board[i] < 0)
			l = i;
	}
	for (i = 0; i < l; i++) {
		if (board[i] > 0)
			break;
	}
	if (i == l)
		race = 1;

	/* print roll */
	move(cturn == -1 ? 18 : 19, 0);
	printw("%s rolls %d %d", *Colorptr, D0, D1);
	clrtoeol();

	/* find out how many moves */
	mvlim = movallow();
	if (mvlim == 0) {
		addstr(" but cannot use it.\n");
		nexturn();
		return;
	}

	/* initialize */
	for (i = 0; i < 4; i++)
		cp[i] = cg[i] = 0;

	/* strategize */
	trymove(0, 0);
	pickmove();

	/* print move */
	addstr(" and moves ");
	for (i = 0; i < mvlim; i++) {
		if (i > 0)
			addch(',');
		printw("%d-%d", p[i] = cp[i], g[i] = cg[i]);
		makmove(i);
	}
	addch('.');

	/* print blots hit */
	move(20, 0);
	for (i = 0; i < mvlim; i++)
		if (h[i])
			wrhit(g[i]);
	/* get ready for next move */
	nexturn();
	if (!okay) {
		refresh();
		sleep(3);
	}
}
Ejemplo n.º 9
0
void ccHistogramWindow::mouseMoveEvent(QMouseEvent *event)
{
	if (event->buttons() & Qt::LeftButton)
	{
		if (m_sfInteractionMode)
		{
			QPoint mousePos = event->pos();
			if (m_histogram)
			{
				QRect rect = m_histogram->rect();
				mousePos.setX(std::min(rect.x()+rect.width(),std::max(rect.x(),mousePos.x())));
			}

			switch(m_selectedItem)
			{
			case NONE:
				//nothing to do
				break;
			case LEFT_AREA:
				if (m_areaLeft)
				{
					double newValue = m_areaLeft->pixelToKey(mousePos.x());
					if (m_areaRight)
						newValue = std::min(newValue,m_areaRight->currentVal());
					setMinDispValue(newValue);
				}
				break;
			case RIGHT_AREA:
				if (m_areaRight)
				{
					double newValue = m_areaRight->pixelToKey(mousePos.x());
					if (m_areaLeft)
						newValue = std::max(newValue,m_areaLeft->currentVal());
					setMaxDispValue(newValue);
				}
				break;
			case BOTH_AREAS:
				{
					int dx = m_lastMouseClick.x() - mousePos.x();
					if (dx < -2)
					{
						//going to the right
						m_selectedItem = RIGHT_AREA;
						//call the same method again
						mouseMoveEvent(event);
						return;
					}
					else if (dx > 2)
					{
						//going to the left
						m_selectedItem = LEFT_AREA;
						//call the same method again
						mouseMoveEvent(event);
						return;
					}
					//else: nothing we can do right now!
				}
				break;
			case LEFT_ARROW:
				if (m_arrowLeft)
				{
					double newValue = m_arrowLeft->pixelToKey(mousePos.x());
					if (m_arrowRight)
						newValue = std::min(newValue,m_arrowRight->currentVal());
					setMinSatValue(newValue);
				}
				break;
			case RIGHT_ARROW:
				if (m_arrowRight)
				{
					double newValue = m_arrowRight->pixelToKey(mousePos.x());
					if (m_arrowLeft)
						newValue = std::max(newValue,m_arrowLeft->currentVal());
					setMaxSatValue(newValue);
				}
				break;
			case BOTH_ARROWS:
				{
					int dx = m_lastMouseClick.x() - mousePos.x();
					if (dx < -2)
					{
						//going to the right
						m_selectedItem = RIGHT_ARROW;
						//call the same method again
						mouseMoveEvent(event);
						return;
					}
					else if (dx > 2)
					{
						//going to the left
						m_selectedItem = LEFT_ARROW;
						//call the same method again
						mouseMoveEvent(event);
						return;
					}
					//else: nothing we can do right now!
				}
				break;
			default:
				assert(false);
				break;
			}
		}
		else
		{
			if (m_histogram && !m_histoValues.empty())
			{
				QRect roi = m_histogram->rect();
				if (roi.contains(event->pos(),false))
				{
					m_drawVerticalIndicator = true;

					int verticalIndicatorPosition = (static_cast<int>(m_histoValues.size()) * (event->x() - roi.x())) / roi.width();
					m_verticalIndicatorPositionPercent = static_cast<double>(verticalIndicatorPosition) / m_histoValues.size();

					refresh();
				}
			}
		}
	}
	else
	{
		event->ignore();
	}
}
Ejemplo n.º 10
0
static void
jana_gtk_recurrence_init (JanaGtkRecurrence *self)
{
	GtkWidget *label, *hbox, *sub_hbox, *arrow, *button;
	GtkSizeGroup *size_group;

	JanaGtkRecurrencePrivate *priv = RECURRENCE_PRIVATE (self);
	
	gtk_box_set_spacing (GTK_BOX (self), 6);
	
	/* Create preview text-view */
	priv->preview_frame = gtk_frame_new (NULL);
	priv->preview_textview = gtk_text_view_new ();
	gtk_text_view_set_editable (GTK_TEXT_VIEW (
		priv->preview_textview), FALSE);
	gtk_text_view_set_cursor_visible (
		GTK_TEXT_VIEW (priv->preview_textview), FALSE);
	gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (priv->preview_textview),
		GTK_WRAP_WORD_CHAR);
	gtk_container_add (GTK_CONTAINER (priv->preview_frame),
		priv->preview_textview);
	gtk_box_pack_end (GTK_BOX (self), priv->preview_frame, TRUE, TRUE, 0);
	gtk_frame_set_shadow_type (
		GTK_FRAME (priv->preview_frame), GTK_SHADOW_NONE);
	gtk_widget_show_all (priv->preview_frame);
	
	priv->edit_vbox = gtk_vbox_new (FALSE, 6);
	size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
	
	/* 'Repeats' (recurrence type) combo box */
	hbox = gtk_hbox_new (FALSE, 6);
	label = gtk_label_new ("Repeats:");
	gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
	gtk_size_group_add_widget (size_group, label);
	gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
	priv->type_combo = gtk_combo_box_new_text ();
	gtk_combo_box_append_text (GTK_COMBO_BOX (priv->type_combo), "None");
	gtk_combo_box_append_text (GTK_COMBO_BOX (priv->type_combo),
		"Every day");
	gtk_combo_box_append_text (GTK_COMBO_BOX (priv->type_combo),
		"Every week");
	gtk_combo_box_append_text (GTK_COMBO_BOX (priv->type_combo),
		"Every year");
	gtk_combo_box_set_active (GTK_COMBO_BOX (priv->type_combo), 0);
	gtk_box_pack_start (GTK_BOX (hbox), priv->type_combo, TRUE, TRUE, 0);
	g_signal_connect (priv->type_combo, "changed",
		G_CALLBACK (type_combo_changed_cb), self);
	/* Interval buttons */
	sub_hbox = gtk_hbox_new (TRUE, 0);
	priv->interval_dec_button = gtk_button_new ();
	arrow = gtk_arrow_new (GTK_ARROW_LEFT, GTK_SHADOW_IN);
	gtk_container_add (GTK_CONTAINER (priv->interval_dec_button), arrow);
	gtk_box_pack_start (GTK_BOX (sub_hbox), priv->interval_dec_button,
		FALSE, TRUE, 0);
	priv->interval_inc_button = gtk_button_new ();
	arrow = gtk_arrow_new (GTK_ARROW_RIGHT, GTK_SHADOW_IN);
	gtk_container_add (GTK_CONTAINER (priv->interval_inc_button), arrow);
	gtk_box_pack_start (GTK_BOX (sub_hbox), priv->interval_inc_button,
		FALSE, TRUE, 0);
	gtk_box_pack_start (GTK_BOX (hbox), sub_hbox, FALSE, TRUE, 0);
	g_signal_connect (priv->interval_inc_button, "clicked",
		G_CALLBACK (interval_inc_clicked_cb), self);
	g_signal_connect (priv->interval_dec_button, "clicked",
		G_CALLBACK (interval_dec_clicked_cb), self);
	
	gtk_widget_show_all (hbox);
	gtk_box_pack_start (GTK_BOX (priv->edit_vbox), hbox, FALSE, TRUE, 0);
	
	/* Weekly recurrence day-chooser */
	priv->week_hbox = gtk_hbox_new (FALSE, 6);
	label = gtk_label_new ("On:");
	gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
	gtk_size_group_add_widget (size_group, label);
	gtk_box_pack_start (GTK_BOX (priv->week_hbox), label, FALSE, TRUE, 0);
	sub_hbox = gtk_hbox_new (TRUE, 0);
	/* Weekday toggle widgets */
#define day_toggle_widget(x) \
	button = gtk_toggle_button_new_with_label (jana_utils_ab_day (x)); \
	gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button), FALSE); \
	gtk_box_pack_start (GTK_BOX (sub_hbox), button, TRUE, TRUE, 0); \
	priv->week_buttons[x] = GTK_TOGGLE_BUTTON (button); \
	g_signal_connect (button, "toggled", \
		G_CALLBACK (day##x##_toggled_cb), self)
	day_toggle_widget(0);
	day_toggle_widget(1);
	day_toggle_widget(2);
	day_toggle_widget(3);
	day_toggle_widget(4);
	day_toggle_widget(5);
	day_toggle_widget(6);
	gtk_box_pack_start (GTK_BOX (priv->week_hbox), sub_hbox, TRUE, TRUE, 0);

	gtk_widget_show_all (priv->week_hbox);
	gtk_box_pack_start (GTK_BOX (priv->edit_vbox), priv->week_hbox,
		FALSE, TRUE, 0);
	
	/* Monthly recurrence by date/day chooser */
	priv->month_hbox = gtk_hbox_new (FALSE, 6);
	label = gtk_label_new ("By:");
	gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
	gtk_size_group_add_widget (size_group, label);
	gtk_box_pack_start (GTK_BOX (priv->month_hbox), label, FALSE, TRUE, 0);
	sub_hbox = gtk_hbox_new (TRUE, 0);
	/* By day */
	priv->byday_button = GTK_TOGGLE_BUTTON (
		gtk_radio_button_new_with_label (NULL, "Day"));
	gtk_toggle_button_set_mode (priv->byday_button, FALSE);
	gtk_box_pack_start (GTK_BOX (sub_hbox), GTK_WIDGET (
		priv->byday_button), FALSE, TRUE, 0);
	/* By date */
	priv->bydate_button = GTK_TOGGLE_BUTTON (
		gtk_radio_button_new_with_label_from_widget (
			GTK_RADIO_BUTTON (priv->byday_button), "Date"));
	gtk_toggle_button_set_mode (priv->bydate_button, FALSE);
	g_signal_connect (priv->bydate_button, "toggled",
		G_CALLBACK (bydate_toggled_cb), self);
	gtk_box_pack_start (GTK_BOX (sub_hbox), GTK_WIDGET (
		priv->bydate_button), FALSE, TRUE, 0);
	gtk_box_pack_start (GTK_BOX (priv->month_hbox), sub_hbox,
		FALSE, TRUE, 0);
	
	gtk_widget_show_all (priv->month_hbox);
	gtk_box_pack_start (GTK_BOX (priv->edit_vbox), priv->month_hbox,
		FALSE, TRUE, 0);
	
	/* Until time editor */
	priv->end_hbox = gtk_hbox_new (FALSE, 6);
	label = gtk_label_new ("Until:");
	gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
	gtk_size_group_add_widget (size_group, label);
	gtk_box_pack_start (GTK_BOX (priv->end_hbox), label, FALSE, TRUE, 0);
	priv->end_button = gtk_button_new ();
	hbox = gtk_hbox_new (FALSE, 6);
	priv->end_label = gtk_label_new (NULL);
	arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_IN);
	gtk_box_pack_start (GTK_BOX (hbox), priv->end_label, TRUE, TRUE, 0);
	gtk_box_pack_end (GTK_BOX (hbox), arrow, FALSE, TRUE, 0);
	gtk_container_add (GTK_CONTAINER (priv->end_button), hbox);
	g_signal_connect (priv->end_button, "clicked",
		G_CALLBACK (end_clicked_cb), self);
	gtk_box_pack_start (GTK_BOX (priv->end_hbox), priv->end_button,
		FALSE, TRUE, 0);
	
	gtk_widget_show_all (priv->end_hbox);
	gtk_box_pack_start (GTK_BOX (priv->edit_vbox), priv->end_hbox,
		FALSE, TRUE, 0);
	
	gtk_box_pack_start (GTK_BOX (self), priv->edit_vbox, FALSE, TRUE, 0);

	gtk_widget_set_no_show_all (priv->edit_vbox, TRUE);
	gtk_widget_set_no_show_all (priv->preview_frame, TRUE);
	
	refresh (self);
}
Ejemplo n.º 11
0
//
// Affiche le tableau des high-scores dans une fenêtre modale.
//
void displayLeaderboard() {
    int i, c;
    
    const int menuWidth = 10;
    
    const int winHeight = MAX_SAVED_SCORES_COUNT + 6;
    const int winWidth = POPUP_WINDOW_WIDTH + 20;
    
    const int colRank = 2;
    const int colScore = 20;
    const int colName = 35;
    const int colBoard = 55;
    
    ITEM* menuItems[2];
    MENU* menu;
    
    Score scores[MAX_SAVED_SCORES_COUNT];
    
    int n = loadScoreBoard(scores);
    
    while (true) {
        clear();
        refresh();
        
        WINDOW* win = newwin(winHeight, winWidth, (LINES - winHeight) / 2, (COLS - winWidth) / 2);
        box(win, 0, 0);
        
        mvwaddch(win, 2, 0, ACS_LTEE);
        mvwhline(win, 2, 1, ACS_HLINE, winWidth - 1);
        mvwaddch(win, 2, winWidth - 1, ACS_RTEE);
        
        mvwprintw(win, 1, colRank, "CLASSEMENT");
        mvwprintw(win, 1, colScore, "SCORE");
        mvwprintw(win, 1, colName, "PSEUDO");
        mvwprintw(win, 1, colBoard, "PLATEAU");
        
        mvwaddch(win, 0, colScore - 2, ACS_TTEE);
        mvwvline(win, 1, colScore - 2, ACS_VLINE, winHeight - 2);
        mvwaddch(win, winHeight - 1, colScore - 2, ACS_BTEE);
        
        mvwaddch(win, 0, colName - 2, ACS_TTEE);
        mvwvline(win, 1, colName - 2, ACS_VLINE, winHeight - 2);
        mvwaddch(win, winHeight - 1, colName - 2, ACS_BTEE);
        
        mvwaddch(win, 0, colBoard - 2, ACS_TTEE);
        mvwvline(win, 1, colBoard - 2, ACS_VLINE, winHeight - 2);
        mvwaddch(win, winHeight - 1, colBoard - 2, ACS_BTEE);
        
        for(i = 0; i < n; i++) {
            mvwprintw(win, i + 3, colRank, "#%d", i+1);
            mvwprintw(win, i + 3, colScore, "%d", scores[i].score);
            mvwprintw(win, i + 3, colName, "%s", scores[i].username);
            mvwprintw(win, i + 3, colBoard, "%s", scores[i].boardName);
        }
        
        menuItems[0] = new_item("<Retour>", NULL);
        menuItems[1] = (ITEM *) NULL;
        
        //on initialise le menu
        menu = new_menu((ITEM **) menuItems);
        
        //on lui précise bien que le menu fait 1 ligne et 1 colonne
        set_menu_format(menu, 1, 1);
        
        //on associe le menu à une fenêtre et une sous-fenêtre
        set_menu_win(menu, win);
        //fenêtre hauteur largeur x y
        set_menu_sub(menu, derwin(win, 1, menuWidth, winHeight - 2, (winWidth - menuWidth) / 2));
        set_menu_mark(menu, "");
        
        noecho();
        curs_set(0);
        
        //et hop, on affiche le menu et on rafraîchit.
        post_menu(menu);
        
        wrefresh(win);
        refresh();
        
        //boucle pour le menu
        while((c = getch())) {
            bool resized = false;
            
            switch(c) {
                case KEY_RESIZE:
                    //si le terminal a été redimensionné, on ré-exécute la boucle d'affichage
                    resized = true;
                    break;
                case KEY_MENU_ENTER: {
                    unpost_menu(menu);
                    free_menu(menu);
                    
                    for(i = 0; i < 2; ++i)
                        free_item(menuItems[i]);
                    
                    clear();
                    refresh();
                    
                    delwin(win);
                    
                    curs_set(1);
                    echo();
                    return;
                }
            }
            
            if(resized) break;
            wrefresh(win);
        }
    }
}
Ejemplo n.º 12
0
//
// Affiche une fenêtre de menu.
//
int displayMenu(char **choices, int nbChoices, char title[], bool logo) {
    if(choices == NULL || nbChoices < 1) return -1;
    
    //variables pour l'affichage du menu
    ITEM **menuItems = NULL;
    MENU *menu = NULL;
    WINDOW *menuWin = NULL;
    
    int i = 0, c;
    int winWidth = POPUP_WINDOW_WIDTH;
    //largeur du menu = longueur du plus grand des choix possibles
    int menuWidth = max_strlen(choices, nbChoices) + 2;
    
    //on alloue de la mémoire pour initialiser les éléments du menu
    menuItems = (ITEM **) calloc(nbChoices + 1, sizeof(ITEM *));
    
    //on créé de nouveaux éléments à partir des choix fournis
    for(i = 0; i < nbChoices; i++) {
        menuItems[i] = new_item(choices[i], NULL);
    }
    
    //on met un élément nul à la fin du tableau
    menuItems[nbChoices] = (ITEM *) NULL;
    
    while(true) {
        clear();
        
        menuWin = (logo) ? getMenuWindow(nbChoices, title) : getMenuWindowNoLogo(nbChoices, title, -1, -1);
        
        //on initialise le menu
        menu = new_menu((ITEM **) menuItems);
        
        //on lui précise bien que le menu fait N lignes et 1 colonne
        set_menu_format(menu, nbChoices, 1);
        
        menu_opts_off(menu, O_NONCYCLIC);
        set_menu_mark(menu, "> ");
        
        //on associe le menu à une fenêtre et une sous-fenêtre
        set_menu_win(menu, menuWin);
        //fenêtre hauteur largeur x y
        set_menu_sub(menu, derwin(menuWin, nbChoices, menuWidth, (logo) ? 15 : 4, (winWidth - menuWidth) / 2));
        
        //et hop, on affiche le menu et on rafraîchit.
        post_menu(menu);
        
        refresh();
        wrefresh(menuWin);
        
        curs_set(0);
        noecho();
        
        //boucle pour le menu
        while((c = getch())) {
            bool resized = false;
            
            switch(c) {
                case KEY_DOWN:
                    menu_driver(menu, REQ_DOWN_ITEM);
                    break;
                case KEY_UP:
                    menu_driver(menu, REQ_UP_ITEM);
                    break;
                case KEY_ESC_ALT:
                    return -1;
                case KEY_RESIZE:
                    //si on a redimensionné le terminal, on ré-exécute la boucle d'affichage
                    resized = true;
                    break;
                case KEY_MENU_ENTER: {
                    int choice = item_index(current_item(menu));
                    
                    //on libère la mémoire pour le menu, les choix, la fenêtre
                    unpost_menu(menu);
                    free_menu(menu);
                    
                    for(i = 0; i < nbChoices; ++i)
                        free_item(menuItems[i]);
                    
                    clear();
                    refresh();
                    
                    delwin(menuWin);
                    
                    //on réactive l'affichage des caractères tapés et du curseur
                    echo();
                    curs_set(1);
                    
                    return choice;
                }
            }
            
            if(resized) break;
            wrefresh(menuWin);
        }

    }
    
    return 0;
}
Ejemplo n.º 13
0
//
// Affiche le plateau de jeu.
//
void displayGameBoard(GameState *state) {
    if(state == NULL) return;
    
    int i, j;
    int width = 4 * BOARD_SIZE + 1;
    int height = 2 * BOARD_SIZE + 1;
    
    WINDOW *boardWin = newwin(height, width, (LINES - height) / 2, (FIRST_COL_WIDTH - width) / 2);
    box(boardWin, 0, 0);
    
    for (i = 0; i < BOARD_SIZE; i++) {
        //début de ligne
        for (j = 0; j < BOARD_SIZE; j++) {
            int charLine = i * 2 + 1;
            int charCol = j * 4;
            
            //on affiche les murs verticaux
            //si il y a quelque-chose dans la case actuelle
            int k;
            bool hasContent = false;
            
            //cases contenant des robots
            for (k = 0; k < ROBOTS_COUNT; k++) {
                //si la case courante contient un robot
                if(state->robots[k].position.y == i && state->robots[k].position.x == j) {
                    int l;
                    bool hasObjective = false;
                    
                    hasContent = true;
                    
                    COL_ON_BOT_BG(boardWin, state->robots[k].robotColor);
                    
                    for (l = 0; l < ROBOTS_COUNT; l++) {
                        //si on a un objectif dans la même case que le robot
                        if(state->gameBoard->objectivesPos[l].y == i && state->gameBoard->objectivesPos[l].x == j) {
                            hasObjective = true;
                            break;
                        }
                    }
                    
                    //on affiche [X] s'il y a un objectif, et simplement trois espaces s'il y a juste un robot
                    if(hasObjective) {
                        mvwprintw(boardWin, charLine, charCol + 1, "[X]");
                    } else {
                        mvwprintw(boardWin, charLine, charCol + 1, "   ");
                    }
                    
                    COL_OFF_BOT_BG(boardWin, state->robots[k].robotColor);
                }
            }
            
            //si la case n'a pas encore de contenu (et donc pas de robot) et que c'est une case objectif
            for (k = 0; k < ROBOTS_COUNT; k++) {
                if(!hasContent && state->gameBoard->objectivesPos[k].y == i && state->gameBoard->objectivesPos[k].x == j) {
                    hasContent = true;
                    
                    COL_ON_BOT(boardWin, k);
                    mvwprintw(boardWin, charLine, charCol + 1, "[X]");
                    COL_OFF_BOT(boardWin, k);
                    
                    break;
                }
            }
            
            //si on doit afficher un mur à droite : si il y a un mur à droite dans la case actuelle ou un mur à gauche dans la case directement à droite
            //on n'oublie pas de prendre en compte les murs en L
            if(state->gameBoard->obstacles[i][j] == CELL_WALL_RIGHT
               || state->gameBoard->obstacles[i][j] == CELL_WALL_BOTTOM_RIGHT
               || state->gameBoard->obstacles[i][j] == CELL_WALL_TOP_RIGHT
               || (j < BOARD_SIZE && state->gameBoard->obstacles[i][j+1] == CELL_WALL_LEFT)
               || (j < BOARD_SIZE && state->gameBoard->obstacles[i][j+1] == CELL_WALL_BOTTOM_LEFT)
               || (j < BOARD_SIZE && state->gameBoard->obstacles[i][j+1] == CELL_WALL_TOP_LEFT)
               || j == BOARD_SIZE - 1) {
                mvwaddch(boardWin, charLine, charCol + 4, ACS_VLINE);
            }
            
            //affichage des T spéciaux pour relier les traits verticaux aux traits horizontaux
            if(j < BOARD_SIZE - 1 && (i == 0 || state->gameBoard->obstacles[i-1][j] == CELL_WALL_BOTTOM)
                && (state->gameBoard->obstacles[i][j+1] == CELL_WALL_LEFT || state->gameBoard->obstacles[i][j] == CELL_WALL_RIGHT)) {
                mvwaddch(boardWin, charLine - 1, charCol + 4, ACS_TTEE);
            } else if(j < BOARD_SIZE - 1 && (i == BOARD_SIZE - 1 || state->gameBoard->obstacles[i+1][j] == CELL_WALL_TOP)
                && (state->gameBoard->obstacles[i][j+1] == CELL_WALL_LEFT || state->gameBoard->obstacles[i][j] == CELL_WALL_RIGHT)) {
                mvwaddch(boardWin, charLine + 1, charCol + 4, ACS_BTEE);
            }
            
            charLine = i * 2 + 2;
            
            //on affiche les murs horizontaux, d'une façon analogue aux murs verticaux
            if(i < BOARD_SIZE - 1 &&
               (state->gameBoard->obstacles[i][j] == CELL_WALL_BOTTOM
                || state->gameBoard->obstacles[i][j] == CELL_WALL_BOTTOM_LEFT
                || state->gameBoard->obstacles[i][j] == CELL_WALL_BOTTOM_RIGHT
                || state->gameBoard->obstacles[i+1][j] == CELL_WALL_TOP
                || state->gameBoard->obstacles[i+1][j] == CELL_WALL_TOP_LEFT
                || state->gameBoard->obstacles[i+1][j] == CELL_WALL_TOP_RIGHT)) {
                   mvwaddch(boardWin, charLine, charCol + 1, ACS_HLINE);
                   mvwaddch(boardWin, charLine, charCol + 2, ACS_HLINE);
                   mvwaddch(boardWin, charLine, charCol + 3, ACS_HLINE);
            }
            
            //affichage d'un point à chaque intersection de cases
            if(i < BOARD_SIZE - 1 && j < BOARD_SIZE - 1 && (i != BOARD_SIZE/2-1 || j != BOARD_SIZE/2-1)) {
                mvwaddch(boardWin, charLine, charCol + 4, ACS_BULLET);
            }
            
            //affichage des coins en L spéciaux entre les traits
            if(state->gameBoard->obstacles[i][j] == CELL_WALL_TOP_LEFT) {
                mvwaddch(boardWin, charLine - 2, charCol, ACS_ULCORNER);
            } else if(state->gameBoard->obstacles[i][j] == CELL_WALL_TOP_RIGHT) {
                mvwaddch(boardWin, charLine - 2, charCol + 4, ACS_URCORNER);
            } else if(state->gameBoard->obstacles[i][j] == CELL_WALL_BOTTOM_RIGHT) {
                mvwaddch(boardWin, charLine, charCol + 4, ACS_LRCORNER);
            } else if(state->gameBoard->obstacles[i][j] == CELL_WALL_BOTTOM_LEFT) {
                mvwaddch(boardWin, charLine, charCol, ACS_LLCORNER);
            }
            
            //affichage des T spéciaux pour relier les traits verticaux aux traits horizontaux
            if(i < BOARD_SIZE - 1 && (j == 0 || state->gameBoard->obstacles[i][j-1] == CELL_WALL_RIGHT)
               && (state->gameBoard->obstacles[i+1][j] == CELL_WALL_TOP || state->gameBoard->obstacles[i][j] == CELL_WALL_BOTTOM)) {
                mvwaddch(boardWin, charLine, charCol, ACS_LTEE);
            } else if(i < BOARD_SIZE - 1 && (j == BOARD_SIZE - 1 || state->gameBoard->obstacles[i][j+1] == CELL_WALL_LEFT)
                      && (state->gameBoard->obstacles[i+1][j] == CELL_WALL_TOP || state->gameBoard->obstacles[i][j] == CELL_WALL_BOTTOM)) {
                mvwaddch(boardWin, charLine, charCol + 4, ACS_RTEE);
            }
        }
    }
    
    refresh();
    wrefresh(boardWin);
    delwin(boardWin);
}
Ejemplo n.º 14
0
//
// Demande à l'utilisateur s'il souhaite rejouer.
//
bool wantsToReplay(WINDOW *win, int top) {
    if(win == NULL || top < 0) return false;
    
    //variables pour l'affichage du menu
    ITEM **menuItems = NULL;
    MENU *menu = NULL;
    
    int i = 0, c;
    int nbChoices = 2;
    
    char *choices[] = {
        "Menu Principal",
        "Quitter"
    };
    
    int winWidth = POPUP_WINDOW_WIDTH;
    //largeur du menu = longueur du plus grand des choix possibles
    int menuWidth = 22;
    
    //on alloue de la mémoire pour initialiser les éléments du menu
    menuItems = (ITEM **) calloc(nbChoices + 1, sizeof(ITEM *));
    
    //on créé de nouveaux éléments à partir des choix fournis
    for(i = 0; i < nbChoices; i++) {
        menuItems[i] = new_item(choices[i], NULL);
    }
    
    //on met un élément nul à la fin du tableau
    menuItems[nbChoices] = (ITEM *) NULL;
    
    //on initialise le menu
    menu = new_menu((ITEM **) menuItems);
    
    //on lui précise bien que le menu fait 1 ligne et 2 colonnes
    set_menu_format(menu, 1, 2);
    
    //on associe le menu à une fenêtre et une sous-fenêtre
    set_menu_win(menu, win);
    //fenêtre hauteur largeur x y
    set_menu_sub(menu, derwin(win, nbChoices, menuWidth, top, (winWidth - menuWidth) / 2));
    
    menu_opts_off(menu, O_NONCYCLIC);
    set_menu_mark(menu, "");
    
    //et hop, on affiche le menu et on rafraîchit.
	post_menu(menu);
	
    refresh();
    wrefresh(win);
    
    curs_set(0);
    noecho();
    
    //boucle pour le menu
    while((c = getch())) {
        switch(c) {
            case KEY_LEFT:
            case KEY_UP:
                menu_driver(menu, REQ_LEFT_ITEM);
                break;
            case KEY_RIGHT:
            case KEY_DOWN:
                menu_driver(menu, REQ_RIGHT_ITEM);
                break;
            case KEY_MENU_ENTER: {
                int choice = item_index(current_item(menu));
                
                unpost_menu(menu);
                free_menu(menu);
                
                for(i = 0; i < nbChoices; ++i)
                    free_item(menuItems[i]);
                
                //si l'indice est 1 on renvoie 0 et vice-versa
                return !choice;
            }
        }
        
        wrefresh(win);
    }
    
    return false;
}