| 1 |
/* ______ ___ ___ |
| 2 |
* /\ _ \ /\_ \ /\_ \ |
| 3 |
* \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___ |
| 4 |
* \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\ |
| 5 |
* \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \ |
| 6 |
* \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/ |
| 7 |
* \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/ |
| 8 |
* /\____/ |
| 9 |
* \_/__/ |
| 10 |
* |
| 11 |
* Polygon with holes drawing routines. |
| 12 |
* |
| 13 |
* |
| 14 |
* By Michał Cichoń. |
| 15 |
* |
| 16 |
* See readme.txt for copyright information. |
| 17 |
*/ |
| 18 |
|
| 19 |
#include <math.h> |
| 20 |
|
| 21 |
#include "allegro5/allegro.h" |
| 22 |
#include "allegro5/allegro_primitives.h" |
| 23 |
#include "allegro5/internal/aintern_prim_addon.h" |
| 24 |
|
| 25 |
#ifdef ALLEGRO_MSVC |
| 26 |
#define hypotf(x, y) _hypotf((x), (y)) |
| 27 |
#endif |
| 28 |
|
| 29 |
static void polygon_push_triangle_callback(int i0, int i1, int i2, void* user_data) |
| 30 |
{ |
| 31 |
ALLEGRO_PRIM_VERTEX_CACHE* cache = (ALLEGRO_PRIM_VERTEX_CACHE*)user_data; |
| 32 |
|
| 33 |
const float* vertices = (const float*)cache->user_data; |
| 34 |
|
| 35 |
const float* v0 = vertices + (i0 * 2); |
| 36 |
const float* v1 = vertices + (i1 * 2); |
| 37 |
const float* v2 = vertices + (i2 * 2); |
| 38 |
|
| 39 |
_al_prim_cache_push_triangle(cache, v0, v1, v2); |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
/* Function: al_draw_polygon |
| 44 |
*/ |
| 45 |
void al_draw_polygon(const float *vertices, int vertex_count, |
| 46 |
int join_style, ALLEGRO_COLOR color, float thickness, float miter_limit) |
| 47 |
{ |
| 48 |
al_draw_polyline(vertices, 2 * sizeof(float), vertex_count, join_style, |
| 49 |
ALLEGRO_LINE_CAP_CLOSED, color, thickness, miter_limit); |
| 50 |
} |
| 51 |
|
| 52 |
/* Function: al_draw_filled_polygon |
| 53 |
*/ |
| 54 |
void al_draw_filled_polygon(const float *vertices, int vertex_count, |
| 55 |
ALLEGRO_COLOR color) |
| 56 |
{ |
| 57 |
ALLEGRO_PRIM_VERTEX_CACHE cache; |
| 58 |
int vertex_counts[2]; |
| 59 |
|
| 60 |
_al_prim_cache_init_ex(&cache, ALLEGRO_PRIM_VERTEX_CACHE_TRIANGLE, color, (void*)vertices); |
| 61 |
|
| 62 |
vertex_counts[0] = vertex_count; |
| 63 |
vertex_counts[1] = 0; /* terminator */ |
| 64 |
al_triangulate_polygon(vertices, sizeof(float) * 2, vertex_counts, |
| 65 |
polygon_push_triangle_callback, &cache); |
| 66 |
|
| 67 |
_al_prim_cache_flush(&cache); |
| 68 |
} |
| 69 |
|
| 70 |
/* Function: al_draw_filled_polygon_with_holes |
| 71 |
*/ |
| 72 |
void al_draw_filled_polygon_with_holes(const float *vertices, |
| 73 |
const int *vertex_counts, ALLEGRO_COLOR color) |
| 74 |
{ |
| 75 |
ALLEGRO_PRIM_VERTEX_CACHE cache; |
| 76 |
|
| 77 |
_al_prim_cache_init_ex(&cache, ALLEGRO_PRIM_VERTEX_CACHE_TRIANGLE, color, (void*)vertices); |
| 78 |
|
| 79 |
al_triangulate_polygon(vertices, sizeof(float) * 2, vertex_counts, |
| 80 |
polygon_push_triangle_callback, &cache); |
| 81 |
|
| 82 |
_al_prim_cache_flush(&cache); |
| 83 |
} |
| 84 |
|
| 85 |
/* vim: set sts=3 sw=3 et: */ |