This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project gfxprim.git.
The branch, master has been updated via 785938474481fa23cda347fd25a3df7f0adde980 (commit) from 35000c49abc94cc97388eab4b040df6dc2bdbee7 (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- http://repo.or.cz/w/gfxprim.git/commit/785938474481fa23cda347fd25a3df7f0adde...
commit 785938474481fa23cda347fd25a3df7f0adde980 Author: Cyril Hrubis metan@ucw.cz Date: Mon Dec 3 23:34:20 2012 +0100
gfx: Add GP_FillPolygon() and GP_Polygon().
This commit adds missing polygon functions as well as polygon into the shapetest.
diff --git a/demos/c_simple/shapetest.c b/demos/c_simple/shapetest.c index 702b210..a807f5b 100644 --- a/demos/c_simple/shapetest.c +++ b/demos/c_simple/shapetest.c @@ -55,8 +55,9 @@ static int show_axes = 1; #define SHAPE_ELLIPSE 4 #define SHAPE_RECTANGLE 5 #define SHAPE_TETRAGON 6 -#define SHAPE_ARC 7 -#define SHAPE_LAST 7 +#define SHAPE_POLYGON 7 +#define SHAPE_ARC 8 +#define SHAPE_LAST 8 static int shape = SHAPE_FIRST;
/* Variants in coordinates, if applicable */ @@ -198,6 +199,42 @@ void draw_testing_tetragon(int x, int y, int xradius, int yradius) GP_Tetragon(win, x0, y0, x1, y1, x2, y2, x3, y3, white); }
+void draw_testing_polygon(int x, int y, int xradius, int yradius) +{ + GP_Coord xy[14]; + unsigned int edges = 7; + + xy[0] = x + xradius; + xy[1] = y; + + xy[2] = x + 3 * xradius / 4; + xy[3] = y + yradius / 4; + + xy[4] = x + 3 * xradius / 4; + xy[5] = y + 3 * yradius / 4; + + xy[6] = x + xradius / 4; + xy[7] = y + 3 * yradius / 4; + + xy[8] = x; + xy[9] = y; + + xy[10] = x - xradius; + xy[11] = y; + + xy[12] = x - 3 * xradius / 4; + xy[13] = y - yradius / 4; + + if (outline == 1) + GP_Polygon(win, edges, xy, yellow); + + if (fill) + GP_FillPolygon(win, edges, xy, red); + + if (outline == 2) + GP_Polygon(win, edges, xy, white); +} + void redraw_screen(void) {
@@ -228,31 +265,35 @@ void redraw_screen(void) case SHAPE_TRIANGLE: draw_testing_triangle(center_x, center_y, xradius, yradius); title = "TRIANGLE"; - break; + break; case SHAPE_CIRCLE: draw_testing_circle(center_x, center_y, xradius, yradius); title = "CIRCLE"; - break; + break; case SHAPE_RING: draw_testing_ring(center_x, center_y, xradius, yradius); title = "RING"; - break; + break; case SHAPE_ELLIPSE: draw_testing_ellipse(center_x, center_y, xradius, yradius); title = "ELLIPSE"; - break; + break; case SHAPE_RECTANGLE: draw_testing_rectangle(center_x, center_y, xradius, yradius); title = "RECTANGLE"; - break; + break; case SHAPE_TETRAGON: draw_testing_tetragon(center_x, center_y, xradius, yradius); title = "TETRAGON"; - break; + break; + case SHAPE_POLYGON: + draw_testing_polygon(center_x, center_y, xradius, yradius); + title = "POLYGON"; + break; case SHAPE_ARC: draw_testing_arc(center_x, center_y, xradius, yradius); title = "ARC"; - break; + break; }
GP_Text(win, &style, 16, 16, GP_ALIGN_RIGHT|GP_VALIGN_BELOW, @@ -428,7 +469,7 @@ void print_instructions(void) printf(" 1/2/3 ............... choose shape variant (if applicable)n"); }
-int main(int argc, char ** argv) +int main(void) { const char *backend_opts = "X11";
diff --git a/include/gfx/GP_Polygon.h b/include/gfx/GP_Polygon.h index 8874a53..1ed256e 100644 --- a/include/gfx/GP_Polygon.h +++ b/include/gfx/GP_Polygon.h @@ -19,16 +19,25 @@ * Copyright (C) 2009-2011 Jiri "BlueBear" Dluhos * * jiri.bluebear.dluhos@gmail.com * * * - * Copyright (C) 2009-2011 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
-#ifndef GP_POLYGON_H -#define GP_POLYGON_H +#ifndef GFX_GP_POLYGON_H +#define GFX_GP_POLYGON_H
#include "core/GP_Context.h"
-void GP_FillPolygon_Raw(GP_Context *context, int vertex_count, +void GP_Polygon(GP_Context *context, unsigned int vertex_count, + const GP_Coord *xy, GP_Pixel pixel); + +void GP_Polygon_Raw(GP_Context *context, unsigned int vertex_count, + const GP_Coord *xy, GP_Pixel pixel); + +void GP_FillPolygon(GP_Context *context, unsigned int vertex_count, + const GP_Coord *xy, GP_Pixel pixel); + +void GP_FillPolygon_Raw(GP_Context *context, unsigned int vertex_count, const GP_Coord *xy, GP_Pixel pixel);
-#endif /* GP_POLYGON_H */ +#endif /* GFX_GP_POLYGON_H */ diff --git a/libs/gfx/GP_Polygon.c b/libs/gfx/GP_Polygon.c index f2ea9cd..ed75a27 100644 --- a/libs/gfx/GP_Polygon.c +++ b/libs/gfx/GP_Polygon.c @@ -16,8 +16,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2012 Jiri Dluhos jiri.bluebear.dluhos@gmail.com * - * Copyright (C) 2012 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009 - 2012 Jiri Dluhos jiri.bluebear.dluhos@gmail.com * + * Copyright (C) 2009 - 2012 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
@@ -27,6 +27,9 @@ #include <stdio.h> #include <math.h>
+#include "core/GP_Transform.h" + +#include "GP_Line.h" #include "GP_HLine.h" #include "GP_Polygon.h"
@@ -118,15 +121,15 @@ static int GP_ComputeScanline(float *results, struct GP_PolygonEdge *edges, return result_index; }
-void GP_FillPolygon_Raw(GP_Context *context, int vertex_count, - const GP_Coord *xy, GP_Pixel pixel) +void GP_FillPolygon_Raw(GP_Context *context, unsigned int vertex_count, + const GP_Coord *xy, GP_Pixel pixel) { float ymin = HUGE_VALF, ymax = -HUGE_VALF; struct GP_PolygonEdge *edge; struct GP_PolygonEdge edges[vertex_count];
int i; - for (i = 0; i < vertex_count - 1; i++) { + for (i = 0; i < (int)vertex_count - 1; i++) { edge = edges + i; GP_InitEdge(edge, xy[2*i], xy[2*i + 1], xy[2*i + 2], xy[2*i + 3]); @@ -147,3 +150,64 @@ void GP_FillPolygon_Raw(GP_Context *context, int vertex_count, } } } + +void GP_FillPolygon(GP_Context *context, unsigned int vertex_count, + const GP_Coord *xy, GP_Pixel pixel) +{ + unsigned int i; + GP_Coord xy_copy[2 * vertex_count]; + + for (i = 0; i < vertex_count; i++) { + unsigned int x = 2 * i; + unsigned int y = 2 * i + 1; + + xy_copy[x] = xy[x]; + xy_copy[y] = xy[y]; + GP_TRANSFORM_POINT(context, xy_copy[x], xy_copy[y]); + } + + GP_FillPolygon_Raw(context, vertex_count, xy_copy, pixel); +} + +void GP_Polygon_Raw(GP_Context *context, unsigned int vertex_count, + const GP_Coord *xy, GP_Pixel pixel) +{ + unsigned int i; + + GP_Coord prev_x = xy[2 * vertex_count - 2]; + GP_Coord prev_y = xy[2 * vertex_count - 1]; + + for (i = 0; i < vertex_count; i++) { + GP_Coord x = xy[2 * i]; + GP_Coord y = xy[2 * i + 1]; + + GP_Line_Raw(context, prev_x, prev_y, x, y, pixel); + + prev_x = x; + prev_y = y; + } +} + + +void GP_Polygon(GP_Context *context, unsigned int vertex_count, + const GP_Coord *xy, GP_Pixel pixel) +{ + unsigned int i; + + GP_Coord prev_x = xy[2 * vertex_count - 2]; + GP_Coord prev_y = xy[2 * vertex_count - 1]; + + GP_TRANSFORM_POINT(context, prev_x, prev_y); + + for (i = 0; i < vertex_count; i++) { + GP_Coord x = xy[2 * i]; + GP_Coord y = xy[2 * i + 1]; + + GP_TRANSFORM_POINT(context, x, y); + + GP_Line_Raw(context, prev_x, prev_y, x, y, pixel); + + prev_x = x; + prev_y = y; + } +}
-----------------------------------------------------------------------
Summary of changes: demos/c_simple/shapetest.c | 61 ++++++++++++++++++++++++++++++------ include/gfx/GP_Polygon.h | 19 ++++++++--- libs/gfx/GP_Polygon.c | 74 +++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 134 insertions(+), 20 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos@gmail.com if you want to unsubscribe, or site admin admin@repo.or.cz if you receive no reply.