From ef4052c18d54e6ee6cf96c2c1b3d7db81b98dc1e Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Wed, 28 Jan 2009 14:47:03 +0000 Subject: [PATCH] Changes cogl_rectangle to take x1, y1, x2, y2 args not x1, y1, width, height This makes it consistent with cogl_rectangle_with_{multi,}texture_coords. Notably the reason cogl_rectangle_with_{multi,}texture_coords wasn't changed instead is that the former approach lets you describe back facing rectangles. (though technically you could pass negative width/height values to achieve this; it doesn't seem as neat.) --- clutter/clutter-rectangle.c | 12 +++---- clutter/clutter-text.c | 9 ++--- clutter/cogl/cogl-path.h | 16 ++++----- clutter/cogl/common/cogl-primitives.c | 13 ++++--- clutter/cogl/gl/cogl-primitives.c | 10 +++--- clutter/cogl/gles/cogl-primitives.c | 10 +++--- clutter/cogl/gles/cogl.c | 8 +++-- clutter/pango/cogl-pango-render.c | 2 +- tests/conform/test-backface-culling.c | 6 ++-- tests/conform/test-binding-pool.c | 4 +-- tests/interactive/test-binding-pool.c | 4 +-- tests/interactive/test-cogl-offscreen.c | 48 ++++++++++++------------- tests/interactive/test-paint-wrapper.c | 2 +- 13 files changed, 75 insertions(+), 69 deletions(-) diff --git a/clutter/clutter-rectangle.c b/clutter/clutter-rectangle.c index 6bcf92921..fb975bed2 100644 --- a/clutter/clutter-rectangle.c +++ b/clutter/clutter-rectangle.c @@ -108,17 +108,17 @@ clutter_rectangle_paint (ClutterActor *self) /* this sucks, but it's the only way to make a border */ cogl_rectangle (priv->border_width, 0, - geom.width - priv->border_width, + geom.width, priv->border_width); cogl_rectangle (geom.width - priv->border_width, priv->border_width, - priv->border_width, - geom.height - priv->border_width); + geom.width, + geom.height); cogl_rectangle (0, geom.height - priv->border_width, geom.width - priv->border_width, - priv->border_width); + geom.height); cogl_rectangle (0, 0, priv->border_width, @@ -135,8 +135,8 @@ clutter_rectangle_paint (ClutterActor *self) tmp_alpha); cogl_rectangle (priv->border_width, priv->border_width, - geom.width - priv->border_width * 2, - geom.height - priv->border_width * 2); + geom.width - priv->border_width, + geom.height - priv->border_width); } else { diff --git a/clutter/clutter-text.c b/clutter/clutter-text.c index 5a0851bcd..ad77f9dd6 100644 --- a/clutter/clutter-text.c +++ b/clutter/clutter-text.c @@ -818,8 +818,8 @@ cursor_paint (ClutterText *self) { cogl_rectangle (priv->cursor_pos.x, priv->cursor_pos.y, - priv->cursor_pos.width, - priv->cursor_pos.height); + priv->cursor_pos.x + priv->cursor_pos.width, + priv->cursor_pos.y + priv->cursor_pos.height); } else { @@ -885,8 +885,9 @@ cursor_paint (ClutterText *self) cogl_rectangle (range_x, CLUTTER_UNITS_TO_DEVICE (y), - range_width, - CLUTTER_UNITS_TO_DEVICE (height)); + range_x + range_width, + CLUTTER_UNITS_TO_DEVICE (y) + + CLUTTER_UNITS_TO_DEVICE (height)); } g_free (ranges); diff --git a/clutter/cogl/cogl-path.h b/clutter/cogl/cogl-path.h index d1433fe4d..361c9ef1b 100644 --- a/clutter/cogl/cogl-path.h +++ b/clutter/cogl/cogl-path.h @@ -52,17 +52,17 @@ G_BEGIN_DECLS /** * cogl_rectangle: - * @x: X coordinate of the top-left corner - * @y: Y coordinate of the top-left corner - * @width: Width of the rectangle - * @height: Height of the rectangle + * @x1: X coordinate of the top-left corner + * @y1: Y coordinate of the top-left corner + * @x2: X coordinate of the bottom-right corner + * @y2: Y coordinate of the bottom-right corner * * Fills a rectangle at the given coordinates with the current source material **/ -void cogl_rectangle (float x, - float y, - float width, - float height); +void cogl_rectangle (float x1, + float y1, + float x2, + float y2); /** * cogl_path_fill: diff --git a/clutter/cogl/common/cogl-primitives.c b/clutter/cogl/common/cogl-primitives.c index 40843fc2b..1454b03c7 100644 --- a/clutter/cogl/common/cogl-primitives.c +++ b/clutter/cogl/common/cogl-primitives.c @@ -45,14 +45,13 @@ void _cogl_path_fill_nodes (); void _cogl_path_stroke_nodes (); void -cogl_rectangle (float x, - float y, - float width, - float height) +cogl_rectangle (float x1, + float y1, + float x2, + float y2) { - cogl_rectangle_with_multitexture_coords (x, y, - x+width, - y+height, + cogl_rectangle_with_multitexture_coords (x1, y1, + x2, y2, NULL, 0); } diff --git a/clutter/cogl/gl/cogl-primitives.c b/clutter/cogl/gl/cogl-primitives.c index ddb3bcc5e..917e69840 100644 --- a/clutter/cogl/gl/cogl-primitives.c +++ b/clutter/cogl/gl/cogl-primitives.c @@ -174,7 +174,8 @@ _cogl_add_path_to_stencil_buffer (floatVec2 nodes_min, significant bit */ GE( glStencilMask (merge ? 6 : 3) ); GE( glStencilOp (GL_ZERO, GL_REPLACE, GL_REPLACE) ); - cogl_rectangle (bounds_x, bounds_y, bounds_w, bounds_h); + cogl_rectangle (bounds_x, bounds_y, + bounds_x + bounds_w, bounds_y + bounds_h); GE( glStencilOp (GL_INVERT, GL_INVERT, GL_INVERT) ); } @@ -200,8 +201,8 @@ _cogl_add_path_to_stencil_buffer (floatVec2 nodes_min, GE( glMatrixMode (GL_PROJECTION) ); GE( glPushMatrix () ); GE( glLoadIdentity () ); - cogl_rectangle (-1.0, -1.0, 2, 2); - cogl_rectangle (-1.0, -1.0, 2, 2); + cogl_rectangle (-1.0, -1.0, 1.0, 1.0); + cogl_rectangle (-1.0, -1.0, 1.0, 1.0); GE( glPopMatrix () ); GE( glMatrixMode (GL_MODELVIEW) ); GE( glPopMatrix () ); @@ -235,7 +236,8 @@ _cogl_path_fill_nodes () CoglPathNode, 0), ctx->clip.stencil_used); - cogl_rectangle (bounds_x, bounds_y, bounds_w, bounds_h); + cogl_rectangle (bounds_x, bounds_y, + bounds_x + bounds_w, bounds_y + bounds_h); /* The stencil buffer now contains garbage so the clip area needs to be rebuilt */ diff --git a/clutter/cogl/gles/cogl-primitives.c b/clutter/cogl/gles/cogl-primitives.c index 612237283..0612d0216 100644 --- a/clutter/cogl/gles/cogl-primitives.c +++ b/clutter/cogl/gles/cogl-primitives.c @@ -180,7 +180,8 @@ _cogl_add_path_to_stencil_buffer (floatVec2 nodes_min, significant bit */ GE( glStencilMask (merge ? 6 : 3) ); GE( glStencilOp (GL_ZERO, GL_REPLACE, GL_REPLACE) ); - cogl_rectangle (bounds_x, bounds_y, bounds_w, bounds_h); + cogl_rectangle (bounds_x, bounds_y, + bounds_x + bounds_w, bounds_y + bounds_h); GE( glStencilOp (GL_INVERT, GL_INVERT, GL_INVERT) ); } @@ -206,8 +207,8 @@ _cogl_add_path_to_stencil_buffer (floatVec2 nodes_min, GE( glMatrixMode (GL_PROJECTION) ); GE( glPushMatrix () ); GE( glLoadIdentity () ); - cogl_rectangle (-1.0, -1.0, 2, 2); - cogl_rectangle (-1.0, -1.0, 2, 2); + cogl_rectangle (-1.0, -1.0, 1.0, 1.0); + cogl_rectangle (-1.0, -1.0, 1.0, 1.0); GE( glPopMatrix () ); GE( glMatrixMode (GL_MODELVIEW) ); GE( glPopMatrix () ); @@ -412,7 +413,8 @@ _cogl_path_fill_nodes () CoglPathNode, 0), ctx->clip.stencil_used); - cogl_rectangle (bounds_x, bounds_y, bounds_w, bounds_h); + cogl_rectangle (bounds_x, bounds_y, + bounds_x + bounds_w, bounds_y + bounds_h); /* The stencil buffer now contains garbage so the clip area needs to be rebuilt */ diff --git a/clutter/cogl/gles/cogl.c b/clutter/cogl/gles/cogl.c index 0b087a161..b0b983d0d 100644 --- a/clutter/cogl/gles/cogl.c +++ b/clutter/cogl/gles/cogl.c @@ -404,7 +404,8 @@ _cogl_add_stencil_clip (float x_offset, GE( glStencilFunc (GL_NEVER, 0x1, 0x1) ); GE( glStencilOp (GL_REPLACE, GL_REPLACE, GL_REPLACE) ); - cogl_rectangle (x_offset, y_offset, width, height); + cogl_rectangle (x_offset, y_offset, + x_offset + width, y_offset + height); } else { @@ -412,7 +413,8 @@ _cogl_add_stencil_clip (float x_offset, rectangle */ GE( glStencilFunc (GL_NEVER, 0x1, 0x3) ); GE( glStencilOp (GL_INCR, GL_INCR, GL_INCR) ); - cogl_rectangle (x_offset, y_offset, width, height); + cogl_rectangle (x_offset, y_offset, + x_offset + width, y_offset + height); /* Subtract one from all pixels in the stencil buffer so that only pixels where both the original stencil buffer and the @@ -423,7 +425,7 @@ _cogl_add_stencil_clip (float x_offset, GE( glMatrixMode (GL_PROJECTION) ); GE( glPushMatrix () ); GE( glLoadIdentity () ); - cogl_rectangle (-1.0, -1.0, 2, 2); + cogl_rectangle (-1.0, -1.0, 1.0, 1.0); GE( glPopMatrix () ); GE( glMatrixMode (GL_MODELVIEW) ); GE( glPopMatrix () ); diff --git a/clutter/pango/cogl-pango-render.c b/clutter/pango/cogl-pango-render.c index 0e839c573..272433273 100644 --- a/clutter/pango/cogl-pango-render.c +++ b/clutter/pango/cogl-pango-render.c @@ -514,7 +514,7 @@ cogl_pango_renderer_draw_rectangle (PangoRenderer *renderer, &x2, &y2); cogl_set_source (priv->solid_material); - cogl_rectangle (x1, y1, x2 - x1, y2 - y1); + cogl_rectangle (x1, y1, x2, y2); } static void diff --git a/tests/conform/test-backface-culling.c b/tests/conform/test-backface-culling.c index 7e7c947e2..2c846941a 100644 --- a/tests/conform/test-backface-culling.c +++ b/tests/conform/test-backface-culling.c @@ -128,14 +128,14 @@ on_paint (ClutterActor *actor, TestState *state) /* Draw a front-facing texture */ cogl_set_source_texture (state->texture); - cogl_rectangle (x1, y1, x2 - x1, y2 - y1); + cogl_rectangle (x1, y1, x2, y2); x1 = x2; x2 = x1 + (float)(TEXTURE_SIZE); /* Draw a back-facing texture */ cogl_set_source_texture (state->texture); - cogl_rectangle (x2, y1, x1 - x2, y2 - y1); + cogl_rectangle (x2, y1, x1, y2); x1 = x2; x2 = x1 + (float)(TEXTURE_SIZE); @@ -172,7 +172,7 @@ on_paint (ClutterActor *actor, TestState *state) /* Draw a regular rectangle (this should always show) */ cogl_set_source_color4f (1.0, 0, 0, 1.0); - cogl_rectangle (x1, y1, x2 - x1, y2 - y1); + cogl_rectangle (x1, y1, x2, y2); /* The second time round draw beneath the first with backface culling disabled */ diff --git a/tests/conform/test-binding-pool.c b/tests/conform/test-binding-pool.c index 9f7f24486..64cf11ee6 100644 --- a/tests/conform/test-binding-pool.c +++ b/tests/conform/test-binding-pool.c @@ -162,8 +162,8 @@ key_group_paint (ClutterActor *actor) cogl_set_source_color4ub (255, 255, 0, 224); cogl_rectangle (CLUTTER_UNITS_TO_DEVICE (box.x1), CLUTTER_UNITS_TO_DEVICE (box.y1), - CLUTTER_UNITS_TO_DEVICE (box.x2 - box.x1), - CLUTTER_UNITS_TO_DEVICE (box.y2 - box.y1)); + CLUTTER_UNITS_TO_DEVICE (box.x2), + CLUTTER_UNITS_TO_DEVICE (box.y2)); } if (CLUTTER_ACTOR_IS_VISIBLE (child)) diff --git a/tests/interactive/test-binding-pool.c b/tests/interactive/test-binding-pool.c index 8fbcb4816..1fb74d8fb 100644 --- a/tests/interactive/test-binding-pool.c +++ b/tests/interactive/test-binding-pool.c @@ -169,8 +169,8 @@ key_group_paint (ClutterActor *actor) cogl_set_source_color4ub (255, 255, 0, 224); cogl_rectangle (CLUTTER_UNITS_TO_DEVICE (box.x1), CLUTTER_UNITS_TO_DEVICE (box.y1), - CLUTTER_UNITS_TO_DEVICE (box.x2 - box.x1), - CLUTTER_UNITS_TO_DEVICE (box.y2 - box.y1)); + CLUTTER_UNITS_TO_DEVICE (box.x2), + CLUTTER_UNITS_TO_DEVICE (box.y2)); } if (CLUTTER_ACTOR_IS_VISIBLE (child)) diff --git a/tests/interactive/test-cogl-offscreen.c b/tests/interactive/test-cogl-offscreen.c index eabb754f7..b8ed3f158 100644 --- a/tests/interactive/test-cogl-offscreen.c +++ b/tests/interactive/test-cogl-offscreen.c @@ -9,7 +9,7 @@ *--------------------------------------------------*/ G_BEGIN_DECLS - + #define TEST_TYPE_COGLBOX test_coglbox_get_type() #define TEST_COGLBOX(obj) \ @@ -44,7 +44,7 @@ struct _TestCoglbox TestCoglboxPrivate *priv; }; -struct _TestCoglboxClass +struct _TestCoglboxClass { ClutterActorClass parent_class; @@ -88,7 +88,7 @@ test_coglbox_paint(ClutterActor *self) CLUTTER_FLOAT_TO_FIXED (1.0f) }; CoglHandle material; - + priv = TEST_COGLBOX_GET_PRIVATE (self); cogl_set_source_color4ub (0x66, 0x66, 0xdd, 0xff); @@ -101,15 +101,15 @@ test_coglbox_paint(ClutterActor *self) 0, 0, CLUTTER_INT_TO_FIXED (6), CLUTTER_INT_TO_FIXED (6)); - + cogl_draw_buffer (COGL_OFFSCREEN_BUFFER, priv->offscreen_id); - + cogl_set_source_color4ub (0xff, 0, 0, 0xff); - cogl_rectangle (20, 20, 100, 100); + cogl_rectangle (20, 20, 20 + 100, 20 + 100); cogl_set_source_color4ub (0, 0xff, 0, 0xff); - cogl_rectangle (80, 80, 100, 100); - + cogl_rectangle (80, 80, 80 + 100, 80 + 100); + cogl_draw_buffer (COGL_WINDOW_BUFFER, 0); material = cogl_material_new (); @@ -136,12 +136,12 @@ static void test_coglbox_dispose (GObject *object) { TestCoglboxPrivate *priv; - + priv = TEST_COGLBOX_GET_PRIVATE (object); - + cogl_texture_unref (priv->texture_id); cogl_offscreen_unref (priv->offscreen_id); - + G_OBJECT_CLASS (test_coglbox_parent_class)->dispose (object); } @@ -150,24 +150,24 @@ test_coglbox_init (TestCoglbox *self) { TestCoglboxPrivate *priv; self->priv = priv = TEST_COGLBOX_GET_PRIVATE(self); - + printf ("Loading redhand.png\n"); priv->texhand_id = cogl_texture_new_from_file ("redhand.png", 0, COGL_TEXTURE_NONE, COGL_PIXEL_FORMAT_ANY, NULL); - + printf ("Creating texture with size\n"); priv->texture_id = cogl_texture_new_with_size (200, 200, 0, COGL_TEXTURE_NONE, COGL_PIXEL_FORMAT_RGB_888); - + if (priv->texture_id == COGL_INVALID_HANDLE) printf ("Failed creating texture with size!\n"); - + printf ("Creating offscreen\n"); priv->offscreen_id = cogl_offscreen_new_to_texture (priv->texture_id); - + if (priv->offscreen_id == COGL_INVALID_HANDLE) printf ("Failed creating offscreen to texture!\n"); } @@ -179,9 +179,9 @@ test_coglbox_class_init (TestCoglboxClass *klass) ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass); gobject_class->finalize = test_coglbox_finalize; - gobject_class->dispose = test_coglbox_dispose; + gobject_class->dispose = test_coglbox_dispose; actor_class->paint = test_coglbox_paint; - + g_type_class_add_private (gobject_class, sizeof (TestCoglboxPrivate)); } @@ -196,21 +196,21 @@ test_cogl_offscreen_main (int argc, char *argv[]) { ClutterActor *stage; ClutterActor *coglbox; - + clutter_init(&argc, &argv); - + /* Stage */ stage = clutter_stage_get_default (); clutter_actor_set_size (stage, 400, 400); clutter_stage_set_title (CLUTTER_STAGE (stage), "Cogl Test"); - + /* Cogl Box */ coglbox = test_coglbox_new (); clutter_container_add_actor (CLUTTER_CONTAINER (stage), coglbox); - + clutter_actor_show_all (stage); - + clutter_main (); - + return 0; } diff --git a/tests/interactive/test-paint-wrapper.c b/tests/interactive/test-paint-wrapper.c index f0d7cb1ec..0a7f7550e 100644 --- a/tests/interactive/test-paint-wrapper.c +++ b/tests/interactive/test-paint-wrapper.c @@ -155,7 +155,7 @@ hand_post_paint (ClutterActor *actor, clutter_actor_get_size (actor, &w, &h); cogl_set_source_color4ub (0, 255, 0, 128); - cogl_rectangle (w / 2, h / 2, w / 2, h / 2); + cogl_rectangle (w / 2, h / 2, w, h); oh->paint_guards[actor_num] = FALSE; }