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.  
  11. #define UNUSED(x) ((x) = (x))
  12.  
  13. #define PENT(op, xco, yco) path[count].operation = op;  \
  14.     path[count].point.x = (xco);                        \
  15.     path[count].point.y = (yco);                        \
  16.     count++
  17.  
  18. static int fill_shape(nsfb_plot_pathop_t *path, int xoff, int yoff)
  19. {
  20.     int count = 0;
  21.  
  22.     PENT(NFSB_PLOT_PATHOP_MOVE, xoff, yoff);
  23.     PENT(NFSB_PLOT_PATHOP_LINE, xoff + 100, yoff + 100);
  24.     PENT(NFSB_PLOT_PATHOP_LINE, xoff + 100, yoff );
  25.     PENT(NFSB_PLOT_PATHOP_LINE, xoff + 200, yoff + 100);
  26.     PENT(NFSB_PLOT_PATHOP_MOVE, xoff + 200, yoff - 200);
  27.     PENT(NFSB_PLOT_PATHOP_MOVE, xoff + 300, yoff + 300);
  28.     PENT(NFSB_PLOT_PATHOP_CUBIC, xoff + 300, yoff );
  29.     PENT(NFSB_PLOT_PATHOP_LINE, xoff + 400, yoff + 100);
  30.     PENT(NFSB_PLOT_PATHOP_LINE, xoff + 400, yoff );
  31.     PENT(NFSB_PLOT_PATHOP_MOVE, xoff + 500, yoff + 200);
  32.     PENT(NFSB_PLOT_PATHOP_QUAD, xoff + 500, yoff );
  33.     PENT(NFSB_PLOT_PATHOP_LINE, xoff + 600, yoff + 150);
  34.     PENT(NFSB_PLOT_PATHOP_LINE, xoff, yoff + 150);
  35.     PENT(NFSB_PLOT_PATHOP_LINE, xoff, yoff);
  36.  
  37.     return count;
  38. }
  39.  
  40. int main(int argc, char **argv)
  41. {
  42.     const char *fename;
  43.     enum nsfb_type_e fetype;
  44.     nsfb_t *nsfb;
  45.  
  46.     int waitloop = 3;
  47.  
  48.     nsfb_event_t event;
  49.     nsfb_bbox_t box;
  50.     uint8_t *fbptr;
  51.     int fbstride;
  52.     nsfb_plot_pen_t pen;
  53.     nsfb_plot_pathop_t path[20];
  54.  
  55.     if (argc < 2) {
  56.         fename="sdl";
  57.     } else {
  58.         fename = argv[1];
  59.     }
  60.  
  61.     fetype = nsfb_type_from_name(fename);
  62.     if (fetype == NSFB_SURFACE_NONE) {
  63.         fprintf(stderr, "Unable to convert \"%s\" to nsfb surface type\n", fename);
  64.         return 1;
  65.     }
  66.  
  67.     nsfb = nsfb_new(fetype);
  68.     if (nsfb == NULL) {
  69.         fprintf(stderr, "Unable to allocate \"%s\" nsfb surface\n", fename);
  70.         return 2;
  71.     }
  72.  
  73.     if (nsfb_init(nsfb) == -1) {
  74.         fprintf(stderr, "Unable to initialise nsfb surface\n");
  75.         nsfb_free(nsfb);
  76.         return 4;
  77.     }
  78.  
  79.     /* get the geometry of the whole screen */
  80.     box.x0 = box.y0 = 0;
  81.     nsfb_get_geometry(nsfb, &box.x1, &box.y1, NULL);
  82.  
  83.     nsfb_get_buffer(nsfb, &fbptr, &fbstride);
  84.  
  85.     /* claim the whole screen for update */
  86.     nsfb_claim(nsfb, &box);
  87.  
  88.     nsfb_plot_clg(nsfb, 0xffffffff);
  89.  
  90.     pen.stroke_colour = 0xff0000ff;
  91.     pen.fill_colour = 0xffff0000;
  92.     pen.stroke_type = NFSB_PLOT_OPTYPE_SOLID;
  93.     pen.fill_type = NFSB_PLOT_OPTYPE_NONE;
  94.  
  95.     nsfb_plot_path(nsfb, fill_shape(path, 100, 50), path, &pen);
  96.  
  97.     pen.fill_type = NFSB_PLOT_OPTYPE_SOLID;
  98.  
  99.     nsfb_plot_path(nsfb, fill_shape(path, 100, 200), path, &pen);
  100.  
  101.     pen.stroke_type = NFSB_PLOT_OPTYPE_NONE;
  102.  
  103.     nsfb_plot_path(nsfb, fill_shape(path, 100, 350), path, &pen);
  104.  
  105.     nsfb_update(nsfb, &box);
  106.  
  107.     /* wait for quit event or timeout */
  108.     while (waitloop > 0) {
  109.         if (nsfb_event(nsfb, &event, 1000)  == false) {
  110.             break;
  111.         }
  112.         if (event.type == NSFB_EVENT_CONTROL) {
  113.             if (event.value.controlcode == NSFB_CONTROL_TIMEOUT) {
  114.                 /* timeout */
  115.                 waitloop--;
  116.             } else if (event.value.controlcode == NSFB_CONTROL_QUIT) {
  117.                 break;
  118.             }
  119.         }
  120.     }
  121.  
  122.     nsfb_free(nsfb);
  123.  
  124.     return 0;
  125. }
  126.  
  127. /*
  128.  * Local variables:
  129.  *  c-basic-offset: 4
  130.  *  tab-width: 8
  131.  * End:
  132.  */
  133.