summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--include/libnsfb.h16
-rw-r--r--include/libnsfb_event.h12
-rw-r--r--include/libnsfb_legacy_plot.h74
-rw-r--r--include/libnsfb_plot.h19
-rw-r--r--include/libnsfb_plot_util.h (renamed from include/plot_util.h)16
-rw-r--r--include/nsfb_plot.h5
-rw-r--r--src/16bpp_plotters.c3
-rw-r--r--src/32bpp_plotters.c3
-rw-r--r--src/8bpp_plotters.c3
-rw-r--r--src/Makefile2
-rw-r--r--src/frontend.c2
-rw-r--r--src/frontend_sdl.c6
-rw-r--r--src/legacy_plot.c114
-rw-r--r--src/libnsfb.c2
-rw-r--r--src/plot.c9
-rw-r--r--src/plot_util.c3
-rw-r--r--src/plotters.c12
18 files changed, 287 insertions, 18 deletions
diff --git a/Makefile b/Makefile
index e94ee66..acbd8d7 100644
--- a/Makefile
+++ b/Makefile
@@ -26,5 +26,9 @@ include build/makefiles/Makefile.top
# Extra installation rules
I := /include
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):include/libnsfb.h
+INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):include/libnsfb_plot.h
+INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):include/libnsfb_plot_util.h
+INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):include/libnsfb_legacy_plot.h
+INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):include/libnsfb_event.h
INSTALL_ITEMS := $(INSTALL_ITEMS) /lib/pkgconfig:lib$(COMPONENT).pc.in
INSTALL_ITEMS := $(INSTALL_ITEMS) /lib:$(OUTPUT)
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 <vince@simtec.co.uk>
+ *
+ * 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 <vince@simtec.co.uk>
+ *
+ * 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 <vince@simtec.co.uk>
+ *
+ * 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/plot_util.h b/include/libnsfb_plot_util.h
index 6565cb1..a1b0159 100644
--- a/include/plot_util.h
+++ b/include/libnsfb_plot_util.h
@@ -1,3 +1,17 @@
+/*
+ * Copyright 2009 Vincent Sanders <vince@simtec.co.uk>
+ *
+ * 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)
@@ -22,3 +36,5 @@ 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/src/16bpp_plotters.c b/src/16bpp_plotters.c
index b2abff7..035a9a6 100644
--- a/src/16bpp_plotters.c
+++ b/src/16bpp_plotters.c
@@ -11,10 +11,11 @@
#include <stdlib.h>
#include "libnsfb.h"
+#include "libnsfb_plot_util.h"
+
#include "nsfb.h"
#include "nsfb_plot.h"
#include "plotters.h"
-#include "plot_util.h"
static inline uint16_t *get_xy_loc(nsfb_t *nsfb, int x, int y)
{
diff --git a/src/32bpp_plotters.c b/src/32bpp_plotters.c
index 5848405..2456f58 100644
--- a/src/32bpp_plotters.c
+++ b/src/32bpp_plotters.c
@@ -11,10 +11,11 @@
#include <stdlib.h>
#include "libnsfb.h"
+#include "libnsfb_plot_util.h"
+
#include "nsfb.h"
#include "nsfb_plot.h"
#include "plotters.h"
-#include "plot_util.h"
static inline uint32_t *
get_xy_loc(nsfb_t *nsfb, int x, int y)
diff --git a/src/8bpp_plotters.c b/src/8bpp_plotters.c
index a6bb3a3..40a06f9 100644
--- a/src/8bpp_plotters.c
+++ b/src/8bpp_plotters.c
@@ -13,10 +13,11 @@
#include <string.h>
#include "libnsfb.h"
+#include "libnsfb_plot_util.h"
+
#include "nsfb.h"
#include "nsfb_plot.h"
#include "plotters.h"
-#include "plot_util.h"
static inline uint8_t *get_xy_loc(nsfb_t *nsfb, int x, int y)
{
diff --git a/src/Makefile b/src/Makefile
index bb142d0..431abd9 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,5 +1,5 @@
# Sources
-DIR_SOURCES := libnsfb.c frontend.c frontend_sdl.c frontend_linux.c frontend_vnc.c frontend_able.c frontend_ram.c plot.c plot_util.c plotters.c 32bpp_plotters.c 16bpp_plotters.c 8bpp_plotters.c
+DIR_SOURCES := libnsfb.c frontend.c frontend_sdl.c frontend_linux.c frontend_vnc.c frontend_able.c frontend_ram.c plot.c legacy_plot.c plot_util.c plotters.c 32bpp_plotters.c 16bpp_plotters.c 8bpp_plotters.c
include build/makefiles/Makefile.subdir
diff --git a/src/frontend.c b/src/frontend.c
index 68edb9e..c53ba66 100644
--- a/src/frontend.c
+++ b/src/frontend.c
@@ -47,7 +47,7 @@ static int frontend_defaults(nsfb_t *nsfb)
nsfb->height = 600;
nsfb->bpp = 16;
- /* select plotters for bpp */
+ /* select default sw plotters for bpp */
select_plotters(nsfb);
return 0;
diff --git a/src/frontend_sdl.c b/src/frontend_sdl.c
index 82342d3..ca98199 100644
--- a/src/frontend_sdl.c
+++ b/src/frontend_sdl.c
@@ -13,6 +13,7 @@
#include "libnsfb_event.h"
#include "nsfb.h"
#include "frontend.h"
+#include "plotters.h"
enum nsfb_key_code_e sdl_nsfb_map[] = {
NSFB_KEY_UNKNOWN,
@@ -378,6 +379,9 @@ static int sdl_set_geometry(nsfb_t *nsfb, int width, int height, int bpp)
nsfb->height = height;
nsfb->bpp = bpp;
+ /* select default sw plotters for bpp */
+ select_plotters(nsfb);
+
return 0;
}
@@ -390,7 +394,7 @@ static int sdl_initialise(nsfb_t *nsfb)
/* sanity checked depth. */
if ((nsfb->bpp != 32) && (nsfb->bpp != 16) && (nsfb->bpp != 8))
- nsfb->bpp = 16;
+ return -1;
/* initialise SDL library */
if (SDL_Init(SDL_INIT_VIDEO) < 0 ) {
diff --git a/src/legacy_plot.c b/src/legacy_plot.c
new file mode 100644
index 0000000..fc7a7ef
--- /dev/null
+++ b/src/legacy_plot.c
@@ -0,0 +1,114 @@
+/*
+ * Copyright 2009 Vincent Sanders <vince@simtec.co.uk>
+ *
+ * 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.
+ */
+
+#include <stdbool.h>
+
+#include "libnsfb.h"
+#include "libnsfb_plot.h"
+#include "libnsfb_legacy_plot.h"
+#include "nsfb.h"
+#include "nsfb_plot.h"
+
+/* legacy interface global context */
+static nsfb_t *gnsfb;
+
+bool nsfb_lplot_ctx(nsfb_t *nsfb)
+{
+ gnsfb = nsfb;
+ return true;
+}
+
+bool nsfb_lplot_clip(int x0, int y0, int x1, int y1)
+{
+ nsfb_bbox_t clip;
+ clip.x0 = x0;
+ clip.y0 = y0;
+ clip.x1 = x1;
+ clip.y1 = y1;
+
+ return gnsfb->plotter_fns->set_clip(gnsfb, &clip);
+}
+
+bool nsfb_lplot_line(int x0, int y0, int x1, int y1, int line_width,
+ nsfb_colour_t c, bool dotted, bool dashed)
+{
+ nsfb_bbox_t line;
+ line.x0 = x0;
+ line.y0 = y0;
+ line.x1 = x1;
+ line.y1 = y1;
+ return gnsfb->plotter_fns->line(gnsfb, &line, line_width, c, dotted, dashed);
+}
+
+bool nsfb_lplot_rectangle(int x0,
+ int y0,
+ int width,
+ int height,
+ int line_width,
+ nsfb_colour_t c,
+ bool dotted,
+ bool dashed)
+{
+ nsfb_bbox_t rect;
+ rect.x0 = x0;
+ rect.y0 = y0;
+ rect.x1 = x0 + width;
+ rect.y1 = y0 + height;
+
+ return gnsfb->plotter_fns->rectangle(gnsfb, &rect, line_width, c, dotted, dashed);
+
+}
+
+bool nsfb_lplot_polygon(const int *p, unsigned int n, nsfb_colour_t fillc)
+{
+ return gnsfb->plotter_fns->polygon(gnsfb, p, n, fillc);
+}
+
+bool nsfb_lplot_fill(int x0, int y0, int x1, int y1, nsfb_colour_t c)
+{
+ nsfb_bbox_t rect;
+ rect.x0 = x0;
+ rect.y0 = y0;
+ rect.x1 = x1;
+ rect.y1 = y1;
+
+ return gnsfb->plotter_fns->fill(gnsfb, &rect, c);
+}
+
+bool nsfb_lplot_clg(nsfb_colour_t c)
+{
+ return gnsfb->plotter_fns->clg(gnsfb, c);
+}
+
+
+bool
+nsfb_lplot_disc(int x, int y, int radius, nsfb_colour_t c, bool filled)
+{
+ nsfb_bbox_t ellipse;
+ ellipse.x0 = x - radius;
+ ellipse.y0 = y - radius;
+ ellipse.x1 = x + radius;
+ ellipse.y1 = y + radius;
+
+ if (filled)
+ return gnsfb->plotter_fns->ellipse_fill(gnsfb, &ellipse, c);
+ else
+ return gnsfb->plotter_fns->ellipse(gnsfb, &ellipse, c);
+}
+
+bool
+nsfb_lplot_arc(int x, int y, int radius, int angle1, int angle2,
+ nsfb_colour_t c)
+{
+ return gnsfb->plotter_fns->arc(gnsfb, x, y, radius, angle1, angle2, c);
+}
+
+
+
diff --git a/src/libnsfb.c b/src/libnsfb.c
index 172b554..83e1a37 100644
--- a/src/libnsfb.c
+++ b/src/libnsfb.c
@@ -51,7 +51,7 @@ nsfb_init_frontend(nsfb_t *nsfb)
return nsfb->frontend_rtns->initialise(nsfb);
}
-bool nsfb_input(nsfb_t *nsfb, nsfb_event_t *event, int timeout)
+bool nsfb_event(nsfb_t *nsfb, nsfb_event_t *event, int timeout)
{
return nsfb->frontend_rtns->input(nsfb, event, timeout);
}
diff --git a/src/plot.c b/src/plot.c
index 99b4882..440a445 100644
--- a/src/plot.c
+++ b/src/plot.c
@@ -15,7 +15,14 @@
*/
bool nsfb_plot_set_clip(nsfb_t *nsfb, nsfb_bbox_t *clip)
{
- return nsfb->plotter_fns->clip(nsfb, clip);
+ return nsfb->plotter_fns->set_clip(nsfb, clip);
+}
+
+/** Get the previously set clipping region.
+ */
+bool nsfb_plot_get_clip(nsfb_t *nsfb, nsfb_bbox_t *clip)
+{
+ return nsfb->plotter_fns->get_clip(nsfb, clip);
}
/** Clears plotting area to a flat colour.
diff --git a/src/plot_util.c b/src/plot_util.c
index 058a0f9..ae1f548 100644
--- a/src/plot_util.c
+++ b/src/plot_util.c
@@ -1,8 +1,9 @@
#include <stdbool.h>
#include "libnsfb.h"
+#include "libnsfb_plot_util.h"
+
#include "nsfb.h"
-#include "plot_util.h"
enum {
POINT_LEFTOF_REGION = 1,
diff --git a/src/plotters.c b/src/plotters.c
index 12a31d1..4a7598e 100644
--- a/src/plotters.c
+++ b/src/plotters.c
@@ -6,9 +6,10 @@
#include <string.h>
#include "libnsfb.h"
+#include "libnsfb_plot_util.h"
+
#include "nsfb.h"
#include "nsfb_plot.h"
-#include "plot_util.h"
#include "plotters.h"
extern const nsfb_plotter_fns_t _nsfb_1bpp_plotters;
@@ -38,6 +39,12 @@ static bool set_clip(nsfb_t *nsfb, nsfb_bbox_t *clip)
return true;
}
+static bool get_clip(nsfb_t *nsfb, nsfb_bbox_t *clip)
+{
+ *clip = nsfb->clip;
+ return true;
+}
+
static bool clg(nsfb_t *nsfb, nsfb_colour_t c)
{
return nsfb->plotter_fns->fill(nsfb, &nsfb->clip, c);
@@ -500,7 +507,8 @@ bool select_plotters(nsfb_t *nsfb)
/* set the generics */
nsfb->plotter_fns->clg = clg;
- nsfb->plotter_fns->clip = set_clip;
+ nsfb->plotter_fns->set_clip = set_clip;
+ nsfb->plotter_fns->get_clip = get_clip;
nsfb->plotter_fns->polygon = polygon;
nsfb->plotter_fns->rectangle = rectangle;
nsfb->plotter_fns->ellipse = ellipse;