mirror of
https://github.com/brl/mutter.git
synced 2024-11-26 18:11:05 -05:00
272e227109
cogl_clip_push() which accepts a rectangle in model space shouldn't have been defined to take x,y,width,height arguments because this isn't consistant with other Cogl API dealing with model space rectangles. If you are using a coordinate system with the origin at the center and the y+ extending up, then x,y,width,height isn't as natural as (x0,y0)(x1,y1). This API has now been replace with cogl_clip_push_rectangle() (As a general note: the Cogl API should only use the x,y,width,height style when the appropriate coordinate space is defined by Cogl to have a top left origin. E.g. window coordinates, or potentially texture coordinates) cogl_clip_push_window_rect() shouldn't have been defined to take float arguments since we only clip with integral pixel precision. We also shouldn't have abbreviated "rectangle". This API has been replaced with cogl_clip_push_window_rectangle() cogl_clip_ensure() wasn't documented at all in Clutter 1.0 and probably no one even knew it existed. This API isn't useful, and so it's now deprecated. If no one complains we may remove the API altogether for Clutter 1.2. cogl_clip_stack_save() and cogl_clip_stack_restore() were originally added to allow us to save/restore the clip when switching to/from offscreen rendering. Now that offscreen draw buffers are defined to own their clip state and the state will be automatically saved and restored this API is now redundant and so deprecated.
151 lines
3.0 KiB
C
151 lines
3.0 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);
|
|
CoglHandle hand;
|
|
|
|
static void
|
|
test_paint_line ()
|
|
{
|
|
cogl_path_line (-50, -25, 50, 25);
|
|
}
|
|
|
|
static void
|
|
test_paint_rect ()
|
|
{
|
|
cogl_path_rectangle (-50, -25, 50, 25);
|
|
}
|
|
|
|
static void
|
|
test_paint_rndrect()
|
|
{
|
|
cogl_path_round_rectangle (-50, -25, 50, 25, 10, 5);
|
|
}
|
|
|
|
static void
|
|
test_paint_polyl ()
|
|
{
|
|
gfloat poly_coords[] = {
|
|
-50, -50,
|
|
+50, -30,
|
|
+30, +30,
|
|
-30, +40
|
|
};
|
|
|
|
cogl_path_polyline (poly_coords, 4);
|
|
}
|
|
|
|
static void
|
|
test_paint_polyg ()
|
|
{
|
|
gfloat poly_coords[] = {
|
|
-50, -50,
|
|
+50, -30,
|
|
+30, +30,
|
|
-30, +40
|
|
};
|
|
|
|
cogl_path_polygon (poly_coords, 4);
|
|
}
|
|
|
|
static void
|
|
test_paint_elp ()
|
|
{
|
|
cogl_path_ellipse (0, 0, 60, 40);
|
|
}
|
|
|
|
static void
|
|
test_paint_curve ()
|
|
{
|
|
cogl_path_move_to (-50, +50);
|
|
|
|
cogl_path_curve_to (+100, -50,
|
|
-100, -50,
|
|
+50, +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_progress (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_set_source_texture (hand);
|
|
cogl_path_fill ();
|
|
|
|
cogl_pop_matrix();
|
|
}
|
|
|
|
G_MODULE_EXPORT int
|
|
test_cogl_primitives_main (int argc, char *argv[])
|
|
{
|
|
ClutterActor *stage;
|
|
ClutterActor *coglbox;
|
|
ClutterTimeline *tl;
|
|
GError *error = NULL;
|
|
|
|
clutter_init(&argc, &argv);
|
|
|
|
hand =cogl_texture_new_from_file ("redhand.png",
|
|
COGL_TEXTURE_NONE,
|
|
COGL_PIXEL_FORMAT_ANY,
|
|
&error);
|
|
if (error)
|
|
{
|
|
g_critical ("Failed to load redhand.png: %s", error->message);
|
|
g_error_free (error);
|
|
return 1;
|
|
}
|
|
|
|
tl = clutter_timeline_new (G_N_ELEMENTS (paint_func) * 1000);
|
|
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;
|
|
}
|