2008-04-25 13:37:36 +00:00
|
|
|
#include <glib.h>
|
2008-11-07 19:32:28 +00:00
|
|
|
#include <gmodule.h>
|
2008-04-25 13:37:36 +00:00
|
|
|
#include <stdlib.h>
|
2011-01-19 14:36:30 +00:00
|
|
|
|
|
|
|
#undef COGL_ENABLE_EXPERIMENTAL_2_0_API
|
2008-04-25 13:37:36 +00:00
|
|
|
#include <cogl/cogl.h>
|
2011-01-19 14:36:30 +00:00
|
|
|
#include <clutter/clutter.h>
|
2008-04-25 13:37:36 +00:00
|
|
|
|
|
|
|
typedef void (*PaintFunc) (void);
|
|
|
|
|
|
|
|
static void
|
2010-05-27 11:18:29 +00:00
|
|
|
test_paint_line (void)
|
2008-04-25 13:37:36 +00:00
|
|
|
{
|
2009-03-09 17:34:23 +00:00
|
|
|
cogl_path_line (-50, -25, 50, 25);
|
2008-04-25 13:37:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-05-27 11:18:29 +00:00
|
|
|
test_paint_rect (void)
|
2008-04-25 13:37:36 +00:00
|
|
|
{
|
2009-03-13 12:20:26 +00:00
|
|
|
cogl_path_rectangle (-50, -25, 50, 25);
|
2008-04-25 13:37:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-05-27 11:18:29 +00:00
|
|
|
test_paint_rndrect(void)
|
2008-04-25 13:37:36 +00:00
|
|
|
{
|
2009-03-13 12:20:26 +00:00
|
|
|
cogl_path_round_rectangle (-50, -25, 50, 25, 10, 5);
|
2008-04-25 13:37:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-05-27 11:18:29 +00:00
|
|
|
test_paint_polyl (void)
|
2008-04-25 13:37:36 +00:00
|
|
|
{
|
2009-03-09 17:34:23 +00:00
|
|
|
gfloat poly_coords[] = {
|
|
|
|
-50, -50,
|
|
|
|
+50, -30,
|
|
|
|
+30, +30,
|
|
|
|
-30, +40
|
2008-04-25 13:37:36 +00:00
|
|
|
};
|
2009-01-23 23:41:26 +00:00
|
|
|
|
2008-05-05 10:25:11 +00:00
|
|
|
cogl_path_polyline (poly_coords, 4);
|
2008-04-25 13:37:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-05-27 11:18:29 +00:00
|
|
|
test_paint_polyg (void)
|
2008-04-25 13:37:36 +00:00
|
|
|
{
|
2009-01-23 13:08:46 +00:00
|
|
|
gfloat poly_coords[] = {
|
2009-03-09 17:34:23 +00:00
|
|
|
-50, -50,
|
|
|
|
+50, -30,
|
|
|
|
+30, +30,
|
|
|
|
-30, +40
|
2008-04-25 13:37:36 +00:00
|
|
|
};
|
2009-01-23 23:41:26 +00:00
|
|
|
|
2008-05-05 10:25:11 +00:00
|
|
|
cogl_path_polygon (poly_coords, 4);
|
2008-04-25 13:37:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-05-27 11:18:29 +00:00
|
|
|
test_paint_elp (void)
|
2008-04-25 13:37:36 +00:00
|
|
|
{
|
2009-03-09 17:34:23 +00:00
|
|
|
cogl_path_ellipse (0, 0, 60, 40);
|
2008-04-25 13:37:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-05-27 11:18:29 +00:00
|
|
|
test_paint_curve (void)
|
2008-04-25 13:37:36 +00:00
|
|
|
{
|
2009-03-09 17:34:23 +00:00
|
|
|
cogl_path_move_to (-50, +50);
|
|
|
|
|
|
|
|
cogl_path_curve_to (+100, -50,
|
|
|
|
-100, -50,
|
|
|
|
+50, +50);
|
2008-04-25 13:37:36 +00:00
|
|
|
}
|
|
|
|
|
2008-04-29 15:41:34 +00:00
|
|
|
static PaintFunc paint_func []=
|
|
|
|
{
|
|
|
|
test_paint_line,
|
|
|
|
test_paint_rect,
|
|
|
|
test_paint_rndrect,
|
|
|
|
test_paint_polyl,
|
|
|
|
test_paint_polyg,
|
|
|
|
test_paint_elp,
|
2008-05-05 10:25:11 +00:00
|
|
|
test_paint_curve
|
2008-04-29 15:41:34 +00:00
|
|
|
};
|
|
|
|
|
2008-04-25 13:37:36 +00:00
|
|
|
static void
|
2009-01-23 23:55:44 +00:00
|
|
|
paint_cb (ClutterActor *self, ClutterTimeline *tl)
|
2008-04-25 13:37:36 +00:00
|
|
|
{
|
2009-06-04 12:05:12 +00:00
|
|
|
gint paint_index = (clutter_timeline_get_progress (tl)
|
|
|
|
* G_N_ELEMENTS (paint_func));
|
2009-01-23 23:41:26 +00:00
|
|
|
|
2008-04-25 13:37:36 +00:00
|
|
|
cogl_push_matrix ();
|
2009-01-23 23:41:26 +00:00
|
|
|
|
2008-04-25 13:37:36 +00:00
|
|
|
paint_func[paint_index] ();
|
2008-12-04 13:45:09 +00:00
|
|
|
|
2008-11-12 13:57:58 +00:00
|
|
|
cogl_translate (100, 100, 0);
|
|
|
|
cogl_set_source_color4ub (0, 160, 0, 255);
|
2008-12-04 13:45:09 +00:00
|
|
|
cogl_path_stroke_preserve ();
|
|
|
|
|
2008-11-12 13:57:58 +00:00
|
|
|
cogl_translate (150, 0, 0);
|
|
|
|
cogl_set_source_color4ub (200, 0, 0, 255);
|
2008-05-05 10:25:11 +00:00
|
|
|
cogl_path_fill ();
|
2009-01-23 23:41:26 +00:00
|
|
|
|
2008-04-25 13:37:36 +00:00
|
|
|
cogl_pop_matrix();
|
|
|
|
}
|
|
|
|
|
2008-11-07 19:32:28 +00:00
|
|
|
G_MODULE_EXPORT int
|
|
|
|
test_cogl_primitives_main (int argc, char *argv[])
|
2008-04-25 13:37:36 +00:00
|
|
|
{
|
|
|
|
ClutterActor *stage;
|
|
|
|
ClutterActor *coglbox;
|
2009-01-23 23:55:44 +00:00
|
|
|
ClutterTimeline *tl;
|
2009-01-23 23:41:26 +00:00
|
|
|
|
2011-02-22 00:19:35 +00:00
|
|
|
if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
|
|
|
|
return 1;
|
2009-01-23 23:41:26 +00:00
|
|
|
|
2009-06-04 12:05:12 +00:00
|
|
|
tl = clutter_timeline_new (G_N_ELEMENTS (paint_func) * 1000);
|
2009-01-23 23:55:44 +00:00
|
|
|
clutter_timeline_set_loop (tl, TRUE);
|
|
|
|
clutter_timeline_start (tl);
|
|
|
|
|
2011-11-09 13:41:15 +00:00
|
|
|
stage = clutter_stage_new ();
|
2008-04-25 13:37:36 +00:00
|
|
|
clutter_actor_set_size (stage, 400, 400);
|
2011-11-09 13:41:15 +00:00
|
|
|
clutter_stage_set_title (CLUTTER_STAGE (stage), "Cogl Path Primitives");
|
|
|
|
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
|
2009-01-23 23:41:26 +00:00
|
|
|
|
2009-01-23 23:55:44 +00:00
|
|
|
coglbox = clutter_group_new ();
|
2008-04-25 13:37:36 +00:00
|
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (stage), coglbox);
|
2009-01-23 23:55:44 +00:00
|
|
|
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);
|
2008-05-05 10:25:11 +00:00
|
|
|
|
|
|
|
clutter_actor_set_rotation (coglbox, CLUTTER_Y_AXIS, -30, 200, 0, 0);
|
|
|
|
clutter_actor_set_position (coglbox, 0, 100);
|
2009-01-23 23:41:26 +00:00
|
|
|
|
2009-01-23 23:55:44 +00:00
|
|
|
clutter_actor_show (stage);
|
|
|
|
|
|
|
|
clutter_main ();
|
2009-01-23 23:41:26 +00:00
|
|
|
|
2009-01-23 23:55:44 +00:00
|
|
|
g_object_unref (tl);
|
2009-01-23 23:41:26 +00:00
|
|
|
|
2008-04-25 13:37:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2011-11-09 13:41:15 +00:00
|
|
|
|
|
|
|
G_MODULE_EXPORT const char *
|
|
|
|
test_cogl_primitives (void)
|
|
|
|
{
|
|
|
|
return "2D Path primitives support in Cogl.";
|
|
|
|
}
|