clutter-1.0 动画效果学习

一.ClutterAnimation

这个类实现的功能比较简单,而且,最主要是,进行动画演示后,actor的外观不会回归原来的位置,必须要经过时间轴反转变回原来的的状态.

二.ClutterAnimator:

比较喜欢clutter_animator_set函数,可以指定起点,过程关键点,以及终点,而且每次都可以按照这个路径运行效果,对于一些单向重复的过程很有用.


三.下面是一个例子.

#include <stdlib.h>
#include <clutter/clutter.h>

/*actor队列*/
GQueue *queue;  
/*actor结构体*/
typedef struct Item
{
	ClutterActor *actor;
	ClutterAnimator *move_c2r_animator;
	ClutterAnimator *move_c2l_animator;
}Item;
/*定义方向枚举*/
typedef enum direction 
{
	right, 
	left
}direction;

/*定义全局方向亦是,默认从右移入,从左移出*/
direction g_direct = left;

/*定义动画持续时间*/
#define DURATION	500

/*
 * 从中间向右移动画开始的回调函数
 */
static void
_to_c2r_animation_started_cb (ClutterTimeline *timeline, 
		gpointer user_data);

/*
 * 从中间向左移动画开始的回调函数
 */
static void
_to_c2l_animation_started_cb (ClutterTimeline *timeline, 
		gpointer user_data);

/*
 * 从中间向右移动画结束的回调函数
 */
static void
_to_c2r_animation_done_cb (ClutterAnimator *animator,
		gpointer user_data);

/*
 * 从中间向右移动画结束的回调函数
 */
static void
_to_c2l_animation_done_cb (ClutterAnimator *animator,
		gpointer user_data);

/*
 * 设置actor的一些初始信息
 * 初始时actor通过把位置设置在stage外使actor不可见.
 */
	static void 
set_actor_property (ClutterActor *actor)
{

	clutter_actor_set_size (CLUTTER_ACTOR (actor), 500, 400);
	clutter_actor_set_position (CLUTTER_ACTOR (actor), -500, -400);
	clutter_actor_hide (CLUTTER_ACTOR (actor));
}

/*
 *将一个从中间向左移动画和一个从中间向右移动画与一个actor联系起来.
 *并为每个动画的时间线添加开始和结束的回调函数.
 *注意: clutter_animator_set的参数不能将gfloat与int,不然容易出现Segment fault.
 */
	static void 
bind_animation_to_item (Item *item)
{
	gfloat stage_w;
	gfloat actor_w;
	ClutterTimeline *timeline;

	stage_w = clutter_actor_get_width (CLUTTER_ACTOR (clutter_stage_get_default ()));
	actor_w = clutter_actor_get_width (item->actor);

	item->move_c2r_animator = clutter_animator_new ();
	clutter_animator_set_duration (item->move_c2r_animator, DURATION);

	clutter_animator_set (item->move_c2r_animator,
			item->actor, "x", CLUTTER_EASE_IN_OUT_CUBIC,
			0.0, 150.0,
			item->actor, "y", CLUTTER_EASE_IN_OUT_CUBIC,
			0.0, 200.0,
			item->actor, "x", CLUTTER_EASE_IN_OUT_CUBIC,
			1.0, stage_w + actor_w,
			item->actor, "y", CLUTTER_EASE_IN_OUT_CUBIC,
			1.0, 200.0,
			item->actor, "scale-x", CLUTTER_EASE_IN_OUT_CUBIC,
			0.0, 1.0,
			item->actor, "scale-y", CLUTTER_EASE_IN_OUT_CUBIC,
			0.0, 1.0,
			item->actor, "scale-x", CLUTTER_EASE_IN_OUT_CUBIC,
			1.0, 0.1,
			item->actor, "scale-y", CLUTTER_EASE_IN_OUT_CUBIC,
			1.0, 0.1,
			item->actor, "rotation-angle-y", CLUTTER_EASE_IN_OUT_CUBIC,
			0.0, 0.0,
			item->actor, "rotation-angle-y", CLUTTER_EASE_IN_OUT_CUBIC,
			1.0, 180.0,

			NULL);

	timeline = clutter_animator_get_timeline (item->move_c2r_animator);
	g_signal_connect (timeline, "completed",
			G_CALLBACK (_to_c2r_animation_done_cb),
			item);
	g_signal_connect (timeline, "started",
			G_CALLBACK (_to_c2r_animation_started_cb),
			item);

	item->move_c2l_animator = clutter_animator_new ();
	clutter_animator_set_duration (item->move_c2l_animator, DURATION);

	clutter_animator_set (item->move_c2l_animator,
			item->actor, "x", CLUTTER_EASE_IN_OUT_CUBIC,
			0.0, 150.0,
			item->actor, "y", CLUTTER_EASE_IN_OUT_CUBIC,
			0.0, 200.0,
			item->actor, "x", CLUTTER_EASE_IN_OUT_CUBIC,
			1.0, -actor_w,
			item->actor, "y", CLUTTER_EASE_IN_OUT_CUBIC,
			1.0, 200.0,
			item->actor, "scale-x", CLUTTER_EASE_IN_OUT_CUBIC,
			0.0, 1.0,
			item->actor, "scale-y", CLUTTER_EASE_IN_OUT_CUBIC,
			0.0, 1.0,
			item->actor, "scale-x", CLUTTER_EASE_IN_OUT_CUBIC,
			1.0, 0.1,
			item->actor, "scale-y", CLUTTER_EASE_IN_OUT_CUBIC,
			1.0, 0.1,
			item->actor, "rotation-angle-y", CLUTTER_EASE_IN_OUT_CUBIC,
			0.0, 0.0,
			item->actor, "rotation-angle-y", CLUTTER_EASE_IN_OUT_CUBIC,
			1.0, 180.0,
			NULL);

	timeline = clutter_animator_get_timeline (item->move_c2l_animator);
	g_signal_connect (timeline, "completed",
			G_CALLBACK (_to_c2l_animation_done_cb),
			item);
	g_signal_connect (timeline, "started",
			G_CALLBACK (_to_c2l_animation_started_cb),
			item);
}

/*
 * 从中间向右移动画开始的回调函数
 */
	static void
_to_c2r_animation_started_cb (ClutterTimeline *timeline, 
		gpointer user_data)
{
	Item *item = (Item *)user_data;
	if (item == NULL)
		return;

	clutter_actor_show (item->actor);
}

/*
 * 从中间向左移动画开始的回调函数
 */
	static void
_to_c2l_animation_started_cb (ClutterTimeline *timeline, 
		gpointer user_data)
{
	Item *item = (Item *)user_data;
	if (item == NULL)
		return;

	clutter_actor_show (item->actor);
}

/*
 * 从中间向右移动画结束的回调函数
 */
	static void
_to_c2r_animation_done_cb (ClutterAnimator *animator,
		gpointer user_data)
{
	Item *item = (Item *)user_data;
	g_assert (item!= NULL);

	if (g_direct == right)
		g_queue_push_tail (queue, item);
}

/*
 * 从中间向右移动画结束的回调函数
 */
	static void
_to_c2l_animation_done_cb (ClutterAnimator *animator,
		gpointer user_data)
{
	Item *item = (Item *)user_data;
	g_return_if_fail (item != NULL);

	if (g_direct == left)
		g_queue_push_tail (queue, item);
}

/*
 *将当前居中原比例显示的一项item调至最底部,也即是从当前画面移除
 *变成等待队列的最后一项
 *注意:	如果移动方向是从左向右: 
 *即当前item的从中间移动到右边的动画有效,且:
 * 此item的从中间到右的item动画正向
 *否则, 当前item的从中间移到左边的动画有效,且:
 *	此item的从中间到左的item动画正向
 *
 */
raise_item_to_bottom (Item *item)
{
	ClutterTimeline *timeline;

	if (item == NULL)
		return;

	if (g_direct == left)
	{
		timeline = clutter_animator_get_timeline (
				item->move_c2l_animator);
		clutter_timeline_set_direction (timeline,CLUTTER_TIMELINE_FORWARD);
		clutter_animator_start (item->move_c2l_animator);
	}
	else
	{

		timeline = clutter_animator_get_timeline (
				item->move_c2r_animator);
		clutter_timeline_set_direction (timeline, CLUTTER_TIMELINE_FORWARD);

		clutter_animator_start (item->move_c2r_animator);
	}
}

/*
 *将等待显示的第一项item调至最顶部,也即是移到到显示居中位置
 *注意:	如果移动方向是从左向右: 
 *即当前item的从中间移动到左边的动画有效,且:
 * 此item的从中间到左的item动画反向
 *否则, 当前item的从中间移到右边的动画有效,且:
 *	此item的从中间到右的item动画反向
 */
	static void 
raise_item_to_top (Item *item)
{
	ClutterTimeline *timeline;

	if (item == NULL)
		return;

	if (g_direct == left)
	{
		timeline = clutter_animator_get_timeline (
				item->move_c2r_animator);
		clutter_timeline_set_direction (timeline, CLUTTER_TIMELINE_BACKWARD);
		clutter_animator_start (item->move_c2r_animator);
	}
	else
	{
		timeline = clutter_animator_get_timeline (
				item->move_c2l_animator);
		clutter_timeline_set_direction (timeline, CLUTTER_TIMELINE_BACKWARD);

		clutter_animator_start (item->move_c2l_animator);
	}
}
/*
 *处理键盘事件.
 *如果当然有有动画正在播放,则忽略键盘事件
 *如要是向左方向键,说明actor从右边移入,从左边移出
 *如果是向右方向键,说明actor从左边移入,从右边移出
 */
	static gboolean
_on_stage_key_cb (ClutterActor *actor, 
		ClutterEvent *event,
		gpointer user_data)
{
	static Item *curr_item = NULL;
	GQueue *queue = (GQueue *)user_data;

	if (curr_item != NULL)
	{
		if (clutter_timeline_is_playing (clutter_animator_get_timeline
					(curr_item->move_c2r_animator)))
			return;
		if (clutter_timeline_is_playing (clutter_animator_get_timeline
					(curr_item->move_c2l_animator)))
			return;
	}

	guint keyval = clutter_event_get_key_symbol (event);

	switch (keyval)
	{
		case CLUTTER_Left:
			g_direct = left;
			break;
		case CLUTTER_Right:
			g_direct = right;
			break;
		default:
			return;
	}

	raise_item_to_bottom (curr_item);
	curr_item = g_queue_pop_head (queue);
	raise_item_to_top (curr_item);
}

/*
 * main函数.
 * 缺少一些资源释放
 * 编译命令: gcc *.c -o main `pkg-config --cflags --libs --clutter-1.0`
 * */
int main (int argc, char *argv[])
{
	gfloat x, y;
	ClutterActor *stage;
	ClutterColor stage_color = {0x00, 0x00, 0x00, 0xff};
	ClutterColor rect_color = {0xff, 0x00, 0x00, 0xff};
	queue = g_queue_new ();

	clutter_init (&argc, &argv);

	stage = clutter_stage_get_default ();
	clutter_stage_set_title (CLUTTER_STAGE (stage), "Hello");
	clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
	clutter_actor_set_size (stage, 800, 800);

	int i;
	for (i = 0; i < 5; i++)
	{
		Item *item = (Item *)malloc (sizeof (Item));
		item->actor = clutter_rectangle_new_with_color (&rect_color);
		set_actor_property (CLUTTER_ACTOR (item->actor));
		clutter_container_add_actor (CLUTTER_CONTAINER (stage), CLUTTER_ACTOR (item->actor));
		bind_animation_to_item (item);
		g_queue_push_tail (queue, item);
	}

	/*添加键盘事件*/
	g_signal_connect (stage, "key-press-event", G_CALLBACK (_on_stage_key_cb), queue);

	clutter_actor_show (stage);

	clutter_main ();

	return EXIT_SUCCESS;

}


aiec@RK3588:~$ dpkg -l | grep gstreamer ii gir1.2-gstreamer-1.0:arm64 1.20.3-0ubuntu1.1 arm64 GObject introspection data for the GStreamer library ii gstreamer1.0-alsa:arm64 1.20.1-1ubuntu0.4 arm64 GStreamer plugin for ALSA ii gstreamer1.0-clutter-3.0:arm64 3.0.27-2ubuntu1 arm64 Clutter PLugin for GStreamer 1.0 ii gstreamer1.0-gl:arm64 1.20.1-1ubuntu0.4 arm64 GStreamer plugins for GL ii gstreamer1.0-libav:arm64 1.20.3-0ubuntu1 arm64 ffmpeg plugin for GStreamer ii gstreamer1.0-packagekit 1.2.5-2ubuntu3 arm64 GStreamer plugin to install codecs using PackageKit ii gstreamer1.0-pipewire:arm64 0.3.48-1ubuntu3 arm64 GStreamer 1.0 plugin for the PipeWire multimedia server ii gstreamer1.0-plugins-bad:arm64 1.20.3-0ubuntu1.1 arm64 GStreamer plugins from the "bad" set ii gstreamer1.0-plugins-base:arm64 1.20.1-1ubuntu0.4 arm64 GStreamer plugins from the "base" set ii gstreamer1.0-plugins-base-apps 1.20.1-1ubuntu0.4 arm64 GStreamer helper programs from the "base" set ii gstreamer1.0-plugins-good:arm64 1.20.3-0ubuntu1.3 arm64 GStreamer plugins from the "good" set ii gstreamer1.0-plugins-ugly:arm64 1.20.1-1 arm64 GStreamer plugins from the "ugly" set ii gstreamer1.0-pulseaudio:arm64 1.20.3-0ubuntu1.3 arm64 GStreamer plugin for PulseAudio (transitional package) ii gstreamer1.0-rockchip1 1.14-4 arm64 The Gstreamer plugins for Rockchip platforms. ii gstreamer1.0-rockchip1-dbgsym 1.14-4 arm64 debug symbols for gstreamer1.0-rockchip1 ii gstreamer1.0-tools 1.20.3-0ubuntu1.1 arm64 Tools for use with GStreamer ii gstreamer1.0-x:arm64 1.20.1-1ubuntu0.4 arm64 GStreamer plugins for X11 and Pango ii libgstreamer-gl1.0-0:arm64 1.20.1-1ubuntu0.4 arm64 GStreamer GL libraries ii libgstreamer-plugins-bad1.0-0:arm64 1.20.3-0ubuntu1.1 arm64 GStreamer libraries from the "bad" set ii libgstreamer-plugins-base1.0-0:arm64 1.20.1-1ubuntu0.4 arm64 GStreamer libraries from the "base" set ii libgstreamer-plugins-good1.0-0:arm64 1.20.3-0ubuntu1.3 arm64 GStreamer development files for libraries from the "good" set ii libgstreamer1.0-0:arm64 1.20.3-0ubuntu1.1 arm64 Core GStreamer libraries and elements 如何查看该gstreamer库安装位置
10-31
<think>我们被要求查找Ubuntu中已安装的gstreamer库的安装位置。根据之前的引用和讨论,我们知道GStreamer在Ubuntu中通常通过apt安装,它的库文件会放在系统的标准库路径下。 在Ubuntu系统中,库文件通常位于以下目录: - /usr/lib/ 或 /usr/lib/x86_64-linux-gnu/(对于64位系统)或 /usr/lib/aarch64-linux-gnu/(对于ARM64系统)等 - /usr/local/lib/(如果是手动编译安装) 由于我们是通过apt安装的,所以应该在/usr/lib/下的相应目录。 我们可以使用以下命令来查找: 1. 使用`dpkg -L`命令列出指定包安装的文件。但是我们需要知道具体的包名。 2. 使用`find`命令在特定目录下查找。 3. 使用`gst-inspect-1.0`工具来查看插件的路径(但主要是插件,不是所有库)。 根据引用[4]中提到的一个插件路径:`/usr/lib/aarch64-linux-gnu/gstreamer-1.0/libgstcoreelements.so`,我们可以推断库文件的一般位置。 不过,用户想知道的是“gstreamer库”的安装位置,这里指的是核心库(如libgstreamer-1.0.so)还是所有相关的库(包括插件)? 通常,核心库的位置我们可以通过以下方式查找: 方法1:使用dpkg查找 首先,确定我们安装了哪些gstreamer相关的包。我们可以查找包含libgstreamer的包: dpkg -l | grep libgstreamer 然后,选择一个核心包,例如libgstreamer1.0-0(这是运行时库),查看其安装的文件: dpkg -L libgstreamer1.0-0 方法2:使用pkg-config 通过pkg-config可以获取库的路径,因为gstreamer-1.0.pc文件会记录库的路径。但是pkg-config给出的是链接选项(如-L路径),我们可以查看这个pc文件的内容。 方法3:直接使用find命令查找 find /usr -name 'libgstreamer-1.0.so*' 考虑到用户可能没有安装所有包,我们选择最直接的方法:使用dpkg查找核心包的文件位置。 步骤: 1. 检查libgstreamer1.0-0包是否安装(这是基本的运行时库) 2. 使用dpkg -L列出该包的文件 另外,开发包(如libgstreamer1.0-dev)会安装头文件和静态库,如果需要查看开发包的安装位置,可以查询对应的开发包。 根据用户需求,我们关注的是库文件(动态库)的位置。 因此,我们给出如下指令: ### 查找核心库安装位置 #### 步骤1:确认已安装的核心包 ```bash # 检查核心库包是否安装 dpkg -l libgstreamer1.0-0 ``` 如果已安装,则继续。 #### 步骤2:列出核心库文件 ```bash # 列出libgstreamer1.0-0包安装的所有文件 dpkg -L libgstreamer1.0-0 ``` 通过这个命令,我们可以找到库文件(通常是.so文件)的位置。通常,动态库会安装在`/usr/lib/x86_64-linux-gnu/`(对于x86_64架构)或类似目录下。 #### 步骤3:查找其他相关库 如果需要查找其他GStreamer库(如插件库),可以使用类似的方法查询对应的包,例如: ```bash # 列出所有已安装的gstreamer相关包 dpkg -l | grep gstreamer # 然后选择一个包,如gstreamer1.0-plugins-base,再查看其文件 dpkg -L gstreamer1.0-plugins-base ``` #### 方法4:使用系统查找命令 如果不知道具体的包名,可以使用`find`命令在全系统查找: ```bash # 查找名为libgstreamer-1.0.so的文件(这是核心库) sudo find /usr -name "libgstreamer-1.0.so*" -type f ``` 注意:由于/usr目录需要管理员权限才能完全搜索,所以这里加了sudo。 ### 示例输出 假设我们运行`dpkg -L libgstreamer1.0-0`,部分输出可能包含: ``` /usr/lib/x86_64-linux-gnu/libgstreamer-1.0.so.0 /usr/lib/x86_64-linux-gnu/libgstreamer-1.0.so.0.1602.0 ``` ### 相关问题 1. 如何查看 GStreamer 插件的安装位置? 2. 如何设置 GStreamer 的插件路径? 3. 在 Ubuntu 中如何卸载 GStreamer? 4. 如何编译时指定 GStreamer 库路径? 5. GStreamer 的配置文件位置在哪里? > 通过上述方法可以快速定位 GStreamer 库的安装位置,便于开发调试或环境配置[^1][^4]。 </think>### 在 Ubuntu 中查找 GStreamer 库安装位置的方法 #### 方法 1:使用 `dpkg` 查询核心库位置 ```bash # 查询核心库文件路径 dpkg -L libgstreamer1.0-0 | grep '\.so' # 示例输出: # /usr/lib/x86_64-linux-gnu/libgstreamer-1.0.so.0 # /usr/lib/x86_64-linux-gnu/libgstreamer-1.0.so.0.1602.0 ``` #### 方法 2:查找插件安装目录 ```bash # 查找所有 GStreamer 插件位置 find /usr -path '*/gstreamer-1.0/*.so' 2>/dev/null # 示例输出: # /usr/lib/x86_64-linux-gnu/gstreamer-1.0/libgstcoreelements.so # /usr/lib/x86_64-linux-gnu/gstreamer-1.0/libgstalsa.so ``` #### 方法 3:通过 `pkg-config` 获取开发库路径 ```bash # 获取开发库的头文件路径 pkg-config --variable=includedir gstreamer-1.0 # 获取开发库的链接路径 pkg-config --variable=libdir gstreamer-1.0 ``` #### 方法 4:检查特定插件位置(如引用[4]的 coreelements) ```bash # 查询特定插件的详细位置 gst-inspect-1.0 coreelements | grep Filename # 示例输出(如引用[4]所示): # Filename: /usr/lib/aarch64-linux-gnu/gstreamer-1.0/libgstcoreelements.so ``` #### 常见安装位置总结 1. **核心库文件**: - `/usr/lib/x86_64-linux-gnu/libgstreamer-1.0.so*` - `/usr/lib/aarch64-linux-gnu/libgstreamer-1.0.so*` (ARM架构) 2. **插件目录**: - `/usr/lib/x86_64-linux-gnu/gstreamer-1.0/` - `/usr/lib/aarch64-linux-gnu/gstreamer-1.0/` (ARM) 3. **开发文件**: - 头文件:`/usr/include/gstreamer-1.0/` - 库文件:`/usr/lib/x86_64-linux-gnu/pkgconfig/gstreamer-1.0.pc` > 注:具体路径可能因系统架构(x86_64/aarch64)和安装方式(APT/源码编译)有所不同[^4]。 ### 相关问题 1. 如何验证 GStreamer 库的版本与安装路径是否匹配? 2. 当系统中有多个 GStreamer 版本时,如何指定使用特定版本? 3. 如何将自定义 GStreamer 插件添加到系统搜索路径? 4. GStreamer 环境变量 `GST_PLUGIN_PATH` 的作用和配置方法是什么? 5. 如何安全地卸载特定 GStreamer 组件而不影响其他依赖? > 通过上述方法可精确定位 GStreamer 在 Ubuntu 中的安装位置,便于开发调试和依赖管理[^1][^4]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值