From 3d5b21e1473dbdee6c3df66d9ba2a9d657f1b486 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Fri, 24 Apr 2009 13:42:40 +0000 Subject: add legacy plotter API svn path=/trunk/libnsfb/; revision=7304 --- include/libnsfb.h | 16 +++++++--- include/libnsfb_event.h | 12 +++++++ include/libnsfb_legacy_plot.h | 74 +++++++++++++++++++++++++++++++++++++++++++ include/libnsfb_plot.h | 19 +++++++++++ include/libnsfb_plot_util.h | 40 +++++++++++++++++++++++ include/nsfb_plot.h | 5 +-- include/plot_util.h | 24 -------------- 7 files changed, 159 insertions(+), 31 deletions(-) create mode 100644 include/libnsfb_legacy_plot.h create mode 100644 include/libnsfb_plot_util.h delete mode 100644 include/plot_util.h (limited to 'include') diff --git a/include/libnsfb.h b/include/libnsfb.h index 3236ea5..c125ead 100644 --- a/include/libnsfb.h +++ b/include/libnsfb.h @@ -1,3 +1,13 @@ +/* + * Copyright 2009 Vincent Sanders + * + * This file is part of libnsfb, http://www.netsurf-browser.org/ + * Licenced under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * + * This is the exported interface for the libnsfb graphics library. + */ + #ifndef _LIBNSFB_H #define _LIBNSFB_H 1 @@ -23,7 +33,7 @@ enum nsfb_frontend_e { NSFB_FRONTEND_LINUX, /**< Linux frontend */ NSFB_FRONTEND_VNC, /**< VNC frontend */ NSFB_FRONTEND_ABLE, /**< ABLE frontend */ - NSFB_FRONTEND_RAM, /**< RAM frontend */ + NSFB_FRONTEND_RAM /**< RAM frontend */ }; /** Initialise nsfb context. @@ -56,10 +66,6 @@ int nsfb_init_frontend(nsfb_t *nsfb); */ enum nsfb_frontend_e nsfb_frontend_from_name(const char *name); -/** Process input from a frontend. - */ -bool nsfb_input(nsfb_t *nsfb, nsfb_event_t *event, int timeout); - /** Claim an area of screen to be redrawn. * * Informs the nsfb library that an area of screen will be updated by the user diff --git a/include/libnsfb_event.h b/include/libnsfb_event.h index 179f24b..0fa275e 100644 --- a/include/libnsfb_event.h +++ b/include/libnsfb_event.h @@ -181,3 +181,15 @@ struct nsfb_event_s { } vector; } value; }; + +/** Process input events. + * + * Gather events from a frontend. + * + * @param nsfb The library handle. + * @param event The event structure to fill. + * @param timeout The number of milliseconds to wait for input, -1 is wait + * forever, 0 returns immediately. + * @return If the /a event structure is updated true else false. + */ +bool nsfb_event(nsfb_t *nsfb, nsfb_event_t *event, int timeout); diff --git a/include/libnsfb_legacy_plot.h b/include/libnsfb_legacy_plot.h new file mode 100644 index 0000000..276acea --- /dev/null +++ b/include/libnsfb_legacy_plot.h @@ -0,0 +1,74 @@ +/* + * Copyright 2009 Vincent Sanders + * + * This file is part of libnsfb, http://www.netsurf-browser.org/ + * Licenced under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * + * This is the exported legacy plotter interface for the libnsfb graphics + * library. This interface should *not* be used for new projects. It is not + * thread safe as the framebuffer context is held as a global and not passed. + */ + +#ifndef _LIBNSFB_LEGACY_PLOT_H +#define _LIBNSFB_LEGACY_PLOT_H 1 + +/** Set the framebuffer context for all legacy plot operations. + */ +bool nsfb_lplot_ctx(nsfb_t *nsfb); + +/** Sets a clip rectangle for subsequent plots. + * + * Sets a clipping area which constrains all subsequent plotting operations. + * The clipping area must lie within the framebuffer visible screen or false + * will be returned and the new clipping area not set. + */ +bool nsfb_lplot_clip(int x0, int y0, int x1, int y1); + +/** Clears plotting area to a flat colour. + */ +bool nsfb_lplot_clg(nsfb_colour_t c); + +/** Plots a rectangle outline. + * + * The line can be solid, dotted or dashed. Top left corner at (x0,y0) and + * rectangle has given width and height. + */ +bool nsfb_lplot_rectangle(int x0, int y0, int width, int height, int line_width, nsfb_colour_t c, bool dotted, bool dashed); + +/** Plots a filled rectangle. + * + * Top left corner at (x0,y0), bottom right corner at (x1,y1). Note: (x0,y0) is + * inside filled area, but (x1,y1) is below and to the right. + */ +bool nsfb_lplot_fill(int x0, int y0, int x1, int y1, nsfb_colour_t c); + +/** Plots a line. + * + * Draw a line from (x0,y0) to (x1,y1). Coordinates are at centre of line + * width/thickness. + */ +bool nsfb_lplot_line(int x0, int y0, int x1, int y1, int line_width, nsfb_colour_t c, bool dotted, bool dashed); + + +/** Plots a filled polygon. + * + * Plots a filled polygon with straight lines between points. The lines around + * the edge of the ploygon are not plotted. The polygon is filled with a + * non-zero winding rule. + * + */ +bool nsfb_lplot_polygon(const int *p, unsigned int n, nsfb_colour_t fillc); + +/** Plots a circle. + */ +bool nsfb_lplot_disc(int x, int y, int radius, nsfb_colour_t c, bool filled); + +/** Plots an arc. + * + * around (x,y), from anticlockwise from angle1 to angle2. Angles are measured + * anticlockwise from horizontal, in degrees. + */ +bool nsfb_lplot_arc(int x, int y, int radius, int angle1, int angle2, nsfb_colour_t c); + +#endif /* _LIBNSFB_LEGACY_PLOT_H */ diff --git a/include/libnsfb_plot.h b/include/libnsfb_plot.h index 2b19b52..317ae95 100644 --- a/include/libnsfb_plot.h +++ b/include/libnsfb_plot.h @@ -1,3 +1,16 @@ +/* + * Copyright 2009 Vincent Sanders + * + * This file is part of libnsfb, http://www.netsurf-browser.org/ + * Licenced under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * + * This is the exported plotter interface for the libnsfb graphics library. + */ + +#ifndef _LIBNSFB_PLOT_H +#define _LIBNSFB_PLOT_H 1 + /** Sets a clip rectangle for subsequent plots. * * Sets a clipping area which constrains all subsequent plotting operations. @@ -6,6 +19,10 @@ */ bool nsfb_plot_set_clip(nsfb_t *nsfb, nsfb_bbox_t *clip); +/** Get the previously set clipping region. + */ +bool nsfb_plot_get_clip(nsfb_t *nsfb, nsfb_bbox_t *clip); + /** Clears plotting area to a flat colour. */ bool nsfb_plot_clg(nsfb_t *nsfb, nsfb_colour_t c); @@ -79,3 +96,5 @@ bool nsfb_plot_glyph8(nsfb_t *nsfb, nsfb_bbox_t *loc, const uint8_t *pixel, int /** Plot an 1 bit glyph. */ bool nsfb_plot_glyph1(nsfb_t *nsfb, nsfb_bbox_t *loc, const uint8_t *pixel, int pitch, nsfb_colour_t c); + +#endif /* _LIBNSFB_PLOT_H */ diff --git a/include/libnsfb_plot_util.h b/include/libnsfb_plot_util.h new file mode 100644 index 0000000..a1b0159 --- /dev/null +++ b/include/libnsfb_plot_util.h @@ -0,0 +1,40 @@ +/* + * Copyright 2009 Vincent Sanders + * + * This file is part of libnsfb, http://www.netsurf-browser.org/ + * Licenced under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * + * This is the exported interface for the libnsfb graphics library. + */ + +#ifndef _LIBNSFB_PLOT_UTIL_H +#define _LIBNSFB_PLOT_UTIL_H 1 + + +/* alpha blend two pixels together */ +static inline nsfb_colour_t +nsfb_plot_ablend(nsfb_colour_t pixel, nsfb_colour_t scrpixel) +{ + int opacity = pixel >> 24; + int transp = 0x100 - opacity; + uint32_t rb, g; + + rb = ((pixel & 0xFF00FF) * opacity + + (scrpixel & 0xFF00FF) * transp) >> 8; + g = ((pixel & 0x00FF00) * opacity + + (scrpixel & 0x00FF00) * transp) >> 8; + + return (rb & 0xFF00FF) | (g & 0xFF00); +} + + +bool nsfb_plot_clip(const nsfb_bbox_t * restrict clip, nsfb_bbox_t * restrict rect); + +bool nsfb_plot_clip_ctx(nsfb_t *nsfb, nsfb_bbox_t * restrict rect); + +bool nsfb_plot_clip_line(const nsfb_bbox_t * restrict clip, nsfb_bbox_t * restrict line); + +bool nsfb_plot_clip_line_ctx(nsfb_t *nsfb, nsfb_bbox_t * restrict line); + +#endif /* _LIBNSFB_PLOT_UTIL_H */ diff --git a/include/nsfb_plot.h b/include/nsfb_plot.h index 02da331..718de6f 100644 --- a/include/nsfb_plot.h +++ b/include/nsfb_plot.h @@ -27,7 +27,7 @@ typedef bool (nsfb_plotfn_polygon_t)(nsfb_t *nsfb, const int *p, unsigned int n, */ typedef bool (nsfb_plotfn_fill_t)(nsfb_t *nsfb, nsfb_bbox_t *rect, nsfb_colour_t c); -/** Sets a clip rectangle for subsequent plots. +/** Clipping operations. */ typedef bool (nsfb_plotfn_clip_t)(nsfb_t *nsfb, nsfb_bbox_t *clip); @@ -87,7 +87,8 @@ typedef struct nsfb_plotter_fns_s { nsfb_plotfn_line_t *line; nsfb_plotfn_polygon_t *polygon; nsfb_plotfn_fill_t *fill; - nsfb_plotfn_clip_t *clip; + nsfb_plotfn_clip_t *get_clip; + nsfb_plotfn_clip_t *set_clip; nsfb_plotfn_ellipse_t *ellipse; nsfb_plotfn_ellipse_fill_t *ellipse_fill; nsfb_plotfn_arc_t *arc; diff --git a/include/plot_util.h b/include/plot_util.h deleted file mode 100644 index 6565cb1..0000000 --- a/include/plot_util.h +++ /dev/null @@ -1,24 +0,0 @@ -/* alpha blend two pixels together */ -static inline nsfb_colour_t -nsfb_plot_ablend(nsfb_colour_t pixel, nsfb_colour_t scrpixel) -{ - int opacity = pixel >> 24; - int transp = 0x100 - opacity; - uint32_t rb, g; - - rb = ((pixel & 0xFF00FF) * opacity + - (scrpixel & 0xFF00FF) * transp) >> 8; - g = ((pixel & 0x00FF00) * opacity + - (scrpixel & 0x00FF00) * transp) >> 8; - - return (rb & 0xFF00FF) | (g & 0xFF00); -} - - -bool nsfb_plot_clip(const nsfb_bbox_t * restrict clip, nsfb_bbox_t * restrict rect); - -bool nsfb_plot_clip_ctx(nsfb_t *nsfb, nsfb_bbox_t * restrict rect); - -bool nsfb_plot_clip_line(const nsfb_bbox_t * restrict clip, nsfb_bbox_t * restrict line); - -bool nsfb_plot_clip_line_ctx(nsfb_t *nsfb, nsfb_bbox_t * restrict line); -- cgit v1.2.3