Beispiel #1
0
static void Widget_canvas_text (LIScrArgs* args)
{
	int dest_clip[4];
	int dest_position[2];
	int dest_size[2];
	float text_align[2];
	float text_color[6];
	int* dest_position_ptr = NULL;
	int* dest_size_ptr = NULL;
	int* dest_clip_ptr = NULL;
	float* text_align_ptr = NULL;
	float* text_color_ptr = NULL;
	const char* text;
	const char* text_font = "default";
	float rotation = 0.0f;
	LIScrData* vector = NULL;
	LIMatVector* rotation_center_ptr = NULL;
	LIWdgWidget* widget;

	/* Process arguments. */
	widget = args->self;
	if (!liscr_args_gets_string (args, "text", &text))
		return;
	liscr_args_gets_string (args, "text_font", &text_font);
	if (liscr_args_gets_intv (args, "dest_clip", 4, dest_clip) == 4)
		dest_clip_ptr = dest_clip;
	if (liscr_args_gets_intv (args, "dest_position", 2, dest_position) == 2)
		dest_position_ptr = dest_position;
	if (liscr_args_gets_intv (args, "dest_size", 2, dest_size) == 2)
		dest_size_ptr = dest_size;
	if (liscr_args_gets_floatv (args, "text_alignment", 2, text_align) == 2)
		text_align_ptr = text_align;
	if (liscr_args_gets_floatv (args, "text_color", 4, text_color) == 4)
	{
		text_color_ptr = text_color;
		text_color[0] = LIMAT_CLAMP (text_color[0], 0.0f, 1.0f);
		text_color[1] = LIMAT_CLAMP (text_color[1], 0.0f, 1.0f);
		text_color[2] = LIMAT_CLAMP (text_color[2], 0.0f, 1.0f);
		text_color[3] = LIMAT_CLAMP (text_color[3], 0.0f, 1.0f);
	}
	liscr_args_gets_float (args, "rotation", &rotation);
	if (liscr_args_gets_data (args, "rotation_center", LISCR_SCRIPT_VECTOR, &vector))
		rotation_center_ptr = liscr_data_get_data (vector);

	/* Create the canvas element. */
	liwdg_widget_canvas_insert_text (widget, text_font, text, dest_clip_ptr, dest_position_ptr,
		dest_size_ptr, text_align_ptr, text_color_ptr, rotation, rotation_center_ptr);
}
Beispiel #2
0
static void Widget_canvas_image (LIScrArgs* args)
{
	float color[4];
	int dest_clip[4];
	int dest_position[2];
	int dest_size[2];
	int source_position[2];
	int source_tiling[6];
	float* color_ptr = NULL;
	int* dest_position_ptr = NULL;
	int* dest_size_ptr = NULL;
	int* dest_clip_ptr = NULL;
	int* source_position_ptr = NULL;
	int* source_tiling_ptr = NULL;
	const char* source_image;
	float rotation = 0.0f;
	LIScrData* vector = NULL;
	LIMatVector* rotation_center_ptr = NULL;
	LIWdgWidget* widget;

	/* Process arguments. */
	widget = args->self;
	if (!liscr_args_gets_string (args, "source_image", &source_image))
		return;
	if (liscr_args_gets_floatv (args, "color", 4, color) == 4)
	{
		color_ptr = color;
		color[0] = LIMAT_CLAMP (color[0], 0.0f, 1.0f);
		color[1] = LIMAT_CLAMP (color[1], 0.0f, 1.0f);
		color[2] = LIMAT_CLAMP (color[2], 0.0f, 1.0f);
		color[3] = LIMAT_CLAMP (color[3], 0.0f, 1.0f);
	}
	if (liscr_args_gets_intv (args, "dest_clip", 4, dest_clip) == 4)
		dest_clip_ptr = dest_clip;
	if (liscr_args_gets_intv (args, "dest_position", 2, dest_position) == 2)
		dest_position_ptr = dest_position;
	if (liscr_args_gets_intv (args, "dest_size", 2, dest_size) == 2)
		dest_size_ptr = dest_size;
	if (liscr_args_gets_intv (args, "source_position", 2, source_position) == 2)
		source_position_ptr = source_position;
	if (liscr_args_gets_intv (args, "source_tiling", 6, source_tiling) == 6)
		source_tiling_ptr = source_tiling;
	liscr_args_gets_float (args, "rotation", &rotation);
	if (liscr_args_gets_data (args, "rotation_center", LISCR_SCRIPT_VECTOR, &vector))
		rotation_center_ptr = liscr_data_get_data (vector);

	/* Create the canvas element. */
	liwdg_widget_canvas_insert_image (widget, source_image, color_ptr, dest_clip_ptr, dest_position_ptr,
		dest_size_ptr, source_position_ptr, source_tiling_ptr, rotation, rotation_center_ptr);
}
Beispiel #3
0
static void Model_add_material (LIScrArgs* args)
{
	int cull;
	float diffuse[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
	float specular[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
	const char* shader;
	LIMdlBuilder* builder;
	LIMdlMaterial material;
	LIEngModel* model;

	/* Create a model builder. */
	model = args->self;
	builder = limdl_builder_new (model->model);
	if (builder == NULL)
		return;

	/* Read material properties. */
	/* TODO: Support more. */
	limdl_material_init (&material);
	if (liscr_args_gets_bool (args, "cull", &cull) && !cull)
		material.flags &= ~LIMDL_MATERIAL_FLAG_CULLFACE;
	if (liscr_args_gets_floatv (args, "diffuse", 4, diffuse))
		limdl_material_set_diffuse (&material, diffuse);
	if (liscr_args_gets_string (args, "shader", &shader))
		limdl_material_set_shader (&material, shader);
	if (liscr_args_gets_floatv (args, "specular", 4, specular))
		limdl_material_set_specular (&material, specular);

	/* Insert the material. */
	limdl_builder_insert_material (builder, &material);
	limdl_builder_finish (builder);

	/* Cleanup. */
	limdl_builder_free (builder);
	limdl_material_free (&material);
}
Beispiel #4
0
static void Model_edit_material (LIScrArgs* args)
{
	int i;
	int j;
	int n;
	float color[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
	const char* str;
	const char* shader = NULL;
	const char* texture = NULL;
	LIEngModel* model;
	LIMdlMaterial* material;

	/* Get the engine model. */
	model = args->self;
	liscr_args_gets_string (args, "match_shader", &shader);
	liscr_args_gets_string (args, "match_texture", &texture);

	/* Edit each matching material. */
	for (i = 0 ; i < model->model->materials.count ; i++)
	{
		material = model->model->materials.array + i;
		if (!limdl_material_compare_shader_and_texture (material, shader, texture))
			continue;
		if (liscr_args_gets_floatv (args, "diffuse", 4, color))
			limdl_material_set_diffuse (material, color);
		if (liscr_args_gets_floatv (args, "specular", 4, color))
			limdl_material_set_specular (material, color);
		if (liscr_args_gets_string (args, "shader", &str))
			limdl_material_set_shader (material, str);
		if (liscr_args_gets_table (args, "textures"))
		{
			/* Count textures. */
			for (n = 0 ; n < 4 ; n++)
			{
				lua_pushnumber (args->lua, n + 1);
				lua_gettable (args->lua, -2);
				j = lua_type (args->lua, -1);
				lua_pop (args->lua, 1);
				if (j != LUA_TSTRING)
					break;
			}
			/* Allocate textures. */
			if (material->textures.count != n)
			{
				if (!limdl_material_realloc_textures (material, n))
				{
					lua_pop (args->lua, 1);
					continue;
				}
			}
			/* Set textures. */
			for (j = 0 ; j < n ; j++)
			{
				lua_pushnumber (args->lua, j + 1);
				lua_gettable (args->lua, -2);
				limdl_material_set_texture (material, j, LIMDL_TEXTURE_TYPE_IMAGE,
					LIMDL_TEXTURE_FLAG_BILINEAR | LIMDL_TEXTURE_FLAG_MIPMAP |
					LIMDL_TEXTURE_FLAG_REPEAT, lua_tostring (args->lua, -1));
				lua_pop (args->lua, 1);
			}
			lua_pop (args->lua, 1);
		}
	}
}