コード例 #1
0
ファイル: helper.cpp プロジェクト: aquileia/wesnoth
void get_screen_size_variables(game_logic::map_formula_callable& variable)
{
	variable.add("screen_width", variant(settings::screen_width));
	variable.add("screen_height", variant(settings::screen_height));
	variable.add("gamemap_width", variant(settings::gamemap_width));
	variable.add("gamemap_height", variant(settings::gamemap_height));
	variable.add("gamemap_x_offset", variant(settings::gamemap_x_offset));
}
コード例 #2
0
ファイル: helper.cpp プロジェクト: freeors/War-Of-Kingdom
void get_screen_size_variables(game_logic::map_formula_callable& variable)
{
	variable.add("screen_width", variant(settings::screen_width));
	variable.add("screen_height", variant(settings::screen_height));
	variable.add("hdpi_ratio", variant(twidget::hdpi_ratio));
	variable.add("default_gui", variant(!game_config::tiny_gui));
	variable.add("vga", variant(settings::screen_width >= 640 * twidget::hdpi_ratio && settings::screen_height >= 480 * twidget::hdpi_ratio));
}
コード例 #3
0
void ttext::draw(surface& canvas
		, const game_logic::map_formula_callable& variables)
{
	assert(variables.has_key("text"));

	// We first need to determine the size of the text which need the rendered
	// text. So resolve and render the text first and then start to resolve
	// the other formulas.
	const t_string text = text_(variables);

	if(text.empty()) {
		DBG_GUI_D << "Text: no text to render, leave.\n";
		return;
	}

	static font::ttext text_renderer;
	text_renderer.set_text(text, text_markup_(variables));

	text_renderer.set_font_size(font_size_)
			.set_font_style(font_style_)
			.set_alignment(text_alignment_(variables))
			.set_foreground_color(color_)
			.set_maximum_width(maximum_width_(variables))
			.set_maximum_height(maximum_height_(variables))
			.set_ellipse_mode(variables.has_key("text_wrap_mode")
				? static_cast<PangoEllipsizeMode>
					(variables.query_value("text_wrap_mode").as_int())
				: PANGO_ELLIPSIZE_END);

	surface surf = text_renderer.render();
	if(surf->w == 0) {
		DBG_GUI_D  << "Text: Rendering '"
				<< text << "' resulted in an empty canvas, leave.\n";
		return;
	}

	game_logic::map_formula_callable local_variables(variables);
	local_variables.add("text_width", variant(surf->w));
	local_variables.add("text_height", variant(surf->h));
/*
	std::cerr << "Text: drawing text '" << text
		<< " maximum width " << maximum_width_(variables)
		<< " maximum height " << maximum_height_(variables)
		<< " text width " << surf->w
		<< " text height " << surf->h;
*/
	///@todo formulas are now recalculated every draw cycle which is a
	// bit silly unless there has been a resize. So to optimize we should
	// use an extra flag or do the calculation in a separate routine.

	const unsigned x = x_(local_variables);
	const unsigned y = y_(local_variables);
	const unsigned w = w_(local_variables);
	const unsigned h = h_(local_variables);

	DBG_GUI_D << "Text: drawing text '" << text
			<< "' drawn from " << x << ',' << y
			<< " width " << w << " height " << h
			<< " canvas size " << canvas->w << ',' << canvas->h << ".\n";

	VALIDATE(static_cast<int>(x) < canvas->w && static_cast<int>(y) < canvas->h
			, _("Text doesn't start on canvas."));

	// A text might be to long and will be clipped.
	if(surf->w > static_cast<int>(w)) {
		WRN_GUI_D << "Text: text is too wide for the "
				"canvas and will be clipped.\n";
	}

	if(surf->h > static_cast<int>(h)) {
		WRN_GUI_D << "Text: text is too high for the "
				"canvas and will be clipped.\n";
	}

	SDL_Rect dst = ::create_rect(x, y, canvas->w, canvas->h);
	blit_surface(surf, 0, canvas, &dst);
}
コード例 #4
0
ファイル: candidates.cpp プロジェクト: shikadilord/wesnoth
void attack_candidate_action::update_callable_map(game_logic::map_formula_callable& callable)
{
	callable.add("me", my_unit_);
	callable.add("target", enemy_unit_);
}
コード例 #5
0
ファイル: candidates.cpp プロジェクト: shikadilord/wesnoth
void move_candidate_action::update_callable_map(game_logic::map_formula_callable& callable)
{
	callable.add("me", my_unit_);
}