summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/cursor.h2
-rw-r--r--include/libnsfb_cursor.h21
-rw-r--r--src/cursor.c26
-rw-r--r--src/surface/sdl.c7
4 files changed, 44 insertions, 12 deletions
diff --git a/include/cursor.h b/include/cursor.h
index e3a8a04..076e6c9 100644
--- a/include/cursor.h
+++ b/include/cursor.h
@@ -20,6 +20,8 @@ struct nsfb_cursor_s {
int bmp_width;
int bmp_height;
int bmp_stride;
+ int hotspot_x;
+ int hotspot_y;
/* current saved image */
nsfb_bbox_t savloc;
diff --git a/include/libnsfb_cursor.h b/include/libnsfb_cursor.h
index 4f36793..525bd83 100644
--- a/include/libnsfb_cursor.h
+++ b/include/libnsfb_cursor.h
@@ -17,15 +17,22 @@ bool nsfb_cursor_init(nsfb_t *nsfb);
/** Set cursor parameters.
*
- * Set a cursor, the cursor will be shown at the specified location and
- * size. The pixel data may be referenced untill the cursor is altered or
- * cleared
+ * Set a cursor bitmap, the cursor will be shown at the location set by
+ * nsfb_cursor_loc_set. The pixel data may be referenced untill the cursor
+ * is altered or cleared
*
- * @param nsfb The frambuffer context.
- * @param loc The location of the cursor
- * @param pixel The pixel data for the cursor
+ * @param nsfb The frambuffer context
+ * @param pixel The cursor bitmap data
+ * @param bmp_width The width of the cursor bitmap
+ * @param bmp_height The height of the cursor bitmap
+ * @param bmp_stride The cursor bitmap's row stride
+ * @param hotspot_x Coordinate within cursor image to place over cursor loc
+ * @param hotspot_y Coordinate within cursor image to place over cursor loc
+ *
+ * (hot_spot_x, hot_spot_y) is from top left. (0, 0) means top left pixel of
+ * cursor bitmap is to be rendered over the cursor location.
*/
-bool nsfb_cursor_set(nsfb_t *nsfb, const nsfb_colour_t *pixel, int bmp_width, int bmp_height, int bmp_stride);
+bool nsfb_cursor_set(nsfb_t *nsfb, const nsfb_colour_t *pixel, int bmp_width, int bmp_height, int bmp_stride, int hotspot_x, int hotspot_y);
/** Set cursor location.
*
diff --git a/src/cursor.c b/src/cursor.c
index bd9f04b..5e3f41e 100644
--- a/src/cursor.c
+++ b/src/cursor.c
@@ -36,7 +36,9 @@ bool nsfb_cursor_init(nsfb_t *nsfb)
return true;
}
-bool nsfb_cursor_set(nsfb_t *nsfb, const nsfb_colour_t *pixel, int bmp_width, int bmp_height, int bmp_stride)
+bool nsfb_cursor_set(nsfb_t *nsfb, const nsfb_colour_t *pixel,
+ int bmp_width, int bmp_height, int bmp_stride,
+ int hotspot_x, int hotspot_y)
{
if (nsfb->cursor == NULL)
return false;
@@ -47,6 +49,9 @@ bool nsfb_cursor_set(nsfb_t *nsfb, const nsfb_colour_t *pixel, int bmp_width, in
nsfb->cursor->bmp_stride = bmp_stride;
nsfb->cursor->loc.x1 = nsfb->cursor->loc.x0 + nsfb->cursor->bmp_width;
nsfb->cursor->loc.y1 = nsfb->cursor->loc.y0 + nsfb->cursor->bmp_height;
+
+ nsfb->cursor->hotspot_x = hotspot_x;
+ nsfb->cursor->hotspot_y = hotspot_y;
return nsfb->surface_rtns->cursor(nsfb, nsfb->cursor);
}
@@ -81,6 +86,12 @@ bool nsfb_cursor_plot(nsfb_t *nsfb, struct nsfb_cursor_s *cursor)
nsfb->plotter_fns->get_clip(nsfb, &sclip);
nsfb->plotter_fns->set_clip(nsfb, NULL);
+ /* offset cursor rect for hotspot */
+ cursor->loc.x0 -= cursor->hotspot_x;
+ cursor->loc.y0 -= cursor->hotspot_y;
+ cursor->loc.x1 -= cursor->hotspot_x;
+ cursor->loc.y1 -= cursor->hotspot_y;
+
cursor->savloc = cursor->loc;
cursor->sav_width = cursor->savloc.x1 - cursor->savloc.x0;
@@ -91,11 +102,12 @@ bool nsfb_cursor_plot(nsfb_t *nsfb, struct nsfb_cursor_s *cursor)
cursor->sav = realloc(cursor->sav, sav_size);
cursor->sav_size = sav_size;
}
-
- nsfb->plotter_fns->readrect(nsfb, &cursor->savloc, cursor->sav );
+
+ nsfb->plotter_fns->readrect(nsfb, &cursor->savloc, cursor->sav);
cursor->sav_width = cursor->savloc.x1 - cursor->savloc.x0;
cursor->sav_height = cursor->savloc.y1 - cursor->savloc.y0;
-
+
+ nsfb->plotter_fns->set_clip(nsfb, NULL);
nsfb->plotter_fns->bitmap(nsfb,
&cursor->loc,
cursor->pixel,
@@ -104,6 +116,12 @@ bool nsfb_cursor_plot(nsfb_t *nsfb, struct nsfb_cursor_s *cursor)
cursor->bmp_stride,
true);
+ /* undo hotspot offset */
+ cursor->loc.x0 += cursor->hotspot_x;
+ cursor->loc.y0 += cursor->hotspot_y;
+ cursor->loc.x1 += cursor->hotspot_x;
+ cursor->loc.y1 += cursor->hotspot_y;
+
nsfb->plotter_fns->set_clip(nsfb, &sclip);
cursor->plotted = true;
diff --git a/src/surface/sdl.c b/src/surface/sdl.c
index 2a905f5..8908a21 100644
--- a/src/surface/sdl.c
+++ b/src/surface/sdl.c
@@ -636,8 +636,13 @@ sdl_cursor(nsfb_t *nsfb, struct nsfb_cursor_s *cursor)
nsfb_bbox_t fbarea;
if ((cursor != NULL) && (cursor->plotted == true)) {
+ nsfb_bbox_t loc_shift = cursor->loc;
+ loc_shift.x0 -= cursor->hotspot_x;
+ loc_shift.y0 -= cursor->hotspot_y;
+ loc_shift.x1 -= cursor->hotspot_x;
+ loc_shift.y1 -= cursor->hotspot_y;
- nsfb_plot_add_rect(&cursor->savloc, &cursor->loc, &redraw);
+ nsfb_plot_add_rect(&cursor->savloc, &loc_shift, &redraw);
/* screen area */
fbarea.x0 = 0;