MxButton を使ってみる

今日は MxButton を使ってみます。GTK+の GtkButton と同じなので、特に説明も不要だと思います。
Mx っぽくするために、MxWindow を回転させることにしました。Mx のアプリケーションウィンドウは stage そのままではなく、 Toolbar など付属品があるウィンドウになります。mx_window_set_child() 配置した MxWidget は MxWindow に配置されている stage に配置されるので、今回のように MxButton -> stage -> window のように 2 段階で親ウィンドウを指定することになります。
Makefile は前回のものを使用するか、 CFLAGS と LDFLAGS を pkg-config の引数として mx-1.0 を利用した --cflags と --libs を使用してください。

#include <mx/mx.h>

static void
clicked (MxButton *button, gpointer user_data)
{
	ClutterActor *stage;
	MxWindow *window;
	MxWindowRotation rotation;
	
	stage = clutter_actor_get_parent (CLUTTER_ACTOR (button));
	window = mx_window_get_for_stage (CLUTTER_STAGE (stage));
	rotation = mx_window_get_window_rotation (window);
	switch (rotation)
	{
		case MX_WINDOW_ROTATION_0:
			mx_window_set_window_rotation (MX_WINDOW (window), MX_WINDOW_ROTATION_90);
			break;
		case MX_WINDOW_ROTATION_90:
			mx_window_set_window_rotation (MX_WINDOW (window), MX_WINDOW_ROTATION_180);
			break;
		case MX_WINDOW_ROTATION_180:
			mx_window_set_window_rotation (MX_WINDOW (window), MX_WINDOW_ROTATION_270);
			break;
		case MX_WINDOW_ROTATION_270:
			mx_window_set_window_rotation (MX_WINDOW (window), MX_WINDOW_ROTATION_0);
			break;
		default:
			mx_window_set_window_rotation (MX_WINDOW (window), MX_WINDOW_ROTATION_0);
	}
}

int
main (int argc, char *argv[])
{
	MxApplication *application;
	MxWindow *window;
	ClutterActor *button;

	application = mx_application_new (&argc, &argv,
		"button", MX_APPLICATION_SINGLE_INSTANCE);
	window = mx_application_create_window (application);
	g_signal_connect (window, "destroy", G_CALLBACK (mx_application_quit), NULL);
	
	button = mx_button_new ();
	mx_button_set_label (MX_BUTTON (button), "Click Me!");
	mx_window_set_child (window, button);
	g_signal_connect (button, "clicked", G_CALLBACK (clicked), NULL);

	mx_window_show (window);
	mx_application_run (application);
	return 0;
}

次回、時間があれば、アイコン付きのボタンやトグルボタンのサンプルを書く予定です。