summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2012-08-01 12:51:30 +0100
committerMichael Drake <tlsa@netsurf-browser.org>2012-08-01 12:51:30 +0100
commitbde04d10347414251b40af574d1bc94962d23a5a (patch)
tree8405dbd53052310d8e83502dbd1e53e8fb37d2e8 /src
parent56dd658e6265fb1902c92d6d88420c3accb79225 (diff)
downloadlibnsfb-bde04d10347414251b40af574d1bc94962d23a5a.tar.gz
libnsfb-bde04d10347414251b40af574d1bc94962d23a5a.tar.bz2
Add support for offset mouse pointer hotspots.
Diffstat (limited to 'src')
-rw-r--r--src/cursor.c26
-rw-r--r--src/surface/sdl.c7
2 files changed, 28 insertions, 5 deletions
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;