Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /* libnsfb plotetr test program */
  2.  
  3. #include <stdio.h>
  4. #include <stdbool.h>
  5. #include <stdlib.h>
  6.  
  7. #include "libnsfb.h"
  8. #include "libnsfb_plot.h"
  9. #include "libnsfb_event.h"
  10. #include "surface.h"
  11. //#include "../src/surface/sdl.c"
  12.  
  13.  
  14.  
  15.  
  16. #define UNUSED(x) ((x) = (x))
  17.  
  18. #include <menuet/os.h>
  19.  
  20. int main(int argc, char **argv)
  21. {
  22. extern nsfb_surface_rtns_t sdl_rtns;
  23.        
  24.         _nsfb_register_surface(NSFB_SURFACE_SDL, &sdl_rtns, "sdl");
  25.        
  26.         __menuet__debug_out("Starting bezier\n");
  27.         freopen("stderr","w",stderr);
  28.        
  29.         freopen("stdout","w",stdout);
  30.  
  31.     const char *fename;
  32.     enum nsfb_type_e fetype;
  33.     nsfb_t *nsfb;
  34.     nsfb_event_t event;
  35.     int waitloop = 3;
  36.  
  37.     nsfb_bbox_t box;
  38.     nsfb_bbox_t box2;
  39.     uint8_t *fbptr;
  40.     int fbstride;
  41.     nsfb_point_t ctrla;
  42.     nsfb_point_t ctrlb;
  43.     int loop;
  44.     nsfb_plot_pen_t pen;
  45.  
  46.     if (argc < 2) {
  47.         fename="sdl";
  48.     } else {
  49.         fename = argv[1];
  50.     }
  51.  
  52.     fetype = nsfb_type_from_name(fename);
  53.     if (fetype == NSFB_SURFACE_NONE) {
  54.     __menuet__debug_out("Can't convert\n");
  55.         fprintf(stderr, "Unable to convert \"%s\" to nsfb surface type\n", fename);
  56.         return 1;
  57.     }
  58.  
  59.     nsfb = nsfb_new(fetype);
  60.     if (nsfb == NULL) {
  61.                 __menuet__debug_out("Can't allocate\n");
  62.         fprintf(stderr, "Unable to allocate \"%s\" nsfb surface\n", fename);
  63.         return 2;
  64.     }
  65.  
  66.     if (nsfb_init(nsfb) == -1) {
  67.                 __menuet__debug_out("Init failed\n");
  68.         fprintf(stderr, "Unable to initialise nsfb surface\n");
  69.         nsfb_free(nsfb);
  70.         return 4;
  71.     }
  72.  
  73.     /* get the geometry of the whole screen */
  74.     box.x0 = box.y0 = 0;
  75.     nsfb_get_geometry(nsfb, &box.x1, &box.y1, NULL);
  76.  
  77.     nsfb_get_buffer(nsfb, &fbptr, &fbstride);
  78.  
  79.     /* claim the whole screen for update */
  80.     nsfb_claim(nsfb, &box);
  81.  
  82.     nsfb_plot_clg(nsfb, 0xffffffff);
  83.  
  84.     box2.x0=100;
  85.     box2.y0=100;
  86.  
  87.     box2.x1=400;
  88.     box2.y1=400;
  89.  
  90.     pen.stroke_colour = 0xff000000;
  91.     pen.fill_colour = 0xffff0000;
  92.     pen.stroke_type = NFSB_PLOT_OPTYPE_SOLID;
  93.     pen.fill_type = NFSB_PLOT_OPTYPE_NONE;
  94.  
  95.     for (loop=-300;loop < 600;loop+=100) {
  96.         ctrla.x = 100;
  97.         ctrla.y = loop;
  98.  
  99.         ctrlb.x = 400;
  100.         ctrlb.y = 500 - loop;
  101.  
  102.         nsfb_plot_cubic_bezier(nsfb, &box2, &ctrla, &ctrlb, &pen);
  103.     }
  104.  
  105.  
  106.     box2.x0=400;
  107.     box2.y0=100;
  108.  
  109.     box2.x1=600;
  110.     box2.y1=400;
  111.  
  112.     nsfb_plot_line(nsfb, &box2, &pen);
  113.  
  114.     box2.x0=800;
  115.     box2.y0=100;
  116.  
  117.     box2.x1=600;
  118.     box2.y1=400;
  119.  
  120.     nsfb_plot_line(nsfb, &box2, &pen);
  121.  
  122.     box2.x0=400;
  123.     box2.y0=100;
  124.  
  125.     box2.x1=800;
  126.     box2.y1=100;
  127.  
  128.     ctrla.x = 600;
  129.     ctrla.y = 400;
  130.  
  131.     pen.stroke_colour = 0xffff0000;
  132.  
  133.     nsfb_plot_cubic_bezier(nsfb, &box2, &ctrla, &ctrla, &pen);
  134.  
  135.     box2.x0=400;
  136.     box2.y0=100;
  137.  
  138.     box2.x1=800;
  139.     box2.y1=100;
  140.  
  141.     ctrla.x = 600;
  142.     ctrla.y = 400;
  143.  
  144.     pen.stroke_colour = 0xff0000ff;
  145.  
  146.     nsfb_plot_quadratic_bezier(nsfb, &box2, &ctrla, &pen);
  147.  
  148.     nsfb_update(nsfb, &box);
  149.    
  150.     /* wait for quit event or timeout */
  151.     while (waitloop > 0) {
  152.         if (nsfb_event(nsfb, &event, 1000)  == false) {
  153.             break;
  154.         }
  155.         if (event.type == NSFB_EVENT_CONTROL) {
  156.             if (event.value.controlcode == NSFB_CONTROL_TIMEOUT) {
  157.                 /* timeout */
  158.                 waitloop--;
  159.             } else if (event.value.controlcode == NSFB_CONTROL_QUIT) {
  160.                 break;
  161.             }
  162.         }
  163.     }
  164.  
  165.     nsfb_free(nsfb);
  166.  
  167.     return 0;
  168. }
  169.  
  170. /*
  171.  * Local variables:
  172.  *  c-basic-offset: 4
  173.  *  tab-width: 8
  174.  * End:
  175.  */
  176.