mirror of
https://github.com/brl/mutter.git
synced 2024-11-30 03:50:47 -05:00
8e437e838f
This removes a lot of code from test-cogl-primitives to make it easier to follow. The TestCoglBox custom actor has gone and instead a blank ClutterGroup is created with a paint signal handler. Instead of rendering constantly and updating when a GTimer elapses a second, a ClutterTimeline is used with 1 fps and a new redraw is queued every frame. The custom main loop is replaced with a regular call to clutter_main. This fixes the close button of the stage window so you can quit without having to press Ctrl+C.
163 lines
3.9 KiB
C
163 lines
3.9 KiB
C
#include <config.h>
|
|
#include <glib.h>
|
|
#include <gmodule.h>
|
|
#include <stdlib.h>
|
|
#include <clutter/clutter.h>
|
|
#include <cogl/cogl.h>
|
|
|
|
typedef void (*PaintFunc) (void);
|
|
|
|
static void
|
|
test_paint_line ()
|
|
{
|
|
cogl_path_line (CLUTTER_INT_TO_FIXED (-50),
|
|
CLUTTER_INT_TO_FIXED (-25),
|
|
CLUTTER_INT_TO_FIXED (50),
|
|
CLUTTER_INT_TO_FIXED (25));
|
|
}
|
|
|
|
static void
|
|
test_paint_rect ()
|
|
{
|
|
cogl_path_rectangle (CLUTTER_INT_TO_FIXED (-50),
|
|
CLUTTER_INT_TO_FIXED (-25),
|
|
CLUTTER_INT_TO_FIXED (100),
|
|
CLUTTER_INT_TO_FIXED (50));
|
|
}
|
|
|
|
static void
|
|
test_paint_rndrect()
|
|
{
|
|
cogl_path_round_rectangle (CLUTTER_INT_TO_FIXED (-50),
|
|
CLUTTER_INT_TO_FIXED (-25),
|
|
CLUTTER_INT_TO_FIXED (100),
|
|
CLUTTER_INT_TO_FIXED (50),
|
|
CLUTTER_INT_TO_FIXED (10),
|
|
5);
|
|
}
|
|
|
|
static void
|
|
test_paint_polyl ()
|
|
{
|
|
ClutterFixed poly_coords[] = {
|
|
CLUTTER_INT_TO_FIXED (-50),
|
|
CLUTTER_INT_TO_FIXED (-50),
|
|
CLUTTER_INT_TO_FIXED (+50),
|
|
CLUTTER_INT_TO_FIXED (-30),
|
|
CLUTTER_INT_TO_FIXED (+30),
|
|
CLUTTER_INT_TO_FIXED (+30),
|
|
CLUTTER_INT_TO_FIXED (-30),
|
|
CLUTTER_INT_TO_FIXED (+40)
|
|
};
|
|
|
|
cogl_path_polyline (poly_coords, 4);
|
|
}
|
|
|
|
static void
|
|
test_paint_polyg ()
|
|
{
|
|
gfloat poly_coords[] = {
|
|
CLUTTER_INT_TO_FIXED (-50),
|
|
CLUTTER_INT_TO_FIXED (-50),
|
|
CLUTTER_INT_TO_FIXED (+50),
|
|
CLUTTER_INT_TO_FIXED (-30),
|
|
CLUTTER_INT_TO_FIXED (+30),
|
|
CLUTTER_INT_TO_FIXED (+30),
|
|
CLUTTER_INT_TO_FIXED (-30),
|
|
CLUTTER_INT_TO_FIXED (+40)
|
|
};
|
|
|
|
cogl_path_polygon (poly_coords, 4);
|
|
}
|
|
|
|
static void
|
|
test_paint_elp ()
|
|
{
|
|
cogl_path_ellipse (0, 0,
|
|
CLUTTER_INT_TO_FIXED (60),
|
|
CLUTTER_INT_TO_FIXED (40));
|
|
}
|
|
|
|
static void
|
|
test_paint_curve ()
|
|
{
|
|
cogl_path_move_to (CLUTTER_INT_TO_FIXED (-50),
|
|
CLUTTER_INT_TO_FIXED (+50));
|
|
|
|
cogl_path_curve_to (CLUTTER_INT_TO_FIXED (+100),
|
|
CLUTTER_INT_TO_FIXED (-50),
|
|
CLUTTER_INT_TO_FIXED (-100),
|
|
CLUTTER_INT_TO_FIXED (-50),
|
|
CLUTTER_INT_TO_FIXED (+50),
|
|
CLUTTER_INT_TO_FIXED (+50));
|
|
}
|
|
|
|
static PaintFunc paint_func []=
|
|
{
|
|
test_paint_line,
|
|
test_paint_rect,
|
|
test_paint_rndrect,
|
|
test_paint_polyl,
|
|
test_paint_polyg,
|
|
test_paint_elp,
|
|
test_paint_curve
|
|
};
|
|
|
|
static void
|
|
paint_cb (ClutterActor *self, ClutterTimeline *tl)
|
|
{
|
|
gint paint_index = (clutter_timeline_get_current_frame (tl)
|
|
% G_N_ELEMENTS (paint_func));
|
|
|
|
cogl_push_matrix ();
|
|
|
|
paint_func[paint_index] ();
|
|
|
|
cogl_translate (100, 100, 0);
|
|
cogl_set_source_color4ub (0, 160, 0, 255);
|
|
cogl_path_stroke_preserve ();
|
|
|
|
cogl_translate (150, 0, 0);
|
|
cogl_set_source_color4ub (200, 0, 0, 255);
|
|
cogl_path_fill ();
|
|
|
|
cogl_pop_matrix();
|
|
}
|
|
|
|
G_MODULE_EXPORT int
|
|
test_cogl_primitives_main (int argc, char *argv[])
|
|
{
|
|
ClutterActor *stage;
|
|
ClutterActor *coglbox;
|
|
ClutterTimeline *tl;
|
|
|
|
clutter_init(&argc, &argv);
|
|
|
|
/* One frame for each paint function at one frame per second */
|
|
tl = clutter_timeline_new (G_N_ELEMENTS (paint_func), 1);
|
|
clutter_timeline_set_loop (tl, TRUE);
|
|
clutter_timeline_start (tl);
|
|
|
|
stage = clutter_stage_get_default ();
|
|
clutter_actor_set_size (stage, 400, 400);
|
|
clutter_stage_set_title (CLUTTER_STAGE (stage), "Cogl Test");
|
|
|
|
coglbox = clutter_group_new ();
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (stage), coglbox);
|
|
g_signal_connect (coglbox, "paint", G_CALLBACK (paint_cb), tl);
|
|
/* Redraw every frame of the timeline */
|
|
g_signal_connect_swapped (tl, "new-frame",
|
|
G_CALLBACK (clutter_actor_queue_redraw), coglbox);
|
|
|
|
clutter_actor_set_rotation (coglbox, CLUTTER_Y_AXIS, -30, 200, 0, 0);
|
|
clutter_actor_set_position (coglbox, 0, 100);
|
|
|
|
clutter_actor_show (stage);
|
|
|
|
clutter_main ();
|
|
|
|
g_object_unref (tl);
|
|
|
|
return 0;
|
|
}
|