summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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
7 files changed, 85 insertions, 41 deletions
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;
}