Subversion Repositories Kolibri OS

Rev

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

  1. /* libnsfb ploygon plotter test program */
  2.  
  3. #include <stdio.h>
  4. #include <stdbool.h>
  5. #include <stdlib.h>
  6. #include <math.h>
  7.  
  8. #include "libnsfb.h"
  9. #include "libnsfb_plot.h"
  10. #include "libnsfb_event.h"
  11. #include "surface.h"
  12.  
  13. #define UNUSED(x) ((x) = (x))
  14.  
  15.  
  16. int main(int argc, char **argv)
  17. {
  18.        
  19.         extern nsfb_surface_rtns_t sdl_rtns;
  20.        
  21.         _nsfb_register_surface(NSFB_SURFACE_SDL, &sdl_rtns, "sdl");
  22.        
  23.     const char *fename;
  24.     enum nsfb_type_e fetype;
  25.     nsfb_t *nsfb;
  26.     nsfb_event_t event;
  27.     int waitloop = 3;
  28.  
  29.     nsfb_bbox_t box;
  30.     uint8_t *fbptr;
  31.     int fbstride;
  32.  
  33.     int sides;
  34.     int radius;
  35.     nsfb_point_t *points;
  36.     int loop;
  37. //    nsfb_plot_pen_t pen;
  38.  
  39.     if (argc < 2) {
  40.         fename="sdl";
  41.     } else {
  42.         fename = argv[1];
  43.     }
  44.  
  45.     fetype = nsfb_type_from_name(fename);
  46.     if (fetype == NSFB_SURFACE_NONE) {
  47.         fprintf(stderr, "Unable to convert \"%s\" to nsfb surface type\n", fename);
  48.         return 1;
  49.     }
  50.  
  51.     nsfb = nsfb_new(fetype);
  52.     if (nsfb == NULL) {
  53.         fprintf(stderr, "Unable to allocate \"%s\" nsfb surface\n", fename);
  54.         return 2;
  55.     }
  56.  
  57.     if (nsfb_init(nsfb) == -1) {
  58.         fprintf(stderr, "Unable to initialise nsfb surface\n");
  59.         nsfb_free(nsfb);
  60.         return 4;
  61.     }
  62.  
  63.     /* get the geometry of the whole screen */
  64.     box.x0 = box.y0 = 0;
  65.     nsfb_get_geometry(nsfb, &box.x1, &box.y1, NULL);
  66.  
  67.     nsfb_get_buffer(nsfb, &fbptr, &fbstride);
  68.  
  69.     /* claim the whole screen for update */
  70.     nsfb_claim(nsfb, &box);
  71.  
  72.     nsfb_plot_clg(nsfb, 0xffffffff);
  73.  
  74.     radius = (box.x1 / 3);
  75.  
  76.     for (sides = 13; sides >=3; sides--) {
  77.             points = malloc(sizeof(nsfb_point_t) * sides);
  78.  
  79.             for (loop = 0; loop < sides;loop++) {
  80.                     points[loop].x = (box.x1 / 2) +
  81.                             (radius * cos(loop * 2 * M_PI / sides));
  82.                     points[loop].y = (box.y1 / 2) +
  83.                             (radius * sin(loop * 2 * M_PI / sides));
  84.             }
  85.  
  86.             nsfb_plot_polygon(nsfb, (const int *)points, sides,
  87.                               0xff000000 | (0xffffff / (sides * 2)));
  88.  
  89.             free(points);
  90.             radius -= 25;
  91.     }
  92.  
  93.     nsfb_update(nsfb, &box);
  94.    
  95.     /* wait for quit event or timeout */
  96.     while (waitloop > 0) {
  97.         if (nsfb_event(nsfb, &event, 1000)  == false) {
  98.             break;
  99.         }
  100.         if (event.type == NSFB_EVENT_CONTROL) {
  101.             if (event.value.controlcode == NSFB_CONTROL_TIMEOUT) {
  102.                 /* timeout */
  103.                 waitloop--;
  104.             } else if (event.value.controlcode == NSFB_CONTROL_QUIT) {
  105.                 break;
  106.             }
  107.         }
  108.     }
  109.  
  110.     nsfb_free(nsfb);
  111.  
  112.     return 0;
  113. }
  114.  
  115. /*
  116.  * Local variables:
  117.  *  c-basic-offset: 4
  118.  *  tab-width: 8
  119.  * End:
  120.  */
  121.