Exemplo n.º 1
0
void balda_controller_next_turn(balda_bool first)
{
	////int active_player = balda_get_active_player(g_balda_controller.balda);
	//balda_view_show_turn(g_balda_controller.view);
	
	if (g_balda_controller.turn_stage != BALDA_TURN_STAGE_AFTER_AI_TURN)
	{
		balda_controller_redraw_after_turn(first);
	}
	
	if (!first)
	{
		//balda_view_draw_score(g_balda_controller.view, balda_get_previous_active_player(g_balda_controller.balda), 1);
		//balda_view_draw_player_last_word(g_balda_controller.view, balda_get_previous_active_player(g_balda_controller.balda), 1);
	}
	
	if (balda_is_active_player_ai(g_balda_controller.balda))
	{
		ShowHourglass();
		balda_make_ai_turn(g_balda_controller.balda);
		HideHourglass();
		
		balda_sequence_t* ai_seq = balda_get_last_ai_sequence(g_balda_controller.balda);
		/*balda_field_view_set_insert_char(g_balda_controller.field_view, ai_seq->insert_pos,
			ai_seq->insert_char);*/
		balda_field_view_load(g_balda_controller.field_view, g_balda_controller.balda);
		balda_field_view_load_sequence(g_balda_controller.field_view, ai_seq);
		
		if (balda_is_game_over(g_balda_controller.balda))
		{
			int active_player = balda_get_active_player(g_balda_controller.balda);
			balda_player_view_update_score(g_balda_controller.player_view[active_player]);
			balda_player_view_draw_last_word(g_balda_controller.player_view[active_player]);
			
			balda_controller_on_game_over();
		}
		else
		{
			g_balda_controller.turn_stage = BALDA_TURN_STAGE_AFTER_AI_TURN;
			balda_controller_redraw_after_turn(first);
		}
	}
	else
	{
		g_balda_controller.turn_stage = BALDA_TURN_STAGE_SELECT_POS;
		
		if (!first && g_balda_controller.turn_stage != BALDA_TURN_STAGE_AFTER_AI_TURN)
			balda_field_view_load(g_balda_controller.field_view, g_balda_controller.balda);
		
		if (balda_is_game_over(g_balda_controller.balda))
		{
			int active_player = balda_get_active_player(g_balda_controller.balda);
			balda_player_view_update_score(g_balda_controller.player_view[active_player]);
			balda_player_view_draw_last_word(g_balda_controller.player_view[active_player]);
			
			balda_controller_on_game_over();
		}
		else
		{
			if (g_balda_controller.ui_type == BALDA_UI_TYPE_KEYS)
			{
				// initially select central point on field
				g_balda_controller.field_pos = balda_make_point(BALDA_FIELD_WIDTH / 2, BALDA_FIELD_HEIGHT / 2);
				balda_field_view_select(g_balda_controller.field_view, g_balda_controller.field_pos);
			}
			else if (g_balda_controller.ui_type == BALDA_UI_TYPE_TOUCHSCREEN)
			{
				// nothing is selected initially
				balda_field_view_deselect(g_balda_controller.field_view);
				balda_keyboard_view_clear_selection(g_balda_controller.kb_view);
			}
			
			balda_button_set_mode(g_balda_controller.btn_cancel, BALDA_BUTTON_MODE_SURRENDER);
			balda_button_set_selected(g_balda_controller.btn_cancel, 0);
			balda_button_set_visible(g_balda_controller.btn_cancel, 1);
			
			balda_button_redraw(g_balda_controller.btn_cancel, 1);
			
			if (g_balda_controller.ui_type == BALDA_UI_TYPE_TOUCHSCREEN)
			{
				balda_button_set_visible(g_balda_controller.btn_confirm, 0);
				balda_button_set_selected(g_balda_controller.btn_cancel, 0);
				balda_button_redraw(g_balda_controller.btn_confirm, 1);
			}
		}
	}
	
	balda_view_update(g_balda_controller.view);
}
Exemplo n.º 2
0
static void search_timer()
{
	FixedPoint xMin = 0, yMin = 0, xMax = 9999999, yMax = 9999999;
	unsigned int ucs4[32];
	unsigned int ucs4_len;
	int i, pw, ph, marginx, marginy;
	double sres;

	if (stext == NULL || ! search_mode) return;
	//fprintf(stderr, "%i\n", spage);

	if (spage < 1 || spage > npages)
	{
		HideHourglass();
		Message(ICON_INFORMATION, GetLangText("@Search"), GetLangText("@No_more_matches"), 2000);
		nresults = 0;
		return;
	}

	getpagesize(spage, &pw, &ph, &sres, &marginx, &marginy);

	/*
	  void displayPage(OutputDev *out, int page,
		 double hDPI, double vDPI, int rotate,
		 GBool useMediaBox, GBool crop, GBool printing,
		 GBool (*abortCheckCbk)(void *data) = NULL,
		 void *abortCheckCbkData = NULL,
			   GBool (*annotDisplayDecideCbk)(Annot *annot, void *user_data) = NULL,
			   void *annotDisplayDecideCbkData = NULL);
	*/

	searchout->found = 0;
	doc->displayPage(searchout, spage, sres, sres, 0, false, false, false);
	if (! searchout->found)
	{
		spage += sdir;
		SetHardTimer("SEARCH", search_timer, 1);
		return;
	}

	doc->displayPage(textout, spage, sres, sres, 0, false, true, false);
	TextPage* textPage = textout->takeText();

	xMin = yMin = 0;
	ucs4_len = utf2ucs4(stext, (unsigned int*)ucs4, 32);

	nresults = 0;
	while (textPage->findText(ucs4, ucs4_len,
							  gFalse, gTrue, gTrue, gFalse, gFalse, gFalse, &xMin, &yMin, &xMax, &yMax))
	{
		i = nresults++;
		results[i].x = (int)xMin - 2;
		results[i].y = (int)yMin - 2;
		results[i].w = (int)(xMax - xMin) + 4;
		results[i].h = (int)(yMax - yMin) + 4;
		if (i == MAXRESULTS - 1) break;
	}

	if (nresults > 0)
	{
		cpage = spage;
		out_page(1);
	}
	else
	{
		spage += sdir;
		SetHardTimer("SEARCH", search_timer, 1);
	}

	delete textPage;
}