当前位置: 首页>>代码示例>>C++>>正文


C++ Canvas::get_width方法代码示例

本文整理汇总了C++中clan::Canvas::get_width方法的典型用法代码示例。如果您正苦于以下问题:C++ Canvas::get_width方法的具体用法?C++ Canvas::get_width怎么用?C++ Canvas::get_width使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在clan::Canvas的用法示例。


在下文中一共展示了Canvas::get_width方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: go

void why::Application::draw_game_over(clan::Canvas &c)
{
	using namespace boost;
	using namespace std;
	using namespace clan;

	static const string go("GAME OVER");
	static const string go2("Press Any Key To Continue");
	
	static Font fbig = m_rc_manager->get_font(80);
	float x = static_cast<float>(
		((c.get_width() / 2.0f) - (fbig.get_text_size(c, go).width / 2.0f))
		);
	float y = c.get_height() / 2.0f;
	
	draw_info_box(c);
	fbig.draw_text(c, x, y, go);

	static Font fsmall = m_rc_manager->get_font();
	
	y += fbig.get_font_metrics().get_height();
	x = static_cast<float>(
		((c.get_width() / 2.0f) - (fsmall.get_text_size(c, go2).width / 2.0f))
		);

	fsmall.draw_text(c, x, y, go2);
}
开发者ID:vdell,项目名称:inertia,代码行数:27,代码来源:why_app.cpp

示例2: draw_text

void TextFade::draw_text(clan::Canvas &canvas, clan::Font &font, int ypos, const char *text)
{
	// For this example, to keep things simple, we only handle ASCII characters

	int gc_width = canvas.get_width();

	clan::Size text_size = clan::Size(font.measure_text(canvas, text).bbox_size);

	int xpos = (gc_width - text_size.width) / 2;

	while(*text)
	{
		char let = *(text++);
		char buffer[2];
		buffer[0] = let;
		buffer[1] = 0;

		int position_off_centre = (gc_width/2) - xpos;
		if (position_off_centre < 0)
			position_off_centre = -position_off_centre;

		float alpha = 1.0f - ( (float) position_off_centre * 2.0f / gc_width );
		if (alpha > 0.0f)
			font.draw_text(canvas, xpos, ypos,  buffer, clan::Colorf(0.4f, 0.4f, 1.0f, alpha));
		xpos += font.get_metrics(canvas, let).bbox_size.width;
	}

}
开发者ID:ARMCoderCHS,项目名称:ClanLib,代码行数:28,代码来源:textfade.cpp

示例3: set_stars

void Timing::set_stars(clan::Canvas &canvas, int star_cnt)
{
	stars.clear();
	stars.resize(star_cnt);
	unsigned int random = 1231;
	int gc_width = canvas.get_width();
	int gc_height = canvas.get_height();

	for (int cnt=0; cnt < star_cnt; cnt++)
	{
		stars[cnt].xpos = (float) (random % gc_width);
		random+= 143222321;
		stars[cnt].ypos = (float) (random % gc_height);
		random+= 89079086;
		stars[cnt].speed = (((float) (random % 256)) ) + 10.0f;
		random*= 595443965;
		stars[cnt].color.r = (((float) (random % 256)) / 256.0f);
		random*= 196243625;
		stars[cnt].color.b = (((float) (random % 256)) / 256.0f);
		random*= 14365;
		stars[cnt].color.g = (((float) (random % 256)) / 256.0f);
		stars[cnt].color.a = 1.0f;

	}

}
开发者ID:doughdemon,项目名称:ClanLib,代码行数:26,代码来源:timing.cpp

示例4: render_bloom_combine

void App::render_bloom_combine(clan::Canvas &canvas, clan::Texture2D &tex_base, clan::Texture2D &tex_bloom, clan::ProgramObject &program_object)
{
	canvas.flush();
	clan::GraphicContext gc = canvas.get_gc();

	gc.set_texture(0, tex_base);
	gc.set_texture(1, tex_bloom);

	gc.set_program_object(program_object);
	program_object.set_uniform1i(("BaseTexture"), 0);
	program_object.set_uniform1f(("BaseIntensity"), base_intensity);
	program_object.set_uniform1f(("BaseSaturation"), base_saturation);

	program_object.set_uniform1i(("BloomTexture"), 1);
	program_object.set_uniform1f(("BloomIntensity"), bloom_intensity);
	program_object.set_uniform1f(("BloomSaturation"), bloom_saturation);

	program_object.set_uniform_matrix("cl_ModelViewProjectionMatrix", canvas.get_projection() * canvas.get_transform());

	draw_texture(gc, clan::Rectf(0,0,canvas.get_width(),canvas.get_height()), clan::Rectf(0.0f, 0.0f, 1.0f, 1.0f));

	gc.reset_program_object();
	gc.reset_texture(0);
	gc.reset_texture(1);

}
开发者ID:keigen-shu,项目名称:ClanLib,代码行数:26,代码来源:app.cpp

示例5: on_render

void ColorWheel::on_render(clan::Canvas &canvas, const clan::Rect &update_rect)
{
    get_options();

    clan::Pointf center( (float) canvas.get_width()/2.0f, (float) canvas.get_height()/2.0f);
    float radius = 200.0f;
    create_colorwheel(center, radius);

    canvas.fill_triangles(colorwheel_positions, colorwheel_colors, colorwheel_segments * 3);

    draw_labels(canvas);
}
开发者ID:punkkeks,项目名称:ClanLib,代码行数:12,代码来源:colorwheel.cpp

示例6: ver

void why::Application::draw_main_menu(clan::Canvas &c)
{
	using namespace clan;
	m_main_menu->draw(c);

	const std::string ver (std::string(INERTIA_VERSION) + "v");
	Font f = m_rc_manager->get_font();

	Pointf vpos;
	vpos.x = c.get_width() - (ver.length() * f.get_font_metrics().get_average_character_width() + 10.0f);
	vpos.y = c.get_height() - 10.0f;

	f.draw_text(c, vpos, ver);
}
开发者ID:vdell,项目名称:inertia,代码行数:14,代码来源:why_app.cpp

示例7: update

bool App::update()
{
	game_time.update();

	canvas.clear(clan::Colorf(0.0f,0.0f,0.0f, 0.0f));
	rock.set_color(clan::Colorf(1.0f, 1.0f, 1.0f, 0.8f));
	rock.draw(canvas, 0.0f, 0.0f);

	// Rotate tux
	rotation += game_time.get_time_elapsed() * 100.0f;
	clan::Angle angle;
	angle.set_degrees(rotation);
	tux.set_angle(angle);

	// Caculate tux position
	clan::Pointf circle_center(  (float) (canvas.get_width()/2), (float) (canvas.get_height()/2) );
	const float radius = 210.0f;
	int tux_circle = 12;
	tux_position.x = -(radius - tux_radius - tux_circle)  * cos( angle.to_radians() / 2.0f );
	tux_position.y = (radius - tux_radius - tux_circle) * sin( angle.to_radians()/ 2.0f );
	tux_position += circle_center;
	tux_position.x -= tux.get_width()/2;
	tux_position.y -= tux.get_height()/2;

	// Give tux circle blue outer outline, because it looks nice
	canvas.fill_circle(tux_position.x + tux_radius, tux_position.y + tux_radius, tux_radius+tux_circle, clan::Colorf(0.0f, 0.0f, 1.0f, 1.0f));

	// Make see through border
	canvas.set_blend_state(blend_state_off);
	canvas.fill_circle(tux_position.x + tux_radius, tux_position.y + tux_radius, tux_radius+tux_circle-2, clan::Colorf(0.0f, 0.0f, 0.0f, 0.0f));
	canvas.reset_blend_state();

	// Give tux circle blue outline, to mask the alpha channel
	canvas.fill_circle(tux_position.x + tux_radius, tux_position.y + tux_radius, tux_radius+2, clan::Colorf(0.0f, 0.0f, 1.0f, 1.0f));

	// Draw tux
	tux.draw(canvas, tux_position.x, tux_position.y);

	// Draw text
	font_large.draw_text(canvas, 10-2, 50-2, "ClanLib Layered Window", clan::Colorf(0.1f, 0.1f, 0.1f, 1.0f));
	font_large.draw_text(canvas, 10, 50, "ClanLib Layered Window", clan::Colorf::green);
	font_small.draw_text(canvas, 60-2, 80-2, "Click mouse on the penguin to exit", clan::Colorf(0.1f, 0.1f, 0.1f, 1.0f));
	font_small.draw_text(canvas, 60, 80, "Click mouse on the penguin to exit", clan::Colorf::green);
	font_small.draw_text(canvas, 110-2, 110-2, "Drag rock to move window", clan::Colorf(0.1f, 0.1f, 0.1f, 1.0f));
	font_small.draw_text(canvas, 110, 110, "Drag rock to move window", clan::Colorf::green);

	window.flip(1);

	return !quit;
}
开发者ID:ArtHome12,项目名称:ClanLib,代码行数:50,代码来源:example.cpp

示例8: draw_demo

void SineScroll::draw_demo(clan::Canvas &canvas, int delta_ms)
{
	clan::Rectf rect(0.0f, 0.0f, clan::Sizef(300.0f, 300.0f));
	clan::Rectf texture_unit1_coords(0.0f, 0.0f, 1.0f, 1.0f);

	std::vector<clan::Vec2f> dest_position;
	std::vector<clan::Vec2f> texture_position;

	int dest_width = canvas.get_width();
	if (dest_width <=0)
		return;

	int dest_xoffset = 0;

	int gc_height = canvas.get_height();

	int dest_height = 128;
	int dest_start_y = (gc_height - dest_height)  / 2;

	float texture_y_start = 0.15f;	// Set to 0.0f for start and 1.0f for end to use the entire texture
	float texture_y_end = 0.5f;

	dest_position.reserve(dest_width * 2);
	texture_position.reserve(dest_width * 2);

	float sin_amplitude = (  (float) gc_height / 4.0f);

	if (delta_ms > 1000)	// Limit to 1 second to frame
		delta_ms = 1000;

	sin_offset += ((float) delta_ms / 1000.0f);
	if (sin_offset > (2.0f * clan::PI))
		sin_offset -= clan::PI * 2.0f;

	for (int cnt=0; cnt < dest_width; cnt++)
	{
		float y_offset = sin_amplitude * sin( sin_offset + (float) cnt / 100.0f ) ;

		dest_position.push_back( clan::Vec2f( cnt, dest_start_y + y_offset ) );
		dest_position.push_back( clan::Vec2f( cnt, dest_start_y + dest_height + y_offset) );

		texture_position.push_back( clan::Vec2f( (float) cnt / dest_width, texture_y_start ) );
		texture_position.push_back( clan::Vec2f( (float) cnt / dest_width, texture_y_end ) );

	}

	canvas.draw_lines(&dest_position[0], &texture_position[0], dest_position.size(), texture);

}
开发者ID:keigen-shu,项目名称:ClanLib,代码行数:49,代码来源:sinescroll.cpp

示例9: render_gaussian_blur

void App::render_gaussian_blur(clan::Canvas &canvas, float blur_amount, clan::Texture2D &source_texture, clan::ProgramObject &program_object, float dx, float dy)
{
    uniforms.sample[0].weight = compute_gaussian(0, blur_amount);
    uniforms.sample[0].offset_x = 0.0f;
    uniforms.sample[0].offset_y = 0.0f;

    float totalWeights = uniforms.sample[0].weight;

    for (int i = 0; i < sampleCount / 2; i++)
    {
        float weight = compute_gaussian(i + 1.0f, blur_amount);

        uniforms.sample[i * 2 + 1].weight = weight;
        uniforms.sample[i * 2 + 2].weight = weight;

        totalWeights += weight * 2;

        float sampleOffset = i * 2 + 1.5f;

        clan::Vec2f delta(dx * sampleOffset, dy * sampleOffset);

        uniforms.sample[i * 2 + 1].offset_x = delta.x;
        uniforms.sample[i * 2 + 1].offset_y = delta.y;
        uniforms.sample[i * 2 + 2].offset_x = -delta.x;
        uniforms.sample[i * 2 + 2].offset_y = -delta.y;
    }

    for (int i = 0; i < sampleCount; i++)
    {
        uniforms.sample[i].weight /= totalWeights;
    }

    canvas.flush();
    clan::GraphicContext gc = canvas.get_gc();

    gc.set_texture(0, source_texture);
    gc.set_program_object(program_object);

    uniforms.cl_ModelViewProjectionMatrix = canvas.get_projection() * canvas.get_transform();
    gpu_uniforms.upload_data(gc, &uniforms, 1);
    gc.set_uniform_buffer(0, gpu_uniforms);

    draw_texture(gc, clan::Rectf(0,0,canvas.get_width(),canvas.get_height()), clan::Rectf(0.0f, 0.0f, 1.0f, 1.0f));

    gc.reset_program_object();
    gc.reset_texture(0);

}
开发者ID:doughdemon,项目名称:ClanLib,代码行数:48,代码来源:app.cpp

示例10: draw_graphics

void Timing::draw_graphics(clan::Canvas &canvas, float time_delta)
{
	int gc_width = canvas.get_width();
	std::vector<Star>::size_type max, cnt;
	max = stars.size();
	for (cnt=0; cnt<max; cnt++)
	{
		float xpos = stars[cnt].xpos;
		xpos += time_delta * stars[cnt].speed;
		if (xpos >= gc_width)
			xpos -= (gc_width + 8);
		stars[cnt].xpos = xpos;

		canvas.fill_circle(xpos, stars[cnt].ypos, 6.0f, stars[cnt].color);
	}
}
开发者ID:doughdemon,项目名称:ClanLib,代码行数:16,代码来源:timing.cpp

示例11: render_shockwave

void App::render_shockwave(clan::Canvas &canvas, clan::Texture2D &source_texture, clan::ProgramObject &program_object)
{
	canvas.flush();
	clan::GraphicContext gc = canvas.get_gc();

	gc.set_texture(0, source_texture);
	gc.set_program_object(program_object);

	uniforms.cl_ModelViewProjectionMatrix = canvas.get_projection() * canvas.get_modelview();
	gpu_uniforms.upload_data(gc, &uniforms, 1);
	gc.set_uniform_buffer(0, gpu_uniforms);

	draw_texture(gc, clan::Rectf(0,0,canvas.get_width(),canvas.get_height()), clan::Rectf(0.0f, 0.0f, 1.0f, 1.0f));

	gc.reset_program_object();
	gc.reset_texture(0);
}
开发者ID:finalJ2,项目名称:ClanLib,代码行数:17,代码来源:app.cpp

示例12: render_extract_highlights

void App::render_extract_highlights(clan::Canvas &canvas, clan::Texture2D &source_texture, clan::ProgramObject &program_object)
{
	canvas.flush();
	clan::GraphicContext gc = canvas.get_gc();

	gc.set_texture(0, source_texture);

	gc.set_program_object(program_object);
	program_object.set_uniform1i(("SourceTexture"), 0);
	program_object.set_uniform1f(("Threshold"), highlight_threshold);

	program_object.set_uniform_matrix("cl_ModelViewProjectionMatrix", canvas.get_projection() * canvas.get_transform());

	draw_texture(gc, clan::Rectf(0,0,canvas.get_width(),canvas.get_height()), clan::Rectf(0.0f, 0.0f, 1.0f, 1.0f));

	gc.reset_program_object();
	gc.reset_texture(0);

}
开发者ID:keigen-shu,项目名称:ClanLib,代码行数:19,代码来源:app.cpp

示例13: screen_width

void why::Application::draw_background(clan::Canvas &c, bool tile)
{
	using namespace clan;

	Sprite *bg = nullptr;
	if (GameState::is_active(GameStateValue::Menu))
	{
		bg = &m_menu_bg_sprite;
	}
	else
	{
		bg = &m_game_bg_sprite;
	}

	const float screen_width(static_cast<float>(c.get_width()));
	const float screen_height(static_cast<float>(c.get_height()));

	const float sprite_width(static_cast<float>(bg->get_width()));
	const float sprite_height(static_cast<float>(bg->get_height()));

	if (tile)
	{
		float x = 0, y = 0;

		while (y < screen_height + sprite_height)
		{
			bg->draw(c, x, y);
			x += sprite_width;
			if (x > screen_width + sprite_width)
			{
				y += sprite_height;
				x = 0.0f;
			}
		}
	}
	else
	{
		bg->draw(c, Rectf(0.0f, 0.0f, sprite_width, sprite_height),
			Rectf(0.0f, 0.0f, screen_width, screen_height));
	}
}
开发者ID:vdell,项目名称:inertia,代码行数:41,代码来源:why_app.cpp


注:本文中的clan::Canvas::get_width方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。