summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/cursor.h5
-rw-r--r--include/frontend.h6
-rw-r--r--include/libnsfb.h18
-rw-r--r--include/libnsfb_plot.h2
-rw-r--r--include/nsfb_plot.h2
-rw-r--r--src/cursor.c30
-rw-r--r--src/frontend.c6
-rw-r--r--src/frontend_sdl.c40
-rw-r--r--src/libnsfb.c4
-rw-r--r--src/plot.c4
-rw-r--r--src/plot_util.c3
-rw-r--r--src/plotters.c39
12 files changed, 106 insertions, 53 deletions
diff --git a/include/cursor.h b/include/cursor.h
index d22d5e6..e3a8a04 100644
--- a/include/cursor.h
+++ b/include/cursor.h
@@ -30,7 +30,10 @@ struct nsfb_cursor_s {
};
-/** plot the cursor saving the image underneath. */
+/** Plot the cursor saving the image underneath. */
bool nsfb_cursor_plot(nsfb_t *nsfb, struct nsfb_cursor_s *cursor);
+/** Clear the cursor restoring the image underneath */
+bool nsfb_cursor_clear(nsfb_t *nsfb, struct nsfb_cursor_s *cursor);
+
#endif /* CURSOR_H */
diff --git a/include/frontend.h b/include/frontend.h
index bf6fee6..f477996 100644
--- a/include/frontend.h
+++ b/include/frontend.h
@@ -15,8 +15,8 @@ typedef int (nsfb_fendfn_geometry_t)(nsfb_t *nsfb, int width, int height, int bp
typedef bool (nsfb_fendfn_input_t)(nsfb_t *nsfb, nsfb_event_t *event, int timeout);
/* frontend area claim */
typedef int (nsfb_fendfn_claim_t)(nsfb_t *nsfb, nsfb_bbox_t *box);
-/* frontend area release */
-typedef int (nsfb_fendfn_release_t)(nsfb_t *nsfb, nsfb_bbox_t *box);
+/* frontend area update */
+typedef int (nsfb_fendfn_update_t)(nsfb_t *nsfb, nsfb_bbox_t *box);
/* frontend cursor display */
typedef int (nsfb_fendfn_cursor_t)(nsfb_t *nsfb, struct nsfb_cursor_s *cursor);
@@ -27,7 +27,7 @@ typedef struct nsfb_frontend_rtns_s {
nsfb_fendfn_geometry_t *geometry;
nsfb_fendfn_input_t *input;
nsfb_fendfn_claim_t *claim;
- nsfb_fendfn_release_t *release;
+ nsfb_fendfn_update_t *update;
nsfb_fendfn_cursor_t *cursor;
} nsfb_frontend_rtns_t;
diff --git a/include/libnsfb.h b/include/libnsfb.h
index d828fca..5975768 100644
--- a/include/libnsfb.h
+++ b/include/libnsfb.h
@@ -68,21 +68,27 @@ enum nsfb_frontend_e nsfb_frontend_from_name(const char *name);
/** Claim an area of screen to be redrawn.
*
- * Informs the nsfb library that an area of screen will be updated by the user
- * program, used for soft cursor plotting.
+ * Informs the nsfb library that an area of screen will be directly
+ * updated by the user program. This is neccisarry so the library can
+ * ensure the soft cursor plotting is correctly handled. After the
+ * update has been perfomed ::nsfb_update should be called.
*
* @param box The bounding box of the area which might be altered.
*/
int nsfb_claim(nsfb_t *nsfb, nsfb_bbox_t *box);
-/** Release an area of screen which has been redrawn.
+/** Update an area of screen which has been redrawn.
*
- * Informs the nsfb library that an area of screen has been updated by the user
- * program. Some frontends only update on area release.
+ * Informs the nsfb library that an area of screen has been directly
+ * updated by the user program. Some frontends only show the update on
+ * notification. The area updated does not neccisarrily have to
+ * corelate with a previous ::nsfb_claim bounding box, however if the
+ * redrawn area is larger than the claimed area pointer plotting
+ * artifacts may occour.
*
* @param box The bounding box of the area which has been altered.
*/
-int nsfb_release(nsfb_t *nsfb, nsfb_bbox_t *box);
+int nsfb_update(nsfb_t *nsfb, nsfb_bbox_t *box);
/** Obtain the geometry of a nsfb context.
*
diff --git a/include/libnsfb_plot.h b/include/libnsfb_plot.h
index 4bb40fa..45aad28 100644
--- a/include/libnsfb_plot.h
+++ b/include/libnsfb_plot.h
@@ -82,7 +82,7 @@ bool nsfb_plot_point(nsfb_t *nsfb, int x, int y, nsfb_colour_t c);
*
* Copy an area of the display.
*/
-bool nsfb_plot_copy(nsfb_t *nsfb, int srcx, int srcy, int width, int height, int dstx, int dsty);
+bool nsfb_plot_copy(nsfb_t *nsfb, nsfb_bbox_t *srcbox, nsfb_bbox_t *dstbox);
/** Plot bitmap.
*/
diff --git a/include/nsfb_plot.h b/include/nsfb_plot.h
index 6574fad..790a923 100644
--- a/include/nsfb_plot.h
+++ b/include/nsfb_plot.h
@@ -67,7 +67,7 @@ typedef bool (nsfb_plotfn_bitmap_t)(nsfb_t *nsfb, const nsfb_bbox_t *loc, const
*
* Copy an area of the display.
*/
-typedef bool (nsfb_plotfn_copy_t)(nsfb_t *nsfb, int srcx, int srcy, int width, int height, int dstx, int dsty);
+typedef bool (nsfb_plotfn_copy_t)(nsfb_t *nsfb, nsfb_bbox_t *srcbox, nsfb_bbox_t *dstbox);
/** Plot an 8 bit per pixel glyph.
diff --git a/src/cursor.c b/src/cursor.c
index faa96b1..98bd07b 100644
--- a/src/cursor.c
+++ b/src/cursor.c
@@ -10,7 +10,6 @@
#include "nsfb_plot.h"
#include "frontend.h"
-
bool nsfb_cursor_init(nsfb_t *nsfb)
{
if (nsfb->cursor != NULL)
@@ -65,6 +64,10 @@ bool nsfb_cursor_loc_get(nsfb_t *nsfb, nsfb_bbox_t *loc)
bool nsfb_cursor_plot(nsfb_t *nsfb, struct nsfb_cursor_s *cursor)
{
int sav_size;
+ nsfb_bbox_t sclip; /* saved clipping area */
+
+ nsfb->plotter_fns->get_clip(nsfb, &sclip);
+ nsfb->plotter_fns->set_clip(nsfb, NULL);
cursor->savloc = cursor->loc;
@@ -88,7 +91,32 @@ bool nsfb_cursor_plot(nsfb_t *nsfb, struct nsfb_cursor_s *cursor)
cursor->bmp_height,
cursor->bmp_stride,
true);
+
+ nsfb->plotter_fns->set_clip(nsfb, &sclip);
+
cursor->plotted = true;
return true;
}
+
+bool nsfb_cursor_clear(nsfb_t *nsfb, struct nsfb_cursor_s *cursor)
+{
+ nsfb_bbox_t sclip; /* saved clipping area */
+
+ nsfb->plotter_fns->get_clip(nsfb, &sclip);
+ nsfb->plotter_fns->set_clip(nsfb, NULL);
+
+ nsfb->plotter_fns->bitmap(nsfb,
+ &cursor->savloc,
+ cursor->sav,
+ cursor->sav_width,
+ cursor->sav_height,
+ cursor->sav_width,
+ false);
+
+ nsfb->plotter_fns->set_clip(nsfb, &sclip);
+
+ cursor->plotted = false;
+ return true;
+
+}
diff --git a/src/frontend.c b/src/frontend.c
index 7b3a72a..1390163 100644
--- a/src/frontend.c
+++ b/src/frontend.c
@@ -60,7 +60,7 @@ static int frontend_claim(nsfb_t *nsfb, nsfb_bbox_t *box)
return 0;
}
-static int frontend_release(nsfb_t *nsfb, nsfb_bbox_t *box)
+static int frontend_update(nsfb_t *nsfb, nsfb_bbox_t *box)
{
nsfb=nsfb;
box=box;
@@ -102,8 +102,8 @@ nsfb_frontend_rtns_t *nsfb_frontend_get_rtns(enum nsfb_frontend_e type)
if (rtns->claim == NULL)
rtns->claim = frontend_claim;
- if (rtns->release == NULL)
- rtns->release = frontend_release;
+ if (rtns->update == NULL)
+ rtns->update = frontend_update;
if (rtns->cursor == NULL)
rtns->cursor = frontend_cursor;
diff --git a/src/frontend_sdl.c b/src/frontend_sdl.c
index 92ae280..13ba666 100644
--- a/src/frontend_sdl.c
+++ b/src/frontend_sdl.c
@@ -544,39 +544,31 @@ static int sdl_claim(nsfb_t *nsfb, nsfb_bbox_t *box)
if ((cursor != NULL) &&
(cursor->plotted == true) &&
(nsfb_plot_bbox_intersect(box, &cursor->loc))) {
-
- nsfb->plotter_fns->bitmap(nsfb,
- &cursor->savloc,
- cursor->sav,
- cursor->sav_width,
- cursor->sav_height,
- cursor->sav_width,
- false);
- cursor->plotted = false;
+ nsfb_cursor_clear(nsfb, cursor);
}
return 0;
}
-static int sdl_cursor(nsfb_t *nsfb, struct nsfb_cursor_s *cursor)
+static int
+sdl_cursor(nsfb_t *nsfb, struct nsfb_cursor_s *cursor)
{
SDL_Surface *sdl_screen = nsfb->frontend_priv;
- nsfb_bbox_t sclip;
nsfb_bbox_t redraw;
+ nsfb_bbox_t fbarea;
if ((cursor != NULL) && (cursor->plotted == true)) {
- sclip = nsfb->clip;
nsfb_plot_add_rect(&cursor->savloc, &cursor->loc, &redraw);
- nsfb->plotter_fns->set_clip(nsfb, &redraw);
+ /* screen area */
+ fbarea.x0 = 0;
+ fbarea.y0 = 0;
+ fbarea.x1 = nsfb->width;
+ fbarea.y1 = nsfb->height;
+
+ nsfb_plot_clip(&fbarea, &redraw);
- nsfb->plotter_fns->bitmap(nsfb,
- &cursor->savloc,
- cursor->sav,
- cursor->sav_width,
- cursor->sav_height,
- cursor->sav_width,
- false);
+ nsfb_cursor_clear(nsfb, cursor);
nsfb_cursor_plot(nsfb, cursor);
@@ -587,18 +579,18 @@ static int sdl_cursor(nsfb_t *nsfb, struct nsfb_cursor_s *cursor)
redraw.y1 - redraw.y0);
- nsfb->clip = sclip;
}
return true;
}
-static int sdl_release(nsfb_t *nsfb, nsfb_bbox_t *box)
+static int sdl_update(nsfb_t *nsfb, nsfb_bbox_t *box)
{
SDL_Surface *sdl_screen = nsfb->frontend_priv;
struct nsfb_cursor_s *cursor = nsfb->cursor;
- if ((cursor != NULL) && (cursor->plotted == false)) {
+ if ((cursor != NULL) &&
+ (cursor->plotted == false)) {
nsfb_cursor_plot(nsfb, cursor);
}
@@ -616,7 +608,7 @@ const nsfb_frontend_rtns_t sdl_rtns = {
.finalise = sdl_finalise,
.input = sdl_input,
.claim = sdl_claim,
- .release = sdl_release,
+ .update = sdl_update,
.cursor = sdl_cursor,
.geometry = sdl_set_geometry,
};
diff --git a/src/libnsfb.c b/src/libnsfb.c
index 83e1a37..b3a1903 100644
--- a/src/libnsfb.c
+++ b/src/libnsfb.c
@@ -61,9 +61,9 @@ int nsfb_claim(nsfb_t *nsfb, nsfb_bbox_t *box)
return nsfb->frontend_rtns->claim(nsfb, box);
}
-int nsfb_release(nsfb_t *nsfb, nsfb_bbox_t *box)
+int nsfb_update(nsfb_t *nsfb, nsfb_bbox_t *box)
{
- return nsfb->frontend_rtns->release(nsfb, box);
+ return nsfb->frontend_rtns->update(nsfb, box);
}
int nsfb_set_geometry(nsfb_t *nsfb, int width, int height, int bpp)
diff --git a/src/plot.c b/src/plot.c
index b79267a..55437cf 100644
--- a/src/plot.c
+++ b/src/plot.c
@@ -110,9 +110,9 @@ bool nsfb_plot_ellipse_fill(nsfb_t *nsfb, nsfb_bbox_t *ellipse, nsfb_colour_t c)
return nsfb->plotter_fns->ellipse_fill(nsfb, ellipse, c);
}
-bool nsfb_plot_copy(nsfb_t *nsfb, int srcx, int srcy, int width, int height, int dstx, int dsty)
+bool nsfb_plot_copy(nsfb_t *nsfb, nsfb_bbox_t *srcbox, nsfb_bbox_t *dstbox)
{
- return nsfb->plotter_fns->copy(nsfb, srcx, srcy, width, height, dstx, dsty);
+ return nsfb->plotter_fns->copy(nsfb, srcbox, dstbox);
}
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)
diff --git a/src/plot_util.c b/src/plot_util.c
index a126021..c30597b 100644
--- a/src/plot_util.c
+++ b/src/plot_util.c
@@ -150,7 +150,8 @@ bool nsfb_plot_clip_line_ctx(nsfb_t *nsfb, nsfb_bbox_t * restrict line)
}
/* documented in libnsfb_plot_util.h */
-bool nsfb_plot_add_rect(const nsfb_bbox_t *box1, const nsfb_bbox_t *box2, nsfb_bbox_t *result)
+bool
+nsfb_plot_add_rect(const nsfb_bbox_t *box1, const nsfb_bbox_t *box2, nsfb_bbox_t *result)
{
/* lower x coordinate */
if (box1->x0 < box2->x0)
diff --git a/src/plotters.c b/src/plotters.c
index 289e2f4..82deb0f 100644
--- a/src/plotters.c
+++ b/src/plotters.c
@@ -22,6 +22,7 @@
#include "nsfb.h"
#include "nsfb_plot.h"
#include "plotters.h"
+#include "frontend.h"
extern const nsfb_plotter_fns_t _nsfb_1bpp_plotters;
extern const nsfb_plotter_fns_t _nsfb_8bpp_plotters;
@@ -434,17 +435,36 @@ static bool ellipse_fill(nsfb_t *nsfb, nsfb_bbox_t *ellipse, nsfb_colour_t c)
}
}
-static bool copy(nsfb_t *nsfb, int srcx, int srcy, int width, int height, int dstx, int dsty)
+/* copy an area of screen from one location to another.
+ *
+ * @warning This implementation is woefully incomplete!
+ */
+static bool
+copy(nsfb_t *nsfb, nsfb_bbox_t *srcbox, nsfb_bbox_t *dstbox)
{
- uint8_t *srcptr = (nsfb->ptr +
- (srcy * nsfb->linelen) +
- ((srcx * nsfb->bpp) / 8));
+ int srcx = srcbox->x0;
+ int srcy = srcbox->y0;
+ int dstx = dstbox->x0;
+ int dsty = dstbox->y0;
+ int width = dstbox->x1 - dstbox->x0;
+ int height = dstbox->y1 - dstbox->y0;
+ uint8_t *srcptr;
+ uint8_t *dstptr;
+ int hloop;
+ nsfb_bbox_t allbox;
- uint8_t *dstptr = (nsfb->ptr +
- (dsty * nsfb->linelen) +
- ((dstx * nsfb->bpp) / 8));
+ nsfb_plot_add_rect(srcbox, dstbox, &allbox);
+
+ nsfb->frontend_rtns->claim(nsfb, &allbox);
+
+ srcptr = (nsfb->ptr +
+ (srcy * nsfb->linelen) +
+ ((srcx * nsfb->bpp) / 8));
+
+ dstptr = (nsfb->ptr +
+ (dsty * nsfb->linelen) +
+ ((dstx * nsfb->bpp) / 8));
- int hloop;
if (width == nsfb->width) {
/* take shortcut and use memmove */
@@ -466,6 +486,9 @@ static bool copy(nsfb_t *nsfb, int srcx, int srcy, int width, int height, int ds
}
}
}
+
+ nsfb->frontend_rtns->update(nsfb, dstbox);
+
return true;
}