Subversion Repositories Kolibri OS

Rev

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

  1. /* public plotter interface */
  2.  
  3. #include <stdbool.h>
  4.  
  5. #include "libnsfb.h"
  6. #include "libnsfb_plot.h"
  7.  
  8. #include "nsfb.h"
  9. #include "plot.h"
  10.  
  11. /** Sets a clip rectangle for subsequent plots.
  12.  *
  13.  * Sets a clipping area which constrains all subsequent plotting operations.
  14.  * The clipping area must lie within the framebuffer visible screen or false
  15.  * will be returned and the new clipping area not set.
  16.  */
  17. bool nsfb_plot_set_clip(nsfb_t *nsfb, nsfb_bbox_t *clip)
  18. {
  19.     return nsfb->plotter_fns->set_clip(nsfb, clip);
  20. }
  21.  
  22. /** Get the previously set clipping region.
  23.  */
  24. bool nsfb_plot_get_clip(nsfb_t *nsfb, nsfb_bbox_t *clip)
  25. {
  26.     return nsfb->plotter_fns->get_clip(nsfb, clip);
  27. }
  28.  
  29. /** Clears plotting area to a flat colour.
  30.  */
  31. bool nsfb_plot_clg(nsfb_t *nsfb, nsfb_colour_t c)
  32. {
  33.     return nsfb->plotter_fns->clg(nsfb, c);
  34. }
  35.  
  36. /** Plots a rectangle outline.
  37.  *
  38.  * The line can be solid, dotted or dashed. Top left corner at (x0,y0) and
  39.  * rectangle has given width and height.
  40.  */
  41. bool
  42. nsfb_plot_rectangle(nsfb_t *nsfb,
  43.                     nsfb_bbox_t *rect,
  44.                     int line_width,
  45.                     nsfb_colour_t c,
  46.                     bool dotted,
  47.                     bool dashed)
  48. {
  49.     return nsfb->plotter_fns->rectangle(nsfb, rect, line_width, c, dotted, dashed);
  50.  
  51. }
  52.  
  53. /** Plots a filled rectangle. Top left corner at (x0,y0), bottom
  54.  *                right corner at (x1,y1). Note: (x0,y0) is inside filled area,
  55.  *                but (x1,y1) is below and to the right. See diagram below.
  56.  */
  57. bool nsfb_plot_rectangle_fill(nsfb_t *nsfb, nsfb_bbox_t *rect, nsfb_colour_t c)
  58. {
  59.     return nsfb->plotter_fns->fill(nsfb, rect, c);
  60. }
  61.  
  62. /** Plots a line.
  63.  *
  64.  * Draw a line from (x0,y0) to (x1,y1). Coordinates are at centre of line
  65.  * width/thickness.
  66.  */
  67. bool nsfb_plot_line(nsfb_t *nsfb, nsfb_bbox_t *line, nsfb_plot_pen_t *pen)
  68. {
  69.         return nsfb->plotter_fns->line(nsfb, 1, line, pen);
  70. }
  71.  
  72. /** Plots more than one line.
  73.  *
  74.  * Draw a line from (x0,y0) to (x1,y1). Coordinates are at centre of line
  75.  * width/thickness.
  76.  */
  77. bool nsfb_plot_lines(nsfb_t *nsfb, int linec, nsfb_bbox_t *line, nsfb_plot_pen_t *pen)
  78. {
  79.         return nsfb->plotter_fns->line(nsfb, linec, line, pen);
  80. }
  81.  
  82. bool nsfb_plot_polylines(nsfb_t *nsfb, int pointc, const nsfb_point_t *points, nsfb_plot_pen_t *pen)
  83. {
  84.         return nsfb->plotter_fns->polylines(nsfb, pointc, points, pen);
  85. }
  86.  
  87. /** Plots a filled polygon.
  88.  *
  89.  * Plots a filled polygon with straight lines between points. The lines around
  90.  * the edge of the ploygon are not plotted. The polygon is filled with a
  91.  * non-zero winding rule.
  92.  *
  93.  *
  94.  */
  95. bool nsfb_plot_polygon(nsfb_t *nsfb, const int *p, unsigned int n, nsfb_colour_t fill)
  96. {
  97.     return nsfb->plotter_fns->polygon(nsfb, p, n, fill);
  98. }
  99.  
  100. /** Plots an arc.
  101.  *
  102.  * around (x,y), from anticlockwise from angle1 to angle2. Angles are measured
  103.  * anticlockwise from horizontal, in degrees.
  104.  */
  105. bool nsfb_plot_arc(nsfb_t *nsfb, int x, int y, int radius, int angle1, int angle2, nsfb_colour_t c)
  106. {
  107.     return nsfb->plotter_fns->arc(nsfb, x, y, radius, angle1, angle2, c);
  108. }
  109.  
  110. /** Plots an alpha blended pixel.
  111.  *
  112.  * plots an alpha blended pixel.
  113.  */
  114. bool nsfb_plot_point(nsfb_t *nsfb, int x, int y, nsfb_colour_t c)
  115. {
  116.     return nsfb->plotter_fns->point(nsfb, x, y, c);
  117. }
  118.  
  119. bool nsfb_plot_ellipse(nsfb_t *nsfb, nsfb_bbox_t *ellipse, nsfb_colour_t c)
  120. {
  121.     return nsfb->plotter_fns->ellipse(nsfb, ellipse, c);
  122. }
  123.  
  124. bool nsfb_plot_ellipse_fill(nsfb_t *nsfb, nsfb_bbox_t *ellipse, nsfb_colour_t c)
  125. {
  126.     return nsfb->plotter_fns->ellipse_fill(nsfb, ellipse, c);
  127. }
  128.  
  129. /* copy an area of surface from one location to another.
  130.  *
  131.  * @warning This implementation is woefully incomplete!
  132.  */
  133. bool
  134. nsfb_plot_copy(nsfb_t *srcfb,
  135.                nsfb_bbox_t *srcbox,
  136.                nsfb_t *dstfb,
  137.                nsfb_bbox_t *dstbox)
  138. {
  139.     bool trans = false;
  140.     nsfb_colour_t srccol;
  141.  
  142.     if (srcfb == dstfb) {
  143.         return dstfb->plotter_fns->copy(srcfb, srcbox, dstbox);
  144.     }
  145.  
  146.     if (srcfb->format == NSFB_FMT_ABGR8888) {
  147.         trans = true;
  148.     }
  149.  
  150.     if ((srcfb->width == 1) && (srcfb->height == 1)) {
  151.         srccol = *(nsfb_colour_t *)(void *)(srcfb->ptr);
  152.        
  153.         /* check for completely transparent */
  154.         if ((srccol & 0xff000000) == 0)
  155.             return true;
  156.  
  157.         /* completely opaque pixels can be replaced with fill */
  158.         if ((srccol & 0xff000000) == 0xff)
  159.             return dstfb->plotter_fns->fill(dstfb, dstbox, srccol);
  160.     }
  161.  
  162.     return dstfb->plotter_fns->bitmap(dstfb, dstbox, (const nsfb_colour_t *)(void *)srcfb->ptr, srcfb->width, srcfb->height, (srcfb->linelen * 8) / srcfb->bpp, trans);
  163.    
  164. }
  165.  
  166. bool nsfb_plot_bitmap(nsfb_t *nsfb, const nsfb_bbox_t *loc, const nsfb_colour_t *pixel, int bmp_width, int bmp_height, int bmp_stride, bool alpha)
  167. {
  168.     return nsfb->plotter_fns->bitmap(nsfb, loc,  pixel, bmp_width, bmp_height, bmp_stride, alpha);
  169. }
  170.  
  171. /** Plot an 8 bit glyph.
  172.  */
  173. bool nsfb_plot_glyph8(nsfb_t *nsfb, nsfb_bbox_t *loc, const uint8_t *pixel, int pitch, nsfb_colour_t c)
  174. {
  175.     return nsfb->plotter_fns->glyph8(nsfb, loc, pixel, pitch, c);
  176. }
  177.  
  178.  
  179. /** Plot an 1 bit glyph.
  180.  */
  181. bool nsfb_plot_glyph1(nsfb_t *nsfb, nsfb_bbox_t *loc, const uint8_t *pixel, int pitch, nsfb_colour_t c)
  182. {
  183.     return nsfb->plotter_fns->glyph1(nsfb, loc, pixel, pitch, c);
  184. }
  185.  
  186. /* read a rectangle from screen into buffer */
  187. bool nsfb_plot_readrect(nsfb_t *nsfb, nsfb_bbox_t *rect, nsfb_colour_t *buffer)
  188. {
  189.     return nsfb->plotter_fns->readrect(nsfb, rect, buffer);
  190. }
  191.  
  192.  
  193. bool nsfb_plot_cubic_bezier(nsfb_t *nsfb, nsfb_bbox_t *curve, nsfb_point_t *ctrla, nsfb_point_t *ctrlb, nsfb_plot_pen_t *pen)
  194. {
  195.     return nsfb->plotter_fns->cubic(nsfb, curve, ctrla, ctrlb, pen);
  196. }
  197.  
  198. bool nsfb_plot_quadratic_bezier(nsfb_t *nsfb, nsfb_bbox_t *curve, nsfb_point_t *ctrla, nsfb_plot_pen_t *pen)
  199. {
  200.     return nsfb->plotter_fns->quadratic(nsfb, curve, ctrla, pen);
  201. }
  202.  
  203. bool nsfb_plot_path(nsfb_t *nsfb, int pathc, nsfb_plot_pathop_t *pathop, nsfb_plot_pen_t *pen)
  204. {
  205.     return nsfb->plotter_fns->path(nsfb, pathc, pathop, pen);
  206. }
  207.  
  208. /*
  209.  * Local variables:
  210.  *  c-basic-offset: 4
  211.  *  tab-width: 8
  212.  * End:
  213.  */
  214.