diff options
author | Vincent Sanders <vince@netsurf-browser.org> | 2010-01-06 22:26:55 +0000 |
---|---|---|
committer | Vincent Sanders <vince@netsurf-browser.org> | 2010-01-06 22:26:55 +0000 |
commit | fd3c7753435658a6aeebf1b68d18178a6c7cf57d (patch) | |
tree | f17b620b6f7831476cae8d4f97ca8c2f9cbaa7b5 /test | |
parent | dfc3faf3fdf331e806cf43971c2251e65111f065 (diff) | |
download | libnsfb-fd3c7753435658a6aeebf1b68d18178a6c7cf57d.tar.gz libnsfb-fd3c7753435658a6aeebf1b68d18178a6c7cf57d.tar.bz2 |
add bezier curve plotters
svn path=/trunk/libnsfb/; revision=9794
Diffstat (limited to 'test')
-rw-r--r-- | test/Makefile | 2 | ||||
-rw-r--r-- | test/bezier.c | 112 |
2 files changed, 113 insertions, 1 deletions
diff --git a/test/Makefile b/test/Makefile index 6d4f4fa..dcb3d8f 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,3 +1,3 @@ -DIR_TEST_ITEMS := plottest:plottest.c;nsglobe.c frontend:frontend.c +DIR_TEST_ITEMS := plottest:plottest.c;nsglobe.c frontend:frontend.c bezier:bezier.c include build/makefiles/Makefile.subdir diff --git a/test/bezier.c b/test/bezier.c new file mode 100644 index 0000000..d44779b --- /dev/null +++ b/test/bezier.c @@ -0,0 +1,112 @@ +/* libnsfb plotetr test program */ + +#include <stdio.h> +#include <stdbool.h> +#include <stdlib.h> + +#include "libnsfb.h" +#include "libnsfb_plot.h" +#include "libnsfb_event.h" + +#define UNUSED(x) ((x) = (x)) + + +int main(int argc, char **argv) +{ + nsfb_t *nsfb; + nsfb_event_t event; + nsfb_bbox_t box; + nsfb_bbox_t box2; + uint8_t *fbptr; + int fbstride; + nsfb_point_t ctrla; + nsfb_point_t ctrlb; + int loop; + + UNUSED(argc); + UNUSED(argv); + + nsfb = nsfb_init(NSFB_FRONTEND_SDL); + if (nsfb == NULL) { + fprintf(stderr, "Unable to initialise nsfb with SDL frontend\n"); + return 1; + } + + if (nsfb_init_frontend(nsfb) == -1) { + fprintf(stderr, "Unable to initialise nsfb frontend\n"); + return 2; + } + + /* get the geometry of the whole screen */ + box.x0 = box.y0 = 0; + nsfb_get_geometry(nsfb, &box.x1, &box.y1, NULL); + + nsfb_get_framebuffer(nsfb, &fbptr, &fbstride); + + /* claim the whole screen for update */ + nsfb_claim(nsfb, &box); + + nsfb_plot_clg(nsfb, 0xffffffff); + + box2.x0=100; + box2.y0=100; + + box2.x1=400; + box2.y1=400; + + for (loop=-300;loop < 600;loop+=100) { + ctrla.x = 100; + ctrla.y = loop; + + ctrlb.x = 400; + ctrlb.y = 500 - loop; + + nsfb_plot_cubic_bezier(nsfb, &box2, &ctrla, &ctrlb, 0xff000000); + } + + + box2.x0=400; + box2.y0=100; + + box2.x1=600; + box2.y1=400; + + nsfb_plot_line(nsfb, &box2, 1, 0xff000000, false, false); + + box2.x0=800; + box2.y0=100; + + box2.x1=600; + box2.y1=400; + + nsfb_plot_line(nsfb, &box2, 1, 0xff000000, false, false); + + box2.x0=400; + box2.y0=100; + + box2.x1=800; + box2.y1=100; + + ctrla.x = 600; + ctrla.y = 400; + + nsfb_plot_cubic_bezier(nsfb, &box2, &ctrla, &ctrla, 0xffff0000); + + box2.x0=400; + box2.y0=100; + + box2.x1=800; + box2.y1=100; + + ctrla.x = 600; + ctrla.y = 400; + + nsfb_plot_quadratic_bezier(nsfb, &box2, &ctrla, 0xff0000ff); + + nsfb_update(nsfb, &box); + + while (event.type != NSFB_EVENT_CONTROL) + nsfb_event(nsfb, &event, -1); + + return 0; +} |